summaryrefslogtreecommitdiff
path: root/pm/functions.in
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2008-02-27 20:06:07 -0600
committerVictor Lowther <victor.lowther@gmail.com>2008-02-27 20:06:07 -0600
commit58c7d77aa0f37f1d50f89753e1a846795476bc47 (patch)
treeb4c1dc7c75d370d302fb35c78fa332a9c749ea35 /pm/functions.in
parentdf278aba456f44fe4573c60ba0d524370ee5ad96 (diff)
Made savestate and restorestate in functions.in orthogonal.
You can pipe data into savestate, and pipe it back out of restorestate. This also makes savestate/restorestate able to cleanly handle data with embedded NULs and other such nasties that may confuse bash. Savestate is still backwards compatible with the older calling convention.
Diffstat (limited to 'pm/functions.in')
-rw-r--r--pm/functions.in14
1 files changed, 12 insertions, 2 deletions
diff --git a/pm/functions.in b/pm/functions.in
index 26f27cf..33e5a85 100644
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -299,10 +299,20 @@ restartservice()
savestate()
{
- echo "$2" > "${STORAGEDIR}/state:$1"
+ if [ -n "$2" ]; then
+ echo "$2" > "${STORAGEDIR}/state:$1"
+ else
+ cat > "${STORAGEDIR}/state:$1"
+ fi
+}
+
+state_exists()
+{
+ [ -O "${STORAGEDIR}/state:$1" ]
}
+
restorestate()
{
- [ -O "${STORAGEDIR}/state:${1}" ] && cat "${STORAGEDIR}/state:${1}"
+ state_exists "$1" && cat "${STORAGEDIR}/state:$1"
}