profiler: Exit gracefully on SIGTERM
authorMatthias Clasen <mclasen@redhat.com>
Wed, 29 Jan 2020 15:55:44 +0000 (16:55 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 30 Jan 2020 09:04:38 +0000 (10:04 +0100)
This is nice, since it lets me quickly launch a test app
and terminate it with Ctrl-C and still produce a usable
sysprof trace.

gdk/gdkprofiler.c

index 93055ac9a82390d0d287d3853088da6fc9f2aa52..5b4e976110576706ae00fb2656783dfa180e2bce 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 
 #include <sys/types.h>
+#include <signal.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -38,7 +39,7 @@ static SysprofCaptureWriter *writer = NULL;
 static gboolean running = FALSE;
 
 static void
-profiler_stop (void)
+profiler_stop (int s)
 {
   if (writer)
     sysprof_capture_writer_unref (writer);
@@ -67,7 +68,8 @@ gdk_profiler_start (int fd)
   if (writer)
     running = TRUE;
 
-  atexit (profiler_stop);
+  atexit (G_CALLBACK (profiler_stop));
+  signal (SIGTERM, profiler_stop);
 }
 
 void