[arch-projects] [PATCH] rc.d: declare ENV as an array

Dave Reisner d at falconindy.com
Fri May 27 09:09:44 EDT 2011


Signed-off-by: Dave Reisner <d at falconindy.com>
---
Sorry to sneak this in -- I should have noticed it earlier. This is simply a
continuation of my crusade against eval, which would happily go to town with
word splitting.

As this conflicts with Eric's patch, one of us will need to refactor slightly.

dave

 rc.d |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/rc.d b/rc.d
index 55871b1..af29574 100755
--- a/rc.d
+++ b/rc.d
@@ -46,13 +46,13 @@ case $1 in
 		shift
 		# set same environment variables as init
 		runlevel=$(/sbin/runlevel)
-		ENV="PATH='/bin:/usr/bin:/sbin:/usr/sbin'"
-		ENV+=" PREVLEVEL='${runlevel:0:1}'"
-		ENV+=" RUNLEVEL='${runlevel:2:1}'"
-		ENV+=" CONSOLE='${CONSOLE:-/dev/console}'"
-		ENV+=" TERM='${TERM}'"
+		ENV=("PATH=/bin:/usr/bin:/sbin:/usr/sbin"
+			"PREVLEVEL=${runlevel%% *}"
+			"RUNLEVEL=${runlevel##* }"
+			"CONSOLE=${CONSOLE:-/dev/console}"
+			"TERM=$TERM")
 		for i; do
-			[[ -x "/etc/rc.d/$i" ]] && cd / && eval /usr/bin/env -i $ENV "/etc/rc.d/$i" "$action"
+			[[ -x "/etc/rc.d/$i" ]] && cd / && /usr/bin/env -i "${ENV[@]}" "/etc/rc.d/$i" "$action"
 			(( ret += !! $? ))  # clamp exit value to 0/1
 		done
 esac
-- 
1.7.5.2



More information about the arch-projects mailing list