]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/openpty.3
dlopen.3: Clarify that constructors are called only when library is first loaded
[thirdparty/man-pages.git] / man3 / openpty.3
1 .\" Copyright (c) OpenBSD Group
2 .\" All rights reserved.
3 .\"
4 .\" %%%LICENSE_START(BSD_3_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. Neither the name of the University nor the names of its contributors
14 .\" may be used to endorse or promote products derived from this software
15 .\" without specific prior written permission.
16 .\"
17 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" SUCH DAMAGE.
28 .\" %%%LICENSE_END
29 .\"
30 .\" Converted into a manpage again by Martin Schulze <joey@infodrom.org>
31 .\"
32 .\" Added -lutil remark, 030718
33 .\"
34 .TH OPENPTY 3 2017-09-15 "GNU" "Linux Programmer's Manual"
35 .SH NAME
36 openpty, login_tty, forkpty \- terminal utility functions
37 .SH SYNOPSIS
38 .nf
39 .B #include <pty.h>
40 .PP
41 .BI "int openpty(int *" amaster ", int *" aslave ", char *" name ,
42 .BI " const struct termios *" termp ,
43 .BI " const struct winsize *" winp );
44 .PP
45 .BI "pid_t forkpty(int *" amaster ", char *" name ,
46 .BI " const struct termios *" termp ,
47 .BI " const struct winsize *" winp );
48
49 .B #include <utmp.h>
50 .PP
51 .BI "int login_tty(int " fd );
52 .PP
53 Link with \fI\-lutil\fP.
54 .fi
55 .SH DESCRIPTION
56 The
57 .BR openpty ()
58 function finds an available pseudoterminal and returns file descriptors
59 for the master and slave in
60 .I amaster
61 and
62 .IR aslave .
63 If
64 .I name
65 is not NULL, the filename of the slave is returned in
66 .IR name .
67 If
68 .I termp
69 is not NULL, the terminal parameters of the slave will be set to the
70 values in
71 .IR termp .
72 If
73 .I winp
74 is not NULL, the window size of the slave will be set to the values in
75 .IR winp .
76 .PP
77 The
78 .BR login_tty ()
79 function prepares for a login on the terminal
80 .I fd
81 (which may be a real terminal device, or the slave of a pseudoterminal as
82 returned by
83 .BR openpty ())
84 by creating a new session, making
85 .I fd
86 the controlling terminal for the calling process, setting
87 .I fd
88 to be the standard input, output, and error streams of the current
89 process, and closing
90 .IR fd .
91 .PP
92 The
93 .BR forkpty ()
94 function combines
95 .BR openpty (),
96 .BR fork (2),
97 and
98 .BR login_tty ()
99 to create a new process operating in a pseudoterminal.
100 The file
101 descriptor of the master side of the pseudoterminal is returned in
102 .IR amaster .
103 If
104 .I name
105 is not NULL, the buffer it points to is used to return the
106 filename of the slave.
107 The
108 .I termp
109 and
110 .I winp
111 arguments, if not NULL,
112 will determine the terminal attributes and window size of the slave
113 side of the pseudoterminal.
114 .SH RETURN VALUE
115 If a call to
116 .BR openpty (),
117 .BR login_tty (),
118 or
119 .BR forkpty ()
120 is not successful, \-1 is returned and
121 .I errno
122 is set to indicate the error.
123 Otherwise,
124 .BR openpty (),
125 .BR login_tty (),
126 and the child process of
127 .BR forkpty ()
128 return 0, and the parent process of
129 .BR forkpty ()
130 returns the process ID of the child process.
131 .SH ERRORS
132 .BR openpty ()
133 fails if:
134 .TP
135 .B ENOENT
136 There are no available terminals.
137 .PP
138 .BR login_tty ()
139 fails if
140 .BR ioctl (2)
141 fails to set
142 .I fd
143 to the controlling terminal of the calling process.
144 .PP
145 .BR forkpty ()
146 fails if either
147 .BR openpty ()
148 or
149 .BR fork (2)
150 fails.
151 .SH ATTRIBUTES
152 For an explanation of the terms used in this section, see
153 .BR attributes (7).
154 .TS
155 allbox;
156 lbw20 lb lb
157 l l l.
158 Interface Attribute Value
159 T{
160 .BR forkpty (),
161 .BR openpty ()
162 T} Thread safety MT-Safe locale
163 T{
164 .BR login_tty ()
165 T} Thread safety MT-Unsafe race:ttyname
166 .TE
167 .sp 1
168 .SH CONFORMING TO
169 These are BSD functions, present in glibc.
170 They are not standardized in POSIX.
171 .SH NOTES
172 The
173 .B const
174 modifiers were added to the structure pointer arguments of
175 .BR openpty ()
176 and
177 .BR forkpty ()
178 in glibc 2.8.
179 .PP
180 In versions of glibc before 2.0.92,
181 .BR openpty ()
182 returns file descriptors for a BSD pseudoterminal pair;
183 since glibc 2.0.92,
184 it first attempts to open a UNIX 98 pseudoterminal pair,
185 and falls back to opening a BSD pseudoterminal pair if that fails.
186 .SH BUGS
187 Nobody knows how much space should be reserved for
188 .IR name .
189 So, calling
190 .BR openpty ()
191 or
192 .BR forkpty ()
193 with non-NULL
194 .I name
195 may not be secure.
196 .SH SEE ALSO
197 .BR fork (2),
198 .BR ttyname (3),
199 .BR pty (7)