You are not logged in.

#1 2011-10-29 02:03:15

supulton
Member
Registered: 2008-12-31
Posts: 58

[SOLVED] Repeated acpid events on AC

I've got an event handler for acpid that runs whenever AC is connected or disconnected:

/etc/acpid/actions/battery.sh:

# ac/battery event handler

status=`awk '{print $2}' /proc/acpi/ac_adapter/AC0/state` 
logger='/usr/bin/logger -t ACPID'

if [[ $status == "off-line" ]]
then
    $logger -p daemon.warn "AC out"
	su vic -c '/home/vic/bin/dzen-bat.sh'
    cpufreq-set -r -g conservative
    echo 5 > /sys/class/backlight/acpi_video0/brightness
    pm-powersave true
	echo 2 > /sys/devices/platform/eeepc/cpufv
else
    $logger -p daemon.info "AC in"
	su vic -c '/home/vic/bin/dzen-bat.sh'
    cpufreq-set -r -g performance
    echo 10 > /sys/class/backlight/acpi_video0/brightness
    pm-powersave false
	echo 1 > /sys/devices/platform/eeepc/cpufv
fi

However, whenever the script is activated (when I connect or disconnect my laptop adapter), the script is run multiple times, as indicated in daemon.log:

Oct 28 18:58:43 localhost ACPID: AC out
Oct 28 18:58:51 localhost ACPID: AC out
Oct 28 18:58:55 localhost ACPID: AC out
Oct 28 18:59:08 localhost ACPID: AC in
Oct 28 18:59:14 localhost ACPID: AC in
Oct 28 18:59:18 localhost ACPID: AC in

and in messages.log--
on disconnect:

Oct 28 18:59:52 localhost vic: acpid: action BAT0 undefined
Oct 28 18:59:52 localhost ACPID: AC out
Oct 28 18:59:52 localhost kernel: [10587.318237] keyboard: can't emulate rawmode for keycode 240
Oct 28 18:59:52 localhost kernel: [10587.318275] keyboard: can't emulate rawmode for keycode 240
Oct 28 18:59:58 localhost vic: acpid: action BAT0 undefined
Oct 28 18:59:58 localhost ACPID: AC out
Oct 28 19:00:02 localhost vic: acpid: action AC0 undefined
Oct 28 19:00:02 localhost vic: acpid: action AC0 undefined
Oct 28 19:00:02 localhost vic: acpid: action BAT0 undefined
Oct 28 19:00:02 localhost ACPID: AC out
Oct 28 19:00:06 localhost vic: acpid: action ATKD undefined
Oct 28 19:00:06 localhost vic: acpid: action CPU0 undefined
Oct 28 19:00:06 localhost vic: acpid: action CPU1 undefined

on AC:

Oct 28 19:01:27 localhost vic: acpid: action AC0 undefined
Oct 28 19:01:27 localhost vic: acpid: action BAT0 undefined
Oct 28 19:01:27 localhost ACPID: AC in
Oct 28 19:01:33 localhost vic: acpid: action ATKD undefined
Oct 28 19:01:33 localhost vic: acpid: action CPU0 undefined
Oct 28 19:01:33 localhost vic: acpid: action CPU1 undefined
Oct 28 19:01:33 localhost vic: acpid: action BAT0 undefined
Oct 28 19:01:33 localhost ACPID: AC in
Oct 28 19:01:37 localhost vic: acpid: action BAT0 undefined
Oct 28 19:01:37 localhost ACPID: AC in
Oct 28 19:01:41 localhost vic: acpid: action AC0 undefined

I have a dzen script that notifies me of the remaining battery life, which gets run several times when I want it run only once. My question is, how can I make this script (battery.sh) run only once on AC change through acpid?

Last edited by supulton (2011-10-30 10:42:32)

Offline

#2 2011-10-30 10:41:59

supulton
Member
Registered: 2008-12-31
Posts: 58

Re: [SOLVED] Repeated acpid events on AC

So, I found this was a bug in my machine, sending acpi events multiple times.
I used a 'lockfile' solution as explained here.

My updated handler now works as it should:

status=`awk '{print $2}' /proc/acpi/ac_adapter/AC0/state` 
logger='/usr/bin/logger -t ACPID'
ac_state=/etc/acpi/actions/ac_state

if [[ $status == "off-line" ]]
then
	if [ ! -e ${ac_state}/ac_event_unplugged ]; then
		touch ${ac_state}/ac_event_unplugged
		$logger -p daemon.warn "AC out"
		su vic -c '/home/vic/bin/dzen-bat.sh'
		cpufreq-set -r -g conservative
		echo 5 > /sys/class/backlight/acpi_video0/brightness
		pm-powersave true
		echo 2 > /sys/devices/platform/eeepc/cpufv
		( sleep 2 ; rm -f ${ac_state}/ac_event_unplugged ) &
	fi
else
	if [ ! -e ${ac_state}/ac_event_plugged ]; then
		touch ${ac_state}/ac_event_plugged
		$logger -p daemon.info "AC in"
		su vic -c '/home/vic/bin/dzen-bat.sh'
		cpufreq-set -r -g performance
		echo 10 > /sys/class/backlight/acpi_video0/brightness
		pm-powersave false
		echo 1 > /sys/devices/platform/eeepc/cpufv
		( sleep 2 ; rm -f ${ac_state}/ac_event_plugged ) &
	fi
fi

Offline

#3 2011-10-30 17:36:20

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [SOLVED] Repeated acpid events on AC

Have you considered using the powersave script from pm-utils?

http://crunchbanglinux.org/forums/topic … or-debian/

It used to work as a good replacement for the acpid daemon. However, since the latest upgrades something broke. At least on my machine.

Regards

Offline

Board footer

Powered by FluxBB