From 1a8a9adc97117f01197713be3254eaf42c4a759d Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 1 Aug 2022 10:15:36 -0700 Subject: [PATCH] tools/sysprof-agent: handle SIGINT like we do for sysprof-cli This just forces the profiler to exit, but lets subsequent ^C usage to actually exit the program. --- src/tools/sysprof-agent.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/tools/sysprof-agent.c b/src/tools/sysprof-agent.c index 4e080404..b29c20f5 100644 --- a/src/tools/sysprof-agent.c +++ b/src/tools/sysprof-agent.c @@ -412,6 +412,20 @@ create_connection (GIOStream *stream, return ret; } +static gboolean +sigint_handler (gpointer user_data) +{ + SysprofProfiler *profiler = user_data; + + g_assert (SYSPROF_IS_PROFILER (profiler)); + + g_printerr ("\n" + "Profiler stopped, extracting symbols and appending to capture.\n" + "Press ^C again to force exit.\n"); + sysprof_profiler_stop (profiler); + return G_SOURCE_REMOVE; +} + int main (int argc, char *argv[]) @@ -606,6 +620,11 @@ main (int argc, G_CALLBACK (subprocess_finished_cb), NULL); + /* SIGINT (keyboard ^C) should stop the profiler and append symbols + * to the SysprofCaptureWriter. + */ + g_unix_signal_add (SIGINT, sigint_handler, profiler); + /* Start the profiler */ sysprof_profiler_start (profiler);