-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 | |||
@@ -33,3 +33,3 @@ FILE *log; // debug only | |||
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 ); |
@@ -75,4 +75,5 @@ 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" ); |
@@ -145,5 +146,6 @@ int main ( int argc, char **argv ) | |||
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 ) { |
@@ -163,2 +165,5 @@ int main ( int argc, char **argv ) | |||
163 | break; | 165 | break; |
166 | case 'f': | ||
167 | fix_rtc = 1; | ||
168 | break; | ||
164 | default: | 169 | default: |
@@ -183,3 +188,3 @@ int main ( int argc, char **argv ) | |||
183 | case 's': | 188 | case 's': |
184 | default : return suspend ( ); | 189 | default : return suspend ( fix_rtc ); |
185 | } | 190 | } |
@@ -189,3 +194,3 @@ int main ( int argc, char **argv ) | |||
189 | 194 | ||
190 | int suspend ( void ) | 195 | int suspend ( int fix_rtc ) |
191 | { | 196 | { |
@@ -193,6 +198,7 @@ int suspend ( void ) | |||
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 | ||
@@ -214,5 +220,5 @@ int suspend ( void ) | |||
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" ); |
@@ -220,9 +226,13 @@ int suspend ( void ) | |||
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 |
@@ -230,4 +240,23 @@ int suspend ( void ) | |||
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" ); |
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 | |||
@@ -4,2 +4,2 @@ | |||
4 | 4 | ||
5 | /opt/QtPalmtop/bin/opiealarm -s | 5 | /opt/QtPalmtop/bin/opiealarm -s -f |