summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/grantpt.3
blob: cfa2d6e2cd86d82a0df501d21697af03a271f5d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
.\"
.\" Copyright (c) 2002 The FreeBSD Project, Inc.
.\" All rights reserved.
.\"
.\" This software includes code contributed to the FreeBSD Project
.\" by Ryan Younce of North Carolina State University.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the FreeBSD Project nor the names of its
.\"    contributors may be used to endorse or promote products derived from
.\"    this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
.\" PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FREEBSD PROJECT
.\" OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
.\" TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
.\" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
.\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd December 23, 2002
.Os
.Dt GRANTPT 3
.Sh NAME
.Nm grantpt ,
.Nm ptsname ,
.Nm unlockpt ,
.Nm posix_openpt
.Nd pseudo-terminal access functions
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In stdlib.h
.Ft int
.Fn grantpt "int fildes"
.Ft "char *"
.Fn ptsname "int fildes"
.Ft int
.Fn unlockpt "int fildes"
.In fcntl.h
.Ft int
.Fn posix_openpt "int mode"
.Sh DESCRIPTION
The
.Fn grantpt ,
.Fn ptsname ,
.Fn unlockpt ,
and
.Fn posix_openpt
functions allow access to pseudo-terminal devices.
The first three functions accept a file descriptor
that references the master half of a pseudo-terminal pair.
This file descriptor is created with
.Fn posix_openpt .
.Pp
The
.Fn grantpt
function is used to establish ownership and permissions
of the slave device counterpart to the master device
specified with
.Fa fildes .
The slave device's ownership is set to the real user ID
of the calling process, and the permissions are set to
user readable-writable and group writable.
The group owner of the slave device is also set to the
group
.Dq Li tty
if it exists on the system; otherwise, it
is left untouched.
.Pp
The
.Fn ptsname
function returns the full pathname of the slave device
counterpart to the master device specified with
.Fa fildes .
This value can be used
to subsequently open the appropriate slave after
.Fn posix_openpt
and
.Fn grantpt
have been called.
.Pp
The
.Fn unlockpt
function clears the lock held on the pseudo-terminal pair
for the master device specified with
.Fa fildes .
.Pp
The
.Fn posix_openpt
function opens the first available master pseudo-terminal
device and returns a descriptor to it.
The
.Fa mode
argument
specifies the flags used for opening the device:
.Bl -tag -width ".Dv O_NOCTTY"
.It Dv O_RDWR
Open for reading and writing.
.It Dv O_NOCTTY
If set, do not allow the terminal to become
the controlling terminal for the calling process.
.El
.Sh RETURN VALUES
.Rv -std grantpt unlockpt
.Pp
The
.Fn ptsname
function returns a pointer to the name
of the slave device on success; otherwise a
.Dv NULL
pointer is returned and the global variable
.Va errno
is set to indicate the error.
.Pp
The
.Fn posix_openpt
function returns a file descriptor to the first
available master pseudo-terminal device on success;
otherwise \-1 is returned and the global variable
.Va errno
is set to indicate the error.
.Sh ERRORS
The
.Fn grantpt ,
.Fn ptsname ,
and
.Fn unlockpt
functions may fail and set
.Va errno
to:
.Bl -tag -width Er
.It Bq Er EINVAL
.Fa fildes
is not a master pseudo-terminal device.
.El
.Pp
In addition, the
.Fn grantpt
function may set
.Va errno
to:
.Bl -tag -width Er
.It Bq Er EACCES
The slave pseudo-terminal device could not be accessed.
.El
.Pp
The
.Fn posix_openpt
function may fail and set
.Va errno
to:
.Bl -tag -width Er
.It Bq Er EINVAL
.Fa mode
consists an an invalid mode bit.
.It Bq Er EAGAIN
The system has no available pseudo-terminal devices.
.El
.Pp
The
.Fn grantpt ,
.Fn ptsname ,
and
.Fn unlockpt
functions may also fail and set
.Va errno
for any of the errors specified for the
.Xr fstat 2
system call.
.Pp
The
.Fn posix_openpt
function may also fail and set
.Va errno
for any of the errors specified for the
.Xr open 2
system call.
.Sh SEE ALSO
.Xr open 2 ,
.Xr pty 4 ,
.Xr tty 4
.Sh STANDARDS
The
.Fn grantpt ,
.Fn ptsname ,
.Fn unlockpt ,
and
.Fn posix_openpt
functions conform to
.St -p1003.1-2001 .
.Sh HISTORY
The
.Fn grantpt ,
.Fn ptsname ,
.Fn unlockpt ,
and
.Fn posix_openpt
functions appeared in
.Fx 5.0 .
.Sh NOTES
The purpose of the
.Fn unlockpt
function has no meaning in
.Fx .
.Pp
The flag
.Dv O_NOCTTY
is included for compatibility; in
.Fx ,
opening a terminal does not cause it to become
a process's controlling terminal.
OpenPOWER on IntegriCloud