summaryrefslogtreecommitdiff
path: root/src/irmd/main.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-04-06 12:22:50 +0200
committerdimitri staessens <[email protected]>2017-04-06 13:24:23 +0200
commit5cae5b510f3fab0d4ed0ac303b7a7f3b99e9ffe7 (patch)
treeb5d17f117b4c189e2c993c3f3a9c992920058c82 /src/irmd/main.c
parente1c0714d5827cd927961f3a687d9720e6e9aa802 (diff)
downloadouroboros-5cae5b510f3fab0d4ed0ac303b7a7f3b99e9ffe7.tar.gz
ouroboros-5cae5b510f3fab0d4ed0ac303b7a7f3b99e9ffe7.zip
irmd: Prevent impatient user deadlock on shutdown
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r--src/irmd/main.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 41beb049..f9acb238 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1584,6 +1584,14 @@ void irmd_sig_handler(int sig,
case SIGINT:
case SIGTERM:
case SIGHUP:
+ pthread_rwlock_rdlock(&irmd.state_lock);
+ if (irmd.state == IRMD_NULL) {
+ log_info("Patience is bitter, but its fruit is sweet.");
+ pthread_rwlock_unlock(&irmd.state_lock);
+ return;
+ }
+ pthread_rwlock_unlock(&irmd.state_lock);
+
log_info("IRMd shutting down...");
pthread_rwlock_wrlock(&irmd.state_lock);
@@ -2293,6 +2301,12 @@ int main(int argc,
char ** argv)
{
struct sigaction sig_act;
+ sigset_t sigset;
+ sigemptyset(&sigset);
+ sigaddset(&sigset, SIGINT);
+ sigaddset(&sigset, SIGQUIT);
+ sigaddset(&sigset, SIGHUP);
+ sigaddset(&sigset, SIGPIPE);
bool use_stdout = false;
@@ -2348,8 +2362,12 @@ int main(int argc,
pthread_cancel(irmd.shm_sanitize);
pthread_join(irmd.shm_sanitize, NULL);
+ pthread_sigmask(SIG_BLOCK, &sigset, NULL);
+
irm_fini();
+ pthread_sigmask(SIG_UNBLOCK, &sigset, NULL);
+
log_fini();
log_info("Bye.");