From 3038d7a0017b729cecbf26d4757228e56e87ac9a Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Wed, 14 Sep 2011 16:12:36 +0000 Subject: [PATCH] Set up monitor signal handlers before forking This avoids a race condition where a child reports "starting..." and begins to service requests before the monitor is ready to handle termination signals. Really only an issue for the test suite. From npmccallum@redhat.com. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25177 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kdc/main.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/kdc/main.c b/src/kdc/main.c index 15a5a9ee7..bee5bd95a 100644 --- a/src/kdc/main.c +++ b/src/kdc/main.c @@ -543,6 +543,26 @@ create_workers(verto_ctx *ctx, int num) struct sigaction s_action; #endif /* POSIX_SIGNALS */ + /* + * Setup our signal handlers which will forward to the children. + * These handlers will be overriden in the child processes. + */ +#ifdef POSIX_SIGNALS + (void) sigemptyset(&s_action.sa_mask); + s_action.sa_flags = 0; + s_action.sa_handler = on_monitor_signal; + (void) sigaction(SIGINT, &s_action, (struct sigaction *) NULL); + (void) sigaction(SIGTERM, &s_action, (struct sigaction *) NULL); + (void) sigaction(SIGQUIT, &s_action, (struct sigaction *) NULL); + s_action.sa_handler = on_monitor_sighup; + (void) sigaction(SIGHUP, &s_action, (struct sigaction *) NULL); +#else /* POSIX_SIGNALS */ + signal(SIGINT, on_monitor_signal); + signal(SIGTERM, on_monitor_signal); + signal(SIGQUIT, on_monitor_signal); + signal(SIGHUP, on_monitor_sighup); +#endif /* POSIX_SIGNALS */ + /* Create child worker processes; return in each child. */ krb5_klog_syslog(LOG_INFO, _("creating %d worker processes"), num); pids = calloc(num, sizeof(pid_t)); @@ -580,23 +600,6 @@ create_workers(verto_ctx *ctx, int num) /* We're going to use our own main loop here. */ loop_free(ctx); - /* Setup our signal handlers which will forward to the children. */ -#ifdef POSIX_SIGNALS - (void) sigemptyset(&s_action.sa_mask); - s_action.sa_flags = 0; - s_action.sa_handler = on_monitor_signal; - (void) sigaction(SIGINT, &s_action, (struct sigaction *) NULL); - (void) sigaction(SIGTERM, &s_action, (struct sigaction *) NULL); - (void) sigaction(SIGQUIT, &s_action, (struct sigaction *) NULL); - s_action.sa_handler = on_monitor_sighup; - (void) sigaction(SIGHUP, &s_action, (struct sigaction *) NULL); -#else /* POSIX_SIGNALS */ - signal(SIGINT, on_monitor_signal); - signal(SIGTERM, on_monitor_signal); - signal(SIGQUIT, on_monitor_signal); - signal(SIGHUP, on_monitor_sighup); -#endif /* POSIX_SIGNALS */ - /* Supervise the worker processes. */ numleft = num; while (!signal_received) { -- 2.26.2