Skip to content

Commit

Permalink
util (ble/builtin/trap): suppress INT processing with user traps
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 9, 2022
1 parent 9e2963c commit 5c28387
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -185,6 +185,7 @@
- trap (`ble/builtin/trap/finalize`): fix a failure of restoring the original trap `#D1864` XXXXXXX
- trap (`trap -p`): print also custom traps `#D1864` XXXXXXX
- trap: preserve positional parameters for user trap handlers `#D1865` XXXXXXX
- trap: suppress `INT` processing with user traps `#D1866` XXXXXXX

## Fixes

Expand Down
5 changes: 5 additions & 0 deletions note.txt
Expand Up @@ -6636,6 +6636,11 @@ bash_tips

2022-08-25

* trap: ユーザーが INT を設定している時は INT によるキャンセルはしない [#D1866]

INT によってコマンドがキャンセルされるのを防ぐ為に trap '' INT としても意味
がない。結局コマンドが中止される処理が走る。

* trap: user trap handler 内で $@ を復元する [#D1865]

2022-08-29 テストが動かなくなった。何故→これは単純なミスだった。shift を実
Expand Down
12 changes: 8 additions & 4 deletions src/edit.sh
Expand Up @@ -6352,14 +6352,18 @@ ble/function#trace _ble_builtin_trap_DEBUG__initialize
_ble_builtin_trap_DEBUG__initialize

function ble-edit/exec:gexec/.TRAPINT {
local sig=130
((_ble_bash>=40300)) || sig=128 # bash-4.2 以下は 128
# ユーザートラップがある時は中断処理は実行しない
local ret; ble/builtin/trap/sig#resolve INT
ble/builtin/trap/user-handler#has "$ret" && return 0

local ext=130
((_ble_bash>=40300)) || ext=128 # bash-4.2 以下は 128
if [[ $_ble_attached ]]; then
ble/util/print "$_ble_term_bold^C$_ble_term_sgr0" >&2
_ble_edit_exec_TRAPDEBUG_INT=$sig
_ble_edit_exec_TRAPDEBUG_INT=$ext
ble-edit/exec:gexec/.TRAPDEBUG/trap
else
_ble_builtin_trap_postproc="{ return $sig || break; } &>/dev/tty"
_ble_builtin_trap_postproc="{ return $ext || break; } &>/dev/tty"
fi
}
function ble-edit/exec:gexec/.TRAPINT/reset {
Expand Down

0 comments on commit 5c28387

Please sign in to comment.