From: Eric Leblond Date: Sat, 25 Jan 2014 11:51:49 +0000 (+0100) Subject: db: cancel injection thread when terminating X-Git-Tag: ulogd-2.0.4~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a71482d3b0b5fc8954c1bbfac0cbd0e590efcfd;p=thirdparty%2Fulogd2.git db: cancel injection thread when terminating Injection thread was not cancelled when a termination signal was sent. This was causing a crash in some cases. This patch fixes this by canceling the thread when a SIGTERM or SIGINT signal is received. --- diff --git a/util/db.c b/util/db.c index 3b72007..1f74712 100644 --- a/util/db.c +++ b/util/db.c @@ -619,6 +619,23 @@ void ulogd_db_signal(struct ulogd_pluginstance *upi, int signal) ulogd_log(ULOGD_ERROR, "No SIGHUP handling if ring buffer is used\n"); break; + case SIGTERM: + case SIGINT: + if (di->ring.size) { + int s = pthread_cancel(di->db_thread_id); + if (s != 0) { + ulogd_log(ULOGD_ERROR, + "Can't cancel injection thread\n"); + break; + } + s = pthread_join(di->db_thread_id, NULL); + if (s != 0) { + ulogd_log(ULOGD_ERROR, + "Error waiting for injection thread" + "cancelation\n"); + } + } + break; default: break; }