From b5d264dc02e318d56038ad785b9f5dc0b301926b Mon Sep 17 00:00:00 2001 From: Katze Miau Date: Sun, 18 Dec 2011 22:36:44 +0000 Subject: fsm: do not lock state file when reading state Locking the state file during `fsm get` operations is annoying. And the returned state may be changed anytime after termination, so the caller can not rely on it being up to date anyway. diff --git a/files/common/sbin/fsm b/files/common/sbin/fsm index 0bfe4ba..e6b62fa 100755 --- a/files/common/sbin/fsm +++ b/files/common/sbin/fsm @@ -53,6 +53,14 @@ callOne () { # args: cwd arg1 arg2 cmdlist done ) } +lockState () { + # lock state file (neccessary also for watch, as it calls scripts + # that assume a certain state as active during their whole + # execution time) + exec 666<$1 + flock -x 666 +} + fail() { echo "$1" 1>&2 exit 1 @@ -81,20 +89,17 @@ else fail "FSM $2 does not exist" fi -# lock state file (neccessary also for watch, as it calls scripts that -# assume a certain state as active during their whole execution time) -exec 666<$PState -flock -x 666 - case "$1" in get) cat $PState ;; watch) + lock $PState watch ;; change) [ -n "$3" ] || printArgs + lock $PState change $3 ;; *) -- cgit v0.10.1