xref: /openbsd-src/share/man/man4/tty.4 (revision d59bb9942320b767f2a19aaa7690c8c6e30b724c)
1.\"	$OpenBSD: tty.4,v 1.47 2016/11/26 11:18:43 mpi Exp $
2.\"	$NetBSD: tty.4,v 1.4 1996/03/19 04:26:01 paulus Exp $
3.\"
4.\" Copyright (c) 1991, 1992, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)tty.4	8.3 (Berkeley) 4/19/94
32.\"
33.Dd $Mdocdate: November 26 2016 $
34.Dt TTY 4
35.Os
36.Sh NAME
37.Nm tty ,
38.Nm cua
39.Nd general terminal interface
40.Sh SYNOPSIS
41.In sys/ioctl.h
42.Sh DESCRIPTION
43This section describes the interface to the terminal drivers
44in the system.
45.Ss Terminal Special Files
46Each hardware terminal port (such as a serial port) on the system usually has a
47terminal special device file associated with it in the directory
48.Pa /dev/
49(for
50example,
51.Pa /dev/tty03 ) .
52When a user logs into
53the system on one of these hardware terminal ports, the system has already
54opened the associated device and prepared the line for normal interactive
55use (see
56.Xr getty 8 ) .
57There is also a special case of a terminal file that connects not to
58a hardware terminal port, but to another program on the other side.
59These special terminal devices are called
60.Em ptys
61and provide the mechanism necessary to give users the same interface to the
62system when logging in over a network (using
63.Xr ssh 1
64or
65.Xr telnet 1
66for example).
67Even in these cases the details of how the terminal
68file was opened and set up is already handled by special software
69in the system.
70Thus, users do not normally need to worry about the details of
71how these lines are opened or used.
72.Pp
73For hardware terminal ports, dial-out is supported through matching
74device nodes called calling units.
75For instance, the terminal called
76.Pa /dev/tty03
77would have a matching calling unit called
78.Pa /dev/cua03 .
79These two devices are normally differentiated by creating the calling
80unit device node with a minor number 128 greater than the dial-in
81device node.
82Whereas the dial-in device (the
83.Em tty )
84normally
85requires a hardware signal to indicate to the system that it is active,
86the dial-out device (the
87.Em cua )
88does not, and hence can communicate unimpeded
89with a device such as a modem, or with another system over a serial link.
90This means that a process like
91.Xr getty 8
92will wait on a dial-in device until a connection is established.
93Meanwhile, a dial-out connection can be established on the dial-out
94device (for the very same hardware terminal port) without disturbing
95anything else on the system.
96The
97.Xr getty 8
98process does not even notice that anything is happening on the terminal
99port.
100If a connecting call comes in after the dial-out connection has finished, the
101.Xr getty 8
102process will deal with it properly, without having noticed the
103intervening dial-out action.
104For more information on dial-out, see
105.Xr cu 1 .
106.Pp
107When an interactive user logs in, the system prepares the line to
108behave in a certain way (called a
109.Em "line discipline" ) ,
110the particular details of which are described in
111.Xr stty 1
112at the command level, and in
113.Xr termios 4
114at the programming level.
115A user may be concerned with changing settings associated with his particular
116login terminal and should refer to the preceding man pages for the common
117cases.
118The remainder of this man page is concerned with describing details of using
119and controlling terminal devices at a low level, such as that possibly
120required by a program wishing to provide features similar to those provided
121by the system.
122.Ss Line disciplines
123A terminal file is used like any other file in the system in that
124it can be opened, read, and written to using standard system
125calls.
126For each existing terminal file, there is a software processing module
127called a
128.Em "line discipline"
129associated with it.
130The
131.Em "line discipline"
132essentially glues the low level device driver code with the high
133level generic interface routines (such as
134.Xr read 2
135and
136.Xr write 2 ) ,
137and is responsible for implementing the semantics associated
138with the device.
139When a terminal file is first opened by a program, the default
140.Em "line discipline"
141called the
142.Dv termios
143line discipline is associated with the file.
144This is the primary line discipline that is used in most cases and provides
145the semantics that users normally associate with a terminal.
146When the
147.Dv termios
148line discipline is in effect, the terminal file behaves and is
149operated according to the rules described in
150.Xr termios 4 .
151Please refer to that man page for a full description of the terminal
152semantics.
153The operations described here
154generally represent features common
155across all
156.Em "line disciplines" ,
157although some of these calls may not
158make sense in conjunction with a line discipline other than
159.Dv termios ,
160and some may not be supported by the underlying
161hardware (or lack thereof, as in the case of ptys).
162.Ss Terminal File Operations
163All of the following operations are invoked using the
164.Xr ioctl 2
165system call.
166Refer to that man page for a description of the
167.Em request
168and
169.Em argp
170parameters.
171In addition to the ioctl
172.Em requests
173defined here, the specific line discipline
174in effect will define other
175.Em requests
176specific to it (actually
177.Xr termios 4
178defines them as function calls, not ioctl
179.Em requests ) .
180The following section lists the available ioctl requests.
181The name of the request, a description of its purpose, and the typed
182.Em argp
183parameter (if any)
184are listed.
185For example, the first entry says
186.Pp
187.D1 Em "TIOCSETD int *ldisc"
188.Pp
189and would be called on the terminal associated with
190file descriptor zero by the following code fragment:
191.Bd -literal
192	int ldisc;
193
194	ldisc = TTYDISC;
195	ioctl(0, TIOCSETD, &ldisc);
196.Ed
197.Ss Terminal File Request Descriptions
198.Bl -tag -width TIOCGWINSZ
199.It Dv TIOCSETD Fa int *ldisc
200Change to the new line discipline pointed to by
201.Fa ldisc .
202The available line disciplines currently available are:
203.Pp
204.Bl -tag -width TIOCGWINSZ -compact
205.It TTYDISC
206Termios interactive line discipline.
207.It PPPDISC
208Point-to-Point Protocol line discipline.
209.It NMEADISC
210NMEA 0183 line discipline.
211.It MSTSDISC
212Meinberg Standard Time String line discipline.
213.El
214.It Dv TIOCGETD Fa int *ldisc
215Return the current line discipline in the integer pointed to by
216.Fa ldisc .
217.It Dv TIOCSBRK Fa void
218Set the terminal hardware into BREAK condition.
219.It Dv TIOCCBRK Fa void
220Clear the terminal hardware BREAK condition.
221.It Dv TIOCSDTR Fa void
222Assert data terminal ready (DTR).
223.It Dv TIOCCDTR Fa void
224Clear data terminal ready (DTR).
225.It Dv TIOCGPGRP Fa int *tpgrp
226Return the current process group the terminal is associated
227with in the integer pointed to by
228.Fa tpgrp .
229This is the underlying call that implements the
230.Xr termios 4
231.Fn tcgetpgrp
232call.
233.It Dv TIOCSPGRP Fa int *tpgrp
234Associate the terminal with the process group (as an integer) pointed to by
235.Fa tpgrp .
236This is the underlying call that implements the
237.Xr termios 4
238.Fn tcsetpgrp
239call.
240.It Dv TIOCGETA Fa struct termios *term
241Place the current value of the termios state associated with the
242device in the termios structure pointed to by
243.Fa term .
244This is the underlying call that implements the
245.Xr termios 4
246.Fn tcgetattr
247call.
248.It Dv TIOCSETA Fa struct termios *term
249Set the termios state associated with the device immediately.
250This is the underlying call that implements the
251.Xr termios 4
252.Fn tcsetattr
253call with the
254.Dv TCSANOW
255option.
256.It Dv TIOCSETAW Fa struct termios *term
257First wait for any output to complete, then set the termios state
258associated with the device.
259This is the underlying call that implements the
260.Xr termios 4
261.Fn tcsetattr
262call with the
263.Dv TCSADRAIN
264option.
265.It Dv TIOCSETAF Fa struct termios *term
266First wait for any output to complete, clear any pending input,
267then set the termios state associated with the device.
268This is the underlying call that implements the
269.Xr termios 4
270.Fn tcsetattr
271call with the
272.Dv TCSAFLUSH
273option.
274.It Dv TIOCOUTQ Fa int *num
275Place the current number of characters in the output queue in the
276integer pointed to by
277.Fa num .
278.It Dv TIOCSTI Fa char *cp
279Simulate typed input.
280Pretend as if the terminal received the character pointed to by
281.Fa cp .
282.It Dv TIOCNOTTY Fa void
283This call is obsolete but left for compatibility.
284In the past, when a process that didn't have a controlling terminal
285(see
286.Em The Controlling Terminal
287in
288.Xr termios 4 )
289first opened a terminal device, it acquired that terminal as its
290controlling terminal.
291For some programs this was a hazard as they didn't want a controlling
292terminal in the first place, and this provided a mechanism to disassociate
293the controlling terminal from the calling process.
294It
295.Em must
296be called by opening the file
297.Pa /dev/tty
298and calling
299.Dv TIOCNOTTY
300on that file descriptor.
301.Pp
302The current system does not allocate a controlling terminal to
303a process on an
304.Fn open
305call: there is a specific ioctl called
306.Dv TIOCSCTTY
307to make a terminal the controlling
308terminal.
309In addition, a program can
310.Fn fork
311and call the
312.Fn setsid
313system call which will place the process into its own session - which
314has the effect of disassociating it from the controlling terminal.
315This is the new and preferred method for programs to lose their controlling
316terminal.
317.It Dv TIOCSETVERAUTH Fa int secs
318Indicate that the current user has successfully authenticated to this session.
319Future authentication checks may then be bypassed by performing a
320.Dv TIOCCHKVERAUTH
321check.
322The verified authentication status will expire after
323.Fa secs
324seconds.
325Only root may perform this operation.
326.It Dv TIOCCLRVERAUTH Fa void
327Clear any verified auth status associated with this session.
328.It Dv TIOCCHKVERAUTH Fa void
329Check the verified auth status of this session.
330The calling process must have the same real user ID and
331parent process as the process which called
332.Dv TIOCSETVERAUTH .
333A zero return indicates success.
334.It Dv TIOCSTOP Fa void
335Stop output on the terminal (like typing ^S at the keyboard).
336.It Dv TIOCSTART Fa void
337Start output on the terminal (like typing ^Q at the keyboard).
338.It Dv TIOCSCTTY Fa void
339Make the terminal the controlling terminal for the process (the process
340must not currently have a controlling terminal).
341.It Dv TIOCDRAIN Fa void
342Wait until all output is drained.
343.It Dv TIOCEXCL Fa void
344Set exclusive use on the terminal.
345No further opens are permitted except by root.
346Of course, this means that programs that are run by root (or setuid)
347will not obey the exclusive setting - which limits the usefulness
348of this feature.
349.It Dv TIOCNXCL Fa void
350Clear exclusive use of the terminal.
351Further opens are permitted.
352.It Dv TIOCFLUSH Fa int *what
353If the value of the int pointed to by
354.Fa what
355contains the
356.Dv FREAD
357bit as defined in
358.In sys/fcntl.h ,
359then all characters in the input queue are cleared.
360If it contains the
361.Dv FWRITE
362bit, then all characters in the output queue are cleared.
363If the value of the integer is zero, then it behaves as if both the
364.Dv FREAD
365and
366.Dv FWRITE
367bits were set (i.e., clears both queues).
368.It Dv TIOCGWINSZ Fa struct winsize *ws
369Put the window size information associated with the terminal in the
370.Va winsize
371structure pointed to by
372.Fa ws .
373The window size structure contains the number of rows and columns (and pixels
374if appropriate) of the devices attached to the terminal.
375It is set by user software and is the means by which most full\&-screen
376oriented programs determine the screen size.
377.It Dv TIOCSWINSZ Fa struct winsize *ws
378Set the window size associated with the terminal to be the value in
379the
380.Va winsize
381structure pointed to by
382.Fa ws
383(see above).
384.It Dv TIOCCONS Fa int *on
385If
386.Fa on
387points to a non-zero integer, redirect kernel console output
388.Po
389kernel
390.Fn printf Ns s
391.Pc
392to this terminal.
393If
394.Fa on
395points to a zero integer, redirect kernel console output back to the normal
396console.
397This is usually used on workstations to redirect kernel messages
398to a particular window.
399.It Dv TIOCMSET Fa int *state
400The integer pointed to by
401.Fa state
402contains bits that correspond to modem state.
403Following is a list of defined variables and the modem state they represent:
404.Pp
405.Bl -tag -width TIOCMXCTS -compact
406.It TIOCM_LE
407Line Enable.
408.It TIOCM_DTR
409Data Terminal Ready.
410.It TIOCM_RTS
411Request To Send.
412.It TIOCM_ST
413Secondary Transmit.
414.It TIOCM_SR
415Secondary Receive.
416.It TIOCM_CTS
417Clear To Send.
418.It TIOCM_CAR
419Carrier Detect.
420.It TIOCM_CD
421Carrier Detect (synonym).
422.It TIOCM_RNG
423Ring Indication.
424.It TIOCM_RI
425Ring Indication (synonym).
426.It TIOCM_DSR
427Data Set Ready.
428.El
429.Pp
430This call sets the terminal modem state to that represented by
431.Fa state .
432Not all terminals may support this.
433.It Dv TIOCMGET Fa int *state
434Return the current state of the terminal modem lines as represented
435above in the integer pointed to by
436.Fa state .
437.It Dv TIOCMBIS Fa int *state
438The bits in the integer pointed to by
439.Fa state
440represent modem state as described above; however, the state is OR-ed
441in with the current state.
442.It Dv TIOCMBIC Fa int *state
443The bits in the integer pointed to by
444.Fa state
445represent modem state as described above; however, each bit which is on
446in
447.Fa state
448is cleared in the terminal.
449.It Dv TIOCGTSTAMP Fa struct timeval *timeval
450Return the (single) timestamp.
451.It Dv TIOCSTSTAMP Fa struct tstamps *tstamps
452Chooses the conditions which will cause the current system time to be
453immediately copied to the terminal timestamp storage.
454This is often used to determine exactly the moment at which one or
455more of these events occurred, though only one can be monitored.
456Only
457.Dv TIOCM_CTS
458and
459.Dv TIOCM_CAR
460are honoured in
461.Va tstamps.ts_set
462and
463.Va tstamps.ts_clr ;
464these indicate which raising and lowering events on the respective lines
465should cause a timestamp capture.
466.It Dv TIOCSFLAGS Fa int *state
467The bits in the integer pointed to by
468.Fa state
469contain bits that correspond to serial port state.
470Following is a list of defined variables and the serial port state they
471represent:
472.Pp
473.Bl -tag -width TIOCFLAG_SOFTCAR -compact
474.It TIOCFLAG_SOFTCAR
475Ignore hardware carrier.
476.It TIOCFLAG_CLOCAL
477Set clocal on open.
478.It TIOCFLAG_CRTSCTS
479Set crtscts on open.
480.It TIOCFLAG_MDMBUF
481Set mdmbuf on open.
482.El
483.Pp
484This call sets the serial port state to that represented by
485.Fa state .
486Not all serial ports may support this.
487.It Dv TIOCGFLAGS Fa int *state
488Return the current state of the serial port as represented
489above in the integer pointed to by
490.Fa state .
491.El
492.Sh FILES
493.Bl -tag -width /dev/tty -compact
494.It Pa /dev/tty
495controlling terminal, if any
496.El
497.Sh SEE ALSO
498.Xr cu 1 ,
499.Xr stty 1 ,
500.Xr tty 1 ,
501.Xr ioctl 2 ,
502.Xr pty 4 ,
503.Xr termios 4 ,
504.Xr ttys 5 ,
505.Xr getty 8
506.Sh HISTORY
507The cua support is inspired by similar support in SunOS.
508