ctdb-common: Start wait computation only after successful startup
authorAmitay Isaacs <amitay@gmail.com>
Thu, 16 Nov 2017 23:52:57 +0000 (10:52 +1100)
committerMartin Schwenke <martins@samba.org>
Tue, 21 Nov 2017 04:03:16 +0000 (05:03 +0100)
This orders the startup events in sock_daemon code.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/common/sock_daemon.c
ctdb/tests/cunit/sock_daemon_test_001.sh

index bb241e0ebd8be205ecb6be2beea78f6ef32db7d8..8ceb7c96bdaafb7bc88d3bdc9da66a2c556d91e7 100644 (file)
@@ -526,6 +526,7 @@ static void sock_daemon_run_reconfigure(struct tevent_req *req);
 static void sock_daemon_run_shutdown(struct tevent_req *req);
 static void sock_daemon_run_socket_fail(struct tevent_req *subreq);
 static void sock_daemon_run_watch_pid(struct tevent_req *subreq);
+static void sock_daemon_run_wait(struct tevent_req *req);
 static void sock_daemon_run_wait_done(struct tevent_req *subreq);
 
 struct tevent_req *sock_daemon_run_send(TALLOC_CTX *mem_ctx,
@@ -615,17 +616,6 @@ struct tevent_req *sock_daemon_run_send(TALLOC_CTX *mem_ctx,
                                        req);
        }
 
-       if (sockd->funcs != NULL && sockd->funcs->wait_send != NULL &&
-           sockd->funcs->wait_recv != NULL) {
-               subreq = sockd->funcs->wait_send(state, ev,
-                                                sockd->private_data);
-               if (tevent_req_nomem(subreq, req)) {
-                       return tevent_req_post(req, ev);
-               }
-               tevent_req_set_callback(subreq, sock_daemon_run_wait_done,
-                                       req);
-       }
-
        return req;
 }
 
@@ -659,6 +649,8 @@ static void sock_daemon_run_started(struct tevent_req *subreq)
 
                D_NOTICE("startup completed successfully\n");
        }
+
+       sock_daemon_run_wait(req);
 }
 
 static void sock_daemon_run_signal_handler(struct tevent_context *ev,
@@ -776,6 +768,25 @@ static void sock_daemon_run_watch_pid(struct tevent_req *subreq)
        tevent_req_set_callback(subreq, sock_daemon_run_watch_pid, req);
 }
 
+static void sock_daemon_run_wait(struct tevent_req *req)
+{
+       struct tevent_req *subreq;
+       struct sock_daemon_run_state *state = tevent_req_data(
+               req, struct sock_daemon_run_state);
+       struct sock_daemon_context *sockd = state->sockd;
+
+       if (sockd->funcs != NULL && sockd->funcs->wait_send != NULL &&
+           sockd->funcs->wait_recv != NULL) {
+               subreq = sockd->funcs->wait_send(state, state->ev,
+                                                sockd->private_data);
+               if (tevent_req_nomem(subreq, req)) {
+                       return;
+               }
+               tevent_req_set_callback(subreq, sock_daemon_run_wait_done,
+                                       req);
+       }
+}
+
 static void sock_daemon_run_wait_done(struct tevent_req *subreq)
 {
        struct tevent_req *req = tevent_req_callback_data(
index cbb5a7e292aafb70ca0fe96250a3952ce970138d..0561863e256f3923ad8c5cbbd47f0b58bc23a359 100755 (executable)
@@ -26,6 +26,7 @@ ok <<EOF
 test1[PID]: daemon started, pid=PID
 test1[PID]: startup failed, ret=1
 test1[PID]: listening on $sockpath
+test1[PID]: daemon started, pid=PID
 test1[PID]: Shutting down
 EOF
 unit_test sock_daemon_test "$pidfile" "$sockpath" 1