aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias.schiffer@ew.tq-group.com>2024-02-15 09:39:53 +0100
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2024-02-16 09:22:58 -0500
commit854dcb7c2bbd8d11f1188838090d6eba3476dc85 (patch)
treec307faf21ad3bb440d96a3bd60e3264fe622accc
parentc58a4d9f7880931a14c4733c013c08c477aefeec (diff)
tools/rfcomm: reset ignored signals after fork
rfcomm sets SIGCHLD and SIGPIPE to SIG_IGN, which is inherited by child processes and preserved across execvp(). Many applications do not expect these signals to be ignored, causing all kinds of breakage (including the standard C system() function misbehaving on glibc and probably other libcs because waitpid() does not work when SIGCHLD is ignored).
-rw-r--r--tools/rfcomm.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/rfcomm.c b/tools/rfcomm.c
index e013ff588e..f635d4aef9 100644
--- a/tools/rfcomm.c
+++ b/tools/rfcomm.c
@@ -212,6 +212,7 @@ static void run_cmdline(struct pollfd *p, sigset_t *sigs, char *devname,
int i;
pid_t pid;
char **cmdargv;
+ struct sigaction sa;
cmdargv = malloc((argc + 1) * sizeof(char *));
if (!cmdargv)
@@ -225,6 +226,11 @@ static void run_cmdline(struct pollfd *p, sigset_t *sigs, char *devname,
switch (pid) {
case 0:
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = SIG_DFL;
+ sigaction(SIGCHLD, &sa, NULL);
+ sigaction(SIGPIPE, &sa, NULL);
+
i = execvp(cmdargv[0], cmdargv);
fprintf(stderr, "Couldn't execute command %s (errno=%d:%s)\n",
cmdargv[0], errno, strerror(errno));