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
@@ -44,4 +44,6 @@ int onac ( void );
44static int opiealarm_was_running; 44static int opiealarm_was_running;
45 45
46static pid_t startpid = 0;
47
46 48
47void log_msg ( const char *msg ) 49void log_msg ( const char *msg )
@@ -59,4 +61,7 @@ void error_msg_and_die ( int perr, const char *msg )
59 log_msg ( msg ); 61 log_msg ( 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
62 sleep ( 1 ); 67 sleep ( 1 );
@@ -66,10 +71,17 @@ void error_msg_and_die ( int perr, const char *msg )
66void sig_handler ( int sig ) 71void 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 ( );
71 exit ( 0 ); 78 exit ( 0 );
72} 79}
73 80
81void sig_handler_parent ( int sig )
82{
83 exit ( 0 );
84}
85
74void usage ( void ) 86void usage ( void )
75{ 87{
@@ -89,6 +101,10 @@ int fork_with_pidfile ( void )
89 pid = fork ( ); 101 pid = fork ( );
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 ) {
94 perror ( "forking failed" ); 110 perror ( "forking failed" );
@@ -181,4 +197,5 @@ int main ( int argc, char **argv )
181 197
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 ( );
184 remove_pidfile ( ); 201 remove_pidfile ( );
@@ -193,4 +210,5 @@ int main ( int argc, char **argv )
193 210
194 211
212
195int suspend ( int fix_rtc ) 213int suspend ( int fix_rtc )
196{ 214{
@@ -210,5 +228,4 @@ int suspend ( int fix_rtc )
210 228
211 229
212
213 if (!( fp = fopen ( "/etc/resumeat", "r" ))) 230 if (!( fp = fopen ( "/etc/resumeat", "r" )))
214 error_msg_and_die ( 1, "/etc/resumeat" ); 231 error_msg_and_die ( 1, "/etc/resumeat" );
@@ -224,6 +241,6 @@ int suspend ( int fix_rtc )
224 error_msg_and_die ( 0, "/etc/resumeat contains an invalid time description" ); 241 error_msg_and_die ( 0, "/etc/resumeat contains an invalid time description" );
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
229 if ( log ) 246 if ( log )
@@ -275,5 +292,7 @@ int suspend ( int fix_rtc )
275 error_msg_and_die ( 1, "ioctl RTC_AIE_ON" ); 292 error_msg_and_die ( 1, "ioctl RTC_AIE_ON" );
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
279 // wait for alarm irq 298 // wait for alarm irq
@@ -327,4 +346,5 @@ int resume ( int resuspend )
327 if ( !fork_with_pidfile ( )) 346 if ( !fork_with_pidfile ( ))
328 return 4; 347 return 4;
348 kill ( startpid, SIGUSR1 );
329 349
330 // sleep <resuspend> sec (not less!) 350 // sleep <resuspend> sec (not less!)