# HG changeset patch # User Dominique Corbex # Date 1333110323 -7200 # Node ID f3bc1a05a4231e6f1469772b6bc95e3290f1ad7e # Parent 9ffc10ecf21031b3c67148daeff38b0821964a76 acpid: fix broken events handling diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/receipt --- a/acpid/receipt Fri Mar 30 00:41:00 2012 +0200 +++ b/acpid/receipt Fri Mar 30 14:25:23 2012 +0200 @@ -1,35 +1,21 @@ # SliTaz package receipt. PACKAGE="acpid" -VERSION="2.0.12" +VERSION="2.0.14" CATEGORY="system-tools" -SHORT_DESC="The ACPI event daemon" -MAINTAINER="domcox@users.sourceforge.net" +SHORT_DESC="The ACPI event daemon with netlink" +MAINTAINER="domcox@slitaz.org" TARBALL="$PACKAGE-$VERSION.tar.gz" WEB_SITE="http://tedfelix.com/linux/acpid-netlink.html" WGET_URL="http://www.tedfelix.com/linux/$TARBALL" KEY_FILE="key-constants" TAGS="power-management" +SUGGESTED="pm-utils" # Rules to configure and make the package. compile_rules() { - # Build acpi_fakekey utility - cp -a $stuff/acpi_fakekey.c . - gcc -g -Wall -o acpi_fakekey acpi_fakekey.c - # Generate key constants file - INPUT_H="/usr/include/linux/input.h" - echo -n '# Generated from $INPUT dated ' > $KEY_FILE - date -r $INPUT_H >> $KEY_FILE - echo "KEY_RESERVED=0" >> $KEY_FILE - awk '/define KEY_/{if($3 <= 255 && $3 > 0) print $2"="$3}' $INPUT_H | sort -nt'=' -k2 >> $KEY_FILE - echo "KEY_LOCK=\$KEY_COFFEE" >> $KEY_FILE - echo "KEY_LIGHT=\$KEY_F19" >> $KEY_FILE - echo "KEY_VIDEOOUT=\$KEY_F20" >> $KEY_FILE - echo "KEY_ROTATESCREEN=\$KEY_F21" >> $KEY_FILE - echo "KEY_VIDEOMODECYCLE=\$KEY_F22" >> $KEY_FILE - echo "KEY_PRESENTATION=\KEY_F23" >> $KEY_FILE - # Build acpid + # Build cd $src make clean && make make DESTDIR=$DESTDIR install @@ -47,28 +33,26 @@ mkdir -p $fs/etc cp -a $stuff/init.d $fs/etc/ cp -a $stuff/acpi $fs/etc/ - # acpi_fakekey - cp -a $src/acpi_fakekey $fs/usr/bin - cp -a $src/$KEY_FILE $fs/etc/acpi/ + chmod go-rwx $fs/etc/acpi/*.sh + chmod go-rwx $fs/etc/acpi/events/* } -# Pre and post remove commands for Tazpkg +# Pre and post remove commands for Tazpkg +post_install() +{ + local root + root=$1 + if [ -z "$root" ]; then + /etc/init.d/acpid start || continue + fi + if ! grep -q ^ACPID_OPTIONS $root/etc/daemons.conf; then + echo '# ACPI daemon options.' >> $root/etc/daemons.conf + echo 'ACPID_OPTIONS=""' >> $root/etc/daemons.conf + echo '' >> $root/etc/daemons.conf + fi +} pre_remove() { /etc/init.d/acpid stop } - -post_remove() -{ - if [ `ls /etc/acpi/events | wc -l` -eq 0 ]; then - echo -n "Removing /etc/acpi/events" - rm -rf /etc/acpi/events - status - fi - if [ `ls /etc/acpi | wc -l` -eq 0 ]; then - echo -n "Removing /etc/acpi" - rm -rf /etc/acpi - status - fi -} diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/stuff/acpi/acpi_handler.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/acpid/stuff/acpi/acpi_handler.sh Fri Mar 30 14:25:23 2012 +0200 @@ -0,0 +1,31 @@ +#!/bin/sh +# A script for handling ACPI events. +# See events/*.conf for a configuration file that can be used to +# run this script. + +if [ $# != 1 ]; then + exit 1 +fi +set $* + +case "$1" in + button/lid) + [ -e /usr/sbin/pm-suspend ] && /usr/sbin/pm-suspend \ + || logger "acpid: pm-suspend not found, skipping.." ;; + ac_adapter) + case "$2" in + AC*|AD*) + case "$4" in + 00000000) # disconnected + [ -e /usr/sbin/pm-powersave ] \ + && /usr/sbin/pm-powersave battery \ + || logger "acpid: pm-powersave not found, skipping.." ;; + 00000001) # connected + [ -e /usr/sbin/pm-powersave ] \ + && /usr/sbin/pm-powersave ac \ + || logger "acpid: pm-powersave not found, skipping.." ;; + esac ;; + esac ;; + *) + logger "acpid: action $1 $2 is not defined" ;; +esac diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/stuff/acpi/button.sh --- a/acpid/stuff/acpi/button.sh Fri Mar 30 00:41:00 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -#!/bin/sh -# button.sh - Managing button events for SliTaz -# - -source /etc/acpi/key-constants - -# logger "button.sh: event=$1" - -# take care about the way events are reported - -EVENT_TYPE=`echo $1 | cut -d/ -f1` -if [ $EVENT_TYPE = $1 ]; then - EVENT=$2 -else - EVENT=`echo "$1" | cut -d/ -f2` -fi - -case $EVENT in - power) - logger "Event: button/power - sending KEY_EXIT($KEY_EXIT)" - /usr/bin/acpi_fakekey $KEY_EXIT - ;; - lid) - if [ -e /usr/bin/suspend ] ; then - logger "Event: button/lid - suspending" - /usr/bin/suspend - else - logger "Event: button/lid - /usr/bin/suspend not found, skipping.." - fi - ;; - sleep) - if [ -e /usr/bin/hibernate ] ; then - logger "Event: button/sleep - hibernating" - /usr/bin/hibernate - else - logger "Event: button/sleep - /usr/bin/hibernate not found, skipping.." - fi - ;; -esac diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/stuff/acpi/events/ac.conf --- a/acpid/stuff/acpi/events/ac.conf Fri Mar 30 00:41:00 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -# /etc/acpi/event/ac.conf -# ac power events - -event=ac_adapter -action=/etc/acpi/power-supply.sh - diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/stuff/acpi/events/ac_adapter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/acpid/stuff/acpi/events/ac_adapter Fri Mar 30 14:25:23 2012 +0200 @@ -0,0 +1,5 @@ +# /etc/acpi/event/ac.conf +# ac power events +event=ac_adapter .* +action=/etc/acpi/acpi_handler.sh "%e" + diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/stuff/acpi/events/battery.conf --- a/acpid/stuff/acpi/events/battery.conf Fri Mar 30 00:41:00 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -# /etc/acpi/event/battery.conf -# Battery events - -event=battery -action=/etc/acpi/power-supply.sh - diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/stuff/acpi/events/button.conf --- a/acpid/stuff/acpi/events/button.conf Fri Mar 30 00:41:00 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -# /etc/acpi/event/button -# lid, sleep or power button events - -event=button -action=/etc/acpi/button.sh %e - diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/stuff/acpi/events/buttons --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/acpid/stuff/acpi/events/buttons Fri Mar 30 14:25:23 2012 +0200 @@ -0,0 +1,5 @@ +# /etc/acpi/event/button +# lid, sleep or power button events +event=button.* +action=/etc/acpi/acpi_handler.sh "%e" + diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/stuff/acpi/power-supply.sh --- a/acpid/stuff/acpi/power-supply.sh Fri Mar 30 00:41:00 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,235 +0,0 @@ -#!/bin/sh -# /etc/acpi/power-supply.sh - Managing power events for SliTaz -# For Tips & Tricks see http://www.lesswatts.org - -# This script turns off power savings mode on ac or when the -# battery almost runs out in a attempt to limit data loss in -# a case of power failure. - -ENABLED=1 -DISABLED=0 - -# AC status (from /sys/class/power_supply/online) -ON_LINE=1 -OFF_LINE=0 - -# Battery status -LOW_BAT=0 -HIGH_BAT=1 - -# Determining the power state. - -ac_status() -{ - POWER_SUPPLY_MAINS=$DISABLED - AC_STATUS=$OFF_LINE - for POWER_SUPPLY in /sys/class/power_supply/* ; do - if [ -f $POWER_SUPPLY/type ] ; then - if [ "$(cat $POWER_SUPPLY/type)" = "Mains" ] ;then - echo -n "Determining power state from $POWER_SUPPLY: " - POWER_SUPPLY_MAINS=$ENABLED - if [ "$(cat $POWER_SUPPLY/online)" = 1 ] ; then - AC_STATUS=$ON_LINE - echo "on-line" - else - echo "off-line" - fi - fi - fi - done - if [ $POWER_SUPPLY_MAINS -eq $DISABLED ] ; then - $AC_STATUS=$ON_LINE - fi -} - -# Determining the battery state. - -battery_status() -{ - BATTERY_STATUS=$LOW_BAT - for BATT in /sys/class/power_supply/* ; do - BATT_TYPE=$(cat $BATT/type) - echo "$BATT is of type $BATT_TYPE." - if [ "$BATT_TYPE" = "Battery" ] ; then - echo " Checking levels for $BATT." - # Only do if the battery is present - if [ $(cat $BATT/present) -eq 1 ] ; then - - # Get the remaining capacity. - if [ -f $BATT/charge_now ] ; then - REMAINING=$(cat $BATT/charge_now) - elif [ -f $BATT/energy_now ] ; then - REMAINING=$(cat $BATT/energy_now) - else - REMAINING=0 - fi - if [ -z "$REMAINING" -o "$REMAINING" -eq 0 ] ; then - echo " Battery does not report remaining charge. Perhaps it is not present?" - else - echo " Remaining charge: $REMAINING" - - # Get the alarm level - ALARM_LEVEL=$(cat $BATT/alarm) - if [ "$ALARM_LEVEL" -eq 0 ] ; then - - # Get the full capacity. - - if [ -f $BATT/charge_full_design ] ; then - CAPACITY=$(cat $BATT/charge_full_design) - elif [ -f $BATT/energy_full_design ] ; then - CAPACITY=$(cat $BATT/energy_full_design) - else - CAPACITY=0 - fi - if [ -z "$CAPACITY" -o "$CAPACITY" -eq 0 ] ; then - echo " Battery does not report design full charge, using non-design full charge." - - if [ -f $BATT/charge_full ] ; then - CAPACITY=$(cat $BATT/charge_full) - elif [ -f $BATT/energy_full_design ] ; then - CAPACITY=$(cat $BATT/energy_full) - else - CAPACITY=0 - fi - if [ -z "$CAPACITY" -o "$CAPACITY" -eq 0] ; then - echo " Battery does not report non-design full charge." - fi - fi - echo " Full capacity: $CAPACITY" - ALARM_LEVEL=$((CAPACITY*5/100)) - fi - echo " Alarm level: $ALARM_LEVEL" - if [ "$ALARM_LEVEL" -ne 0 ] ; then - if [ "$REMAINING" -ge "$ALARM_LEVEL" ] ; then - # this battery does count as having enough charge. - BATTERY_STATUS=$HIGH_BAT - echo " Battery status: high" - else - echo " Battery status: low" - fi - fi - fi - else - echo "Battery is not present." - fi - fi - done -} - -online_mode() -{ - # Disable laptop mode - # When laptop mode is enabled, the kernel will try to be smart - # about when to do IO, to give the disk and the SATA links as - # much time as possible in a low power state. - - if [ -e /proc/sys/vm/laptop_mode ] ; then - echo "Disabling laptop mode" - echo 0 > /proc/sys/vm/laptop_mode - fi - - # AC97 audio power saving mode - # The AC97 onboard audio chips support power saving, where the - # analog parts (codec) are powered down when no program is using - # the audio device. - - if [ -e /sys/module/snd_ac97_codec/parameters/power_save ] ; then - echo "Disabling AC97 audio power saving mode" - echo 0 > /sys/module/snd_ac97_codec/parameters/power_save - fi - - # The VM writeback time - # The VM subsystem caching allows the kernel to group consecutive - # writes into one big write, and to generally optimize the disk IO - # to be the most efficient. - - if [ -e /proc/sys/vm/dirty_writeback_centisecs ] ; then - echo "Writeback time reset to 500ms" - echo 500 > /proc/sys/vm/dirty_writeback_centisecs - fi -} - -offline_mode() -{ - # Enable laptop mode - # When laptop mode is enabled, the kernel will try to be smart - # about when to do IO, to give the disk and the SATA links as - # much time as possible in a low power state. - - if [ ! -e /proc/sys/vm/laptop_mode ] ; then - echo "Kernel does not have support for laptop mode." - else - echo "Enabling laptop mode" - echo 5 > /proc/sys/vm/laptop_mode - fi - - # AC97 audio power saving mode - # The AC97 onboard audio chips support power saving, where the - # analog parts (codec) are powered down when no program is using - # the audio device. - - if [ -e /sys/module/snd_ac97_codec/parameters/power_save ] ; then - echo "Enabling AC97 audio power saving mode" - echo 1 > /sys/module/snd_ac97_codec/parameters/power_save - echo 1 > /dev/dsp - fi - - # The VM writeback time - # The VM subsystem caching allows the kernel to group consecutive - # writes into one big write, and to generally optimize the disk IO - # to be the most efficient. - - if [ -e /proc/sys/vm/dirty_writeback_centisecs ] ; then - echo "Writeback time set to 1500ms" - echo 1500 > /proc/sys/vm/dirty_writeback_centisecs - fi -} - -power_status() -{ - if [ $(cat /proc/sys/vm/dirty_writeback_centisecs) -gt 1000 ]; then - POWER_SAVINGS=$ENABLED - echo "power-savings-mode enabled" - else - POWER_SAVINGS=$DISABLED - echo "power-savings-mode disabled" - fi -} - -custom_scripts() -{ - # Custom scripts in /etc/acpi/ac.d - - if [ -d /etc/acpi/ac.d ]; then - for SCRIPT in /etc/acpi/ac.d/*.sh; do - . $SCRIPT $AC_STATUS $BATTERY_STATUS $0 - done - fi - - # Custom scripts in /etc/acpi/battery.d - - if [ -d /etc/acpi/battery.d ]; then - for SCRIPT in /etc/acpi/battery.d/*.sh; do - . $SCRIPT $AC_STATUS $BATTERY_STATUS $0 - done - fi -} - -ac_status -battery_status -power_status -case "$AC_STATUS+$BATTERY_STATUS" in - "$OFF_LINE+$HIGH_BAT") - if [ $POWER_SAVINGS = $DISABLED ]; then - logger "Start power savings mode" - offline_mode - fi - ;; - *) - if [ $POWER_SAVINGS = $ENABLED ]; then - logger "Stop power savings mode" - online_mode - fi - ;; -esac -custom_scripts \ No newline at end of file diff -r 9ffc10ecf210 -r f3bc1a05a423 acpid/stuff/acpi_fakekey.c --- a/acpid/stuff/acpi_fakekey.c Fri Mar 30 00:41:00 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8))) - -int find_keyboard() { - int i, j; - int fd; - char filename[32]; - char key_bitmask[(KEY_MAX + 7) / 8]; - - for (i=0; i<32; i++) { - snprintf(filename,sizeof(filename), "/dev/input/event%d", i); - - fd = open(filename, O_RDWR); - ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask); - - for (j = 0; j < BTN_MISC; j++) { - if (TestBit(j, key_bitmask)) - break; - } - - if (j < BTN_MISC) { - return fd; - } - close (fd); - } - return 0; -} - -int main(int argc, char** argv) { - int fd; - int key; - struct input_event event; - - if (argc == 2) { - key = atoi(argv[1]); - } else { - return 1; - } - - fd = find_keyboard(); - - if (!fd) { - return 2; - } - - event.type = EV_KEY; - event.code = key; - event.value = 1; - write(fd, &event, sizeof event); - - event.type = EV_KEY; - event.code = key; - event.value = 0; - write(fd, &event, sizeof event); - - return 0; -} -