Skip to content

Commit

Permalink
util (trap): fix a bug of restoring original traps
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jul 24, 2022
1 parent fa955c1 commit 8d918b6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -94,6 +94,7 @@
- edit: work around a bash-4.4..5.1 bug of `exit` outputting time to stderr of exit context `#D1765` 3de751e e61dbaa
- edit (`exec_elapsed_mark`): show hours and days `#D1793` 699dabb
- util: preserve original traps and restore them on unload `#D1775` `#D1776` `#D1777` 398e404
- util (trap): fix a bug of restoring original traps `#D1850` XXXXXXX
- progcomp: support `compopt -o ble/no-default` to suppress default completions `#D1789` 7b70a0e
- sabbrev: support options `-r` and `--reset` to remove entries `#D1790` 29b8be3
- util (blehook): support `hook!=handler` and `hook+-=handler` `#D1791` 0b8c097
Expand Down
32 changes: 32 additions & 0 deletions note.txt
Expand Up @@ -6530,6 +6530,38 @@ bash_tips

2022-07-24

* util: starship で ble-reload した後に C-d で抜けると滅茶苦茶沢山のログが出る [#D1850]

declare が無引数で呼び出されているという事だろうか。ble-reload していない時
には関係ない。EXIT trap を先ず確認するのが良いだろう → blehook EXIT= とし
ても同様に問題が生じる。trap - EXIT とすると問題は発生せずに exit する事が
できる。

どうも trap handler に "set" という文字列が登録されている様だ。何故? 実際に
trap handler の配列を見てみると以下の様になっている。

declare -a _ble_builtin_trap_handlers=([0]="set")

因みに starship init bash の出力には trap も set も含まれてはいない。うーん。
実際に値を設定している箇所は一箇所しかない様な気がする。確認する。確認して
みた所、実際に ble/builtin/trap -- set EXIT という呼び出しが行われている。

これは元々設定されていたtrapを再設定する時に、元々設定されていたtrapの抽出
に失敗しているという事だろうか。ble/builtin/trap の呼び出し元を確認すると

ble/builtin/trap/install-hook

であった。やはり既存設定の抽出に失敗しているという事だろう → うーん。何故
か builtin trap -p EXIT の結果が本当に trap -- set EXIT になっている様だ。
何事だろうか。unload の差異に set を設定する様になっている可能性? というの
も変な気がする。だとしたら starship と関係ないはず。

どうも ble/base/unload-for-reload に於いて trap -- set EXIT が設定されてい
る様である。つまり、元々の trap を設定する際に誤って set を設定してしまって
いる。

これは結局単純なミスだった。

* main, util: make check が nix-build @ macOS で失敗する (reported by aiotter) [#D1849]
https://github.com/NixOS/nixpkgs/pull/181963#issuecomment-1193125126

Expand Down
2 changes: 1 addition & 1 deletion src/util.sh
Expand Up @@ -1927,7 +1927,7 @@ function ble/builtin/trap/finalize {
local name=${_ble_builtin_trap_signames[index]}
[[ $name && ${_ble_builtin_trap_reserved[sig]} ]] || continue
if [[ ${_ble_builtin_trap_handlers[sig]+set} ]]; then
builtin trap -- "${_ble_builtin_trap_handlers[sig]+set}" "$name"
builtin trap -- "${_ble_builtin_trap_handlers[sig]-}" "$name"
else
builtin trap -- - "$name"
fi
Expand Down

0 comments on commit 8d918b6

Please sign in to comment.