[at-spi2-core: 1/2] test-application.c: Install a signal handler to exit cleanly




commit 396487b09e1880b6cdbaf6936085722328ed4fd0
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Jun 13 11:36:12 2022 -0500

    test-application.c: Install a signal handler to exit cleanly
    
    The app-test program gets run by atk_test_util.c, and gets sent a
    SIGTERM when the parent process wants it to terminate.  This is fine,
    but if app-test terminates forcefully with the default handler for
    SIGTERM, then libgcc won't get a chance to write out its code coverage
    information.
    
    So, we install a signal handler for SIGTERM, and the handler exits the
    main loop.

 tests/at-spi2-atk/test-application.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
---
diff --git a/tests/at-spi2-atk/test-application.c b/tests/at-spi2-atk/test-application.c
index 78444613..d2fb14bb 100644
--- a/tests/at-spi2-atk/test-application.c
+++ b/tests/at-spi2-atk/test-application.c
@@ -31,7 +31,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <signal.h>
 #include <glib.h>
+#include <glib-unix.h>
 #include <atk/atk.h>
 #include <atk-bridge.h>
 #include "my-atk.h"
@@ -93,6 +95,14 @@ static GOptionEntry optentries[] = {
   {NULL}
 };
 
+static gboolean
+sigterm_received_cb (gpointer user_data)
+{
+  GMainLoop *mainloop = user_data;
+  g_main_loop_quit (mainloop);
+  return G_SOURCE_REMOVE;
+}
+
 int main (int argc, char *argv[])
 {
   GOptionContext *opt;
@@ -109,6 +119,7 @@ int main (int argc, char *argv[])
   atk_bridge_adaptor_init (NULL, NULL);
 
   mainloop = g_main_loop_new (NULL, FALSE);
+  g_unix_signal_add (SIGTERM, sigterm_received_cb, mainloop);
   g_main_loop_run (mainloop);
 
   return 0;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]