Small cleanups to openpty().
- Pass O_NOCTTY to posix_openpt(2). This makes the implementation work consistently on implementations that make the PTY the controlling TTY by default. - Call unlockpt() before opening the slave device. POSIX mentions that de slave device should only be opened after grantpt() and unlockpt() have been called. - Replace some redundant code by a label. In theory we could remove a lot of code from openpty() on FreeBSD -CURRENT, because grantpt(), unlockpt() and revoke() are not needed in our implementation. We'd better keep them there. This makes the code still work with older FreeBSD releases and even makes it work on other non-BSD operating systems. I've compiled openpty() on Linux. You only need to remove the revoke() call, because revoke() on Linux always returns -1. Apart from that, it seems to work like it should. Reviewed by: jhb
This commit is contained in:
parent
728747680a
commit
8d333b3c85
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=183565
@ -56,37 +56,26 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp,
|
||||
const char *slavename;
|
||||
int master, slave;
|
||||
|
||||
master = posix_openpt(O_RDWR);
|
||||
master = posix_openpt(O_RDWR|O_NOCTTY);
|
||||
if (master == -1)
|
||||
return (-1);
|
||||
|
||||
if (grantpt(master) == -1) {
|
||||
close(master);
|
||||
return (-1);
|
||||
}
|
||||
if (grantpt(master) == -1)
|
||||
goto bad;
|
||||
|
||||
if (unlockpt(master) == -1)
|
||||
goto bad;
|
||||
|
||||
slavename = ptsname(master);
|
||||
if (slavename == NULL) {
|
||||
close(master);
|
||||
return (-1);
|
||||
}
|
||||
if (slavename == NULL)
|
||||
goto bad;
|
||||
|
||||
if (revoke(slavename) == -1) {
|
||||
close(master);
|
||||
return (-1);
|
||||
}
|
||||
if (revoke(slavename) == -1)
|
||||
goto bad;
|
||||
|
||||
slave = open(slavename, O_RDWR);
|
||||
if (slave == -1) {
|
||||
close(master);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (unlockpt(master) == -1) {
|
||||
close(master);
|
||||
close(slave);
|
||||
return (-1);
|
||||
}
|
||||
if (slave == -1)
|
||||
goto bad;
|
||||
|
||||
*amaster = master;
|
||||
*aslave = slave;
|
||||
@ -99,6 +88,9 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp,
|
||||
ioctl(slave, TIOCSWINSZ, (char *)winp);
|
||||
|
||||
return (0);
|
||||
|
||||
bad: close(master);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user