For some blurb, read the quest for an off button that really works.
The pmpolicy kernel patch and accompanying userspace example utility was written to allow you to determine when an APM power management event should be rejected.
An alternative is to just reject every event, and let a userspace program decide whether to suspend the machine or not. This is the pmevent patch. It is simpler and more in tune with other PM schemes. The pmevent patch lets userspace programs receive information whenever a PM event occurs. At the moment only the APM driver exports this information but the userspace interface was explicitly designed to allow other PM systems to losslessly imform userspace about events.
The pmevent patch implements a device node that can be opened, and read by any number of processes. You can create it with the commnand
mknod pmevent c 10 137
It will appear in the misc/ directory of devfs as pmevent.
You can see what events occur simply by "cat"ing it to the console. The format is very simple.
<event> <WS> <subsystem> <WS> <description> <LF>
Where <event> is one of the strings OFF,SLEEP,WAKE,EMERGENCY,NOTIFY (if a reader does not read events quickly enough, it will get a MSGFLOOD event), <WS> is a space character, <subsystem> is a word denoting the kernel pm interface responsible for generating the event, <description> is an arbitrary string. <LF> is a newline character \n.
This is flexible. It means a reasonable default behaviour can be suggested by the kernel (OFF,SLEEP,etc.) for events that userspace doesn't know about, but userspace can choose fine grained policy and provide helpful error messages based on the exact event name by checking the description.
You can download the patch.
The pmpolicy patch is different from the pmevent patch. You can't use both at the same time.
Currently the default settings for the pmpolicy patch mean the computer will be shut down cleanly whenever it receives an APM user suspend (e.g. someone closes the case of their laptop, presses a soft-off button). If you don't like this, edit the /sbin/powermanager script provided.
The kernel patch augments the rudimentary power management interfaces in linux-2.4 to allow people to ask for power management events to take place. It then patches the APM driver to do this. The power management interface is also patched to ask userspace what it thinks of these requests by running the /sbin/powermanager program. (Further if any PM enabled device driver doesn't think the event is a good idea it's called off as well.)
Download the powermanager tarball, untar, ./configure and make install it. You must then patch your kernel. For this you must have the Linux kernel sources. The patch is against the 2.4.0 kernel, but also applies cleanly to Linus' comically named 2.4.0-test13* (and 2.4.0-prerelease) released before 2.4.0. Note that there are several versions of the patch. You need only apply one (choose the one with the highest last number unless you are weird). Do
# cd linux # patch -p1 < ~/incoming/patch # make dep install modules modules_install
Last modified: Tue Apr 22 00:22:01 BST 2003