[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf -u "$fd"?
From: |
Koichi Murase |
Subject: |
Re: printf -u "$fd"? |
Date: |
Wed, 22 May 2024 14:25:45 +0900 |
2024年5月22日(水) 0:15 Zachary Santer <zsanter@gmail.com>:
> Additionally, I was hoping the discussion of having a way to make fds
> not CLOEXEC without a loadable builtin[3][4] would get some more
> attention.
I haven't followed the discussion in the original thread for multiple
coprocs, but you can remove CLOEXEC relatively easily [1]:
# Requires Bash >= 4.0
function remove-cloexec {
local fd=$1
if ((fd!=0)); then
builtin eval -- "exec 0<&$fd $fd<&- $fd<&0" </dev/null
else
builtin eval -- "exec 1>&$fd $fd>&- $fd>&1" >/dev/null
fi
}
This uses Bash's behavior of removing CLOEXEC for standard streams
0,1,2. (This behavior is probably undocumented, but I haven't checked
the document carefully). Adding CLOEXEC is more complicated and
relying on some assumptions.
[1]
https://github.com/akinomyoga/ble.sh/blob/59787ee5528a8489e78ba09f712ed4b1f5a8e62f/src/util.sh#L3208-L3215
[2]
https://github.com/akinomyoga/ble.sh/blob/59787ee5528a8489e78ba09f712ed4b1f5a8e62f/src/util.sh#L3114-L3207
--
Koichi
- Re: printf -u "$fd"?, (continued)
- Re: printf -u "$fd"?, Chet Ramey, 2024/05/20
- Re: printf -u "$fd"?, Zachary Santer, 2024/05/21
- Re: printf -u "$fd"?, Chet Ramey, 2024/05/21
- Re: printf -u "$fd"?, Zachary Santer, 2024/05/21
- Re: printf -u "$fd"?, Chet Ramey, 2024/05/21
- Re: printf -u "$fd"?, Zachary Santer, 2024/05/22
- Re: printf -u "$fd"?, Zachary Santer, 2024/05/22
- Re: printf -u "$fd"?, Chet Ramey, 2024/05/22
- Re: printf -u "$fd"?,
Koichi Murase <=