early: keep stdio files open
authorGabor Juhos <juhosg@openwrt.org>
Fri, 19 Jul 2013 06:43:35 +0000 (08:43 +0200)
committerJohn Crispin <blogic@openwrt.org>
Mon, 22 Jul 2013 06:18:46 +0000 (08:18 +0200)
At the end of the 'early_console' function, the
file descriptor is closed unconditionally. This
'close' call closes the stdio files if the fd
returned by the 'open(dev/console)' call equals
with any of the STD{IN,OUT,ERR}_FILENO values.
When this happens, all subsequent accesses to
the stdio files will fail and early console
access won't work.

To avoid this, don't close the file descriptor if
that equals with any of the STD*_FILENO values.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
early.c

diff --git a/early.c b/early.c
index 27d092971cd1437adc2dee08359d99225890eb77..204623b79ecc27ca2f357d8d83b4e0b319faf2bc 100644 (file)
--- a/early.c
+++ b/early.c
@@ -65,7 +65,11 @@ static void early_console(const char *dev)
        dup2(dd, STDIN_FILENO);
        dup2(dd, STDOUT_FILENO);
        dup2(dd, STDERR_FILENO);
-       close(dd);
+
+       if (dd != STDIN_FILENO &&
+           dd != STDOUT_FILENO &&
+           dd != STDERR_FILENO)
+               close(dd);
 }
 
 static void early_env(void)