svn commit: r286830 - head/lib/libc/gen

Jilles Tjoelker jilles at FreeBSD.org
Sun Aug 16 19:42:16 UTC 2015


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);


More information about the svn-src-head mailing list