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 3316004d188bd30ee8639300a8b951f4fd4318db..782d8868a060eb634a144134e72a34ca2fea6fb7 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 41f4952f1e54e104dbfab634d41039cb94e6560a..8971ff6d2401d0a44ace883ded1627b1b8932c74 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 d56a99042e3a28634336b9bb2088a98d6e9c7cdc..3c4d838bb8ee8b0f3a94a848b7373fd8e7b4b1bd 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 b3ad3770bdbeb77e6ee299a92a1c305678903e08..8fe9e06dcf7ed23120d10c2492110ec569f3170b 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 ebb8b1b29e44b1b797a4e003344350a103f462c2..d11ecdcdbfc88224a43e788de9967c9987123d9f 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 39909675f6d30d4ec39ec732491f57f400c8257e..f8487c064c03e8a9b7e8115552d0af738323c51c 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 *);