wok-current rev 1624
acpid: add power savings scripts
author | Dominique Corbex <domcox@users.sourceforge.net> |
---|---|
date | Thu Oct 23 20:07:24 2008 +0000 (2008-10-23) |
parents | 3a574003f9dd |
children | 473dba2a800f |
files | acpid/acpi_fakekey acpid/acpi_fakekey.c acpid/key-constants acpid/receipt acpid/stuff/acpi/ac.sh acpid/stuff/acpi/battery.sh acpid/stuff/acpi/button.sh acpid/stuff/acpi/events/ac acpid/stuff/acpi/events/ac.conf acpid/stuff/acpi/events/battery acpid/stuff/acpi/events/battery.conf acpid/stuff/acpi/events/button.conf acpid/stuff/acpi/power-supply.sh acpid/stuff/init.d/acpid |
line diff
1.1 Binary file acpid/acpi_fakekey has changed
2.1 --- a/acpid/acpi_fakekey.c Thu Oct 23 20:13:41 2008 +0200 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,64 +0,0 @@ 2.4 -#include <unistd.h> 2.5 -#include <fcntl.h> 2.6 -#include <string.h> 2.7 -#include <stdlib.h> 2.8 -#include <stdio.h> 2.9 -#include <linux/input.h> 2.10 - 2.11 -#define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8))) 2.12 - 2.13 -int find_keyboard() { 2.14 - int i, j; 2.15 - int fd; 2.16 - char filename[32]; 2.17 - char key_bitmask[(KEY_MAX + 7) / 8]; 2.18 - 2.19 - for (i=0; i<32; i++) { 2.20 - snprintf(filename,sizeof(filename), "/dev/input/event%d", i); 2.21 - 2.22 - fd = open(filename, O_RDWR); 2.23 - ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask); 2.24 - 2.25 - for (j = 0; j < BTN_MISC; j++) { 2.26 - if (TestBit(j, key_bitmask)) 2.27 - break; 2.28 - } 2.29 - 2.30 - if (j < BTN_MISC) { 2.31 - return fd; 2.32 - } 2.33 - close (fd); 2.34 - } 2.35 - return 0; 2.36 -} 2.37 - 2.38 -int main(int argc, char** argv) { 2.39 - int fd; 2.40 - int key; 2.41 - struct input_event event; 2.42 - 2.43 - if (argc == 2) { 2.44 - key = atoi(argv[1]); 2.45 - } else { 2.46 - return 1; 2.47 - } 2.48 - 2.49 - fd = find_keyboard(); 2.50 - 2.51 - if (!fd) { 2.52 - return 2; 2.53 - } 2.54 - 2.55 - event.type = EV_KEY; 2.56 - event.code = key; 2.57 - event.value = 1; 2.58 - write(fd, &event, sizeof event); 2.59 - 2.60 - event.type = EV_KEY; 2.61 - event.code = key; 2.62 - event.value = 0; 2.63 - write(fd, &event, sizeof event); 2.64 - 2.65 - return 0; 2.66 -} 2.67 -
3.1 --- a/acpid/key-constants Thu Oct 23 20:13:41 2008 +0200 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,246 +0,0 @@ 3.4 -# Generated from $INPUT dated mar aoû 26 22:06:20 CEST 2008 3.5 -KEY_RESERVED=0 3.6 -KEY_ESC=1 3.7 -KEY_1=2 3.8 -KEY_2=3 3.9 -KEY_3=4 3.10 -KEY_4=5 3.11 -KEY_5=6 3.12 -KEY_6=7 3.13 -KEY_7=8 3.14 -KEY_8=9 3.15 -KEY_9=10 3.16 -KEY_0=11 3.17 -KEY_MINUS=12 3.18 -KEY_EQUAL=13 3.19 -KEY_BACKSPACE=14 3.20 -KEY_TAB=15 3.21 -KEY_Q=16 3.22 -KEY_W=17 3.23 -KEY_E=18 3.24 -KEY_R=19 3.25 -KEY_T=20 3.26 -KEY_Y=21 3.27 -KEY_U=22 3.28 -KEY_I=23 3.29 -KEY_O=24 3.30 -KEY_P=25 3.31 -KEY_LEFTBRACE=26 3.32 -KEY_RIGHTBRACE=27 3.33 -KEY_ENTER=28 3.34 -KEY_LEFTCTRL=29 3.35 -KEY_A=30 3.36 -KEY_S=31 3.37 -KEY_D=32 3.38 -KEY_F=33 3.39 -KEY_G=34 3.40 -KEY_H=35 3.41 -KEY_J=36 3.42 -KEY_K=37 3.43 -KEY_L=38 3.44 -KEY_SEMICOLON=39 3.45 -KEY_APOSTROPHE=40 3.46 -KEY_GRAVE=41 3.47 -KEY_LEFTSHIFT=42 3.48 -KEY_BACKSLASH=43 3.49 -KEY_Z=44 3.50 -KEY_X=45 3.51 -KEY_C=46 3.52 -KEY_V=47 3.53 -KEY_B=48 3.54 -KEY_N=49 3.55 -KEY_M=50 3.56 -KEY_COMMA=51 3.57 -KEY_DOT=52 3.58 -KEY_SLASH=53 3.59 -KEY_RIGHTSHIFT=54 3.60 -KEY_KPASTERISK=55 3.61 -KEY_LEFTALT=56 3.62 -KEY_SPACE=57 3.63 -KEY_CAPSLOCK=58 3.64 -KEY_F1=59 3.65 -KEY_F2=60 3.66 -KEY_F3=61 3.67 -KEY_F4=62 3.68 -KEY_F5=63 3.69 -KEY_F6=64 3.70 -KEY_F7=65 3.71 -KEY_F8=66 3.72 -KEY_F9=67 3.73 -KEY_F10=68 3.74 -KEY_NUMLOCK=69 3.75 -KEY_SCROLLLOCK=70 3.76 -KEY_KP7=71 3.77 -KEY_KP8=72 3.78 -KEY_KP9=73 3.79 -KEY_KPMINUS=74 3.80 -KEY_KP4=75 3.81 -KEY_KP5=76 3.82 -KEY_KP6=77 3.83 -KEY_KPPLUS=78 3.84 -KEY_KP1=79 3.85 -KEY_KP2=80 3.86 -KEY_KP3=81 3.87 -KEY_KP0=82 3.88 -KEY_KPDOT=83 3.89 -KEY_ZENKAKUHANKAKU=85 3.90 -KEY_102ND=86 3.91 -KEY_F11=87 3.92 -KEY_F12=88 3.93 -KEY_RO=89 3.94 -KEY_KATAKANA=90 3.95 -KEY_HIRAGANA=91 3.96 -KEY_HENKAN=92 3.97 -KEY_KATAKANAHIRAGANA=93 3.98 -KEY_MUHENKAN=94 3.99 -KEY_KPJPCOMMA=95 3.100 -KEY_KPENTER=96 3.101 -KEY_RIGHTCTRL=97 3.102 -KEY_KPSLASH=98 3.103 -KEY_SYSRQ=99 3.104 -KEY_RIGHTALT=100 3.105 -KEY_LINEFEED=101 3.106 -KEY_HOME=102 3.107 -KEY_UP=103 3.108 -KEY_PAGEUP=104 3.109 -KEY_LEFT=105 3.110 -KEY_RIGHT=106 3.111 -KEY_END=107 3.112 -KEY_DOWN=108 3.113 -KEY_PAGEDOWN=109 3.114 -KEY_INSERT=110 3.115 -KEY_DELETE=111 3.116 -KEY_MACRO=112 3.117 -KEY_MUTE=113 3.118 -KEY_VOLUMEDOWN=114 3.119 -KEY_VOLUMEUP=115 3.120 -KEY_POWER=116 3.121 -KEY_KPEQUAL=117 3.122 -KEY_KPPLUSMINUS=118 3.123 -KEY_PAUSE=119 3.124 -KEY_KPCOMMA=121 3.125 -KEY_HANGEUL=122 3.126 -KEY_HANJA=123 3.127 -KEY_YEN=124 3.128 -KEY_LEFTMETA=125 3.129 -KEY_RIGHTMETA=126 3.130 -KEY_COMPOSE=127 3.131 -KEY_STOP=128 3.132 -KEY_AGAIN=129 3.133 -KEY_PROPS=130 3.134 -KEY_UNDO=131 3.135 -KEY_FRONT=132 3.136 -KEY_COPY=133 3.137 -KEY_OPEN=134 3.138 -KEY_PASTE=135 3.139 -KEY_FIND=136 3.140 -KEY_CUT=137 3.141 -KEY_HELP=138 3.142 -KEY_MENU=139 3.143 -KEY_CALC=140 3.144 -KEY_SETUP=141 3.145 -KEY_SLEEP=142 3.146 -KEY_WAKEUP=143 3.147 -KEY_FILE=144 3.148 -KEY_SENDFILE=145 3.149 -KEY_DELETEFILE=146 3.150 -KEY_XFER=147 3.151 -KEY_PROG1=148 3.152 -KEY_PROG2=149 3.153 -KEY_WWW=150 3.154 -KEY_MSDOS=151 3.155 -KEY_COFFEE=152 3.156 -KEY_DIRECTION=153 3.157 -KEY_CYCLEWINDOWS=154 3.158 -KEY_MAIL=155 3.159 -KEY_BOOKMARKS=156 3.160 -KEY_COMPUTER=157 3.161 -KEY_BACK=158 3.162 -KEY_FORWARD=159 3.163 -KEY_CLOSECD=160 3.164 -KEY_EJECTCD=161 3.165 -KEY_EJECTCLOSECD=162 3.166 -KEY_NEXTSONG=163 3.167 -KEY_PLAYPAUSE=164 3.168 -KEY_PREVIOUSSONG=165 3.169 -KEY_STOPCD=166 3.170 -KEY_RECORD=167 3.171 -KEY_REWIND=168 3.172 -KEY_PHONE=169 3.173 -KEY_ISO=170 3.174 -KEY_CONFIG=171 3.175 -KEY_HOMEPAGE=172 3.176 -KEY_REFRESH=173 3.177 -KEY_EXIT=174 3.178 -KEY_MOVE=175 3.179 -KEY_EDIT=176 3.180 -KEY_SCROLLUP=177 3.181 -KEY_SCROLLDOWN=178 3.182 -KEY_KPLEFTPAREN=179 3.183 -KEY_KPRIGHTPAREN=180 3.184 -KEY_NEW=181 3.185 -KEY_REDO=182 3.186 -KEY_F13=183 3.187 -KEY_F14=184 3.188 -KEY_F15=185 3.189 -KEY_F16=186 3.190 -KEY_F17=187 3.191 -KEY_F18=188 3.192 -KEY_F19=189 3.193 -KEY_F20=190 3.194 -KEY_F21=191 3.195 -KEY_F22=192 3.196 -KEY_F23=193 3.197 -KEY_F24=194 3.198 -KEY_PLAYCD=200 3.199 -KEY_PAUSECD=201 3.200 -KEY_PROG3=202 3.201 -KEY_PROG4=203 3.202 -KEY_SUSPEND=205 3.203 -KEY_CLOSE=206 3.204 -KEY_PLAY=207 3.205 -KEY_FASTFORWARD=208 3.206 -KEY_BASSBOOST=209 3.207 -KEY_PRINT=210 3.208 -KEY_HP=211 3.209 -KEY_CAMERA=212 3.210 -KEY_SOUND=213 3.211 -KEY_QUESTION=214 3.212 -KEY_EMAIL=215 3.213 -KEY_CHAT=216 3.214 -KEY_SEARCH=217 3.215 -KEY_CONNECT=218 3.216 -KEY_FINANCE=219 3.217 -KEY_SPORT=220 3.218 -KEY_SHOP=221 3.219 -KEY_ALTERASE=222 3.220 -KEY_CANCEL=223 3.221 -KEY_BRIGHTNESSDOWN=224 3.222 -KEY_BRIGHTNESSUP=225 3.223 -KEY_MEDIA=226 3.224 -KEY_SWITCHVIDEOMODE=227 3.225 -KEY_KBDILLUMTOGGLE=228 3.226 -KEY_KBDILLUMDOWN=229 3.227 -KEY_KBDILLUMUP=230 3.228 -KEY_SEND=231 3.229 -KEY_REPLY=232 3.230 -KEY_FORWARDMAIL=233 3.231 -KEY_SAVE=234 3.232 -KEY_DOCUMENTS=235 3.233 -KEY_BATTERY=236 3.234 -KEY_BLUETOOTH=237 3.235 -KEY_WLAN=238 3.236 -KEY_UWB=239 3.237 -KEY_UNKNOWN=240 3.238 -KEY_VIDEO_NEXT=241 3.239 -KEY_VIDEO_PREV=242 3.240 -KEY_BRIGHTNESS_CYCLE=243 3.241 -KEY_BRIGHTNESS_ZERO=244 3.242 -KEY_DISPLAY_OFF=245 3.243 -KEY_WIMAX=246 3.244 -KEY_LOCK=$KEY_COFFEE 3.245 -KEY_LIGHT=$KEY_F19 3.246 -KEY_VIDEOOUT=$KEY_F20 3.247 -KEY_ROTATESCREEN=$KEY_F21 3.248 -KEY_VIDEOMODECYCLE=$KEY_F22 3.249 -KEY_PRESENTATION=\KEY_F23
4.1 --- a/acpid/receipt Thu Oct 23 20:13:41 2008 +0200 4.2 +++ b/acpid/receipt Thu Oct 23 20:07:24 2008 +0000 4.3 @@ -2,10 +2,12 @@ 4.4 4.5 PACKAGE="acpid" 4.6 VERSION="1.0.6" 4.7 +EXTRAVERSION="-3" 4.8 CATEGORY="system-tools" 4.9 SHORT_DESC="The ACPI event daemon" 4.10 MAINTAINER="domcox@users.sourceforge.net" 4.11 DEPENDS="" 4.12 +BUILD_DEPENDS="linux-headers" 4.13 TARBALL="$PACKAGE-$VERSION.tar.gz" 4.14 WEB_SITE="http://acpid.sourceforge.net/" 4.15 WGET_URL="$SF_MIRROR/$PACKAGE/$TARBALL" 4.16 @@ -47,8 +49,6 @@ 4.17 mkdir -p $fs/etc 4.18 cp -a stuff/init.d $fs/etc/ 4.19 cp -a stuff/acpi $fs/etc/ 4.20 - mkdir -p $fs/var/log/ 4.21 - touch $fs/var/log/acpid.log && chmod 700 $fs/var/log/acpid.log 4.22 # acpi_fakekey 4.23 cp -a acpi_fakekey $fs/usr/bin 4.24 cp -a $KEY_FILE $fs/etc/acpi/
5.1 --- a/acpid/stuff/acpi/ac.sh Thu Oct 23 20:13:41 2008 +0200 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,40 +0,0 @@ 5.4 -#!/bin/sh 5.5 -## 5.6 -## ac.sh 5.7 -## 5.8 -## Made by Dominique Corbex 5.9 -## Login <domcox@users.sourceforge.net> 5.10 -## 5.11 -## Started on Mon Oct 6 12:56:58 2008 Dominique Corbex 5.12 -## Last update 5.13 -## 5.14 - 5.15 -# Disable laptop mode 5.16 -# When laptop mode is enabled, the kernel will try to be smart 5.17 -# about when to do IO, to give the disk and the SATA links as 5.18 -# much time as possible in a low power state. 5.19 - 5.20 -if [ -e /proc/sys/vm/laptop_mode ] ; then 5.21 - echo "Disabling laptop mode" 5.22 - echo 0 > /proc/sys/vm/laptop_mode 5.23 -fi 5.24 - 5.25 -# AC97 audio power saving mode 5.26 -# The AC97 onboard audio chips support power saving, where the 5.27 -# analog parts (codec) are powered down when no program is using 5.28 -# the audio device. 5.29 - 5.30 -if [ -e /sys/module/snd_ac97_codec/parameters/power_save ] ; then 5.31 - echo "Enabling AC97 audio power saving mode" 5.32 - echo 0 > /sys/module/snd_ac97_codec/parameters/power_save 5.33 -fi 5.34 - 5.35 -# The VM writeback time 5.36 -# The VM subsystem caching allows the kernel to group consecutive 5.37 -# writes into one big write, and to generally optimize the disk IO 5.38 -# to be the most efficient. 5.39 - 5.40 -if [ -e /proc/sys/vm/dirty_writeback_centisecs ] ; then 5.41 - echo "Writeback time reset back to 500ms" 5.42 - echo 500 > /proc/sys/vm/dirty_writeback_centisecs 5.43 -fi
6.1 --- a/acpid/stuff/acpi/battery.sh Thu Oct 23 20:13:41 2008 +0200 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,46 +0,0 @@ 6.4 -#!/bin/sh 6.5 -## 6.6 -## battery.sh 6.7 -## 6.8 -## Made by Dominique Corbex 6.9 -## Login <domcox@users.sourceforge.net 6.10 -## 6.11 -## Started on Mon Oct 6 12:09:59 2008 Dominique Corbex 6.12 -## Last update 6.13 -## 6.14 -## Tips & Tricks taken from http://www.lesswatts.org 6.15 - 6.16 -# Enable laptop mode 6.17 -# When laptop mode is enabled, the kernel will try to be smart 6.18 -# about when to do IO, to give the disk and the SATA links as 6.19 -# much time as possible in a low power state. 6.20 - 6.21 -if [ ! -e /proc/sys/vm/laptop_mode ] ; then 6.22 - echo "Kernel does not have support for laptop mode. Please apply the laptop mode" >&2 6.23 - echo "patch or install a newer kernel." >&2 6.24 -else 6.25 - echo "Enabling laptop mode" 6.26 - echo 5 > /proc/sys/vm/laptop_mode 6.27 -fi 6.28 - 6.29 -# AC97 audio power saving mode 6.30 -# The AC97 onboard audio chips support power saving, where the 6.31 -# analog parts (codec) are powered down when no program is using 6.32 -# the audio device. 6.33 - 6.34 -if [ -e /sys/module/snd_ac97_codec/parameters/power_save ] ; then 6.35 - echo "Enabling AC97 audio power saving mode" 6.36 - echo 1 > /sys/module/snd_ac97_codec/parameters/power_save 6.37 - echo 1 > /dev/dsp 6.38 -fi 6.39 - 6.40 -# The VM writeback time 6.41 -# The VM subsystem caching allows the kernel to group consecutive 6.42 -# writes into one big write, and to generally optimize the disk IO 6.43 -# to be the most efficient. 6.44 - 6.45 -if [ -e /proc/sys/vm/dirty_writeback_centisecs ] ; then 6.46 - echo "Writeback time set to 1500ms" 6.47 - echo 1500 > /proc/sys/vm/dirty_writeback_centisecs 6.48 -fi 6.49 -
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/acpid/stuff/acpi/button.sh Thu Oct 23 20:07:24 2008 +0000 7.3 @@ -0,0 +1,39 @@ 7.4 +#!/bin/sh 7.5 +# button.sh - Managing button events for SliTaz 7.6 +# 7.7 + 7.8 +source /etc/acpi/key-constants 7.9 + 7.10 +# logger "button.sh: event=$1" 7.11 + 7.12 +# take care about the way events are reported 7.13 + 7.14 +EVENT_TYPE=`echo $1 | cut -d/ -f1` 7.15 +if [ $EVENT_TYPE = $1 ]; then 7.16 + EVENT=$2 7.17 +else 7.18 + EVENT=`echo "$1" | cut -d/ -f2` 7.19 +fi 7.20 + 7.21 +case $EVENT in 7.22 + power) 7.23 + logger "Event: button/power - sending KEY_EXIT($KEY_EXIT)" 7.24 + /usr/bin/acpi_fakekey $KEY_EXIT 7.25 + ;; 7.26 + lid) 7.27 + if [ -e /usr/bin/suspend ] ; then 7.28 + logger "Event: button/lid - suspending" 7.29 + /usr/bin/suspend 7.30 + else 7.31 + logger "Event: button/lid - /usr/bin/suspend not found, skipping.." 7.32 + fi 7.33 + ;; 7.34 + sleep) 7.35 + if [ -e /usr/bin/hibernate ] ; then 7.36 + logger "Event: button/sleep - hibernating" 7.37 + /usr/bin/hibernate 7.38 + else 7.39 + logger "Event: button/sleep - /usr/bin/hibernate not found, skipping.." 7.40 + fi 7.41 + ;; 7.42 +esac
8.1 --- a/acpid/stuff/acpi/events/ac Thu Oct 23 20:13:41 2008 +0200 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,5 +0,0 @@ 8.4 -# /etc/acpi/event/ac 8.5 -# called when the user connects ac power 8.6 - 8.7 -event=ac_adapter 8.8 -action=/etc/acpi/ac.sh
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/acpid/stuff/acpi/events/ac.conf Thu Oct 23 20:07:24 2008 +0000 9.3 @@ -0,0 +1,6 @@ 9.4 +# /etc/acpi/event/ac.conf 9.5 +# ac power events 9.6 + 9.7 +event=ac_adapter 9.8 +action=/etc/acpi/power-supply.sh 9.9 +
10.1 --- a/acpid/stuff/acpi/events/battery Thu Oct 23 20:13:41 2008 +0200 10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 10.3 @@ -1,5 +0,0 @@ 10.4 -# /etc/acpi/event/battery 10.5 -# called when ac power goes away 10.6 - 10.7 -event=battery 10.8 -action=/etc/acpi/battery.sh
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/acpid/stuff/acpi/events/battery.conf Thu Oct 23 20:07:24 2008 +0000 11.3 @@ -0,0 +1,6 @@ 11.4 +# /etc/acpi/event/battery.conf 11.5 +# Battery events 11.6 + 11.7 +event=battery 11.8 +action=/etc/acpi/power-supply.sh 11.9 +
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/acpid/stuff/acpi/events/button.conf Thu Oct 23 20:07:24 2008 +0000 12.3 @@ -0,0 +1,6 @@ 12.4 +# /etc/acpi/event/button 12.5 +# lid, sleep or power button events 12.6 + 12.7 +event=button 12.8 +action=/etc/acpi/button.sh %e 12.9 +
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/acpid/stuff/acpi/power-supply.sh Thu Oct 23 20:07:24 2008 +0000 13.3 @@ -0,0 +1,235 @@ 13.4 +#!/bin/sh 13.5 +# /etc/acpi/power-supply.sh - Managing power events for SliTaz 13.6 +# For Tips & Tricks see http://www.lesswatts.org 13.7 + 13.8 +# This script turns off power savings mode on ac or when the 13.9 +# battery almost runs out in a attempt to limit data loss in 13.10 +# a case of power failure. 13.11 + 13.12 +ENABLED=1 13.13 +DISABLED=0 13.14 + 13.15 +# AC status (from /sys/class/power_supply/online) 13.16 +ON_LINE=1 13.17 +OFF_LINE=0 13.18 + 13.19 +# Battery status 13.20 +LOW_BAT=0 13.21 +HIGH_BAT=1 13.22 + 13.23 +# Determining the power state. 13.24 + 13.25 +ac_status() 13.26 +{ 13.27 + POWER_SUPPLY_MAINS=$DISABLED 13.28 + AC_STATUS=$OFF_LINE 13.29 + for POWER_SUPPLY in /sys/class/power_supply/* ; do 13.30 + if [ -f $POWER_SUPPLY/type ] ; then 13.31 + if [ "$(cat $POWER_SUPPLY/type)" = "Mains" ] ;then 13.32 + echo -n "Determining power state from $POWER_SUPPLY: " 13.33 + POWER_SUPPLY_MAINS=$ENABLED 13.34 + if [ "$(cat $POWER_SUPPLY/online)" = 1 ] ; then 13.35 + AC_STATUS=$ON_LINE 13.36 + echo "on-line" 13.37 + else 13.38 + echo "off-line" 13.39 + fi 13.40 + fi 13.41 + fi 13.42 + done 13.43 + if [ $POWER_SUPPLY_MAINS -eq $DISABLED ] ; then 13.44 + $AC_STATUS=$ON_LINE 13.45 + fi 13.46 +} 13.47 + 13.48 +# Determining the battery state. 13.49 + 13.50 +battery_status() 13.51 +{ 13.52 + BATTERY_STATUS=$LOW_BAT 13.53 + for BATT in /sys/class/power_supply/* ; do 13.54 + BATT_TYPE=$(cat $BATT/type) 13.55 + echo "$BATT is of type $BATT_TYPE." 13.56 + if [ "$BATT_TYPE" = "Battery" ] ; then 13.57 + echo " Checking levels for $BATT." 13.58 + # Only do if the battery is present 13.59 + if [ $(cat $BATT/present) -eq 1 ] ; then 13.60 + 13.61 + # Get the remaining capacity. 13.62 + if [ -f $BATT/charge_now ] ; then 13.63 + REMAINING=$(cat $BATT/charge_now) 13.64 + elif [ -f $BATT/energy_now ] ; then 13.65 + REMAINING=$(cat $BATT/energy_now) 13.66 + else 13.67 + REMAINING=0 13.68 + fi 13.69 + if [ -z "$REMAINING" -o "$REMAINING" -eq 0 ] ; then 13.70 + echo " Battery does not report remaining charge. Perhaps it is not present?" 13.71 + else 13.72 + echo " Remaining charge: $REMAINING" 13.73 + 13.74 + # Get the alarm level 13.75 + ALARM_LEVEL=$(cat $BATT/alarm) 13.76 + if [ "$ALARM_LEVEL" -eq 0 ] ; then 13.77 + 13.78 + # Get the full capacity. 13.79 + 13.80 + if [ -f $BATT/charge_full_design ] ; then 13.81 + CAPACITY=$(cat $BATT/charge_full_design) 13.82 + elif [ -f $BATT/energy_full_design ] ; then 13.83 + CAPACITY=$(cat $BATT/energy_full_design) 13.84 + else 13.85 + CAPACITY=0 13.86 + fi 13.87 + if [ -z "$CAPACITY" -o "$CAPACITY" -eq 0 ] ; then 13.88 + echo " Battery does not report design full charge, using non-design full charge." 13.89 + 13.90 + if [ -f $BATT/charge_full ] ; then 13.91 + CAPACITY=$(cat $BATT/charge_full) 13.92 + elif [ -f $BATT/energy_full_design ] ; then 13.93 + CAPACITY=$(cat $BATT/energy_full) 13.94 + else 13.95 + CAPACITY=0 13.96 + fi 13.97 + if [ -z "$CAPACITY" -o "$CAPACITY" -eq 0] ; then 13.98 + echo " Battery does not report non-design full charge." 13.99 + fi 13.100 + fi 13.101 + echo " Full capacity: $CAPACITY" 13.102 + ALARM_LEVEL=$((CAPACITY*5/100)) 13.103 + fi 13.104 + echo " Alarm level: $ALARM_LEVEL" 13.105 + if [ "$ALARM_LEVEL" -ne 0 ] ; then 13.106 + if [ "$REMAINING" -ge "$ALARM_LEVEL" ] ; then 13.107 + # this battery does count as having enough charge. 13.108 + BATTERY_STATUS=$HIGH_BAT 13.109 + echo " Battery status: high" 13.110 + else 13.111 + echo " Battery status: low" 13.112 + fi 13.113 + fi 13.114 + fi 13.115 + else 13.116 + echo "Battery is not present." 13.117 + fi 13.118 + fi 13.119 + done 13.120 +} 13.121 + 13.122 +online_mode() 13.123 +{ 13.124 + # Disable laptop mode 13.125 + # When laptop mode is enabled, the kernel will try to be smart 13.126 + # about when to do IO, to give the disk and the SATA links as 13.127 + # much time as possible in a low power state. 13.128 + 13.129 + if [ -e /proc/sys/vm/laptop_mode ] ; then 13.130 + echo "Disabling laptop mode" 13.131 + echo 0 > /proc/sys/vm/laptop_mode 13.132 + fi 13.133 + 13.134 + # AC97 audio power saving mode 13.135 + # The AC97 onboard audio chips support power saving, where the 13.136 + # analog parts (codec) are powered down when no program is using 13.137 + # the audio device. 13.138 + 13.139 + if [ -e /sys/module/snd_ac97_codec/parameters/power_save ] ; then 13.140 + echo "Disabling AC97 audio power saving mode" 13.141 + echo 0 > /sys/module/snd_ac97_codec/parameters/power_save 13.142 + fi 13.143 + 13.144 + # The VM writeback time 13.145 + # The VM subsystem caching allows the kernel to group consecutive 13.146 + # writes into one big write, and to generally optimize the disk IO 13.147 + # to be the most efficient. 13.148 + 13.149 + if [ -e /proc/sys/vm/dirty_writeback_centisecs ] ; then 13.150 + echo "Writeback time reset to 500ms" 13.151 + echo 500 > /proc/sys/vm/dirty_writeback_centisecs 13.152 + fi 13.153 +} 13.154 + 13.155 +offline_mode() 13.156 +{ 13.157 + # Enable laptop mode 13.158 + # When laptop mode is enabled, the kernel will try to be smart 13.159 + # about when to do IO, to give the disk and the SATA links as 13.160 + # much time as possible in a low power state. 13.161 + 13.162 + if [ ! -e /proc/sys/vm/laptop_mode ] ; then 13.163 + echo "Kernel does not have support for laptop mode." 13.164 + else 13.165 + echo "Enabling laptop mode" 13.166 + echo 5 > /proc/sys/vm/laptop_mode 13.167 + fi 13.168 + 13.169 + # AC97 audio power saving mode 13.170 + # The AC97 onboard audio chips support power saving, where the 13.171 + # analog parts (codec) are powered down when no program is using 13.172 + # the audio device. 13.173 + 13.174 + if [ -e /sys/module/snd_ac97_codec/parameters/power_save ] ; then 13.175 + echo "Enabling AC97 audio power saving mode" 13.176 + echo 1 > /sys/module/snd_ac97_codec/parameters/power_save 13.177 + echo 1 > /dev/dsp 13.178 + fi 13.179 + 13.180 + # The VM writeback time 13.181 + # The VM subsystem caching allows the kernel to group consecutive 13.182 + # writes into one big write, and to generally optimize the disk IO 13.183 + # to be the most efficient. 13.184 + 13.185 + if [ -e /proc/sys/vm/dirty_writeback_centisecs ] ; then 13.186 + echo "Writeback time set to 1500ms" 13.187 + echo 1500 > /proc/sys/vm/dirty_writeback_centisecs 13.188 + fi 13.189 +} 13.190 + 13.191 +power_status() 13.192 +{ 13.193 + if [ $(cat /proc/sys/vm/dirty_writeback_centisecs) -gt 1000 ]; then 13.194 + POWER_SAVINGS=$ENABLED 13.195 + echo "power-savings-mode enabled" 13.196 + else 13.197 + POWER_SAVINGS=$DISABLED 13.198 + echo "power-savings-mode disabled" 13.199 + fi 13.200 +} 13.201 + 13.202 +custom_scripts() 13.203 +{ 13.204 + # Custom scripts in /etc/acpi/ac.d 13.205 + 13.206 + if [ -d /etc/acpi/ac.d ]; then 13.207 + for SCRIPT in /etc/acpi/ac.d/*.sh; do 13.208 + . $SCRIPT $AC_STATUS $BATTERY_STATUS $0 13.209 + done 13.210 + fi 13.211 + 13.212 + # Custom scripts in /etc/acpi/battery.d 13.213 + 13.214 + if [ -d /etc/acpi/battery.d ]; then 13.215 + for SCRIPT in /etc/acpi/battery.d/*.sh; do 13.216 + . $SCRIPT $AC_STATUS $BATTERY_STATUS $0 13.217 + done 13.218 + fi 13.219 +} 13.220 + 13.221 +ac_status 13.222 +battery_status 13.223 +power_status 13.224 +case "$AC_STATUS+$BATTERY_STATUS" in 13.225 + "$OFF_LINE+$HIGH_BAT") 13.226 + if [ $POWER_SAVINGS = $DISABLED ]; then 13.227 + logger "Start power savings mode" 13.228 + offline_mode 13.229 + fi 13.230 + ;; 13.231 + *) 13.232 + if [ $POWER_SAVINGS = $ENABLED ]; then 13.233 + logger "Stop power savings mode" 13.234 + online_mode 13.235 + fi 13.236 + ;; 13.237 +esac 13.238 +custom_scripts 13.239 \ No newline at end of file
14.1 --- a/acpid/stuff/init.d/acpid Thu Oct 23 20:13:41 2008 +0200 14.2 +++ b/acpid/stuff/init.d/acpid Thu Oct 23 20:07:24 2008 +0000 14.3 @@ -12,11 +12,12 @@ 14.4 DESC="ACPI event deamon" 14.5 DAEMON=/usr/sbin/acpid 14.6 OPTIONS=$ACPID_OPTIONS 14.7 -PIDFILE=/var/run/acpid.pid 14.8 +NPID=`ps ax | grep $DAEMON | wc -l` 14.9 +PID=`ps ax | grep $DAEMON | awk '{print $1}'` 14.10 14.11 case "$1" in 14.12 start) 14.13 - if [ -f $PIDFILE ] ; then 14.14 + if [ $NPID -ne 0 ] ; then 14.15 echo "$NAME already running." 14.16 exit 1 14.17 fi 14.18 @@ -25,21 +26,21 @@ 14.19 status 14.20 ;; 14.21 stop) 14.22 - if [ ! -f $PIDFILE ] ; then 14.23 + if [ $NPID -eq 0 ] ; then 14.24 echo "$NAME is not running." 14.25 exit 1 14.26 fi 14.27 echo -n "Stopping $DESC: $NAME... " 14.28 - kill `cat $PIDFILE` 14.29 + kill $PID 14.30 status 14.31 ;; 14.32 restart) 14.33 - if [ ! -f $PIDFILE ] ; then 14.34 + if [ $NPID -eq 0 ] ; then 14.35 echo "$NAME is not running." 14.36 exit 1 14.37 fi 14.38 echo -n "Restarting $DESC: $NAME... " 14.39 - kill `cat $PIDFILE` 14.40 + kill $PID 14.41 sleep 2 14.42 $DAEMON $OPTIONS > /dev/null 14.43 status