samba-bgqd: fix startup and logging
authorRalph Boehme <slow@samba.org>
Thu, 11 Nov 2021 04:23:09 +0000 (05:23 +0100)
committerRalph Boehme <slow@samba.org>
Thu, 11 Nov 2021 13:49:32 +0000 (13:49 +0000)
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 <slow@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/printing/samba-bgqd.c

index 336a007ab9aa19111667bb46504f056c8584baf4..f21327fc6229fb75917d505caf79293ecaac5f39 100644 (file)
@@ -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);