From 0b2a5ddd786f2e7b6ce0f1b6d7ac7efd424aadbd Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Sun, 13 Sep 2009 23:43:43 -0400 Subject: Consolidate check_iface and get_iface_prof 1. Change the behavior of check_iface to match that of get_iface_prof (that is, echo either "external" or the profile name, and return 0=true, or echo nothing and return 1=false). 2. Then eliminate get_iface_prof. Signed-off-by: Jim Pryor --- src/network | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/network b/src/network index d1c4235..996d0d1 100644 --- a/src/network +++ b/src/network @@ -88,7 +88,7 @@ all_resume() . "$STATE_DIR/suspend/$prof" if [[ $# -eq 0 || ! " $* " =~ " $INTERFACE " ]]; then report_notify "resuming interface $INTERFACE with profile $prof" - profile_up "$prof" + profile_up "$prof" rm -f "$STATE_DIR/suspend/$prof" # if profile_up succeeds, it will have already removed this fi done @@ -196,7 +196,7 @@ profile_down() fi report_try "$PROFILE down" - if [[ "$(get_iface_prof "$INTERFACE")" == "external" ]]; then + if [[ "$(check_iface "$INTERFACE")" == "external" ]]; then report_fail "$interface was connected by another application" exit 1 fi @@ -248,25 +248,26 @@ quirk() { # interface_down() { - local prof=$(get_iface_prof "$1") - profile_down "$prof" - return $? + local status=$(check_iface "$1") + case "$status" in + disabled) return 0 ;; + "") return 0 ;; + external) return 1 ;; + *) profile_down "$status" ;; + esac } ## # check_iface interface -# Return 0 if interface up -# Return 1 if interface down +# Return 0 if interface unavailable (in use by a profile or externally, or disabled) +# Return 1 if interface down and available to be used # check_iface() { if [[ -f "$STATE_DIR/interfaces/$1" ]]; then ( . "$STATE_DIR/interfaces/$1" - if [[ "$PROFILE" == "external" ]]; then - echo "external" - else - echo "up" - fi + echo "$PROFILE" # may be: external, disabled, or a profile name + return 0 ) return 0 else @@ -274,19 +275,6 @@ check_iface() { fi } -# get_iface_prof interface -# Echo interface profile and return 0 if up -# Return 1 if down. -# -get_iface_prof() { - if check_iface "$1" &>/dev/null; then - . "$STATE_DIR/interfaces/$1" - echo "$PROFILE" - else - return 1 - fi -} - # list_profiles # Outputs a list of all profiles list_profiles() { -- cgit v1.2.3-24-g4f1b