]> granicus.if.org Git - icinga2/commitdiff
Don't log when running autocomplete 6328/head
authorJean Flach <jean-marcel.flach@icinga.com>
Wed, 23 May 2018 12:23:48 +0000 (14:23 +0200)
committerJean Flach <jean-marcel.flach@icinga.com>
Wed, 23 May 2018 13:18:53 +0000 (15:18 +0200)
Logging breaks autocomplete, with this patch we should only log when
something is going terribly wrong and execution can't be guaranteed or
is destined to fail.
This commit depends on the previous one which is why it's not in its own
pull request.

fixes #6256

icinga-app/icinga.cpp

index 44d7ab1320beec2030ca73fad499842f0d53cfa7..0e462307c56ca757e0277996edcfdeb049a1ef98 100644 (file)
@@ -156,7 +156,7 @@ static int Main()
        Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d");
 
 #ifndef _WIN32
-       if (!Utility::PathExists(Application::GetSysconfigFile())) {
+       if (!autocomplete && !Utility::PathExists(Application::GetSysconfigFile())) {
                Log(LogWarning, "icinga-app")
                        << "Sysconfig file '" << Application::GetSysconfigFile() << "' cannot be read. Using default values.";
        }
@@ -173,50 +173,52 @@ static int Main()
        Application::DeclareRunAsUser(icingaUser);
        Application::DeclareRunAsGroup(icingaGroup);
 
+       if (!autocomplete) {
 #ifdef RLIMIT_NOFILE
-       String rLimitFiles = Utility::GetFromEnvironment("ICINGA2_RLIMIT_FILES");
-       if (rLimitFiles.IsEmpty())
-               Application::DeclareRLimitFiles(Application::GetDefaultRLimitFiles());
-       else {
-               try {
-                       Application::DeclareRLimitFiles(Convert::ToLong(rLimitFiles));
-               } catch (const std::invalid_argument& ex) {
-                       std::cout
-                               << "Error setting \"ICINGA2_RLIMIT_FILES\": " << ex.what() << '\n';
-                       return EXIT_FAILURE;
+               String rLimitFiles = Utility::GetFromEnvironment("ICINGA2_RLIMIT_FILES");
+               if (rLimitFiles.IsEmpty())
+                       Application::DeclareRLimitFiles(Application::GetDefaultRLimitFiles());
+               else {
+                       try {
+                               Application::DeclareRLimitFiles(Convert::ToLong(rLimitFiles));
+                       } catch (const std::invalid_argument& ex) {
+                               std::cout
+                                       << "Error setting \"ICINGA2_RLIMIT_FILES\": " << ex.what() << '\n';
+                               return EXIT_FAILURE;
+                       }
                }
-       }
 #endif /* RLIMIT_NOFILE */
 
 #ifdef RLIMIT_NPROC
-       String rLimitProcesses = Utility::GetFromEnvironment("ICINGA2_RLIMIT_PROCESSES");
-       if (rLimitProcesses.IsEmpty())
-               Application::DeclareRLimitProcesses(Application::GetDefaultRLimitProcesses());
-       else {
-               try {
-                       Application::DeclareRLimitProcesses(Convert::ToLong(rLimitProcesses));
-               } catch (const std::invalid_argument& ex) {
-                       std::cout
-                               << "Error setting \"ICINGA2_RLIMIT_PROCESSES\": " << ex.what() << '\n';
-                       return EXIT_FAILURE;
+               String rLimitProcesses = Utility::GetFromEnvironment("ICINGA2_RLIMIT_PROCESSES");
+               if (rLimitProcesses.IsEmpty())
+                       Application::DeclareRLimitProcesses(Application::GetDefaultRLimitProcesses());
+               else {
+                       try {
+                               Application::DeclareRLimitProcesses(Convert::ToLong(rLimitProcesses));
+                       } catch (const std::invalid_argument& ex) {
+                               std::cout
+                                       << "Error setting \"ICINGA2_RLIMIT_PROCESSES\": " << ex.what() << '\n';
+                               return EXIT_FAILURE;
+                       }
                }
-       }
 #endif /* RLIMIT_NPROC */
 
 #ifdef RLIMIT_STACK
-       String rLimitStack = Utility::GetFromEnvironment("ICINGA2_RLIMIT_STACK");
-       if (rLimitStack.IsEmpty())
-               Application::DeclareRLimitStack(Application::GetDefaultRLimitStack());
-       else {
-               try {
-                       Application::DeclareRLimitStack(Convert::ToLong(rLimitStack));
-               } catch (const std::invalid_argument& ex) {
-                       std::cout
-                               << "Error setting \"ICINGA2_RLIMIT_STACK\": " << ex.what() << '\n';
-                       return EXIT_FAILURE;
+               String rLimitStack = Utility::GetFromEnvironment("ICINGA2_RLIMIT_STACK");
+               if (rLimitStack.IsEmpty())
+                       Application::DeclareRLimitStack(Application::GetDefaultRLimitStack());
+               else {
+                       try {
+                               Application::DeclareRLimitStack(Convert::ToLong(rLimitStack));
+                       } catch (const std::invalid_argument& ex) {
+                               std::cout
+                                       << "Error setting \"ICINGA2_RLIMIT_STACK\": " << ex.what() << '\n';
+                               return EXIT_FAILURE;
+                       }
                }
-       }
 #endif /* RLIMIT_STACK */
+       }
 
        Application::DeclareConcurrency(std::thread::hardware_concurrency());
        Application::DeclareMaxConcurrentChecks(Application::GetDefaultMaxConcurrentChecks());