From 37a3e7e4d5adb0b63b95368f311b71f223f67a3c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 15 Jul 2019 13:59:17 +0200 Subject: [PATCH] Application::RunEventLoop(): forward restart requests to umbrella process refs #5230 --- lib/base/application.cpp | 18 ++++++++++++++++++ lib/base/application.hpp | 8 ++++++++ lib/cli/daemoncommand.cpp | 1 + 3 files changed, 27 insertions(+) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 3e1408542..4d10ad027 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -27,6 +27,8 @@ #endif /* __linux__ */ #ifdef _WIN32 #include +#else /* _WIN32 */ +#include #endif /* _WIN32 */ #ifdef HAVE_SYSTEMD #include @@ -42,6 +44,11 @@ bool Application::m_ShuttingDown = false; bool Application::m_RequestRestart = false; bool Application::m_RequestReopenLogs = false; pid_t Application::m_ReloadProcess = 0; + +#ifndef _WIN32 +pid_t Application::m_UmbrellaProcess = 0; +#endif /* _WIN32 */ + static bool l_Restarting = false; static bool l_InExceptionHandler = false; int Application::m_ArgC; @@ -300,11 +307,15 @@ void Application::RunEventLoop() sd_notify(0, "RELOADING=1"); #endif /* HAVE_SYSTEMD */ +#ifdef _WIN32 // are we already restarting? ignore request if we already are if (!l_Restarting) { l_Restarting = true; m_ReloadProcess = StartReloadProcess(); } +#else /* _WIN32 */ + (void)kill(m_UmbrellaProcess, SIGHUP); +#endif /* _WIN32 */ } else { /* Watches for changes to the system time. Adjusts timers if necessary. */ Utility::Sleep(2.5); @@ -446,6 +457,13 @@ void Application::RequestReopenLogs() m_RequestReopenLogs = true; } +#ifndef _WIN32 +void Application::SetUmbrellaProcess(pid_t pid) +{ + m_UmbrellaProcess = pid; +} +#endif /* _WIN32 */ + /** * Retrieves the full path of the executable. * diff --git a/lib/base/application.hpp b/lib/base/application.hpp index ad7fd9606..de046daed 100644 --- a/lib/base/application.hpp +++ b/lib/base/application.hpp @@ -57,6 +57,10 @@ public: static void RequestRestart(); static void RequestReopenLogs(); +#ifndef _WIN32 + static void SetUmbrellaProcess(pid_t pid); +#endif /* _WIN32 */ + static bool IsShuttingDown(); static bool IsRestarting(); @@ -122,6 +126,10 @@ private: static pid_t m_ReloadProcess; /**< The PID of a subprocess doing a reload, only valid when l_Restarting==true */ static bool m_RequestReopenLogs; /**< Whether we should re-open log files. */ +#ifndef _WIN32 + static pid_t m_UmbrellaProcess; +#endif /* _WIN32 */ + static int m_ArgC; /**< The number of command-line arguments. */ static char **m_ArgV; /**< Command-line arguments. */ FILE *m_PidFile; /**< The PID file */ diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index dbc683649..7a95e2e7e 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -477,6 +477,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector