The time now is Fri 24 May 2013, 13:27
All times are UTC - 4 |
| Author |
Message |
Karl Godt

Joined: 20 Jun 2010 Posts: 2679 Location: Kiel,Germany
|
Posted: Fri 01 Jun 2012, 16:47 Post subject:
busybox acpid |
|
Good day !
After examinig busybox acpid i have these two scripts :
1) /etc/init.d/bb_acpi
2) /etc/acpi/PWRF/00000080
Busybox acpid was introduced with version 1.14 and had major changes from 1.17 to 1.18 .
What i still not had getting finished is the syntax for the /etc/acpid.conf and /etc/acpid.map files .
Busybox acpid changes to /etc/acpi directory and if the Power Button is pressed, triggers the file ./PWRF/00000080 .
The directory /proc/acpi/button/PWRF at my desktop pc gets apparently created by the button.ko module .
At my netbook i have only the directory LID inside /proc/acpi/button directory , though button.ko module is loaded .
Closing the LID does not do anything for now, i think the busybox source has a LID0 line .
So here's the /etc/init.d/bb_acpi script to start busybox acpid at bootup :
| Code: | #!/bin/sh
# Karl Reimer Godt in June 2012
# usual Puppy license
Version='1.0 Puppy_Linux_Racy_5.3 KRG'
usage(){
MSG="
$0 [start|stop]
Starts busybox acpid daemon at boot and
shuts it down at reboot or poweroff event.
"
if [ "$2" ];then
MSG="$MSG
$2
"
fi
echo "$MSG"
[ "$DISPLAY" ] && xmessage -bg blue3 "$MSG"
exit $1
}
ACPID_BIN=`which acpid`
[ "$ACPID_BIN" ] || usage 1 "No (executable) acpid binary installed?"
[ "`readlink "$ACPID_BIN" | grep -i 'busybox'`" ] || usage 1 "$0: Laucher for busybox acppid applet."
Config_directory=/etc/acpi # -c
proc_event_file=/proc/acpi/event # -e
Log_file=/var/log/acpid.log # -l
#acpid: invalid option -- 'p'
#BusyBox v1.19.3 (2011-11-09 07:34:50 WST)
Pid_file=/var/run/acpid.pid # -p
Action_file=/etc/acpid.conf # -a
Map_file=/etc/acpi.map # -M
case $1 in
help) usage 0;;
version) echo -e "$0: Version '$Version'\nTry help for more info.\n";exit 0;;
start)
if pidof acpid ;then
echo "acpid Already running."
else
acpid -c "$Config_directory" \
-e "$proc_event_file" \
-l "$Log_file" \
-a "$Action_file" \
-M "$Map_file"
sleep 2
echo -n "Started acpid:"
pidof acpid || echo "FAILED."
fi
;;
stop)
if pidof acpid;then
for n in {1..4};do
kill -$n `pidof acpid`
sleep 1
pidof acpid || break
done
if [ -f "$Pid_file" ];then
pid_file_pid=$(cat "$Pid_file")
[ "$pid_file_pid" ] || pid_file_pid=999999999999999 #fake, hopefully never used :oops:
if ps | grep -w "$pid_file_pid";then
for n in {1..4};do
kill -$n `pidof acpid`
sleep 1
pidof acpid || break
done
fi
fi
if pidof acpid;then
echo "FAILED to stop acpid."
else
echo "acpid stopped."
fi
else
echo "acpid not running."
fi
rm -f "$Pid_file"
;;
"") usage 1 "Need Parameter.";;
*) usage 1 "Unknown Parameter '$1' .";;
esac
|
And this is /etc/acpi/PWRF/00000080 trigger script :
| Code: | #!/bin/sh
# Karl Reimer Godt in June 2012
# usual Puppy license
Version='1.0 Puppy_Racy_5.3 KRG'
usage(){
MSG="
$0 [help]
Script to suspend or hibernate
called by busybox applet 'acpid'.
Busybox acpid since version 1.18 needs
the 'evdev' kernelmodule loaded , but
seems not to need the 'button' module.
Works only with the Powerbutton,
not with closing the lid.
Please don't call busybox applets with
'busybox appletname' . Closing commands like
kill could accidentaly kill busybox init, which
would result in immedeate reboot. Always call it with
the [/path/to/link/]appletname.
Uses acpitool if installed, otherwise the
simple 'echo \"\$state\" >/sys/power/state' .
Full acpid pkg available : unknown.
"
if [ "$2" ];then
MSG="$MSG
$2
"
fi
echo "$MSG"
[ "$DISPLAY" ] && xmessage -bg blue3 "$MSG"
exit $1
}
case $1 in
help) usage 0;;
version) echo -e "$0: Version '$Version'\nTry help for more info.\n";exit 0;;
"") :;;
*) usage 1 "Unknown Parameter '$1'";;
esac
loop_umount_func(){
M_LOOP=`mount | grep '/dev/loop' |grep -v '/initrd'`
M_LOOP=`echo $M_LOOP |rev|sed 's!)!\n)!g'|rev`
M_LOOP=`echo "$M_LOOP" |grep -o ' on .* type ' |sed -r 's!( on )(.*)( type )!\2!'`
for mloop in $M_LOOP;do
umount $mloop
[ $? -ne 0 ] && { xmessage -bg red2 "Please umount '$mloop' manually and try again";exit 0; }
done
}
part_umount_func(){
M_DEV=`mount | grep '/dev/[shfmd]+[0-9]' |grep -v '/initrd'`
M_DEV=`echo $M_DEV |rev|sed 's!)!)\n!g'|rev`
M_POI=`echo "$M_DEV" |grep -o ' on .* type ' |sed -r 's!( on )(.*)( type )!\2!'`
M_DEV=`echo "$M_DEV" |grep -o '.* on ' |sed 's!(.*)( on )!\1!'`
for mpart in $M_POI;do
umount $mpart
[ $? -ne 0 ] && { xmessage -bg red2 "Please umount '$mpart' manually and try again";exit 0; }
done
}
restore_mounts(){
for part in $M_DEV;do
FS_TYPE=`guess_fstype $part`
dirn=${part##*/}
mkdir -p /mnt/$dirn
mount -t $FS_TYPE $part /mnt/$dirn
done
}
ACPITOOL=`which acpitool`
states_avail=`cat /sys/power/state`
states_avail=`echo "$states_avail" |tr ' ' '\n'|sed 's!disk!S4 Hibernation:disk!;s!mem!S3 PM_SLEEP:mem!'`
aplay /usr/share/audio/2barks.au
xmessage -bg red1 "$0
Available states:
$states_avail
"
xmessage -buttons "HIBERNATE On DISK:204,RAM SLEEP:203,ESCAPE GUI:200" -bg blue3 "Busybox acpid :
Do you want to go into ACPI PM SLEEP mode ?"
ANSWER=$?
if [ "$ANSWER" = 200 ];then
:
elif [ "$ANSWER" = 203 ];then
loop_umount_func
part_umount_func
sync
sleep 1
if [ "$ACPITOOL" ];then
acpitool -s
else
echo 'mem' >/sys/power/state
fi
restore_mounts
elif [ "$ANSWER" = 204 ];then
loop_umount_func
part_umount_func
sync
sleep 1
if [ "$ACPITOOL" ];then
PROC_SWAPS=`cat /proc/swaps |sed '1d'|awk '{print $1}'`
for swap in $PROC_SWAPS;do
RESUME=`blkid $swap |grep -iE 'Winter|Hiber|Resume'`
[ "$RESUME" ] && break
done
if [ ! "$RESUME" ];then
FDISK_SWAPS=`fdisk -l |grep -i swap|awk '{print $1}'`
for swap in $FDISK_SWAPS;do
RESUME=`blkid $swap |grep -iE 'Winter|Hiber|Resume'`
[ "$RESUME" ] && break
done
fi
if [ "$RESUME" ];then
for swap in $PROC_SWAPS;do
[ "$swap" = "$RESUME" ] && continue
swapoff $swap
done
swapon $RESUME
fi
sync
sleep 1
acpitool -S
sleep 1
for swap in $PROC_SWAPS;do
swapon $swap
done
if [ "$RESUME" ];then
if test cat /proc/swaps |sed '1d' |wc -l -gt 1;then
swapoff $RESUME
fi
fi
else #acpitool
echo 'disk' >/sys/power/state
fi
restore_mounts
else
:
fi
sleep 5
case $ANSWER in
203)
xmessage "RETURNED from RAM light sleep"
;;
204)
xmessage "RETURNED from DISK winter sleep"
;;
*) :;;
esac
exit 0 |
Note 1:
The Hibernate choice should not work with stock Puppy kernels by BK because hibernation is unfortunately not enabled by him . Others like Saluki and Dpup Exprimo i guess should be able to hibernate .
Note 2:
I started to have two swap partitions : one normal swap and one reserved for hibernation . I have labeled one Swap Partition "Resume" and blkid should find it, and use it, even if it is not primary first swap in /proc/swaps file or not mounted by rc.sysinit .
Note 3:
On my installations the code looks different everywhere, so likely the code i posted has bugs .
Note 4:
It seems that starting /etc/init.d/bb_acpi does start the daemon but it seems not to work as it should. Starting "/etc/init.d/bb_acpi start" works for me from terminal .
[EDIT]
OK found the cause :
Starting acpid before Xorg the DISPLAY variable is not exported system wide yet. Though /etc/acpi/PWRF/00000080 gets executed later while X is running, acpid does export a NULL DISPLAY variable to 00000080 . It is also a matter of login : The DISPLAY variable gets only exported for the current logged in person, normally "root" , so login spot or fido in rxvt terminal would not give a DISPLAY variable to them and a simply 'xmessage "HELLO"' would not work that way either. If i want a dialog GUI for choosing the SLEEP MODE pressing the Power Button of a machine, I need to launch /etc/init.d/bb_acpi from /root/.xinitrc or /usr/sbin/delayedrun . I have chosen to make /etc/init.d/bb_acpi non-executable, so it would not get launched by /etc/rc.d/rc.services and put in a line in /root/.xinitrc :
| Code: | --- /initrd/pup_ro2/root/.xinitrc 2010-11-07 03:32:29.000000000 +0100
+++ /root/.xinitrc 2012-06-02 12:11:08.242407245 +0100
@@ -71,6 +71,7 @@ if [ -f /etc/xrandrindex ];then
fi
fi
+source /etc/init.d/busybox_acpid start
if [ -f /root/.xset.sh ];then
#this is created by /usr/bin/pupx...
|
[/EDIT]
Note 5:
It only works with pressing the Power Button of the machine, closing the lid does nothing (for now) .
Note 6:
busybox 1.18.3 acpid works with the -p option, 1.19.3 at racy seems not to like the -p option .
[EDIT]
So far as i can observe it, busybox acpid does not create files in /var :/var/log/acpid.log and /var/run/acpid.pid don't get created (bb 1.19.3)
[/EDIT]
Note 7:
Maybe the button module is not necessary, but the evdev.ko module .
Have fun !
|
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2679 Location: Kiel,Germany
|
Posted: Sat 02 Jun 2012, 07:33 Post subject:
|
|
screenshot of GUIs :
| Description |
|
| Filesize |
35.91 KB |
| Viewed |
602 Time(s) |

|
|
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2679 Location: Kiel,Germany
|
Posted: Thu 16 Aug 2012, 07:36 Post subject:
busybox acpid severe bug for input devices Subject description: busybox <=1.20.0 |
|
Short update and warning : Busybox acpid seems to have a bug that makes a function looping resulting in 100% CPU usage of one Core .
: acpid hangs with full cpu usage when removing USB input devices
I can confirm this for busybox-1.18.3 acpid with the automatic deconnection of a bluetooth mouse to a usb bt-dongle when the mouse is too long idle.
Should be fixed in 1.20.x version .
| Quote: | | acpid: close fds which are reported as dead (POLLERR/POLLHUP/POLLNVAL) by poll |
http://www.busybox.net/
|
|
Back to top
|
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|