[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
Mon Nov 19 19:40:29 UTC 2007

The following issue has been SUBMITTED. 
Reported By:                vomlehn
Assigned To:                BusyBox
Project:                    BusyBox
Issue ID:                   1597
Category:                   Other
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     assigned
Date Submitted:             11-19-2007 11:40 PST
Last Modified:              11-19-2007 11:40 PST
Summary:                    If stdout is not open, redirection to a file causes
that file to always be used as stdout
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

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.

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         

More information about the busybox-cvs mailing list