author | zecke <zecke> | 2003-06-13 10:41:14 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-06-13 10:41:14 (UTC) |
commit | 60ba51b33a060dde352caa678f2e337f5f5590f5 (patch) (unidiff) | |
tree | 29da8884e438bb768f2d0a5f41dbaad62ce7776c | |
parent | 3dd3e5caf9ca85c814442b04485f07da060dc257 (diff) | |
download | opie-60ba51b33a060dde352caa678f2e337f5f5590f5.zip opie-60ba51b33a060dde352caa678f2e337f5f5590f5.tar.gz opie-60ba51b33a060dde352caa678f2e337f5f5590f5.tar.bz2 |
fix here as well
-rw-r--r-- | core/opiealarm/opiealarm.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/core/opiealarm/opiealarm.c b/core/opiealarm/opiealarm.c index 072dca7..465e633 100644 --- a/core/opiealarm/opiealarm.c +++ b/core/opiealarm/opiealarm.c | |||
@@ -71,49 +71,49 @@ void usage ( void ) | |||
71 | exit ( 1 ); | 71 | exit ( 1 ); |
72 | } | 72 | } |
73 | 73 | ||
74 | int fork_with_pidfile ( void ) | 74 | int fork_with_pidfile ( void ) |
75 | { | 75 | { |
76 | FILE *fp; | 76 | FILE *fp; |
77 | pid_t pid; | 77 | pid_t pid; |
78 | 78 | ||
79 | pid = fork ( ); | 79 | pid = fork ( ); |
80 | 80 | ||
81 | if ( pid > 0 ) { | 81 | if ( pid > 0 ) { |
82 | // We can not just exit now, because the kernel could suspend | 82 | // We can not just exit now, because the kernel could suspend |
83 | // the iPAQ just before the child process sets the RTC. | 83 | // the iPAQ just before the child process sets the RTC. |
84 | // Solution: just wait for SIGUSR1 - the child process will | 84 | // Solution: just wait for SIGUSR1 - the child process will |
85 | // signal this when it thinks it is safe to exit. | 85 | // signal this when it thinks it is safe to exit. |
86 | 86 | ||
87 | signal ( SIGUSR1, sig_handler_parent ); | 87 | signal ( SIGUSR1, sig_handler_parent ); |
88 | while ( 1 ) | 88 | while ( 1 ) |
89 | sleep ( 1000 ); | 89 | sleep ( 1000 ); |
90 | exit ( 0 ); | 90 | exit ( 0 ); |
91 | } | 91 | } |
92 | else if ( pid < 0 ) { | 92 | else if ( pid < 0 ) { |
93 | perror ( "forking failed" ); | 93 | perror ( "forking failed" ); |
94 | return 0; | 94 | return 0; |
95 | } | 95 | } |
96 | 96 | ||
97 | // child process needs to react to SIGUSR2. This is sent when | 97 | // child process needs to react to SIGUSR2. This is sent when |
98 | // a new opiealarm process is started. | 98 | // a new opiealarm process is started. |
99 | 99 | ||
100 | signal ( SIGUSR2, sig_handler_child ); | 100 | signal ( SIGUSR2, sig_handler_child ); |
101 | 101 | ||
102 | // save pid | 102 | // save pid |
103 | if (( fp = fopen ( PIDFILE, "w" ))) { | 103 | if (( fp = fopen ( PIDFILE, "w" ))) { |
104 | fprintf ( fp, "%d", getpid ( )); | 104 | fprintf ( fp, "%d", getpid ( )); |
105 | fclose ( fp ); | 105 | fclose ( fp ); |
106 | 106 | ||
107 | // detach | 107 | // detach |
108 | close ( 0 ); | 108 | close ( 0 ); |
109 | close ( 1 ); | 109 | close ( 1 ); |
110 | close ( 2 ); | 110 | close ( 2 ); |
111 | 111 | ||
112 | setpgid ( 0, 0 ); | 112 | setpgid ( 0, 0 ); |
113 | 113 | ||
114 | return 1; | 114 | return 1; |
115 | } | 115 | } |
116 | else { | 116 | else { |
117 | perror ( PIDFILE ); | 117 | perror ( PIDFILE ); |
118 | return 0; | 118 | return 0; |
119 | } | 119 | } |
@@ -237,76 +237,78 @@ int suspend ( int fix_rtc ) | |||
237 | 237 | ||
238 | rtct = mktime ( &rtc ); | 238 | rtct = mktime ( &rtc ); |
239 | 239 | ||
240 | 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 |
241 | 241 | ||
242 | if ( fix_rtc && (( rtc_sys_diff < -3 ) || ( rtc_sys_diff > 3 ))) { | 242 | if ( fix_rtc && (( rtc_sys_diff < -3 ) || ( rtc_sys_diff > 3 ))) { |
243 | struct tm set; | 243 | struct tm set; |
244 | set = *gmtime ( &syst ); | 244 | set = *gmtime ( &syst ); |
245 | 245 | ||
246 | // 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, |
247 | // 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. |
248 | 248 | ||
249 | if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) | 249 | if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) |
250 | break; // ( 1, "ioctl RTC_SET_TIME" ); | 250 | break; // ( 1, "ioctl RTC_SET_TIME" ); |
251 | } | 251 | } |
252 | 252 | ||
253 | // read the wakeup time from TIMEFILE | 253 | // read the wakeup time from TIMEFILE |
254 | if (!( fp = fopen ( TIMEFILE, "r" ))) | 254 | if (!( fp = fopen ( TIMEFILE, "r" ))) |
255 | break; // ( 1, TIMEFILE ); | 255 | break; // ( 1, TIMEFILE ); |
256 | 256 | ||
257 | if ( !fgets ( buf, sizeof( buf ) - 1, fp )) | 257 | if ( !fgets ( buf, sizeof( buf ) - 1, fp )) |
258 | break; // ( 1, TIMEFILE ); | 258 | break; // ( 1, TIMEFILE ); |
259 | 259 | ||
260 | fclose ( fp ); | 260 | fclose ( fp ); |
261 | fp = 0; | ||
261 | 262 | ||
262 | alrt = atoi ( buf ); // get the alarm time | 263 | alrt = atoi ( buf ); // get the alarm time |
263 | 264 | ||
264 | if ( alrt == 0 ) | 265 | if ( alrt == 0 ) |
265 | break; // ( 0, TIMEFILE " contains an invalid time description" ); | 266 | break; // ( 0, TIMEFILE " contains an invalid time description" ); |
266 | alrt -= 5; // wake up 5 sec before the specified time | 267 | alrt -= 5; // wake up 5 sec before the specified time |
267 | 268 | ||
268 | alr = *gmtime ( &alrt ); | 269 | alr = *gmtime ( &alrt ); |
269 | 270 | ||
270 | if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) // set RTC alarm time | 271 | if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) // set RTC alarm time |
271 | break; // ( 1, "ioctl RTC_ALM_SET" ); | 272 | break; // ( 1, "ioctl RTC_ALM_SET" ); |
272 | 273 | ||
273 | if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) | 274 | if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) |
274 | break; // ( 1, "ioctl RTC_AIE_ON" ); // enable RTC alarm irq | 275 | break; // ( 1, "ioctl RTC_AIE_ON" ); // enable RTC alarm irq |
275 | 276 | ||
276 | // tell the parent it is safe to exit now .. we have set the RTC alarm | 277 | // tell the parent it is safe to exit now .. we have set the RTC alarm |
277 | kill ( parent_pid, SIGUSR1 ); | 278 | kill ( parent_pid, SIGUSR1 ); |
278 | 279 | ||
279 | if ( read ( fd, buf, sizeof( unsigned long )) < 0 ) // wait for the RTC alarm irq | 280 | if ( read ( fd, buf, sizeof( unsigned long )) < 0 ) // wait for the RTC alarm irq |
280 | break; // ( 1, "read rtc alarm" ); | 281 | break; // ( 1, "read rtc alarm" ); |
281 | 282 | ||
282 | // iPAQ woke up via RTC irq -- otherwise we would have received a SIGUSR2 | 283 | // iPAQ woke up via RTC irq -- otherwise we would have received a SIGUSR2 |
283 | // from the "resume instance" of opiealarm. | 284 | // from the "resume instance" of opiealarm. |
284 | 285 | ||
285 | if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 ) // disable RTC alarm irq | 286 | if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 ) // disable RTC alarm irq |
286 | break; // ( 1, "ioctl RTC_AIE_OFF" ); | 287 | break; // ( 1, "ioctl RTC_AIE_OFF" ); |
287 | 288 | ||
288 | close ( fd ); | 289 | close ( fd ); |
290 | fd = -1; | ||
289 | 291 | ||
290 | remove_pidfile ( ); | 292 | remove_pidfile ( ); |
291 | 293 | ||
292 | return 0; | 294 | return 0; |
293 | 295 | ||
294 | } while ( 0 ); | 296 | } while ( 0 ); |
295 | 297 | ||
296 | if ( fp != NULL ) | 298 | if ( fp != NULL ) |
297 | fclose ( fp ); | 299 | fclose ( fp ); |
298 | 300 | ||
299 | if ( fd != -1 ) | 301 | if ( fd != -1 ) |
300 | close ( fd ); | 302 | close ( fd ); |
301 | 303 | ||
302 | kill ( parent_pid, SIGUSR1 ); | 304 | kill ( parent_pid, SIGUSR1 ); |
303 | 305 | ||
304 | while ( 1 ) // pretend that we are waiting on RTC, so opiealarm -r can kill us | 306 | while ( 1 ) // pretend that we are waiting on RTC, so opiealarm -r can kill us |
305 | sleep ( 1000 ); // if we don't do this, the "resuspend on AC" would be triggerd | 307 | sleep ( 1000 ); // if we don't do this, the "resuspend on AC" would be triggerd |
306 | return 0; | 308 | return 0; |
307 | } | 309 | } |
308 | 310 | ||
309 | int onac ( void ) | 311 | int onac ( void ) |
310 | { | 312 | { |
311 | FILE *fp; | 313 | FILE *fp; |
312 | int on = 0; | 314 | int on = 0; |