Add 'shutdown' cli command
authorHannes Reinecke <hare@suse.de>
Tue, 28 Apr 2009 09:11:23 +0000 (11:11 +0200)
committerHannes Reinecke <hare@suse.de>
Wed, 18 May 2011 09:02:17 +0000 (11:02 +0200)
Rather than sending a signal to the process (which might get caught
by any thread, possibly blocking it) we can as well implement a
'shutdown' cli command, making sure the daemon will be terminated.

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

index 3316004..782d886 100644 (file)
@@ -180,6 +180,7 @@ load_keys (void)
        r += add_key(keys, "wildcards", WILDCARDS, 0);
        r += add_key(keys, "quit", QUIT, 0);
        r += add_key(keys, "exit", QUIT, 0);
+       r += add_key(keys, "shutdown", SHUTDOWN, 0);
 
        if (r) {
                free_keys(keys);
@@ -445,6 +446,7 @@ cli_init (void) {
        add_handler(REINSTATE+PATH, NULL);
        add_handler(FAIL+PATH, NULL);
        add_handler(QUIT, NULL);
+       add_handler(SHUTDOWN, NULL);
 
        return 0;
 }
index 41f4952..8971ff6 100644 (file)
@@ -25,6 +25,7 @@ enum {
        __FMT,
        __WILDCARDS,
        __QUIT,
+       __SHUTDOWN,
 };
 
 #define LIST           (1 << __LIST)
@@ -49,11 +50,12 @@ enum {
 #define TOPOLOGY       (1 << __TOPOLOGY)
 #define CONFIG         (1 << __CONFIG)
 #define BLACKLIST      (1 << __BLACKLIST)
-#define DEVICES        (1 << __DEVICES)
-#define FMT            (1 << __FMT)
+#define DEVICES                (1 << __DEVICES)
+#define FMT            (1 << __FMT)
 #define COUNT          (1 << __COUNT)
 #define WILDCARDS      (1 << __WILDCARDS)
 #define QUIT           (1 << __QUIT)
+#define SHUTDOWN       (1 << __SHUTDOWN)
 
 #define INITIAL_REPLY_LEN 1000
 
index d56a990..3c4d838 100644 (file)
@@ -812,3 +812,11 @@ cli_quit (void * v, char ** reply, int * len, void * data)
 {
        return 0;
 }
+
+int
+cli_shutdown (void * v, char ** reply, int * len, void * data)
+{
+       condlog(3, "shutdown (operator)");
+
+       return exit_daemon(0);
+}
index b3ad377..8fe9e06 100644 (file)
@@ -27,3 +27,4 @@ int cli_resume(void * v, char ** reply, int * len, void * data);
 int cli_reinstate(void * v, char ** reply, int * len, void * data);
 int cli_fail(void * v, char ** reply, int * len, void * data);
 int cli_quit(void * v, char ** reply, int * len, void * data);
+int cli_shutdown(void * v, char ** reply, int * len, void * data);
index ebb8b1b..d11ecdc 100644 (file)
@@ -806,6 +806,7 @@ uxlsnrloop (void * ap)
        set_handler_callback(DISABLEQ+MAPS, cli_disable_all_queueing);
        set_handler_callback(RESTOREQ+MAPS, cli_restore_all_queueing);
        set_handler_callback(QUIT, cli_quit);
+       set_handler_callback(SHUTDOWN, cli_shutdown);
 
        umask(077);
        uxsock_listen(&uxsock_trigger, ap);
@@ -813,7 +814,7 @@ uxlsnrloop (void * ap)
        return NULL;
 }
 
-static int
+int
 exit_daemon (int status)
 {
        if (status != 0)
index 3990967..f8487c0 100644 (file)
@@ -3,6 +3,7 @@
 
 #define MAPGCINT 5
 
+int exit_daemon(int);
 int reconfigure (struct vectors *);
 int ev_add_path (char *, struct vectors *);
 int ev_remove_path (char *, struct vectors *);