Skip to content

Commit

Permalink
main: record external file descriptors on "ble-attach"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 28, 2024
1 parent bf59529 commit a508a82
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
6 changes: 6 additions & 0 deletions ble.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,12 @@ function ble-attach {
#%end.i
fi

# reconnect standard streams
ble/fd/save-external-standard-streams
exec 0<&"$_ble_util_fd_tui_stdin"
exec 1>&"$_ble_util_fd_tui_stdout"
exec 2>&"$_ble_util_fd_tui_stderr"

# char_width_mode=auto
ble/canvas/attach
#%if leakvar
Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
- util: support `ble/fd#add-cloexec` and add `O_CLOEXEC` by default `#D2158` 785267e1
- util: fix error of bad file descriptors (reported by ragnarov) `#D2159` 785267e1
- util: work around macOS/FreeBSD failure on `exec 32>&2` (reported by tessus, jon-hotaisle) `#D2165` 8f0dfe9b
- main: record external file descriptors on `ble-attach` `#D2183` xxxxxxxx
- main: fix unprocessed `-PGID` in `*.pid` for cleanup `#D2143` a5da23c0
- history: prevent `SIGPIPE` from reverting the TTY state in trap `EXIT` `#D2153` 4b8a0799
- history: fix initially shifted history index `#D2180` xxxxxxxx
Expand Down
12 changes: 6 additions & 6 deletions note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1955,12 +1955,6 @@ bash_tips
* bug-bash: bash-3.1..dev exec fd1<&"$var"- で $var の fd が存在しない時のエ
ラーメッセージが fd1 が存在しない、という物になっている。

2024-02-19

* _ble_util_fd_cmd_std* は ble-attach の時の物を覚えるべき。prompt attach で
はそちらの方が安全。警告メッセージが嫌で source ble.sh 2>/dev/null とする人
がいるので。というか ble-attach の時に改めて tui から fd を dup するべき。

2024-02-14

* complete: / の入った関数名で曖昧補完できていない?
Expand Down Expand Up @@ -7375,6 +7369,12 @@ bash_tips

2024-02-25

* 2024-02-19 _ble_util_fd_cmd_std* は ble-attach の時の物を覚えるべき [#D2183]

prompt attach ではそちらの方が安全。警告メッセージが嫌で source ble.sh
2>/dev/null とする人がいるので。というか ble-attach の時に改めて tui から
fd を dup するべき。

* 2024-02-08 bleopt: wildcard @ は 0文字以上に一致するべきでは [#D2182]
Ref #D1568 #D1861

Expand Down
7 changes: 1 addition & 6 deletions src/edit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7133,12 +7133,7 @@ function ble-edit/exec:gexec/.save-lastarg {
# stderr (2) are redirected to /dev/null to suppress "set -x" messages in
# this context. Instead, we use 4 and 5 because stdout and stderr are copied
# to 4 and 5, respectively, by the caller.
ble/fd#alloc _ble_util_fd_cmd_stdin '<&0' base:overwrite
ble/fd#alloc _ble_util_fd_cmd_stdout '>&4' base:overwrite
ble/fd#alloc _ble_util_fd_cmd_stderr '>&5' base:overwrite
ble/fd#add-cloexec "$_ble_util_fd_cmd_stdin"
ble/fd#add-cloexec "$_ble_util_fd_cmd_stdout"
ble/fd#add-cloexec "$_ble_util_fd_cmd_stderr"
ble/fd/save-external-standard-streams 0 4 5

return "$_ble_edit_exec_lastexit"
}
Expand Down
13 changes: 13 additions & 0 deletions src/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3408,6 +3408,19 @@ ble/fd/.initialize-standard-stream stdin '0<'
ble/fd/.initialize-standard-stream stdout '1>'
ble/fd/.initialize-standard-stream stderr '2>'

## @fn ble/fd/save-external-standard-streams [fd_in fd_out fd_err]
## @var[in,opt] fd_in fd_out fd_err
## Specify the source file descriptors that are saved as standard streams
## for the external state.
function ble/fd/save-external-standard-streams {
ble/fd#alloc _ble_util_fd_cmd_stdin "<&${1:-0}" base:overwrite
ble/fd#alloc _ble_util_fd_cmd_stdout ">&${2:-1}" base:overwrite
ble/fd#alloc _ble_util_fd_cmd_stderr ">&${3:-2}" base:overwrite
ble/fd#add-cloexec "$_ble_util_fd_cmd_stdin"
ble/fd#add-cloexec "$_ble_util_fd_cmd_stdout"
ble/fd#add-cloexec "$_ble_util_fd_cmd_stderr"
}

function ble/fd#close-all-tty {
local ret
ble/fd#list
Expand Down

0 comments on commit a508a82

Please sign in to comment.