From ed52e59444681a51465ed0f2856202c1dac470d7 Mon Sep 17 00:00:00 2001 From: midipix Date: Jun 18 2020 21:07:44 +0000 Subject: driver: added --log-file support. --- diff --git a/include/toksvc/toksvc.h b/include/toksvc/toksvc.h index 2cfcd67..25f336d 100644 --- a/include/toksvc/toksvc.h +++ b/include/toksvc/toksvc.h @@ -111,6 +111,7 @@ struct toks_common_ctx { const nt_guid * uuid; void * hroot; const char * sysroot; + const char * logfile; char ** eargv; }; diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index 293264a..3fe0043 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -290,6 +290,7 @@ int toks_get_driver_ctx( int32_t ctrlpid; int32_t csyspid; int64_t timeout; + void * hlog; void * hkernel32; char * targv[TOKS_SARGV_ELEMENTS]; @@ -315,6 +316,7 @@ int toks_get_driver_ctx( if (!(flags & TOKS_DRIVER_MODE_CLIENT)) flags |= TOKS_DRIVER_MODE_SERVER; + hlog = 0; uuid = 0; tokpid = 0; tsyspid = 0; @@ -422,6 +424,10 @@ int toks_get_driver_ctx( &key.token,entry->arg, keylen); break; + + case TAG_LOGFILE: + cctx.logfile = entry->arg; + break; } } else /* strict */ @@ -498,6 +504,24 @@ int toks_get_driver_ctx( if (!(ctx = toks_driver_ctx_alloc(meta,&cctx))) return toks_get_driver_ctx_fail(meta); + if (ctx->rtdata->hroot && cctx.hroot) { + ntapi->zw_close(ctx->rtdata->hroot); + ctx->rtdata->hroot = cctx.hroot; + } + + if (cctx.logfile && toks_open_log_file(&hlog,ctx->rtdata->hroot,cctx.logfile,false)) { + if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) + toks_dprintf(STDERR_FILENO, + "%s: error: could not create logfile '%s'", + program,cctx.logfile); + return toks_get_driver_ctx_fail(meta); + } + + if (ctx->rtdata->hlog && cctx.logfile) { + ntapi->zw_close(ctx->rtdata->hlog); + ctx->rtdata->hlog = hlog; + } + if ((cctx.drvflags & TOKS_DRIVER_ACTION_RELEASE)) { if (toks_client_str_to_token(&ctx->ctx,&key)) { if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) @@ -536,6 +560,8 @@ int toks_get_driver_ctx( &(nt_filetime){{0,0}}, &ctx->ticks.pcfreq); + + ctx->hlog = hlog; ctx->tokpid = tokpid; ctx->tsyspid = tsyspid; ctx->ctrlpid = ctrlpid; @@ -546,6 +572,9 @@ int toks_get_driver_ctx( ctx->ctx.cctx = &ctx->cctx; ctx->cctx.uuid = &ctx->uuid; + ctx->rtdata->hroot = cctx.hroot; + ctx->rtdata->hlog = hlog; + toks_set_driver_refstr(&ctx->ctx,refstr); if (cctx.drvflags & TOKS_DRIVER_MODE_SERVER) { @@ -651,6 +680,9 @@ static void toks_free_driver_ctx_impl(struct toks_driver_ctx_alloc * ictx) if (ictx->ctx.hserver) ntapi->zw_close(ictx->ctx.hserver); + if (ictx->ctx.hlog) + ntapi->zw_close(ictx->ctx.hlog); + if (ictx->ctx.tokens) toks_free(ictx->ctx.tokens); diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index 2c3a6c2..6d37294 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -41,6 +41,7 @@ enum app_tags { TAG_SYSPID, TAG_CTRLPID, TAG_CSYSPID, + TAG_LOGFILE, }; struct toks_ticks { @@ -64,6 +65,7 @@ struct toks_driver_ctx_impl { void * hsvclink; void * hservice; void * hserver; + void * hlog; int nwaiters; int ntokens; int tokpid; diff --git a/src/skin/toks_skin_default.c b/src/skin/toks_skin_default.c index a57ef22..cf00237 100644 --- a/src/skin/toks_skin_default.c +++ b/src/skin/toks_skin_default.c @@ -64,5 +64,11 @@ const struct argv_option toks_default_options[] = { "set the service's controlling process to the " "system process identified by %s"}, + {"log-file", 'o',TAG_LOGFILE,ARGV_OPTARG_REQUIRED,0,0,"", + "set the log file to %s, which may be in root-relative " + "format (/path/to/log, native shell format " + "(x:/path/to/log), or native driver format " + "(e.g. \\Device\\HarddiskX\\path\\to\\log"}, + {0,0,0,0,0,0,0,0} };