Package: acpi-support
Version: 0.137-4
Severity: wishlist

Posixfication and speed: some ideas in the attached patch.
Lots of scripts do things in an inefficient way, and should benefit from
being rewritten.

Take, for example, the latest addition which closes bug #589625. Think
lower performant CPU:s (like laptops, netbooks, embedded and others).
The attached (somewhat annotated) patch is a PoC that saves a few CPU
cycles.

Do not fork and use pipes if there's a perfect builtin for the job.
Do not go rounds testing on '$?' if it can be done in one go.
'read' compared to 'cat' is some 30x more efficient.  Specially fitted for
1 line files.

Lots of other scripts would benefit from similar treatment.


-- 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-4    tool to generate fake key events
ii  acpi-support-base             0.137-4    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
--- lid.sh.orig	2010-06-23 04:27:29.000000000 +0200
+++ lid.sh	2010-08-17 18:36:00.000000000 +0200
@@ -1,46 +1,44 @@
-#!/bin/bash
-# TODO:  Change the above to /bin/sh
+#!/bin/sh
 
-test -f /usr/share/acpi-support/state-funcs || exit 0
+# FIXME: Is this really needed here?
+[ -f /usr/share/acpi-support/state-funcs ] || exit 0
 
 . /usr/share/acpi-support/power-funcs
 . /usr/share/acpi-support/policy-funcs
 . /etc/default/acpi-support
 
-[ -x /etc/acpi/local/lid.sh.pre ] && /etc/acpi/local/lid.sh.pre
+[ ! -x /etc/acpi/local/lid.sh.pre ] || /etc/acpi/local/lid.sh.pre
 
-if [ `CheckPolicy` = 0 ]; then exit; fi
+# FIXME: 'CheckPolicy' doesn't 'echo' stuff, it 'return's an exit status!
+! CheckPolicy || exit 0
 
-grep -q closed /proc/acpi/button/lid/*/state
-if [ $? = 0 ]
-then
+
+if grep -q closed /proc/acpi/button/lid/*/state; then
     for x in /tmp/.X11-unix/*; do
-	displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
-	getXuser;
-	if [ x"$XAUTHORITY" != x"" ]; then
-	    export DISPLAY=":$displaynum"	    
+	# FIXME: Skip fork and pipe
+	#displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
+	displaynum=${x#/tmp/.X11-unix/X}
+	getXuser
+	[ -z "$XAUTHORITY" ] || {
+	    export DISPLAY=:$displaynum
 	    . /usr/share/acpi-support/screenblank
-	fi
+	}
     done
 else
     for x in /tmp/.X11-unix/*; do
-	displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
-	getXuser;
-	if [ x"$XAUTHORITY" != x"" ]; then
-	    export DISPLAY=":$displaynum"
-	    grep -q off-line /proc/acpi/ac_adapter/*/state
-	    if [ $? = 1 ]
-		then
-		if pidof xscreensaver > /dev/null; then 
-		    su $user -c "xscreensaver-command -unthrottle"
-		fi
-	    fi
-	    if [ x$RADEON_LIGHT = xtrue ]; then
-		[ -x /usr/sbin/radeontool ] && radeontool light on
-	    fi
-	    if [ `pidof xscreensaver` ]; then
+	# FIXME: Skip fork and pipe
+	#displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
+	displaynum=${x#/tmp/.X11-unix/X}
+	getXuser
+	if [ "$XAUTHORITY" ]; then
+	    export DISPLAY=:$displaynum
+	    grep -q off-line /proc/acpi/ac_adapter/*/state ||
+		! pidof xscreensaver >/dev/null 2>&1 ||
+		su $user -c "xscreensaver-command -unthrottle"
+	    [ "$RADEON_LIGHT" != true ]
+		[ ! -x /usr/sbin/radeontool ] || radeontool light on
+	    ! pidof xscreensaver >/dev/null 2>&1 ||
 		su $user -c "xscreensaver-command -deactivate"
-	    fi
 	    su $user -c "xset dpms force on"
 	fi
     done

Reply via email to