gmain: Reset signal handlers to default when source is destroyed

If someone creates a unix signal source for e.g. SIGINT, and then
removes it, reset the handler to SIG_DFL.

Not doing this was the source of race conditions in the
glib/tests/unix test, but this will also just make us a "good citizen"
by cleaning up.

For example, if a project temporarily creates a handler for SIGTERM,
and then later removes it, they almost certainly want SIGTERM to
revert to the default of terminating the process, rather than doing
nothing.

https://bugzilla.gnome.org/show_bug.cgi?id=704699
This commit is contained in:
Colin Walters
2013-07-22 19:06:31 +01:00
parent 6fbb146342
commit 2e471acfca
2 changed files with 35 additions and 27 deletions

View File

@@ -158,18 +158,15 @@ test_sigterm (void)
static void
test_sighup_add_remove (void)
{
GMainLoop *mainloop;
guint id;
mainloop = g_main_loop_new (NULL, FALSE);
struct sigaction action;
sig_received = FALSE;
id = g_unix_signal_add (SIGHUP, on_sig_received, mainloop);
id = g_unix_signal_add (SIGHUP, on_sig_received, NULL);
g_source_remove (id);
kill (getpid (), SIGHUP);
g_assert (!sig_received);
g_main_loop_unref (mainloop);
sigaction (SIGHUP, NULL, &action);
g_assert (action.sa_handler == SIG_DFL);
}
static gboolean