]> granicus.if.org Git - icinga2/commitdiff
fixup set rlimit stack failed condition
authorlihan <tclh123@gmail.com>
Tue, 27 Feb 2018 04:56:36 +0000 (12:56 +0800)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 19 Apr 2018 09:35:05 +0000 (11:35 +0200)
refs #6119
refs #6215

lib/base/application.cpp

index 70b2c40e9b591c8270cc142646d970c5da2618dc..b6e09bfce7fd0c470c50287e87bf676f872f8455 100644 (file)
@@ -256,32 +256,33 @@ void Application::SetResourceLimits(void)
                else
                        rl.rlim_cur = rl.rlim_max;
 
-               if (setrlimit(RLIMIT_STACK, &rl) < 0)
+               if (setrlimit(RLIMIT_STACK, &rl) < 0) {
                        Log(LogNotice, "Application", "Could not adjust resource limit for stack size (RLIMIT_STACK)");
-               else if (set_stack_rlimit) {
-                       char **new_argv = static_cast<char **>(malloc(sizeof(char *) * (argc + 2)));
+                       if (set_stack_rlimit) {
+                               char **new_argv = static_cast<char **>(malloc(sizeof(char *) * (argc + 2)));
 
-                       if (!new_argv) {
-                               perror("malloc");
-                               Exit(EXIT_FAILURE);
-                       }
+                               if (!new_argv) {
+                                       perror("malloc");
+                                       Exit(EXIT_FAILURE);
+                               }
 
-                       new_argv[0] = argv[0];
-                       new_argv[1] = strdup("--no-stack-rlimit");
+                               new_argv[0] = argv[0];
+                               new_argv[1] = strdup("--no-stack-rlimit");
 
-                       if (!new_argv[1]) {
-                               perror("strdup");
-                               exit(1);
-                       }
+                               if (!new_argv[1]) {
+                                       perror("strdup");
+                                       exit(1);
+                               }
 
-                       for (int i = 1; i < argc; i++)
-                               new_argv[i + 1] = argv[i];
+                               for (int i = 1; i < argc; i++)
+                                       new_argv[i + 1] = argv[i];
 
-                       new_argv[argc + 1] = NULL;
+                               new_argv[argc + 1] = NULL;
 
-                       (void) execvp(new_argv[0], new_argv);
-                       perror("execvp");
-                       _exit(EXIT_FAILURE);
+                               (void) execvp(new_argv[0], new_argv);
+                               perror("execvp");
+                               _exit(EXIT_FAILURE);
+                       }
                }
 #      else /* RLIMIT_STACK */
                Log(LogNotice, "Application", "System does not support adjusting the resource limit for stack size (RLIMIT_STACK)");