* [PATCH 1/3] header-zone: refactor hook_edit nad hook_new
@ 2017-07-19 14:10 Jonatan Schlag
2017-07-19 14:10 ` [PATCH 2/3] zone: fix zone_new Jonatan Schlag
2017-07-19 14:10 ` [PATCH 3/3] hook: return error codes to previos functions Jonatan Schlag
0 siblings, 2 replies; 3+ messages in thread
From: Jonatan Schlag @ 2017-07-19 14:10 UTC (permalink / raw)
To: network
[-- Attachment #1: Type: text/plain, Size: 1423 bytes --]
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(a)ipfire.org>
---
| 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
--git a/src/header-zone b/src/header-zone
index 98b0ce7..219b0d6 100644
--- a/src/header-zone
+++ b/src/header-zone
@@ -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() {
--
2.6.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/3] zone: fix zone_new
2017-07-19 14:10 [PATCH 1/3] header-zone: refactor hook_edit nad hook_new Jonatan Schlag
@ 2017-07-19 14:10 ` Jonatan Schlag
2017-07-19 14:10 ` [PATCH 3/3] hook: return error codes to previos functions Jonatan Schlag
1 sibling, 0 replies; 3+ messages in thread
From: Jonatan Schlag @ 2017-07-19 14:10 UTC (permalink / raw)
To: network
[-- Attachment #1: Type: text/plain, Size: 817 bytes --]
Everytime somethings goes wrong when we call hook_new we wannt to call zone_destroy.
Not only when we get an EXIT_ERROR also when we get an EXIT_CONF_ERROR and so on.
Signed-off-by: Jonatan Schlag <jonatan.schlag(a)ipfire.org>
---
src/functions/functions.zone | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/functions/functions.zone b/src/functions/functions.zone
index 11a8dc2..91ce629 100644
--- a/src/functions/functions.zone
+++ b/src/functions/functions.zone
@@ -243,7 +243,7 @@ zone_new() {
# Maybe the zone new hook did not exit correctly.
# If this is the case we remove the created zone immediately.
- if [ "${ret}" = "${EXIT_ERROR}" ]; then
+ if [ "${ret}" != "${EXIT_OK}" ]; then
zone_destroy_now "${zone}"
return ${EXIT_ERROR}
fi
--
2.6.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 3/3] hook: return error codes to previos functions
2017-07-19 14:10 [PATCH 1/3] header-zone: refactor hook_edit nad hook_new Jonatan Schlag
2017-07-19 14:10 ` [PATCH 2/3] zone: fix zone_new Jonatan Schlag
@ 2017-07-19 14:10 ` Jonatan Schlag
1 sibling, 0 replies; 3+ messages in thread
From: Jonatan Schlag @ 2017-07-19 14:10 UTC (permalink / raw)
To: network
[-- Attachment #1: Type: text/plain, Size: 972 bytes --]
When we call an hook we should not exit with the error code.
Instead we should return the code to the function that called that hook function.
So we candle handle errors better.
Signed-off-by: Jonatan Schlag <jonatan.schlag(a)ipfire.org>
---
src/functions/functions.hook | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/functions/functions.hook b/src/functions/functions.hook
index b99023d..d1f6506 100644
--- a/src/functions/functions.hook
+++ b/src/functions/functions.hook
@@ -102,11 +102,11 @@ hook_exec() {
${EXIT_COMMAND_NOT_FOUND}|${EXIT_NOT_SUPPORTED})
log ERROR "Hook '${hook}' does not implement the method '${cmd}':"
log ERROR " arguments: $@"
- exit ${EXIT_COMMAND_NOT_FOUND}
+ return ${EXIT_COMMAND_NOT_FOUND}
;;
${EXIT_ERROR_ASSERT})
log ERROR "Hook exited with an assertion error."
- exit ${EXIT_ERROR_ASSERT}
+ return ${EXIT_ERROR_ASSERT}
;;
esac
--
2.6.3
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-19 14:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-19 14:10 [PATCH 1/3] header-zone: refactor hook_edit nad hook_new Jonatan Schlag
2017-07-19 14:10 ` [PATCH 2/3] zone: fix zone_new Jonatan Schlag
2017-07-19 14:10 ` [PATCH 3/3] hook: return error codes to previos functions Jonatan Schlag
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox