Teach openpty() how to deal with pts.

This commit is contained in:
Olivier Houchard 2006-01-26 01:33:26 +00:00
parent e83d253beb
commit db256336b8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=154835

View File

@ -53,6 +53,48 @@ static char sccsid[] = "@(#)pty.c 8.3 (Berkeley) 5/16/94";
#include <termios.h>
#include <unistd.h>
int __use_pts(void);
static int
new_openpty(int *amaster, int *aslave, char *name, struct termios *termp,
struct winsize *winp)
{
int master, slave;
master = posix_openpt(O_RDWR);
if (master == -1)
return (-1);
if (grantpt(master) == -1) {
close(master);
return (-1);
}
slave = open(ptsname(master), O_RDWR);
if (slave == -1) {
close(master);
return (-1);
}
if (unlockpt(master) == -1) {
close(master);
close(slave);
return (-1);
}
*amaster = master;
*aslave = slave;
if (name)
strcpy(name, ptsname(master));
if (termp)
tcsetattr(slave, TCSAFLUSH, termp);
if (winp)
ioctl(slave, TIOCSWINSZ, (char *)winp);
return (0);
}
int
openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp)
{
@ -61,6 +103,9 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct win
int master, slave, ttygid;
struct group *gr;
if (__use_pts())
return (new_openpty(amaster, aslave, name, termp, winp));
if ((gr = getgrnam("tty")) != NULL)
ttygid = gr->gr_gid;
else