version 1.7, 1999/11/24 00:26:02 |
version 1.8, 1999/11/24 19:53:48 |
|
|
#define O_NOCTTY 0 |
#define O_NOCTTY 0 |
#endif |
#endif |
|
|
/* Allocates and opens a pty. Returns 0 if no pty could be allocated, |
/* |
or nonzero if a pty was successfully allocated. On success, open file |
* Allocates and opens a pty. Returns 0 if no pty could be allocated, or |
descriptors for the pty and tty sides and the name of the tty side are |
* nonzero if a pty was successfully allocated. On success, open file |
returned (the buffer must be able to hold at least 64 characters). */ |
* descriptors for the pty and tty sides and the name of the tty side are |
|
* returned (the buffer must be able to hold at least 64 characters). |
|
*/ |
|
|
int |
int |
pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) |
pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) |
|
|
return 1; |
return 1; |
#else /* HAVE_OPENPTY */ |
#else /* HAVE_OPENPTY */ |
#ifdef HAVE__GETPTY |
#ifdef HAVE__GETPTY |
/* _getpty(3) exists in SGI Irix 4.x, 5.x & 6.x -- it generates |
/* |
more pty's automagically when needed */ |
* _getpty(3) exists in SGI Irix 4.x, 5.x & 6.x -- it generates more |
|
* pty's automagically when needed |
|
*/ |
char *slave; |
char *slave; |
|
|
slave = _getpty(ptyfd, O_RDWR, 0622, 0); |
slave = _getpty(ptyfd, O_RDWR, 0622, 0); |
|
|
return 1; |
return 1; |
#else /* HAVE__GETPTY */ |
#else /* HAVE__GETPTY */ |
#ifdef HAVE_DEV_PTMX |
#ifdef HAVE_DEV_PTMX |
/* This code is used e.g. on Solaris 2.x. (Note that Solaris 2.3 |
/* |
also has bsd-style ptys, but they simply do not work.) */ |
* This code is used e.g. on Solaris 2.x. (Note that Solaris 2.3 |
|
* also has bsd-style ptys, but they simply do not work.) |
|
*/ |
int ptm; |
int ptm; |
char *pts; |
char *pts; |
|
|
|
|
close(*ptyfd); |
close(*ptyfd); |
return 0; |
return 0; |
} |
} |
/* Push the appropriate streams modules, as described in Solaris |
/* Push the appropriate streams modules, as described in Solaris pts(7). */ |
pts(7). */ |
|
if (ioctl(*ttyfd, I_PUSH, "ptem") < 0) |
if (ioctl(*ttyfd, I_PUSH, "ptem") < 0) |
error("ioctl I_PUSH ptem: %.100s", strerror(errno)); |
error("ioctl I_PUSH ptem: %.100s", strerror(errno)); |
if (ioctl(*ttyfd, I_PUSH, "ldterm") < 0) |
if (ioctl(*ttyfd, I_PUSH, "ldterm") < 0) |
|
|
/* BSD-style pty code. */ |
/* BSD-style pty code. */ |
char buf[64]; |
char buf[64]; |
int i; |
int i; |
const char *ptymajors = |
const char *ptymajors = "pqrstuvwxyzabcdefghijklmnoABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
"pqrstuvwxyzabcdefghijklmnoABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
const char *ptyminors = "0123456789abcdef"; |
const char *ptyminors = "0123456789abcdef"; |
int num_minors = strlen(ptyminors); |
int num_minors = strlen(ptyminors); |
int num_ptys = strlen(ptymajors) * num_minors; |
int num_ptys = strlen(ptymajors) * num_minors; |
|
|
if (setsid() < 0) |
if (setsid() < 0) |
error("setsid: %.100s", strerror(errno)); |
error("setsid: %.100s", strerror(errno)); |
|
|
/* Verify that we are successfully disconnected from the |
/* |
controlling tty. */ |
* Verify that we are successfully disconnected from the controlling |
|
* tty. |
|
*/ |
fd = open("/dev/tty", O_RDWR | O_NOCTTY); |
fd = open("/dev/tty", O_RDWR | O_NOCTTY); |
if (fd >= 0) { |
if (fd >= 0) { |
error("Failed to disconnect from controlling tty."); |
error("Failed to disconnect from controlling tty."); |
|
|
/* Make it our controlling tty. */ |
/* Make it our controlling tty. */ |
#ifdef TIOCSCTTY |
#ifdef TIOCSCTTY |
debug("Setting controlling tty using TIOCSCTTY."); |
debug("Setting controlling tty using TIOCSCTTY."); |
/* We ignore errors from this, because HPSUX defines TIOCSCTTY, |
/* |
but returns EINVAL with these arguments, and there is |
* We ignore errors from this, because HPSUX defines TIOCSCTTY, but |
absolutely no documentation. */ |
* returns EINVAL with these arguments, and there is absolutely no |
|
* documentation. |
|
*/ |
ioctl(*ttyfd, TIOCSCTTY, NULL); |
ioctl(*ttyfd, TIOCSCTTY, NULL); |
#endif /* TIOCSCTTY */ |
#endif /* TIOCSCTTY */ |
fd = open(ttyname, O_RDWR); |
fd = open(ttyname, O_RDWR); |