[BusyBox 0001597]: If stdout is not open, redirection to a file causes that file to always be used as stdout

bugs at busybox.net bugs at busybox.net
Tue Nov 20 01:24:40 UTC 2007


A NOTE has been added to this issue. 
====================================================================== 
http://busybox.net/bugs/view.php?id=1597 
====================================================================== 
Reported By:                vomlehn
Assigned To:                BusyBox
====================================================================== 
Project:                    BusyBox
Issue ID:                   1597
Category:                   Other
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     feedback
====================================================================== 
Date Submitted:             11-19-2007 11:40 PST
Last Modified:              11-19-2007 17:24 PST
====================================================================== 
Summary:                    If stdout is not open, redirection to a file causes
that file to always be used as stdout
Description: 
I am booting an INITRAMFS filesystem in which /init is a script that starts
with "#!/bin/sh" and, so, invokes busybox. My console is a USB serial
device and things work normally if I have a serial device attached. If I
boot my system with no USB serial device attached, the open of
/dev/console fails and the busybox has no open file descriptors when it
starts.

In my /init script, I use:
    echo /sbin/hotplug >/proc/sys/kernel/hotplug
The correct data is put into that pseudo-file. The problem is that
subsequent output is *also* put into that pseudo-file. This is a big
problem since my hotplug script is no longer getting run.

My guess is that, when cleaning up after a command, busybox closes all
file descriptors except for 0, 1, and 2 (standard in, out, and error).
This would be incorrect behavior. I think it should close *every* file
descriptor opened by the command. This would restore it to having no file
descriptors open, which would prevent data from going to the wrong file.

There appear to be two ways to implement this:
1. Keep track of every open and close, and close everything opened during
invocation of a command.
2. Determine whether file descriptors 0, 1, and 2 are open at
initialization, at command termination, close each one that wasn't open.
====================================================================== 

---------------------------------------------------------------------- 
 vda - 11-19-07 17:23  
---------------------------------------------------------------------- 
Which version of busybox do you use? Sometime ago, busybox's init was
changed
to NOT try to open /dev/console, but just use whatever fd's were passed to
it by kernel.
Which shell is configured to be "sh" (ash,msh,hush,lash?) 

---------------------------------------------------------------------- 
 vda - 11-19-07 17:24  
---------------------------------------------------------------------- 
Oh, I see. You don't use busybox's init. so that fix is not applicable. But
I still need to know version and shell. 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
11-19-07 11:40  vomlehn        New Issue                                    
11-19-07 11:40  vomlehn        Status                   new => assigned     
11-19-07 11:40  vomlehn        Assigned To               => BusyBox         
11-19-07 17:23  vda            Note Added: 0002940                          
11-19-07 17:23  vda            Status                   assigned => feedback
11-19-07 17:24  vda            Note Added: 0002941                          
======================================================================




More information about the busybox-cvs mailing list