diff options
author | Ralph Boehme <slow@samba.org> | 2021-09-03 12:25:00 +0200 |
---|---|---|
committer | Jule Anger <janger@samba.org> | 2021-09-06 19:17:11 +0000 |
commit | c65fb0b0a0e2867c0656bb5a84606f70d02dbe65 (patch) | |
tree | d6b32bfcf90dcd831d4b6fbeabd74db210b5d0d0 /source3 | |
parent | 3eef217a9daba415774680b4f4c0bf1188909edd (diff) | |
download | samba-c65fb0b0a0e2867c0656bb5a84606f70d02dbe65.tar.gz |
winbindd: use POPT_COMMON_DAEMON
Note: this also changes logging to go to stderr instead of stdout which is the
same behaviour as smbd and nmbd (starting with 4.15).
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 9d82454cdfc2b4b8007c7b54b3afd5686f49be19)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/winbindd/winbindd.c | 88 |
1 files changed, 23 insertions, 65 deletions
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index cb793cf182c..8c35b8eae76 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -1594,50 +1594,11 @@ static void winbindd_addr_changed(struct tevent_req *req) int main(int argc, const char **argv) { - static bool is_daemon = False; - static bool Fork = True; static bool log_stdout = False; - static bool no_process_group = False; - enum { - OPT_DAEMON = 1000, - OPT_FORK, - OPT_NO_PROCESS_GROUP - }; + struct samba_cmdline_daemon_cfg *cmdline_daemon_cfg = NULL; struct poptOption long_options[] = { POPT_AUTOHELP { - .longName = "foreground", - .shortName = 'F', - .argInfo = POPT_ARG_NONE, - .arg = NULL, - .val = OPT_FORK, - .descrip = "Daemon in foreground mode", - }, - { - .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 = "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 = 'i', - .descrip = "Interactive mode", - }, - { .longName = "no-caching", .shortName = 'n', .argInfo = POPT_ARG_NONE, @@ -1646,6 +1607,7 @@ int main(int argc, const char **argv) .descrip = "Disable caching", }, POPT_COMMON_SAMBA + POPT_COMMON_DAEMON POPT_COMMON_VERSION POPT_TABLEEND }; @@ -1693,6 +1655,8 @@ int main(int argc, const char **argv) exit(1); } + cmdline_daemon_cfg = samba_cmdline_get_daemon_cfg(); + pc = samba_popt_get_context(getprogname(), argc, argv, long_options, 0); if (pc == NULL) { DBG_ERR("Failed to setup popt parser!\n"); @@ -1702,19 +1666,6 @@ int main(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { - /* Don't become a daemon */ - case OPT_DAEMON: - is_daemon = True; - break; - case 'i': - interactive = True; - break; - case OPT_FORK: - Fork = false; - break; - case OPT_NO_PROCESS_GROUP: - no_process_group = true; - break; case 'n': opt_nocache = true; break; @@ -1739,7 +1690,7 @@ int main(int argc, const char **argv) set_remote_machine_name("winbindd", False); dump_core_setup("winbindd", lp_logfile(talloc_tos(), lp_sub)); - if (is_daemon && interactive) { + if (cmdline_daemon_cfg->daemon && cmdline_daemon_cfg->interactive) { d_fprintf(stderr,"\nERROR: " "Option -i|--interactive is not allowed together with -D|--daemon\n\n"); poptPrintUsage(pc, stderr, 0); @@ -1747,12 +1698,18 @@ int main(int argc, const char **argv) } log_stdout = (debug_get_log_type() == DEBUG_STDOUT); - if (interactive) { - Fork = true; + if (cmdline_daemon_cfg->interactive) { + /* + * libcmdline POPT_DAEMON callback sets "fork" to false if "-i" + * for interactive is passed on the commandline. Set it back to + * true. TODO: check if this is correct, smbd and nmbd don't do + * this. + */ + cmdline_daemon_cfg->fork = true; log_stdout = true; } - if (log_stdout && Fork) { + if (log_stdout && cmdline_daemon_cfg->fork) { d_fprintf(stderr, "\nERROR: " "Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n\n"); poptPrintUsage(pc, stderr, 0); @@ -1770,11 +1727,6 @@ int main(int argc, const char **argv) } } - if (log_stdout) { - setup_logging("winbindd", DEBUG_STDOUT); - } else { - setup_logging("winbindd", DEBUG_FILE); - } reopen_logs(); DEBUG(0,("winbindd version %s started.\n", samba_version_string())); @@ -1938,7 +1890,9 @@ int main(int argc, const char **argv) BlockSignals(False, SIGCHLD); if (!interactive) { - become_daemon(Fork, no_process_group, log_stdout); + become_daemon(cmdline_daemon_cfg->fork, + cmdline_daemon_cfg->no_process_group, + log_stdout); } else { daemon_status("winbindd", "Starting process ..."); } @@ -1950,8 +1904,11 @@ int main(int argc, const char **argv) * If we're interactive we want to set our own process group for * signal management. */ - if (interactive && !no_process_group) + if (cmdline_daemon_cfg->interactive && + !cmdline_daemon_cfg->no_process_group) + { setpgid( (pid_t)0, (pid_t)0); + } #endif TimeInit(); @@ -1985,7 +1942,8 @@ int main(int argc, const char **argv) exit_daemon(nt_errstr(status), map_errno_from_nt_status(status)); } - winbindd_register_handlers(global_messaging_context(), !Fork); + winbindd_register_handlers(global_messaging_context(), + !cmdline_daemon_cfg->fork); if (!messaging_parent_dgm_cleanup_init(global_messaging_context())) { exit(1); |