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

NAME

6       openpty, login_tty, forkpty - terminal utility functions
7

SYNOPSIS

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

DESCRIPTION

26       The  openpty()  function  finds an available pseudoterminal and returns
27       file descriptors for the master and slave in amaster  and  aslave.   If
28       name  is  not  NULL, the filename of the slave is returned in name.  If
29       termp is not NULL, the terminal parameters of the slave will be set  to
30       the values in termp.  If winp is not NULL, the window size of the slave
31       will be set to the values in winp.
32
33       The login_tty() function prepares for a login on the terminal fd (which
34       may  be  a  real  terminal  device, or the slave of a pseudoterminal as
35       returned by openpty()) by creating a new session, making  fd  the  con‐
36       trolling  terminal  for the calling process, setting fd to be the stan‐
37       dard input, output, and error streams of the current process, and clos‐
38       ing fd.
39
40       The  forkpty() function combines openpty(), fork(2), and login_tty() to
41       create a new process operating in a pseudoterminal.  The file  descrip‐
42       tor  of  the  master side of the pseudoterminal is returned in amaster.
43       If name is not NULL, the buffer it points to  is  used  to  return  the
44       filename of the slave.  The termp and winp arguments, if not NULL, will
45       determine the terminal attributes and window size of the slave side  of
46       the pseudoterminal.
47

RETURN VALUE

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

ERRORS

56       openpty() fails if:
57
58       ENOENT There are no available terminals.
59
60       login_tty() fails if ioctl(2) fails to set fd to the controlling termi‐
61       nal of the calling process.
62
63       forkpty() fails if either openpty() or fork(2) fails.
64

ATTRIBUTES

66       For  an  explanation  of  the  terms  used   in   this   section,   see
67       attributes(7).
68
69       ┌─────────────────────┬───────────────┬────────────────────────┐
70Interface            Attribute     Value                  
71       ├─────────────────────┼───────────────┼────────────────────────┤
72forkpty(), openpty() │ Thread safety │ MT-Safe locale         │
73       ├─────────────────────┼───────────────┼────────────────────────┤
74login_tty()          │ Thread safety │ MT-Unsafe race:ttyname │
75       └─────────────────────┴───────────────┴────────────────────────┘
76

CONFORMING TO

78       These  are  BSD functions, present in glibc.  They are not standardized
79       in POSIX.
80

NOTES

82       The const modifiers were added to the structure  pointer  arguments  of
83       openpty() and forkpty() in glibc 2.8.
84
85       In  versions of glibc before 2.0.92, openpty() returns file descriptors
86       for a BSD pseudoterminal pair; since glibc 2.0.92, it first attempts to
87       open  a  UNIX  98  pseudoterminal pair, and falls back to opening a BSD
88       pseudoterminal pair if that fails.
89

BUGS

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

SEE ALSO

95       fork(2), ttyname(3), pty(7)
96

COLOPHON

98       This  page  is  part of release 4.15 of the Linux man-pages project.  A
99       description of the project, information about reporting bugs,  and  the
100       latest     version     of     this    page,    can    be    found    at
101       https://www.kernel.org/doc/man-pages/.
102
103
104
105GNU                               2017-09-15                        OPENPTY(3)
Impressum