summaryrefslogtreecommitdiff
path: root/core/opiealarm
Unidiff
Diffstat (limited to 'core/opiealarm') (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;
45 45
46static pid_t startpid = 0;
47
46 48
@@ -60,2 +62,5 @@ void error_msg_and_die ( int perr, const char *msg )
60 62
63 if ( getpid ( ) != startpid )
64 kill ( startpid, SIGUSR1 );
65
61 while ( 1 ) // pretend we are waiting on RTC, so opiealarm -r can kill us 66 while ( 1 ) // pretend we are waiting on RTC, so opiealarm -r can kill us
@@ -67,4 +72,6 @@ void sig_handler ( int sig )
67{ 72{
68 log_msg ( "GOT SIGNAL -> EXITING\n" ); 73 if ( log ) {
69 fclose ( log ); 74 log_msg ( "GOT SIGNAL -> EXITING\n" );
75 fclose ( log );
76 }
70 remove_pidfile ( ); 77 remove_pidfile ( );
@@ -73,2 +80,7 @@ void sig_handler ( int sig )
73 80
81void sig_handler_parent ( int sig )
82{
83 exit ( 0 );
84}
85
74void usage ( void ) 86void usage ( void )
@@ -90,4 +102,8 @@ int fork_with_pidfile ( void )
90 102
91 if ( pid > 0 ) 103 if ( pid > 0 ) {
104 signal ( SIGUSR1, sig_handler_parent );
105 while ( 1 )
106 sleep ( 1000 );
92 exit ( 0 ); 107 exit ( 0 );
108 }
93 else if ( pid < 0 ) { 109 else if ( pid < 0 ) {
@@ -182,2 +198,3 @@ int main ( int argc, char **argv )
182 // kill running opiealarm 198 // kill running opiealarm
199 startpid = getpid ( );
183 opiealarm_was_running = kill_with_pidfile ( ); 200 opiealarm_was_running = kill_with_pidfile ( );
@@ -194,2 +211,3 @@ int main ( int argc, char **argv )
194 211
212
195int suspend ( int fix_rtc ) 213int suspend ( int fix_rtc )
@@ -211,3 +229,2 @@ int suspend ( int fix_rtc )
211 229
212
213 if (!( fp = fopen ( "/etc/resumeat", "r" ))) 230 if (!( fp = fopen ( "/etc/resumeat", "r" )))
@@ -225,4 +242,4 @@ int suspend ( int fix_rtc )
225 242
226 /* subtract 5 sec from event time... */ 243 alrt -= 5; // wake up 5 sec before the specified time
227 alrt -= 5; 244
228 245
@@ -276,3 +293,5 @@ int suspend ( int fix_rtc )
276 293
277 log_msg ( "SLEEPING\n" ); 294 if ( log )
295 fprintf( log, "SIGUSR: pid %d - SLEEPING: pid %d\n", startpid, getpid ( ));
296 kill ( startpid, SIGUSR1 );
278 297
@@ -328,2 +347,3 @@ int resume ( int resuspend )
328 return 4; 347 return 4;
348 kill ( startpid, SIGUSR1 );
329 349