]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-daemon: Fork when not interactive and test mode is enabled
authorMartin Schwenke <martin@meltin.net>
Wed, 29 Jan 2020 05:28:46 +0000 (16:28 +1100)
committerAmitay Isaacs <amitay@samba.org>
Mon, 10 Feb 2020 04:07:39 +0000 (04:07 +0000)
There is no sane way of keeping stdin open when using the shell to
background ctdbd in local_daemons.sh.  Instead, have ctdbd fork when
not interactive and when test mode is enabled.  become_daemon() can't
be used for this: if it forks then it also closes stdin.

For the interactive case, become_daemon() wasn't doing anything
special, so do nothing instead.

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

index 8b4c05887f96d22327d544e8dafceae4ec25b747..7ebb419bc1ff7aee5c19331785084f2224e3635f 100644 (file)
@@ -1439,6 +1439,22 @@ static int setup_stdin_handler(struct ctdb_context *ctdb)
        return 0;
 }
 
+static void fork_only(void)
+{
+       pid_t pid;
+
+       pid = fork();
+       if (pid == -1) {
+               D_ERR("Fork failed (errno=%d)\n", errno);
+               exit(1);
+       }
+
+       if (pid != 0) {
+               /* Parent simply exits... */
+               exit(0);
+       }
+}
+
 /*
   start the protocol going as a daemon
 */
@@ -1448,9 +1464,17 @@ int ctdb_start_daemon(struct ctdb_context *ctdb,
 {
        int res, ret = -1;
        struct tevent_fd *fde;
-       bool do_fork = !(interactive || test_mode_enabled);
 
-       become_daemon(do_fork, !do_fork, false);
+       /* Fork if not interactive */
+       if (!interactive) {
+               if (test_mode_enabled) {
+                       /* Keep stdin open */
+                       fork_only();
+               } else {
+                       /* Fork, close stdin, start a session */
+                       become_daemon(true, false, false);
+               }
+       }
 
        ignore_signal(SIGPIPE);
        ignore_signal(SIGUSR1);
index 9306697f92afdf6c62913b1c19b0a178496eb0c5..e9f9423cb0c1e8f2f9b07eddfb74bbfee9072fa1 100755 (executable)
@@ -354,7 +354,7 @@ local_daemons_start ()
 
        onnode_common
 
-       onnode -i "$_nodes" "${VALGRIND:-} ctdbd &"
+       onnode -i "$_nodes" "${VALGRIND:-} ctdbd"
 }
 
 local_daemons_stop ()