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: None
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.

 

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.)

Thanks,
Bernard.

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #3901:  fds.sh 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

 

CC list is empty

 

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):

 

 

Follows 1 latest change.

Date Changed By Updated Field Previous Value => Replaced By
Thu 18 Nov 2004 10:44:50 AM UTCNoneAttached File-=>Added fds.sh, #80

Back to the top


Powered by Savane 3.1-cleanup