Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Try harder to find a tty.



details:   https://anonhg.NetBSD.org/src/rev/a999713c9d3a
branches:  trunk
changeset: 525377:a999713c9d3a
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Apr 10 15:52:07 2002 +0000

description:
Try harder to find a tty.

diffstat:

 bin/sh/jobs.c |  15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diffs (36 lines):

diff -r 395294e20ff8 -r a999713c9d3a bin/sh/jobs.c
--- a/bin/sh/jobs.c     Wed Apr 10 15:44:23 2002 +0000
+++ b/bin/sh/jobs.c     Wed Apr 10 15:52:07 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: jobs.c,v 1.44 2002/04/03 14:30:44 christos Exp $       */
+/*     $NetBSD: jobs.c,v 1.45 2002/04/10 15:52:07 christos Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)jobs.c     8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: jobs.c,v 1.44 2002/04/03 14:30:44 christos Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.45 2002/04/10 15:52:07 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -152,8 +152,15 @@
                int err;
                if (ttyfd != -1)
                        close(ttyfd);
-               if ((ttyfd = open("/dev/tty", O_RDWR)) == -1)
-                       goto out;
+               if ((ttyfd = open("/dev/tty", O_RDWR)) == -1) {
+                       int i;
+                       for (i = 0; i < 3; i++) {
+                               if (isatty(i) && (ttyfd = dup(i)) != -1)
+                                       break;
+                       }
+                       if (i == 3)
+                               goto out;
+               }
 #ifdef FIOCLEX
                err = ioctl(ttyfd, FIOCLEX, 0);
 #elif FD_CLOEXEC



Home | Main Index | Thread Index | Old Index