diff options
author | Eric Leblond <eric@regit.org> | 2014-01-25 12:51:49 +0100 |
---|---|---|
committer | Eric Leblond <eric@regit.org> | 2014-01-25 19:17:56 +0100 |
commit | 8a71482d3b0b5fc8954c1bbfac0cbd0e590efcfd (patch) | |
tree | f1de7398d5577d033afda422e784e05c20a4c5ce /util/db.c | |
parent | 24a66507871884203229bee9da29ae53c872103e (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.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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; } |