ctdb-cluster-mutex: Don't call the supplied hander more than once
authorMartin Schwenke <martin@meltin.net>
Wed, 1 Jun 2016 08:46:41 +0000 (18:46 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 7 Jun 2016 22:51:28 +0000 (00:51 +0200)
After the first activity on the file descriptor, ignore any subsequent
activity.  Single-shot handlers are easier to write.

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

index 12950c443d03598785dce63c934d9daf14b3fe51..8e9d1793c8414d4f2a2db2ecfa0ca7d7111c4426 100644 (file)
@@ -45,6 +45,7 @@ struct ctdb_cluster_mutex_handle {
        struct tevent_fd *fde;
        pid_t child;
        struct timeval start_time;
+       bool have_response;
 };
 
 void ctdb_cluster_mutex_set_handler(struct ctdb_cluster_mutex_handle *h,
@@ -98,6 +99,13 @@ static void cluster_mutex_handler(struct tevent_context *ev,
 
        ret = sys_read(h->fd[0], &c, 1);
 
+       /* Don't call the handler more than once.  It only exists to
+        * process the initial response from the helper. */
+       if (h->have_response) {
+               return;
+       }
+       h->have_response = true;
+
        /* If the child wrote status then just pass it to the handler.
         * If no status was written then this is an unexpected error
         * so pass generic error code to handler. */
@@ -193,6 +201,7 @@ ctdb_cluster_mutex(struct ctdb_context *ctdb,
        h->start_time = timeval_current();
        h->fd[0] = -1;
        h->fd[1] = -1;
+       h->have_response = false;
 
        ret = pipe(h->fd);
        if (ret != 0) {