Blob Blame History Raw
From 6e3cc00f4882edbabea75945308f8ae7c353bf82 Mon Sep 17 00:00:00 2001
From: Will Woods <wwoods@redhat.com>
Date: Tue, 6 Mar 2012 18:25:25 -0500
Subject: [PATCH] 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.
---
 dracut-functions.sh                 |    2 +-
 modules.d/40network/net-genrules.sh |   24 +++++++++---------------
 modules.d/99base/initqueue.sh       |   15 +++++++--------
 3 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/dracut-functions.sh b/dracut-functions.sh
index 05c1d3a..f4ccf53 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 6c46d9a..84fd3ac 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 2c06a0b..3387e88 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