ctdb-tools: Wait for ctdb daemon to go away in shutdown
authorAmitay Isaacs <amitay@gmail.com>
Tue, 6 Mar 2018 03:28:43 +0000 (14:28 +1100)
committerMartin Schwenke <martins@samba.org>
Fri, 9 Mar 2018 06:08:23 +0000 (07:08 +0100)
This can only be done on the local node.  For remote node, exit as
soon as the control returns.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tools/ctdb.c

index 2cb46b057f00a790b85c9457b2299b615a821f11..8535c784c9388bd54ddbc58e45062a467055495e 100644 (file)
@@ -2833,15 +2833,29 @@ static int control_unban(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 
 }
 
+static void wait_for_shutdown(void *private_data)
+{
+       bool *done = (bool *)private_data;
+
+       *done = true;
+}
+
 static int control_shutdown(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                            int argc, const char **argv)
 {
        int ret;
+       bool done = false;
 
        if (argc != 0) {
                usage("shutdown");
        }
 
+       if (ctdb->pnn == ctdb->cmd_pnn) {
+               ctdb_client_set_disconnect_callback(ctdb->client,
+                                                   wait_for_shutdown,
+                                                   &done);
+       }
+
        ret = ctdb_ctrl_shutdown(mem_ctx, ctdb->ev, ctdb->client,
                                 ctdb->cmd_pnn, TIMEOUT());
        if (ret != 0) {
@@ -2849,6 +2863,10 @@ static int control_shutdown(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                return ret;
        }
 
+       if (ctdb->pnn == ctdb->cmd_pnn) {
+               ctdb_client_wait(ctdb->ev, &done);
+       }
+
        return 0;
 }