Skip to content

Commit 78616e5

Browse files
committed
Ensure subprocess termination on Ctrl-C
1 parent 1bca539 commit 78616e5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

main.sh

+18
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,24 @@ manage_scan() {
447447
done
448448
}
449449

450+
onint() {
451+
# send HUP to the whole process group
452+
# to avoid leaving subprocesses behind after a Ctrl-C
453+
kill -HUP -$$
454+
}
455+
456+
onhup() {
457+
echo
458+
exit
459+
}
460+
450461
manage_scans() {
451462
local all_done domains_chunk chunk droplet
452463
declare -i num_lines=0
453464

465+
trap onhup HUP
466+
trap onint INT
467+
454468
while true; do
455469
all_done=true
456470

@@ -512,6 +526,10 @@ manage_scans() {
512526
sleep 30
513527

514528
done
529+
530+
# restore default signal behavior
531+
trap - INT
532+
trap - HUP
515533
}
516534

517535
merge_results() {

0 commit comments

Comments
 (0)