summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/debug.c1
-rw-r--r--source3/lib/util.c9
-rw-r--r--source3/nmbd/nmbd.c24
-rw-r--r--source3/nsswitch/winbindd.c24
-rw-r--r--source3/smbd/server.c18
-rw-r--r--source3/web/startstop.c6
-rw-r--r--source3/wrepld/server.c25
7 files changed, 89 insertions, 18 deletions
diff --git a/source3/lib/debug.c b/source3/lib/debug.c
index ea5bad3b6d..966a53fca3 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 acc717e13c..479b35da07 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 94849f9f5c..c5474a46b8 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -632,6 +632,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;
@@ -640,6 +642,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},
@@ -678,7 +682,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) */
@@ -767,7 +781,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