-rw-r--r-- | core/launcher/main.cpp | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp index a19da14..1e741d5 100644 --- a/core/launcher/main.cpp +++ b/core/launcher/main.cpp | |||
@@ -333,20 +333,50 @@ int initApplication( int argc, char ** argv ) | |||
333 | return rv; | 333 | return rv; |
334 | } | 334 | } |
335 | 335 | ||
336 | static const char *pidfile_path = "/var/run/opie.pid"; | ||
337 | |||
338 | void create_pidfile ( ) | ||
339 | { | ||
340 | FILE *f; | ||
341 | |||
342 | if (( f = ::fopen ( pidfile_path, "w" ))) { | ||
343 | ::fprintf ( f, "%d", getpid ( )); | ||
344 | ::fclose ( f ); | ||
345 | } | ||
346 | } | ||
347 | |||
348 | void remove_pidfile ( ) | ||
349 | { | ||
350 | ::unlink ( pidfile_path ); | ||
351 | } | ||
352 | |||
353 | void handle_sigterm ( int sig ) | ||
354 | { | ||
355 | if ( qApp ) | ||
356 | qApp-> quit ( ); | ||
357 | } | ||
358 | |||
336 | int main( int argc, char ** argv ) | 359 | int main( int argc, char ** argv ) |
337 | { | 360 | { |
338 | #ifndef SINGLE_APP | 361 | #ifndef SINGLE_APP |
339 | signal( SIGCHLD, SIG_IGN ); | 362 | ::signal( SIGCHLD, SIG_IGN ); |
363 | |||
364 | ::signal ( SIGTERM, handle_sigterm ); | ||
365 | |||
366 | ::setsid ( ); | ||
367 | ::setpgid ( 0, 0 ); | ||
368 | |||
369 | ::atexit ( remove_pidfile ); | ||
370 | create_pidfile ( ); | ||
340 | #endif | 371 | #endif |
341 | 372 | ||
342 | int retVal = initApplication( argc, argv ); | 373 | int retVal = initApplication ( argc, argv ); |
343 | 374 | ||
344 | #ifndef SINGLE_APP | 375 | #ifndef SINGLE_APP |
345 | // Kill them. Kill them all. | 376 | // Kill them. Kill them all. |
346 | setpgid( getpid(), getppid() ); | 377 | ::kill ( 0, SIGTERM ); |
347 | killpg( getpid(), SIGTERM ); | 378 | ::sleep( 1 ); |
348 | sleep( 1 ); | 379 | ::kill ( 0, SIGKILL ); |
349 | killpg( getpid(), SIGKILL ); | ||
350 | #endif | 380 | #endif |
351 | 381 | ||
352 | return retVal; | 382 | return retVal; |