diff options
author | Roland McGrath <roland@gnu.org> | 1999-05-19 18:14:58 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1999-05-19 18:14:58 +0000 |
commit | 4e46c1b12f0b0f2cd3a31df83e48c6bb04c80d88 (patch) | |
tree | 0954d4cc5999d696aca50a8b3f23e191a2bb051b | |
parent | 1db06536226ad3bee54164aa9c9761e2e79070a3 (diff) |
1999-05-19 Roland McGrath <roland@baalperazim.frob.com>
* console.c (diskfs_console_stdio): If there is an fd 2 that appears
to work, just leave it as is and dup2 it to fd 1 as well.
-rw-r--r-- | libdiskfs/console.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/libdiskfs/console.c b/libdiskfs/console.c index 5c6dd4be..a7113ace 100644 --- a/libdiskfs/console.c +++ b/libdiskfs/console.c @@ -1,6 +1,6 @@ /* Redirect stdio to the console if possible - Copyright (C) 1995, 96, 98 Free Software Foundation, Inc. + Copyright (C) 1995, 96, 98, 99 Free Software Foundation, Inc. Written by Miles Bader <miles@gnu.ai.mit.edu> @@ -33,19 +33,26 @@ #include "priv.h" -/* Make errors go somewhere reasonable. */ +/* 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 { |