From 7ae917a0ea8517ff0ffe03d3884aee64cd7dcfcd Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Sat, 29 Dec 2012 22:04:52 +0100 Subject: Don't call systemctl if there's nothing to do When starting/stopping multiple profiles, check whether we don't try to start/stop no profiles at all. --- src/netctl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/netctl b/src/netctl index 524d03b..897f648 100755 --- a/src/netctl +++ b/src/netctl @@ -44,15 +44,18 @@ store() { restore() { if [[ ! -r $STATE_FILE ]]; then exit_error "Could not read state file '$STATE_FILE'" + elif [[ ! -s $STATE_FILE ]]; then + report_debug "No profiles to restore in state file '$STATE_FILE'" + else + mapfile -t Units < "$STATE_FILE" + do_debug systemctl start "${Units[@]}" fi - mapfile -t Units < "$STATE_FILE" - do_debug systemctl start "${Units[@]}" } stop_all() { # We cannot pipe to mapfile, as the end of a pipe is inside a subshell mapfile -t Profiles < <(list_profiles) - do_debug systemctl stop "${Profiles[@]/#/netctl@}" 2> \ + [[ $Profiles ]] && do_debug systemctl stop "${Profiles[@]/#/netctl@}" 2> \ >(grep -Fv "not loaded" >&2) } @@ -70,7 +73,7 @@ switch_to() { fi mapfile -t AllProfiles < <(list_profiles) mapfile -t Profiles < <(grep -Fl "$InterfaceLine" "${AllProfiles[@]}") - do_debug systemctl stop "${Profiles[@]/#/netctl@}" 2> \ + [[ $Profiles ]] && do_debug systemctl stop "${Profiles[@]/#/netctl@}" 2> \ >(grep -Fv "not loaded" >&2) do_debug systemctl start "netctl@$1" } -- cgit v1.2.3-24-g4f1b