aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-04-16 16:37:15 +0200
committerLeah Neukirchen <leah@vuxu.org>2022-04-16 16:37:15 +0200
commit9a0e8cec85194e739e99e297d0cb830db370c73c (patch)
treebd01755c65f9a70b9226f84664b8ef65d68b4464
parentffc3d7af4540bb089c169ab3688dd429befea9dc (diff)
downloadextrace-master.tar.gz
extrace-master.tar.xz
extrace-master.zip
sigchld: only quit when we reaped our own childHEADmaster
Previously, the signal handler would also quit when it was triggered by backgrounding the child.
-rw-r--r--extrace.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/extrace.c b/extrace.c
index a00a1db..2e457f9 100644
--- a/extrace.c
+++ b/extrace.c
@@ -92,6 +92,7 @@
#define CMDLINE_MAX 32768
#define CMDLINE_DB_MAX 32
pid_t parent = 1;
+pid_t child;
int flat = 0;
int run = 0;
int full_path = 0;
@@ -242,10 +243,16 @@ sig2name(int sig)
static void
sigchld(int sig)
{
+ int old_errno = errno;
+ pid_t pid;
+
(void)sig;
- while (waitpid(-1, NULL, WNOHANG) > 0)
- ;
- quit = 1;
+
+ while ((pid = waitpid(-1, NULL, WNOHANG)) > 0)
+ if (pid == child)
+ quit = 1;
+
+ errno = old_errno;
}
static void
@@ -588,8 +595,6 @@ usage:
}
if (optind != argc) {
- pid_t child;
-
parent = getpid();
signal(SIGCHLD, sigchld);