Module Name:    src
Committed By:   christos
Date:           Wed Jun 17 15:34:08 UTC 2015

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

Log Message:
Use the bourne shell if the after command has shell metachars.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/xinstall/Makefile
cvs rdiff -u -r1.119 -r1.120 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.24 src/usr.bin/xinstall/Makefile:1.25
--- src/usr.bin/xinstall/Makefile:1.24	Mon Jun 15 12:33:38 2015
+++ src/usr.bin/xinstall/Makefile	Wed Jun 17 11:34:08 2015
@@ -1,12 +1,15 @@
-#	$NetBSD: Makefile,v 1.24 2015/06/15 16:33:38 christos Exp $
+#	$NetBSD: Makefile,v 1.25 2015/06/17 15:34:08 christos Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
 
 .include <bsd.own.mk>
 
 PROG=	xinstall
-SRCS=	xinstall.c getid.c
+SRCS=	xinstall.c getid.c metachar.c
 MAN=	install.1
 
+.PATH:		${NETBSDSRCDIR}/usr.bin/make
+CPPFLAGS+=	-I${NETBSDSRCDIR}/usr.bin/make
+
 .PATH:		${NETBSDSRCDIR}/usr.sbin/mtree
 CPPFLAGS+=	-I${NETBSDSRCDIR}/usr.sbin/mtree
 CPPFLAGS+=	-DHAVE_POSIX_SPAWN

Index: src/usr.bin/xinstall/xinstall.c
diff -u src/usr.bin/xinstall/xinstall.c:1.119 src/usr.bin/xinstall/xinstall.c:1.120
--- src/usr.bin/xinstall/xinstall.c:1.119	Mon Jun 15 12:33:38 2015
+++ src/usr.bin/xinstall/xinstall.c	Wed Jun 17 11:34:08 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: xinstall.c,v 1.119 2015/06/15 16:33:38 christos Exp $	*/
+/*	$NetBSD: xinstall.c,v 1.120 2015/06/17 15:34:08 christos 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.119 2015/06/15 16:33:38 christos Exp $");
+__RCSID("$NetBSD: xinstall.c,v 1.120 2015/06/17 15:34:08 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -83,6 +83,7 @@ __RCSID("$NetBSD: xinstall.c,v 1.119 201
 
 #include "pathnames.h"
 #include "mtree.h"
+#include "metachar.h"
 
 #define BACKUP_SUFFIX ".old"
 
@@ -969,6 +970,7 @@ static void
 run(const char *command, const char *flags, const char *to_name, int errunlink)
 {
 	char	*args[4];
+	char	*cmd;
 	int	status;
 	int	rv;
 	size_t	i;
@@ -976,10 +978,22 @@ run(const char *command, const char *fla
 	i = 1;
 	status = 0;
 
+	if (hasmeta(command)) {
+		rv = asprintf(&cmd, "%s %s%s%s", command, flags ? flags : "",
+		    flags ? " " : "", to_name);
+		if (rv < 0) {
+			warn("Cannot execute %s", command);
+			goto out;
+		}
+		command = _PATH_BSHELL;
+		flags = "-c";
+	} else
+		cmd = __UNCONST(to_name);
+
 	args[0] = __UNCONST(command);
 	if (flags)
 		args[i++] = __UNCONST(flags);
-	args[i++] = __UNCONST(to_name);
+	args[i++] = cmd;
 	args[i] = NULL;
 
 #ifdef HAVE_POSIX_SPAWN
@@ -1018,11 +1032,14 @@ run(const char *command, const char *fla
 		_exit(1);
 		/*NOTREACHED*/
 	default:
-		rv = wait(&status);
 		break;
 	}
 #endif
-	if ((rv == -1 || status) && errunlink)
+	rv = wait(&status);
+	if (cmd != to_name)
+		free(cmd);
+out:
+	if ((rv < 0 || status) && errunlink)
 		(void)unlink(to_name);
 }
 

Reply via email to