author | sandman <sandman> | 2002-07-01 21:28:44 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-07-01 21:28:44 (UTC) |
commit | cce43bef3e68b007f027f52328972b6b86af1098 (patch) (unidiff) | |
tree | 1bd915e0c5901f1b47e0bd66d696828413eaf0ce /core | |
parent | 3c6fd2159f4ff609408a2b5c645ee5a454d01325 (diff) | |
download | opie-cce43bef3e68b007f027f52328972b6b86af1098.zip opie-cce43bef3e68b007f027f52328972b6b86af1098.tar.gz opie-cce43bef3e68b007f027f52328972b6b86af1098.tar.bz2 |
Fixed a race. Kernel could send iPAQ sleeping while opiealarm had not yet
set the RTC alarm.
-rw-r--r-- | core/opiealarm/opiealarm.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/core/opiealarm/opiealarm.c b/core/opiealarm/opiealarm.c index ce0103e..d96ffaf 100644 --- a/core/opiealarm/opiealarm.c +++ b/core/opiealarm/opiealarm.c | |||
@@ -45,2 +45,4 @@ static int opiealarm_was_running; | |||
45 | 45 | ||
46 | static pid_t startpid = 0; | ||
47 | |||
46 | 48 | ||
@@ -60,2 +62,5 @@ void error_msg_and_die ( int perr, const char *msg ) | |||
60 | 62 | ||
63 | if ( getpid ( ) != startpid ) | ||
64 | kill ( startpid, SIGUSR1 ); | ||
65 | |||
61 | while ( 1 ) // pretend we are waiting on RTC, so opiealarm -r can kill us | 66 | while ( 1 ) // pretend we are waiting on RTC, so opiealarm -r can kill us |
@@ -67,4 +72,6 @@ void sig_handler ( int sig ) | |||
67 | { | 72 | { |
73 | if ( log ) { | ||
68 | log_msg ( "GOT SIGNAL -> EXITING\n" ); | 74 | log_msg ( "GOT SIGNAL -> EXITING\n" ); |
69 | fclose ( log ); | 75 | fclose ( log ); |
76 | } | ||
70 | remove_pidfile ( ); | 77 | remove_pidfile ( ); |
@@ -73,2 +80,7 @@ void sig_handler ( int sig ) | |||
73 | 80 | ||
81 | void sig_handler_parent ( int sig ) | ||
82 | { | ||
83 | exit ( 0 ); | ||
84 | } | ||
85 | |||
74 | void usage ( void ) | 86 | void usage ( void ) |
@@ -90,4 +102,8 @@ int fork_with_pidfile ( void ) | |||
90 | 102 | ||
91 | if ( pid > 0 ) | 103 | if ( pid > 0 ) { |
104 | signal ( SIGUSR1, sig_handler_parent ); | ||
105 | while ( 1 ) | ||
106 | sleep ( 1000 ); | ||
92 | exit ( 0 ); | 107 | exit ( 0 ); |
108 | } | ||
93 | else if ( pid < 0 ) { | 109 | else if ( pid < 0 ) { |
@@ -182,2 +198,3 @@ int main ( int argc, char **argv ) | |||
182 | // kill running opiealarm | 198 | // kill running opiealarm |
199 | startpid = getpid ( ); | ||
183 | opiealarm_was_running = kill_with_pidfile ( ); | 200 | opiealarm_was_running = kill_with_pidfile ( ); |
@@ -194,2 +211,3 @@ int main ( int argc, char **argv ) | |||
194 | 211 | ||
212 | |||
195 | int suspend ( int fix_rtc ) | 213 | int suspend ( int fix_rtc ) |
@@ -211,3 +229,2 @@ int suspend ( int fix_rtc ) | |||
211 | 229 | ||
212 | |||
213 | if (!( fp = fopen ( "/etc/resumeat", "r" ))) | 230 | if (!( fp = fopen ( "/etc/resumeat", "r" ))) |
@@ -225,4 +242,4 @@ int suspend ( int fix_rtc ) | |||
225 | 242 | ||
226 | /* subtract 5 sec from event time... */ | 243 | alrt -= 5; // wake up 5 sec before the specified time |
227 | alrt -= 5; | 244 | |
228 | 245 | ||
@@ -276,3 +293,5 @@ int suspend ( int fix_rtc ) | |||
276 | 293 | ||
277 | log_msg ( "SLEEPING\n" ); | 294 | if ( log ) |
295 | fprintf( log, "SIGUSR: pid %d - SLEEPING: pid %d\n", startpid, getpid ( )); | ||
296 | kill ( startpid, SIGUSR1 ); | ||
278 | 297 | ||
@@ -328,2 +347,3 @@ int resume ( int resuspend ) | |||
328 | return 4; | 347 | return 4; |
348 | kill ( startpid, SIGUSR1 ); | ||
329 | 349 | ||