[SCM] Samba Shared Repository - branch master updated
Ralph Böhme
slow at samba.org
Mon Sep 6 14:24:02 UTC 2021
The branch, master has been updated
via 28686f87139 s4/samba: POPT_COMMON_DAEMON
via 9d82454cdfc winbindd: use POPT_COMMON_DAEMON
via a20f63b3847 nmbd: use POPT_COMMON_DAEMON
via ae22442db43 smbd: use POPT_COMMON_DAEMON
via 877183ac0b5 lib/cmdline: restore pre-4.15 logging behaviour for daemons
via aaa3c6a4132 lib/cmdline: add POPT_COMMON_DAEMON daemon popt options
from 2f2c53c4f8f s3: smbd: Fix openat_pathref_fsp() to cope with FIFO's in the filesystem.
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 28686f8713958726085bd38a0889aa7725c95371
Author: Ralph Boehme <slow at samba.org>
Date: Fri Sep 3 14:04:22 2021 +0200
s4/samba: POPT_COMMON_DAEMON
Note: this also changes logging to go to stderr instead of stdout which is the
same behaviour as smbd, nmbd and winbindd (starting with 4.15).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14803
RN: smbd/winbindd started in daemon mode generate output on stderr/stdout
Signed-off-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
Autobuild-User(master): Ralph Böhme <slow at samba.org>
Autobuild-Date(master): Mon Sep 6 14:23:15 UTC 2021 on sn-devel-184
commit 9d82454cdfc2b4b8007c7b54b3afd5686f49be19
Author: Ralph Boehme <slow at samba.org>
Date: Fri Sep 3 12:25:00 2021 +0200
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 at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
commit a20f63b384750d389aeafd4bd5e229aed72cb271
Author: Ralph Boehme <slow at samba.org>
Date: Fri Sep 3 12:14:19 2021 +0200
nmbd: use POPT_COMMON_DAEMON
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14803
Signed-off-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
commit ae22442db437061aada6427adde205cd13f1d202
Author: Ralph Boehme <slow at samba.org>
Date: Fri Sep 3 07:33:39 2021 +0200
smbd: use POPT_COMMON_DAEMON
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14803
Signed-off-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
commit 877183ac0b57f5b2902446e41bb6ab3191f84fa6
Author: Ralph Boehme <slow at samba.org>
Date: Fri Sep 3 07:28:45 2021 +0200
lib/cmdline: restore pre-4.15 logging behaviour for daemons
For servers ensure logging is configured to go to a logfile unless in
interactive mode by calling setup_logging() before lp_load_global() is
called.
In 4.14 servers had the chance to call setup_logging(getprogname(),
DEBUG_FILE) before they called lp_load_*() explicitly in the server.
Now in 4.15 lp_load_*() is called internally when parsing the command
line arguments triggered by the server running the poptGetNextOpt()
loop, so it's too late when the server calls
setup_logging(getprogname(), DEBUG_FILE) as lots of debugging from
lp_load_()* was already written to DEBUG_DEFAULT_STDERR.
Note that there's a chicken and egg problem *within* this patchset:
this change here breaks stdout logging for servers until the servers
are converted to use the new POPT_COMMON_DAEMON. The only way to
address that would be squashing all changes into one patchset, but for
the sake of reviewability (is that an actual english word? :)) I chose
to split the changes.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14803
Signed-off-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
commit aaa3c6a4132d2e739958e168e7dc3e78dfa4a72e
Author: Ralph Boehme <slow at samba.org>
Date: Fri Sep 3 07:22:18 2021 +0200
lib/cmdline: add POPT_COMMON_DAEMON daemon popt options
Note: interactive=true implies fork=false. This matches the semantics
that currently 3/4 daemons implement manually.
Not used so far, no change in behaviour.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14803
Signed-off-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
-----------------------------------------------------------------------
Summary of changes:
lib/cmdline/cmdline.c | 80 ++++++++++++++++++++++++++++++
lib/cmdline/cmdline.h | 29 +++++++++++
lib/cmdline/cmdline_private.h | 4 ++
lib/cmdline/cmdline_s3.c | 11 ++++-
source3/nmbd/nmbd.c | 103 +++++++++-----------------------------
source3/smbd/server.c | 112 +++++++++++++-----------------------------
source3/winbindd/winbindd.c | 88 +++++++++------------------------
source4/samba/server.c | 88 ++++++++-------------------------
8 files changed, 223 insertions(+), 292 deletions(-)
Changeset truncated at 500 lines:
diff --git a/lib/cmdline/cmdline.c b/lib/cmdline/cmdline.c
index a0a55f4dcfb..a299a229f69 100644
--- a/lib/cmdline/cmdline.c
+++ b/lib/cmdline/cmdline.c
@@ -28,6 +28,7 @@ static TALLOC_CTX *cmdline_mem_ctx;
static struct loadparm_context *cmdline_lp_ctx;
static struct cli_credentials *cmdline_creds;
static samba_cmdline_load_config cmdline_load_config_fn;
+static struct samba_cmdline_daemon_cfg cmdline_daemon_cfg;
/* PRIVATE */
bool samba_cmdline_set_talloc_ctx(TALLOC_CTX *mem_ctx)
@@ -59,6 +60,10 @@ bool samba_cmdline_init_common(TALLOC_CTX *mem_ctx)
return false;
}
+ cmdline_daemon_cfg = (struct samba_cmdline_daemon_cfg) {
+ .fork = true,
+ };
+
fault_setup();
/*
@@ -112,6 +117,11 @@ struct cli_credentials *samba_cmdline_get_creds(void)
return cmdline_creds;
}
+struct samba_cmdline_daemon_cfg *samba_cmdline_get_daemon_cfg(void)
+{
+ return &cmdline_daemon_cfg;
+}
+
void samba_cmdline_burn(int argc, char *argv[])
{
bool found = false;
@@ -1134,6 +1144,73 @@ static struct poptOption popt_common_version[] = {
POPT_TABLEEND
};
+/**********************************************************
+ * DAEMON POPT
+ **********************************************************/
+
+static void popt_daemon_callback(poptContext ctx,
+ enum poptCallbackReason reason,
+ const struct poptOption *opt,
+ const char *arg,
+ const void *data)
+{
+ switch(opt->val) {
+ case OPT_DAEMON:
+ cmdline_daemon_cfg.daemon = true;
+ break;
+ case OPT_INTERACTIVE:
+ cmdline_daemon_cfg.interactive = true;
+ cmdline_daemon_cfg.fork = false;
+ break;
+ case OPT_FORK:
+ cmdline_daemon_cfg.fork = false;
+ break;
+ case OPT_NO_PROCESS_GROUP:
+ cmdline_daemon_cfg.no_process_group = true;
+ break;
+ }
+}
+
+static struct poptOption popt_common_daemon[] = {
+ {
+ .argInfo = POPT_ARG_CALLBACK,
+ .arg = (void *)popt_daemon_callback
+ },
+ {
+ .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) and log to stdout",
+ },
+ {
+ .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" ,
+ },
+ POPT_TABLEEND
+};
+
/**********************************************************
* LEGACY S3 POPT
**********************************************************/
@@ -1270,6 +1347,9 @@ struct poptOption *samba_cmdline_get_popt(enum smb_cmdline_popt_options opt)
case SAMBA_CMDLINE_POPT_OPT_VERSION:
return popt_common_version;
break;
+ case SAMBA_CMDLINE_POPT_OPT_DAEMON:
+ return popt_common_daemon;
+ break;
case SAMBA_CMDLINE_POPT_OPT_SAMBA_LDB:
return popt_common_samba_ldb;
break;
diff --git a/lib/cmdline/cmdline.h b/lib/cmdline/cmdline.h
index 3c0c9e8c18d..1f85da0099e 100644
--- a/lib/cmdline/cmdline.h
+++ b/lib/cmdline/cmdline.h
@@ -46,11 +46,19 @@ enum smb_cmdline_popt_options {
SAMBA_CMDLINE_POPT_OPT_CONNECTION,
SAMBA_CMDLINE_POPT_OPT_CREDENTIALS,
SAMBA_CMDLINE_POPT_OPT_VERSION,
+ SAMBA_CMDLINE_POPT_OPT_DAEMON,
SAMBA_CMDLINE_POPT_OPT_SAMBA_LDB,
SAMBA_CMDLINE_POPT_OPT_LEGACY_S3,
SAMBA_CMDLINE_POPT_OPT_LEGACY_S4,
};
+struct samba_cmdline_daemon_cfg {
+ bool daemon;
+ bool interactive;
+ bool fork;
+ bool no_process_group;
+};
+
/**
* @brief Initialize the commandline interface for parsing options.
*
@@ -114,6 +122,15 @@ struct cli_credentials *samba_cmdline_get_creds(void);
*/
struct poptOption *samba_cmdline_get_popt(enum smb_cmdline_popt_options opt);
+/**
+ * @brief Get a pointer to the poptOptions for daemons
+ *
+ * @return A pointer to the daemon options
+ *
+ * @see POPT_COMMON_DAEMON
+ */
+struct samba_cmdline_daemon_cfg *samba_cmdline_get_daemon_cfg(void);
+
/**
* @brief Burn secrets on the command line.
*
@@ -249,6 +266,18 @@ poptContext samba_popt_get_context(const char * name,
.descrip = "Version options:", \
.argDescrip = NULL },
+/**
+ * @brief A popt structure for daemon options.
+ */
+#define POPT_COMMON_DAEMON { \
+ .longName = NULL, \
+ .shortName = '\0', \
+ .argInfo = POPT_ARG_INCLUDE_TABLE, \
+ .arg = samba_cmdline_get_popt(SAMBA_CMDLINE_POPT_OPT_DAEMON), \
+ .val = 0, \
+ .descrip = "Daemon options:", \
+ .argDescrip = NULL },
+
/**
* @brief A popt structure for common samba options.
*/
diff --git a/lib/cmdline/cmdline_private.h b/lib/cmdline/cmdline_private.h
index 2261e753447..b1584e020dc 100644
--- a/lib/cmdline/cmdline_private.h
+++ b/lib/cmdline/cmdline_private.h
@@ -34,6 +34,10 @@ enum {
OPT_USE_KERBEROS_CCACHE,
OPT_USE_WINBIND_CCACHE,
OPT_CLIENT_PROTECTION,
+ OPT_DAEMON,
+ OPT_INTERACTIVE,
+ OPT_FORK,
+ OPT_NO_PROCESS_GROUP,
};
typedef bool (*samba_cmdline_load_config)(void);
diff --git a/lib/cmdline/cmdline_s3.c b/lib/cmdline/cmdline_s3.c
index 70fd768a648..1f8d9ed5eb5 100644
--- a/lib/cmdline/cmdline_s3.c
+++ b/lib/cmdline/cmdline_s3.c
@@ -55,10 +55,19 @@ static bool _samba_cmdline_load_config_s3(void)
case SAMBA_CMDLINE_CONFIG_CLIENT:
ok = lp_load_client(config_file);
break;
- case SAMBA_CMDLINE_CONFIG_SERVER:
+ case SAMBA_CMDLINE_CONFIG_SERVER:
+ {
+ const struct samba_cmdline_daemon_cfg *cmdline_daemon_cfg =
+ samba_cmdline_get_daemon_cfg();
+
+ if (!cmdline_daemon_cfg->interactive) {
+ setup_logging(getprogname(), DEBUG_FILE);
+ }
+
ok = lp_load_global(config_file);
break;
}
+ }
if (!ok) {
fprintf(stderr,
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,56 +771,14 @@ 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',
@@ -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");
}
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index e40cc27d2b8..b9fb7e855b8 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1538,10 +1538,7 @@ extern void build_options(bool screen);
int main(int argc,const char *argv[])
{
/* shall I run as a daemon */
- bool is_daemon = false;
- bool interactive = false;
- bool Fork = true;
- bool no_process_group = false;
+ struct samba_cmdline_daemon_cfg *cmdline_daemon_cfg = NULL;
bool log_stdout = false;
char *ports = NULL;
char *profile_level = NULL;
@@ -1550,46 +1547,8 @@ extern void build_options(bool screen);
bool print_build_options = False;
bool serving_printers = false;
struct server_id main_server_id = {0};
- 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) and log to stdout",
- },
- {
- .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 = "build-options",
.shortName = 'b',
@@ -1615,6 +1574,7 @@ extern void build_options(bool screen);
.descrip = "Set profiling level","PROFILE_LEVEL",
},
POPT_COMMON_SAMBA
+ POPT_COMMON_DAEMON
POPT_COMMON_VERSION
POPT_TABLEEND
};
@@ -1674,6 +1634,8 @@ extern void build_options(bool screen);
exit(ENOMEM);
}
+ cmdline_daemon_cfg = samba_cmdline_get_daemon_cfg();
+
pc = samba_popt_get_context(getprogname(),
argc,
argv,
@@ -1686,18 +1648,6 @@ extern void build_options(bool screen);
--
Samba Shared Repository
More information about the samba-cvs
mailing list