]> granicus.if.org Git - icinga2/commitdiff
Fix stack rlimit problem
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 21 Jul 2014 11:33:01 +0000 (13:33 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 21 Jul 2014 11:33:01 +0000 (13:33 +0200)
fixes #6450

lib/base/application.cpp

index e62a1a6e1f2d8004f93163e5f9567c26e1a3bde2..0d47989a71699a14657119d32f7a4a78a09ba206 100644 (file)
@@ -182,37 +182,42 @@ void Application::SetResourceLimits(void)
                }
        }
 
-       if (set_stack_rlimit) {
-               rl.rlim_cur = 1024 * 1024;
-               rl.rlim_max = rl.rlim_cur;
-
-               if (setrlimit(RLIMIT_STACK, &rl) < 0)
-                       Log(LogNotice, "Application", "Could not adjust resource limit for stack size (RLIMIT_STACK)");
-               else {
-                       char **new_argv = static_cast<char **>(malloc(sizeof(char *) * (argc + 2)));
-
-                       if (!new_argv) {
-                               perror("malloc");
-                               exit(1);
-                       }
+       if (getrlimit(RLIMIT_STACK, &rl) < 0) {
+               Log(LogWarning, "Application", "Could not determine resource limit for stack size (RLIMIT_STACK)");
+               rl.rlim_max = RLIM_INFINITY;
+       }
 
-                       for (int i = 0; i < argc; i++)
-                               new_argv[i] = argv[i];
+       if (set_stack_rlimit)
+               rl.rlim_cur = 256 * 1024;
+       else
+               rl.rlim_cur = rl.rlim_max;
 
-                       new_argv[argc] = strdup("--no-stack-rlimit");
+       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 (!new_argv[argc]) {
-                               perror("strdup");
-                               exit(1);
-                       }
+               if (!new_argv) {
+                       perror("malloc");
+                       exit(1);
+               }
 
-                       new_argv[argc + 1] = NULL;
+               for (int i = 0; i < argc; i++)
+                       new_argv[i] = argv[i];
 
-                       if (execvp(new_argv[0], new_argv) < 0)
-                               perror("execvp");
+               new_argv[argc] = strdup("--no-stack-rlimit");
 
+               if (!new_argv[argc]) {
+                       perror("strdup");
                        exit(1);
                }
+
+               new_argv[argc + 1] = NULL;
+
+               if (execvp(new_argv[0], new_argv) < 0)
+                       perror("execvp");
+
+               exit(1);
        }
 #      else /* RLIMIT_STACK */
        Log(LogNotice, "Application", "System does not support adjusting the resource limit for stack size (RLIMIT_STACK)");