summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-04-06 11:31:39 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-04-06 11:31:39 +0000
commitffd9b03b88c1593840a4f05d93d4f764b48a46f2 (patch)
treeb5d17f117b4c189e2c993c3f3a9c992920058c82 /src/irmd
parent34ef0da6c1b3a3419dbdf2041ed1e3ba107dc915 (diff)
parent5cae5b510f3fab0d4ed0ac303b7a7f3b99e9ffe7 (diff)
downloadouroboros-ffd9b03b88c1593840a4f05d93d4f764b48a46f2.tar.gz
ouroboros-ffd9b03b88c1593840a4f05d93d4f764b48a46f2.zip
Merged in dstaesse/ouroboros/be-patience (pull request #465)
irmd: Prevent impatient user deadlock on shutdown
Diffstat (limited to 'src/irmd')
-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.");