diff -urp source/nsswitch/winbindd.c source.fix/nsswitch/winbindd.c --- source/nsswitch/winbindd.c Sat Aug 7 00:38:19 2004 +++ source.fix/nsswitch/winbindd.c Thu Oct 7 12:15:03 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" }, diff -urp source/smbd/server.c source.fix/smbd/server.c --- source/smbd/server.c Thu Aug 19 16:39:11 2004 +++ source.fix/smbd/server.c Thu Oct 7 14:34:13 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,24 @@ 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 background = 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 (default)" }, + {"foreground", 'F', POPT_ARG_VAL, &background, 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 +697,23 @@ void build_options(BOOL screen); poptFreeContext(pc); + /* sanitize params */ + inetd_style = is_a_socket(0); + if (single_thread) { + background = 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; + }; + background = False; + } + if (!background) { + daemonize = False; + } + #ifdef HAVE_SETLUID /* needed for SecureWare on SCO */ setluid(0); @@ -704,16 +725,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 +778,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 +799,24 @@ 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 (background) { DEBUG( 3, ( "Becoming a daemon.\n" ) ); - become_daemon(Fork); + become_daemon(daemonize); } #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 (background) pidfile_create("smbd"); /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */ @@ -850,15 +848,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); /*