From: Ralph Boehme Date: Thu, 11 Nov 2021 04:23:09 +0000 (+0100) Subject: samba-bgqd: fix startup and logging X-Git-Tag: ldb-2.5.0~97 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=54f54fc2627acbf5fac5e1fa86ab9f743741f3c4;p=thirdparty%2Fsamba.git samba-bgqd: fix startup and logging Let samba-bgqd use the new POPT_COMMON_DAEMON infrastructure. The calls to setup_logging() can safely be removed as this is already taken care of by samba_cmdline_init(). To avoid a logfile basename of ".log" when using "%m", we add a call to set_remote_machine_name(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=14897 Signed-off-by: Ralph Boehme Reviewed-by: Andreas Schneider --- diff --git a/source3/printing/samba-bgqd.c b/source3/printing/samba-bgqd.c index 336a007ab9a..f21327fc622 100644 --- a/source3/printing/samba-bgqd.c +++ b/source3/printing/samba-bgqd.c @@ -41,6 +41,7 @@ #include "source3/lib/util_procid.h" #include "source3/auth/proto.h" #include "source3/printing/queue_process.h" +#include "source3/lib/substitute.h" static void watch_handler(struct tevent_req *req) { @@ -158,6 +159,7 @@ static int samba_bgqd_pidfile_create( int main(int argc, const char *argv[]) { + struct samba_cmdline_daemon_cfg *cmdline_daemon_cfg = NULL; const struct loadparm_substitution *lp_sub = loadparm_s3_global_substitution(); const char *progname = getprogname(); @@ -168,8 +170,6 @@ int main(int argc, const char *argv[]) struct tevent_req *watch_req = NULL; struct tevent_signal *sigterm_handler = NULL; struct bq_state *bq = NULL; - int foreground = 0; - int no_process_group = 0; int log_stdout = 0; int ready_signal_fd = -1; int watch_fd = -1; @@ -182,21 +182,7 @@ int main(int argc, const char *argv[]) struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_SAMBA - { - .longName = "foreground", - .shortName = 'F', - .argInfo = POPT_ARG_NONE, - .arg = &foreground, - .descrip = "Run daemon in foreground " - "(for daemontools, etc.)", - }, - { - .longName = "no-process-group", - .shortName = '\0', - .argInfo = POPT_ARG_NONE, - .arg = &no_process_group, - .descrip = "Don't create a new process group" , - }, + POPT_COMMON_DAEMON /* * File descriptor to write the PID of the helper @@ -234,6 +220,7 @@ int main(int argc, const char *argv[]) talloc_enable_null_tracking(); frame = talloc_stackframe(); umask(0); + set_remote_machine_name("smbd-bgqd", true); ok = samba_cmdline_init(frame, SAMBA_CMDLINE_CONFIG_SERVER, @@ -243,6 +230,8 @@ int main(int argc, const char *argv[]) exit(ENOMEM); } + cmdline_daemon_cfg = samba_cmdline_get_daemon_cfg(); + pc = samba_popt_get_context(progname, argc, argv, @@ -263,16 +252,12 @@ int main(int argc, const char *argv[]) log_stdout = (debug_get_log_type() == DEBUG_STDOUT); - if (foreground) { + if (!cmdline_daemon_cfg->fork) { daemon_status(progname, "Starting process ... "); } else { - become_daemon(true, no_process_group, log_stdout); - } - - if (log_stdout) { - setup_logging(progname, DEBUG_STDOUT); - } else { - setup_logging(progname, DEBUG_FILE); + become_daemon(true, + cmdline_daemon_cfg->no_process_group, + log_stdout); } BlockSignals(true, SIGPIPE);