summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Pryor <profjim@jimpryor.net>2009-08-11 14:05:12 +0200
committerJames Rayner <james@archlinux.org>2009-08-15 04:28:30 +0200
commit2282776f1dd928b6c5f56e30cbf2c52a4f26303d (patch)
tree27405023000e067eb0f440bb03fc7bb2afbf4e33 /src
parentdc0c1d07198702dfaeece618f05608ae14e9f358 (diff)
downloadnetctl-2282776f1dd928b6c5f56e30cbf2c52a4f26303d.tar.gz
netctl-2282776f1dd928b6c5f56e30cbf2c52a4f26303d.tar.xz
Improve suspend/resume, allow for subsets of ifaces
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
Diffstat (limited to 'src')
-rw-r--r--src/network51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/network b/src/network
index f1ce0b2..ae74837 100644
--- a/src/network
+++ b/src/network
@@ -43,34 +43,53 @@ all_down()
done
}
-# all_suspend
-# store a list of running profiles and take them down
-#
-all_suspend()
+# interface_suspend interface/all [call_profile_down? default=yes]
+# store a list of running profiles and take them down (unless $2 is "no")
+interface_suspend()
{
- [[ ! -d $STATE_DIR ]] && mkdir -p $STATE_DIR/{interfaces,profiles}
- [[ ! -d $STATE_DIR/suspend ]] && mkdir $STATE_DIR/suspend
+ report_debug interface_suspend "$@"
+
+ [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles}
+ [[ ! -d "$STATE_DIR/suspend" ]] && mkdir "$STATE_DIR/suspend"
find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \
| while read prof; do
# the pipe to "while read" will create a subshell, so sourced variables will already be in a sandbox
- report_notify "suspending profile $prof"
- cp "$STATE_DIR/profiles/$prof" "$STATE_DIR/suspend/"
- profile_down "$prof"
+ # we just need to clear INTERFACE which is all we care about
+ unset INTERFACE
+ . "$STATE_DIR/profiles/$prof"
+ if [[ "$1" == all || "$1" == "$INTERFACE" ]]; then
+ report_notify "suspending interface $INTERFACE with profile $prof"
+ cp "$STATE_DIR/profiles/$prof" "$STATE_DIR/suspend/"
+ if checkyesno "${2:-yes}"; then
+ profile_down "$prof"
+ fi
+ fi
done
}
+# all_suspend
+# store a list of running profiles and take them down
+all_suspend() {
+ interface_suspend all
+}
# all_resume
# resume suspended interfaces
+# optional arguments: interfaces not to resume (e.g., because they're disabled)
all_resume()
{
report_debug all_resume "$@"
find "$STATE_DIR/suspend/" -maxdepth 1 -type f -printf '%f\n' \
| while read prof; do
# the pipe to "while read" will create a subshell, so sourced variables will already be in a sandbox
- report_notify "resuming profile $prof"
+ # we just need to clear INTERFACE which is all we care about
+ unset INTERFACE
+ . "$STATE_DIR/suspend/$prof"
+ if [[ $# -eq 0 || ! " $* " =~ " $INTERFACE " ]]; then
+ report_notify "resuming interface $INTERFACE with profile $prof"
profile_up "$prof"
- rm -f "$STATE_DIR/suspend/$prof" # if profile_up succeeds, it will have already removed this
+ rm -f "$STATE_DIR/suspend/$prof" # if profile_up succeeds, it will have already removed this
+ fi
done
}
@@ -82,7 +101,7 @@ profile_up()
(
# Keep inside subshell so that options from one profile don't cross to others
# exit 1 used in a subshell is effectively exiting a new process
- [[ ! -d $STATE_DIR ]] && mkdir -p $STATE_DIR/{interfaces,profiles}
+ [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles,suspend}
local PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks
load_profile "$PROFILE" || exit 1
@@ -160,7 +179,7 @@ profile_up()
profile_down()
{
(
- [[ ! -d $STATE_DIR ]] && mkdir -p $STATE_DIR/{interfaces,profiles}
+ [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles,suspend}
local PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks
@@ -271,11 +290,11 @@ list_profiles() {
find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '*~' -not -name '*.conf' -not -name '.*' -printf "%f\n"
}
# check_profile profile
-# Return 0 if profile up
-# Return 1 if profile down
+# Return 0 if profile registered as being up
+# Return 1 if profile not registered
#
check_profile() {
- [[ -f $STATE_DIR/profiles/$1 ]] && return 0
+ [[ -f $STATE_DIR/profiles/$1 && ! -f "$STATE_DIR/suspend/$1" ]] && return 0
return 1
}