diff -urpN source/lib/util.c source.fix2/lib/util.c --- source/lib/util.c Sun Sep 12 06:47:17 2004 +++ source.fix2/lib/util.c Fri Oct 8 09:59:22 2004 @@ -809,10 +809,6 @@ void become_daemon(BOOL Fork) } } #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 */ } /**************************************************************************** diff -urpN source/nmbd/nmbd.c source.fix2/nmbd/nmbd.c --- source/nmbd/nmbd.c Sun Apr 4 10:37:37 2004 +++ source.fix2/nmbd/nmbd.c Fri Oct 8 09:59:08 2004 @@ -687,6 +687,7 @@ static BOOL open_sockets(BOOL isdaemon, if (is_daemon && !opt_interactive) { DEBUG( 2, ( "Becoming a daemon.\n" ) ); become_daemon(Fork); + close_low_fds(False); } #if HAVE_SETPGID diff -urpN source/nsswitch/winbindd.c source.fix2/nsswitch/winbindd.c --- source/nsswitch/winbindd.c Sat Aug 7 00:38:19 2004 +++ source.fix2/nsswitch/winbindd.c Fri Oct 8 09:59:02 2004 @@ -793,7 +793,8 @@ int main(int argc, char **argv) static BOOL log_stdout = False; struct poptOption long_options[] = { POPT_AUTOHELP - { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, + { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, /* deprecated */ + { "log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Daemon in foreground mode" }, { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Interactive mode" }, { "single-daemon", 'Y', POPT_ARG_VAL, &opt_dual_daemon, False, "Single daemon mode" }, @@ -913,8 +914,10 @@ int main(int argc, char **argv) CatchSignal(SIGUSR2, sigusr2_handler); /* Debugging sigs */ CatchSignal(SIGHUP, sighup_handler); - if (!interactive) + if (!interactive) { become_daemon(Fork); + close_low_fds(False); + } pidfile_create("winbindd"); diff -urpN source/smbd/server.c source.fix2/smbd/server.c --- source/smbd/server.c Thu Aug 19 16:39:11 2004 +++ source.fix2/smbd/server.c Fri Oct 8 10:01:05 2004 @@ -179,7 +179,7 @@ static BOOL allowable_number_of_smbd_pro Open the socket communication. ****************************************************************************/ -static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_ports) +static BOOL open_sockets_smbd(BOOL inetd_style, BOOL single_thread, BOOL log_stdout, const char *smb_ports) { int num_interfaces = iface_count(); int num_sockets = 0; @@ -189,7 +189,7 @@ static BOOL open_sockets_smbd(BOOL is_da int i; char *ports; - if (!is_daemon) { + if (inetd_style) { return open_sockets_inetd(); } @@ -387,7 +387,7 @@ static BOOL open_sockets_smbd(BOOL is_da /* Ensure child is set to blocking mode */ set_blocking(smbd_server_fd(),True); - if (smbd_server_fd() != -1 && interactive) + if (smbd_server_fd() != -1 && single_thread) return True; if (allowable_number_of_smbd_processes() && smbd_server_fd() != -1 && sys_fork()==0) { @@ -396,10 +396,12 @@ static BOOL open_sockets_smbd(BOOL is_da /* close the listening socket(s) */ for(i = 0; i < num_sockets; i++) close(fd_listenset[i]); - - /* close our standard file - descriptors */ - close_low_fds(False); + + if(!log_stdout) { + /* close our standard file descriptors */ + close_low_fds(False); + } + am_parent = 0; set_socket_options(smbd_server_fd(),"SO_KEEPALIVE"); @@ -653,22 +655,23 @@ static BOOL init_structs(void ) void build_options(BOOL screen); - int main(int argc,const char *argv[]) +int main(int argc,const char *argv[]) { /* shall I run as a daemon */ - static BOOL is_daemon = False; - static BOOL interactive = False; - static BOOL Fork = True; + static BOOL single_thread = False; + static BOOL daemonize = True; static BOOL log_stdout = False; + static BOOL inetd_style; + static char *ports = NULL; int opt; poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP - {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" }, - {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"}, - {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, + {"daemon", 'D', POPT_ARG_VAL, &daemonize, True, "Become a daemon, close stdin/stdout (default)" }, + {"foreground", 'F', POPT_ARG_VAL, &daemonize, False, "Run in foreground (for daemontools & etc)" }, + {"interactive", 'i', POPT_ARG_VAL, &single_thread, True, "Run interactive (foreground, single-threaded)"}, {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" }, {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"}, @@ -693,6 +696,20 @@ void build_options(BOOL screen); poptFreeContext(pc); + /* sanitize params */ + inetd_style = is_a_socket(0); + if (single_thread) { + daemonize = False; + log_stdout = True; + } + if (inetd_style) { + if (log_stdout) { + fputs("ERROR: inetd-style smbd must not log to stdout!\n", stderr); + log_stdout = False; + }; + daemonize = False; + } + #ifdef HAVE_SETLUID /* needed for SecureWare on SCO */ setluid(0); @@ -704,16 +721,6 @@ void build_options(BOOL screen); set_remote_machine_name("smbd", False); - if (interactive) { - Fork = False; - log_stdout = True; - } - - if (log_stdout && Fork) { - DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); - exit(1); - } - setup_logging(argv[0],log_stdout); /* we want to re-seed early to prevent time delays causing @@ -767,8 +774,7 @@ void build_options(BOOL screen); build_options(False); if (sizeof(uint16) < 2 || sizeof(uint32) < 4) { - DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n")); - exit(1); + ERROR_Samba_is_not_configured_correctly_for_the_word_size_on_your_machine(); } /* @@ -789,36 +795,26 @@ void build_options(BOOL screen); DEBUG(3,( "loaded services\n")); - if (!is_daemon && !is_a_socket(0)) { - if (!interactive) - DEBUG(0,("standard input is not a socket, assuming -D option\n")); - - /* - * Setting is_daemon here prevents us from eventually calling - * the open_sockets_inetd() - */ - - is_daemon = True; - } - - if (is_daemon && !interactive) { + if (daemonize) { DEBUG( 3, ( "Becoming a daemon.\n" ) ); - become_daemon(Fork); + become_daemon(daemonize); + if (!log_stdout) + close_low_fds(False); } #if HAVE_SETPGID /* - * If we're interactive we want to set our own process group for + * If we're single_thread we want to set our own process group for * signal management. */ - if (interactive) + if (single_thread) setpgid( (pid_t)0, (pid_t)0); #endif if (!directory_exist(lp_lockdir(), NULL)) mkdir(lp_lockdir(), 0755); - if (is_daemon) + if (daemonize) pidfile_create("smbd"); /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */ @@ -850,15 +846,15 @@ void build_options(BOOL screen); claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD); - /* only start the background queue daemon if we are - running as a daemon -- bad things will happen if + /* only start the background queue daemon if we are not + running inetd-style -- bad things will happen if smbd is launched via inetd and we fork a copy of ourselves here */ - if ( is_daemon ) + if (!inetd_style && !single_thread) start_background_queue(); - if (!open_sockets_smbd(is_daemon, interactive, ports)) + if (!open_sockets_smbd(inetd_style, single_thread, log_stdout, ports)) exit(1); /* diff -urpN source/web/startstop.c source.fix2/web/startstop.c --- source/web/startstop.c Sun Apr 4 10:37:22 2004 +++ source.fix2/web/startstop.c Fri Oct 8 09:58:42 2004 @@ -37,6 +37,7 @@ void start_smbd(void) slprintf(binfile, sizeof(pstring) - 1, "%s/smbd", dyn_SBINDIR); become_daemon(True); + close_low_fds(False); execl(binfile, binfile, "-D", NULL); @@ -57,6 +58,7 @@ void start_nmbd(void) slprintf(binfile, sizeof(pstring) - 1, "%s/nmbd", dyn_SBINDIR); become_daemon(True); + close_low_fds(False); execl(binfile, binfile, "-D", NULL); @@ -77,6 +79,7 @@ void start_winbindd(void) slprintf(binfile, sizeof(pstring) - 1, "%s/winbindd", dyn_SBINDIR); become_daemon(True); + close_low_fds(False); execl(binfile, binfile, NULL); diff -urpN source/wrepld/server.c source.fix2/wrepld/server.c --- source/wrepld/server.c Sat Aug 7 00:38:19 2004 +++ source.fix2/wrepld/server.c Fri Oct 8 09:58:22 2004 @@ -626,6 +626,7 @@ static void process(void) if (is_daemon && !interactive) { DEBUG( 3, ( "Becoming a daemon.\n" ) ); become_daemon(Fork); + close_low_fds(False); } #if HAVE_SETPGID