[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
exec 10>&- does not close fd 10
From: |
alex . dupuy |
Subject: |
exec 10>&- does not close fd 10 |
Date: |
Tue, 10 Oct 2006 15:07:08 -0400 |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: x86_64-redhat-linux-gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu'
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H -I. -I. -I./include -I./lib -D_GNU_SOURCE -O2 -g -pipe
-Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic
uname output: Linux doe 2.6.15-1.2054_FC5 #1 SMP Tue Mar 14 15:48:20 EST 2006
x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu
Bash Version: 3.1
Patch Level: 7
Release Status: release
Description:
While the exec command can be used with the special redirection
expression to close any of file descriptors 0-9, it does not work with
file descriptors of two or more digits. Other redirection syntax
*does* work with these, so it seems unlikely this is intentional.
Repeat-By:
lsof-self() { lsof -p $$ || ls -l /proc/self/fd; }
exec 9>/dev/null 10>/tmp/bash-exec-fd-bug
lsof-self # to see that fd 9 and 10 are open
exec 9>&- 10>&-
lsof-self # to see that fd 9 is now closed, but 10 is still open
# at this point, a bash-3.0 shell has (correctly) closed fds 9 & 10
# but a bash-3.1 shell has only close fd 9; but other redirection with
# double-digit-descriptors does work with bash-3.1, as shown below:
exec 11>&10-
lsof-self # to see that fd 10 (/tmp file) has moved to fd 11
exec 9>&11-
lsof-self # to see that fd 11 (/tmp file) has moved to fd 9
exec 9>&- # now we can close the fd!
Fix:
I don't have a fix for this, but I do have a workaround, which is to
use the file descriptor move operation to move the fd to a single-digit
descriptor number, and then close that, as shown at the end. The only
catch is that *moving* an already closed fd is an error, while closing
an already closed fd is not, so I have to make sure it is open (using
/proc/self/fd/) first.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- exec 10>&- does not close fd 10,
alex . dupuy <=