diff options
author | Greg Hudson <ghudson@mit.edu> | 2011-09-14 16:12:36 +0000 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2011-09-14 16:12:36 +0000 |
commit | 3038d7a0017b729cecbf26d4757228e56e87ac9a (patch) | |
tree | 12a052d9bde8aa2512abe355bbec1c099f069431 | |
parent | 232ee45a29845cc8b31955bdc398ac335421e63c (diff) | |
download | krb5-3038d7a0017b729cecbf26d4757228e56e87ac9a.tar.gz krb5-3038d7a0017b729cecbf26d4757228e56e87ac9a.tar.xz krb5-3038d7a0017b729cecbf26d4757228e56e87ac9a.zip |
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
-rw-r--r-- | src/kdc/main.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/kdc/main.c b/src/kdc/main.c index 15a5a9ee7f..bee5bd95ac 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) { |