[PATCH] -F (foreground) and -S (stdout logging) for nmbd, smbd, winbindd (daemontools)
Michael Handler
handler-list-samba-technical at grendel.net
Tue Jun 4 09:55:02 GMT 2002
Michael Handler <handler-list-samba-technical at grendel.net> writes:
> ok, here's the second revision of my patches to nmbd, smbd, and winbindd.
> to summarize:
and here's the patch that applies cleanly to HEAD. on the web at:
http://www.sub-rosa.com/handler/pub/samba-HEAD-daemontools-diff
--michael
Index: docs/docbook/manpages/nmbd.8.sgml
===================================================================
RCS file: /cvsroot/samba/docs/docbook/manpages/nmbd.8.sgml,v
retrieving revision 1.8
diff -u -r1.8 nmbd.8.sgml
--- docs/docbook/manpages/nmbd.8.sgml 8 May 2002 15:34:57 -0000 1.8
+++ docs/docbook/manpages/nmbd.8.sgml 4 Jun 2002 16:49:55 -0000
@@ -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>
@@ -88,6 +90,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.
@@ -100,8 +124,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 deamon 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>
Index: docs/docbook/manpages/smbd.8.sgml
===================================================================
RCS file: /cvsroot/samba/docs/docbook/manpages/smbd.8.sgml,v
retrieving revision 1.8
diff -u -r1.8 smbd.8.sgml
--- docs/docbook/manpages/smbd.8.sgml 8 May 2002 15:34:58 -0000 1.8
+++ docs/docbook/manpages/smbd.8.sgml 4 Jun 2002 16:49:55 -0000
@@ -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">-a</arg>
<arg choice="opt">-i</arg>
<arg choice="opt">-o</arg>
@@ -90,6 +92,28 @@
</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>-a</term>
<listitem><para>If this parameter is specified, each new
connection will append log messages to the log file.
@@ -102,8 +126,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 deamon mode when run from the
- command line.
- </para></listitem>
+ command line. <command>smbd</command> also logs to standard
+ output, as if the <command>-S</command> parameter had been
+ given. </para></listitem>
</varlistentry>
<varlistentry>
Index: docs/docbook/manpages/winbindd.8.sgml
===================================================================
RCS file: /cvsroot/samba/docs/docbook/manpages/winbindd.8.sgml,v
retrieving revision 1.8
diff -u -r1.8 winbindd.8.sgml
--- docs/docbook/manpages/winbindd.8.sgml 8 May 2002 15:34:58 -0000 1.8
+++ docs/docbook/manpages/winbindd.8.sgml 4 Jun 2002 16:49:55 -0000
@@ -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">-d <debug level></arg>
<arg choice="opt">-s <smb config file></arg>
@@ -104,6 +106,28 @@
<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
@@ -116,7 +140,10 @@
<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>
</variablelist>
</refsect1>
Index: source/lib/util.c
===================================================================
RCS file: /cvsroot/samba/source/lib/util.c,v
retrieving revision 1.369
diff -u -r1.369 util.c
--- source/lib/util.c 3 Jun 2002 03:07:24 -0000 1.369
+++ source/lib/util.c 4 Jun 2002 16:49:56 -0000
@@ -658,10 +658,12 @@
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 */
@@ -677,8 +679,10 @@
}
#endif /* HAVE_SETSID */
- /* Close fd's 0,1,2. Needed if started by rsh */
- close_low_fds();
+ if (fork) {
+ /* Close fd's 0,1,2. Needed if started by rsh */
+ close_low_fds();
+ }
}
Index: source/nmbd/nmbd.c
===================================================================
RCS file: /cvsroot/samba/source/nmbd/nmbd.c,v
retrieving revision 1.134
diff -u -r1.134 nmbd.c
--- source/nmbd/nmbd.c 29 Mar 2002 13:58:32 -0000 1.134
+++ source/nmbd/nmbd.c 4 Jun 2002 16:49:57 -0000
@@ -672,9 +672,11 @@
static void usage(char *pname)
{
- printf( "Usage: %s [-DaiohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname );
+ printf( "Usage: %s [-DFSaiohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname );
printf( " [-n name] [-p port] [-s configuration file]\n" );
printf( "\t-D Become a daemon (default)\n" );
+ printf( "\t-F Run daemon in foreground (for daemontools, etc)\n" );
+ printf( "\t-S Log to stdout\n" );
printf( "\t-a Append to log file (default)\n" );
printf( "\t-i Run interactive (not a daemon)\n" );
printf( "\t-o Overwrite log file, don't append\n" );
@@ -699,6 +701,8 @@
extern char *optarg;
extern BOOL append_log;
BOOL opt_interactive = False;
+ BOOL fork = True;
+ BOOL log_stdout = False;
pstring logfile;
append_log = True; /* Default, override with '-o' option. */
@@ -742,10 +746,16 @@
#endif
while( EOF !=
- (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:i" )) )
+ (opt = getopt( argc, argv, "FSVaos:T:I:C:bAB:N:Rn:l:d:Dp:hH:G:f:i" )) )
{
switch (opt)
{
+ case 'F':
+ fork = False;
+ break;
+ case 'S':
+ log_stdout = True;
+ break;
case 's':
pstrcpy(dyn_CONFIGFILE, optarg);
break;
@@ -758,6 +768,8 @@
break;
case 'i':
opt_interactive = True;
+ log_stdout = True;
+ fork = False; /* for stdout logging check below */
break;
case 'H':
pstrcpy(dyn_LMHOSTSFILE, optarg);
@@ -804,7 +816,13 @@
}
}
- setup_logging( argv[0], opt_interactive );
+ if (log_stdout && fork) {
+ printf("Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n");
+ usage(argv[0]);
+ exit(1);
+ }
+
+ setup_logging( argv[0], log_stdout );
reopen_logs();
@@ -838,7 +856,7 @@
if (is_daemon && !opt_interactive)
{
DEBUG( 2, ( "Becoming a daemon.\n" ) );
- become_daemon();
+ become_daemon(fork);
}
#if HAVE_SETPGID
Index: source/nsswitch/winbindd.c
===================================================================
RCS file: /cvsroot/samba/source/nsswitch/winbindd.c,v
retrieving revision 1.59
diff -u -r1.59 winbindd.c
--- source/nsswitch/winbindd.c 13 May 2002 00:23:06 -0000 1.59
+++ source/nsswitch/winbindd.c 4 Jun 2002 16:49:57 -0000
@@ -736,6 +736,8 @@
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");
@@ -753,6 +755,8 @@
pstring logfile;
int accept_sock;
BOOL interactive = False;
+ BOOL fork = True;
+ BOOL log_stdout = False;
int opt;
/* glibc (?) likes to print "User defined signal 1" and exit if a
@@ -782,12 +786,20 @@
/* 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; /* for stdout logging check below */
break;
/* dual daemon system */
@@ -821,9 +833,16 @@
}
}
+ 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 ) );
@@ -850,7 +869,7 @@
fstrcpy(global_myworkgroup, lp_workgroup());
if (!interactive)
- become_daemon();
+ become_daemon(fork);
#if HAVE_SETPGID
/*
Index: source/smbd/server.c
===================================================================
RCS file: /cvsroot/samba/source/smbd/server.c,v
retrieving revision 1.374
diff -u -r1.374 server.c
--- source/smbd/server.c 22 May 2002 12:14:28 -0000 1.374
+++ source/smbd/server.c 4 Jun 2002 16:49:57 -0000
@@ -577,9 +577,11 @@
static void usage(char *pname)
{
- d_printf("Usage: %s [-DaioPh?Vb] [-d debuglevel] [-l log basename] [-p port]\n", pname);
+ d_printf("Usage: %s [-DFSaioPh?Vb] [-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");
@@ -606,6 +608,8 @@
extern char *optarg;
/* shall I run as a daemon */
BOOL is_daemon = False;
+ BOOL fork = True;
+ BOOL log_stdout = False;
BOOL interactive = False;
BOOL specified_logfile = False;
int port = SMB_PORT;
@@ -622,7 +626,7 @@
argc--;
}
- while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?bVaiof:")) )
+ while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:DFSp:h?bVaiof:")) )
switch (opt) {
case 'O':
pstrcpy(user_socket_options,optarg);
@@ -642,8 +646,18 @@
append_log = True;
break;
+ case 'F':
+ fork = False;
+ break;
+
+ case 'S':
+ log_stdout = True;
+ break;
+
case 'i':
interactive = True;
+ log_stdout = True;
+ fork = False; /* for stdout logging check below */
break;
case 'o':
@@ -686,6 +700,12 @@
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 */
setluid(0);
@@ -704,7 +724,7 @@
fstrcpy(remote_machine, "smbd");
- 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) */
@@ -800,7 +820,7 @@
if (is_daemon && !interactive) {
DEBUG( 3, ( "Becoming a daemon.\n" ) );
- become_daemon();
+ become_daemon(fork);
}
#if HAVE_SETPGID
Index: source/web/startstop.c
===================================================================
RCS file: /cvsroot/samba/source/web/startstop.c,v
retrieving revision 1.11
diff -u -r1.11 startstop.c
--- source/web/startstop.c 20 Mar 2002 06:57:03 -0000 1.11
+++ source/web/startstop.c 4 Jun 2002 16:49:57 -0000
@@ -39,7 +39,7 @@
slprintf(binfile, sizeof(pstring) - 1, "%s/smbd", dyn_SBINDIR);
- become_daemon();
+ become_daemon(True);
execl(binfile, binfile, "-D", NULL);
@@ -60,7 +60,7 @@
slprintf(binfile, sizeof(pstring) - 1, "%s/nmbd", dyn_SBINDIR);
- become_daemon();
+ become_daemon(True);
execl(binfile, binfile, "-D", NULL);
Index: source/wrepld/server.c
===================================================================
RCS file: /cvsroot/samba/source/wrepld/server.c,v
retrieving revision 1.5
diff -u -r1.5 server.c
--- source/wrepld/server.c 30 Apr 2002 09:11:23 -0000 1.5
+++ source/wrepld/server.c 4 Jun 2002 16:49:57 -0000
@@ -190,9 +190,11 @@
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");
@@ -548,6 +550,8 @@
BOOL is_daemon = False;
BOOL interactive = False;
BOOL specified_logfile = False;
+ BOOL fork = True;
+ BOOL log_stdout = False;
int opt;
pstring logfile;
@@ -561,8 +565,14 @@
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;
@@ -583,6 +593,8 @@
case 'i':
interactive = True;
+ log_stdout = True;
+ fork = False; /* for stdout logging check below */
break;
case 'o':
@@ -620,6 +632,12 @@
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 */
setluid(0);
@@ -639,7 +657,7 @@
pstrcpy(remote_machine, "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) */
@@ -718,7 +736,7 @@
if (is_daemon && !interactive) {
DEBUG( 3, ( "Becoming a daemon.\n" ) );
- become_daemon();
+ become_daemon(fork);
}
#if HAVE_SETPGID
More information about the samba-technical
mailing list