Log warning when sysconfig file cannot be read

refs #6215
This commit is contained in:
Michael Friedrich 2018-04-19 09:54:29 +02:00
parent 8b0126411b
commit e6f214fa29
2 changed files with 11 additions and 0 deletions

View File

@ -155,6 +155,13 @@ static int Main()
Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d");
#ifndef _WIN32
if (!Utility::PathExists(Application::GetSysconfigFile())) {
Log(LogWarning, "icinga-app")
<< "Sysconfig file '" << Application::GetSysconfigFile() << "' cannot be read. Using default values.";
}
#endif /* _WIN32 */
String icingaUser = Utility::GetFromSysconfig("ICINGA2_USER");
if (icingaUser.IsEmpty())
icingaUser = ICINGA_USER;
@ -456,6 +463,7 @@ static int Main()
std::cout << visibleDesc << std::endl
<< "Report bugs at <https://github.com/Icinga/icinga2>" << std::endl
<< "Get support: <https://www.icinga.com/support/>" << std::endl
<< "Icinga home page: <https://www.icinga.com/>" << std::endl;
return EXIT_SUCCESS;
}

View File

@ -1943,6 +1943,9 @@ String Utility::GetFromSysconfig(const String& env)
if (sysconf.IsEmpty())
return "";
if (!Utility::PathExists(sysconf))
return "";
String cmdInner = ". " + EscapeShellArg(sysconf) + " 2>&1 >/dev/null;echo \"$" + env + "\"";
String cmd = "sh -c " + EscapeShellArg(cmdInner);