[Pm-utils] POSIXification of pm-utils

Michael Biebl mbiebl at gmail.com
Wed Jan 30 04:12:28 PST 2008


2008/1/30, Stefan Seyfried <seife at suse.de>:
> On Thu, Jan 17, 2008 at 10:10:23PM -0600, Victor Lowther wrote:
>
> > The attached patch (against cvs head) makes all the scripting in
> > pm-utils POSIX compliant.  This patch has been tested on a basic
>
> I still think this is unnecessary (if not stupid).

I didn't initiate this effort, but I welcome it.

> > install of Debian sid, with the Debian native pm-utils overwritten by
> > this one and dash installed as /bin/sh.  Debian is able to
> > hibernate/resume normally.
>
> > --- pm-utils/pm/functions     2007-12-29 05:58:18.000000000 -0600
> > +++ working/pm/functions      2008-01-14 16:44:38.000000000 -0600
>
> > +# first, source our config files
> > +for cfg in /etc/pm/config.d/*[!~] ; do
> > +     [ -f "$cfg" ] || continue
> > +     set -a
> > +     . "${cfg}"
>
> If a user has created his own hooks, using "bashisms", knowing that
> pm-utils is using bash, this will break. How are you handling that?

If the hook has a proper #!/bin/bash shebang, I don't see a problem
for custom hooks.

> > +# 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
> >  }
>
> This only works if timeout is 0.

As said, that's already fixed.

> > -source_configs
> > +# release the lock
> > +release_lock()
> > +{
> > +     # $1 = directory used as the lock directory
> > +     # make sure it is ours first.
> > +     rm -rf "$1"
> > +     return $?
> > +}
>
> Make sure that nobody can trick your code into calling this with "/" as
> parameter...

I agree, we should be extra careful here and add some safety checks.


Michael


-- 
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