1OPENPTY(3)                 Linux Programmer's Manual                OPENPTY(3)
2
3
4

NAME

6       openpty, login_tty, forkpty - tty utility functions
7

SYNOPSIS

9       #include <pty.h>
10
11       int openpty(int *amaster, int *aslave, char *name,
12                   struct termios *termp, struct winsize *winp);
13
14       pid_t forkpty(int *amaster, char *name, struct termios *termp,
15                     struct winsize *winp);
16
17       #include <utmp.h>
18
19       int login_tty(int fd);
20
21       Link with -lutil.
22

DESCRIPTION

24       The  openpty()  function finds an available pseudo-terminal and returns
25       file descriptors for the master and slave in amaster  and  aslave.   If
26       name  is  not  NULL, the filename of the slave is returned in name.  If
27       termp is not NULL, the terminal parameters of the slave will be set  to
28       the values in termp.  If winp is not NULL, the window size of the slave
29       will be set to the values in winp.
30
31       The login_tty() function prepares for a login on the tty fd (which  may
32       be  a real tty device, or the slave of a pseudo-terminal as returned by
33       openpty()) by creating a new session, making fd the controlling  termi‐
34       nal  for the calling process, setting fd to be the standard input, out‐
35       put, and error streams of the current process, and closing fd.
36
37       The forkpty() function combines openpty(), fork(2), and login_tty()  to
38       create a new process operating in a pseudo-terminal.  The file descrip‐
39       tor of the master side of the pseudo-terminal is returned  in  amaster,
40       and the filename of the slave in name if it is not NULL.  The termp and
41       winp arguments, if not NULL, will determine the terminal attributes and
42       window size of the slave side of the pseudo-terminal.
43

RETURN VALUE

45       If a call to openpty(), login_tty(), or forkpty() is not successful, -1
46       is returned and  errno  is  set  to  indicate  the  error.   Otherwise,
47       openpty(),  login_tty(),  and  the child process of forkpty() return 0,
48       and the parent process of forkpty() returns the process ID of the child
49       process.
50

ERRORS

52       openpty() will fail if:
53
54       ENOENT There are no available ttys.
55
56       login_tty()  will  fail  if ioctl(2) fails to set fd to the controlling
57       terminal of the calling process.
58
59       forkpty() will fail if either openpty() or fork(2) fails.
60

CONFORMING TO

62       These are BSD functions, present in libc5 and glibc2.
63

NOTES

65       In versions of glibc before 2.0.92, openpty() returns file  descriptors
66       for  a  BSD pseudo-terminal pair; since glibc 2.0.92, it first attempts
67       to open a Unix 98 pseudo-terminal pair, and falls back to opening a BSD
68       pseudo-terminal pair if that fails.
69

BUGS

71       Nobody  knows  how much space should be reserved for name.  So, calling
72       openpty() or forkpty() with non-NULL name may not be secure.
73

SEE ALSO

75       fork(2), ttyname(3), pty(7)
76

COLOPHON

78       This page is part of release 3.22 of the Linux  man-pages  project.   A
79       description  of  the project, and information about reporting bugs, can
80       be found at http://www.kernel.org/doc/man-pages/.
81
82
83
84GNU                               2003-07-18                        OPENPTY(3)
Impressum