hooks: Add overwritable function to determine the port name
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 3 Jun 2019 09:50:13 +0000 (11:50 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 3 Jun 2019 09:50:13 +0000 (11:50 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/header-port

index d75fdd8..7d0b272 100644 (file)
@@ -68,6 +68,12 @@ hook_hotplug_rename_by_address() {
        return ${EXIT_ERROR}
 }
 
+# Returns the suggested name of the port
+hook_find_port_name() {
+       assert isset HOOK_PORT_PATTERN
+       port_find_free "${HOOK_PORT_PATTERN}"
+}
+
 hook_default_new() {
        local ${HOOK_SETTINGS[*]}
 
@@ -78,14 +84,16 @@ hook_default_new() {
                return ${EXIT_ERROR}
        fi
 
-       assert isset HOOK_PORT_PATTERN
-
-       local port=$(port_find_free ${HOOK_PORT_PATTERN})
+       # Determine a name for this port
+       local port="$(hook_find_port_name)"
        assert isset port
 
-       port_settings_write "${port}" ${HOOK_SETTINGS[*]}
+       # Save settings
+       if ! port_settings_write "${port}" ${HOOK_SETTINGS[*]}; then
+               return ${EXIT_ERROR}
+       fi
 
-       exit ${EXIT_OK}
+       return ${EXIT_OK}
 }
 
 hook_new() {