diff --git a/gancioff b/gancioff index 03cc56b..332c85c 100755 --- a/gancioff +++ b/gancioff @@ -132,6 +132,7 @@ max_post_length = 840 0: regular run 1: some error occurred +99: killed with signal (ctrl+c, etc.) [[[ DISCLAIMER AND LICENSE ]]] @@ -191,6 +192,12 @@ for ($i=1; $i<$argc; $i++) { } } +//declare(ticks=1); +pcntl_async_signals(true); +pcntl_signal(SIGTERM,'sighandler');// Termination ('kill' was called) +pcntl_signal(SIGHUP,'sighandler');// Terminal log-out +pcntl_signal(SIGINT,'sighandler');// Interrupted (ctrl-c is pressed) + $langsFP=__DIR__.'/lib/iso-639-1-langcodes.txt'; if ($opts['update-language-codes']) { $langCodes=[]; @@ -485,6 +492,13 @@ function hent($str) { return html_entity_decode($str,ENT_QUOTES,'UTF-8'); } +function sighandler($sig) { + global $fh; + if (isset($fh)) fclose($fh); + echo "\nInfo: received signal {$sig}, shutting down.\n"; + exit(99); +} + function dieYoung($msg,$ec) { fwrite(STDERR,$msg); die($ec);