diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index 228ed180ab8..21799619751 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -446,7 +446,7 @@ static void NotifyWatchdog() * @param closeConsoleLog Whether to close the console log after config loading * @param stderrFile Where to log errors * - * @return The worker's PID on success, -1 on failure (if the worker couldn't load its config) + * @return The worker's PID on success, -1 on fork(2) failure, -2 if the worker couldn't load its config */ static pid_t StartUnixWorker(const std::vector& configs, bool closeConsoleLog = false, const String& stderrFile = String()) { @@ -472,7 +472,17 @@ static pid_t StartUnixWorker(const std::vector& configs, bool close case -1: Log(LogCritical, "cli") << "fork() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; - exit(EXIT_FAILURE); + + try { + Application::InitializeBase(); + } catch (const std::exception& ex) { + Log(LogCritical, "cli") + << "Failed to re-initialize thread pool after forking (parent): " << DiagnosticInformation(ex); + exit(EXIT_FAILURE); + } + + (void)sigprocmask(SIG_UNBLOCK, &l_UnixWorkerSignals, nullptr); + return -1; case 0: try { @@ -550,7 +560,7 @@ static pid_t StartUnixWorker(const std::vector& configs, bool close NotifyWatchdog(); #endif /* HAVE_SYSTEMD */ } - pid = -1; + pid = -2; break; default: Utility::Sleep(0.2); @@ -710,7 +720,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector