diff options
-rw-r--r-- | docs/docbook/manpages/nmbd.8.sgml | 29 | ||||
-rw-r--r-- | docs/docbook/manpages/smbd.8.sgml | 28 | ||||
-rw-r--r-- | docs/docbook/manpages/winbindd.8.sgml | 29 | ||||
-rw-r--r-- | source3/lib/debug.c | 1 | ||||
-rw-r--r-- | source3/lib/util.c | 9 | ||||
-rw-r--r-- | source3/nmbd/nmbd.c | 24 | ||||
-rw-r--r-- | source3/nsswitch/winbindd.c | 24 | ||||
-rw-r--r-- | source3/smbd/server.c | 18 | ||||
-rw-r--r-- | source3/web/startstop.c | 6 | ||||
-rw-r--r-- | source3/wrepld/server.c | 25 |
10 files changed, 171 insertions, 22 deletions
diff --git a/docs/docbook/manpages/nmbd.8.sgml b/docs/docbook/manpages/nmbd.8.sgml index b8986110a6..db920c79a1 100644 --- a/docs/docbook/manpages/nmbd.8.sgml +++ b/docs/docbook/manpages/nmbd.8.sgml @@ -17,6 +17,8 @@ <cmdsynopsis> <command>nmbd</command> <arg choice="opt">-D</arg> + <arg choice="opt">-F</arg> + <arg choice="opt">-S</arg> <arg choice="opt">-a</arg> <arg choice="opt">-i</arg> <arg choice="opt">-o</arg> @@ -87,6 +89,28 @@ </varlistentry> <varlistentry> + <term>-F</term> + <listitem><para>If specified, this parameter causes + the main <command>nmbd</command> process to not daemonize, + i.e. double-fork and disassociate with the terminal. + Child processes are still created as normal to service + each connection request, but the main process does not + exit. This operation mode is suitable for running + <command>nmbd</command> under process supervisors such + as <command>supervise</command> and <command>svscan</command> + from Daniel J. Bernstein's <command>daemontools</command> + package, or the AIX process monitor. + </para></listitem> + </varlistentry> + + <varlistentry> + <term>-S</term> + <listitem><para>If specified, this parameter causes + <command>nmbd</command> to log to standard output rather + than a file.</para></listitem> + </varlistentry> + + <varlistentry> <term>-a</term> <listitem><para>If this parameter is specified, each new connection will append log messages to the log file. @@ -99,8 +123,9 @@ server to run "interactively", not as a daemon, even if the server is executed on the command line of a shell. Setting this parameter negates the implicit daemon mode when run from the - command line. - </para></listitem> + command line. <command>nmbd</command> also logs to standard + output, as if the <command>-S</command> parameter had been + given. </para></listitem> </varlistentry> <varlistentry> diff --git a/docs/docbook/manpages/smbd.8.sgml b/docs/docbook/manpages/smbd.8.sgml index 4ae8b3148b..6dfb0f5746 100644 --- a/docs/docbook/manpages/smbd.8.sgml +++ b/docs/docbook/manpages/smbd.8.sgml @@ -16,6 +16,8 @@ <cmdsynopsis> <command>smbd</command> <arg choice="opt">-D</arg> + <arg choice="opt">-F</arg> + <arg choice="opt">-S</arg> <arg choice="opt">-i</arg> <arg choice="opt">-h</arg> <arg choice="opt">-V</arg> @@ -87,12 +89,36 @@ </varlistentry> <varlistentry> + <term>-F</term> + <listitem><para>If specified, this parameter causes + the main <command>smbd</command> process to not daemonize, + i.e. double-fork and disassociate with the terminal. + Child processes are still created as normal to service + each connection request, but the main process does not + exit. This operation mode is suitable for running + <command>smbd</command> under process supervisors such + as <command>supervise</command> and <command>svscan</command> + from Daniel J. Bernstein's <command>daemontools</command> + package, or the AIX process monitor. + </para></listitem> + </varlistentry> + + <varlistentry> + <term>-S</term> + <listitem><para>If specified, this parameter causes + <command>smbd</command> to log to standard output rather + than a file.</para></listitem> + </varlistentry> + + <varlistentry> <term>-i</term> <listitem><para>If this parameter is specified it causes the server to run "interactively", not as a daemon, even if the server is executed on the command line of a shell. Setting this parameter negates the implicit deamon mode when run from the - command line. + command line. <command>smbd</command> also logs to standard + output, as if the <command>-S</command> parameter had been + given. </para></listitem> </para></listitem> </varlistentry> diff --git a/docs/docbook/manpages/winbindd.8.sgml b/docs/docbook/manpages/winbindd.8.sgml index 848f6ed3fa..ccef2fa623 100644 --- a/docs/docbook/manpages/winbindd.8.sgml +++ b/docs/docbook/manpages/winbindd.8.sgml @@ -16,6 +16,8 @@ <refsynopsisdiv> <cmdsynopsis> <command>winbindd</command> + <arg choice="opt">-F</arg> + <arg choice="opt">-S</arg> <arg choice="opt">-i</arg> <arg choice="opt">-B</arg> <arg choice="opt">-d <debug level></arg> @@ -106,6 +108,28 @@ group: files winbind <variablelist> <varlistentry> + <term>-F</term> + <listitem><para>If specified, this parameter causes + the main <command>winbindd</command> process to not daemonize, + i.e. double-fork and disassociate with the terminal. + Child processes are still created as normal to service + each connection request, but the main process does not + exit. This operation mode is suitable for running + <command>winbindd</command> under process supervisors such + as <command>supervise</command> and <command>svscan</command> + from Daniel J. Bernstein's <command>daemontools</command> + package, or the AIX process monitor. + </para></listitem> + </varlistentry> + + <varlistentry> + <term>-S</term> + <listitem><para>If specified, this parameter causes + <command>winbindd</command> to log to standard output rather + than a file.</para></listitem> + </varlistentry> + + <varlistentry> <term>-d debuglevel</term> <listitem><para>Sets the debuglevel to an integer between 0 and 100. 0 is for no debugging and 100 is for reams and @@ -118,7 +142,10 @@ group: files winbind <listitem><para>Tells <command>winbindd</command> to not become a daemon and detach from the current terminal. This option is used by developers when interactive debugging - of <command>winbindd</command> is required. </para></listitem> + of <command>winbindd</command> is required. + <command>winbindd</command> also logs to standard output, + as if the <command>-S</command> parameter had been given. + </para></listitem> </varlistentry> <varlistentry> diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 0836dbe790..2efdd3c2a3 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -525,6 +525,7 @@ void setup_logging(const char *pname, BOOL interactive) if (interactive) { stdout_logging = True; dbf = x_stdout; + x_setbuf( x_stdout, NULL ); } #ifdef WITH_SYSLOG else { diff --git a/source3/lib/util.c b/source3/lib/util.c index 67de9e4bf2..ec967e4abf 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -873,10 +873,13 @@ void msleep(unsigned int t) Become a daemon, discarding the controlling terminal. ****************************************************************************/ -void become_daemon(void) +void become_daemon(BOOL Fork) { - if (sys_fork()) - _exit(0); + if (Fork) { + if (sys_fork()) { + _exit(0); + } + } /* detach from the terminal */ #ifdef HAVE_SETSID diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 988127e431..2b7d8033a2 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -32,6 +32,12 @@ extern BOOL global_in_nmbd; /* are we running as a daemon ? */ static BOOL is_daemon = False; +/* fork or run in foreground ? */ +static BOOL Fork = True; + +/* log to standard output ? */ +static BOOL log_stdout = False; + /* have we found LanMan clients yet? */ BOOL found_lm_clients = False; @@ -590,6 +596,8 @@ static BOOL open_sockets(BOOL isdaemon, int port) POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, + {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, + {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, dyn_LMHOSTSFILE, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, @@ -639,8 +647,18 @@ static BOOL open_sockets(BOOL isdaemon, int port) { } poptFreeContext(pc); - - setup_logging( argv[0], opt_interactive ); + + if ( opt_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 ); reopen_logs(); @@ -672,7 +690,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) if (is_daemon && !opt_interactive) { DEBUG( 2, ( "Becoming a daemon.\n" ) ); - become_daemon(); + become_daemon(Fork); } #if HAVE_SETPGID diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c index 71e426e818..eadbf56074 100644 --- a/source3/nsswitch/winbindd.c +++ b/source3/nsswitch/winbindd.c @@ -758,6 +758,8 @@ struct winbindd_state server_state; /* Server state information */ static void usage(void) { printf("Usage: winbindd [options]\n"); + printf("\t-F daemon in foreground mode\n"); + printf("\t-S log to stdout\n"); printf("\t-i interactive mode\n"); printf("\t-B dual daemon mode\n"); printf("\t-n disable cacheing\n"); @@ -771,6 +773,8 @@ static void usage(void) extern BOOL AllowDebugChange; pstring logfile; BOOL interactive = False; + BOOL Fork = True; + BOOL log_stdout = False; int opt; /* glibc (?) likes to print "User defined signal 1" and exit if a @@ -795,12 +799,20 @@ static void usage(void) /* Initialise samba/rpc client stuff */ - while ((opt = getopt(argc, argv, "id:s:nhB")) != EOF) { + while ((opt = getopt(argc, argv, "FSid:s:nhB")) != EOF) { switch (opt) { + case 'F': + Fork = False; + break; + case 'S': + log_stdout = True; + break; /* Don't become a daemon */ case 'i': interactive = True; + log_stdout = True; + Fork = False; break; /* dual daemon system */ @@ -834,9 +846,15 @@ static void usage(void) } } + if (log_stdout && Fork) { + printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n"); + usage(); + exit(1); + } + snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE); lp_set_logfile(logfile); - setup_logging("winbindd", interactive); + setup_logging("winbindd", log_stdout); reopen_logs(); DEBUG(1, ("winbindd version %s started.\n", VERSION ) ); @@ -853,7 +871,7 @@ static void usage(void) exit(1); if (!interactive) { - become_daemon(); + become_daemon(Fork); pidfile_create("winbindd"); } diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 0a11919577..c235283f6c 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -636,6 +636,8 @@ static BOOL init_structs(void ) /* shall I run as a daemon */ static BOOL is_daemon = False; static BOOL interactive = False; + static BOOL Fork = True; + static BOOL log_stdout = False; static char *ports = NULL; int opt; poptContext pc; @@ -644,6 +646,8 @@ static BOOL init_structs(void ) 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)" }, + {"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"}, {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug}, @@ -682,7 +686,17 @@ static BOOL init_structs(void ) set_remote_machine_name("smbd"); - setup_logging(argv[0],interactive); + 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 client problems at a later date. (tridge) */ @@ -771,7 +785,7 @@ static BOOL init_structs(void ) if (is_daemon && !interactive) { DEBUG( 3, ( "Becoming a daemon.\n" ) ); - become_daemon(); + become_daemon(Fork); } #if HAVE_SETPGID diff --git a/source3/web/startstop.c b/source3/web/startstop.c index e10dff4118..c6babff954 100644 --- a/source3/web/startstop.c +++ b/source3/web/startstop.c @@ -39,7 +39,7 @@ void start_smbd(void) slprintf(binfile, sizeof(pstring) - 1, "%s/smbd", dyn_SBINDIR); - become_daemon(); + become_daemon(True); execl(binfile, binfile, "-D", NULL); @@ -60,7 +60,7 @@ void start_nmbd(void) slprintf(binfile, sizeof(pstring) - 1, "%s/nmbd", dyn_SBINDIR); - become_daemon(); + become_daemon(True); execl(binfile, binfile, "-D", NULL); @@ -81,7 +81,7 @@ void start_winbindd(void) slprintf(binfile, sizeof(pstring) - 1, "%s/winbindd", dyn_SBINDIR); - become_daemon(); + become_daemon(True); execl(binfile, binfile, NULL); diff --git a/source3/wrepld/server.c b/source3/wrepld/server.c index e39fb148d6..349f2a21ab 100644 --- a/source3/wrepld/server.c +++ b/source3/wrepld/server.c @@ -166,9 +166,11 @@ void exit_server(const char *reason) static void usage(char *pname) { - d_printf("Usage: %s [-DaioPh?V] [-d debuglevel] [-l log basename] [-p port]\n", pname); + d_printf("Usage: %s [-DFSaioPh?V] [-d debuglevel] [-l log basename] [-p port]\n", pname); d_printf(" [-O socket options] [-s services file]\n"); d_printf("\t-D Become a daemon (default)\n"); + d_printf("\t-F Run daemon in foreground (for daemontools, etc)\n"); + d_printf("\t-S Log to stdout\n"); d_printf("\t-a Append to log file (default)\n"); d_printf("\t-i Run interactive (not a daemon)\n" ); d_printf("\t-o Overwrite log file, don't append\n"); @@ -523,6 +525,8 @@ static void process(void) BOOL is_daemon = False; BOOL interactive = False; BOOL specified_logfile = False; + BOOL Fork = True; + BOOL log_stdout = False; int opt; pstring logfile; @@ -536,8 +540,14 @@ static void process(void) argc--; } - while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?Vaiof:")) ) + while ( EOF != (opt = getopt(argc, argv, "FSO:l:s:d:Dp:h?Vaiof:")) ) switch (opt) { + case 'F': + Fork = False; + break; + case 'S': + log_stdout = True; + break; case 'O': pstrcpy(user_socket_options,optarg); break; @@ -554,6 +564,8 @@ static void process(void) case 'i': interactive = True; + Fork = False; + log_stdout = True; break; case 'D': @@ -586,6 +598,11 @@ static void process(void) usage(argv[0]); exit(1); } + if (log_stdout && Fork) { + d_printf("Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"); + usage(argv[0]); + exit(1); + } #ifdef HAVE_SETLUID /* needed for SecureWare on SCO */ @@ -604,7 +621,7 @@ static void process(void) set_remote_machine_name("wrepld"); - setup_logging(argv[0],interactive); + setup_logging(argv[0],log_stdout); /* we want to re-seed early to prevent time delays causing client problems at a later date. (tridge) */ @@ -682,7 +699,7 @@ static void process(void) if (is_daemon && !interactive) { DEBUG( 3, ( "Becoming a daemon.\n" ) ); - become_daemon(); + become_daemon(Fork); } #if HAVE_SETPGID |