ctdb-daemon: Bind to Unix domain socket after PID file creation
authorMartin Schwenke <martin@meltin.net>
Thu, 22 Sep 2016 04:43:58 +0000 (14:43 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 22 Sep 2016 06:34:20 +0000 (08:34 +0200)
No use touching the socket if PID file creation fails.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12287

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

index 2b960a5dd4b9dcd1b51e5da21ae918f5f1515001..a4e4f40555aeb58ac62ff05e78ce986de2c70d9c 100644 (file)
@@ -1233,13 +1233,6 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
        int res, ret = -1;
        struct tevent_fd *fde;
 
-       /* create a unix domain stream socket to listen to */
-       res = ux_socket_bind(ctdb);
-       if (res!=0) {
-               DEBUG(DEBUG_ALERT,("Cannot continue.  Exiting!\n"));
-               exit(10);
-       }
-
        if (do_fork && fork()) {
                return 0;
        }
@@ -1264,6 +1257,13 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
                          CTDB_VERSION_STRING, ctdb->ctdbd_pid));
        ctdb_create_pidfile(ctdb);
 
+       /* create a unix domain stream socket to listen to */
+       res = ux_socket_bind(ctdb);
+       if (res!=0) {
+               DEBUG(DEBUG_ALERT,("Cannot continue.  Exiting!\n"));
+               exit(10);
+       }
+
        /* Make sure we log something when the daemon terminates.
         * This must be the first exit handler to run (so the last to
         * be registered.