From adda6b2aaf2a5631d0dfa0371f8f93855176a9c8 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Mon, 25 Jul 2016 14:47:32 +0100 Subject: [PATCH] Allow waiting for debugger. If the service is started with the single argument "debug" eg by setting the Start parameters of the service in services.msc, we delayed startup in service_main() until the await_debugger variable is set to false. Attach to nssm.exe with your debugger of choice, set a breakpoint within that function and poke the variable when ready. Beware that the behaviour of the service manager when service_main doesn't complete operation promptly is undefined. --- service.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/service.cpp b/service.cpp index 849f790..88c1820 100644 --- a/service.cpp +++ b/service.cpp @@ -1503,6 +1503,9 @@ void WINAPI service_main(unsigned long argc, TCHAR **argv) { nssm_service_t *service = alloc_nssm_service(); if (! service) return; + static volatile bool await_debugger = (argc > 1 && str_equiv(argv[1], _T("debug"))); + while (await_debugger) Sleep(1000); + if (_sntprintf_s(service->name, _countof(service->name), _TRUNCATE, _T("%s"), argv[0]) < 0) { log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("service->name"), _T("service_main()"), 0); return; -- 2.7.4