From 8a22b1f0ea81f06616a2dc41a138c5126359f009 Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 20 Apr 2007 18:34:33 +0000 Subject: r22417: Refactor the various daemon run-mode options to make the semantics of the various flags explicit. (This used to be commit 19c929c6330a50f278ac322ac5fcb83d03734ea2) --- source3/nsswitch/winbindd.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'source3/nsswitch/winbindd.c') diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c index fcedaebb27..da0473583f 100644 --- a/source3/nsswitch/winbindd.c +++ b/source3/nsswitch/winbindd.c @@ -30,7 +30,6 @@ #define DBGC_CLASS DBGC_WINBIND BOOL opt_nocache = False; -static BOOL interactive = False; extern BOOL override_logfile; @@ -911,15 +910,17 @@ static void process_loop(void) int main(int argc, char **argv, char **envp) { pstring logfile; - static BOOL Fork = True; - static BOOL log_stdout = False; - static BOOL no_process_group = False; + BOOL log_stdout = False; + BOOL no_process_group = False; + + enum smb_server_mode server_mode = SERVER_MODE_DAEMON; + struct poptOption long_options[] = { POPT_AUTOHELP { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, - { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Daemon in foreground mode" }, + { "foreground", 'F', POPT_ARG_VAL, &server_mode, SERVER_MODE_FOREGROUND, "Daemon in foreground mode" }, { "no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" }, - { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Interactive mode" }, + { "interactive", 'i', POPT_ARG_VAL, &server_mode, SERVER_MODE_INTERACTIVE, "Interactive mode" }, { "no-caching", 'n', POPT_ARG_VAL, &opt_nocache, True, "Disable caching" }, POPT_COMMON_SAMBA POPT_TABLEEND @@ -957,20 +958,17 @@ int main(int argc, char **argv, char **envp) pc = poptGetContext("winbindd", argc, (const char **)argv, long_options, POPT_CONTEXT_KEEP_FIRST); - while ((opt = poptGetNextOpt(pc)) != -1) { - switch (opt) { - /* Don't become a daemon */ - case 'i': - interactive = True; - log_stdout = True; - Fork = False; - break; + while ((opt = poptGetNextOpt(pc)) != -1) {} + + if (server_mode == SERVER_MODE_INTERACTIVE) { + log_stdout = True; + if (DEBUGLEVEL >= 9) { + talloc_enable_leak_report(); } } - - if (log_stdout && Fork) { - printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n"); + if (log_stdout && server_mode == SERVER_MODE_DAEMON) { + printf("Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"); poptPrintUsage(pc, stderr, 0); exit(1); } @@ -1041,8 +1039,12 @@ int main(int argc, char **argv, char **envp) CatchSignal(SIGUSR2, sigusr2_handler); /* Debugging sigs */ CatchSignal(SIGHUP, sighup_handler); - if (!interactive) - become_daemon(Fork, no_process_group); + if (server_mode == SERVER_MODE_DAEMON) { + DEBUG( 3, ( "Becoming a daemon.\n" ) ); + become_daemon(True, no_process_group); + } else if (server_mode == SERVER_MODE_FOREGROUND) { + become_daemon(False, no_process_group); + } pidfile_create("winbindd"); @@ -1067,8 +1069,9 @@ int main(int argc, char **argv, char **envp) * If we're interactive we want to set our own process group for * signal management. */ - if (interactive && !no_process_group) + if (server_mode == SERVER_MODE_INTERACTIVE && !no_process_group) { setpgid( (pid_t)0, (pid_t)0); + } #endif TimeInit(); -- cgit