-rw-r--r-- | core/opiealarm/Makefile | 4 | ||||
-rw-r--r-- | core/opiealarm/config.in | 2 | ||||
-rw-r--r-- | core/opiealarm/opiealarm.c | 7 |
3 files changed, 5 insertions, 8 deletions
diff --git a/core/opiealarm/Makefile b/core/opiealarm/Makefile index 0c8467e..255083d 100644 --- a/core/opiealarm/Makefile +++ b/core/opiealarm/Makefile | |||
@@ -11,16 +11,12 @@ LDFLAGS:= | |||
11 | 11 | ||
12 | all: $(DESTDIR)/opiealarm | 12 | all: $(DESTDIR)/opiealarm |
13 | 13 | ||
14 | $(DESTDIR)/opiealarm: opiealarm.c | 14 | $(DESTDIR)/opiealarm: opiealarm.c |
15 | $(CC) $(CFLAGS) opiealarm.c -o $(DESTDIR)/opiealarm $(LDFLAGS) | 15 | $(CC) $(CFLAGS) opiealarm.c -o $(DESTDIR)/opiealarm $(LDFLAGS) |
16 | $(STRIP) --strip-all $(DESTDIR)/opiealarm | 16 | $(STRIP) --strip-all $(DESTDIR)/opiealarm |
17 | chmod u+s $(DESTDIR)/opiealarm | 17 | chmod u+s $(DESTDIR)/opiealarm |
18 | chown root $(DESTDIR)/opiealarm 2>/dev/null || echo -e "\nopiealarm must be owned by root to work correctly.\n" | 18 | chown root $(DESTDIR)/opiealarm 2>/dev/null || echo -e "\nopiealarm must be owned by root to work correctly.\n" |
19 | 19 | ||
20 | clean: | 20 | clean: |
21 | -rm -f *~ core | 21 | -rm -f *~ core |
22 | 22 | ||
23 | install: | ||
24 | cp $(DESTDIR)/opiealarm $(INSTALL_ROOT)/opt/QtPalmtop/bin | ||
25 | chown root $(INSTALL_ROOT)/opt/QtPalmtop/bin/opiealarm | ||
26 | chmod u+s $(INSTALL_ROOT)/opt/QtPalmtop/bin/opiealarm 2>/dev/null || echo -e "\nopiealarm must be owned by root to work correctly.\n" | ||
diff --git a/core/opiealarm/config.in b/core/opiealarm/config.in index 2be9bd4..f86d01c 100644 --- a/core/opiealarm/config.in +++ b/core/opiealarm/config.in | |||
@@ -1,4 +1,4 @@ | |||
1 | config OPIEALARM | 1 | config OPIEALARM |
2 | boolean "opie-opiealarm (Alarm daemon, sets RTC with wakeup time on suspend)" | 2 | boolean "Opiealarm (Alarm daemon, sets RTC with wakeup time on suspend)" |
3 | depends ! TARGET_X86 | 3 | depends ! TARGET_X86 |
4 | default "y" | 4 | default "y" |
diff --git a/core/opiealarm/opiealarm.c b/core/opiealarm/opiealarm.c index 998cabd..90a743f 100644 --- a/core/opiealarm/opiealarm.c +++ b/core/opiealarm/opiealarm.c | |||
@@ -84,24 +84,25 @@ int fork_with_pidfile ( void ) | |||
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 | //sleep( 60 ); | ||
96 | 97 | ||
97 | // child process needs to react to SIGUSR2. This is sent when | 98 | // child process needs to react to SIGUSR2. This is sent when |
98 | // a new opiealarm process is started. | 99 | // a new opiealarm process is started. |
99 | 100 | ||
100 | signal ( SIGUSR2, sig_handler_child ); | 101 | signal ( SIGUSR2, sig_handler_child ); |
101 | 102 | ||
102 | // save pid | 103 | // save pid |
103 | if (( fp = fopen ( PIDFILE, "w" ))) { | 104 | if (( fp = fopen ( PIDFILE, "w" ))) { |
104 | fprintf ( fp, "%d", getpid ( )); | 105 | fprintf ( fp, "%d", getpid ( )); |
105 | fclose ( fp ); | 106 | fclose ( fp ); |
106 | 107 | ||
107 | // detach | 108 | // detach |
@@ -197,25 +198,25 @@ int main ( int argc, char **argv ) | |||
197 | case 's': | 198 | case 's': |
198 | default : opt = suspend ( fix_rtc ); | 199 | default : opt = suspend ( fix_rtc ); |
199 | break; | 200 | break; |
200 | } | 201 | } |
201 | 202 | ||
202 | parent_pid = 0; | 203 | parent_pid = 0; |
203 | return opt; | 204 | return opt; |
204 | } | 205 | } |
205 | 206 | ||
206 | 207 | ||
207 | int suspend ( int fix_rtc ) | 208 | int suspend ( int fix_rtc ) |
208 | { | 209 | { |
209 | FILE *fp; | 210 | FILE *fp = NULL; |
210 | char buf [64]; | 211 | char buf [64]; |
211 | time_t alrt, syst, rtct; | 212 | time_t alrt, syst, rtct; |
212 | struct tm alr, sys, rtc; | 213 | struct tm alr, sys, rtc; |
213 | int fd; | 214 | int fd; |
214 | int rtc_sys_diff; | 215 | int rtc_sys_diff; |
215 | 216 | ||
216 | 217 | ||
217 | if ( !fork_with_pidfile ( )) | 218 | if ( !fork_with_pidfile ( )) |
218 | return 3; | 219 | return 3; |
219 | 220 | ||
220 | // we are the child process from here on ... | 221 | // we are the child process from here on ... |
221 | 222 | ||
@@ -249,25 +250,25 @@ int suspend ( int fix_rtc ) | |||
249 | if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) | 250 | if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) |
250 | break; // ( 1, "ioctl RTC_SET_TIME" ); | 251 | break; // ( 1, "ioctl RTC_SET_TIME" ); |
251 | } | 252 | } |
252 | 253 | ||
253 | // read the wakeup time from TIMEFILE | 254 | // read the wakeup time from TIMEFILE |
254 | if (!( fp = fopen ( TIMEFILE, "r" ))) | 255 | if (!( fp = fopen ( TIMEFILE, "r" ))) |
255 | break; // ( 1, TIMEFILE ); | 256 | break; // ( 1, TIMEFILE ); |
256 | 257 | ||
257 | if ( !fgets ( buf, sizeof( buf ) - 1, fp )) | 258 | if ( !fgets ( buf, sizeof( buf ) - 1, fp )) |
258 | break; // ( 1, TIMEFILE ); | 259 | break; // ( 1, TIMEFILE ); |
259 | 260 | ||
260 | fclose ( fp ); | 261 | fclose ( fp ); |
261 | fp = 0; | 262 | fp = NULL; |
262 | 263 | ||
263 | alrt = atoi ( buf ); // get the alarm time | 264 | alrt = atoi ( buf ); // get the alarm time |
264 | 265 | ||
265 | if ( alrt == 0 ) | 266 | if ( alrt == 0 ) |
266 | break; // ( 0, TIMEFILE " contains an invalid time description" ); | 267 | break; // ( 0, TIMEFILE " contains an invalid time description" ); |
267 | alrt -= 5; // wake up 5 sec before the specified time | 268 | alrt -= 5; // wake up 5 sec before the specified time |
268 | 269 | ||
269 | alr = *gmtime ( &alrt ); | 270 | alr = *gmtime ( &alrt ); |
270 | 271 | ||
271 | if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) // set RTC alarm time | 272 | if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) // set RTC alarm time |
272 | break; // ( 1, "ioctl RTC_ALM_SET" ); | 273 | break; // ( 1, "ioctl RTC_ALM_SET" ); |
273 | 274 | ||
@@ -362,22 +363,22 @@ int resume ( int resuspend ) | |||
362 | argv[3] = 0; | 363 | argv[3] = 0; |
363 | 364 | ||
364 | // hard coded for now ...but needed | 365 | // hard coded for now ...but needed |
365 | // another way would be to simulate a power-button press | 366 | // another way would be to simulate a power-button press |
366 | 367 | ||
367 | setenv ( "LOGNAME", "root", 1 ); | 368 | setenv ( "LOGNAME", "root", 1 ); |
368 | setenv ( "HOME", "/root", 1 ); | 369 | setenv ( "HOME", "/root", 1 ); |
369 | setenv ( "LD_LIBRARY_PATH", "/opt/QtPalmtop/lib", 1 ); | 370 | setenv ( "LD_LIBRARY_PATH", "/opt/QtPalmtop/lib", 1 ); |
370 | setenv ( "QTDIR", "/opt/QtPalmtop", 1 ); | 371 | setenv ( "QTDIR", "/opt/QtPalmtop", 1 ); |
371 | 372 | ||
372 | remove_pidfile ( ); | 373 | remove_pidfile ( ); |
373 | 374 | ||
374 | // no need for system() since this process is no longer usefull anyway | 375 | // no need for system() since this process is no longer usefull anyway |
375 | execv ( "/opt/QtPalmtop/bin/qcop", argv ); | 376 | execv ( "/opt/QtPalmtop/bin/qcop", argv ); |
376 | 377 | ||
377 | perror ( "exec for qcop failed" ); | 378 | perror ( "exec for qcop failed" ); |
378 | return 5; | 379 | return 5; |
379 | } | 380 | } |
380 | } | 381 | } |
381 | } | 382 | } |
382 | return 0; | 383 | return 0; |
383 | } | 384 | } |