summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorcognet <cognet@FreeBSD.org>2006-01-26 01:33:26 +0000
committercognet <cognet@FreeBSD.org>2006-01-26 01:33:26 +0000
commitb7565a36f0740ca308cf5c22f50efde269d137fe (patch)
tree3ec4d0fca7f44fa2b1f7157adf2c3e2102b65f5b /lib/libutil
parentd6ecc915cc27c2d4d19e9d25926a18aae2eb5e13 (diff)
downloadFreeBSD-src-b7565a36f0740ca308cf5c22f50efde269d137fe.zip
FreeBSD-src-b7565a36f0740ca308cf5c22f50efde269d137fe.tar.gz
Teach openpty() how to deal with pts.
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/pty.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/libutil/pty.c b/lib/libutil/pty.c
index b230edb..553468c 100644
--- a/lib/libutil/pty.c
+++ b/lib/libutil/pty.c
@@ -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
OpenPOWER on IntegriCloud