From a47da8246e3e3523c0152e67277fd6bc825e6b2b Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 1 Jun 2016 18:46:41 +1000 Subject: [PATCH] ctdb-cluster-mutex: Don't call the supplied hander more than once After the first activity on the file descriptor, ignore any subsequent activity. Single-shot handlers are easier to write. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/server/ctdb_cluster_mutex.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ctdb/server/ctdb_cluster_mutex.c b/ctdb/server/ctdb_cluster_mutex.c index 12950c443d0..8e9d1793c84 100644 --- a/ctdb/server/ctdb_cluster_mutex.c +++ b/ctdb/server/ctdb_cluster_mutex.c @@ -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) { -- 2.47.3