Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Aug 2015 19:42:15 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r286830 - head/lib/libc/gen
Message-ID:  <201508161942.t7GJgFPs032642@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Aug 16 19:42:15 2015
New Revision: 286830
URL: https://svnweb.freebsd.org/changeset/base/286830

Log:
  wordexp(): Stop using the undocumented wordexp builtin.
  
  The functionality of the wordexp builtin is easily replaced using normal
  shell code, although performance is slightly worse.
  
  This does not mean that wordexp() will remain shell-independent -- a fully
  reliable implementation of WRDE_NOCMD is really only possible using
  extensions to the shell, or by adding much of the shell's code to libc.

Modified:
  head/lib/libc/gen/wordexp.c

Modified: head/lib/libc/gen/wordexp.c
==============================================================================
--- head/lib/libc/gen/wordexp.c	Sun Aug 16 19:06:23 2015	(r286829)
+++ head/lib/libc/gen/wordexp.c	Sun Aug 16 19:42:15 2015	(r286830)
@@ -138,8 +138,7 @@ we_askshell(const char *words, wordexp_t
 	}
 	else if (pid == 0) {
 		/*
-		 * We are the child; just get /bin/sh to run the wordexp
-		 * builtin on `words'.
+		 * We are the child; make /bin/sh expand `words'.
 		 */
 		(void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
 		if ((pdes[1] != STDOUT_FILENO ?
@@ -147,7 +146,9 @@ we_askshell(const char *words, wordexp_t
 		    _fcntl(pdes[1], F_SETFD, 0)) < 0)
 			_exit(1);
 		execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u",
-		    "-c", "IFS=$1;eval \"$2\";eval \"wordexp $3\"", "",
+		    "-c", "IFS=$1;eval \"$2\";eval \"set -- $3\";IFS=;a=\"$*\";"
+		    "printf '%08x' \"$#\" \"${#a}\";printf '%s\\0' \"$@\"",
+		    "",
 		    ifs != NULL ? ifs : " \t\n",
 		    flags & WRDE_SHOWERR ? "" : "exec 2>/dev/null", words,
 		    (char *)NULL);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508161942.t7GJgFPs032642>