diff options
| author | Baptiste Daroussin <bapt@FreeBSD.org> | 2018-06-09 20:24:17 +0000 |
|---|---|---|
| committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2018-06-09 20:24:17 +0000 |
| commit | 6fa5bf0832efe8a894f612968c5afe1ad91f3a03 (patch) | |
| tree | 63c447bffc0581ca045a4b097996f01b66933108 /usr.bin/diff/diffreg.c | |
| parent | dd0bdd6b456dcc3a798f6dba142eac0e334824b0 (diff) | |
Notes
Diffstat (limited to 'usr.bin/diff/diffreg.c')
| -rw-r--r-- | usr.bin/diff/diffreg.c | 86 |
1 files changed, 6 insertions, 80 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index b7a0135bdf12..84cb4ac58c21 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -70,11 +70,7 @@ __FBSDID("$FreeBSD$"); #include <sys/capsicum.h> -#include <sys/procdesc.h> #include <sys/stat.h> -#include <sys/types.h> -#include <sys/event.h> -#include <sys/wait.h> #include <capsicum_helpers.h> #include <ctype.h> @@ -88,15 +84,11 @@ __FBSDID("$FreeBSD$"); #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> -#include <limits.h> -#include <signal.h> +#include "pr.h" #include "diff.h" #include "xmalloc.h" -#define _PATH_PR "/usr/bin/pr" - /* * diff - compare two files. */ @@ -260,13 +252,9 @@ diffreg(char *file1, char *file2, int flags, int capsicum) { FILE *f1, *f2; int i, rval; - int ostdout = -1; - int pr_pd, kq; - struct kevent *e; + struct pr *pr = NULL; cap_rights_t rights_ro; - e = NULL; - kq = -1; f1 = f2 = NULL; rval = D_SAME; anychange = 0; @@ -324,52 +312,8 @@ diffreg(char *file1, char *file2, int flags, int capsicum) goto closem; } - if (lflag) { - /* redirect stdout to pr */ - int pfd[2]; - pid_t pid; - char *header; - - xasprintf(&header, "%s %s %s", diffargs, file1, file2); - signal(SIGPIPE, SIG_IGN); - fflush(stdout); - rewind(stdout); - pipe(pfd); - switch ((pid = pdfork(&pr_pd, PD_CLOEXEC))) { - case -1: - status |= 2; - free(header); - err(2, "No more processes"); - case 0: - /* child */ - if (pfd[0] != STDIN_FILENO) { - dup2(pfd[0], STDIN_FILENO); - close(pfd[0]); - } - close(pfd[1]); - execl(_PATH_PR, _PATH_PR, "-h", header, (char *)0); - _exit(127); - default: - - /* parent */ - if (pfd[1] != STDOUT_FILENO) { - ostdout = dup(STDOUT_FILENO); - dup2(pfd[1], STDOUT_FILENO); - close(pfd[1]); - } - close(pfd[0]); - rewind(stdout); - free(header); - kq = kqueue(); - if (kq == -1) - err(2, "kqueue"); - e = xmalloc(sizeof(struct kevent)); - EV_SET(e, pr_pd, EVFILT_PROCDESC, EV_ADD, NOTE_EXIT, 0, - NULL); - if (kevent(kq, e, 1, NULL, 0, NULL) == -1) - err(2, "kevent"); - } - } + if (lflag) + pr = start_pr(file1, file2); if (capsicum) { cap_rights_init(&rights_ro, CAP_READ, CAP_FSTAT, CAP_SEEK); @@ -443,26 +387,8 @@ diffreg(char *file1, char *file2, int flags, int capsicum) ixnew = xreallocarray(ixnew, len[1] + 2, sizeof(*ixnew)); check(f1, f2, flags); output(file1, f1, file2, f2, flags); - if (ostdout != -1 && e != NULL) { - /* close the pipe to pr and restore stdout */ - int wstatus; - - fflush(stdout); - if (ostdout != STDOUT_FILENO) { - close(STDOUT_FILENO); - dup2(ostdout, STDOUT_FILENO); - close(ostdout); - } - if (kevent(kq, NULL, 0, e, 1, NULL) == -1) - err(2, "kevent"); - wstatus = e[0].data; - close(kq); - if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != 0) - errx(2, "pr exited abnormally"); - else if (WIFSIGNALED(wstatus)) - errx(2, "pr killed by signal %d", - WTERMSIG(wstatus)); - } + if (pr != NULL) + stop_pr(pr); closem: if (anychange) { |
