]> git.ipfire.org Git - people/ms/network.git/commitdiff
Let hotplug handlers return a status code
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Sep 2014 09:54:04 +0000 (11:54 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Sep 2014 09:54:04 +0000 (11:54 +0200)
After a port has been hotplugged, we will walk through all
port configuration files and check if the device matches.
The hooks must now return whether they have handled the event
so that we can stop searching or not.

src/functions/functions.constants
src/header-port
src/hooks/ports/batman-adv-port
src/hooks/ports/wireless-ap
src/udev/network-hotplug

index c9ad263a592a6889bd8eca06c352e15044322a2e..e47b4c13da9f25ef71df4f26a4a582eb889790f1 100644 (file)
@@ -52,6 +52,7 @@ EXIT_OK=0
 EXIT_ERROR=1
 EXIT_CONF_ERROR=2
 EXIT_NOT_SUPPORTED=3
+EXIT_NOT_HANDLED=4
 EXIT_COMMAND_NOT_FOUND=127
 EXIT_ERROR_ASSERT=128
 
index cf4ef0de6113d2cf5c69f4d86cda82b579e5fa3d..a26d8db237e05f99e088a52984a349d702a0017f 100644 (file)
@@ -26,7 +26,9 @@ INFO_SETTINGS="HOOK PORT_PARENTS PORT_CHILDREN"
 # The function is intended to create child ports and things
 # like that.
 function hook_hotplug() {
-       exit ${EXIT_OK}
+       # If the hook does not handle the hotplug event, it
+       # must return EXIT_NOT_HANDLED.
+       exit ${EXIT_NOT_HANDLED}
 }
 
 # This function gets called when a device is plugged in
index 129acb72eab7c95bfd41c1d42e673245d603ae2b..55d7e2e6d6c757fa337fd73fbdd6dbc23bf7ec59 100644 (file)
@@ -178,16 +178,18 @@ function hook_hotplug() {
        port_settings_read "${port}" ${HOOK_SETTINGS}
 
        # Get the address of the phy.
-       local phy_address=$(phy_get_address ${phy})
+       local phy_address=$(phy_get_address "${phy}")
 
        # Check if the phy is the same we have
        # read from the configuration file.
        if [ "${PHY}" = "${phy_address}" ]; then
                # Bring up the device.
                port_up "${port}"
+
+               exit ${EXIT_OK}
        fi
 
-       exit ${EXIT_OK}
+       exit ${EXIT_NOT_HANDLED}
 }
 
 function hook_find_parent() {
index 90a72d096f970f6429467b23c97d2da502a97268..ab84b1f4e972a91aa0d8f538206599d0fe844adf 100644 (file)
@@ -205,7 +205,9 @@ function hook_hotplug() {
        if [ "${PHY}" = "${phy_address}" ]; then
                wireless_create ${port} --phy="${phy_address}" --type="ap" \
                        --address="${ADDRESS}"
+
+               exit ${EXIT_OK}
        fi
 
-       exit ${EXIT_OK}
+       exit ${EXIT_NOT_HANDLED}
 }
index 7b664a9f23546b2154c0c197685083b1202b9ba1..a9787c4977690c4c8effb0b8518225d20af2323b 100644 (file)
@@ -72,7 +72,21 @@ case "${ACTION}" in
 
                                        # Create configured child devices.
                                        for port in $(ports_get_all); do
-                                               port_cmd hotplug ${port} ${phy}
+                                               port_cmd hotplug "${port}" "${phy}"
+                                               ret=$?
+
+                                               case "${ret}" in
+                                                       ${EXIT_OK})
+                                                               log DEBUG "phy '${phy}' was handled by port '${port}'"
+                                                               break
+                                                               ;;
+                                                       ${EXIT_NOT_HANDLED})
+                                                               log DEBUG "phy '${phy}' was not handled by port '${port}'"
+                                                               ;;
+                                                       *)
+                                                               log WARNING "Unknown exit code for port '${port}': ${ret}"
+                                                               ;;
+                                               esac
                                        done
                                        ;;