The branch main has been updated by bapt:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=0ec58e7c2e533a15eabfe8dca4a14e9ae93de4b5

commit 0ec58e7c2e533a15eabfe8dca4a14e9ae93de4b5
Author:     Baptiste Daroussin <[email protected]>
AuthorDate: 2026-02-02 15:44:34 +0000
Commit:     Baptiste Daroussin <[email protected]>
CommitDate: 2026-02-02 16:13:16 +0000

    diff: use pdwait(2) instead of homemade one
    
    MFC After:      3 days
    Reviewed by:    des
    Differential Revision:  https://reviews.freebsd.org/D55053
---
 usr.bin/diff/pr.c | 19 ++++++-------------
 usr.bin/diff/pr.h |  3 +--
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/usr.bin/diff/pr.c b/usr.bin/diff/pr.c
index c3ea280073af..f254fbab28b7 100644
--- a/usr.bin/diff/pr.c
+++ b/usr.bin/diff/pr.c
@@ -28,6 +28,7 @@
 #include <sys/wait.h>
 
 #include <err.h>
+#include <errno.h>
 #include <paths.h>
 #include <signal.h>
 #include <stdio.h>
@@ -72,7 +73,7 @@ start_pr(char *file1, char *file2)
                execl(_PATH_PR, _PATH_PR, "-h", header, (char *)0);
                _exit(127);
        default:
-
+               pr->pidfd = pr_pd;
                /* parent */
                if (pfd[1] != STDOUT_FILENO) {
                        pr->ostdout = dup(STDOUT_FILENO);
@@ -82,14 +83,6 @@ start_pr(char *file1, char *file2)
                close(pfd[0]);
                rewind(stdout);
                free(header);
-               pr->kq = kqueue();
-               if (pr->kq == -1)
-                       err(2, "kqueue");
-               pr->e = xmalloc(sizeof(struct kevent));
-               EV_SET(pr->e, pr_pd, EVFILT_PROCDESC, EV_ADD, NOTE_EXIT, 0,
-                   NULL);
-               if (kevent(pr->kq, pr->e, 1, NULL, 0, NULL) == -1)
-                       err(2, "kevent");
        }
        return (pr);
 }
@@ -109,10 +102,10 @@ stop_pr(struct pr *pr)
                dup2(pr->ostdout, STDOUT_FILENO);
                close(pr->ostdout);
        }
-       if (kevent(pr->kq, NULL, 0, pr->e, 1, NULL) == -1)
-               err(2, "kevent");
-       wstatus = pr->e[0].data;
-       close(pr->kq);
+       while (pdwait(pr->pidfd, &wstatus, WEXITED, NULL, NULL) == -1) {
+               if (errno != EINTR)
+                       err(2, "pdwait");
+       }
        free(pr);
        if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != 0)
                errx(2, "pr exited abnormally");
diff --git a/usr.bin/diff/pr.h b/usr.bin/diff/pr.h
index 2ff5949f282f..80f20ca7c329 100644
--- a/usr.bin/diff/pr.h
+++ b/usr.bin/diff/pr.h
@@ -28,8 +28,7 @@
 
 struct pr {
        int ostdout;
-       int kq;
-       struct kevent *e;
+       int pidfd;
 };
 
 struct pr *start_pr(char *file1, char *file2);

Reply via email to