Resume Event

From OESF

Revision as of 02:48, 28 November 2004 by Offroadgeek (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

How to detect when the user resumes.

For information on how to run commands/applications on a resume or even a suspend, please see the __Suspend/Resume Architecture__ section further below.

Author: Neil Horlock

For an application that will probably never come to see the light of day I wanted to detect the power on (resume) event. Thanks to Darryl Okahata who responded to my inital query on the Zaurus developer mailing list (zaurus-devel@lists.sourceforge.net).

There does not appear to be a suspend event, this may seem harsh or even unwise but really this makes sense as you probably want the system to simply turn off, not to wait while a poorly written app tidies up after itself. So we are left with the resume event.

When the Zaurus is powered on all process that are running receive the SIGCONT signal.The following code tests this. All it aims to do is prove that the SIGCONT is generated and that it is received upon resume.

 /* first include the relevent headers */
 #include "signal.h"
 #include "stdio.h"
 #include "time.h"
 /* define a signal handler see signal(2) fro more details */
 /* In this case for the given signal signum, get the present time print it along with the signal number */
 /* reinstate the handler for the next time and return */
 void handler(int signum)
 {
 time_t tim;
 time(&tim);
 fprintf(stderr, "Time now is %s", ctime(&tim));
 fprintf(stderr, "received signal %d\n", signum);
 signal(signum, handler);
 }
 /* finally the simplest little main to activeate the thing */
 /* set up the signal handler across a range of signals, this was done to check whether anything other */
 /* than SIGCONT occurred (it doesn't) */
 /* then loop forever printing the current time and sleepiong for a second */
 int main(int argc, char *argv[])
 {
 int i;
 for(i=12;i<60;i++)
 {
 signal(i, handler);
 }
 for(;;){
 time_t tim;
 time(&tim);
 fprintf(stderr, "Time is %s\n", ctime(&tim));
 sleep(1);
 };
 }

Compiling this and running it in a console on the Z will clearly show timestamps ticking away every second until the shutdown. Upon resume (some time later) the signal will be received and the time logged along with the signal number (18), the normal loop now continues. The timestamp logged alongside the SIGCONT clearly shows that the signal was received immediately upon resume.


Suspend/Resume Architecture

Author: Colin Pinkney (a.k.a. tumnus)

I created a simple architecture that allows you to easily specify any number of arbitrary scripts/commands to run when you suspend or resume your Zaurus. It is loosely based on the Linux Init System and was also inspired by SafeBoot.

To get it, simply download and install the ipk from here: http://www.cpinkney.org.uk/zaurus.html#susp-resume

Once installed you will get the following directories:

/etc/apm.d
/etc/apm.d/suspend.d
/etc/apm.d/resume.d

Any executable commands in or linked from /etc/apm.d/suspend.d/ that have the filename format Snnxxxx (e.g. S20Today) will be run in order (a la Init System) with the argument 'suspend' when you suspend your Zaurus.

Any executable commands in or linked from /etc/apm.d/resume.d/ that have the filename format Rnnxxxx (e.g. R50Today) will be run in order with the argument 'resume' when you resume your Zaurus.

Examples of suspend/resume applications can be found on the page linked above.

The suspend part also has a timeout feature so that if the suspend commands take longer than a predefined number of seconds then the suspend scripts are killed off and your Zaurus is allowed to suspend normally. This is so you do not get into a state where your Zaurus will not suspend. Because of this, it is best to give the critical and stable suspend commands lower filenames to ensure they are run first. The timeout value is located in the script /usr/local/bin/susp.sh and is 20 seconds by default.

Personal tools