* Do the actual work (config loading, ...)
*
* @param configs Files to read config from
+ * @param closeConsoleLog Whether to close the console log after config loading
+ * @param stderrFile Where to log errors
*
* @return Exit code
*/
static inline
-int RunWorker(const std::vector<std::string>& configs)
+int RunWorker(const std::vector<std::string>& configs, bool closeConsoleLog = false, const String& stderrFile = String())
{
Log(LogInformation, "cli", "Loading configuration file(s).");
Log(LogNotice, "cli")
<< "Waiting for the umbrella process to let us doing the actual work";
+ if (closeConsoleLog) {
+ CloseStdIO(stderrFile);
+ Logger::DisableConsoleLog();
+ }
+
while (!l_AllowedToWork.load()) {
Utility::Sleep(0.2);
}
* Starts seemless worker process doing the actual work (config loading, ...)
*
* @param configs Files to read config from
+ * @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)
*/
-static pid_t StartUnixWorker(const std::vector<std::string>& configs)
+static pid_t StartUnixWorker(const std::vector<std::string>& configs, bool closeConsoleLog = false, const String& stderrFile = String())
{
Log(LogNotice, "cli")
<< "Spawning seemless worker process doing the actual work";
_exit(EXIT_FAILURE);
}
- _exit(RunWorker(configs));
+ _exit(RunWorker(configs, closeConsoleLog, stderrFile));
} catch (...) {
_exit(EXIT_FAILURE);
}
});
#endif /* _WIN32 */
- if (vm.count("daemonize") || vm.count("close-stdio")) {
+ if (vm.count("daemonize")) {
// After disabling the console log, any further errors will go to the configured log only.
// Let's try to make this clear and say good bye.
Log(LogInformation, "cli", "Closing console log.");
(void)sigaction(SIGHUP, &sa, nullptr);
}
+ bool closeConsoleLog = !vm.count("daemonize") && vm.count("close-stdio");
+
+ String errorLog;
+ if (vm.count("errorlog"))
+ errorLog = vm["errorlog"].as<std::string>();
+
// The PID of the current seemless worker
- pid_t currentWorker = StartUnixWorker(configs);
+ pid_t currentWorker = StartUnixWorker(configs, closeConsoleLog, errorLog);
if (currentWorker == -1) {
return EXIT_FAILURE;
}
+ if (closeConsoleLog) {
+ // After disabling the console log, any further errors will go to the configured log only.
+ // Let's try to make this clear and say good bye.
+ Log(LogInformation, "cli", "Closing console log.");
+
+ CloseStdIO(errorLog);
+ Logger::DisableConsoleLog();
+ }
+
// Immediately allow the first (non-reload) worker to continue working beyond config validation
(void)kill(currentWorker, SIGUSR2);