Skip to content

Instantly share code, notes, and snippets.

@zsol
Created October 8, 2014 09:34
Show Gist options
  • Save zsol/00d5bb59b12d48406810 to your computer and use it in GitHub Desktop.
Save zsol/00d5bb59b12d48406810 to your computer and use it in GitHub Desktop.
diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp
index 8ecfe56..4ec014f 100644
--- a/icinga-app/icinga.cpp
+++ b/icinga-app/icinga.cpp
@@ -210,8 +210,8 @@ static bool SetDaemonIO(const String& stderrFile)
if (fdnull != 0)
dup2(fdnull, 0);
- if (fdnull != 1)
- dup2(fdnull, 1);
+ // if (fdnull != 1)
+ // dup2(fdnull, 1);
if (fdnull > 1)
close(fdnull);
@@ -514,7 +514,11 @@ int Main(void)
ScriptVariable::Set("UseVfork", true, false, true);
Application::MakeVariablesConstant();
-
+ std::ostringstream oss;
+ oss << "/var/log/icinga2/zsol." << static_cast<int>(getpid()) << "log";
+ int logfd = open(oss.str().c_str(), O_CREAT | O_WRONLY | O_APPEND, 0600);
+ if (logfd > 0)
+ dup2(logfd, 1);
Log(LogInformation, "icinga-app", "Icinga application loader (version: " + Application::GetVersion() + ")");
String appType = LoadAppType(Application::GetApplicationType());
@@ -549,6 +553,16 @@ int Main(void)
return EXIT_SUCCESS;
}
+ String errorLog;
+ if (g_AppParams.count("errorlog")) {
+ errorLog = g_AppParams["errorlog"].as<std::string>();
+ SetDaemonIO(errorLog);
+ }
+
+ if (g_AppParams.count("daemonize")) {
+ Logger::DisableConsoleLog();
+ }
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment