On 2022-11-26 14:05, "凋叶棕" via Bug reports for the GNU Bourne Again
SHell wrote:
Hello,
I find that the file descriptor leaks when I execute the command pvs
in bash 5.2, The abnormal scenario is similar to the bug which
reported by
http://lists.gnu.org/archive/html/bug-bash/2017-01/msg00026.html
When I execute pvs in the terminal opened through xshell,it’s ok
PV VG Fmt Attr PSize PFree
/dev/sda2 euleros lvm2 a-- <126.00g 0
But when I execute pvs in the terminal opened through vscode(use
Remote-SHH to connect linux), the File descriptor was leaked
File descriptor 19 (/dev/ptmx) leaked on pvs invocation. Parent PID
3789: /usr/bin/bash
File descriptor 20 (/dev/ptmx) leaked on pvs invocation. Parent PID
3789: /usr/bin/bash
File descriptor 21 (/dev/ptmx) leaked on pvs invocation. Parent PID
3789: /usr/bin/bash
File descriptor 99
(/root/.vscode-server/bin/899d46d82c4c95423fb7e10e68eba52050e30ba3/vscode-remote-lock.root.899d46d82c4c95423fb7e10e68eba52050e30ba3)
leaked on pvs invocation. Parent PID 3789: /usr/bin/bash
PV VG Fmt Attr PSize PFree
/dev/sda2 euleros lvm2 a-- <126.00g 0
I found that the leaked file descriptor was created in subst.c
/* Pipe the output of executing STRING into the current shell. */
if (pipe(fildes) < 0)
{
sys_error("%s", _("cannot make pipe for command substitution"));
goto error_exit;
}
add it leaked in
if (--bufn <= 0)
{
SET_CLOSE_ON_EXEC(fd);
bufn = zread(fd, buf, sizeof(buf));
if (bufn <= 0)
break;
bufp = buf;
}
I try to add SET_CLOSE_ON_EXEC (fd) before zread, but it doesn't seem
to work.
Same behavior was in bash 4.4 (as well as now in bash 5.2):
# echo $BASH_VERSION
4.4.0(1)-release
# exec 66</etc/hosts
# pvs
File descriptor 66 (/etc/hosts) leaked on pvs invocation. Parent PID
1057606: ./bash
But we use the fact tat bash doesn't close FD for example to preliminary
open log file for utility that we will `exec' later.
Unfortunately bash doesn't provide any fcntl() mechanism to control FD
flags.
It'll be great to have ability to manage CLOEXEC or any other FD flags
from the script.
Regards,
Alexey.