Skip to content

Commit

Permalink
global: fix status check for read timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 20, 2021
1 parent 69248ff commit e886883
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion memo/ChangeLog.md
Expand Up @@ -56,7 +56,8 @@
- global: refactor `setup => set up / set-up` `#D1456` c37a9dd
- global: clean up helps of user functions `#D1459` 33c283e
- benchmark (`ble-measure`): support `-T TIME` and `-B TIME` option `#D1460` 1aa471b
- util, color (`bleopt`, `blehook`, `ble-color-setface`): support `--color` and fix `sgr0` contamination in non-color output `#D1466` 0000000
- util, color (`bleopt`, `blehook`, `ble-color-setface`): support `--color` and fix `sgr0` contamination in non-color output `#D1466` 69248ff
- global: fix status check for read timeout `#D1467` 0000000

<!---------------------------------------------------------------------------->
# ble-0.4.0-devel2
Expand Down
15 changes: 15 additions & 0 deletions note.txt
Expand Up @@ -3813,6 +3813,21 @@ bash_tips

2021-02-04

* global: read timeout は $?==142 とは限らない [#D1467]

read timeout は本当に常に 142 なのか。と思ったが現在の用例では 142 は
conditional-sync によって固定で返されているので気にしなくて良い。因みに
bash のソースコードを確認する限りは 142 は hardcoded ではない。

* edit (ble/builtin/read/.loop): うーん。予め 142 に対応する終了ステータス
を調べておくか、或いは 128 以上を一括で timeout と解釈するか。マニュアル
には "128 より大きな値になる" とだけ書かれている。マニュアルに従った判定
にするのが良い気がする。

* util (ble/util/msleep/.use-read-timeout): これは現在は使っていない。何れ
にしても Cygwin/MSYS の時にだけチェックする様にすれば、これらのシステムで
は 142 固定と期待されるので大丈夫。

* util (bleopt): bleopt でパイプに繋いでいても _ble_term_sgr0 が出力されている場合がある [#D1466]
追加で関連する関数に於いて --color オプションで着色を制御できるようにする。
* "--color" options for bleopt, blehook, ble-color-setface
Expand Down
4 changes: 3 additions & 1 deletion src/edit.sh
Expand Up @@ -7468,8 +7468,10 @@ function ble/builtin/read/.loop {

# read 1 character
TMOUT= IFS= builtin read -r -d '' -n 1 $timeout_option char "${opts_in[@]}"; local ext=$?
if ((ext==142)); then
if ((ext>128)); then
# timeout
# Note: #D1467 Cygwin/Linux では read の timeout は 142 だが、これはシステム依存。
# man bash にある様に 128 より大きいかどうかで判定する。
_ble_edit_read_accept=142
break
fi
Expand Down
6 changes: 4 additions & 2 deletions src/util.sh
Expand Up @@ -2642,9 +2642,11 @@ function ble/util/msleep/.use-read-timeout {
esac

# Note: 古い Cygwin では双方向パイプで "Communication error on send" というエラーになる。
# 期待通りの振る舞いをしなかったらプロセス置換に置き換える。 #D1449
# 期待通りの振る舞いをしなかったらプロセス置換に置き換える。 #D1449
# #D1467 Cygwin/Linux では timeout は 142 だが、これはシステム依存。
# man bash にある様に 128 より大きいかどうかで判定
if [[ :$opts: == *:check:* && $_ble_util_msleep_fd ]]; then
if builtin read -t 0.000001 -u "$_ble_util_msleep_fd" _ble_util_msleep_dummy 2>/dev/null; (($?!=142)); then
if builtin read -t 0.000001 -u "$_ble_util_msleep_fd" _ble_util_msleep_dummy 2>/dev/null; (($?<=128)); then
ble/fd#close _ble_util_msleep_fd
_ble_util_msleep_fd=
return 1
Expand Down

0 comments on commit e886883

Please sign in to comment.