summaryrefslogtreecommitdiff
path: root/utils/shd.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-01-28 20:02:04 +0000
committerRoland McGrath <roland@gnu.org>1995-01-28 20:02:04 +0000
commit8ff69ce0b0dca330c596bb5276aaa653d049763e (patch)
treeef6129b6a4f847a532eebe0b5343b8b81a0b9b8a /utils/shd.c
parent1d862406db123c28d5007865afa316c9b48036d0 (diff)
(main): Only open /dev/tty if stdin is unreadable.
Diffstat (limited to 'utils/shd.c')
-rw-r--r--utils/shd.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/utils/shd.c b/utils/shd.c
index 8a8db3af..8e260ccf 100644
--- a/utils/shd.c
+++ b/utils/shd.c
@@ -237,15 +237,16 @@ main ()
exec_init (getdport (0), getauth (),
MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND);
- {
- int ttyd = open ("/dev/tty", O_RDWR|O_IGNORE_CTTY);
- if (ttyd >= 0)
- {
- fcntl (ttyd, F_SETFD, FD_CLOEXEC);
- stdin = fdopen (ttyd, "r");
- stdout = stderr = fdopen (ttyd, "w");
- }
- }
+ if ((fcntl (0, F_GETFL) & O_READ) == 0)
+ {
+ int ttyd = open ("/dev/tty", O_RDWR|O_IGNORE_CTTY);
+ if (ttyd >= 0)
+ {
+ fcntl (ttyd, F_SETFD, FD_CLOEXEC);
+ stdin = fdopen (ttyd, "r");
+ stdout = stderr = fdopen (ttyd, "w");
+ }
+ }
atexit ((void (*) (void)) &sync);