summaryrefslogtreecommitdiff
authorsandman <sandman>2002-12-10 22:21:58 (UTC)
committer sandman <sandman>2002-12-10 22:21:58 (UTC)
commit887fb36c5344574f04d19c7442f3db899920e04d (patch) (unidiff)
tree3a1ccbdb5489bf628979a2b712a779ae009383dc
parent2173e57fcbd5d460fceb34a111845389dca56506 (diff)
downloadopie-887fb36c5344574f04d19c7442f3db899920e04d.zip
opie-887fb36c5344574f04d19c7442f3db899920e04d.tar.gz
opie-887fb36c5344574f04d19c7442f3db899920e04d.tar.bz2
/etc/resumeat is now in /var/run/resumeat
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opiealarm/opiealarm.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/core/opiealarm/opiealarm.c b/core/opiealarm/opiealarm.c
index 5ea24b7..072dca7 100644
--- a/core/opiealarm/opiealarm.c
+++ b/core/opiealarm/opiealarm.c
@@ -17,24 +17,25 @@
17#include <fcntl.h> 17#include <fcntl.h>
18#include <unistd.h> 18#include <unistd.h>
19#include <errno.h> 19#include <errno.h>
20#include <time.h> 20#include <time.h>
21#include <stdlib.h> 21#include <stdlib.h>
22#include <syslog.h> 22#include <syslog.h>
23#include <signal.h> 23#include <signal.h>
24#include <errno.h> 24#include <errno.h>
25#include <string.h> 25#include <string.h>
26 26
27 27
28 #define PIDFILE "/var/run/opiealarm.pid" 28 #define PIDFILE "/var/run/opiealarm.pid"
29#define TIMEFILE "/var/run/resumeat"
29 #define APMFILE "/proc/apm" 30 #define APMFILE "/proc/apm"
30 31
31int resume ( int resuspend ); 32int resume ( int resuspend );
32int suspend ( int fix_rtc ); 33int suspend ( int fix_rtc );
33int main ( int argc, char **argv ); 34int main ( int argc, char **argv );
34int fork_with_pidfile ( void ); 35int fork_with_pidfile ( void );
35int kill_with_pidfile ( void ); 36int kill_with_pidfile ( void );
36void remove_pidfile ( void ); 37void remove_pidfile ( void );
37void usage ( void ); 38void usage ( void );
38void sig_handler_child ( int sig ); 39void sig_handler_child ( int sig );
39void sig_handler_parent ( int sig ); 40void sig_handler_parent ( int sig );
40int onac ( void ); 41int onac ( void );
@@ -236,41 +237,41 @@ int suspend ( int fix_rtc )
236 237
237 rtct = mktime ( &rtc ); 238 rtct = mktime ( &rtc );
238 239
239 rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff; // calculate the difference between system and hardware time 240 rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff; // calculate the difference between system and hardware time
240 241
241 if ( fix_rtc && (( rtc_sys_diff < -3 ) || ( rtc_sys_diff > 3 ))) { 242 if ( fix_rtc && (( rtc_sys_diff < -3 ) || ( rtc_sys_diff > 3 ))) {
242 struct tm set; 243 struct tm set;
243 set = *gmtime ( &syst ); 244 set = *gmtime ( &syst );
244 245
245 // if the difference between system and hardware time is more than 3 seconds, 246 // if the difference between system and hardware time is more than 3 seconds,
246 // we have to set the RTC (hwclock --systohc), or alarms won't work reliably. 247 // we have to set the RTC (hwclock --systohc), or alarms won't work reliably.
247 248
248 if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) 249 if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 )
249 break; // ( 1, "ioctl RTC_SET_TIME" ); 250 break; // ( 1, "ioctl RTC_SET_TIME" );
250 } 251 }
251 252
252 // read the wakeup time from /etc/resumeat 253 // read the wakeup time from TIMEFILE
253 if (!( fp = fopen ( "/etc/resumeat", "r" ))) 254 if (!( fp = fopen ( TIMEFILE, "r" )))
254 break; // ( 1, "/etc/resumeat" ); 255 break; // ( 1, TIMEFILE );
255 256
256 if ( !fgets ( buf, sizeof( buf ) - 1, fp )) 257 if ( !fgets ( buf, sizeof( buf ) - 1, fp ))
257 break; // ( 1, "/etc/resumeat" ); 258 break; // ( 1, TIMEFILE );
258 259
259 fclose ( fp ); 260 fclose ( fp );
260 261
261 alrt = atoi ( buf ); // get the alarm time 262 alrt = atoi ( buf ); // get the alarm time
262 263
263 if ( alrt == 0 ) 264 if ( alrt == 0 )
264 break; // ( 0, "/etc/resumeat contains an invalid time description" ); 265 break; // ( 0, TIMEFILE " contains an invalid time description" );
265 alrt -= 5; // wake up 5 sec before the specified time 266 alrt -= 5; // wake up 5 sec before the specified time
266 267
267 alr = *gmtime ( &alrt ); 268 alr = *gmtime ( &alrt );
268 269
269 if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) // set RTC alarm time 270 if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) // set RTC alarm time
270 break; // ( 1, "ioctl RTC_ALM_SET" ); 271 break; // ( 1, "ioctl RTC_ALM_SET" );
271 272
272 if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) 273 if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 )
273 break; // ( 1, "ioctl RTC_AIE_ON" ); // enable RTC alarm irq 274 break; // ( 1, "ioctl RTC_AIE_ON" ); // enable RTC alarm irq
274 275
275 // tell the parent it is safe to exit now .. we have set the RTC alarm 276 // tell the parent it is safe to exit now .. we have set the RTC alarm
276 kill ( parent_pid, SIGUSR1 ); 277 kill ( parent_pid, SIGUSR1 );
@@ -281,25 +282,25 @@ int suspend ( int fix_rtc )
281 // iPAQ woke up via RTC irq -- otherwise we would have received a SIGUSR2 282 // iPAQ woke up via RTC irq -- otherwise we would have received a SIGUSR2
282 // from the "resume instance" of opiealarm. 283 // from the "resume instance" of opiealarm.
283 284
284 if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 ) // disable RTC alarm irq 285 if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 ) // disable RTC alarm irq
285 break; // ( 1, "ioctl RTC_AIE_OFF" ); 286 break; // ( 1, "ioctl RTC_AIE_OFF" );
286 287
287 close ( fd ); 288 close ( fd );
288 289
289 remove_pidfile ( ); 290 remove_pidfile ( );
290 291
291 return 0; 292 return 0;
292 293
293 } while ( 0 ) 294 } while ( 0 );
294 295
295 if ( fp != NULL ) 296 if ( fp != NULL )
296 fclose ( fp ); 297 fclose ( fp );
297 298
298 if ( fd != -1 ) 299 if ( fd != -1 )
299 close ( fd ); 300 close ( fd );
300 301
301 kill ( parent_pid, SIGUSR1 ); 302 kill ( parent_pid, SIGUSR1 );
302 303
303 while ( 1 ) // pretend that we are waiting on RTC, so opiealarm -r can kill us 304 while ( 1 ) // pretend that we are waiting on RTC, so opiealarm -r can kill us
304 sleep ( 1000 ); // if we don't do this, the "resuspend on AC" would be triggerd 305 sleep ( 1000 ); // if we don't do this, the "resuspend on AC" would be triggerd
305 return 0; 306 return 0;