1openpty(3)                 Library Functions Manual                 openpty(3)
2
3
4

NAME

6       openpty, login_tty, forkpty - terminal utility functions
7

LIBRARY

9       System utilities library (libutil, -lutil)
10

SYNOPSIS

12       #include <pty.h>
13
14       int openpty(int *amaster, int *aslave, char *name,
15                     const struct termios *termp,
16                     const struct winsize *winp);
17       pid_t forkpty(int *amaster, char *name,
18                     const struct termios *termp,
19                     const struct winsize *winp);
20
21       #include <utmp.h>
22
23       int login_tty(int fd);
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  referred
34       to  by  the file descriptor fd (which may be a real terminal device, or
35       the slave of a pseudoterminal as returned by openpty()) by  creating  a
36       new  session,  making  fd  the  controlling  terminal  for  the calling
37       process, setting fd to be the standard input, output, and error streams
38       of the current process, and closing fd.
39
40       The  forkpty() function combines openpty(), fork(2), and login_tty() to
41       create a new process operating in a pseudoterminal.  A file  descriptor
42       referring  to 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  at‐
67       tributes(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

STANDARDS

78       BSD.
79

HISTORY

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

BUGS

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

SEE ALSO

94       fork(2), ttyname(3), pty(7)
95
96
97
98Linux man-pages 6.05              2023-07-20                        openpty(3)
Impressum