summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdiskfs/console.c23
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
{