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:
34
kdc/config.c
34
kdc/config.c
@@ -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)
|
||||
|
@@ -867,16 +867,17 @@ next_min_free(krb5_context context, struct descr **d, unsigned int *ndescr)
|
||||
}
|
||||
|
||||
void
|
||||
loop(krb5_context context,
|
||||
krb5_kdc_configuration *config)
|
||||
loop(krb5_context context, krb5_kdc_configuration *config)
|
||||
{
|
||||
struct descr *d;
|
||||
unsigned int ndescr;
|
||||
int ret;
|
||||
|
||||
ndescr = init_sockets(context, config, &d);
|
||||
if(ndescr <= 0)
|
||||
krb5_errx(context, 1, "No sockets!");
|
||||
kdc_log(context, config, 0, "KDC started");
|
||||
roken_detach_finish(NULL, daemon_child);
|
||||
while(exit_flag == 0){
|
||||
struct timeval tmout;
|
||||
fd_set fds;
|
||||
|
@@ -44,10 +44,8 @@ struct perf {
|
||||
struct perf *next;
|
||||
} *ptop;
|
||||
|
||||
#ifdef SUPPORT_DETACH
|
||||
int detach_from_console = -1;
|
||||
#define DETACH_IS_DEFAULT FALSE
|
||||
#endif
|
||||
int daemon_child = -1;
|
||||
|
||||
static krb5_kdc_configuration *kdc_config;
|
||||
static krb5_context kdc_context;
|
||||
|
@@ -99,12 +99,8 @@ extern krb5_addresses explicit_addresses;
|
||||
|
||||
extern int enable_http;
|
||||
|
||||
#ifdef SUPPORT_DETACH
|
||||
|
||||
#define DETACH_IS_DEFAULT FALSE
|
||||
|
||||
extern int detach_from_console;
|
||||
#endif
|
||||
extern int daemon_child;
|
||||
|
||||
extern const struct units _kdc_digestunits[];
|
||||
|
||||
|
@@ -44,9 +44,8 @@
|
||||
|
||||
sig_atomic_t exit_flag = 0;
|
||||
|
||||
#ifdef SUPPORT_DETACH
|
||||
int detach_from_console = -1;
|
||||
#endif
|
||||
int daemon_child = -1;
|
||||
|
||||
static RETSIGTYPE
|
||||
sigterm(int sig)
|
||||
@@ -105,7 +104,6 @@ switch_environment(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -157,10 +155,6 @@ main(int argc, char **argv)
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SUPPORT_DETACH
|
||||
if (detach_from_console)
|
||||
daemon(0, 0);
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
bonjour_announce(context, config);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user