From owner-svn-src-all@freebsd.org Thu Aug 27 21:52:11 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EE8D59C3687; Thu, 27 Aug 2015 21:52:10 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D2970EA8; Thu, 27 Aug 2015 21:52:10 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7RLqAUr068285; Thu, 27 Aug 2015 21:52:10 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7RLqA8K068282; Thu, 27 Aug 2015 21:52:10 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201508272152.t7RLqA8K068282@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Thu, 27 Aug 2015 21:52:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287223 - stable/10/usr.bin/patch X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Aug 2015 21:52:11 -0000 Author: delphij Date: Thu Aug 27 21:52:09 2015 New Revision: 287223 URL: https://svnweb.freebsd.org/changeset/base/287223 Log: MFC r281800 (pfg): patch(1): small include changes. Mostly to match OpenBSD, no functional change. MFC r286601 + 286617: use posix_spawn(3) instead of fork() and exec() manually as suggested by jmg@. Modified: stable/10/usr.bin/patch/inp.c stable/10/usr.bin/patch/pch.c stable/10/usr.bin/patch/util.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/patch/inp.c ============================================================================== --- stable/10/usr.bin/patch/inp.c Thu Aug 27 21:27:47 2015 (r287222) +++ stable/10/usr.bin/patch/inp.c Thu Aug 27 21:52:09 2015 (r287223) @@ -36,8 +36,10 @@ #include #include #include -#include +#include +#include #include +#include #include #include #include @@ -134,14 +136,13 @@ reallocate_lines(size_t *lines_allocated static bool plan_a(const char *filename) { - int ifd, statfailed, devnull, pstat; + int ifd, statfailed, pstat; char *p, *s, lbuf[INITLINELEN]; struct stat filestat; ptrdiff_t sz; size_t i; size_t iline, lines_allocated; pid_t pid; - char *argp[4] = {NULL}; #ifdef DEBUGGING if (debug & 8) @@ -178,7 +179,9 @@ plan_a(const char *filename) ((filestat.st_mode & 0022) == 0 && filestat.st_uid != getuid())) { char *filebase, *filedir; struct stat cstat; - char *tmp_filename1, *tmp_filename2; + char *tmp_filename1, *tmp_filename2; + char *argp[4] = { NULL }; + posix_spawn_file_actions_t file_actions; tmp_filename1 = strdup(filename); tmp_filename2 = strdup(filename); @@ -188,6 +191,8 @@ plan_a(const char *filename) filebase = basename(tmp_filename1); filedir = dirname(tmp_filename2); + memset(argp, 0, sizeof(argp)); + #define try(f, a1, a2, a3) \ (snprintf(lbuf, sizeof(lbuf), f, a1, a2, a3), stat(lbuf, &cstat) == 0) @@ -213,50 +218,39 @@ plan_a(const char *filename) say("Comparing file %s to default " "RCS version...\n", filename); - switch (pid = fork()) { - case -1: - fatal("can't fork: %s\n", - strerror(errno)); - case 0: - devnull = open("/dev/null", O_RDONLY); - if (devnull == -1) { - fatal("can't open /dev/null: %s", - strerror(errno)); - } - (void)dup2(devnull, STDOUT_FILENO); - argp[0] = strdup(RCSDIFF); - argp[1] = strdup(filename); - execv(RCSDIFF, argp); - exit(127); - } - pid = waitpid(pid, &pstat, 0); - if (pid == -1 || WEXITSTATUS(pstat) != 0) { - fatal("can't check out file %s: " - "differs from default RCS version\n", - filename); - } + argp[0] = __DECONST(char *, RCSDIFF); + argp[1] = __DECONST(char *, filename); + posix_spawn_file_actions_init(&file_actions); + posix_spawn_file_actions_addopen(&file_actions, + STDOUT_FILENO, _PATH_DEVNULL, O_WRONLY, 0); + if (posix_spawn(&pid, RCSDIFF, &file_actions, + NULL, argp, NULL) == 0) { + pid = waitpid(pid, &pstat, 0); + if (pid == -1 || WEXITSTATUS(pstat) != 0) + fatal("can't check out file %s: " + "differs from default RCS version\n", + filename); + } else + fatal("posix_spawn: %s\n", strerror(errno)); + posix_spawn_file_actions_destroy(&file_actions); } if (verbose) say("Checking out file %s from RCS...\n", filename); - switch (pid = fork()) { - case -1: - fatal("can't fork: %s\n", strerror(errno)); - case 0: - argp[0] = strdup(CHECKOUT); - argp[1] = strdup("-l"); - argp[2] = strdup(filename); - execv(CHECKOUT, argp); - exit(127); - } - pid = waitpid(pid, &pstat, 0); - if (pid == -1 || WEXITSTATUS(pstat) != 0 || - stat(filename, &filestat)) { - fatal("can't check out file %s from RCS\n", - filename); - } + argp[0] = __DECONST(char *, CHECKOUT); + argp[1] = __DECONST(char *, "-l"); + argp[2] = __DECONST(char *, filename); + if (posix_spawn(&pid, CHECKOUT, NULL, NULL, argp, + NULL) == 0) { + pid = waitpid(pid, &pstat, 0); + if (pid == -1 || WEXITSTATUS(pstat) != 0 || + stat(filename, &filestat)) + fatal("can't check out file %s from RCS\n", + filename); + } else + fatal("posix_spawn: %s\n", strerror(errno)); } else if (statfailed) { fatal("can't find %s\n", filename); } Modified: stable/10/usr.bin/patch/pch.c ============================================================================== --- stable/10/usr.bin/patch/pch.c Thu Aug 27 21:27:47 2015 (r287222) +++ stable/10/usr.bin/patch/pch.c Thu Aug 27 21:52:09 2015 (r287223) @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include Modified: stable/10/usr.bin/patch/util.c ============================================================================== --- stable/10/usr.bin/patch/util.c Thu Aug 27 21:27:47 2015 (r287222) +++ stable/10/usr.bin/patch/util.c Thu Aug 27 21:52:09 2015 (r287223) @@ -27,13 +27,13 @@ * $FreeBSD$ */ -#include #include #include #include #include #include +#include #include #include #include @@ -96,7 +96,7 @@ int backup_file(const char *orig) { struct stat filestat; - char bakname[MAXPATHLEN], *s, *simplename; + char bakname[PATH_MAX], *s, *simplename; dev_t orig_device; ino_t orig_inode; @@ -406,7 +406,7 @@ fetchname(const char *at, bool *exists, char * checked_in(char *file) { - char *filebase, *filedir, tmpbuf[MAXPATHLEN]; + char *filebase, *filedir, tmpbuf[PATH_MAX]; struct stat filestat; filebase = basename(file);