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 <psychon@znc.in>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Uli Schlachter 2009-08-25 11:17:00 +02:00 committed by Julien Danjou
parent 7e5097aa09
commit 47f3a4b3df
1 changed files with 18 additions and 1 deletions

19
spawn.c
View File

@ -237,6 +237,23 @@ spawn_launchee_timeout(struct ev_loop *loop, ev_timer *w, int revents)
p_delete(&w); 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. /** Spawn a command.
* \param command_line The command line to launch. * \param command_line The command line to launch.
* \param error A error pointer to fill with the possible error from * \param error A error pointer to fill with the possible error from
@ -253,7 +270,7 @@ spawn_command(const gchar *command_line, GError **error)
return FALSE; return FALSE;
retval = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, retval = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
NULL, NULL, NULL, error); spawn_child_callback, NULL, NULL, error);
g_strfreev (argv); g_strfreev (argv);
return retval; return retval;