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