From owner-svn-src-head@FreeBSD.ORG Sat Mar 8 23:05:29 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7CC556C9; Sat, 8 Mar 2014 23:05:29 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4FFBD5F4; Sat, 8 Mar 2014 23:05:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s28N5Tlf098576; Sat, 8 Mar 2014 23:05:29 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s28N5Tt1098575; Sat, 8 Mar 2014 23:05:29 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201403082305.s28N5Tt1098575@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 8 Mar 2014 23:05:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r262934 - head/usr.bin/xinstall X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Mar 2014 23:05:29 -0000 Author: jilles Date: Sat Mar 8 23:05:28 2014 New Revision: 262934 URL: http://svnweb.freebsd.org/changeset/base/262934 Log: install: Use posix_spawnp() for starting strip and improve error messages. Modified: head/usr.bin/xinstall/xinstall.c Modified: head/usr.bin/xinstall/xinstall.c ============================================================================== --- head/usr.bin/xinstall/xinstall.c Sat Mar 8 20:31:04 2014 (r262933) +++ head/usr.bin/xinstall/xinstall.c Sat Mar 8 23:05:28 2014 (r262934) @@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -102,6 +103,8 @@ static enum { DIGEST_SHA512, } digesttype = DIGEST_NONE; +extern char **environ; + static gid_t gid; static uid_t uid; static int dobackup, docompare, dodir, dolink, dopreserve, dostrip, dounpriv, @@ -1215,27 +1218,33 @@ static void strip(const char *to_name) { const char *stripbin; - int serrno, status; - - switch (fork()) { - case -1: - serrno = errno; + const char *args[3]; + pid_t pid; + int error, status; + + stripbin = getenv("STRIPBIN"); + if (stripbin == NULL) + stripbin = "strip"; + args[0] = stripbin; + args[1] = to_name; + args[2] = NULL; + error = posix_spawnp(&pid, stripbin, NULL, NULL, + __DECONST(char **, args), environ); + if (error != 0) { (void)unlink(to_name); - errno = serrno; - err(EX_TEMPFAIL, "fork"); - case 0: - stripbin = getenv("STRIPBIN"); - if (stripbin == NULL) - stripbin = "strip"; - execlp(stripbin, stripbin, to_name, (char *)NULL); - err(EX_OSERR, "exec(%s)", stripbin); - default: - if (wait(&status) == -1 || status) { - serrno = errno; - (void)unlink(to_name); - errc(EX_SOFTWARE, serrno, "wait"); - /* NOTREACHED */ - } + errc(error == EAGAIN || error == EPROCLIM || error == ENOMEM ? + EX_TEMPFAIL : EX_OSERR, error, "spawn %s", stripbin); + } + if (waitpid(pid, &status, 0) == -1) { + error = errno; + (void)unlink(to_name); + errc(EX_SOFTWARE, error, "wait"); + /* NOTREACHED */ + } + if (status != 0) { + (void)unlink(to_name); + errx(EX_SOFTWARE, "strip command %s failed on %s", + stripbin, to_name); } }