http://bugs.gentoo.org/149426 keep from blowing up when people have duplicate aliases ... the grep ends up including new lines and with certain formed comments, hits an infinite loop ... for example, the following inputs illustrates the problem: ---------------------------------------------- # Old nvidia support ... alias char-major-195 NVdriver alias /dev/nvidiactl char-major-195 alias char-major-195 nvidia alias /dev/nvidiactl char-major-195 # To enable Side Band Adressing: NVreg_EnableAGPSBA=1 #options nvidia NVreg_EnableAGPSBA=1 NVreg_EnableAGPFW=1 #options nvidia NVreg_SoftEDIDs=0 NVreg_Mobile=3 ---------------------------------------------- alias a b alias b a ---------------------------------------------- fixes from Martin Väth --- generate-modprobe.conf +++ generate-modprobe.conf @@ -65,19 +65,29 @@ # Resolve (possibly recursive) alias: args filename alias resolve_alias() { - RA_RESOLVE=`grep "^alias[ ][ ]*$2[ ]" -- $1 | awk '{ print $3 }'` + if [ 0$3 -gt 99 ]; then + echo "Infinite recursion detected; aborting after $3 tries (alias '$2')" 1>&2 + return 1 + fi + + _RA_RESOLVE=`grep "^alias[ ][ ]*$2[ ]" -- $1 | awk '{ print $3 }'` + RA_RESOLVE=`echo "$_RA_RESOLVE" | head -n 1` + if [ x"$_RA_RESOLVE" != x"$RA_RESOLVE" ]; then + echo "Invalid dupliate alias found for '$2' (results: `echo $_RA_RESOLVE`)" 1>&2 + return 1 + fi if [ x"$RA_RESOLVE" = x ]; then echo $2 return fi # Recurse. - (resolve_alias $1 "$RA_RESOLVE") + (resolve_alias $1 "$RA_RESOLVE" $(($3 + 1))) } # Parse alias: args filename modulename aliasto. parse_alias() { - PA_ALIAS=`resolve_alias $1 $3` + PA_ALIAS=`resolve_alias $1 $3` || exit 1 NAME=`echo $2|sed -e 's/\(block\|char\)-major-\([0-9]\+\)$/\1-major-\2-*/'` echo "alias $NAME $PA_ALIAS" @@ -180,7 +190,8 @@ parse_options $MODULE `grab_noninstall_options $REST` INSTALL_OPTIONS=`grab_install_options $REST` INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" - eval install_$MODNAME=\"/sbin/modprobe $INSTALL_OPTIONS --ignore-install `resolve_alias $MODPROBECONF $MODULE`\" + INSTALL_ALIAS=`resolve_alias $MODPROBECONF "$MODULE"` || exit 1 + eval install_$MODNAME=\"/sbin/modprobe $INSTALL_OPTIONS --ignore-install $INSTALL_ALIAS\" ;; *) parse_options $MODULE "$REST"