summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opiealarm/opiealarm.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/core/opiealarm/opiealarm.c b/core/opiealarm/opiealarm.c
index ce0103e..d96ffaf 100644
--- a/core/opiealarm/opiealarm.c
+++ b/core/opiealarm/opiealarm.c
@@ -45,2 +45,4 @@ static int opiealarm_was_running;
+static pid_t startpid = 0;
+
@@ -60,2 +62,5 @@ void error_msg_and_die ( int perr, const char *msg )
+ if ( getpid ( ) != startpid )
+ kill ( startpid, SIGUSR1 );
+
while ( 1 ) // pretend we are waiting on RTC, so opiealarm -r can kill us
@@ -67,4 +72,6 @@ void sig_handler ( int sig )
{
- log_msg ( "GOT SIGNAL -> EXITING\n" );
- fclose ( log );
+ if ( log ) {
+ log_msg ( "GOT SIGNAL -> EXITING\n" );
+ fclose ( log );
+ }
remove_pidfile ( );
@@ -73,2 +80,7 @@ void sig_handler ( int sig )
+void sig_handler_parent ( int sig )
+{
+ exit ( 0 );
+}
+
void usage ( void )
@@ -90,4 +102,8 @@ int fork_with_pidfile ( void )
- if ( pid > 0 )
+ if ( pid > 0 ) {
+ signal ( SIGUSR1, sig_handler_parent );
+ while ( 1 )
+ sleep ( 1000 );
exit ( 0 );
+ }
else if ( pid < 0 ) {
@@ -182,2 +198,3 @@ int main ( int argc, char **argv )
// kill running opiealarm
+ startpid = getpid ( );
opiealarm_was_running = kill_with_pidfile ( );
@@ -194,2 +211,3 @@ int main ( int argc, char **argv )
+
int suspend ( int fix_rtc )
@@ -211,3 +229,2 @@ int suspend ( int fix_rtc )
-
if (!( fp = fopen ( "/etc/resumeat", "r" )))
@@ -225,4 +242,4 @@ int suspend ( int fix_rtc )
- /* subtract 5 sec from event time... */
- alrt -= 5;
+ alrt -= 5; // wake up 5 sec before the specified time
+
@@ -276,3 +293,5 @@ int suspend ( int fix_rtc )
- log_msg ( "SLEEPING\n" );
+ if ( log )
+ fprintf( log, "SIGUSR: pid %d - SLEEPING: pid %d\n", startpid, getpid ( ));
+ kill ( startpid, SIGUSR1 );
@@ -328,2 +347,3 @@ int resume ( int resuspend )
return 4;
+ kill ( startpid, SIGUSR1 );