Daemons detach atomically to avoid having to wait
Tests that start daemons have to "wait" for them to start. This commit makes Heimdal daemons prep to detach (when requested) by forking early, then having the child signal readiness to the parent when the child really is ready. The parent exits only which the child is ready. This means that tests will no longer need to wait for daemons. However, tests will still need a pidfile or such so they can stop the daemons. Note that the --detach options should not be used on OS X from launchd, only from tests.
This commit is contained in:
@@ -514,9 +514,8 @@ static int version_flag;
|
||||
static int help_flag;
|
||||
static char *keytab_str;
|
||||
static char *port_str;
|
||||
#ifdef SUPPORT_DETACH
|
||||
static int detach_from_console = 0;
|
||||
#endif
|
||||
static int detach_from_console;
|
||||
static int daemon_child = -1;
|
||||
|
||||
static struct getargs args[] = {
|
||||
{ "config-file", 'c', arg_string, &config_file, NULL, NULL },
|
||||
@@ -529,10 +528,10 @@ static struct getargs args[] = {
|
||||
"file to write out status into", "file" },
|
||||
{ "port", 0, arg_string, &port_str,
|
||||
"port ipropd-slave will connect to", "port"},
|
||||
#ifdef SUPPORT_DETACH
|
||||
{ "detach", 0, arg_flag, &detach_from_console,
|
||||
"detach from console", NULL },
|
||||
#endif
|
||||
{ "daemon-child", 0 , arg_integer, &daemon_child,
|
||||
"private argument, do not use", NULL },
|
||||
{ "hostname", 0, arg_string, rk_UNCONST(&slave_str),
|
||||
"hostname of slave (if not same as hostname)", "hostname" },
|
||||
{ "version", 0, arg_flag, &version_flag, NULL, NULL },
|
||||
@@ -572,16 +571,21 @@ main(int argc, char **argv)
|
||||
|
||||
setprogname(argv[0]);
|
||||
|
||||
if(getarg(args, num_args, argc, argv, &optidx))
|
||||
if (getarg(args, num_args, argc, argv, &optidx))
|
||||
usage(1);
|
||||
|
||||
if(help_flag)
|
||||
if (help_flag)
|
||||
usage(0);
|
||||
if(version_flag) {
|
||||
|
||||
if (version_flag) {
|
||||
print_version(NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (detach_from_console && daemon_child == -1)
|
||||
roken_detach_prep(argc, argv, "--daemon-child");
|
||||
pidfile(NULL);
|
||||
|
||||
ret = krb5_init_context(&context);
|
||||
if (ret)
|
||||
errx (1, "krb5_init_context failed: %d", ret);
|
||||
@@ -616,17 +620,7 @@ main(int argc, char **argv)
|
||||
krb5_errx(context, 1, "can't allocate status file buffer");
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_DETACH
|
||||
if (detach_from_console){
|
||||
int aret = daemon(0, 0);
|
||||
if (aret == -1) {
|
||||
/* not much to do if detaching fails... */
|
||||
krb5_err(context, 1, aret, "failed to daemon(3)ise");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
pidfile (NULL);
|
||||
krb5_openlog (context, "ipropd-slave", &log_facility);
|
||||
krb5_openlog(context, "ipropd-slave", &log_facility);
|
||||
krb5_set_warn_dest(context, log_facility);
|
||||
|
||||
slave_status(context, status_file, "bootstrapping");
|
||||
@@ -683,6 +677,8 @@ main(int argc, char **argv)
|
||||
|
||||
slave_status(context, status_file, "ipropd-slave started");
|
||||
|
||||
roken_detach_finish(NULL, daemon_child);
|
||||
|
||||
while (!exit_flag) {
|
||||
time_t now, elapsed;
|
||||
int connected = FALSE;
|
||||
|
Reference in New Issue
Block a user