From bdfdbba76a2b657bafd99f3c89c9294a901db3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Wed, 20 Jul 2022 12:54:00 +0200 Subject: [PATCH] fff-layer3-config: return error values in functions instead of terminating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Robert Langhammer --- .../files/usr/sbin/configure-layer3 | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/packages/fff/fff-layer3-config/files/usr/sbin/configure-layer3 b/src/packages/fff/fff-layer3-config/files/usr/sbin/configure-layer3 index b32a7100..170e39cb 100755 --- a/src/packages/fff/fff-layer3-config/files/usr/sbin/configure-layer3 +++ b/src/packages/fff/fff-layer3-config/files/usr/sbin/configure-layer3 @@ -7,6 +7,7 @@ execute_subshell() { if [ $# -ne 1 ]; then echo "Usage:" "$0" "" + 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() {