From 05365355a5ebbee14f0f97126d998ec08e96074d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 6 Sep 2014 11:54:04 +0200 Subject: [PATCH] Let hotplug handlers return a status code 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 | 1 + src/header-port | 4 +++- src/hooks/ports/batman-adv-port | 6 ++++-- src/hooks/ports/wireless-ap | 4 +++- src/udev/network-hotplug | 16 +++++++++++++++- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/functions/functions.constants b/src/functions/functions.constants index c9ad263a..e47b4c13 100644 --- a/src/functions/functions.constants +++ b/src/functions/functions.constants @@ -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 diff --git a/src/header-port b/src/header-port index cf4ef0de..a26d8db2 100644 --- a/src/header-port +++ b/src/header-port @@ -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 diff --git a/src/hooks/ports/batman-adv-port b/src/hooks/ports/batman-adv-port index 129acb72..55d7e2e6 100644 --- a/src/hooks/ports/batman-adv-port +++ b/src/hooks/ports/batman-adv-port @@ -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() { diff --git a/src/hooks/ports/wireless-ap b/src/hooks/ports/wireless-ap index 90a72d09..ab84b1f4 100644 --- a/src/hooks/ports/wireless-ap +++ b/src/hooks/ports/wireless-ap @@ -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} } diff --git a/src/udev/network-hotplug b/src/udev/network-hotplug index 7b664a9f..a9787c49 100644 --- a/src/udev/network-hotplug +++ b/src/udev/network-hotplug @@ -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 ;; -- 2.47.3