diff --git a/lib/arch/CArchAppUtilWindows.cpp b/lib/arch/CArchAppUtilWindows.cpp index 6dbd0ccd..a8268176 100644 --- a/lib/arch/CArchAppUtilWindows.cpp +++ b/lib/arch/CArchAppUtilWindows.cpp @@ -76,6 +76,10 @@ CArchAppUtilWindows::parseArg(const int& argc, const char* const* argv, int& i) } app().m_bye(kExitSuccess); } + else if (app().isArg(i, argc, argv, NULL, "--debug-service-wait")) { + + app().argsBase().m_debugServiceWait = true; + } else { // option not supported here return false; @@ -197,6 +201,20 @@ int CArchAppUtilWindows::daemonNTMainLoop(int argc, const char** argv) { app().parseArgs(argc, argv); + + if (app().argsBase().m_debugServiceWait) + { + while(true) + { + // this code is only executed when the process is launched via the + // windows service controller (and --debug-service-wait arg is + // used). to debug, set a breakpoint on this line so that + // execution is delayed until the debugger is attached. + ARCH->sleep(1); + LOG((CLOG_INFO "waiting for debugger to attach")); + } + } + app().argsBase().m_backend = false; app().loadConfig(); return CArchMiscWindows::runDaemon(mainLoopStatic); diff --git a/lib/synergy/CApp.cpp b/lib/synergy/CApp.cpp index e45ea274..84efbb40 100644 --- a/lib/synergy/CApp.cpp +++ b/lib/synergy/CApp.cpp @@ -48,6 +48,7 @@ CApp::~CApp() CApp::CArgsBase::CArgsBase() : #if SYSAPI_WIN32 m_daemon(false), // daemon mode not supported on windows (use --service) +m_debugServiceWait(false), #else m_daemon(true), // backward compatibility for unix (daemon by default) #endif diff --git a/lib/synergy/CApp.h b/lib/synergy/CApp.h index 31ff8b52..f7ccb1bd 100644 --- a/lib/synergy/CApp.h +++ b/lib/synergy/CApp.h @@ -39,6 +39,9 @@ public: const char* m_logFile; const char* m_display; CString m_name; +#if SYSAPI_WIN32 + bool m_debugServiceWait; +#endif }; CApp(CArgsBase* args);