From 8a71482d3b0b5fc8954c1bbfac0cbd0e590efcfd Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sat, 25 Jan 2014 12:51:49 +0100 Subject: 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. --- util/db.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'util/db.c') 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; } -- cgit v1.2.3