]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
db: cancel injection thread when terminating
authorEric Leblond <eric@regit.org>
Sat, 25 Jan 2014 11:51:49 +0000 (12:51 +0100)
committerEric Leblond <eric@regit.org>
Sat, 25 Jan 2014 18:17:56 +0000 (19:17 +0100)
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

index 3b72007e4d5f38831cf74693a0e66a1610da2343..1f74712d6a61aa1f4bc7571a422c2559b17be772 100644 (file)
--- 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;
        }