Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 20 Apr 2014, 05:16
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
busybox acpid
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
Karl Godt


Joined: 20 Jun 2010
Posts: 3860
Location: Kiel,Germany

PostPosted: 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
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3860
Location: Kiel,Germany

PostPosted: Sat 02 Jun 2012, 07:33    Post subject:  

screenshot of GUIs :
_acpi_GUIs.jpg
 Description   
 Filesize   35.91 KB
 Viewed   1081 Time(s)

_acpi_GUIs.jpg

Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3860
Location: Kiel,Germany

PostPosted: 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
View user's profile Send private message Visit poster's website 
scabz


Joined: 30 Apr 2009
Posts: 299
Location: Tallahassee FL US

PostPosted: Mon 05 Aug 2013, 12:05    Post subject:  

Precise 5.6.1 has BusyBox v1.21.0, power button and lid switch works but cant find any other keys presses.

the script i use for power button.

/etc/acpi/PWRF/00000080
Code:
#!/bin/sh
# Patriot Jan 2009 for Puppy Linux 4.1.1 GPL
# Revision 0.0.6
# 13sep09 dialogbox by shinobar
# 4nov09 TIMELIMIT 30sec
# 26dec09 wmpoweroff, adjustable less than 10sec.
# 12feb10 stop acpid before powroff

TIMELIMIT=30   # sec, no dialog if 0(zero).

_farewell="Power button is pushed, and about to shut down..."
_press_ok="Press 'OK' to shutdown right now,"
_or_cancel="'Cancel' to continue puppy."
#_ten_sec="Shutting down in 10 seconds."
_limit1="Shutting down in"
_limit2="seconds."

#echo $0 > /root/acpi.log
#date >> /root/acpi.log

SOUND="/usr/share/audio/bark.au"
PLAY="aplay"
[ -f "$SOUND" ] && which $(basename $PLAY) >/dev/null && $(basename $PLAY) "$SOUND"

#echo "DISPLAY=$DISPLAY" >> /root/acpi.log
X_pid=`ps ax | awk '{if (match($5, "X$") || $5 == "X") print $1}'`
if [ "$X_pid" != "" ]; then
#if [ "$DISPLAY" != "" ]; then
 [ -f /etc/rc.d/PUPSTATE ] && source /etc/rc.d/PUPSTATE
 [ -f /etc/rc.d/pupsave.conf ] && source /etc/rc.d/pupsave.conf
 GTKDIALOG=$(which gtkdialog3)
 PUPSAVECONFIG=$(which pupsaveconfig)
 [ "$PUPSAVECONFIG" = "" ] && PUPSAVECONFIG=$(which pupsave)
 [ "$TIMELIMIT" = "" ] && TIMELIMIT=0
 if [ $TIMELIMIT -gt 0 ] && [ "$GTKDIALOG" != "" ] && \
  [ "$PUPMODE" != "5" -o "$PRECHOICE" != "" -o "$PUPSAVECONFIG" = "" ]; then

   mo=acpi.mo
   # set locale
   for lng in C $(echo $LANGUAGE|cut -d':' -f1) $LC_ALL $LANG;do :;done   # ex.    ja_JP.UTF-8
   # search locale file
   lng1=$(echo $lng|cut -d'.' -f1)      # ex.   ja_JP
   lng2=$(echo $lng|cut -d'_' -f1)   # ex.   ja
   LOCALEDIR=/usr/share/locale
   [ "$mo" ] || mo=$(basename $0).mo
   for D in en C $lng2 $lng1 $lng
   do
     F="$LOCALEDIR/$D/LC_MESSAGES/$mo"
     [ -f "$F" ] && . "$F"
   done
   DIV=10
   [ $TIMELIMIT -le 20 ] && DIV=5
   [ $TIMELIMIT -le 10 ] && DIV=$TIMELIMIT
   STEP=$(($TIMELIMIT / $DIV))
   TIMELIMIT=$(($STEP * $DIV))
   PITCH=$((100 / $DIV))
   export DIALOG="<window title=\"acpid\"><vbox>
  <text><label>$_farewell</label></text>
  <text><label>$_press_ok</label></text>
  <text><label>$_or_cancel</label></text>
  <progressbar><label>$_limit1 $TIMELIMIT $_limit2</label>
      <input>for i in \$(seq 0 $PITCH 100); do echo \$i; sleep $STEP; done</input>
      <action type=\"exit\">OK</action>
  </progressbar>
  <hbox>
   <button cancel></button>
   <button ok></button>
  </hbox>
 </vbox></window>"
 #echo "$DIALOG"
   eval $($GTKDIALOG -p DIALOG -c)
   [ "$EXIT" = "Cancel" ] && exit
 fi
 P=wmpoweroff
else
 P=poweroff
fi
/etc/init.d/rc.acpi stop
exec $P


and lid switch

/etc/acpi/LID/00000080
Code:
#!/bin/sh
echo mem > /sys/power/state


I use xbindkeys for the keys that do not work with busybox acpid, thankfully fn keys work with xbindkeys.

My eeepc 1005hab needs this boot option for fn keys to work acpi_osi=Linux

My eeepc 900a does not need any boot options for fn keys to work.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger 
Karl Godt


Joined: 20 Jun 2010
Posts: 3860
Location: Kiel,Germany

PostPosted: Mon 05 Aug 2013, 14:54    Post subject:  

Hi Scabz !

Right now have installed MacpupFoxy3 full to sda9 on a dmidecode
Quote:
Base Board Information
Manufacturer: ASUSTeK Computer INC.
Product Name: 1005HAG
Version: x.xx
Serial Number: EeePC-0123456789
Asset Tag: To Be Filled By O.E.M.
Features:
Board is a hosting board
Board is replaceable
Location In Chassis: To Be Filled By O.E.M.
Chassis Handle: 0x0003
Type: Motherboard


running kernel uname -r 3.9.9-KRG-iCore2-smp-pae-srv1000gz
cat /proc/cmdline panic=56 loglevel=3 root=/dev/sda9 ro debug panic=20 vga=ask

Fn keys work as numpad replacement : 1-9 0, Pup/Pdn/Home/End +-*/ .

For the others I have to find out . I am guessing busybox uses its own syntax or acpid v1 syntax . For regular keys I think I would look into recent lighthouse or saluki to check out theirs /etc/acpi/keys file .
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3860
Location: Kiel,Germany

PostPosted: Mon 05 Aug 2013, 15:04    Post subject:  

BTW> just installed flashblock into FF-16 -- The add on top of the forum is much much much too heavy for flashplayer 11.2.202.x on 2x800MHz .
_________________
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal Razz
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

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
[ Time: 0.0842s ][ Queries: 13 (0.0038s) ][ GZIP on ]