int argc,
const char *argv[])
{
- bool opt_daemon = false;
- bool opt_fork = true;
- bool opt_interactive = false;
- bool opt_no_process_group = false;
+ struct samba_cmdline_daemon_cfg *cmdline_daemon_cfg = NULL;
bool db_is_backup = false;
int opt;
int ret;
int max_runtime = 0;
struct stat st;
enum {
- OPT_DAEMON = 1000,
- OPT_FOREGROUND,
- OPT_INTERACTIVE,
- OPT_PROCESS_MODEL,
+ OPT_PROCESS_MODEL = 1000,
OPT_SHOW_BUILD,
- OPT_NO_PROCESS_GROUP,
};
struct poptOption long_options[] = {
POPT_AUTOHELP
- {
- .longName = "daemon",
- .shortName = 'D',
- .argInfo = POPT_ARG_NONE,
- .val = OPT_DAEMON,
- .descrip = "Become a daemon (default)",
- },
- {
- .longName = "foreground",
- .shortName = 'F',
- .argInfo = POPT_ARG_NONE,
- .val = OPT_FOREGROUND,
- .descrip = "Run the daemon in foreground",
- },
- {
- .longName = "interactive",
- .shortName = 'i',
- .argInfo = POPT_ARG_NONE,
- .val = OPT_INTERACTIVE,
- .descrip = "Run interactive (not a daemon)",
- },
{
.longName = "model",
.shortName = 'M',
.val = OPT_SHOW_BUILD,
.descrip = "show build info",
},
- {
- .longName = "no-process-group",
- .argInfo = POPT_ARG_NONE,
- .val = OPT_NO_PROCESS_GROUP,
- .descrip = "Don't create a new process group",
- },
POPT_COMMON_SAMBA
+ POPT_COMMON_DAEMON
POPT_COMMON_VERSION
POPT_TABLEEND
};
struct tevent_signal *se = NULL;
struct samba_tevent_trace_state *samba_tevent_trace_state = NULL;
struct loadparm_context *lp_ctx = NULL;
- bool log_stdout = false;
bool ok;
setproctitle("root process");
exit(1);
}
+ cmdline_daemon_cfg = samba_cmdline_get_daemon_cfg();
+
pc = samba_popt_get_context(binary_name,
argc,
argv,
while((opt = poptGetNextOpt(pc)) != -1) {
switch(opt) {
- case OPT_DAEMON:
- opt_daemon = true;
- break;
- case OPT_FOREGROUND:
- opt_fork = false;
- break;
- case OPT_INTERACTIVE:
- opt_interactive = true;
- break;
case OPT_PROCESS_MODEL:
model = poptGetOptArg(pc);
break;
case OPT_SHOW_BUILD:
show_build();
break;
- case OPT_NO_PROCESS_GROUP:
- opt_no_process_group = true;
- break;
default:
fprintf(stderr, "\nInvalid option %s: %s\n\n",
poptBadOption(pc, 0), poptStrerror(opt));
}
}
- if (opt_daemon && opt_interactive) {
+ if (cmdline_daemon_cfg->daemon && cmdline_daemon_cfg->interactive) {
fprintf(stderr,"\nERROR: "
"Option -i|--interactive is "
"not allowed together with -D|--daemon\n\n");
poptPrintUsage(pc, stderr, 0);
return 1;
- } else if (!opt_interactive && opt_fork) {
+ } else if (!cmdline_daemon_cfg->interactive &&
+ cmdline_daemon_cfg->fork) {
/* default is --daemon */
- opt_daemon = true;
+ cmdline_daemon_cfg->daemon = true;
}
poptFreeContext(pc);
talloc_enable_null_tracking();
- log_stdout = (debug_get_log_type() == DEBUG_STDOUT);
- if (opt_interactive) {
- log_stdout = true;
- }
-
- if (log_stdout) {
- setup_logging(binary_name, DEBUG_STDOUT);
- } else {
- setup_logging(binary_name, DEBUG_FILE);
- }
setup_signals();
/* we want total control over the permissions on created files,
return 1;
}
- if (opt_daemon) {
+ if (cmdline_daemon_cfg->daemon) {
DBG_NOTICE("Becoming a daemon.\n");
- become_daemon(opt_fork, opt_no_process_group, false);
- } else if (!opt_interactive) {
+ become_daemon(cmdline_daemon_cfg->fork,
+ cmdline_daemon_cfg->no_process_group,
+ false);
+ } else if (!cmdline_daemon_cfg->interactive) {
daemon_status("samba", "Starting process...");
}
samba_tevent_trace_callback,
samba_tevent_trace_state);
- if (opt_interactive) {
+ if (cmdline_daemon_cfg->interactive) {
/* terminate when stdin goes away */
stdin_event_flags = TEVENT_FD_READ;
} else {
* If we're interactive we want to set our own process group for
* signal management, unless --no-process-group specified.
*/
- if (opt_interactive && !opt_no_process_group)
+ if (cmdline_daemon_cfg->interactive &&
+ !cmdline_daemon_cfg->no_process_group)
+ {
setpgid((pid_t)0, (pid_t)0);
+ }
#endif
/* catch EOF on stdin */
}
}
- if (!opt_interactive) {
+ if (!cmdline_daemon_cfg->interactive) {
daemon_ready("samba");
}