ctdb-recoverd: Release recovery lock on exit
authorMartin Schwenke <martin@meltin.net>
Wed, 1 Jun 2016 23:26:40 +0000 (09:26 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 7 Jun 2016 22:51:29 +0000 (00:51 +0200)
The recovery lock helper must exit when it notices its parent is gone.
However, that can take a few seconds.

The usual way of terminating the recovery daemon is for the main ctdbd
to send it a SIGTERM.  Installing a handler is nice and simple.

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

index 1becc53f324c458d25738b0a138437caff9d4416..b55f8b0d1f632488f7f8f640190eae27ddd796b2 100644 (file)
@@ -3817,11 +3817,25 @@ takeover_run_checks:
        }
 }
 
+static void recd_sig_term_handler(struct tevent_context *ev,
+                                 struct tevent_signal *se, int signum,
+                                 int count, void *dont_care,
+                                 void *private_data)
+{
+       struct ctdb_recoverd *rec = talloc_get_type_abort(
+               private_data, struct ctdb_recoverd);
+
+       ctdb_recovery_unlock(rec);
+       exit(0);
+}
+
+
 /*
   the main monitoring loop
  */
 static void monitor_cluster(struct ctdb_context *ctdb)
 {
+       struct tevent_signal *se;
        struct ctdb_recoverd *rec;
 
        DEBUG(DEBUG_NOTICE,("monitor_cluster starting\n"));
@@ -3842,6 +3856,13 @@ static void monitor_cluster(struct ctdb_context *ctdb)
        rec->priority_time = timeval_current();
        rec->frozen_on_inactive = false;
 
+       se = tevent_add_signal(ctdb->ev, ctdb, SIGTERM, 0,
+                              recd_sig_term_handler, rec);
+       if (se == NULL) {
+               DEBUG(DEBUG_ERR, ("Failed to install SIGTERM handler\n"));
+               exit(1);
+       }
+
        /* register a message port for sending memory dumps */
        ctdb_client_set_message_handler(ctdb, CTDB_SRVID_MEM_DUMP, mem_dump_handler, rec);