]> git.ipfire.org Git - people/ms/network.git/commitdiff
header-zone: refactor hook_edit nad hook_new
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 19 Jul 2017 14:10:20 +0000 (16:10 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Jul 2017 17:10:11 +0000 (19:10 +0200)
We now return error codes and break when something important goes wrong.
because of that, we have to split hook_new and hook_edit.
When zone_settins-read fails in hook_edit we cannot go but it would every time we would call it in hook_new.

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

index 98b0ce775ea29b0b624aa573d5c2bed0b7fb1c7a..219b0d624e477cec4d6487483d17842a945a6589 100644 (file)
@@ -34,17 +34,39 @@ hook_new() {
        assert isset zone
        shift
 
-       zone_settings_read "${zone}"
-
-       hook_parse_cmdline $@
+       if ! hook_parse_cmdline $@; then
+               return ${EXIT_ERROR}
+       fi
 
-       zone_settings_write "${zone}"
+       if ! zone_settings_write "${zone}"; then
+               log ERROR "Could not write settings for zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
 
        exit ${EXIT_OK}
 }
 
 hook_edit() {
-       hook_new $@
+       local zone="${1}"
+       assert isset zone
+       shift
+
+       if ! zone_settings_read "${zone}"; then
+               log ERROR "Could not read settings for zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
+
+       if ! hook_parse_cmdline $@; then
+               return ${EXIT_ERROR}
+       fi
+
+       if ! zone_settings_write "${zone}"; then
+               log ERROR "Could not write settings for zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
+
+       exit ${EXIT_OK}
+
 }
 
 hook_remove() {