daemon: Allow monitored daemon to dump core no more than once.
authorBen Pfaff <blp@nicira.com>
Tue, 11 May 2010 17:56:10 +0000 (10:56 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 13 May 2010 16:45:21 +0000 (09:45 -0700)
If the monitored daemon dumps core frequently, then this can quickly
exhaust the host's disk space.  This commit limits core dumps to at most
one per monitored session (typically, once per boot).

lib/daemon.c

index 081912b..292be14 100644 (file)
@@ -353,6 +353,18 @@ monitor_daemon(pid_t daemon_pid)
             free(s);
 
             if (should_restart(status)) {
+                if (WCOREDUMP(status)) {
+                    /* Disable further core dumps to save disk space. */
+                    struct rlimit r;
+
+                    r.rlim_cur = 0;
+                    r.rlim_max = 0;
+                    if (setrlimit(RLIMIT_CORE, &r) == -1) {
+                        VLOG_WARN("failed to disable core dumps: %s",
+                                  strerror(errno));
+                    }
+                }
+
                 VLOG_ERR("%s, restarting", status_msg);
                 daemon_pid = fork_and_wait_for_startup(&daemonize_fd);
                 if (!daemon_pid) {