diff options
author | Ralph Boehme <slow@samba.org> | 2021-09-03 12:14:19 +0200 |
---|---|---|
committer | Jule Anger <janger@samba.org> | 2021-09-06 19:17:11 +0000 |
commit | 3eef217a9daba415774680b4f4c0bf1188909edd (patch) | |
tree | ac7edfdc353d1e8afdbc94561d6061302c63c950 /source3 | |
parent | e1be4413c990f75f7efe9dc2c62a86646f2932d4 (diff) | |
download | samba-3eef217a9daba415774680b4f4c0bf1188909edd.tar.gz |
nmbd: use POPT_COMMON_DAEMON
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14803
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
(cherry picked from commit a20f63b384750d389aeafd4bd5e229aed72cb271)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/nmbd/nmbd.c | 103 |
1 files changed, 23 insertions, 80 deletions
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index c33d3a441ae..d43c52bb406 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -771,57 +771,15 @@ static bool open_sockets(bool isdaemon, int port) int main(int argc, const char *argv[]) { - bool is_daemon = false; - bool opt_interactive = false; - bool Fork = true; - bool no_process_group = false; + struct samba_cmdline_daemon_cfg *cmdline_daemon_cfg = NULL; bool log_stdout = false; poptContext pc; char *p_lmhosts = NULL; int opt; struct messaging_context *msg; - enum { - OPT_DAEMON = 1000, - OPT_INTERACTIVE, - OPT_FORK, - OPT_NO_PROCESS_GROUP - }; struct poptOption long_options[] = { POPT_AUTOHELP { - .longName = "daemon", - .shortName = 'D', - .argInfo = POPT_ARG_NONE, - .arg = NULL, - .val = OPT_DAEMON, - .descrip = "Become a daemon (default)", - }, - { - .longName = "interactive", - .shortName = 'i', - .argInfo = POPT_ARG_NONE, - .arg = NULL, - .val = OPT_INTERACTIVE, - .descrip = "Run interactive (not a daemon)", - }, - { - .longName = "foreground", - .shortName = 'F', - .argInfo = POPT_ARG_NONE, - .arg = NULL, - .val = OPT_FORK, - .descrip = "Run daemon in foreground " - "(for daemontools, etc.)", - }, - { - .longName = "no-process-group", - .shortName = 0, - .argInfo = POPT_ARG_NONE, - .arg = NULL, - .val = OPT_NO_PROCESS_GROUP, - .descrip = "Don't create a new process group", - }, - { .longName = "hosts", .shortName = 'H', .argInfo = POPT_ARG_STRING, @@ -838,6 +796,7 @@ static bool open_sockets(bool isdaemon, int port) .descrip = "Listen on the specified port", }, POPT_COMMON_SAMBA + POPT_COMMON_DAEMON POPT_COMMON_VERSION POPT_TABLEEND }; @@ -870,6 +829,8 @@ static bool open_sockets(bool isdaemon, int port) exit(ENOMEM); } + cmdline_daemon_cfg = samba_cmdline_get_daemon_cfg(); + global_nmb_port = NMB_PORT; pc = samba_popt_get_context(getprogname(), @@ -884,25 +845,9 @@ static bool open_sockets(bool isdaemon, int port) } while ((opt = poptGetNextOpt(pc)) != -1) { - switch (opt) { - case OPT_DAEMON: - is_daemon = true; - break; - case OPT_INTERACTIVE: - opt_interactive = true; - break; - case OPT_FORK: - Fork = false; - break; - case OPT_NO_PROCESS_GROUP: - no_process_group = true; - break; - default: - d_fprintf(stderr, "\nInvalid option %s: %s\n\n", - poptBadOption(pc, 0), poptStrerror(opt)); - poptPrintUsage(pc, stderr, 0); - exit(1); - } + d_fprintf(stderr, "\nInvalid options\n\n"); + poptPrintUsage(pc, stderr, 0); + exit(1); }; poptFreeContext(pc); @@ -943,27 +888,20 @@ static bool open_sockets(bool isdaemon, int port) CatchChild(); log_stdout = (debug_get_log_type() == DEBUG_STDOUT); - if ( opt_interactive ) { - Fork = False; + if ( cmdline_daemon_cfg->interactive ) { log_stdout = True; } - if ( log_stdout && Fork ) { + if ( log_stdout && cmdline_daemon_cfg->fork ) { DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); exit(1); } - if (!log_stdout) { - setup_logging( argv[0], DEBUG_FILE); - } - reopen_logs(); DEBUG(0,("nmbd version %s started.\n", samba_version_string())); DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); - reopen_logs(); - if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC && !lp_parm_bool(-1, "server role check", "inhibit", false)) { /* TODO: when we have a merged set of defaults for @@ -1000,15 +938,17 @@ static bool open_sockets(bool isdaemon, int port) set_samba_nb_type(); - if (!is_daemon && !is_a_socket(0)) { + if (!cmdline_daemon_cfg->daemon && !is_a_socket(0)) { DEBUG(3, ("standard input is not a socket, assuming -D option\n")); - is_daemon = True; + cmdline_daemon_cfg->daemon = true; } - if (is_daemon && !opt_interactive) { + if (cmdline_daemon_cfg->daemon && !cmdline_daemon_cfg->interactive) { DEBUG(3, ("Becoming a daemon.\n")); - become_daemon(Fork, no_process_group, log_stdout); - } else if (!opt_interactive) { + become_daemon(cmdline_daemon_cfg->fork, + cmdline_daemon_cfg->no_process_group, + log_stdout); + } else if (!cmdline_daemon_cfg->interactive) { daemon_status("nmbd", "Starting process..."); } @@ -1017,8 +957,11 @@ static bool open_sockets(bool isdaemon, int port) * If we're interactive we want to set our own process group for * signal management. */ - if (opt_interactive && !no_process_group) + if (cmdline_daemon_cfg->interactive && + !cmdline_daemon_cfg->no_process_group) + { setpgid( (pid_t)0, (pid_t)0 ); + } #endif #ifndef SYNC_DNS @@ -1059,7 +1002,7 @@ static bool open_sockets(bool isdaemon, int port) if (!nmbd_setup_sig_term_handler(msg)) exit_daemon("NMBD failed to setup signal handler", EINVAL); - if (!nmbd_setup_stdin_handler(msg, !Fork)) + if (!nmbd_setup_stdin_handler(msg, !cmdline_daemon_cfg->fork)) exit_daemon("NMBD failed to setup stdin handler", EINVAL); if (!nmbd_setup_sig_hup_handler(msg)) exit_daemon("NMBD failed to setup SIGHUP handler", EINVAL); @@ -1086,7 +1029,7 @@ static bool open_sockets(bool isdaemon, int port) DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); - if ( !open_sockets( is_daemon, global_nmb_port ) ) { + if ( !open_sockets( cmdline_daemon_cfg->daemon, global_nmb_port ) ) { kill_async_dns_child(); return 1; } @@ -1136,7 +1079,7 @@ static bool open_sockets(bool isdaemon, int port) exit_daemon( "NMBD failed to setup packet server.", EACCES); } - if (!opt_interactive) { + if (!cmdline_daemon_cfg->interactive) { daemon_ready("nmbd"); } |