aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-12-07 16:21:11 +0100
committerThomas White <taw@physics.org>2021-12-07 17:19:42 +0100
commitfe938a0ad2af037fff80114ca2832d41dc48e55e (patch)
tree71d68e0f4e14f669b91d85f326f3dc4d562a88bc /src
parent681fbbe63fc58fe0783310f840f7de390470b351 (diff)
indexamajig: Shut down cleanly on SIGUSR1
Diffstat (limited to 'src')
-rw-r--r--src/im-sandbox.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/im-sandbox.c b/src/im-sandbox.c
index 1d334adb..9724c245 100644
--- a/src/im-sandbox.c
+++ b/src/im-sandbox.c
@@ -674,6 +674,13 @@ static void start_worker_process(struct sandbox *sb, int slot)
exit(1);
}
+ sa.sa_handler = SIG_IGN;
+ r = sigaction(SIGUSR1, &sa, NULL);
+ if ( r == -1 ) {
+ ERROR("Failed to set signal handler!\n");
+ exit(1);
+ }
+
ll = 64 + strlen(sb->tmpdir);
tmp = malloc(ll);
if ( tmp == NULL ) {
@@ -855,6 +862,7 @@ static int fill_queue(struct get_pattern_ctx *gpctx, struct sandbox *sb)
volatile sig_atomic_t at_zombies = 0;
volatile sig_atomic_t at_interrupt = 0;
+volatile sig_atomic_t at_shutdown = 0;
static void sigchld_handler(int sig, siginfo_t *si, void *uc_v)
{
@@ -868,6 +876,12 @@ static void sigint_handler(int sig, siginfo_t *si, void *uc_v)
}
+static void sigusr1_handler(int sig, siginfo_t *si, void *uc_v)
+{
+ at_shutdown = 1;
+}
+
+
static void check_signals(struct sandbox *sb, const char *semname_q,
int respawn)
{
@@ -880,6 +894,14 @@ static void check_signals(struct sandbox *sb, const char *semname_q,
sem_unlink(semname_q);
exit(0);
}
+
+ if ( at_shutdown ) {
+ at_shutdown = 0;
+ STATUS("Received signal - shutting down cleanly.\n");
+ pthread_mutex_lock(&sb->shared->totals_lock);
+ sb->shared->should_shutdown = 1;
+ pthread_mutex_unlock(&sb->shared->totals_lock);
+ }
}
@@ -1151,6 +1173,16 @@ int create_sandbox(struct index_args *iargs, int n_proc, char *prefix,
return 0;
}
+ /* Set up signal handler to shut down gracefully on request */
+ sa.sa_flags = SA_SIGINFO | SA_NOCLDSTOP | SA_RESTART;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_sigaction = sigusr1_handler;
+ r = sigaction(SIGUSR1, &sa, NULL);
+ if ( r == -1 ) {
+ ERROR("Failed to set signal handler!\n");
+ return 0;
+ }
+
taccs = time_accounts_init();
do {