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:
Nicolas Williams
2015-03-17 16:03:15 -05:00
parent 0778b19c3f
commit b48bed5f42
25 changed files with 522 additions and 197 deletions

View File

@@ -94,19 +94,14 @@ static struct getargs args[] = {
{ "ports", 'P', arg_string, rk_UNCONST(&port_str),
"ports to listen to", "portspec"
},
#ifdef SUPPORT_DETACH
#if DETACH_IS_DEFAULT
{
"detach", 'D', arg_negative_flag, &detach_from_console,
"don't detach from console", NULL
},
#else
{
"detach", 0 , arg_flag, &detach_from_console,
"detach from console", NULL
},
#endif
#endif
{
"daemon-child", 0 , arg_flag, &daemon_child,
"private argument, do not use", NULL
},
{ "addresses", 0, arg_strings, &addresses_str,
"addresses to listen on", "list of addresses" },
{ "disable-des", 0, arg_flag, &disable_des,
@@ -158,10 +153,10 @@ configure(krb5_context context, int argc, char **argv, int *optidx)
*optidx = 0;
while(getarg(args, num_args, argc, argv, optidx))
while (getarg(args, num_args, argc, argv, optidx))
warnx("error at argument `%s'", argv[*optidx]);
if(help_flag)
if (help_flag)
usage (0);
if (version_flag) {
@@ -179,6 +174,15 @@ configure(krb5_context context, int argc, char **argv, int *optidx)
exit(0);
}
if(detach_from_console == -1)
detach_from_console = krb5_config_get_bool_default(context, NULL,
FALSE,
"kdc",
"detach", NULL);
if (detach_from_console && daemon_child == -1)
roken_detach_prep(argc, argv, "--daemon-child");
{
char **files;
int aret;
@@ -265,14 +269,6 @@ configure(krb5_context context, int argc, char **argv, int *optidx)
krb5_errx(context, 1, "enforce-transited-policy deprecated, "
"use [kdc]transited-policy instead");
#ifdef SUPPORT_DETACH
if(detach_from_console == -1)
detach_from_console = krb5_config_get_bool_default(context, NULL,
DETACH_IS_DEFAULT,
"kdc",
"detach", NULL);
#endif /* SUPPORT_DETACH */
if(max_request_tcp == 0)
max_request_tcp = 64 * 1024;
if(max_request_udp == 0)