summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Pryor <profjim@jimpryor.net>2009-09-14 05:43:43 +0200
committerJames Rayner <james@archlinux.org>2009-09-14 08:25:45 +0200
commit0b2a5ddd786f2e7b6ce0f1b6d7ac7efd424aadbd (patch)
tree27130baa4feef9eb9c6a8f5b04342cd0d1a3ccb0 /src
parentae4adf79c86e1c77192dc0022ead9b46214418fe (diff)
downloadnetctl-0b2a5ddd786f2e7b6ce0f1b6d7ac7efd424aadbd.tar.gz
netctl-0b2a5ddd786f2e7b6ce0f1b6d7ac7efd424aadbd.tar.xz
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 <profjim@jimpryor.net>
Diffstat (limited to 'src')
-rw-r--r--src/network38
1 files 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() {