From 0994cc314e07f947a8e24302aa86c3e2df777428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Feb 2020 13:54:44 +0100 Subject: [PATCH] main: Ensure that a gcov flush happens on SIGTERM When coverage is enabled fprintd test won't generate any .gcda file and so apparently no data, this happens because gcov doesn't handle properly the process termination when SIGTERM is used, and so when in fprintd.py we terminate the process no coverage data is reported. To avoid this, quit the main loop cleanly on SIGTERM, so that we will exit from the main function cleanly, making libc to perform a gcov flush when we exit the program. --- src/main.c | 10 ++++++++++ tests/fprintd.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index bae586d..1a669fc 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "fprintd.h" @@ -129,6 +130,14 @@ static const GOptionEntry entries[] = { { NULL } }; +static gboolean sigterm_callback(gpointer data) +{ + GMainLoop *loop = data; + + g_main_loop_quit (loop); + return FALSE; +} + int main(int argc, char **argv) { GOptionContext *context; @@ -178,6 +187,7 @@ int main(int argc, char **argv) store.init (); loop = g_main_loop_new(NULL, FALSE); + g_unix_signal_add (SIGTERM, sigterm_callback, loop); g_debug("Launching FprintObject"); diff --git a/tests/fprintd.py b/tests/fprintd.py index 60d85de..eeb632a 100755 --- a/tests/fprintd.py +++ b/tests/fprintd.py @@ -233,7 +233,7 @@ class FPrintdTest(dbusmock.DBusTestCase): self.daemon.terminate() except OSError: pass - self.daemon.wait() + self.daemon.wait(timeout=2) self.daemon = None self.client = None