ctdb-daemon: Use become_daemon() instead of custom code
authorMartin Schwenke <martin@meltin.net>
Tue, 15 Aug 2017 02:53:02 +0000 (12:53 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 29 Aug 2017 09:14:09 +0000 (11:14 +0200)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_daemon.c

index 2ffeae0f968bdf12a201bdbbb867daa2d032a411..41f042ecd8446cbd3022222b956c51b62291cf94 100644 (file)
@@ -34,6 +34,7 @@
 #include "lib/util/debug.h"
 #include "lib/util/time.h"
 #include "lib/util/blocking.h"
+#include "lib/util/become_daemon.h"
 
 #include "ctdb_version.h"
 #include "ctdb_private.h"
@@ -1197,20 +1198,8 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
        int res, ret = -1;
        struct tevent_fd *fde;
 
-       if (do_fork && fork()) {
-               return 0;
-       }
+       become_daemon(do_fork, false, false);
 
-       if (do_fork) {
-               if (setsid() == -1) {
-                       ctdb_die(ctdb, "Failed to setsid()\n");
-               }
-               close(0);
-               if (open("/dev/null", O_RDONLY) != 0) {
-                       DEBUG(DEBUG_ALERT,(__location__ " Failed to setup stdin on /dev/null\n"));
-                       exit(11);
-               }
-       }
        ignore_signal(SIGPIPE);
        ignore_signal(SIGUSR1);