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
@@ -33,3 +33,3 @@ FILE *log; // debug only
int resume ( int resuspend );
-int suspend ( void );
+int suspend ( int fix_rtc );
int main ( int argc, char **argv );
@@ -75,4 +75,5 @@ 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" );
@@ -145,5 +146,6 @@ int main ( int argc, char **argv )
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 ) {
@@ -163,2 +165,5 @@ int main ( int argc, char **argv )
break;
+ case 'f':
+ fix_rtc = 1;
+ break;
default:
@@ -183,3 +188,3 @@ int main ( int argc, char **argv )
case 's':
- default : return suspend ( );
+ default : return suspend ( fix_rtc );
}
@@ -189,3 +194,3 @@ int main ( int argc, char **argv )
-int suspend ( void )
+int suspend ( int fix_rtc )
{
@@ -193,6 +198,7 @@ int suspend ( void )
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;
+
@@ -214,5 +220,5 @@ int suspend ( void )
- t = atoi ( buf );
+ alrt = atoi ( buf );
- if ( t == 0 )
+ if ( alrt == 0 )
error_msg_and_die ( 0, "/etc/resumeat contains an invalid time description" );
@@ -220,9 +226,13 @@ int suspend ( void )
/* 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
@@ -230,4 +240,23 @@ int suspend ( void )
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" );
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 @@
-/opt/QtPalmtop/bin/opiealarm -s
+/opt/QtPalmtop/bin/opiealarm -s -f