diff --git a/src/daemon/toks_daemon_loop.c b/src/daemon/toks_daemon_loop.c index 258806d..505c0b5 100644 --- a/src/daemon/toks_daemon_loop.c +++ b/src/daemon/toks_daemon_loop.c @@ -162,9 +162,11 @@ int32_t __stdcall toks_daemon_loop(void * ctx) int32_t opcode; int32_t status; + /* runtime data */ if (ntapi->tt_get_runtime_data(&rtdata,0)) return NT_STATUS_INTERNAL_ERROR; + /* daemon context and controlling (system) process */ dctx = (struct toks_daemon_ctx *)ctx; dctx->ctrlpid = toks_get_driver_ctrlpid(dctx->driver_ctx); @@ -180,6 +182,12 @@ int32_t __stdcall toks_daemon_loop(void * ctx) NT_CURRENT_PROCESS_HANDLE, status); + /* service synchronization */ + if (rtdata->hsync) { + ntapi->zw_set_event(rtdata->hsync,0); + ntapi->zw_close(rtdata->hsync); + } + /* init */ request = &dctx->request; reply = &dctx->reply; diff --git a/src/service/toks_service_start.c b/src/service/toks_service_start.c index 5a7825e..bc3bc96 100644 --- a/src/service/toks_service_start.c +++ b/src/service/toks_service_start.c @@ -47,6 +47,7 @@ static int toks_spawn_impl( char tokbuf[32]; char pidbuf[32]; char logbuf[32]; + void * hduo[2]; /* init */ self = toks_get_driver_rtdata(dctx); @@ -129,6 +130,13 @@ static int toks_spawn_impl( rtctx.stdout_type = NT_FILE_TYPE_UNKNOWN; rtctx.stderr_type = NT_FILE_TYPE_UNKNOWN; + /* service synchronization */ + if ((status = ntapi->tt_create_inheritable_event( + &rtctx.hsync, + NT_NOTIFICATION_EVENT, + NT_EVENT_NOT_SIGNALED))) + return status; + /* hoppla */ status = ntapi->tt_spawn_native_process(&sparams); @@ -142,6 +150,16 @@ static int toks_spawn_impl( if (!(sparams.eready.signal_state)) status = toks_spawn_child_exit_code(sparams.hprocess); + /* service synchronization */ + hduo[0] = sparams.hprocess; + hduo[1] = rtctx.hsync; + + ntapi->zw_wait_for_multiple_objects( + 2,hduo, + NT_WAIT_ANY, + NT_SYNC_NON_ALERTABLE, + 0); + /* finalize */ ntapi->zw_close(sparams.hprocess); ntapi->zw_close(sparams.hthread);