Initial import from FreeBSD RELENG_4:
[games.git] / share / man / man4 / tty.4
1 .\" Copyright (c) 1991, 1992, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)tty.4       8.3 (Berkeley) 4/19/94
33 .\" $FreeBSD: src/share/man/man4/tty.4,v 1.9.2.6 2001/12/17 11:30:12 ru Exp $
34 .\"
35 .Dd August 14, 1992
36 .Dt TTY 4
37 .Os
38 .Sh NAME
39 .Nm tty
40 .Nd general terminal interface
41 .Sh SYNOPSIS
42 .In sys/ioctl.h
43 .Sh DESCRIPTION
44 This section describes the interface to the terminal drivers
45 in the system.
46 .Ss Terminal Special Files
47 Each hardware terminal port on the system usually has a terminal special device
48 file associated with it in the directory ``/dev/'' (for
49 example, ``/dev/tty03'').
50 When a user logs into
51 the system on one of these hardware terminal ports, the system has already
52 opened the associated device and prepared the line for normal interactive
53 use (see
54 .Xr getty 8 . )
55 There is also a special case of a terminal file that connects not to
56 a hardware terminal port, but to another program on the other side.
57 These special terminal devices are called
58 .Em ptys
59 and provide the mechanism necessary to give users the same interface to the
60 system when logging in over a network (using
61 .Xr rlogin 1 ,
62 or
63 .Xr telnet 1
64 for example).  Even in these cases the details of how the terminal
65 file was opened and set up is already handled by special software
66 in the system.
67 Thus, users do not normally need to worry about the details of
68 how these lines are opened or used.  Also, these lines are often used
69 for dialing out of a system (through an out-calling modem), but again
70 the system provides programs that hide the details of accessing
71 these terminal special files (see
72 .Xr tip 1 ) .
73 .Pp
74 When an interactive user logs in, the system prepares the line to
75 behave in a certain way (called a
76 .Em "line discipline" ) ,
77 the particular details of which is described in
78 .Xr stty 1
79 at the command level, and in
80 .Xr termios 4
81 at the programming level.  A user may be concerned with changing
82 settings associated with his particular login terminal and should refer
83 to the preceding man pages for the common cases.  The remainder of
84 this man page is concerned
85 with describing details of using and controlling terminal devices
86 at a low level, such as that possibly required by a program wishing
87 to provide features similar to those provided by the system.
88 .Ss Line disciplines
89 A terminal file is used like any other file in the system in that
90 it can be opened, read, and written to using standard system
91 calls.  For each existing terminal file, there is a software processing module
92 called a
93 .Em "line discipline"
94 is associated with it.  The
95 .Em "line discipline"
96 essentially glues the low level device driver code with the high
97 level generic interface routines (such as
98 .Xr read 2
99 and
100 .Xr write 2 ) ,
101 and is responsible for implementing the semantics associated
102 with the device.  When a terminal file is first opened by a program,
103 the default
104 .Em "line discipline"
105 called the
106 .Dv termios
107 line discipline is associated with the file.  This is the primary
108 line discipline that is used in most cases and provides the semantics
109 that users normally associate with a terminal.  When the
110 .Dv termios
111 line discipline is in effect, the terminal file behaves and is
112 operated according to the rules described in
113 .Xr termios 4 .
114 Please refer to that man page for a full description of the terminal
115 semantics.
116 The operations described here
117 generally represent features common
118 across all
119 .Em "line disciplines" ,
120 however some of these calls may not
121 make sense in conjunction with a line discipline other than
122 .Dv termios ,
123 and some may not be supported by the underlying
124 hardware (or lack thereof, as in the case of ptys).
125 .Ss Terminal File Operations
126 All of the following operations are invoked using the
127 .Xr ioctl 2
128 system call.  Refer to that man page for a description of
129 the
130 .Em request
131 and
132 .Em argp
133 parameters.
134 In addition to the ioctl
135 .Em requests
136 defined here, the specific line discipline
137 in effect will define other
138 .Em requests
139 specific to it (actually
140 .Xr termios 4
141 defines them as function calls, not ioctl
142 .Em requests . )
143 The following section lists the available ioctl requests.  The
144 name of the request, a description of its purpose, and the typed
145 .Em argp
146 parameter (if any)
147 are listed.  For example, the first entry says
148 .Pp
149 .D1 Em "TIOCSETD int *ldisc"
150 .Pp
151 and would be called on the terminal associated with
152 file descriptor zero by the following code fragment:
153 .Bd -literal
154         int ldisc;
155
156         ldisc = TTYDISC;
157         ioctl(0, TIOCSETD, &ldisc);
158 .Ed
159 .Ss Terminal File Request Descriptions
160 .Bl -tag -width TIOCGWINSZ
161 .It Dv TIOCSETD Fa int *ldisc
162 Change to the new line discipline pointed to by
163 .Fa ldisc .
164 The available line disciplines are listed in
165 .Aq Pa sys/ttycom.h
166 and currently are:
167 .Pp
168 .Bl -tag -width NETGRAPHDISC -compact
169 .It TTYDISC
170 Termios interactive line discipline.
171 .It TABLDISC
172 Tablet line discipline.
173 .It SLIPDISC
174 Serial IP line discipline.
175 .It PPPDISC
176 PPP line discipline.
177 .It NETGRAPHDISC
178 Netgraph
179 .Xr ng_tty 4
180 line discipline.
181 .El
182 .Pp
183 .It Dv TIOCGETD Fa int *ldisc
184 Return the current line discipline in the integer pointed to by
185 .Fa ldisc .
186 .It Dv TIOCSBRK Fa void
187 Set the terminal hardware into BREAK condition.
188 .It Dv TIOCCBRK Fa void
189 Clear the terminal hardware BREAK condition.
190 .It Dv TIOCSDTR Fa void
191 Assert data terminal ready (DTR).
192 .It Dv TIOCCDTR Fa void
193 Clear data terminal ready (DTR).
194 .It Dv TIOCGPGRP Fa int *tpgrp
195 Return the current process group with which the terminal is associated
196 in the integer pointed to by
197 .Fa tpgrp .
198 This is the underlying call that implements the
199 .Xr termios 4
200 .Fn tcgetattr
201 call.
202 .It Dv TIOCSPGRP Fa int *tpgrp
203 Associate the terminal with the process group (as an integer) pointed to by
204 .Fa tpgrp .
205 This is the underlying call that implements the
206 .Xr termios 4
207 .Fn tcsetattr
208 call.
209 .It Dv TIOCGETA Fa struct termios *term
210 Place the current value of the termios state associated with the
211 device in the termios structure pointed to by
212 .Fa term .
213 This is the underlying call that implements the
214 .Xr termios 4
215 .Fn tcgetattr
216 call.
217 .It Dv TIOCSETA Fa struct termios *term
218 Set the termios state associated with the device immediately.
219 This is the underlying call that implements the
220 .Xr termios 4
221 .Fn tcsetattr
222 call with the
223 .Dv TCSANOW
224 option.
225 .It Dv TIOCSETAW Fa struct termios *term
226 First wait for any output to complete, then set the termios state
227 associated with the device.
228 This is the underlying call that implements the
229 .Xr termios 4
230 .Fn tcsetattr
231 call with the
232 .Dv TCSADRAIN
233 option.
234 .It Dv TIOCSETAF Fa struct termios *term
235 First wait for any output to complete, clear any pending input,
236 then set the termios state associated with the device.
237 This is the underlying call that implements the
238 .Xr termios 4
239 .Fn tcsetattr
240 call with the
241 .Dv TCSAFLUSH
242 option.
243 .It Dv TIOCOUTQ Fa int *num
244 Place the current number of characters in the output queue in the
245 integer pointed to by
246 .Fa num .
247 .It Dv TIOCSTI Fa char *cp
248 Simulate typed input.  Pretend as if the terminal received the
249 character pointed to by
250 .Fa cp .
251 .It Dv TIOCNOTTY Fa void
252 This call is obsolete but left for compatibility.  In the past, when
253 a process that didn't have a controlling terminal (see
254 .Em The Controlling Terminal
255 in
256 .Xr termios 4 )
257 first opened a terminal device, it acquired that terminal as its
258 controlling terminal.  For some programs this was a hazard as they
259 didn't want a controlling terminal in the first place, and this
260 provided a mechanism to disassociate the controlling terminal from
261 the calling process.  It
262 .Em must
263 be called by opening the file
264 .Pa /dev/tty
265 and calling
266 .Dv TIOCNOTTY
267 on that file descriptor.
268 .Pp
269 The current system does not allocate a controlling terminal to
270 a process on an
271 .Fn open
272 call: there is a specific ioctl called
273 .Dv TIOSCTTY
274 to make a terminal the controlling
275 terminal.
276 In addition, a program can
277 .Fn fork
278 and call the
279 .Fn setsid
280 system call which will place the process into its own session - which
281 has the effect of disassociating it from the controlling terminal.  This
282 is the new and preferred method for programs to lose their controlling
283 terminal.
284 .It Dv TIOCSTOP Fa void
285 Stop output on the terminal (like typing ^S at the keyboard).
286 .It Dv TIOCSTART Fa void
287 Start output on the terminal (like typing ^Q at the keyboard).
288 .It Dv TIOCSCTTY Fa void
289 Make the terminal the controlling terminal for the process (the process
290 must not currently have a controlling terminal).
291 .It Dv TIOCDRAIN Fa void
292 Wait until all output is drained.
293 .It Dv TIOCEXCL Fa void
294 Set exclusive use on the terminal.  No further opens are permitted
295 except by root.  Of course, this means that programs that are run by
296 root (or setuid) will not obey the exclusive setting - which limits
297 the usefulness of this feature.
298 .It Dv TIOCNXCL Fa void
299 Clear exclusive use of the terminal.  Further opens are permitted.
300 .It Dv TIOCFLUSH Fa int *what
301 If the value of the int pointed to by
302 .Fa what
303 contains the
304 .Dv FREAD
305 bit as defined in
306 .Aq Pa sys/file.h ,
307 then all characters in the input queue are cleared.  If it contains
308 the
309 .Dv FWRITE
310 bit, then all characters in the output queue are cleared.  If the
311 value of the integer is zero, then it behaves as if both the
312 .Dv FREAD
313 and
314 .Dv FWRITE
315 bits were set (i.e. clears both queues).
316 .It Dv TIOCGWINSZ Fa struct winsize *ws
317 Put the window size information associated with the terminal in the
318 .Va winsize
319 structure pointed to by
320 .Fa ws .
321 The window size structure contains the number of rows and columns (and pixels
322 if appropriate) of the devices attached to the terminal.  It is set by user software
323 and is the means by which most full\&-screen oriented programs determine the
324 screen size.  The
325 .Va winsize
326 structure is defined in
327 .Aq Pa sys/ioctl.h .
328 .It Dv TIOCSWINSZ Fa struct winsize *ws
329 Set the window size associated with the terminal to be the value in
330 the
331 .Va winsize
332 structure pointed to by
333 .Fa ws
334 (see above).
335 .It Dv TIOCCONS Fa int *on
336 If
337 .Fa on
338 points to a non-zero integer, redirect kernel console output (kernel printf's)
339 to this terminal.
340 If
341 .Fa on
342 points to a zero integer, redirect kernel console output back to the normal
343 console.  This is usually used on workstations to redirect kernel messages
344 to a particular window.
345 .It Dv TIOCMSET Fa int *state
346 The integer pointed to by
347 .Fa state
348 contains bits that correspond to modem state.  Following is a list
349 of defined variables and the modem state they represent:
350 .Pp
351 .Bl -tag -width TIOCMXCTS -compact
352 .It TIOCM_LE
353 Line Enable.
354 .It TIOCM_DTR
355 Data Terminal Ready.
356 .It TIOCM_RTS
357 Request To Send.
358 .It TIOCM_ST
359 Secondary Transmit.
360 .It TIOCM_SR
361 Secondary Receive.
362 .It TIOCM_CTS
363 Clear To Send.
364 .It TIOCM_CAR
365 Carrier Detect.
366 .It TIOCM_CD
367 Carrier Detect (synonym).
368 .It TIOCM_RNG
369 Ring Indication.
370 .It TIOCM_RI
371 Ring Indication (synonym).
372 .It TIOCM_DSR
373 Data Set Ready.
374 .El
375 .Pp
376 This call sets the terminal modem state to that represented by
377 .Fa state .
378 Not all terminals may support this.
379 .It Dv TIOCMGET Fa int *state
380 Return the current state of the terminal modem lines as represented
381 above in the integer pointed to by
382 .Fa state .
383 .It Dv TIOCMBIS Fa int *state
384 The bits in the integer pointed to by
385 .Fa state
386 represent modem state as described above, however the state is OR-ed
387 in with the current state.
388 .It Dv TIOCMBIC Fa int *state
389 The bits in the integer pointed to by
390 .Fa state
391 represent modem state as described above, however each bit which is on
392 in
393 .Fa state
394 is cleared in the terminal.
395 .El
396 .Sh SEE ALSO
397 .Xr stty 1 ,
398 .Xr ioctl 2 ,
399 .Xr ng_tty 4 ,
400 .Xr pty 4 ,
401 .Xr termios 4 ,
402 .Xr getty 8