diff --git a/include/toksvc/toksvc.h b/include/toksvc/toksvc.h index d0fb247..021acd6 100644 --- a/include/toksvc/toksvc.h +++ b/include/toksvc/toksvc.h @@ -59,6 +59,9 @@ extern "C" { #define TOKS_DRIVER_ACTION_NTOKENS_GET 0X1000000 #define TOKS_DRIVER_ACTION_NTOKENS_SET 0X2000000 +#define TOKS_DRIVER_ACTION_SVCINFO_GET 0X10000000 +#define TOKS_DRIVER_ACTION_SVCINFO_LOG 0X20000000 + /* message options */ #define TOKS_OPT_SYSTEM_PID 0x0000 #define TOKS_OPT_FRAMEWORK_PID 0x0001 diff --git a/src/driver/toks_amain.c b/src/driver/toks_amain.c index d1ff0be..f24fb92 100644 --- a/src/driver/toks_amain.c +++ b/src/driver/toks_amain.c @@ -15,6 +15,8 @@ #include "toksvc_nolibc_impl.h" #include "toksvc_log_impl.h" +#undef free + #ifndef TOKS_DRIVER_FLAGS #define TOKS_DRIVER_FLAGS TOKS_DRIVER_VERBOSITY_ERRORS \ | TOKS_DRIVER_DAEMON_ALWAYS \ @@ -53,6 +55,37 @@ static ssize_t toks_version(struct toks_driver_ctx * dctx) verclr[4],verinfo->commit,verclr[5]); } +static ssize_t toks_output_service_info(struct toks_service_info * svcinfo) +{ + char guidstr[40]; + + toks_uuid_to_string( + &svcinfo->uuid, + &guidstr); + + return toks_dprintf(STDOUT_FILENO, + "toks_uuid:%s\n" + "toks_syspid:%d\n" + "toks_systid:%d\n" + "toks_ctrlpid:%d\n" + "toks_csyspid:%d\n" + "toks_allocated:%d\n" + "toks_available:%d\n" + "toks_used:%d\n" + "toks_free:%d\n" + "toks_loglevel:%d\n", + guidstr, + svcinfo->syspid, + svcinfo->systid, + svcinfo->ctrlpid, + svcinfo->csyspid, + svcinfo->allocated, + svcinfo->available, + svcinfo->used, + svcinfo->free, + svcinfo->loglevel); +} + static int toks_exit(struct toks_driver_ctx * dctx, int nerrors) { toks_free_driver_ctx(dctx); @@ -65,6 +98,7 @@ int toks_main(char ** argv, char ** envp) int32_t status; struct toks_driver_ctx * dctx; struct toks_token_string toks; + struct toks_service_info svcinfo; if ((ret = toks_init())) return ret; @@ -175,6 +209,45 @@ int toks_main(char ** argv, char ** envp) } } + if (dctx->cctx->drvflags & TOKS_DRIVER_ACTION_SVCINFO_GET) { + status = toks_client_query_service(dctx,&svcinfo); + ret = status ? 2 : 0; + + switch (status) { + case NT_STATUS_SUCCESS: + toks_output_service_info(&svcinfo); + break; + + default: + toks_dprintf(STDERR_FILENO, + "%s: the TOKS_IOCTL_GET_SERVICE_INFO " + "ioctl operataion has failed " + "(check the system's documentation) [0x%x].", + toks_log_basename(argv[0]),status); + } + } + + if (dctx->cctx->drvflags & TOKS_DRIVER_ACTION_SVCINFO_LOG) { + status = toks_service_ioctl(dctx,TOKS_IOCTL_LOG_SERVICE_INFO,0,0); + ret = status ? 2 : 0; + + switch (status) { + case NT_STATUS_SUCCESS: + toks_dprintf(STDERR_FILENO, + "%s: a service info log record " + "was successfully created\n", + toks_log_basename(argv[0])); + break; + + default: + toks_dprintf(STDERR_FILENO, + "%s: the TOKS_IOCTL_LOG_SERVICE_INFO " + "ioctl operataion has failed " + "(check the system's documentation) [0x%x].", + toks_log_basename(argv[0]),status); + } + } + return (dctx->cctx->drvflags & TOKS_DRIVER_MODE_SERVER) ? NT_STATUS_SERVICE_NOTIFICATION : toks_exit(dctx,ret); diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index 8164323..fd3cf61 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -646,6 +646,18 @@ int toks_get_driver_ctx( cctx.drvflags |= TOKS_DRIVER_ACTION_NTOKENS_SET; ntokens = toks_arg_to_int32(entry); break; + + case TAG_GETSVCINFO: + cctx.drvflags &= ~(uint64_t)TOKS_DRIVER_MODE_SERVER; + cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; + cctx.drvflags |= TOKS_DRIVER_ACTION_SVCINFO_GET; + break; + + case TAG_LOGSVCINFO: + cctx.drvflags &= ~(uint64_t)TOKS_DRIVER_MODE_SERVER; + cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; + cctx.drvflags |= TOKS_DRIVER_ACTION_SVCINFO_LOG; + break; } } else /* strict */ diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index 630d2d2..1dbe4ac 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -46,6 +46,8 @@ enum app_tags { TAG_LOGLEVEL, TAG_NTOKENSGET, TAG_NTOKENSSET, + TAG_GETSVCINFO, + TAG_LOGSVCINFO, }; struct toks_ticks { diff --git a/src/skin/toks_skin_default.c b/src/skin/toks_skin_default.c index a371160..86af40b 100644 --- a/src/skin/toks_skin_default.c +++ b/src/skin/toks_skin_default.c @@ -85,5 +85,13 @@ const struct argv_option toks_default_options[] = { "connect to the server and set the service's overall " "number of tokens to %s"}, + {"get-service-info", 'i',TAG_GETSVCINFO,ARGV_OPTARG_NONE,0,0,0, + "connect to the server and output the current service " + "information"}, + + {"log-service-info", 'I',TAG_LOGSVCINFO,ARGV_OPTARG_NONE,0,0,0, + "connect to the server and request that the current " + "service information be sent to its log"}, + {0,0,0,0,0,0,0,0} };