diff --git a/src/daemon/toks_daemon_init.c b/src/daemon/toks_daemon_init.c index d500854..cc05f00 100644 --- a/src/daemon/toks_daemon_init.c +++ b/src/daemon/toks_daemon_init.c @@ -83,7 +83,6 @@ static int32_t toks_daemon_init_impl( dctx->driver_ctx, hsvclink); - /* todo: check driver flags or defer to driver */ return ntapi->tty_request_peer( htty, TOKS_DAEMON_TTYSIGNAL, @@ -98,11 +97,37 @@ int32_t __stdcall toks_daemon_init(struct toks_daemon_ctx * dctx, const nt_guid int32_t status; nt_timeout timeout; nt_runtime_data * rtdata; + nt_filetime pcnt; + nt_guid cliguid; + uint32_t * data; /* rtdata */ if ((status = ntapi->tt_get_runtime_data(&rtdata,0))) return status; + /* arbitrary client uuid */ + if (!svcguid) { + toks_query_performance_counters(dctx->driver_ctx,&pcnt); + + svcguid = &cliguid; + data = &cliguid.data1; + + data[0] = ntapi->tt_buffer_crc32( + (uint32_t)(uintptr_t)&cliguid, + &pcnt,sizeof(pcnt)); + + data[1] = ntapi->tt_buffer_crc32( + (uint32_t)(uintptr_t)rtdata, + rtdata,sizeof(*rtdata)); + + data[2] = ntapi->tt_buffer_crc32( + data[1],dctx,sizeof(*dctx)); + + data[3] = ntapi->tt_buffer_crc32( + data[2],dctx->driver_ctx, + sizeof(*dctx->driver_ctx)); + } + /* once */ switch (at_locked_cas_32(&toks_daemon_once,0,1)) { case 0: diff --git a/src/daemon/toks_daemon_loop.c b/src/daemon/toks_daemon_loop.c index 8054e06..d038982 100644 --- a/src/daemon/toks_daemon_loop.c +++ b/src/daemon/toks_daemon_loop.c @@ -27,9 +27,15 @@ static toks_daemon_routine * toks_daemon_vtbl[TOKS_VTBL_ELEMENTS] = { TOKS_HANDLER(ABORT, toks_daemon_abort), }; +static toks_daemon_routine * toks_client_vtbl[TOKS_VTBL_ELEMENTS] = { + TOKS_HANDLER(CONNECT, toks_daemon_connect), + TOKS_HANDLER(TTYSIGNAL, toks_daemon_signal), +}; + int32_t __stdcall toks_daemon_loop(void * ctx) { struct toks_daemon_ctx * dctx; + toks_daemon_routine ** svcvtbl; nt_rtdata * rtdata; nt_tty_port_msg * request; @@ -43,6 +49,10 @@ int32_t __stdcall toks_daemon_loop(void * ctx) dctx = (struct toks_daemon_ctx *)ctx; + svcvtbl = (dctx->driver_ctx->cctx->drvflags & TOKS_DRIVER_MODE_SERVER) + ? toks_daemon_vtbl + : toks_client_vtbl; + /* init */ request = &dctx->request; reply = &dctx->reply; @@ -58,7 +68,10 @@ int32_t __stdcall toks_daemon_loop(void * ctx) /* message loop */ do { - toks_log_lpc_request(dctx->driver_ctx,request); + if (svcvtbl == toks_daemon_vtbl) + toks_log_lpc_request( + dctx->driver_ctx, + request); switch (request->header.msg_type) { case NT_LPC_REQUEST: @@ -89,8 +102,8 @@ int32_t __stdcall toks_daemon_loop(void * ctx) reply->ttyinfo.exarg = (void *)request->header.client_id.process_id; opcode -= TOKS_DAEMON_OPCODE_BASE; - if (toks_daemon_vtbl[opcode]) - reply->ttyinfo.status = toks_daemon_vtbl[opcode](dctx); + if (svcvtbl[opcode]) + reply->ttyinfo.status = svcvtbl[opcode](dctx); else reply->ttyinfo.status = NT_STATUS_NOT_IMPLEMENTED; } else { diff --git a/src/driver/toks_amain.c b/src/driver/toks_amain.c index f989b3b..c179626 100644 --- a/src/driver/toks_amain.c +++ b/src/driver/toks_amain.c @@ -17,6 +17,7 @@ #ifndef TOKS_DRIVER_FLAGS #define TOKS_DRIVER_FLAGS TOKS_DRIVER_VERBOSITY_ERRORS \ + | TOKS_DRIVER_DAEMON_ALWAYS \ | TOKS_DRIVER_VERBOSITY_USAGE #endif diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index 9da2c37..098a426 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -440,6 +440,24 @@ int toks_get_driver_ctx( } if (cctx.drvflags & TOKS_DRIVER_MODE_CLIENT) { + if (cctx.drvflags & TOKS_DRIVER_DAEMON_ALWAYS) { + toks_daemon_ctx.driver_ctx = &ctx->ctx; + + switch ((status = toks_daemon_init(&toks_daemon_ctx,0))) { + case NT_STATUS_SUCCESS: + break; + + default: + if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) + toks_dprintf(STDERR_FILENO, + "%s: error: failed to initialize signal handling " + "(check the system's documentation) [0x%x].", + program,status); + + return toks_get_driver_ctx_fail(meta); + } + } + switch ((status = toks_client_connect(&ctx->ctx))) { case NT_STATUS_SUCCESS: break;