[Pm-utils] [patch commit] [000] POSIXification of pm-utils

Michael Biebl mbiebl at gmail.com
Wed Jan 30 03:59:47 PST 2008


2008/1/30, Stefan Seyfried <seife at suse.de>:
> On Sun, Jan 27, 2008 at 02:25:43PM -0600, Victor Lowther wrote:
> > Adds a generic locking mechanism built around directory creation/removal.
>
> > diff -U 0 -rNX diffignore pm-utils.updates/pm/functions working/pm/functions
> > --- pm-utils.updates/pm/functions     2008-01-27 11:58:02.000000000 -0600
> > +++ working/pm/functions      2008-01-27 11:26:51.000000000 -0600
> > @@ -18,0 +18 @@
> > +LOCKDIR="/tmp/.suspended"
> > @@ -42,0 +38,33 @@
> > +# try to take the lock.  Fail if we cannot get it.
> > +try_lock()
> > +{
> > +     # $1 = directory to use as lock directory
> > +     # we use directory creation because the kernel enforces atomicity,
> > +     # and mkdir will fail if the directory already exists.
> > +     mkdir "$1" >/dev/null 2>&1 || return 1
> > +     return 0
> > +}
> > +
> > +# spin waiting for the lock with optional timeout.
> > +# return once we have it, or the timeout has expired
> > +spin_lock()
> > +{
> > +     # $1 = directory to use as the lock directory
> > +     # $2 = optional timeout
> > +     local elapsed=0
> > +     while ! try_lock $1; do
> > +             sleep 1;
> > +             [ "x$2" != "x" ] && [ $(( $elapsed == $2 )) -ne 0 ] && return 1
> > +     done
>
> Does not work if timeout != 0.

That's fixed in current git.


-- 
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?


More information about the Pm-utils mailing list