]> git.ipfire.org Git - network.git/commitdiff
header-zone: refactor hook_config_destroy
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Fri, 14 Jul 2017 12:19:42 +0000 (14:19 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 Jul 2017 09:38:58 +0000 (11:38 +0200)
We now just bring the hook down, execute hook_destroy which can be not empty inside the hook,
because it is defined in src/header-config.
After this we delete the config file.

Fixes: #11416
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/header-config
src/header-zone

index e3c642338c33b06f0a288185ae38633c455c7b91..868dce499710ad8761a9c2aa3285f367b977fa82 100644 (file)
@@ -76,3 +76,7 @@ hook_edit() {
 
        exit ${EXIT_OK}
 }
+
+hook_destroy() {
+       return ${EXIT_OK}
+}
index 219b0d624e477cec4d6487483d17842a945a6589..189fbc38d7f365d5215f29e4a9c51ee2efb16f79 100644 (file)
@@ -243,7 +243,21 @@ hook_config_destroy() {
        local hook=$(zone_config_get_hook_from_id ${zone}  ${id})
        assert isset hook
 
-       hook_config_cmd "destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"
+       # First we bring the hook down
+       hook_config_cmd "down" "${zone}" "${hook}" "${hook}.${id}"
+
+       # If a hook_destroy function is implemented in the hook this function will be executed.
+       # If not a empty defined in header-config is executed.
+       if ! hook_config_cmd "destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"; then
+
+               # A better error message should printed inside the hook.
+               # We will not bring the config up because we do not know if it is safe or if some parts are already destroyed.
+               log ERROR "Could not destroy config with the follwoing id: ${id}"
+               return ${EXIT_ERROR}
+       fi
+
+       # Now we delete the config of the zone
+       zone_config_settings_destroy "${zone}" "${hook}.${id}"
 }
 
 hook_config_edit() {