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


Groups > gnu.bash.bug > #15802

trap: interactive bash exits on resending SIGINT twice

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Martijn Dekker <martijn@inlv.org>
Newsgroups gnu.bash.bug
Subject trap: interactive bash exits on resending SIGINT twice
Date Tue, 14 Jan 2020 17:24:10 +0100
Lines 24
Approved bug-bash@gnu.org
Message-ID <mailman.2542.1579019061.1979.bug-bash@gnu.org> (permalink)
References <9e22237a-78bf-c0bf-efcf-7f536cbed5ea@inlv.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace usenet.stanford.edu 1579019061 1607 209.51.188.17 (14 Jan 2020 16:24:21 GMT)
X-Complaints-To action@cs.stanford.edu
To Bug reports for the GNU Bourne Again SHell <bug-bash@gnu.org>
Envelope-to bug-bash@gnu.org
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.4.1
Content-Language en-GB
X-detected-operating-system by eggs.gnu.org: GNU/Linux 3.x [fuzzy]
X-Received-From 37.59.109.123
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <9e22237a-78bf-c0bf-efcf-7f536cbed5ea@inlv.org>
Xref csiph.com gnu.bash.bug:15802

Show key headers only | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web