Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15802 > unrolled thread

trap: interactive bash exits on resending SIGINT twice

Started byMartijn Dekker <martijn@inlv.org>
First post2020-01-14 17:24 +0100
Last post2020-01-14 17:24 +0100
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  trap: interactive bash exits on resending SIGINT twice Martijn Dekker <martijn@inlv.org> - 2020-01-14 17:24 +0100

#15802 — trap: interactive bash exits on resending SIGINT twice

FromMartijn Dekker <martijn@inlv.org>
Date2020-01-14 17:24 +0100
Subjecttrap: interactive bash exits on resending SIGINT twice
Message-ID<mailman.2542.1579019061.1979.bug-bash@gnu.org>
Setting the following trap makes an interactive bash (any version) exit 
on issuing SIGINT:

trap 'trap "true" INT; kill -s INT $$; trap - INT; kill -s INT $$' INT
#     ^^^^^^^^^^^^^^^ eat signal       ^^^^^^^^^^ unset trap

After setting that trap, pressing Ctrl+C, or otherwise causing SIGINT to 
be sent, causes an interactive bash to exit.

Expected behaviour: no exit.
Confirmed on macOS and Debian.

Ignoring the signal instead of merely eating it seems to be an effective 
workaround on more recent bash versions:
trap 'trap "" INT; kill -s INT $$; trap - INT; kill -s INT $$' INT
This avoids an interactive shell exiting on SIGINT on bash 4.4 and 5.0, 
but not 4.3 or earlier.

- M.

-- 
modernish -- harness the shell
https://github.com/modernish/modernish

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web