From 979029833353271b22321099417e8ed46bfdbd51 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 23 Jan 2012 18:16:09 +0200 Subject: [PATCH] pty: unblock all signals before exec'ing the child When we register signals in the eloop we also block them in our signal mask. The signal mask is inherited by the child. Therefore, if the child does not reset its mask (e.g. bash and most normal processes), it will not receive any of the signals that we handle. So for example C-c (SIGINT) does nothing in the child process. We now unblock all signals before we exec the child. [It's also worth noting that if we _ignore_ a signal - sigaction(SIG_IGN) - this is also inherited and we must reset it to default. However, we do not ignore signals so this is unneeded.] Here is some more discussion on signalfd and this problem: https://lwn.net/Articles/415684/ Signed-off-by: Ran Benita --- src/pty.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pty.c b/src/pty.c index 4f53170..612d3c3 100644 --- a/src/pty.c +++ b/src/pty.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -122,10 +123,19 @@ exec_child(int pty_master) static int fork_pty_child(int master, struct winsize *ws) { int ret, saved_errno; + sigset_t sigset; pid_t pid; const char *slave_name; int slave = -1; + /* The child should not inherit our signal mask. */ + sigfillset(&sigset); + ret = sigprocmask(SIG_UNBLOCK, &sigset, NULL); + if (ret) { + log_warning("pty: cannot unblock all signals: %m\n"); + /* This is non fatal. */ + } + /* This doesn't actually do anything on linux. */ ret = grantpt(master); if (ret < 0) {