Difference between revisions of "Acpid"

From ArchWiki
Jump to navigation Jump to search
(function getuser added)
Line 57: Line 57:
 
== Extending acpid with pm-utils ==
 
== Extending acpid with pm-utils ==
 
Although <tt>acpid</tt> can provide basic suspend2ram out-of-the-box, a more robust system may be desired.  [[Pm-utils]] provides a very flexible framework for suspend2ram (suspend) and suspend2disk (hibernate) operations, including fixes to stubborn hardware and drivers (e.g. fglrx video).  pm-utils primarily consists of 2 scripts, <tt>pm-suspend</tt> and <tt>pm-hibernate</tt>, both of which can be inserted as events into acpid.  For more information, check the [[Pm-utils]] wiki.
 
Although <tt>acpid</tt> can provide basic suspend2ram out-of-the-box, a more robust system may be desired.  [[Pm-utils]] provides a very flexible framework for suspend2ram (suspend) and suspend2disk (hibernate) operations, including fixes to stubborn hardware and drivers (e.g. fglrx video).  pm-utils primarily consists of 2 scripts, <tt>pm-suspend</tt> and <tt>pm-hibernate</tt>, both of which can be inserted as events into acpid.  For more information, check the [[Pm-utils]] wiki.
 +
 +
== Getting user name at the current display ==
 +
You can use function getuser
 +
 +
getuser ()
 +
{
 +
export DISPLAY=`echo $DISPLAY | cut -c -2`
 +
user=`who | grep " $DISPLAY" | awk '{print $1}'`
 +
export XAUTHORITY=/home/$user/.Xauthority
 +
eval $1=$user
 +
}
 +
 +
to achieve user at the current display. For example when you press the power button and want to shutdown KDE properly you can use this function:
 +
button/power)
 +
                case "$2" in
 +
                        PBTN)
 +
                                getuser "$user"
 +
                                echo $user > /dev/tty5
 +
                                su $user -c "dcop ksmserver ksmserver logout 0 2 0"
 +
                                ;;
 +
                        *)    logger "ACPI action undefined $2" ;;
 +
                esac
 +
                ;;
  
 
= More Resources =
 
= More Resources =
 
*http://acpid.sourceforge.net/ - acpid homepage
 
*http://acpid.sourceforge.net/ - acpid homepage
 
*http://www.capaman.8m.com/acpid.html - acpid mini-howto
 
*http://www.capaman.8m.com/acpid.html - acpid mini-howto

Revision as of 06:14, 30 August 2007


Summary

ACPID is a flexible and extensible daemon for delivering ACPI events. These events are triggered by certain actions, such as:

  • Pressing the Power button
  • Pressing the Sleep/Suspend button
  • Closing a notebook lid
  • (Un)Plugging an AC power adapter from a notebook

acpid can be used by itself, or combined with a more robust system such as Pm-utils and Cpufrequtils to provide a more complete power management solution.

Installation

The acpid package is available from the Current repository:

# pacman -S acpid

Edit /etc/rc.conf as root and add acpid to the DAEMONS array, for example:

DAEMONS=(syslog-ng acpid cpufreq dhcdbd networkmanager @alsa @crond ... )

Note: If you already have hal specified in your DAEMONS, there is no need to add acpid. HAL will automatically detect and load the acpid daemon.

Configuration

acpid comes with a number of predefined actions for triggered events, such as what should happen when you press the Power button on your machine. By default, these actions are defined in /etc/acpi/handler.sh. The following is a shortened example one such action, in this case when the Sleep Button is pressed acpid runs the command echo -n mem >/sys/power/state which should place the computer into a sleep state.

	button/sleep)
		case "$2" in
			SLPB) echo -n mem >/sys/power/state ;;
			*)    logger "ACPI action undefined: $2" ;;
		esac
		;;

Unfortunately, not every computer labels the ACPI events in the same way. For example, the Sleep button may be identified on one machine as SLPB and on another as SBTN.

To determine how your buttons or Fn shortcuts are recognized, run the following command from a terminal as root:

# tail -f /var/log/messages.log

Now press the Power button and/or Sleep button (e.g. Fn+Esc) on your machine. The result should look something this:

Aug 29 17:18:31 dublin logger: ACPI action undefined: PBTN
Aug 29 17:18:33 dublin logger: ACPI action undefined: SBTN

As you might have noticed, the Sleep button in the sample output is actually recognized as SBTN, rather than the SLPB label specified in the default /etc/acpi/handler.sh. In order for Sleep function to work properly on this machine, we would need to replace SLPB) with SBTN).

Using this information as a base, you can easily customize the handler.sh file to execute a variety of commands depending on which event is triggered. See the Tips & Tricks section below for more sample commands.

Tips & Tricks

Sample Events

The following are samples of events that can be dropped into the existing /etc/acpi/handler.sh script. Bolded text indicates modifications or additions to the default script. As noted above, your event labels may differ so some tweaking may be necessary.

Activate Xscreensaver upon lid closure:

button/lid)
       #echo "LID switched!">/dev/tty5
       /usr/bin/xscreensaver-command -lock
       ;;

Execute pm-suspend (from Pm-utils) when the Sleep button is pressed:

button/sleep)
	case "$2" in
		SBTN) 
			#echo -n mem >/sys/power/state
			/usr/sbin/pm-suspend
			;;

Extending acpid with pm-utils

Although acpid can provide basic suspend2ram out-of-the-box, a more robust system may be desired. Pm-utils provides a very flexible framework for suspend2ram (suspend) and suspend2disk (hibernate) operations, including fixes to stubborn hardware and drivers (e.g. fglrx video). pm-utils primarily consists of 2 scripts, pm-suspend and pm-hibernate, both of which can be inserted as events into acpid. For more information, check the Pm-utils wiki.

Getting user name at the current display

You can use function getuser

getuser ()
{
export DISPLAY=`echo $DISPLAY | cut -c -2`
user=`who | grep " $DISPLAY" | awk '{print $1}'`
export XAUTHORITY=/home/$user/.Xauthority
eval $1=$user
}

to achieve user at the current display. For example when you press the power button and want to shutdown KDE properly you can use this function:

button/power)
               case "$2" in
                       PBTN)
                               getuser "$user"
                               echo $user > /dev/tty5
                               su $user -c "dcop ksmserver ksmserver logout 0 2 0"
                               ;;
                       *)    logger "ACPI action undefined $2" ;;
               esac
               ;;

More Resources