Page MenuHomeFreeBSD

D58314.id182434.diff
No OneTemporary

D58314.id182434.diff

diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1
--- a/bin/pwait/pwait.1
+++ b/bin/pwait/pwait.1
@@ -30,7 +30,7 @@
.\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
.\" OF SUCH DAMAGE.
.\"
-.Dd October 22, 2025
+.Dd July 22, 2026
.Dt PWAIT 1
.Os
.Sh NAME
@@ -127,8 +127,10 @@
[2] 1675
$ pwait -v -t 60 1674 1675
1674: exited with status 0.
-1675: exited with status 0.
+1674: collected.
[1]- Done sleep 30
+1675: exited with status 0.
+1675: collected.
[2]+ Done sleep 40
$ echo $?
0
diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c
--- a/bin/pwait/pwait.c
+++ b/bin/pwait/pwait.c
@@ -40,6 +40,7 @@
#include <sys/tree.h>
#include <sys/wait.h>
+#include <assert.h>
#include <err.h>
#include <errno.h>
#include <signal.h>
@@ -190,7 +191,8 @@
free(p);
continue;
}
- EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
+ EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD,
+ NOTE_EXIT | NOTE_REAP, 0, NULL);
if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1) {
if (errno != ESRCH)
err(EX_OSERR, "kevent()");
@@ -230,9 +232,11 @@
printf("timeout\n");
}
ret = 124;
+ continue;
}
+ assert(e[i].filter == EVFILT_PROC);
pid = e[i].ident;
- if (verbose) {
+ if ((e[i].fflags & NOTE_EXIT) && verbose) {
status = e[i].data;
if (WIFEXITED(status)) {
printf("%ld: exited with status %d.\n",
@@ -244,13 +248,17 @@
printf("%ld: terminated.\n", pid);
}
}
- k.pid = pid;
- if ((p = RB_FIND(pidtree, &pids, &k)) != NULL) {
- RB_REMOVE(pidtree, &pids, p);
- free(p);
- ndone++;
+ if ((e[i].fflags & NOTE_REAP)) {
+ if (verbose)
+ printf("%ld: collected.\n", pid);
+ k.pid = pid;
+ if ((p = RB_FIND(pidtree, &pids, &k)) != NULL) {
+ RB_REMOVE(pidtree, &pids, p);
+ free(p);
+ ndone++;
+ }
+ --nleft;
}
- --nleft;
}
}
if (pflag) {
diff --git a/bin/pwait/tests/pwait_test.sh b/bin/pwait/tests/pwait_test.sh
--- a/bin/pwait/tests/pwait_test.sh
+++ b/bin/pwait/tests/pwait_test.sh
@@ -249,7 +249,7 @@
p6=$!
atf_check \
- -o inline:"$p2: exited with status 0.\n" \
+ -o inline:"$p2: exited with status 0.\n$p2: collected.\n" \
-e empty \
-s exit:0 \
timeout --preserve-status 15 pwait -o -v $p2 $p4 $p6
@@ -273,7 +273,7 @@
timeout --preserve-status 15 pwait -o $p4 $p6
atf_check \
- -o inline:"$p6: exited with status 0.\n" \
+ -o inline:"$p6: exited with status 0.\n$p6: collected.\n" \
-e empty \
-s exit:0 \
timeout --preserve-status 15 pwait -o -v $p6

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 1, 4:24 AM (12 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39945636
Default Alt Text
D58314.id182434.diff (2 KB)

Event Timeline