From 0d21df81684e9d2a7376cfa41f02732dadd748e3 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 25 Aug 2009 11:17:00 +0200 Subject: [PATCH] Clear the signal mask for child processes This adds a callback function which glib calls after it fork()'d and did all the necessary setup. This callback function clears our signal mask. This is necessary because libev 3.8 and later use signalfd and therefor have to add those signals to the signal mask. Processes started through awesome would inherit this signal mask and I can tell you, some app which ignores ctrl-c confuses people a lot. Signed-off-by: Uli Schlachter Signed-off-by: Julien Danjou --- spawn.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/spawn.c b/spawn.c index 829768ab..e7d86626 100644 --- a/spawn.c +++ b/spawn.c @@ -253,6 +253,23 @@ spawn_launchee_timeout(struct ev_loop *loop, ev_timer *w, int revents) p_delete(&w); } +/** This callback is executed in the child process after fork(). It clears the + * signal mask. Without this, child processes would be started with e.g. + * SIGINT blocked if we are compiled against libev 3.8 or newer. + * BEWARE: Pending signals are inherited by child processes. This might mean + * that we receive a signal that was meant for awesome after clearing the signal + * mask! Sadly, we can't do anything about this. + * \param user_data Not used. + */ +static void +spawn_child_callback(gpointer user_data) +{ + sigset_t empty; + + sigemptyset(&empty); + sigprocmask(SIG_SETMASK, &empty, NULL); +} + /** Spawn a command. * \param command_line The command line to launch. * \param error A error pointer to fill with the possible error from @@ -269,7 +286,7 @@ spawn_command(const gchar *command_line, GError **error) return FALSE; retval = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, error); + spawn_child_callback, NULL, NULL, error); g_strfreev (argv); return retval;