author | sandman <sandman> | 2002-06-17 02:19:40 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-06-17 02:19:40 (UTC) |
commit | b646eee10051aa1065f60113066eb0028d17efc4 (patch) (unidiff) | |
tree | a079377b12b97bc54a7a960a36d7453716d1f497 | |
parent | 0d9911023b9a5c70916c0354ca3358c90b601f32 (diff) | |
download | opie-b646eee10051aa1065f60113066eb0028d17efc4.zip opie-b646eee10051aa1065f60113066eb0028d17efc4.tar.gz opie-b646eee10051aa1065f60113066eb0028d17efc4.tar.bz2 |
Added a new switch (-f) to opiealarm. When enabled the RTC is 'fixed'
on suspend, if system and RTC time differ more than 5 seconds. This
works both with a installed /etc/localtime and without.
This should fix many reported problems regarding ipaqalarm/opiealarm.
-rw-r--r-- | core/opiealarm/opiealarm.c | 57 | ||||
-rwxr-xr-x | root/etc/suspend-scripts/S46opiealarm | 2 |
2 files changed, 44 insertions, 15 deletions
diff --git a/core/opiealarm/opiealarm.c b/core/opiealarm/opiealarm.c index ac98832..128929e 100644 --- a/core/opiealarm/opiealarm.c +++ b/core/opiealarm/opiealarm.c | |||
@@ -31,7 +31,7 @@ | |||
31 | FILE *log; // debug only | 31 | FILE *log; // debug only |
32 | 32 | ||
33 | int resume ( int resuspend ); | 33 | int resume ( int resuspend ); |
34 | int suspend ( void ); | 34 | int suspend ( int fix_rtc ); |
35 | int main ( int argc, char **argv ); | 35 | int main ( int argc, char **argv ); |
36 | int fork_with_pidfile ( void ); | 36 | int fork_with_pidfile ( void ); |
37 | int kill_with_pidfile ( void ); | 37 | int kill_with_pidfile ( void ); |
@@ -73,8 +73,9 @@ void sig_handler ( int sig ) | |||
73 | 73 | ||
74 | void usage ( void ) | 74 | void usage ( void ) |
75 | { | 75 | { |
76 | fprintf ( stderr, "Usage: opiealarm -r|-s [-a]\n\n" ); | 76 | fprintf ( stderr, "Usage: opiealarm -s [-f] | -r [-a]\n\n" ); |
77 | fprintf ( stderr, "\t-s\tSuspend mode: set RTC alarm\n" ); | 77 | fprintf ( stderr, "\t-s\tSuspend mode: set RTC alarm\n" ); |
78 | fprintf ( stderr, "\t-f \tFix RTC, if RTC and system have more than 5sec difference (suspend mode)\n" ); | ||
78 | fprintf ( stderr, "\t-r\tResume mode: kill running opiealarm\n" ); | 79 | fprintf ( stderr, "\t-r\tResume mode: kill running opiealarm\n" ); |
79 | fprintf ( stderr, "\t-a <x>\tResuspend in <x> seconds (resume mode)\n\n" ); | 80 | fprintf ( stderr, "\t-a <x>\tResuspend in <x> seconds (resume mode)\n\n" ); |
80 | exit ( 1 ); | 81 | exit ( 1 ); |
@@ -143,9 +144,10 @@ int main ( int argc, char **argv ) | |||
143 | { | 144 | { |
144 | int mode = 0; | 145 | int mode = 0; |
145 | int ac_resusp = 0; | 146 | int ac_resusp = 0; |
147 | int fix_rtc = 0; | ||
146 | int opt; | 148 | int opt; |
147 | 149 | ||
148 | while (( opt = getopt ( argc, argv, "a:rs" )) != EOF ) { | 150 | while (( opt = getopt ( argc, argv, "a:frs" )) != EOF ) { |
149 | switch ( opt ) { | 151 | switch ( opt ) { |
150 | case 's': | 152 | case 's': |
151 | mode = 's'; | 153 | mode = 's'; |
@@ -161,6 +163,9 @@ int main ( int argc, char **argv ) | |||
161 | fprintf ( stderr, "Warning: resuspend timeout must be >= 30 sec. -- now set to 120 sec\n" ); | 163 | fprintf ( stderr, "Warning: resuspend timeout must be >= 30 sec. -- now set to 120 sec\n" ); |
162 | } | 164 | } |
163 | break; | 165 | break; |
166 | case 'f': | ||
167 | fix_rtc = 1; | ||
168 | break; | ||
164 | default: | 169 | default: |
165 | usage ( ); | 170 | usage ( ); |
166 | } | 171 | } |
@@ -181,20 +186,21 @@ int main ( int argc, char **argv ) | |||
181 | switch ( mode ) { | 186 | switch ( mode ) { |
182 | case 'r': return resume ( ac_resusp ); | 187 | case 'r': return resume ( ac_resusp ); |
183 | case 's': | 188 | case 's': |
184 | default : return suspend ( ); | 189 | default : return suspend ( fix_rtc ); |
185 | } | 190 | } |
186 | return 0; | 191 | return 0; |
187 | } | 192 | } |
188 | 193 | ||
189 | 194 | ||
190 | int suspend ( void ) | 195 | int suspend ( int fix_rtc ) |
191 | { | 196 | { |
192 | FILE *fp; | 197 | FILE *fp; |
193 | char buf [64]; | 198 | char buf [64]; |
194 | time_t t; | 199 | time_t alrt, syst, rtct; |
195 | struct tm *tm; | 200 | struct tm alr, sys, rtc; |
196 | int fd; | 201 | int fd; |
197 | 202 | int rtc_sys_diff; | |
203 | |||
198 | 204 | ||
199 | if ( !fork_with_pidfile ( )) | 205 | if ( !fork_with_pidfile ( )) |
200 | return 3; | 206 | return 3; |
@@ -212,24 +218,47 @@ int suspend ( void ) | |||
212 | 218 | ||
213 | fclose ( fp ); | 219 | fclose ( fp ); |
214 | 220 | ||
215 | t = atoi ( buf ); | 221 | alrt = atoi ( buf ); |
216 | 222 | ||
217 | if ( t == 0 ) | 223 | if ( alrt == 0 ) |
218 | 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" ); |
219 | 225 | ||
220 | /* subtract 5 sec from event time... */ | 226 | /* subtract 5 sec from event time... */ |
221 | t -= 5; | 227 | alrt -= 5; |
222 | 228 | ||
223 | if ( log ) | 229 | if ( log ) |
224 | fprintf ( log, "Setting RTC alarm to %d\n", t ); | 230 | fprintf ( log, "Setting RTC alarm to %d\n", alrt ); |
225 | 231 | ||
226 | tm = gmtime ( &t ); | 232 | alr = *gmtime ( &alrt ); |
227 | 233 | ||
234 | // get system time | ||
235 | time ( &syst ); | ||
236 | sys = *localtime ( &syst ); | ||
237 | |||
228 | // Write alarm time to RTC | 238 | // Write alarm time to RTC |
229 | if (( fd = open ( "/dev/misc/rtc", O_RDWR )) < 0 ) | 239 | if (( fd = open ( "/dev/misc/rtc", O_RDWR )) < 0 ) |
230 | error_msg_and_die ( 1, "/dev/misc/rtc" ); | 240 | error_msg_and_die ( 1, "/dev/misc/rtc" ); |
241 | |||
242 | // get RTC time | ||
243 | if ( ioctl ( fd, RTC_ALM_SET, &rtc ) < 0 ) | ||
244 | error_msg_and_die ( 1, "ioctl RTC_RD_TIME" ); | ||
245 | rtct = mktime ( &rtc ); | ||
246 | |||
247 | rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff; | ||
248 | |||
249 | if ( fix_rtc && (( rtc_sys_diff < -4 ) || ( rtc_sys_diff > 4 ))) { | ||
250 | struct tm set; | ||
251 | |||
252 | set = *gmtime ( &syst ); | ||
253 | |||
254 | fprintf ( log, "Correcting RTC: %d seconds\n", rtc_sys_diff ); | ||
255 | |||
256 | if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) | ||
257 | error_msg_and_die ( 1, "ioctl RTC_SET_TIME" ); | ||
258 | } | ||
259 | |||
231 | // set alarm time | 260 | // set alarm time |
232 | if ( ioctl ( fd, RTC_ALM_SET, tm ) < 0 ) | 261 | if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) |
233 | error_msg_and_die ( 1, "ioctl RTC_ALM_SET" ); | 262 | error_msg_and_die ( 1, "ioctl RTC_ALM_SET" ); |
234 | // enable alarm irq | 263 | // enable alarm irq |
235 | if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) | 264 | if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) |
diff --git a/root/etc/suspend-scripts/S46opiealarm b/root/etc/suspend-scripts/S46opiealarm index 9b936e4..a41dae5 100755 --- a/root/etc/suspend-scripts/S46opiealarm +++ b/root/etc/suspend-scripts/S46opiealarm | |||
@@ -2,4 +2,4 @@ | |||
2 | # Starts opiealarm, which only runs while the iPaq sleeps | 2 | # Starts opiealarm, which only runs while the iPaq sleeps |
3 | # and wakes it up when the RTC alarm goes off. | 3 | # and wakes it up when the RTC alarm goes off. |
4 | 4 | ||
5 | /opt/QtPalmtop/bin/opiealarm -s | 5 | /opt/QtPalmtop/bin/opiealarm -s -f |