]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libutil/pty.3
MFV: zlib: examples: define functions as static ones. (PR #855)
[FreeBSD/FreeBSD.git] / lib / libutil / pty.3
1 .\"
2 .\" Copyright (c) 1996 Joerg Wunsch
3 .\"
4 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 .\" "
26 .Dd June 2, 2018
27 .Dt PTY 3
28 .Os
29 .Sh NAME
30 .Nm openpty ,
31 .Nm forkpty
32 .Nd auxiliary functions to obtain a pseudo-terminal
33 .Sh LIBRARY
34 .Lb libutil
35 .Sh SYNOPSIS
36 .In sys/types.h
37 .In sys/ioctl.h
38 .In termios.h
39 .In libutil.h
40 .Ft int
41 .Fn openpty "int *amaster" "int *aslave" "char *name" "struct termios *termp" "struct winsize *winp"
42 .Ft int
43 .Fn forkpty "int *amaster" "char *name" "struct termios *termp" "struct winsize *winp"
44 .Sh DESCRIPTION
45 The function
46 .Fn openpty
47 attempts to obtain the next available pseudo-terminal from the system (see
48 .Xr pty 4 ) .
49 If it successfully finds one, it subsequently changes the
50 ownership of the slave device to the real UID of the current process,
51 the group membership to the group
52 .Dq tty
53 (if such a group exists in the system), the access permissions for
54 reading and writing by the owner, and for writing by the group, and
55 invalidates any current use of the line by calling
56 .Xr revoke 2 .
57 .Pp
58 If the argument
59 .Fa name
60 is not
61 .Dv NULL ,
62 .Fn openpty
63 copies the pathname of the slave pty to this area.
64 The caller is
65 responsible for allocating the required space in this array.
66 .Pp
67 If the arguments
68 .Fa termp
69 or
70 .Fa winp
71 are not
72 .Dv NULL ,
73 .Fn openpty
74 initializes the termios and window size settings from the structures
75 these arguments point to, respectively.
76 .Pp
77 Upon return, the open file descriptors for the master and slave side
78 of the pty are returned in the locations pointed to by
79 .Fa amaster
80 and
81 .Fa aslave ,
82 respectively.
83 .Pp
84 The
85 .Fn forkpty
86 function first calls
87 .Fn openpty
88 to obtain the next available pseudo-terminal from the system.
89 Upon success,
90 it forks off a new process.
91 In the child process, it closes the descriptor
92 for the master side of the pty, and calls
93 .Xr login_tty 3
94 for the slave pty.
95 In the parent process, it closes the descriptor for the
96 slave side of the pty.
97 The arguments
98 .Fa amaster ,
99 .Fa name ,
100 .Fa termp ,
101 and
102 .Fa winp
103 have the same meaning as described for
104 .Fn openpty .
105 .Sh RETURN VALUES
106 The
107 .Fn openpty
108 function returns 0 on success, or -1 on failure.
109 .Pp
110 The
111 .Fn forkpty
112 function returns -1 on failure, 0 in the slave process, and the process ID of
113 the slave process in the parent process.
114 .Sh ERRORS
115 The
116 .Fn openpty
117 function may fail and set the global variable
118 .Dv errno
119 for any of the errors specified for the
120 .Xr grantpt 3 ,
121 .Xr posix_openpt 2 ,
122 .Xr ptsname 3 ,
123 and
124 .Xr unlockpt 3
125 functions and the
126 .Xr revoke 2
127 system call.
128 .Pp
129 In addition to this,
130 .Fn forkpty
131 may set it to any value as described for
132 .Xr fork 2 .
133 .Sh SEE ALSO
134 .Xr chmod 2 ,
135 .Xr chown 2 ,
136 .Xr fork 2 ,
137 .Xr getuid 2 ,
138 .Xr open 2 ,
139 .Xr revoke 2 ,
140 .Xr login_tty 3 ,
141 .Xr pty 4 ,
142 .Xr termios 4 ,
143 .Xr group 5
144 .Sh HISTORY
145 The
146 .Fn openpty
147 and
148 .Fn forkpty
149 functions first appeared in
150 .Bx 4.3 Reno .
151 .Sh BUGS
152 .Fn openpty
153 writes the slave terminal's name to
154 .Fa name ,
155 but does not check that sufficient space is available.
156 It is advisable to use
157 .Xr ptsname 3
158 instead.