Module Name:    src
Committed By:   martin
Date:           Mon Jun 15 07:05:09 UTC 2015

Modified Files:
        src/usr.bin/xinstall: Makefile xinstall.c

Log Message:
Add optional support for posix_spawn (instead of vfork) and enable it for
the in-tree build.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xinstall/Makefile
cvs rdiff -u -r1.117 -r1.118 src/usr.bin/xinstall/xinstall.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xinstall/Makefile
diff -u src/usr.bin/xinstall/Makefile:1.22 src/usr.bin/xinstall/Makefile:1.23
--- src/usr.bin/xinstall/Makefile:1.22	Wed Aug 17 14:00:30 2011
+++ src/usr.bin/xinstall/Makefile	Mon Jun 15 07:05:09 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.22 2011/08/17 14:00:30 christos Exp $
+#	$NetBSD: Makefile,v 1.23 2015/06/15 07:05:09 martin Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
 
 .include <bsd.own.mk>
@@ -8,7 +8,7 @@ SRCS=	xinstall.c getid.c
 MAN=	install.1
 
 .PATH:		${NETBSDSRCDIR}/usr.sbin/mtree
-CPPFLAGS+=	-I${NETBSDSRCDIR}/usr.sbin/mtree
+CPPFLAGS+=	-I${NETBSDSRCDIR}/usr.sbin/mtree -DHAVE_POSIX_SPAWN
 
 .if (${HOSTPROG:U} == "")
 DPADD+= ${LIBUTIL}

Index: src/usr.bin/xinstall/xinstall.c
diff -u src/usr.bin/xinstall/xinstall.c:1.117 src/usr.bin/xinstall/xinstall.c:1.118
--- src/usr.bin/xinstall/xinstall.c:1.117	Sun Jul  6 20:54:47 2014
+++ src/usr.bin/xinstall/xinstall.c	Mon Jun 15 07:05:09 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: xinstall.c,v 1.117 2014/07/06 20:54:47 apb Exp $	*/
+/*	$NetBSD: xinstall.c,v 1.118 2015/06/15 07:05:09 martin Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 19
 #if 0
 static char sccsid[] = "@(#)xinstall.c	8.1 (Berkeley) 7/21/93";
 #else
-__RCSID("$NetBSD: xinstall.c,v 1.117 2014/07/06 20:54:47 apb Exp $");
+__RCSID("$NetBSD: xinstall.c,v 1.118 2015/06/15 07:05:09 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -72,6 +72,10 @@ __RCSID("$NetBSD: xinstall.c,v 1.117 201
 #include <util.h>
 #include <vis.h>
 
+#ifdef HAVE_POSIX_SPAWN
+#include <spawn.h>
+#endif
+
 #include <md5.h>
 #include <rmd160.h>
 #include <sha1.h>
@@ -965,9 +969,16 @@ copy(int from_fd, char *from_name, int t
 static void
 strip(char *to_name)
 {
+	int	status;
+#ifdef HAVE_POSIX_SPAWN
+	char	*args[4];
+	const char *stripprog;
+	int	rv;
+#else
 	static const char exec_failure[] = ": exec of strip failed: ";
-	int	serrno, status;
-	const char * volatile stripprog, *progname;
+	int	serrno;
+	const char * volatile *progname, *stripprog;
+#endif
 	char *cmd;
 
 	if ((stripprog = getenv("STRIP")) == NULL || *stripprog == '\0') {
@@ -992,6 +1003,26 @@ strip(char *to_name)
 			err(1, "asprintf failed");
 	}
 
+#ifdef HAVE_POSIX_SPAWN
+	status = -1;
+	if (stripArgs) {
+		args[0] = __UNCONST("sh");
+		args[1] = __UNCONST("-c");
+		args[2] = cmd;
+		args[3] = NULL;
+		rv = posix_spawn(NULL, _PATH_BSHELL, NULL, NULL, args, NULL);
+	} else {
+		args[0] = __UNCONST(strip);
+		args[1] = to_name;
+		args[2] = NULL;
+		rv = posix_spawnp(NULL, stripprog, NULL, NULL, args, NULL);
+	}
+
+	if (rv == 0)
+		wait(&status);
+	if (rv || status == -1)
+		unlink(to_name);
+#else
 	switch (vfork()) {
 	case -1:
 		serrno = errno;
@@ -1016,6 +1047,7 @@ strip(char *to_name)
 		if (wait(&status) == -1 || status)
 			(void)unlink(to_name);
 	}
+#endif
 
 	free(cmd);
 }
@@ -1028,9 +1060,33 @@ strip(char *to_name)
 static void
 afterinstall(const char *command, const char *to_name, int errunlink)
 {
-	int	serrno, status;
+#ifdef HAVE_POSIX_SPAWN
+	char	*args[4];
+	int	rv;
+#else
+	int	serrno;
+#endif
+	int	status;
 	char	*cmd;
 
+#ifdef HAVE_POSIX_SPAWN
+	/*
+	 * build up a command line and let /bin/sh
+	 * parse the arguments
+	 */
+	asprintf(&cmd, "%s %s", command, to_name);
+	args[0] = __UNCONST("sh");
+	args[1] = __UNCONST("-c");
+	args[2] = cmd;
+	args[3] = NULL;
+
+	rv = posix_spawn(NULL, _PATH_BSHELL, NULL, NULL, args, NULL);
+	if (rv == 0)
+		wait(&status);
+	if ((rv || status == -1) && errunlink)
+		(void)unlink(to_name);
+	free(cmd);
+#else
 	switch (vfork()) {
 	case -1:
 		serrno = errno;
@@ -1061,6 +1117,7 @@ afterinstall(const char *command, const 
 		if ((wait(&status) == -1 || status) && errunlink)
 			(void)unlink(to_name);
 	}
+#endif
 }
 
 /*

Reply via email to