diff options
author | Martin Schwenke <martin@meltin.net> | 2019-06-27 14:13:50 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2019-07-26 03:34:17 +0000 |
commit | af8de1bcfd4cfb2b2517b5badcc9ab564276fb92 (patch) | |
tree | dbf82688b59e68176585bbff7686a6e960eea670 /ctdb/server | |
parent | fae8e438f019e7c1d20582f167b3adeac781ddbe (diff) | |
download | samba-af8de1bcfd4cfb2b2517b5badcc9ab564276fb92.tar.gz |
ctdb-mutex: Add an intermediate asynchronous computation for waiting
This will allow more conditions to be waited on via additional
sub-requests. At the moment this just completes when the parent wait
completes.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/server')
-rw-r--r-- | ctdb/server/ctdb_mutex_fcntl_helper.c | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/ctdb/server/ctdb_mutex_fcntl_helper.c b/ctdb/server/ctdb_mutex_fcntl_helper.c index 85095c64c71..bfd78565c6a 100644 --- a/ctdb/server/ctdb_mutex_fcntl_helper.c +++ b/ctdb/server/ctdb_mutex_fcntl_helper.c @@ -157,6 +157,63 @@ static bool wait_for_parent_recv(struct tevent_req *req) return true; } +/* + * Wait for a reason to exit, indicating that the lock is lost + */ + +struct wait_for_exit_state { +}; + +static void wait_for_exit_parent_done(struct tevent_req *subreq); + +static struct tevent_req *wait_for_exit_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + pid_t ppid) +{ + struct tevent_req *req, *subreq; + struct wait_for_exit_state *state; + + req = tevent_req_create(mem_ctx, &state, struct wait_for_exit_state); + if (req == NULL) { + return NULL; + } + + subreq = wait_for_parent_send(state, ev, ppid); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, wait_for_exit_parent_done, req); + + return req; +} + +static void wait_for_exit_parent_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + bool status; + + status = wait_for_parent_recv(subreq); + TALLOC_FREE(subreq); + if (! status) { + /* Ignore error */ + fprintf(stderr, + "ctdb_mutex_fcntl_helper: " + "wait_for_parent_recv() failed\n"); + } + + tevent_req_done(req); +} + +static bool wait_for_exit_recv(struct tevent_req *req) +{ + if (tevent_req_is_unix_error(req, NULL)) { + return false; + } + + return true; +} + int main(int argc, char *argv[]) { struct tevent_context *ev; @@ -191,20 +248,20 @@ int main(int argc, char *argv[]) return 0; } - req = wait_for_parent_send(ev, ev, ppid); + req = wait_for_exit_send(ev, ev, ppid); if (req == NULL) { fprintf(stderr, - "%s: wait_for_parent_send() failed\n", + "%s: wait_for_exit_send() failed\n", progname); exit(1); } tevent_req_poll(req, ev); - status = wait_for_parent_recv(req); + status = wait_for_exit_recv(req); if (! status) { fprintf(stderr, - "%s: wait_for_parent_recv() failed\n", + "%s: wait_for_exit_recv() failed\n", progname); } |