[Pm-utils] [PATCH 4/6] Made savestate and restorestate in functions.in orthogonal.
Victor Lowther
victor.lowther at gmail.com
Wed Feb 27 18:29:11 PST 2008
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.
---
pm/functions.in | 14 ++++++++++++--
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"
}
--
1.5.4.3
More information about the Pm-utils
mailing list