diff --git a/src/apps/deskflow-daemon/deskflow-daemon.cpp b/src/apps/deskflow-daemon/deskflow-daemon.cpp index d73a60d88..b6f34008c 100644 --- a/src/apps/deskflow-daemon/deskflow-daemon.cpp +++ b/src/apps/deskflow-daemon/deskflow-daemon.cpp @@ -69,8 +69,10 @@ int main(int argc, char **argv) daemon.moveToThread(&daemonThread); QObject::connect(&daemonThread, &QThread::started, [&daemon, &daemonThread]() { + LOG_DEBUG("daemon thread started"); daemon.run(); daemonThread.quit(); + LOG_DEBUG("daemon thread finished"); }); QObject::connect(&daemonThread, &QThread::finished, &app, &QCoreApplication::quit); diff --git a/src/lib/arch/win32/ArchDaemonWindows.cpp b/src/lib/arch/win32/ArchDaemonWindows.cpp index f7bed713b..733d36735 100644 --- a/src/lib/arch/win32/ArchDaemonWindows.cpp +++ b/src/lib/arch/win32/ArchDaemonWindows.cpp @@ -6,6 +6,7 @@ */ #include "arch/win32/ArchDaemonWindows.h" + #include "arch/Arch.h" #include "arch/win32/ArchMiscWindows.h" #include "arch/win32/XArchWindows.h" @@ -59,6 +60,8 @@ void ArchDaemonWindows::installDaemon( const char *name, const char *description, const char *pathname, const char *commandLine, const char *dependencies ) { + LOG_DEBUG("installing windows service: %s", name); + // open service manager SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_WRITE); if (mgr == NULL) { @@ -125,6 +128,8 @@ void ArchDaemonWindows::installDaemon( void ArchDaemonWindows::uninstallDaemon(const char *name) { + LOG_DEBUG("uninstalling windows service: %s", name); + // remove parameters for this service. ignore failures. HKEY key = openNTServicesKey(); key = ArchMiscWindows::openKey(key, name); diff --git a/src/lib/deskflow/DaemonApp.cpp b/src/lib/deskflow/DaemonApp.cpp index 8b506177d..f8bf7aa37 100644 --- a/src/lib/deskflow/DaemonApp.cpp +++ b/src/lib/deskflow/DaemonApp.cpp @@ -80,17 +80,17 @@ DaemonApp::~DaemonApp() = default; void DaemonApp::run() { if (m_foreground) { - LOG_INFO("starting daemon in foreground"); + LOG_DEBUG("starting daemon in foreground"); // run process in foreground instead of daemonizing. // useful for debugging. mainLoop(m_foreground); } else { #if SYSAPI_WIN32 - LOG_INFO("daemonizing windows service"); + LOG_DEBUG("daemonizing windows service"); ARCH->daemonize(kAppName, winMainLoopStatic); #elif SYSAPI_UNIX - LOG_INFO("daemonizing unix service"); + LOG_DEBUG("daemonizing unix service"); ARCH->daemonize(kAppName, unixMainLoopStatic); #endif } @@ -253,9 +253,12 @@ void DaemonApp::mainLoop(bool foreground) m_watchdog->startAsync(); #endif + LOG_INFO("daemon is running"); m_events->loop(); + LOG_INFO("daemon is stopping"); #if SYSAPI_WIN32 + LOG_DEBUG("stopping process watchdog"); m_watchdog->stop(); #endif diff --git a/src/lib/platform/MSWindowsProcess.cpp b/src/lib/platform/MSWindowsProcess.cpp index e1e0ddc9a..bacdeca77 100644 --- a/src/lib/platform/MSWindowsProcess.cpp +++ b/src/lib/platform/MSWindowsProcess.cpp @@ -127,12 +127,16 @@ void MSWindowsProcess::shutdown(HANDLE handle, DWORD pid, int timeout) SetEvent(hCloseEvent); CloseHandle(hCloseEvent); } else { - LOG((CLOG_WARN "could not send close event to process")); + LOG_WARN("could not send close event to process"); throw XArch(new XArchEvalWindows); } DWORD exitCode; - GetExitCodeProcess(handle, &exitCode); + if (!GetExitCodeProcess(handle, &exitCode)) { + LOG_ERR("failed to get process exit code for process %d", pid); + throw XArch(new XArchEvalWindows); + } + if (exitCode != STILL_ACTIVE) { LOG_DEBUG("process %d is already shutdown", pid); return; diff --git a/src/lib/platform/MSWindowsWatchdog.cpp b/src/lib/platform/MSWindowsWatchdog.cpp index bb04e13d4..6277e8c10 100644 --- a/src/lib/platform/MSWindowsWatchdog.cpp +++ b/src/lib/platform/MSWindowsWatchdog.cpp @@ -93,10 +93,14 @@ void MSWindowsWatchdog::stop() { m_monitoring = false; - m_thread->wait(5); + if (!m_thread->wait(5)) { + LOG((CLOG_WARN "could not stop main thread")); + } delete m_thread; - m_outputThread->wait(5); + if (!m_outputThread->wait(5)) { + LOG((CLOG_WARN "could not stop output thread")); + } delete m_outputThread; } @@ -161,7 +165,7 @@ MSWindowsWatchdog::getUserToken(LPSECURITY_ATTRIBUTES security, bool elevatedTok void MSWindowsWatchdog::mainLoop(void *) { - LOG_DEBUG("starting main loop"); + LOG_DEBUG("starting watchdog main loop"); shutdownExistingProcesses(); @@ -277,7 +281,7 @@ void MSWindowsWatchdog::mainLoop(void *) m_processStarted = false; } - LOG((CLOG_DEBUG "watchdog main thread finished")); + LOG((CLOG_DEBUG "watchdog main loop finished")); } bool MSWindowsWatchdog::isProcessRunning() @@ -347,8 +351,10 @@ void MSWindowsWatchdog::startProcess() LOG((CLOG_ERR "exit code: %d", exitCode)); throw XArch(new XArchEvalWindows); } else { - // wait for program to fail. + // Wait for program to fail. This needs to be 1 second, as the process may take some time to fail. + LOG_DEBUG("waiting for process start result"); ARCH->sleep(1); + if (!isProcessRunning()) { m_process.reset(); throw XMSWindowsWatchdogError("process immediately stopped");