s3-smbd: Don't close stdout if we want to log to stdout.
authorAndreas Schneider <asn@redhat.com>
Fri, 26 Mar 2010 10:17:37 +0000 (11:17 +0100)
committerAndreas Schneider <asn@redhat.com>
Fri, 26 Mar 2010 13:48:54 +0000 (14:48 +0100)
lib/util/become_daemon.c
lib/util/util.h
source3/nmbd/nmbd.c
source3/smbd/server.c
source3/web/startstop.c
source3/winbindd/winbindd.c
source4/smbd/server.c

index 3d06a4363df9b9097ac8dabe04e78de196ee0b95..2af16316b53e885220ca8731d510c72c774d97d5 100644 (file)
@@ -66,7 +66,7 @@ _PUBLIC_ void close_low_fds(bool stderr_too)
  Become a daemon, discarding the controlling terminal.
 ****************************************************************************/
 
-_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group)
+_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout)
 {
        if (do_fork) {
                if (sys_fork()) {
@@ -87,7 +87,9 @@ _PUBLIC_ void become_daemon(bool do_fork, bool no_process_group)
        }
 #endif /* HAVE_SETSID */
 
-       /* Close fd's 0,1,2. Needed if started by rsh */
-       close_low_fds(false);  /* Don't close stderr, let the debug system
-                                 attach it to the logfile */
+       if (!log_stdout) {
+               /* Close fd's 0,1,2. Needed if started by rsh */
+               close_low_fds(false);  /* Don't close stderr, let the debug system
+                                         attach it to the logfile */
+       }
 }
index b89a7d60508f2354c135f7e419a7e5192aa6df93..8383344cd5f092001f02223765f5c2fe64b80b82 100644 (file)
@@ -827,7 +827,7 @@ _PUBLIC_ void close_low_fds(bool stderr_too);
 /**
  Become a daemon, discarding the controlling terminal.
 **/
-_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group);
+_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout);
 
 /**
  * Load a ini-style file.
index 4443dfae9f87f54df5b39eb4a0526c7600749ea9..5dc021a54733bc87ca07cc5203854ae5a189cc9f 100644 (file)
@@ -889,7 +889,7 @@ static bool open_sockets(bool isdaemon, int port)
   
        if (is_daemon && !opt_interactive) {
                DEBUG( 2, ( "Becoming a daemon.\n" ) );
-               become_daemon(Fork, no_process_group);
+               become_daemon(Fork, no_process_group, log_stdout);
        }
 
 #if HAVE_SETPGID
index e5cfc2779490e34909570204d94b7d0ed4d09694..49e2eda3cec1e4a93f6a68dd859c22d57fb494e8 100644 (file)
@@ -1235,7 +1235,7 @@ extern void build_options(bool screen);
 
        if (is_daemon && !interactive) {
                DEBUG( 3, ( "Becoming a daemon.\n" ) );
-               become_daemon(Fork, no_process_group);
+               become_daemon(Fork, no_process_group, log_stdout);
        }
 
 #if HAVE_SETPGID
index b24410a89f8d82cae416c4f2aa82a4df24b8732a..81350e62f5ca9bcd4bd33aa1e15149bce57a8c38 100644 (file)
@@ -36,7 +36,7 @@ void start_smbd(void)
        }
 
        if (asprintf(&binfile, "%s/smbd", get_dyn_SBINDIR()) > 0) {
-               become_daemon(true, false);
+               become_daemon(true, false, false);
                execl(binfile, binfile, "-D", NULL);
        }
        exit(0);
@@ -56,7 +56,7 @@ void start_nmbd(void)
        }
 
        if (asprintf(&binfile, "%s/nmbd", get_dyn_SBINDIR()) > 0) {
-               become_daemon(true, false);
+               become_daemon(true, false, false);
                execl(binfile, binfile, "-D", NULL);
        }
        exit(0);
@@ -76,7 +76,7 @@ void start_winbindd(void)
        }
 
        if (asprintf(&binfile, "%s/winbindd", get_dyn_SBINDIR()) > 0) {
-               become_daemon(true, false);
+               become_daemon(true, false, false);
                execl(binfile, binfile, NULL);
        }
        exit(0);
index b04fd5db2bc9294568287b39eb3c521bbb1b08d8..86304e98c508b1d240792baee165d071fd77779f 100644 (file)
@@ -1185,7 +1185,7 @@ int main(int argc, char **argv, char **envp)
        BlockSignals(False, SIGCHLD);
 
        if (!interactive)
-               become_daemon(Fork, no_process_group);
+               become_daemon(Fork, no_process_group, log_stdout);
 
        pidfile_create("winbindd");
 
index 83f6e7d8063c660f68297abfdba024c39101b002..a09da3ce76f65a47a601f8a5150ce43f1d8028ef 100644 (file)
@@ -336,7 +336,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 
        if (opt_daemon) {
                DEBUG(3,("Becoming a daemon.\n"));
-               become_daemon(true, false);
+               become_daemon(true, false, false);
        }
 
        cleanup_tmp_files(cmdline_lp_ctx);