[Pm-utils] various errors in pm/functions

Stefan Seyfried seife at suse.de
Thu Oct 5 08:48:54 PDT 2006


Hi,

i tested pm-utils and pm-suspend gave me the following:
t8200:~ # pm-suspend
/etc/pm/functions: line 3: /etc/rc.d/init.d/functions: No such file or directory
/etc/pm/functions: line 36: /usr/bin/fgconsole: No such file or directory
/etc/pm/functions: line 3: /etc/rc.d/init.d/functions: No such file or directory
/etc/pm/functions: line 3: /etc/rc.d/init.d/functions: No such file or directory
/etc/pm/functions: line 3: /etc/rc.d/init.d/functions: No such file or directory
/etc/pm/functions: line 3: /etc/rc.d/init.d/functions: No such file or directory
/etc/pm/functions: line 3: /etc/rc.d/init.d/functions: No such file or directory
/etc/pm/functions: line 3: /etc/rc.d/init.d/functions: No such file or directory
/etc/pm/functions: line 3: /etc/rc.d/init.d/functions: No such file or directory
awk: { for (i=NF; i>=1; i--) if ($i !~ /~$/ { print $i } }
awk:                                        ^ syntax error
usage: chvt N
t8200:~ #

so i am suggesting the following patches:
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:37:46 -0000
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-. /etc/rc.d/init.d/functions
+[ -e /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions
 
 # default values go here
 HIBERNATE_RESUME_POST_VIDEO=no

-----------------
It would be interesting what stuff actually is in /etc/rc.d/init.d/functions
and what i will loose by not including it...


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

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

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

I'll additionally attach the patches since i am not sure which way is the
preferred one.

HTH,

   Stefan
-- 
Stefan Seyfried
QA / R&D Team Mobile Devices        |              "Any ideas, John?"
SUSE LINUX Products GmbH, Nürnberg  | "Well, surrounding them's out." 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pm-utils-test-for-rc.d-functions.diff
Type: text/x-patch
Size: 469 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/pm-utils/attachments/20061005/eafc6688/pm-utils-test-for-rc.d-functions.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pm-utils-avoid-awk.diff
Type: text/x-patch
Size: 771 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/pm-utils/attachments/20061005/eafc6688/pm-utils-avoid-awk.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pm-utils-find-fgconsole-and-avoid-useless-abuse-of-cat.diff
Type: text/x-patch
Size: 547 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/pm-utils/attachments/20061005/eafc6688/pm-utils-find-fgconsole-and-avoid-useless-abuse-of-cat.bin


More information about the Pm-utils mailing list