[Pm-utils] various errors in pm/functions

Peter Jones pjones at redhat.com
Tue Oct 10 09:07:27 PDT 2006


> > -. /etc/rc.d/init.d/functions
> > +[ -e /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions
> 
> Looks very sane.

I don't think we're currently using anything from there at all; at one
point we were getting "success" and "failure" from that, but now we're
output-free, so we don't use them any more.  I'll take it out and test
to be sure.

> > Index: pm/functions
> > ===================================================================
> > RCS file: /cvs/pm-utils/pm-utils/pm/functions,v
> > retrieving revision 1.20
> > diff -u -p -r1.20 functions
> > --- pm/functions	28 Sep 2006 21:25:36 -0000	1.20
> > +++ pm/functions	5 Oct 2006 15:18:24 -0000
> > @@ -62,9 +62,15 @@ run_hooks()
> >  	[ -f /var/run/pm-suspend ] && . /var/run/pm-suspend
> >  	rm -f /var/run/pm-suspend
> >  
> > -	files="/etc/pm/hooks/*"
> > +	files="/etc/pm/hooks/*[^~]"
> >  	if [ "$2" = "reverse" ]; then
> > -		files=$(echo $files | awk '{ for (i=NF; i>=1; i--) if ($i !~ /~$/ { print $i } }')
> > +		filea=($files)
> > +		filen=${#filea[*]}
> > +		files=""
> > +		while [ $filen -gt 0 ]; do
> > +			let filen--
> > +			files="$files ${filea[$filen]}"
> > +		done
> >  	fi
> >  	for file in $files ; do
> >  		[ -x $file ] && $file $1
> > 
> > -------
> > (actually, the awk is just missing a ")" after "if ($i !~ /~$/) {...", but
> > this "if" is totally unneeded by adjusting the glob pattern, and it probably
> > is cheaper to reverse the files in bash than forking off awk, i did it in
> > bash).
> 
> yes, this looks good too.

Yeah, applied.

> > Index: pm/functions
> > ===================================================================
> > RCS file: /cvs/pm-utils/pm-utils/pm/functions,v
> > retrieving revision 1.20
> > diff -u -p -r1.20 functions
> > --- pm/functions	28 Sep 2006 21:25:36 -0000	1.20
> > +++ pm/functions	5 Oct 2006 15:39:47 -0000
> > @@ -33,10 +33,10 @@ source_configs
> >  
> >  take_suspend_lock()
> >  {
> > -	VT=$(/usr/bin/fgconsole)
> > +	VT=$(PATH=/bin:/usr/bin fgconsole)
> >  	chvt 63
> >  	if [ -f /.suspended ]; then
> > -		pid=$(cat /.suspended)
> > +		read pid < /.suspended
> >  		if [ -d /proc/$pid ]; then
> >  			return 1
> >  		fi
> 
> Yes, also this is good.
>
> > ----------
> > maybe we could also find fgconsole with configure and hardcode it depending
> > on the distribution, might be faster than searching the two directories, but
> > i am not too autofoo-savvy so i went the easy way. We should save this by
> > avoiding forking off cat :-)
> 
> Hmm, I would trade an extra fork for not doing lots of configure-foo.

You know, I don't like either approach much.  We ought to just be
setting a sane PATH at the top of the script, and trusting the distro
not to have more than one program named "fgconsole" sitting in a common
place.

-- 
  Peter



More information about the Pm-utils mailing list