Skip to content

Commit

Permalink
decode: fix a hang on attach failure by cache corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 6, 2021
1 parent 7244e2f commit 24ea379
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
1 change: 1 addition & 0 deletions memo/ChangeLog.md
Expand Up @@ -82,6 +82,7 @@
- edit: fix error messages on accessing undo records in emacs mode (reported by rux616) `#D1497` 61a57c0 e9be69e
- canvas: fix a glitch that SGR at the end of command line is applied to new lines `#D1498` 4bdfdbf
- syntax: fix a bug that `eval() { :; }`, `declare() { :; }` are not treated as function definition `#D1529` 0000000
- decode: fix a hang on attach failure by cache corruption `#D1531` 0000000

## Compatibility

Expand Down
37 changes: 26 additions & 11 deletions note.txt
Expand Up @@ -1384,17 +1384,6 @@ bash_tips
るというのは不自然すぎる。それならば ble.sh 自体が変数を定義するのでそれに
よって被覆されてしまうと説明した方が自然である。

2021-04-28

* keymap 初期化に失敗した時にそれを検出しているのにも拘らず操作不能になる

$_ble_base_cache/keymap.emacs が空の時、The keymap 'emacs' is empty 等の様
にメッセージが表示されて空かどうかのチェックが為されている筈なのに、その後
に何も操作できなくなる。

ble/decode/attach の中でチェックが起こっている気がするが、その場合には
attach せずに終わって操作不能にはならない筈なので関係ないかもしれない。

2021-04-26

* keymap/vi: vi における既定の keymap を imap ではなく nmap にするオプション
Expand Down Expand Up @@ -4291,6 +4280,32 @@ bash_tips

2021-05-05

* 2021-04-28 keymap 初期化に失敗した時にそれを検出しているのにも拘らず操作不能になる [#D1531]

$_ble_base_cache/keymap.emacs が空の時、The keymap 'emacs' is empty 等の様
にメッセージが表示されて空かどうかのチェックが為されている筈なのに、その後
に何も操作できなくなる。

ble/decode/attach の中でチェックが起こっている気がするが、その場合には
attach せずに終わって操作不能にはならない筈なので関係ないかもしれない。

今試しに keymap.emacs を空にして bash --norc から ble.sh をロードしてみたが、
stty の状態が変になる物の操作不能になる訳ではない。set -o vi でスタートさせ
てset -o emacs で切り替えようとすると問題が再現する。つまり、detach して
attach した時の問題である。

調べてみるとどうもコマンドは実行されている様である。stdout.off の状態になっ
ている事によって操作できなくなってしまっているという事の様である。そしてそ
れは、ble/decode/attach の呼び出し元の .check-detach の更に呼び出し元におい
て、bind/.tail 経由で改めて stdout.off が実行されているという事になる。これ
を抑制する為に、.check-detach の中で rebind に失敗した時には改めて
.check-detach を呼び出して抜ける処理を実行する事にした。

→然しそれでもやはり stdout.off が呼び出されてしまう。と思ったが、どうも
.check-detach の戻り値を使って実際に detach が起こったかどうかを伝達してい
る様である。ちゃんと再帰的に呼び出した .check-detach の終了ステータスを外に
伝播させる。これで問題なく抜ける様になった。

* 2021-04-06 main (--rcfile): 通常ファイルしか許可していないが [#D1530]

<() や /dev/null を食わせたい事もあるだろう。後、ファイルが見つからなかった
Expand Down
15 changes: 11 additions & 4 deletions src/edit.sh
Expand Up @@ -4932,7 +4932,10 @@ function ble-edit/exec:gexec/TERM/enter {
# Note: ble/decode/rebind ではなく元の binding の記録・復元も含めてやり直す。
ble/edit/info/immediate-show text 'ble: TERM has changed. rebinding...'
ble/decode/detach
ble/decode/attach
if ! ble/decode/attach; then
ble-detach
ble-edit/bind/.check-detach && return 1
fi
ble/edit/info/immediate-clear
fi
}
Expand Down Expand Up @@ -4979,7 +4982,7 @@ function ble-edit/exec:gexec/.end {
ble/util/joblist.flush >&2
ble-edit/bind/.check-detach && return 0
ble/term/enter
ble-edit/exec:gexec/TERM/enter
ble-edit/exec:gexec/TERM/enter || return 0 # rebind に失敗した時 .tail せずに抜ける
[[ $1 == restore ]] && return 0 # Note: 前回の呼出で .end に失敗した時 #D1170
ble-edit/bind/.tail # flush will be called here
}
Expand Down Expand Up @@ -7426,7 +7429,7 @@ function ble/widget/.change-editing-mode {
set -o "$mode"
ble/decode/reset-default-keymap
ble/decode/detach
ble/decode/attach
ble/decode/attach || ble-detach
fi
else
bleopt default_keymap="$mode"
Expand Down Expand Up @@ -8237,7 +8240,11 @@ function ble-edit/bind/.check-detach {
if [[ ( $state == emacs || $state == vi ) && ! -o $state ]]; then
ble/decode/reset-default-keymap
ble/decode/detach
ble/decode/attach
if ! ble/decode/attach; then
ble-detach
ble-edit/bind/.check-detach # 改めて終了処理
return $?
fi
fi

return 1
Expand Down

0 comments on commit 24ea379

Please sign in to comment.