diff options
| author | Baptiste Daroussin <bapt@FreeBSD.org> | 2026-02-02 15:44:34 +0000 |
|---|---|---|
| committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2026-02-02 16:13:16 +0000 |
| commit | 0ec58e7c2e533a15eabfe8dca4a14e9ae93de4b5 (patch) | |
| tree | f0564e07f5ae51d1a1d46e0686f257313887b586 | |
| parent | 4d73b07d02d12cdff0558d3ca6c4b3224cae831f (diff) | |
diff: use pdwait(2) instead of homemade one
MFC After: 3 days
Reviewed by: des
Differential Revision: https://reviews.freebsd.org/D55053
| -rw-r--r-- | usr.bin/diff/pr.c | 19 | ||||
| -rw-r--r-- | 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); |
