Skip to contentSkip to conversation

more precise option parsing in init script

PATCH New Jeff Moyer 1 participant 1 message May 6, 2004 Kernel automounter

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 more precise option parsing in init script

Hi Ian, List,

The current parsing out of daemon options in the init script can lead to collisions with filesystem options. For instance, if we see a -g, -t, -v, or -d, we assume this is ghost, timeout, verbose, or debug, respectively. In fact, this could be a filesystem option beginning with the same letter. This patch addresses this issue. I've done unit testing on each of the expressions to ensure it matches where it should, and doesn't match where it shouldn't. If anyone on the list is especially gifted in regexp, please review.

-Jeff

samples/rc.autofs.in renamed from samples/rc.autofs.in.diffme +30 -18
@@ -152,35 +152,47 @@
 		# If the options include a -t or --timeout or a -g or --ghost
 		# parameter, then pull those particular options out.
 		: echo DAEMONOPTIONS OPTIONS $DAEMONOPTIONS $options
+
 		startupoptions=
-		if echo "$DAEMONOPTIONS" | grep -q -- '-t' ; then
-		    startupoptions="--timeout=$(echo $DAEMONOPTIONS $options | \
-		      sed 's/.*--*t\(imeout\)*[ \t=]*\([0-9][0-9]*\).*$/\2/g')"
-		fi
-		# Override timeout in $DAEMONOPTIONS with map $options
-		if echo "$options" | grep -q -- '-t' ; then
-		    startupoptions="--timeout=$(echo $DAEMONOPTIONS $options | \
+		if echo "$options" | grep -qE -- '\B-(t\b|-timeout\b=)' ;
+		then
+		    startupoptions="--timeout=$(echo $options |\
+			sed 's/.*-\(t[^0-9]*\|-timeout\)[ \t=]*\([0-9][0-9]*\).*$/\2/g')"
+		elif echo "$DAEMONOPTIONS" | grep -q -- '-t' ;
+		then
+		    # It's okay to be sloppy with DAEMONOPTIONS as there is no
+		    # possibility of conflicting with mount or map options.
+		    startupoptions="--timeout=$(echo $DAEMONOPTIONS | \
 		      sed 's/.*--*t\(imeout\)*[ \t=]*\([0-9][0-9]*\).*$/\2/g')"
 		fi
-		if echo "$DAEMONOPTIONS $options" | grep -q -- '-g' ; then
+
+		# Check for the ghost option
+		if echo "$options" | grep -qE -- '\B-(g\b|-ghost\b)' ;
+		then
 		    startupoptions="$startupoptions --ghost"
 		fi
-		if echo "$DAEMONOPTIONS $options" | grep -q -- '-v' ; then
+
+		# Check for verbose
+		if echo "$DAEMONOPTIONS $options" | \
+					grep -qE -- '\B-(v\b|-verbose\b)' ;
+		then
 		    startupoptions="$startupoptions --verbose"
 		fi
-		if echo "$DAEMONOPTIONS $options" | grep -q -- '-d' ; then
+
+		# Check for debug
+		if echo "$DAEMONOPTIONS $options" | \
+					grep -qE -- '\B-(d\b|-debug\b)' ;
+		then
 		    startupoptions="$startupoptions --debug"
 		fi
+
 		# Other option flags are intended for maps.
 		mapoptions="$(echo "$DAEMONOPTIONS $options" |\
-		      sed   's/--*t\(imeout\)*[ \t=]*\([0-9][0-9]*\)//g' |
-		      sed   's/--*g\(host\)*//g' |
-		      sed   's/--*v\(verbose\)*//g' |
-		      sed   's/--*d\(ebug\)*//g')"
-		if [ $STRIPDASH -eq 1 ] ; then
-		    mapoptions="$(echo "$mapoptions" |\
-			sed  's/^\([ \t]*-\)//g')"
-		fi
+		      sed   's/-\(t[^0-9]*\|-timeout\)[ \t=]*\([0-9][0-9]*\)//g' |
+		      sed   's/-\(g\b\|-ghost\b\)//g' |
+		      sed   's/-\(v\b\|-verbose\b\)//g' |
+		      sed   's/-\(d\b\|-debug\b\)//g')"
+
 		# Break up the maptype and map, if the map type is specified
 		maptype=`echo $map | cut -f1 -d:`
 		# Handle degenerate map specifiers