bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

'exec </dev/null' fails if ulimit -n 6


From: Paul Eggert
Subject: 'exec </dev/null' fails if ulimit -n 6
Date: Sat, 12 Nov 2011 16:15:40 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu' 
-DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/cs/bash-4.2/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2
uname output: Linux lnxsrvg1.seas.ucla.edu 2.6.18-274.7.1.el5 #1 SMP Mon Oct 17 
11:57:14 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

Bash Version: 4.2
Patch Level: 10
Release Status: release

Description:
        Bash can't do I/O redirection using 'exec' when operating
        in an environment where all FDs above 10 are taken, even
        if there are FDs available below 10.

        This caused a coreutils test case to fail.  There is a
        workaround, but the Bash bug should get fixed too.  See:
        <http://lists.gnu.org/archive/html/coreutils/2011-11/msg00036.html>.

Repeat-By:
        Run this command:

          bash -c 'ulimit -n 6; exec </dev/null && echo ok'

        This should output "ok", but instead it outputs:

          bash: redirection error: cannot duplicate fd: Invalid argument
          ./bash: /dev/null: Invalid argument

        Running 'strace' indicates the following set of syscalls:

          setrlimit(RLIMIT_NOFILE, {rlim_cur=6, rlim_max=6}) = 0
          open("/dev/null", O_RDONLY)             = 4
          fcntl(0, F_GETFD)                       = 0
          fcntl(0, F_DUPFD, 10)                   = -1 EINVAL (Invalid argument)
          fcntl(0, F_DUPFD, 10)                   = -1 EINVAL (Invalid argument)
          write(2, "./bash: redirection error: canno"..., 65./bash: redirection 
error: cannot duplicate fd: Invalid argument
          ) = 65

        So, Bash is unnecessarily dup'ing file descriptor 0 to 10-or-more,
        and then complaining because the dup fails.  But there is
        no reason to dup here.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]