multipathd: Add PID to 'show daemon' cli command
authorHannes Reinecke <hare@suse.de>
Wed, 18 May 2011 11:22:13 +0000 (13:22 +0200)
committerHannes Reinecke <hare@suse.de>
Wed, 18 May 2011 11:22:13 +0000 (13:22 +0200)
We might want to know the PID of the daemon itself.
So adding it to the 'show daemon' cli command.

Signed-off-by: Hannes Reinecke <hare@suse.de>
multipathd/cli_handlers.c
multipathd/main.c
multipathd/main.h

index 39ca6fe..31ca84a 100644 (file)
@@ -294,7 +294,8 @@ show_daemon (char ** r, int *len)
                return 1;
 
        c = reply;
-       c += snprintf(c, INITIAL_REPLY_LEN, "%s\n", daemon_status());
+       c += snprintf(c, INITIAL_REPLY_LEN, "pid %d %s\n",
+                     daemon_pid, daemon_status());
 
        *r = reply;
        *len = (int)(c - reply + 1);
index 082f851..bd54a25 100644 (file)
@@ -70,6 +70,7 @@ pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 int logsink;
 enum daemon_status running_state;
+pid_t daemon_pid;
 
 /*
  * global copy of vecs for use in sig handlers
@@ -1544,7 +1545,7 @@ child (void * param)
 
        pthread_mutex_lock(&exit_mutex);
        /* Startup complete, create logfile */
-       if (pidfile_create(DEFAULT_PIDFILE, getpid()))
+       if (pidfile_create(DEFAULT_PIDFILE, daemon_pid))
                /* Ignore errors, we can live without */
                condlog(1, "failed to create pidfile");
 
@@ -1636,6 +1637,7 @@ daemonize(void)
        else if (pid != 0)
                _exit(0);
 
+       daemon_pid = getpid();
        in_fd = open("/dev/null", O_RDONLY);
        if (in_fd < 0){
                fprintf(stderr, "cannot open /dev/null for input : %s\n",
index 87f24c7..c34eddb 100644 (file)
@@ -11,6 +11,8 @@ enum daemon_status {
     DAEMON_SHUTDOWN,
 };
 
+extern pid_t daemon_pid;
+
 int exit_daemon(int);
 const char * daemon_status(void);
 int reconfigure (struct vectors *);