Instead of manually scanning the list of zombie processes, just use
zombiefind().
The extra check in the current code for a zombie whose process group ID
matches the pid being checked can be safely removed because process groups
stay in the global hash (and thus found with pgfind()) until all the
processes in them are *reaped*, so the process group of a zombie process
is certain to still be found by pgfind().
(Those curious to verify that can play with this perl snippet:
perl -e '$pid = fork(); if(!$pid){setpgrp();sleep 4;exit} print "$pid\n";
sleep 1; if (fork()){waitpid $pid, 0;sleep 3600; exit } setpgrp(0,$pid) or
die "$!"; sleep 5; print "becoming a zombie\n"; exit' &
The pid that it prints will end up only being occupied by a zombie and you
can then verify that ktrace -g and kill both find it.)
ok?
Philip
Index: kern/kern_fork.c
===================================================================
RCS file: /data/src/openbsd/src/sys/kern/kern_fork.c,v
retrieving revision 1.189
diff -u -p -r1.189 kern_fork.c
--- kern/kern_fork.c 3 Sep 2016 14:29:05 -0000 1.189
+++ kern/kern_fork.c 8 Oct 2016 08:52:12 -0000
@@ -564,11 +564,8 @@ ispidtaken(pid_t pid)
return (1);
if (pgfind(pid) != NULL)
return (1);
- LIST_FOREACH(pr, &zombprocess, ps_list) {
- if (pr->ps_pid == pid ||
- (pr->ps_pgrp && pr->ps_pgrp->pg_id == pid))
- return (1);
- }
+ if (zombiefind(pid) != NULL)
+ return (1);
return (0);
}