summaryrefslogtreecommitdiff
path: root/sfeed_update
diff options
context:
space:
mode:
Diffstat (limited to 'sfeed_update')
-rwxr-xr-xsfeed_update27
1 files changed, 16 insertions, 11 deletions
diff --git a/sfeed_update b/sfeed_update
index e2f9677..5ee99ee 100755
--- a/sfeed_update
+++ b/sfeed_update
@@ -77,8 +77,9 @@ fetchfeed() {
feed() {
# wait until ${maxjobs} are finished: throughput using this logic is
# non-optimal, but it is simple and portable.
+ [ ${signo} -ne 0 ] && return
[ $((curjobs % maxjobs)) -eq 0 ] && wait
- [ ${isinterrupted} -eq 1 ] && return
+ [ ${signo} -ne 0 ] && return
curjobs=$((curjobs + 1))
(name="$1"
@@ -123,8 +124,12 @@ cleanup() {
rm -rf "${sfeedtmpdir}"
}
-interrupted() {
- isinterrupted=1
+sighandler() {
+ signo="$1"
+ # ignore TERM signal for myself.
+ trap -- "" TERM
+ # kill all running childs >:D
+ kill -TERM -$$
}
feeds() {
@@ -134,12 +139,12 @@ feeds() {
# job counter.
curjobs=0
-# kill whole current process group on ^C (SIGINT).
-isinterrupted=0
+# signal number received for parent.
+signo=0
+# SIGINT: signal to interrupt parent.
+trap -- "sighandler 2" "INT"
# SIGTERM: signal to terminate parent.
-trap -- "interrupted" "TERM"
-# SIGINT: kill all running childs >:D
-trap -- "kill -TERM -$$" "INT"
+trap -- "sighandler 15" "TERM"
# load config file.
loadconfig "$1"
# fetch feeds and store in temporary file.
@@ -149,9 +154,9 @@ mkdir -p "${sfeedpath}"
# fetch feeds specified in config file.
feeds
# wait till all feeds are fetched (concurrently).
-wait
+[ ${signo} -eq 0 ] && wait
# cleanup temporary files etc.
cleanup
-# on SIGINT exit with 128 + signal (SIGINT = 2).
-[ ${isinterrupted} -eq 1 ] && exit 130
+# on signal SIGINT and SIGTERM exit with signal number + 128.
+[ ${signo} -ne 0 ] && exit $((signo+128))
exit 0