diff options
Diffstat (limited to 'libdiskfs/console.c')
-rw-r--r-- | libdiskfs/console.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/libdiskfs/console.c b/libdiskfs/console.c index 885f527e..a4c3a1af 100644 --- a/libdiskfs/console.c +++ b/libdiskfs/console.c @@ -1,8 +1,7 @@ /* Redirect stdio to the console if possible - Copyright (C) 1995, 1996 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> + Copyright (C) 1995,96,98,99,2001 Free Software Foundation, Inc. + Written by Miles Bader <miles@gnu.org> This file is part of the GNU Hurd. @@ -31,24 +30,35 @@ #include <device/device.h> #include <hurd.h> -/* Make errors go somewhere reasonable. */ +#include "priv.h" + +/* Make sure errors go somewhere reasonable. */ void diskfs_console_stdio () { if (getpid () > 0) { - int fd = open ("/dev/console", O_RDWR); + if (write (2, "", 0) == 0) + /* We have a working stderr from our parent (e.g. settrans -a). + Just use it. */ + dup2 (2, 1); + else + { + int fd = open ("/dev/console", O_RDWR); - dup2 (fd, 0); - dup2 (fd, 1); - dup2 (fd, 2); - if (fd > 2) - close (fd); + dup2 (fd, 0); + dup2 (fd, 1); + dup2 (fd, 2); + if (fd > 2) + close (fd); + } } else { mach_port_t dev, cons; error_t err; + if (diskfs_boot_filesystem ()) + _diskfs_boot_privports (); err = get_privileged_ports (NULL, &dev); assert_perror (err); err = device_open (dev, D_READ|D_WRITE, "console", &cons); |