diff options
author | Dan McGregor <dan.mcgregor@usask.ca> | 2016-09-14 18:16:25 +0300 |
---|---|---|
committer | Dan McGregor <dan.mcgregor@usask.ca> | 2017-04-12 20:51:38 +0300 |
commit | 0e73f3364f19fa7dd7e12b73adec63a8cb777d38 (patch) | |
tree | 0ccd5f3f9001cc59728312ca02b4f3a3f60510d7 /src/libexec | |
parent | abbc3feebc13d2a629aa452b9651e99d446be10f (diff) |
Do not wait for our own pid
Fix a race condition where pwait would hang if passed its own pid. This
could happen if kern.randompid is set and a the intended waitee pid gets
recycled before pwait got called.
Instead of deadlocking just exit immediately.
Diffstat (limited to 'src/libexec')
-rw-r--r-- | src/libexec/poudriere/pwait/pwait.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libexec/poudriere/pwait/pwait.c b/src/libexec/poudriere/pwait/pwait.c index 749d50f7..87b7f7bc 100644 --- a/src/libexec/poudriere/pwait/pwait.c +++ b/src/libexec/poudriere/pwait/pwait.c @@ -86,6 +86,7 @@ main(int argc, char *argv[]) long pid; char *s, *end; double timeout; + pid_t me; tflag = verbose = 0; memset(&itv, 0, sizeof(itv)); @@ -146,6 +147,9 @@ main(int argc, char *argv[]) if (argc == 0) usage(); + + me = getpid(); + #ifdef SHELL INTOFF; trap_push(SIGINFO, &info_oact); @@ -179,6 +183,10 @@ main(int argc, char *argv[]) warnx("%s: bad process id", s); continue; } + if (pid == me) { + warnx("%s: ignoring own process id", s); + continue; + } duplicate = 0; for (i = 0; i < nleft; i++) if (e[i].ident == (uintptr_t)pid) |