summaryrefslogtreecommitdiffstats
path: root/util/db.c
diff options
context:
space:
mode:
authorEric Leblond <eric@regit.org>2014-01-25 12:51:49 +0100
committerEric Leblond <eric@regit.org>2014-01-25 19:17:56 +0100
commit8a71482d3b0b5fc8954c1bbfac0cbd0e590efcfd (patch)
treef1de7398d5577d033afda422e784e05c20a4c5ce /util/db.c
parent24a66507871884203229bee9da29ae53c872103e (diff)
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.
Diffstat (limited to 'util/db.c')
-rw-r--r--util/db.c17
1 files changed, 17 insertions, 0 deletions
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;
}