1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-08 04:58:40 +03:00

patch to include support for daemontools from Michael Handler

(This used to be commit 4c48c475a28450ad4fd8dcc8263e841c0c39a80e)
This commit is contained in:
Gerald Carter 2003-01-03 17:32:11 +00:00
parent fc744091d4
commit df4af79c78
10 changed files with 171 additions and 22 deletions

View File

@ -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>
@ -86,6 +88,28 @@
</para></listitem>
</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
@ -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>

View File

@ -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>
@ -86,13 +88,37 @@
</para></listitem>
</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>

View File

@ -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 &lt;debug level&gt;</arg>
@ -105,6 +107,28 @@ group: files winbind
<title>OPTIONS</title>
<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
@ -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>

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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");
}

View File

@ -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

View File

@ -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);

View File

@ -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