summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2018-10-05 20:43:24 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2018-10-05 20:43:24 +0200
commitbb6dd44d8638ccba315973f2c6c66262ef72f1d2 (patch)
treec97f3eac1242e2b56641ac509b25b315ec9af188
parent774dc3ed45bc2a1efcddeea2eb885e140949f9eb (diff)
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.
-rwxr-xr-xsfeed_update7
1 files 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