diff options
author | Ben Pfaff <blp@nicira.com> | 2010-01-19 15:00:56 -0800 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2010-01-26 10:52:46 -0800 |
commit | 40f0707cd9d105203c2b8b97a955b57aca426f13 (patch) | |
tree | fe1150b1cdd4ee8dbfabc3ce37ed2bceced12ac9 /lib/daemon.c | |
parent | 7c6a5f146742506a7a15cceface63ec3ba1e3076 (diff) | |
download | openvswitch-40f0707cd9d105203c2b8b97a955b57aca426f13.tar.gz |
daemon: Make --monitor process change its process title.
When --monitor is used, administrators sometimes become confused about the
presence of two copies of each process. This commit attempts to clarify
the situation by making the monitoring process change its process name, as
seen in /proc/$pid/cmdline and in "ps", to clearly indicate what is going
on.
CC: Dan Wendlandt <dan@nicira.com>
Diffstat (limited to 'lib/daemon.c')
-rw-r--r-- | lib/daemon.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/daemon.c b/lib/daemon.c index 862911463..140e0f725 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -22,6 +22,7 @@ #include <string.h> #include <sys/wait.h> #include <unistd.h> +#include "command-line.h" #include "fatal-signal.h" #include "dirs.h" #include "lockfile.h" @@ -325,13 +326,19 @@ monitor_daemon(pid_t daemon_pid) /* XXX Should limit the rate at which we restart the daemon. */ /* XXX Should log daemon's stderr output at startup time. */ const char *saved_program_name; + char *status_msg; saved_program_name = program_name; program_name = xasprintf("monitor(%s)", program_name); + status_msg = xstrdup("healthy"); for (;;) { int retval; int status; + proctitle_set("%s: monitoring pid %lu (%s)", + saved_program_name, (unsigned long int) daemon_pid, + status_msg); + do { retval = waitpid(daemon_pid, &status, 0); } while (retval == -1 && errno == EINTR); @@ -339,25 +346,27 @@ monitor_daemon(pid_t daemon_pid) if (retval == -1) { ovs_fatal(errno, "waitpid failed"); } else if (retval == daemon_pid) { - char *status_msg = process_status_msg(status); - if (should_restart(status)) { - VLOG_ERR("%s daemon died unexpectedly (%s), restarting", - saved_program_name, status_msg); - free(status_msg); + char *s = process_status_msg(status); + free(status_msg); + status_msg = xasprintf("pid %lu died, %s", + (unsigned long int) daemon_pid, s); + free(s); + if (should_restart(status)) { + VLOG_ERR("%s, restarting", status_msg); daemon_pid = fork_and_wait_for_startup(&daemonize_fd); if (!daemon_pid) { break; } } else { - VLOG_INFO("%s daemon exited normally (%s), exiting", - saved_program_name, status_msg); + VLOG_INFO("%s, exiting", status_msg); exit(0); } } } /* Running in new daemon process. */ + proctitle_restore(); free((char *) program_name); program_name = saved_program_name; } |