summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-03-08 23:05:28 +0000
committerjilles <jilles@FreeBSD.org>2014-03-08 23:05:28 +0000
commit75a534eddd03e167df7b703c5da0fd0424576dec (patch)
treef7ec1f301c2e3de3f4822ce93865323eaba5da9e /usr.bin
parent65c32b3a4c98c2274f511a650a899bacd4733868 (diff)
downloadFreeBSD-src-75a534eddd03e167df7b703c5da0fd0424576dec.zip
FreeBSD-src-75a534eddd03e167df7b703c5da0fd0424576dec.tar.gz
install: Use posix_spawnp() for starting strip and improve error messages.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/xinstall/xinstall.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index 2a2dc15..f40cdc5 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
#include <sha.h>
#include <sha256.h>
#include <sha512.h>
+#include <spawn.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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);
}
}
OpenPOWER on IntegriCloud