From 6aea30b730381af91300397a02e684a462bf55a7 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 28 May 2016 20:13:08 +0200 Subject: ipcpd: cleanup of IPC processes This stops IPC processes from hanging due to bad locks. It first informs all threads that the IPCP is shutting down, then cancels all threads. Cancellation is still required because threads may be in accept() or receivefrom(). --- src/ipcpd/local/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/ipcpd/local') diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index f3224de0..b07b0a52 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -246,20 +246,24 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c) case SIGHUP: case SIGQUIT: if (info->si_pid == irmd_pid) { + bool clean_threads = false; LOG_DBG("Terminating by order of %d. Bye.", info->si_pid); rw_lock_wrlock(&_ipcp->state_lock); - if (_ipcp->state == IPCP_ENROLLED) { - pthread_cancel(_ap_instance->sduloop); - pthread_join(_ap_instance->sduloop, NULL); - } + if (_ipcp->state == IPCP_ENROLLED) + clean_threads = true; _ipcp->state = IPCP_SHUTDOWN; rw_lock_unlock(&_ipcp->state_lock); + if (clean_threads) { + pthread_cancel(_ap_instance->sduloop); + pthread_join(_ap_instance->sduloop, NULL); + } + pthread_cancel(_ap_instance->mainloop); } default: -- cgit v1.2.3