Skip to content

Commit

Permalink
HBSD: pull in upstream fix for pwait hang when watching its own pid
Browse files Browse the repository at this point in the history
From the FreeBSD Bug 218598:

  pwait will deadlock when passed its own PID.
  I experienced this when kern.randompid was set with poudriere.
  The code was more or less this:

  #!/bin/sh
  do_the_thing&
  pwait $!
  do_the_other_thing

  If do_the_thing ends before pwait starts, and do_the_thing and
  pwait get the same pid, pwait waits indefinitely.

FreeBSD-PR: 218598
FreeBSD-PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=218598
MFC-to: 10-STABLE
MFC-to: 11-STABLE
X-MFC-with: baf6bf5b16681f98941f25302074ff64df89e076
Submitted-by: Dan McGregor <[email protected]>
Signed-off-by: Oliver Pinter <[email protected]>
(cherry picked from commit e0b45ab3bc9443689c2d95ce2e3b552a027f5494)
Signed-off-by: Oliver Pinter <[email protected]>
(cherry picked from commit 81c3c9c)
Signed-off-by: Oliver Pinter <[email protected]>
  • Loading branch information
opntr committed Sep 23, 2017
1 parent 5c0bfdf commit 0940151
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bin/pwait/pwait.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ main(int argc, char *argv[])
long pid;
char *s, *end;
double timeout;
pid_t me;

tflag = verbose = 0;
memset(&itv, 0, sizeof(itv));
Expand Down Expand Up @@ -118,6 +119,8 @@ main(int argc, char *argv[])
if (argc == 0)
usage();

me = getpid();

kq = kqueue();
if (kq == -1)
err(1, "kqueue");
Expand All @@ -136,6 +139,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)
Expand Down

0 comments on commit 0940151

Please sign in to comment.