summaryrefslogtreecommitdiff
path: root/pty.c
diff options
context:
space:
mode:
Diffstat (limited to 'pty.c')
-rw-r--r--pty.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/pty.c b/pty.c
index 34ed48d61..e46842138 100644
--- a/pty.c
+++ b/pty.c
@@ -14,7 +14,7 @@
14 */ 14 */
15 15
16#include "includes.h" 16#include "includes.h"
17RCSID("$Id: pty.c,v 1.4 1999/11/24 13:26:22 damien Exp $"); 17RCSID("$Id: pty.c,v 1.5 1999/11/25 00:54:59 damien Exp $");
18 18
19#include "pty.h" 19#include "pty.h"
20#include "ssh.h" 20#include "ssh.h"
@@ -32,10 +32,12 @@ RCSID("$Id: pty.c,v 1.4 1999/11/24 13:26:22 damien Exp $");
32#define O_NOCTTY 0 32#define O_NOCTTY 0
33#endif 33#endif
34 34
35/* Allocates and opens a pty. Returns 0 if no pty could be allocated, 35/*
36 or nonzero if a pty was successfully allocated. On success, open file 36 * Allocates and opens a pty. Returns 0 if no pty could be allocated, or
37 descriptors for the pty and tty sides and the name of the tty side are 37 * nonzero if a pty was successfully allocated. On success, open file
38 returned (the buffer must be able to hold at least 64 characters). */ 38 * descriptors for the pty and tty sides and the name of the tty side are
39 * returned (the buffer must be able to hold at least 64 characters).
40 */
39 41
40int 42int
41pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) 43pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
@@ -52,8 +54,10 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
52 return 1; 54 return 1;
53#else /* HAVE_OPENPTY */ 55#else /* HAVE_OPENPTY */
54#ifdef HAVE__GETPTY 56#ifdef HAVE__GETPTY
55 /* _getpty(3) exists in SGI Irix 4.x, 5.x & 6.x -- it generates 57 /*
56 more pty's automagically when needed */ 58 * _getpty(3) exists in SGI Irix 4.x, 5.x & 6.x -- it generates more
59 * pty's automagically when needed
60 */
57 char *slave; 61 char *slave;
58 62
59 slave = _getpty(ptyfd, O_RDWR, 0622, 0); 63 slave = _getpty(ptyfd, O_RDWR, 0622, 0);
@@ -72,8 +76,10 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
72 return 1; 76 return 1;
73#else /* HAVE__GETPTY */ 77#else /* HAVE__GETPTY */
74#ifdef HAVE_DEV_PTMX 78#ifdef HAVE_DEV_PTMX
75 /* This code is used e.g. on Solaris 2.x. (Note that Solaris 2.3 79 /*
76 also has bsd-style ptys, but they simply do not work.) */ 80 * This code is used e.g. on Solaris 2.x. (Note that Solaris 2.3
81 * also has bsd-style ptys, but they simply do not work.)
82 */
77 int ptm; 83 int ptm;
78 char *pts; 84 char *pts;
79 85
@@ -103,8 +109,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
103 close(*ptyfd); 109 close(*ptyfd);
104 return 0; 110 return 0;
105 } 111 }
106 /* Push the appropriate streams modules, as described in Solaris 112 /* Push the appropriate streams modules, as described in Solaris pts(7). */
107 pts(7). */
108 if (ioctl(*ttyfd, I_PUSH, "ptem") < 0) 113 if (ioctl(*ttyfd, I_PUSH, "ptem") < 0)
109 error("ioctl I_PUSH ptem: %.100s", strerror(errno)); 114 error("ioctl I_PUSH ptem: %.100s", strerror(errno));
110 if (ioctl(*ttyfd, I_PUSH, "ldterm") < 0) 115 if (ioctl(*ttyfd, I_PUSH, "ldterm") < 0)
@@ -138,8 +143,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
138 /* BSD-style pty code. */ 143 /* BSD-style pty code. */
139 char buf[64]; 144 char buf[64];
140 int i; 145 int i;
141 const char *ptymajors = 146 const char *ptymajors = "pqrstuvwxyzabcdefghijklmnoABCDEFGHIJKLMNOPQRSTUVWXYZ";
142 "pqrstuvwxyzabcdefghijklmnoABCDEFGHIJKLMNOPQRSTUVWXYZ";
143 const char *ptyminors = "0123456789abcdef"; 147 const char *ptyminors = "0123456789abcdef";
144 int num_minors = strlen(ptyminors); 148 int num_minors = strlen(ptyminors);
145 int num_ptys = strlen(ptymajors) * num_minors; 149 int num_ptys = strlen(ptymajors) * num_minors;
@@ -198,8 +202,10 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
198 if (setsid() < 0) 202 if (setsid() < 0)
199 error("setsid: %.100s", strerror(errno)); 203 error("setsid: %.100s", strerror(errno));
200 204
201 /* Verify that we are successfully disconnected from the 205 /*
202 controlling tty. */ 206 * Verify that we are successfully disconnected from the controlling
207 * tty.
208 */
203 fd = open("/dev/tty", O_RDWR | O_NOCTTY); 209 fd = open("/dev/tty", O_RDWR | O_NOCTTY);
204 if (fd >= 0) { 210 if (fd >= 0) {
205 error("Failed to disconnect from controlling tty."); 211 error("Failed to disconnect from controlling tty.");
@@ -208,9 +214,11 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
208 /* Make it our controlling tty. */ 214 /* Make it our controlling tty. */
209#ifdef TIOCSCTTY 215#ifdef TIOCSCTTY
210 debug("Setting controlling tty using TIOCSCTTY."); 216 debug("Setting controlling tty using TIOCSCTTY.");
211 /* We ignore errors from this, because HPSUX defines TIOCSCTTY, 217 /*
212 but returns EINVAL with these arguments, and there is 218 * We ignore errors from this, because HPSUX defines TIOCSCTTY, but
213 absolutely no documentation. */ 219 * returns EINVAL with these arguments, and there is absolutely no
220 * documentation.
221 */
214 ioctl(*ttyfd, TIOCSCTTY, NULL); 222 ioctl(*ttyfd, TIOCSCTTY, NULL);
215#endif /* TIOCSCTTY */ 223#endif /* TIOCSCTTY */
216 fd = open(ttyname, O_RDWR); 224 fd = open(ttyname, O_RDWR);