Skip to content

Commit

Permalink
etc: scripts: Fix Ctrl-C handling in iptsd-foreach
Browse files Browse the repository at this point in the history
Ctrl-C needs to be passed through to the iptsd instance, otherwise it
will be killed without properly executing its termination handlers.
  • Loading branch information
StollD committed Apr 26, 2024
1 parent bad9b84 commit 811524e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions etc/scripts/iptsd-foreach
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,23 @@ function run-iptsd-foreach() {
tmux -S "${tmux_socket}" new-session -d -n iptsd
fi

# Save existing traps
local -r saved_traps="$(trap)"

# Ignore SIGINT and SIGTERM, these have to be handled by xargs / iptsd
trap -- "" SIGINT
trap -- "" SIGTERM

# Run the supplied commands on all devices
echo -n "${devices[@]}" | xargs -d ' ' -P "${xargs_procs}" -i "${xargs_cmd[@]}"

# Restore SIGINT and SIGTERM to their defaults
trap -- - SIGINT
trap -- - SIGTERM

# Restore previous traps
eval "${saved_traps}"

if [ -n "${tmux_socket}" ]; then
tmux -S "${tmux_socket}" kill-window -t 0
tmux -S "${tmux_socket}" attach
Expand Down

0 comments on commit 811524e

Please sign in to comment.