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

Victor Lowther victor.lowther at gmail.com
Wed Jan 30 05:29:17 PST 2008


On Jan 30, 2008 5:45 AM, Stefan Seyfried <seife at suse.de> wrote:
> 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.

Should be fixed in git HEAD

> --
> Stefan Seyfried
> R&D Team Mobile Devices            |              "Any ideas, John?"
> SUSE LINUX Products GmbH, Nürnberg | "Well, surrounding them's out."
>
> This footer brought to you by insane German lawmakers:
> SUSE Linux Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)
>
> _______________________________________________
> Pm-utils mailing list
> Pm-utils at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/pm-utils
>


More information about the Pm-utils mailing list