summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opiealarm/opiealarm.c57
-rwxr-xr-xroot/etc/suspend-scripts/S46opiealarm2
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
@@ -32,5 +32,5 @@ FILE *log; // debug only
int resume ( int resuspend );
-int suspend ( void );
+int suspend ( int fix_rtc );
int main ( int argc, char **argv );
int fork_with_pidfile ( void );
@@ -74,6 +74,7 @@ void sig_handler ( int sig )
void usage ( void )
{
- fprintf ( stderr, "Usage: opiealarm -r|-s [-a]\n\n" );
+ fprintf ( stderr, "Usage: opiealarm -s [-f] | -r [-a]\n\n" );
fprintf ( stderr, "\t-s\tSuspend mode: set RTC alarm\n" );
+ fprintf ( stderr, "\t-f \tFix RTC, if RTC and system have more than 5sec difference (suspend mode)\n" );
fprintf ( stderr, "\t-r\tResume mode: kill running opiealarm\n" );
fprintf ( stderr, "\t-a <x>\tResuspend in <x> seconds (resume mode)\n\n" );
@@ -144,7 +145,8 @@ int main ( int argc, char **argv )
int mode = 0;
int ac_resusp = 0;
+ int fix_rtc = 0;
int opt;
- while (( opt = getopt ( argc, argv, "a:rs" )) != EOF ) {
+ while (( opt = getopt ( argc, argv, "a:frs" )) != EOF ) {
switch ( opt ) {
case 's':
@@ -162,4 +164,7 @@ int main ( int argc, char **argv )
}
break;
+ case 'f':
+ fix_rtc = 1;
+ break;
default:
usage ( );
@@ -182,5 +187,5 @@ int main ( int argc, char **argv )
case 'r': return resume ( ac_resusp );
case 's':
- default : return suspend ( );
+ default : return suspend ( fix_rtc );
}
return 0;
@@ -188,12 +193,13 @@ int main ( int argc, char **argv )
-int suspend ( void )
+int suspend ( int fix_rtc )
{
FILE *fp;
char buf [64];
- time_t t;
- struct tm *tm;
+ time_t alrt, syst, rtct;
+ struct tm alr, sys, rtc;
int fd;
-
+ int rtc_sys_diff;
+
if ( !fork_with_pidfile ( ))
@@ -213,22 +219,45 @@ int suspend ( void )
fclose ( fp );
- t = atoi ( buf );
+ alrt = atoi ( buf );
- if ( t == 0 )
+ if ( alrt == 0 )
error_msg_and_die ( 0, "/etc/resumeat contains an invalid time description" );
/* subtract 5 sec from event time... */
- t -= 5;
+ alrt -= 5;
if ( log )
- fprintf ( log, "Setting RTC alarm to %d\n", t );
+ fprintf ( log, "Setting RTC alarm to %d\n", alrt );
- tm = gmtime ( &t );
+ alr = *gmtime ( &alrt );
+ // get system time
+ time ( &syst );
+ sys = *localtime ( &syst );
+
// Write alarm time to RTC
if (( fd = open ( "/dev/misc/rtc", O_RDWR )) < 0 )
error_msg_and_die ( 1, "/dev/misc/rtc" );
+
+ // get RTC time
+ if ( ioctl ( fd, RTC_ALM_SET, &rtc ) < 0 )
+ error_msg_and_die ( 1, "ioctl RTC_RD_TIME" );
+ rtct = mktime ( &rtc );
+
+ rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff;
+
+ if ( fix_rtc && (( rtc_sys_diff < -4 ) || ( rtc_sys_diff > 4 ))) {
+ struct tm set;
+
+ set = *gmtime ( &syst );
+
+ fprintf ( log, "Correcting RTC: %d seconds\n", rtc_sys_diff );
+
+ if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 )
+ error_msg_and_die ( 1, "ioctl RTC_SET_TIME" );
+ }
+
// set alarm time
- if ( ioctl ( fd, RTC_ALM_SET, tm ) < 0 )
+ if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 )
error_msg_and_die ( 1, "ioctl RTC_ALM_SET" );
// enable alarm irq
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
@@ -3,3 +3,3 @@
# and wakes it up when the RTC alarm goes off.
-/opt/QtPalmtop/bin/opiealarm -s
+/opt/QtPalmtop/bin/opiealarm -s -f