s4:samba: Allow samba daemon to run in foreground
authorAndreas Schneider <asn@samba.org>
Fri, 10 Nov 2017 08:18:18 +0000 (09:18 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 28 Nov 2017 10:37:06 +0000 (11:37 +0100)
We are passing the no_process_group to become_daemon() that setsid() is
not called. In case we are double forking, we run in SysV daemon mode,
setsid() should be called!

See:
https://www.freedesktop.org/software/systemd/man/daemon.html

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

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/smbd/server.c
source4/smbd/server.c

index 916727635f942cbc95ef4237c81be5fc9f537785..5b421ff4bb341bf60eee2dcdb4e5005ba6d26875 100644 (file)
@@ -1593,7 +1593,7 @@ extern void build_options(bool screen);
        struct poptOption long_options[] = {
        POPT_AUTOHELP
        {"daemon", 'D', POPT_ARG_NONE, NULL, OPT_DAEMON, "Become a daemon (default)" },
-       {"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE, "Run interactive (not a daemon)"},
+       {"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE, "Run interactive (not a daemon) and log to stdout"},
        {"foreground", 'F', POPT_ARG_NONE, NULL, OPT_FORK, "Run daemon in foreground (for daemontools, etc.)" },
        {"no-process-group", '\0', POPT_ARG_NONE, NULL, OPT_NO_PROCESS_GROUP, "Don't create a new process group" },
        {"log-stdout", 'S', POPT_ARG_NONE, NULL, OPT_LOG_STDOUT, "Log to stdout" },
index f107350e1af09c01edc1e47008d1ab59b87173d3..006f76bc8599ddcbc01f197b6014189381ba91dd 100644 (file)
@@ -367,6 +367,7 @@ static int binary_smbd_main(const char *binary_name,
                                const char *argv[])
 {
        bool opt_daemon = false;
+       bool opt_fork = true;
        bool opt_interactive = false;
        bool opt_no_process_group = false;
        int opt;
@@ -382,6 +383,7 @@ static int binary_smbd_main(const char *binary_name,
        struct stat st;
        enum {
                OPT_DAEMON = 1000,
+               OPT_FOREGROUND,
                OPT_INTERACTIVE,
                OPT_PROCESS_MODEL,
                OPT_SHOW_BUILD,
@@ -391,6 +393,8 @@ static int binary_smbd_main(const char *binary_name,
                POPT_AUTOHELP
                {"daemon", 'D', POPT_ARG_NONE, NULL, OPT_DAEMON,
                 "Become a daemon (default)", NULL },
+               {"foreground", 'F', POPT_ARG_NONE, NULL, OPT_FOREGROUND,
+                "Run the daemon in foreground", NULL },
                {"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE,
                 "Run interactive (not a daemon)", NULL},
                {"model", 'M', POPT_ARG_STRING, NULL, OPT_PROCESS_MODEL,
@@ -417,6 +421,9 @@ static int binary_smbd_main(const char *binary_name,
                case OPT_DAEMON:
                        opt_daemon = true;
                        break;
+               case OPT_FOREGROUND:
+                       opt_fork = false;
+                       break;
                case OPT_INTERACTIVE:
                        opt_interactive = true;
                        break;
@@ -443,7 +450,7 @@ static int binary_smbd_main(const char *binary_name,
                        "not allowed together with -D|--daemon\n\n");
                poptPrintUsage(pc, stderr, 0);
                return 1;
-       } else if (!opt_interactive) {
+       } else if (!opt_interactive && !opt_fork) {
                /* default is --daemon */
                opt_daemon = true;
        }
@@ -480,7 +487,7 @@ static int binary_smbd_main(const char *binary_name,
 
        if (opt_daemon) {
                DBG_NOTICE("Becoming a daemon.\n");
-               become_daemon(true, false, false);
+               become_daemon(opt_fork, opt_no_process_group, false);
        }
 
        /* Create the memory context to hang everything off. */