helpThe GNU Bourne-Again SHell - Support: sr #103583, Bash redirection undo file...


sr #103583: Bash redirection undo file descriptors not closed before forking off processes.

Submitted by:  None
Submitted on:  Thu 18 Nov 2004 10:44:50 AM UTC  
Category: NonePriority: 5 - Normal
Severity: 3 - NormalStatus: Done
Privacy: PublicAssigned to: None
Originator Email: -unavailable-Open/Closed: Open
Operating System: None

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


Wed 25 Mar 2015 02:54:16 PM UTC, comment #1:

Not reproducible,

dualbus@yaqui ~ % bash
total 0
lr-x------ 1 dualbus dualbus 64 Mar 25 08:53 0 -> /dev/null
l-wx------ 1 dualbus dualbus 64 Mar 25 08:53 1 -> /dev/null
l-wx------ 1 dualbus dualbus 64 Mar 25 08:53 2 -> /dev/null
c is 3

Eduardo Bustamante <dualbus>
Thu 18 Nov 2004 10:44:50 AM UTC, original submission:

With some elaborate redirections, it appears that some file descriptors are not being closed prior to spawning off processes. After running the attached script, one can observe the FDs of the sleep process by typing:

$ ls -l /proc/`pidof sleep`/fd/

This gives:
total 4
lr-x------ 1 b b 64 Nov 18 18:32 0 -> /dev/null
l-wx------ 1 b b 64 Nov 18 18:32 1 -> /dev/null
l-wx------ 1 b b 64 Nov 18 18:32 10 -> pipe:[245971]
l-wx------ 1 b b 64 Nov 18 18:32 2 -> /dev/null

As you can see, there is an extra FD 10 there which is inherited by sleep. The other end of that pipe is attached to the script. Hence the script will hang until the sleep process terminates (or whatever other long-lived process or daemon is spawned by this script).

Looking at bash's source, it appears related to the add_undo_redirect function and its actions. (Should the FD have the close-on-exec flag set?)

The same script operates correctly under zsh and dash.

(The reasons for the crazy redirections is to obtain the exit status of "Stuff" portably. In bash, PIPESTATUS would suffice but is not portable.)




(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):

Attached Files
file #3901: added by None (167B - text/x-sh - Example script to demonstrate bug.)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by chet (Updated the item)
  • -unavailable- added by dualbus (Posted a comment)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 12 Nov 2015 01:27:59 PM UTCchetStatusNone=>Done
    Thu 18 Nov 2004 10:44:50 AM UTCNoneAttached File-=>Added, #80

    Back to the top

    Powered by Savane 3.1-cleanup