forked from freifunk-franken/firmware
fff-layer3-config: return error values in functions instead of terminating
Many functions of configure-layer3 terminate the program after successful execution, as they were originally only intended for execution of configure-layer3 commands. However, some functions are used both for command exection, but also as helper functions. For example, revert_changes() is used as a helper function in test_changes(). Terminating the program at the end of the function therefore ends the exection of test_changes() prematurely. As a result, the test mode of configure-layer3 never reloads services after a successful configuration revert. Replace exit commands with appropriate function return values, which can then be evaluated by the caller where appropriate. While at it, add a missing return to the parameter validation in execute_subshell(). Fixes: #256 Signed-off-by: Fabian Bläse <fabian@blaese.de> Reviewed-by: Robert Langhammer <rlanghammer@web.de>
This commit is contained in:
parent
baca28ece3
commit
bdfdbba76a
|
@ -7,6 +7,7 @@
|
|||
execute_subshell() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage:" "$0" "<function>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
for script in /etc/layer3.d/*; do
|
||||
|
@ -23,7 +24,7 @@ execute_subshell() {
|
|||
if [ $? -ne 0 ]; then
|
||||
echo
|
||||
echo "Error when executing" "$1" "from" "$(basename "$script")"
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -32,29 +33,33 @@ configure() {
|
|||
echo "This script might remove existing vlans, interfaces, addresses, etc."
|
||||
read -r -p "Do you really want to continue? (y/n) " response
|
||||
if ! ( [ "$response" == "y" ] || [ "$response" == "Y" ] ); then
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo
|
||||
execute_subshell configure
|
||||
execute_subshell configure || return $?
|
||||
|
||||
exit 0
|
||||
return 0
|
||||
}
|
||||
|
||||
reload_services() {
|
||||
execute_subshell reload
|
||||
reload_config
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
apply_changes() {
|
||||
execute_subshell apply
|
||||
reload_services
|
||||
exit 0
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
revert_changes() {
|
||||
execute_subshell revert
|
||||
exit 0
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
keep_changes() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user