Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Dec 2018 01:38:51 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r341803 - head/libexec/rc
Message-ID:  <201812110138.wBB1cp1p006660@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Tue Dec 11 01:38:50 2018
New Revision: 341803
URL: https://svnweb.freebsd.org/changeset/base/341803

Log:
  rc.subr: Implement list_vars without using 'read'
  
  'read' pessimistically read(2)s one byte at a time, which can be quite
  silly for large environments in slow emulators.
  
  In my boring user environment, truss shows that the number of read()
  syscalls to source rc.subr and invoke list_vars is reduced by something like
  3400 to 60.  ministat(1) shows a significant time difference of about -71%
  for my environment.
  
  Suggested by:	jilles
  Discussed with:	dteske, jhb, jilles
  Differential Revision:	https://reviews.freebsd.org/D18481

Modified:
  head/libexec/rc/rc.subr

Modified: head/libexec/rc/rc.subr
==============================================================================
--- head/libexec/rc/rc.subr	Mon Dec 10 21:47:19 2018	(r341802)
+++ head/libexec/rc/rc.subr	Tue Dec 11 01:38:50 2018	(r341803)
@@ -58,17 +58,29 @@ JID=0
 #	---------
 
 # list_vars pattern
-#	List vars matching pattern.
+#	List variables matching glob pattern.
 # 
 list_vars()
 {
-	set | { while read LINE; do
-		var="${LINE%%=*}"
-		case "$var" in
-		"$LINE"|*[!a-zA-Z0-9_]*) continue ;;
-		$1) echo $var
+	# Localize 'set' option below.
+	local -
+	local IFS=$'\n' line varname
+
+	# Disable path expansion in unquoted 'for' parameters below.
+	set -o noglob
+
+	for line in $(set); do
+		varname="${line%%=*}"
+
+		case "$varname" in
+		"$line"|*[!a-zA-Z0-9_]*)
+			continue
+			;;
+		$1)
+			echo $varname
+			;;
 		esac
-	done; }
+	done
 }
 
 # set_rcvar [var] [defval] [desc]



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