-rw-r--r-- | core/opiealarm/Makefile | 2 | ||||
-rw-r--r-- | core/opiealarm/opiealarm.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/core/opiealarm/Makefile b/core/opiealarm/Makefile index e988abf..f20d451 100644 --- a/core/opiealarm/Makefile +++ b/core/opiealarm/Makefile | |||
@@ -1,26 +1,26 @@ | |||
1 | 1 | ||
2 | DESTDIR=../../bin | 2 | DESTDIR=../../bin |
3 | 3 | ||
4 | CROSS:=arm-linux- | 4 | CROSS:=arm-linux- |
5 | CC :=$(CROSS)gcc | 5 | CC :=$(CROSS)gcc |
6 | LD :=$(CROSS)gcc | 6 | LD :=$(CROSS)gcc |
7 | STRIP:=$(CROSS)strip | 7 | STRIP:=$(CROSS)strip |
8 | 8 | ||
9 | CFLAGS:=-O2 | 9 | CFLAGS:=-O2 |
10 | LDFLAGS:= | 10 | LDFLAGS:= |
11 | 11 | ||
12 | all: $(DESTDIR)/opiealarm $(DESTDIR)/opieatd | 12 | all: $(DESTDIR)/opiealarm $(DESTDIR)/opieatd |
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) -s $(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 | $(DESTDIR)/opieatd: opieatd | 20 | $(DESTDIR)/opieatd: opieatd |
21 | cp opieatd $(DESTDIR)/opieatd | 21 | cp opieatd $(DESTDIR)/opieatd |
22 | chmod +x $(DESTDIR)/opieatd | 22 | chmod +x $(DESTDIR)/opieatd |
23 | 23 | ||
24 | clean: | 24 | clean: |
25 | -rm -f *~ core | 25 | -rm -f *~ core |
26 | 26 | ||
diff --git a/core/opiealarm/opiealarm.c b/core/opiealarm/opiealarm.c index 71367b3..ce0103e 100644 --- a/core/opiealarm/opiealarm.c +++ b/core/opiealarm/opiealarm.c | |||
@@ -198,97 +198,97 @@ int suspend ( int fix_rtc ) | |||
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 | tzset ( ); | 232 | tzset ( ); |
233 | 233 | ||
234 | alr = *gmtime ( &alrt ); | 234 | alr = *gmtime ( &alrt ); |
235 | 235 | ||
236 | // get system time | 236 | // get system time |
237 | time ( &syst ); | 237 | time ( &syst ); |
238 | sys = *localtime ( &syst ); | 238 | sys = *localtime ( &syst ); |
239 | 239 | ||
240 | // Write alarm time to RTC | 240 | // Write alarm time to RTC |
241 | if (( fd = open ( "/dev/misc/rtc", O_RDWR )) < 0 ) | 241 | if (( fd = open ( "/dev/misc/rtc", O_RDWR )) < 0 ) |
242 | error_msg_and_die ( 1, "/dev/misc/rtc" ); | 242 | error_msg_and_die ( 1, "/dev/misc/rtc" ); |
243 | 243 | ||
244 | // get RTC time | 244 | // get RTC time |
245 | memset ( &rtc, 0, sizeof ( struct tm )); | 245 | memset ( &rtc, 0, sizeof ( struct tm )); |
246 | if ( ioctl ( fd, RTC_ALM_SET, &rtc ) < 0 ) | 246 | if ( ioctl ( fd, RTC_RD_TIME, &rtc ) < 0 ) |
247 | error_msg_and_die ( 1, "ioctl RTC_RD_TIME" ); | 247 | error_msg_and_die ( 1, "ioctl RTC_RD_TIME" ); |
248 | rtct = mktime ( &rtc ); | 248 | rtct = mktime ( &rtc ); |
249 | 249 | ||
250 | fprintf ( log, "System time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", sys. tm_mday, sys. tm_mon + 1, sys. tm_year + 1900, sys. tm_hour, sys. tm_min, sys. tm_sec, sys. tm_isdst, sys. tm_zone, sys. tm_gmtoff ); | 250 | fprintf ( log, "System time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", sys. tm_mday, sys. tm_mon + 1, sys. tm_year + 1900, sys. tm_hour, sys. tm_min, sys. tm_sec, sys. tm_isdst, sys. tm_zone, sys. tm_gmtoff ); |
251 | fprintf ( log, "RTC time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", rtc. tm_mday, rtc. tm_mon + 1, rtc. tm_year + 1900, rtc. tm_hour, rtc. tm_min, rtc. tm_sec, rtc. tm_isdst, rtc. tm_zone, rtc. tm_gmtoff ); | 251 | fprintf ( log, "RTC time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", rtc. tm_mday, rtc. tm_mon + 1, rtc. tm_year + 1900, rtc. tm_hour, rtc. tm_min, rtc. tm_sec, rtc. tm_isdst, rtc. tm_zone, rtc. tm_gmtoff ); |
252 | fprintf ( log, "Wakeup time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", alr. tm_mday, alr. tm_mon + 1, alr. tm_year + 1900, alr. tm_hour, alr. tm_min, alr. tm_sec, alr. tm_isdst, alr. tm_zone, alr. tm_gmtoff ); | 252 | fprintf ( log, "Wakeup time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", alr. tm_mday, alr. tm_mon + 1, alr. tm_year + 1900, alr. tm_hour, alr. tm_min, alr. tm_sec, alr. tm_isdst, alr. tm_zone, alr. tm_gmtoff ); |
253 | 253 | ||
254 | fprintf ( log, "System/RTC diff: %d seconds\n", ( syst - rtct ) - sys. tm_gmtoff ); | 254 | fprintf ( log, "System/RTC diff: %d seconds\n", ( syst - rtct ) - sys. tm_gmtoff ); |
255 | 255 | ||
256 | 256 | ||
257 | rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff; | 257 | rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff; |
258 | 258 | ||
259 | if ( fix_rtc && (( rtc_sys_diff < -4 ) || ( rtc_sys_diff > 4 ))) { | 259 | if ( fix_rtc && (( rtc_sys_diff < -4 ) || ( rtc_sys_diff > 4 ))) { |
260 | struct tm set; | 260 | struct tm set; |
261 | 261 | ||
262 | set = *gmtime ( &syst ); | 262 | set = *gmtime ( &syst ); |
263 | 263 | ||
264 | fprintf ( log, "Correcting RTC: %d seconds\n", rtc_sys_diff ); | 264 | fprintf ( log, "Correcting RTC: %d seconds\n", rtc_sys_diff ); |
265 | 265 | ||
266 | if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) | 266 | if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) |
267 | error_msg_and_die ( 1, "ioctl RTC_SET_TIME" ); | 267 | error_msg_and_die ( 1, "ioctl RTC_SET_TIME" ); |
268 | } | 268 | } |
269 | 269 | ||
270 | // set alarm time | 270 | // set alarm time |
271 | if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) | 271 | if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) |
272 | error_msg_and_die ( 1, "ioctl RTC_ALM_SET" ); | 272 | error_msg_and_die ( 1, "ioctl RTC_ALM_SET" ); |
273 | // enable alarm irq | 273 | // enable alarm irq |
274 | if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) | 274 | if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) |
275 | error_msg_and_die ( 1, "ioctl RTC_AIE_ON" ); | 275 | error_msg_and_die ( 1, "ioctl RTC_AIE_ON" ); |
276 | 276 | ||
277 | log_msg ( "SLEEPING\n" ); | 277 | log_msg ( "SLEEPING\n" ); |
278 | 278 | ||
279 | // wait for alarm irq | 279 | // wait for alarm irq |
280 | if ( read ( fd, buf, sizeof( unsigned long )) < 0 ) | 280 | if ( read ( fd, buf, sizeof( unsigned long )) < 0 ) |
281 | error_msg_and_die ( 1, "read rtc alarm" ); | 281 | error_msg_and_die ( 1, "read rtc alarm" ); |
282 | 282 | ||
283 | log_msg ( "WAKEUP\n" ); | 283 | log_msg ( "WAKEUP\n" ); |
284 | 284 | ||
285 | // disable alarm irq | 285 | // disable alarm irq |
286 | if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 ) | 286 | if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 ) |
287 | error_msg_and_die ( 1, "ioctl RTC_AIE_OFF" ); | 287 | error_msg_and_die ( 1, "ioctl RTC_AIE_OFF" ); |
288 | 288 | ||
289 | close ( fd ); | 289 | close ( fd ); |
290 | 290 | ||
291 | log_msg ( "EXITING\n" ); | 291 | log_msg ( "EXITING\n" ); |
292 | 292 | ||
293 | fclose ( log ); | 293 | fclose ( log ); |
294 | remove_pidfile ( ); | 294 | remove_pidfile ( ); |