diff --git a/src/driver/toks_amain.c b/src/driver/toks_amain.c index f6580c3..c83737b 100644 --- a/src/driver/toks_amain.c +++ b/src/driver/toks_amain.c @@ -207,6 +207,38 @@ int toks_main(char ** argv, char ** envp) } } + if (dctx->cctx->drvflags & TOKS_DRIVER_ACTION_LOGLEVEL_GET) { + toks_dprintf(STDOUT_FILENO, + "toks_loglevel:%d\n", + dctx->cctx->loglevel); + } + + if (dctx->cctx->drvflags & TOKS_DRIVER_ACTION_LOGLEVEL_SET) { + status = toks_service_ioctl( + dctx,TOKS_IOCTL_SET_LOG_LEVEL, + &(uintptr_t){dctx->cctx->loglevel}, + 0); + + ret = status ? 2 : 0; + + switch (status) { + case NT_STATUS_SUCCESS: + toks_dprintf(STDERR_FILENO, + "%s: the service's log-level parameter " + "was successfully set to %d\n", + toks_log_basename(argv[0]), + dctx->cctx->loglevel); + break; + + default: + toks_dprintf(STDERR_FILENO, + "%s: the TOKS_IOCTL_SET_LOG_LEVEL " + "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_GET) { status = toks_client_query_service(dctx,&svcinfo); ret = status ? 2 : 0; diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index fd3cf61..2b6d0ef 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -658,6 +658,23 @@ int toks_get_driver_ctx( cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; cctx.drvflags |= TOKS_DRIVER_ACTION_SVCINFO_LOG; break; + + case TAG_LOGLEVELGET: + cctx.drvflags &= ~(uint64_t)TOKS_DRIVER_MODE_SERVER; + cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; + cctx.drvflags |= TOKS_DRIVER_ACTION_LOGLEVEL_GET; + break; + + case TAG_LOGLEVELSET: + cctx.drvflags &= ~(uint64_t)TOKS_DRIVER_MODE_SERVER; + cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; + cctx.drvflags |= TOKS_DRIVER_ACTION_LOGLEVEL_SET; + + loglevel = toks_arg_to_int32(entry); + loglevel = (loglevel > 9) ? (-1) : loglevel; + cctx.loglevel = loglevel; + + break; } } else /* strict */ @@ -966,6 +983,28 @@ int toks_get_driver_ctx( return toks_get_driver_ctx_fail(meta); } } + + if (cctx.drvflags & TOKS_DRIVER_ACTION_LOGLEVEL_GET) { + status = toks_service_ioctl( + &ctx->ctx,TOKS_IOCTL_GET_LOG_LEVEL, + &opdata,0); + + switch (status) { + case NT_STATUS_SUCCESS: + ctx->cctx.loglevel = opdata; + break; + + default: + if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) + toks_dprintf(STDERR_FILENO, + "%s: error: could not obtain the server's " + "current log-level parameter " + "(check the system's documentation) [0x%x].", + program,status); + + return toks_get_driver_ctx_fail(meta); + } + } } *pctx = &ctx->ctx; diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index 2503eca..5e85ad3 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_LOGLEVELGET, + TAG_LOGLEVELSET, TAG_GETSVCINFO, TAG_LOGSVCINFO, }; diff --git a/src/skin/toks_skin_default.c b/src/skin/toks_skin_default.c index 86af40b..b563b14 100644 --- a/src/skin/toks_skin_default.c +++ b/src/skin/toks_skin_default.c @@ -93,5 +93,14 @@ const struct argv_option toks_default_options[] = { "connect to the server and request that the current " "service information be sent to its log"}, + {"get-log-level", 'g',TAG_LOGLEVELGET,ARGV_OPTARG_NONE,0,0,0, + "connect to the server and output the service's " + "current log level"}, + + {"set-log-level", 'G',TAG_LOGLEVELSET,ARGV_OPTARG_REQUIRED,0,0,"", + "connect to the server and request that the service's " + "log-level be set to %s in the range of 0..9"}, + + {0,0,0,0,0,0,0,0} };