Bug 179949 - endless loop caused by #!/bin/bash and BASH_ENV=~/.bashrc
endless loop caused by #!/bin/bash and BASH_ENV=~/.bashrc
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: initscripts (Show other bugs)
4
All Linux
medium Severity medium
: ---
: ---
Assigned To: Bill Nottingham
Brock Organ
:
: 179947 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-02-03 19:34 EST by Lidwien Engel-Ligtvoet
Modified: 2014-03-16 22:58 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-02-03 21:55:28 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Lidwien Engel-Ligtvoet 2006-02-03 19:34:28 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.0.7-1.1.fc4 Firefox/1.0.7

Description of problem:
After starting Vim on a console (/dev/tty2), inside of Vim I wanted to execute a command and then go to a subshell, using ":!time pwd" and ":sh".  Both times my commands were unresponsive until I hit ctrl-C.  I wanted to know what was going on, so I logged in on /dev/tty3 and started "top".  Then I started  :sh  inside of Vim again on the other console, /dev/tty2.  After a minute I noticed sudden disc activity (the system had started swapping) and after two minutes I switched to /dev/tty3 and in "top" I saw lots of instances of "unicode_start",
disappearing within seconds, used swap space dropping fast, then used memory dropping fast.
I can easily have the system run out of swap space if I start :sh from within Vim, then do nothing except to wait for several more minutes.
My environment:
TERM=linux
LANG=en_US.UTF-8
SHELL=/bin/bash
BASH_ENV=$HOME/.bashrc

If I do ":!time pwd" from within Vim on the console, wait for the command to finish, see nothing happen, then after several minutes I switch to /dev/tty4 and switch back to the Vim session, I get to see this:
/home/a3

real    0m0.000s
user    0m0.000s
sys     0m0.000s

The same kind of thing happens on another (slower, less memory) computer with Fedora Core 4 when I do  :!ls -l  and after several minutes of waiting I get: 

        /etc/profile.d/lang.sh: line 64: /sbin/consoletype: Too many open files in system
        /etc/bashrc: line 43: /etc/profile.d/less.sh: Too many open files in system
        /etc/bashrc: line 43: /etc/profile.d/qt.sh: Too many open files in system
        /etc/bashrc: line 43: /etc/profile.d/vim.sh: Too many open files in system
        /etc/bashrc: line 43: /etc/profile.d/which-2.sh: Too many open files in system
        /bin/bash: /bin/unicode_start: Too many open files in system
        /etc/bashrc: line 43: /etc/profile.d/less.sh: Too many open files in system
        /etc/bashrc: line 43: /etc/profile.d/qt.sh: Too many open files in system
        /etc/bashrc: line 43: /etc/profile.d/vim.sh: Too many open files in system
        /etc/bashrc: line 43: /etc/profile.d/which-2.sh: Too many open files in system
        /bin/bash: /bin/unicode_start: Too many open files in system
        etc. etc.


I tracked it down to this:
1. Vim starts a subshell by calling $SHELL (/bin/bash)
2. bash reads ~/.bashrc (according to $BASH_ENV)
3. .bashrc starts /etc/bashrc
4. /etc/bashrc executes /etc/profile.d/lang.sh from /etc/profile.d/*.sh
5. /etc/profile.d/lang.sh executes /bin/unicode_start
6. The first line of /bin/unicode_start says #!/bin/bash, so bash will be called
7. according to $BASH_ENV, bash executes ~/.bashrc (see also 2.), proceed to 3., proceed to 4., 5., 6. etc.

Version-Release number of selected component (if applicable):
initscripts-8.11.1-1

How reproducible:
Always

Steps to Reproduce:
1. Log in to two consoles, say /dev/tty2 and /dev/tty3, as an ordinary user.
2. ~/.bashrc should begin with if [ -f /etc/bashrc ]; then . /etc/bashrc; fi
3. Environment: 
TERM=linux
LANG=en_US.UTF-8
SHELL=/bin/bash
BASH_ENV=$HOME/.bashrc
4. Start Vim; from within Vim do :sh or some other shell command
5. Do nothing, just watch the system run out of swap space after several minutes

Actual Results:  The system ran out of swap space.


Expected Results:  The system shouldn't run out of swap space.

The problem can be fixed by changing "#!/bin/bash" into "#!/bin/sh" in /bin/unicode_start.

Additional info:

If you change the first line of /bin/unicode_start from "#!/bin/bash" to "#!/bin/sh" then the problem disappears!

The problem can also be reproduced as follows:

cat > /tmp/testing
        export TERM=linux
        export LANG=en_US.UTF-8
        export SHELL=/bin/bash
        echo . /etc/bashrc > /tmp/loops
        chmod +x /tmp/loops
        export BASH_ENV=/tmp/loops
        . /tmp/loops
[ctrl-D]

Then, on a console (e.g. /dev/tty2), execute the command:
        sh /tmp/testing
and wait for several minutes doing nothing...
Comment 1 Miloslav Trmač 2006-02-03 20:53:02 EST
*** Bug 179947 has been marked as a duplicate of this bug. ***
Comment 2 Bill Nottingham 2006-02-03 21:55:28 EST
You cannot have BASH_ENV set in your .bash_profile - it will cause loops. (See
#172059).

Note You need to log in before you can comment on or make changes to this bug.