summaryrefslogtreecommitdiff
authorsandman <sandman>2002-06-18 14:11:42 (UTC)
committer sandman <sandman>2002-06-18 14:11:42 (UTC)
commit5538834e726c3b5d3ba7998c56845ea652d184dd (patch) (unidiff)
treef2c78c7116b2d695cd9c939f39f38c1a59506a17
parent99cf287037a0d9f99e4fc035d1b9f6db08bb6583 (diff)
downloadopie-5538834e726c3b5d3ba7998c56845ea652d184dd.zip
opie-5538834e726c3b5d3ba7998c56845ea652d184dd.tar.gz
opie-5538834e726c3b5d3ba7998c56845ea652d184dd.tar.bz2
Fix a compiler warning
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opiealarm/opiealarm.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/opiealarm/opiealarm.c b/core/opiealarm/opiealarm.c
index 128929e..a4d46ed 100644
--- a/core/opiealarm/opiealarm.c
+++ b/core/opiealarm/opiealarm.c
@@ -194,157 +194,157 @@ int main ( int argc, char **argv )
194 194
195int suspend ( int fix_rtc ) 195int suspend ( int fix_rtc )
196{ 196{
197 FILE *fp; 197 FILE *fp;
198 char buf [64]; 198 char buf [64];
199 time_t alrt, syst, rtct; 199 time_t alrt, syst, rtct;
200 struct tm alr, sys, rtc; 200 struct tm alr, sys, rtc;
201 int fd; 201 int fd;
202 int rtc_sys_diff; 202 int rtc_sys_diff;
203 203
204 204
205 if ( !fork_with_pidfile ( )) 205 if ( !fork_with_pidfile ( ))
206 return 3; 206 return 3;
207 207
208 log = fopen ( "/tmp/opiealarm.log", "w" ); 208 log = fopen ( "/tmp/opiealarm.log", "w" );
209 log_msg ( "STARTING\n" ); 209 log_msg ( "STARTING\n" );
210 210
211 211
212 212
213 if (!( fp = fopen ( "/etc/resumeat", "r" ))) 213 if (!( fp = fopen ( "/etc/resumeat", "r" )))
214 error_msg_and_die ( 1, "/etc/resumeat" ); 214 error_msg_and_die ( 1, "/etc/resumeat" );
215 215
216 if ( !fgets ( buf, sizeof( buf ) - 1, fp )) 216 if ( !fgets ( buf, sizeof( buf ) - 1, fp ))
217 error_msg_and_die ( 1, "/etc/resumeat" ); 217 error_msg_and_die ( 1, "/etc/resumeat" );
218 218
219 fclose ( fp ); 219 fclose ( fp );
220 220
221 alrt = atoi ( buf ); 221 alrt = atoi ( buf );
222 222
223 if ( alrt == 0 ) 223 if ( alrt == 0 )
224 error_msg_and_die ( 0, "/etc/resumeat contains an invalid time description" ); 224 error_msg_and_die ( 0, "/etc/resumeat contains an invalid time description" );
225 225
226 /* subtract 5 sec from event time... */ 226 /* subtract 5 sec from event time... */
227 alrt -= 5; 227 alrt -= 5;
228 228
229 if ( log ) 229 if ( log )
230 fprintf ( log, "Setting RTC alarm to %d\n", alrt ); 230 fprintf ( log, "Setting RTC alarm to %d\n", alrt );
231 231
232 alr = *gmtime ( &alrt ); 232 alr = *gmtime ( &alrt );
233 233
234 // get system time 234 // get system time
235 time ( &syst ); 235 time ( &syst );
236 sys = *localtime ( &syst ); 236 sys = *localtime ( &syst );
237 237
238 // Write alarm time to RTC 238 // Write alarm time to RTC
239 if (( fd = open ( "/dev/misc/rtc", O_RDWR )) < 0 ) 239 if (( fd = open ( "/dev/misc/rtc", O_RDWR )) < 0 )
240 error_msg_and_die ( 1, "/dev/misc/rtc" ); 240 error_msg_and_die ( 1, "/dev/misc/rtc" );
241 241
242 // get RTC time 242 // get RTC time
243 if ( ioctl ( fd, RTC_ALM_SET, &rtc ) < 0 ) 243 if ( ioctl ( fd, RTC_ALM_SET, &rtc ) < 0 )
244 error_msg_and_die ( 1, "ioctl RTC_RD_TIME" ); 244 error_msg_and_die ( 1, "ioctl RTC_RD_TIME" );
245 rtct = mktime ( &rtc ); 245 rtct = mktime ( &rtc );
246 246
247 rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff; 247 rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff;
248 248
249 if ( fix_rtc && (( rtc_sys_diff < -4 ) || ( rtc_sys_diff > 4 ))) { 249 if ( fix_rtc && (( rtc_sys_diff < -4 ) || ( rtc_sys_diff > 4 ))) {
250 struct tm set; 250 struct tm set;
251 251
252 set = *gmtime ( &syst ); 252 set = *gmtime ( &syst );
253 253
254 fprintf ( log, "Correcting RTC: %d seconds\n", rtc_sys_diff ); 254 fprintf ( log, "Correcting RTC: %d seconds\n", rtc_sys_diff );
255 255
256 if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) 256 if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 )
257 error_msg_and_die ( 1, "ioctl RTC_SET_TIME" ); 257 error_msg_and_die ( 1, "ioctl RTC_SET_TIME" );
258 } 258 }
259 259
260 // set alarm time 260 // set alarm time
261 if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) 261 if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 )
262 error_msg_and_die ( 1, "ioctl RTC_ALM_SET" ); 262 error_msg_and_die ( 1, "ioctl RTC_ALM_SET" );
263 // enable alarm irq 263 // enable alarm irq
264 if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) 264 if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 )
265 error_msg_and_die ( 1, "ioctl RTC_AIE_ON" ); 265 error_msg_and_die ( 1, "ioctl RTC_AIE_ON" );
266 266
267 log_msg ( "SLEEPING\n" ); 267 log_msg ( "SLEEPING\n" );
268 268
269 // wait for alarm irq 269 // wait for alarm irq
270 if ( read ( fd, buf, sizeof( unsigned long )) < 0 ) 270 if ( read ( fd, buf, sizeof( unsigned long )) < 0 )
271 error_msg_and_die ( 1, "read rtc alarm" ); 271 error_msg_and_die ( 1, "read rtc alarm" );
272 272
273 log_msg ( "WAKEUP\n" ); 273 log_msg ( "WAKEUP\n" );
274 274
275 // disable alarm irq 275 // disable alarm irq
276 if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 ) 276 if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 )
277 error_msg_and_die ( 1, "ioctl RTC_AIE_OFF" ); 277 error_msg_and_die ( 1, "ioctl RTC_AIE_OFF" );
278 278
279 close ( fd ); 279 close ( fd );
280 280
281 log_msg ( "EXITING\n" ); 281 log_msg ( "EXITING\n" );
282 282
283 fclose ( log ); 283 fclose ( log );
284 remove_pidfile ( ); 284 remove_pidfile ( );
285 285
286 return 0; 286 return 0;
287} 287}
288 288
289 289
290static int onac ( void ) 290int onac ( void )
291{ 291{
292 FILE *fp; 292 FILE *fp;
293 int on = 0; 293 int on = 0;
294 294
295 if (( fp = fopen ( APMFILE, "r" ))) { 295 if (( fp = fopen ( APMFILE, "r" ))) {
296 int ac = 0; 296 int ac = 0;
297 297
298 if ( fscanf ( fp, "%*[^ ] %*d.%*d 0x%*x 0x%x 0x%*x 0x%*x %*d%% %*i %*c", &ac ) == 1 ) 298 if ( fscanf ( fp, "%*[^ ] %*d.%*d 0x%*x 0x%x 0x%*x 0x%*x %*d%% %*i %*c", &ac ) == 1 )
299 on = ( ac == 0x01 ) ? 1 : 0; 299 on = ( ac == 0x01 ) ? 1 : 0;
300 300
301 fclose ( fp ); 301 fclose ( fp );
302 } 302 }
303 return on; 303 return on;
304} 304}
305 305
306int resume ( int resuspend ) 306int resume ( int resuspend )
307{ 307{
308 FILE *fp; 308 FILE *fp;
309 309
310 // re-suspend when on AC (optional) when woken up via RTC 310 // re-suspend when on AC (optional) when woken up via RTC
311 311
312 if ( !opiealarm_was_running ) { // opiealarm -s got it's RTC signal -> wake up by RTC 312 if ( !opiealarm_was_running ) { // opiealarm -s got it's RTC signal -> wake up by RTC
313 if ( resuspend && onac ( )) { 313 if ( resuspend && onac ( )) {
314 time_t start, now; 314 time_t start, now;
315 char *argv [4]; 315 char *argv [4];
316 316
317 if ( !fork_with_pidfile ( )) 317 if ( !fork_with_pidfile ( ))
318 return 4; 318 return 4;
319 319
320 // sleep <resuspend> sec (not less!) 320 // sleep <resuspend> sec (not less!)
321 time ( &start ); 321 time ( &start );
322 do { 322 do {
323 sleep ( 1 ); 323 sleep ( 1 );
324 time ( &now ); 324 time ( &now );
325 } while (( now - start ) < resuspend ); 325 } while (( now - start ) < resuspend );
326 326
327 if ( onac ( )) { // still on ac 327 if ( onac ( )) { // still on ac
328 // system() without fork 328 // system() without fork
329 argv[0] = "qcop"; 329 argv[0] = "qcop";
330 argv[1] = "QPE/Desktop"; 330 argv[1] = "QPE/Desktop";
331 argv[2] = "suspend()"; 331 argv[2] = "suspend()";
332 argv[3] = 0; 332 argv[3] = 0;
333 333
334 // hard coded for now ...but needed 334 // hard coded for now ...but needed
335 setenv ( "LOGNAME", "root", 1 ); 335 setenv ( "LOGNAME", "root", 1 );
336 setenv ( "HOME", "/root", 1 ); 336 setenv ( "HOME", "/root", 1 );
337 setenv ( "LD_LIBRARY_PATH", "/opt/QtPalmtop/lib", 1 ); 337 setenv ( "LD_LIBRARY_PATH", "/opt/QtPalmtop/lib", 1 );
338 setenv ( "QTDIR", "/opt/QtPalmtop", 1 ); 338 setenv ( "QTDIR", "/opt/QtPalmtop", 1 );
339 339
340 remove_pidfile ( ); 340 remove_pidfile ( );
341 341
342 execv ( "/opt/QtPalmtop/bin/qcop", argv ); 342 execv ( "/opt/QtPalmtop/bin/qcop", argv );
343 343
344 perror ( "exec for qcop failed" ); 344 perror ( "exec for qcop failed" );
345 return 5; 345 return 5;
346 } 346 }
347 } 347 }
348 } 348 }
349 return 0; 349 return 0;
350} 350}