]> andersk Git - openssh.git/blobdiff - pty.c
- (bal) Changed from GNU rx to PCRE on suggestion from djm.
[openssh.git] / pty.c
diff --git a/pty.c b/pty.c
index bffac4e539cd8f9bbb216e36763e58931afc9341..04004d20f672ec3ab05a88b2363f6bc02b68e40b 100644 (file)
--- a/pty.c
+++ b/pty.c
@@ -1,20 +1,18 @@
 /*
- *
- * pty.c
- *
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
- *
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  *                    All rights reserved
- *
- * Created: Fri Mar 17 04:37:25 1995 ylo
- *
  * Allocating a pseudo-terminal, and making it the controlling tty.
  *
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose.  Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
  */
 
 #include "includes.h"
-RCSID("$Id$");
+RCSID("$OpenBSD: pty.c,v 1.16 2000/09/07 21:13:37 markus Exp $");
 
 #ifdef HAVE_UTIL_H
 # include <util.h>
@@ -118,6 +116,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
                close(*ptyfd);
                return 0;
        }
+#ifndef HAVE_CYGWIN
        /* Push the appropriate streams modules, as described in Solaris pts(7). */
        if (ioctl(*ttyfd, I_PUSH, "ptem") < 0)
                error("ioctl I_PUSH ptem: %.100s", strerror(errno));
@@ -126,6 +125,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
 #ifndef _HPUX_SOURCE
        if (ioctl(*ttyfd, I_PUSH, "ttcompat") < 0)
                error("ioctl I_PUSH ttcompat: %.100s", strerror(errno));
+#endif
 #endif
        return 1;
 #else /* HAVE_DEV_PTMX */
@@ -162,12 +162,19 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
        for (i = 0; i < num_ptys; i++) {
                snprintf(buf, sizeof buf, "/dev/pty%c%c", ptymajors[i / num_minors],
                         ptyminors[i % num_minors]);
-               *ptyfd = open(buf, O_RDWR | O_NOCTTY);
-               if (*ptyfd < 0)
-                       continue;
                snprintf(namebuf, namebuflen, "/dev/tty%c%c",
                    ptymajors[i / num_minors], ptyminors[i % num_minors]);
 
+               *ptyfd = open(buf, O_RDWR | O_NOCTTY);
+               if (*ptyfd < 0) {
+                       /* Try SCO style naming */
+                       snprintf(buf, sizeof buf, "/dev/ptyp%d", i);
+                       snprintf(namebuf, namebuflen, "/dev/ttyp%d", i);
+                       *ptyfd = open(buf, O_RDWR | O_NOCTTY);
+                       if (*ptyfd < 0)
+                               continue;
+               }       
+                       
                /* Open the slave side. */
                *ttyfd = open(namebuf, O_RDWR | O_NOCTTY);
                if (*ttyfd < 0) {
@@ -201,6 +208,9 @@ void
 pty_make_controlling_tty(int *ttyfd, const char *ttyname)
 {
        int fd;
+#ifdef USE_VHANGUP
+       void *old;
+#endif /* USE_VHANGUP */
 
        /* First disconnect from the old controlling tty. */
 #ifdef TIOCNOTTY
@@ -232,12 +242,26 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
         */
        ioctl(*ttyfd, TIOCSCTTY, NULL);
 #endif /* TIOCSCTTY */
+#ifdef HAVE_NEWS4
+       if (setpgrp(0,0) < 0)
+               error("SETPGRP %s",strerror(errno));
+#endif /* HAVE_NEWS4 */
+#ifdef USE_VHANGUP
+       old = signal(SIGHUP, SIG_IGN);
+       vhangup();
+       signal(SIGHUP, old);
+#endif /* USE_VHANGUP */
        fd = open(ttyname, O_RDWR);
-       if (fd < 0)
+       if (fd < 0) {
                error("%.100s: %.100s", ttyname, strerror(errno));
-       else
+       } else {
+#ifdef USE_VHANGUP
+               close(*ttyfd);
+               *ttyfd = fd;
+#else /* USE_VHANGUP */
                close(fd);
-
+#endif /* USE_VHANGUP */
+       }
        /* Verify that we now have a controlling tty. */
        fd = open("/dev/tty", O_WRONLY);
        if (fd < 0)
This page took 0.037701 seconds and 4 git commands to generate.