Skip to content

Commit

Permalink
util.bgproc: fix an "fd#alloc" failure in bash-4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 3, 2023
1 parent d92fa4a commit 7c4ff7b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -142,6 +142,7 @@
- util.bgproc: separate `ble/util/bgproc` from `histdb` (motivated by bkerin) `#D2017` 7803305f
- util.bgproc: fix use of `ble/util/idle` in bash-3 `#D2026` xxxxxxxx
- util.bgproc: increase frequency of bgproc termination check (motivated by bkerin) `#D2027` xxxxxxxx
- util.bgproc: fix an `fd#alloc` failure in bash-4.2 `#D2029` xxxxxxxx
- menu-complete: support selection by index (requested by bkerin) `#D2023` b91b8bc8

## Changes
Expand Down
16 changes: 9 additions & 7 deletions lib/util.bgproc.sh
Expand Up @@ -5,10 +5,10 @@
## calling "ble/util/bgproc#close PREFIX". The background process is usually
## started on the start of the session and terminated on closing the session.
## In addition, if requested, the background process can be stopped and
## started any time in the session. If the background process is stopped
## when it is needed, it is automatically restarted. If "timeout=TIMEOUT" is
## specified in OPTS, the background process is automatically stopped where
## there is no access for the time duration specified by TIMEOUT.
## started any time in the session. If the background process is stopped, it
## is automatically restarted when it becomes needed. If "timeout=TIMEOUT"
## is specified in OPTS, the background process is automatically stopped
## where there is no access for the time duration specified by TIMEOUT.
##
## @param[in] prefix
## This names the identifier of the bgproc. This is actually used as the
Expand Down Expand Up @@ -231,11 +231,13 @@ function ble/util/bgproc#start {
[[ ! ${bgproc[1]-} ]] || ble/fd#close 'bgproc[1]'

# Note: mkfifo may fail in MSYS-1
local _ble_local_ext=0
local _ble_local_ext=0 _ble_local_bgproc0= _ble_local_bgproc1=
if ble/util/bgproc/.mkfifo &&
ble/fd#alloc 'bgproc[0]' '<> "${bgproc_fname[0]}"' &&
ble/fd#alloc 'bgproc[1]' '<> "${bgproc_fname[1]}"'
ble/fd#alloc _ble_local_bgproc0 '<> "${bgproc_fname[0]}"' &&
ble/fd#alloc _ble_local_bgproc1 '<> "${bgproc_fname[1]}"'
then
bgproc[0]=$_ble_local_bgproc0
bgproc[1]=$_ble_local_bgproc1
# Note: We want to assign a new process group to the background process
# without affecting the job table of the main shell so use the subshell
# `(...)'. The process group is later used to kill the process tree in
Expand Down
5 changes: 5 additions & 0 deletions note.txt
Expand Up @@ -6726,6 +6726,11 @@ bash_tips

2023-04-02

* bgproc: bash-4.2 での bgproc#start で {bgproc[0]} は存在しないというエラーメッセージ [#D2029]

これは exec {fdvar}redirect で発生しているエラーだった。bash-4.1,4.2では
{fdvar} の fdvar として配列要素には対応していない。

* bgproc: シェルの終了時に即座に強制終了するオプションをつける? (motivated by bkerin) [#D2028]
https://github.com/akinomyoga/ble.sh/discussions/309#discussioncomment-5498921

Expand Down

0 comments on commit 7c4ff7b

Please sign in to comment.