From bb6dd44d8638ccba315973f2c6c66262ef72f1d2 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 5 Oct 2018 20:43:24 +0200 Subject: sfeed_update: improve SIGINT handling When SIGINT occurs on waiting for jobs it returns 130 (128 + SIGINT). Make sure to check for interrupted and return immediately. Tested with ksh, dash, bash, zsh. Sidenote: ideally we want to cleanup() on SIGTERM too, but this is too inconsistent over various shells. --- sfeed_update | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sfeed_update b/sfeed_update index e924784..e2f9677 100755 --- a/sfeed_update +++ b/sfeed_update @@ -78,6 +78,7 @@ feed() { # wait until ${maxjobs} are finished: throughput using this logic is # non-optimal, but it is simple and portable. [ $((curjobs % maxjobs)) -eq 0 ] && wait + [ ${isinterrupted} -eq 1 ] && return curjobs=$((curjobs + 1)) (name="$1" @@ -123,7 +124,7 @@ cleanup() { } interrupted() { - isinterrupted="1" + isinterrupted=1 } feeds() { @@ -134,7 +135,7 @@ feeds() { # job counter. curjobs=0 # kill whole current process group on ^C (SIGINT). -isinterrupted="0" +isinterrupted=0 # SIGTERM: signal to terminate parent. trap -- "interrupted" "TERM" # SIGINT: kill all running childs >:D @@ -152,5 +153,5 @@ wait # cleanup temporary files etc. cleanup # on SIGINT exit with 128 + signal (SIGINT = 2). -[ "${isinterrupted}" = "1" ] && exit 130 +[ ${isinterrupted} -eq 1 ] && exit 130 exit 0 -- cgit v1.2.3