From 4e46c1b12f0b0f2cd3a31df83e48c6bb04c80d88 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Wed, 19 May 1999 18:14:58 +0000 Subject: 1999-05-19 Roland McGrath * 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. --- libdiskfs/console.c | 23 +++++++++++++++-------- 1 file 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 @@ -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 { -- cgit v1.2.3