summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2020-01-29 16:28:46 +1100
committerAmitay Isaacs <amitay@samba.org>2020-02-10 04:07:39 +0000
commit1a0e1f89246685730612819d23a8398b340cb673 (patch)
treea21f9f65596d3da8762a224491dfbb31b5c20a69 /ctdb
parenta220e9454a6dd56f3b0f317d9b4361d0328ff79a (diff)
downloadsamba-1a0e1f89246685730612819d23a8398b340cb673.tar.gz
ctdb-daemon: Fork when not interactive and test mode is enabled
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>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/server/ctdb_daemon.c28
-rwxr-xr-xctdb/tests/local_daemons.sh2
2 files changed, 27 insertions, 3 deletions
diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index 8b4c05887f9..7ebb419bc1f 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -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);
diff --git a/ctdb/tests/local_daemons.sh b/ctdb/tests/local_daemons.sh
index 9306697f92a..e9f9423cb0c 100755
--- a/ctdb/tests/local_daemons.sh
+++ b/ctdb/tests/local_daemons.sh
@@ -354,7 +354,7 @@ local_daemons_start ()
onnode_common
- onnode -i "$_nodes" "${VALGRIND:-} ctdbd &"
+ onnode -i "$_nodes" "${VALGRIND:-} ctdbd"
}
local_daemons_stop ()