[Pkg-acpi-devel] Bug#593975: acpi-support: function CheckPolicy from policy-funcs

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Sun Aug 22 19:33:58 UTC 2010


Package: acpi-support
Version: 0.137-5
Severity: normal

Execution time and use of resources can be improved by avoiding
unnecessary forks.

It's inefficient for CheckPolicy to 'echo' '0' or '1' instead of
'return'ing them.

With the current implementation, the caller runs the function in a forked
subshell:

	if [ `CheckPolicy` = 0 ]; then exit; fi

which costs more than when 'return'ing a status code:

	if CheckPolicy; then exit; fi

in the same shell, or even better:

	! CheckPolicy || exit 0

IOW:

--- lib/policy-funcs.orig	2010-08-18 23:34:26.000000000 +0200
+++ lib/policy-funcs	2010-08-22 20:54:29.000000000 +0200
@@ -23,9 +23,9 @@
 	if pidof -x $PMS > /dev/null ||
 	   (test "$XUSER" != "" && pidof dcopserver > /dev/null && test -x /usr/bin/dcop && /usr/bin/dcop --user $XUSER kded kded loadedModules | grep -q klaptopdaemon) ||
 	   PowerDevilRunning ; then
-		echo 0;
+		return 0
 	else
-		echo 1;
+		return 1
 	fi
 }


And, by the way, newline _is_ a command separator.  There's no need for
another one ';'.


'(...)' forks a subshell to execute '...'.  It's not needed, IMO, in this
case.  This:

--- lib/policy-funcs.a	2010-08-22 20:54:29.000000000 +0200
+++ lib/policy-funcs	2010-08-22 21:07:35.000000000 +0200
@@ -20,9 +20,13 @@
 	getXconsole
 	PMS="/usr/bin/gnome-power-manager /usr/bin/kpowersave /usr/bin/xfce4-power-manager"
 	PMS="$PMS /usr/bin/guidance-power-manager /usr/lib/dalston/dalston-power-applet"
-	if pidof -x $PMS > /dev/null ||
-	   (test "$XUSER" != "" && pidof dcopserver > /dev/null && test -x /usr/bin/dcop && /usr/bin/dcop --user $XUSER kded kded loadedModules | grep -q klaptopdaemon) ||
-	   PowerDevilRunning ; then
+	if pidof -x $PMS >/dev/null ||
+	   { [ "$XUSER" ] &&
+	     pidof dcopserver >/dev/null &&
+	     [ -x /usr/bin/dcop ] &&
+	     /usr/bin/dcop --user $XUSER kded kded loadedModules |
+	     grep -q klaptopdaemon; } ||
+	   PowerDevilRunning; then
 		return 0
 	else
 		return 1

will run the tests in the same shell (no subshell forks).

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing')
Architecture: i386 (i686)

Kernel: Linux 2.6.32-5-686 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash

Versions of packages acpi-support depends on:
ii  acpi-fakekey                  0.137-5    tool to generate fake key events
ii  acpi-support-base             0.137-5    scripts for handling base ACPI eve
ii  acpid                         1:2.0.6-1  Advanced Configuration and Power I
ii  lsb-base                      3.2-23.1   Linux Standard Base 3.2 init scrip
ii  pm-utils                      1.3.0-2    utilities and scripts for power ma
ii  x11-xserver-utils             7.5+2      X server utilities

Versions of packages acpi-support recommends:
ii  dbus                          1.2.24-3   simple interprocess messaging syst
pn  radeontool                    <none>     (no description available)
ii  vbetool                       1.1-2      run real-mode video BIOS code to a
pn  xscreensaver | gnome-screensa <none>     (no description available)

Versions of packages acpi-support suggests:
ii  rfkill                        0.4-1      tool for enabling and disabling wi
ii  xinput                        1.5.2-1    Runtime configuration and test of

-- no debconf information


Cheers,

-- 
Cristian





More information about the Pkg-acpi-devel mailing list