Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xinstall Use the bourne shell if the after command h...



details:   https://anonhg.NetBSD.org/src/rev/1b0c7fd41e3a
branches:  trunk
changeset: 338934:1b0c7fd41e3a
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jun 17 15:34:08 2015 +0000

description:
Use the bourne shell if the after command has shell metachars.

diffstat:

 usr.bin/xinstall/Makefile   |   7 +++++--
 usr.bin/xinstall/xinstall.c |  27 ++++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 7 deletions(-)

diffs (96 lines):

diff -r 0e869acfda01 -r 1b0c7fd41e3a usr.bin/xinstall/Makefile
--- a/usr.bin/xinstall/Makefile Wed Jun 17 14:32:31 2015 +0000
+++ b/usr.bin/xinstall/Makefile Wed Jun 17 15:34:08 2015 +0000
@@ -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
diff -r 0e869acfda01 -r 1b0c7fd41e3a usr.bin/xinstall/xinstall.c
--- a/usr.bin/xinstall/xinstall.c       Wed Jun 17 14:32:31 2015 +0000
+++ b/usr.bin/xinstall/xinstall.c       Wed Jun 17 15:34:08 2015 +0000
@@ -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 @@
 #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 @@
 
 #include "pathnames.h"
 #include "mtree.h"
+#include "metachar.h"
 
 #define BACKUP_SUFFIX ".old"
 
@@ -969,6 +970,7 @@
 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 @@
        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 @@
                _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);
 }
 



Home | Main Index | Thread Index | Old Index