From: Will Woods Date: Tue, 6 Mar 2012 23:25:25 +0000 (-0500) Subject: add initqueue --env and "online" hook X-Git-Tag: 018~64 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6e3cc00f4882edbabea75945308f8ae7c353bf82;p=thirdparty%2Fdracut.git add initqueue --env and "online" hook The "online" hook runs whenever a network interface comes online (that is, once it's actually up and configured). The initqueue --env argument is used to set "$netif" to the name of the newly-online network interface. --- diff --git a/dracut-functions.sh b/dracut-functions.sh index 05c1d3a58..f4ccf53a8 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -35,7 +35,7 @@ fi # export standard hookdirs [[ $hookdirs ]] || { hookdirs="cmdline pre-udev pre-trigger netroot " - hookdirs+="initqueue initqueue/settled initqueue/finished initqueue/timeout " + hookdirs+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout " hookdirs+="pre-mount pre-pivot mount " hookdirs+="emergency shutdown-emergency shutdown cleanup " export hookdirs diff --git a/modules.d/40network/net-genrules.sh b/modules.d/40network/net-genrules.sh index 6c46d9afb..84fd3ac23 100755 --- a/modules.d/40network/net-genrules.sh +++ b/modules.d/40network/net-genrules.sh @@ -31,33 +31,27 @@ fix_bootif() { IFACES=${bondslaves%% *} fi + ifup='/sbin/ifup $env{INTERFACE}' + [ -z "$netroot" ] && ifup="$ifup -m" + # BOOTIF says everything, use only that one BOOTIF=$(getarg 'BOOTIF=') if [ -n "$BOOTIF" ] ; then BOOTIF=$(fix_bootif "$BOOTIF") - if [ -n "$netroot" ]; then - printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", OPTIONS+="event_timeout=360", RUN+="/sbin/initqueue --onetime /sbin/ifup $env{INTERFACE}"\n' "$BOOTIF" - else - printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", OPTIONS+="event_timeout=360", RUN+="/sbin/initqueue --onetime /sbin/ifup $env{INTERFACE} -m"\n' "$BOOTIF" - fi + printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="%s"\n' "$BOOTIF" "/sbin/initqueue --onetime $ifup" # If we have to handle multiple interfaces, handle only them. elif [ -n "$IFACES" ] ; then for iface in $IFACES ; do - if [ -n "$netroot" ]; then - printf 'SUBSYSTEM=="net", ENV{INTERFACE}=="%s", OPTIONS+="event_timeout=360", RUN+="/sbin/initqueue --onetime /sbin/ifup $env{INTERFACE}"\n' "$iface" - else - printf 'SUBSYSTEM=="net", ENV{INTERFACE}=="%s", OPTIONS+="event_timeout=360", RUN+="/sbin/initqueue --onetime /sbin/ifup $env{INTERFACE} -m"\n' "$iface" - fi + printf 'SUBSYSTEM=="net", ENV{INTERFACE}=="%s", RUN+="%s"\n' "$iface" "/sbin/initqueue --onetime $ifup" done # Default: We don't know the interface to use, handle all else - if [ -n "$netroot" ]; then - printf 'SUBSYSTEM=="net", OPTIONS+="event_timeout=360", RUN+="/sbin/initqueue --onetime /sbin/ifup $env{INTERFACE}"\n' - else - printf 'SUBSYSTEM=="net", OPTIONS+="event_timeout=360", RUN+="/sbin/initqueue --onetime /sbin/ifup $env{INTERFACE} -m"\n' - fi + printf 'SUBSYSTEM=="net", RUN+="%s"\n' "/sbin/initqueue --onetime $ifup" fi + # Run the "online" hook + printf 'SUBSYSTEM=="net", ACTION=="online", RUN+="/sbin/initqueue --onetime --env netif=$env{INTERFACE} source_hook initqueue/online"\n' + } > /etc/udev/rules.d/60-net.rules diff --git a/modules.d/99base/initqueue.sh b/modules.d/99base/initqueue.sh index 2c06a0b26..3387e8888 100755 --- a/modules.d/99base/initqueue.sh +++ b/modules.d/99base/initqueue.sh @@ -25,6 +25,8 @@ while [ $# -gt 0 ]; do unique="yes";; --name) name="$2";shift;; + --env) + env="$2"; shift;; *) break;; esac @@ -43,14 +45,11 @@ shift [ -x "$exe" ] || exe=$(command -v $exe) -if [ -n "$onetime" ]; then - { - echo '[ -e "$job" ] && rm "$job"' - echo "$exe $@" - } > "/tmp/$$-${job}.sh" -else - echo "$exe $@" > "/tmp/$$-${job}.sh" -fi +{ + [ -n "$onetime" ] && echo '[ -e "$job" ] && rm "$job"' + [ -n "$env" ] && echo "$env" + echo "$exe $@" +} > "/tmp/$$-${job}.sh" mv -f "/tmp/$$-${job}.sh" "$hookdir/initqueue${qname}/${job}.sh" [ -z "$qname" ] && >> $hookdir/initqueue/work