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.