xref: /openbsd/share/man/man4/tty.4 (revision fc61954a)
1.\"	$OpenBSD: tty.4,v 1.46 2016/09/02 21:00:28 tedu 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: September 2 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 TABLDISC
208Tablet line discipline.
209.It SLIPDISC
210Serial IP line discipline.
211.It PPPDISC
212Point-to-Point Protocol line discipline.
213.It STRIPDISC
214Starmode Radio IP line discipline.
215.It NMEADISC
216NMEA 0183 line discipline.
217.It MSTSDISC
218Meinberg Standard Time String line discipline.
219.El
220.It Dv TIOCGETD Fa int *ldisc
221Return the current line discipline in the integer pointed to by
222.Fa ldisc .
223.It Dv TIOCSBRK Fa void
224Set the terminal hardware into BREAK condition.
225.It Dv TIOCCBRK Fa void
226Clear the terminal hardware BREAK condition.
227.It Dv TIOCSDTR Fa void
228Assert data terminal ready (DTR).
229.It Dv TIOCCDTR Fa void
230Clear data terminal ready (DTR).
231.It Dv TIOCGPGRP Fa int *tpgrp
232Return the current process group the terminal is associated
233with in the integer pointed to by
234.Fa tpgrp .
235This is the underlying call that implements the
236.Xr termios 4
237.Fn tcgetpgrp
238call.
239.It Dv TIOCSPGRP Fa int *tpgrp
240Associate the terminal with the process group (as an integer) pointed to by
241.Fa tpgrp .
242This is the underlying call that implements the
243.Xr termios 4
244.Fn tcsetpgrp
245call.
246.It Dv TIOCGETA Fa struct termios *term
247Place the current value of the termios state associated with the
248device in the termios structure pointed to by
249.Fa term .
250This is the underlying call that implements the
251.Xr termios 4
252.Fn tcgetattr
253call.
254.It Dv TIOCSETA Fa struct termios *term
255Set the termios state associated with the device immediately.
256This is the underlying call that implements the
257.Xr termios 4
258.Fn tcsetattr
259call with the
260.Dv TCSANOW
261option.
262.It Dv TIOCSETAW Fa struct termios *term
263First wait for any output to complete, then set the termios state
264associated with the device.
265This is the underlying call that implements the
266.Xr termios 4
267.Fn tcsetattr
268call with the
269.Dv TCSADRAIN
270option.
271.It Dv TIOCSETAF Fa struct termios *term
272First wait for any output to complete, clear any pending input,
273then set the termios state associated with the device.
274This is the underlying call that implements the
275.Xr termios 4
276.Fn tcsetattr
277call with the
278.Dv TCSAFLUSH
279option.
280.It Dv TIOCOUTQ Fa int *num
281Place the current number of characters in the output queue in the
282integer pointed to by
283.Fa num .
284.It Dv TIOCSTI Fa char *cp
285Simulate typed input.
286Pretend as if the terminal received the character pointed to by
287.Fa cp .
288.It Dv TIOCNOTTY Fa void
289This call is obsolete but left for compatibility.
290In the past, when a process that didn't have a controlling terminal
291(see
292.Em The Controlling Terminal
293in
294.Xr termios 4 )
295first opened a terminal device, it acquired that terminal as its
296controlling terminal.
297For some programs this was a hazard as they didn't want a controlling
298terminal in the first place, and this provided a mechanism to disassociate
299the controlling terminal from the calling process.
300It
301.Em must
302be called by opening the file
303.Pa /dev/tty
304and calling
305.Dv TIOCNOTTY
306on that file descriptor.
307.Pp
308The current system does not allocate a controlling terminal to
309a process on an
310.Fn open
311call: there is a specific ioctl called
312.Dv TIOCSCTTY
313to make a terminal the controlling
314terminal.
315In addition, a program can
316.Fn fork
317and call the
318.Fn setsid
319system call which will place the process into its own session - which
320has the effect of disassociating it from the controlling terminal.
321This is the new and preferred method for programs to lose their controlling
322terminal.
323.It Dv TIOCSETVERAUTH Fa int secs
324Indicate that the current user has successfully authenticated to this session.
325Future authentication checks may then be bypassed by performing a
326.Dv TIOCCHKVERAUTH
327check.
328The verified authentication status will expire after
329.Fa secs
330seconds.
331Only root may perform this operation.
332.It Dv TIOCCLRVERAUTH Fa void
333Clear any verified auth status associated with this session.
334.It Dv TIOCCHKVERAUTH Fa void
335Check the verified auth status of this session.
336The calling process must have the same real user ID and
337parent process as the process which called
338.Dv TIOCSETVERAUTH .
339A zero return indicates success.
340.It Dv TIOCSTOP Fa void
341Stop output on the terminal (like typing ^S at the keyboard).
342.It Dv TIOCSTART Fa void
343Start output on the terminal (like typing ^Q at the keyboard).
344.It Dv TIOCSCTTY Fa void
345Make the terminal the controlling terminal for the process (the process
346must not currently have a controlling terminal).
347.It Dv TIOCDRAIN Fa void
348Wait until all output is drained.
349.It Dv TIOCEXCL Fa void
350Set exclusive use on the terminal.
351No further opens are permitted except by root.
352Of course, this means that programs that are run by root (or setuid)
353will not obey the exclusive setting - which limits the usefulness
354of this feature.
355.It Dv TIOCNXCL Fa void
356Clear exclusive use of the terminal.
357Further opens are permitted.
358.It Dv TIOCFLUSH Fa int *what
359If the value of the int pointed to by
360.Fa what
361contains the
362.Dv FREAD
363bit as defined in
364.In sys/fcntl.h ,
365then all characters in the input queue are cleared.
366If it contains the
367.Dv FWRITE
368bit, then all characters in the output queue are cleared.
369If the value of the integer is zero, then it behaves as if both the
370.Dv FREAD
371and
372.Dv FWRITE
373bits were set (i.e., clears both queues).
374.It Dv TIOCGWINSZ Fa struct winsize *ws
375Put the window size information associated with the terminal in the
376.Va winsize
377structure pointed to by
378.Fa ws .
379The window size structure contains the number of rows and columns (and pixels
380if appropriate) of the devices attached to the terminal.
381It is set by user software and is the means by which most full\&-screen
382oriented programs determine the screen size.
383.It Dv TIOCSWINSZ Fa struct winsize *ws
384Set the window size associated with the terminal to be the value in
385the
386.Va winsize
387structure pointed to by
388.Fa ws
389(see above).
390.It Dv TIOCCONS Fa int *on
391If
392.Fa on
393points to a non-zero integer, redirect kernel console output
394.Po
395kernel
396.Fn printf Ns s
397.Pc
398to this terminal.
399If
400.Fa on
401points to a zero integer, redirect kernel console output back to the normal
402console.
403This is usually used on workstations to redirect kernel messages
404to a particular window.
405.It Dv TIOCMSET Fa int *state
406The integer pointed to by
407.Fa state
408contains bits that correspond to modem state.
409Following is a list of defined variables and the modem state they represent:
410.Pp
411.Bl -tag -width TIOCMXCTS -compact
412.It TIOCM_LE
413Line Enable.
414.It TIOCM_DTR
415Data Terminal Ready.
416.It TIOCM_RTS
417Request To Send.
418.It TIOCM_ST
419Secondary Transmit.
420.It TIOCM_SR
421Secondary Receive.
422.It TIOCM_CTS
423Clear To Send.
424.It TIOCM_CAR
425Carrier Detect.
426.It TIOCM_CD
427Carrier Detect (synonym).
428.It TIOCM_RNG
429Ring Indication.
430.It TIOCM_RI
431Ring Indication (synonym).
432.It TIOCM_DSR
433Data Set Ready.
434.El
435.Pp
436This call sets the terminal modem state to that represented by
437.Fa state .
438Not all terminals may support this.
439.It Dv TIOCMGET Fa int *state
440Return the current state of the terminal modem lines as represented
441above in the integer pointed to by
442.Fa state .
443.It Dv TIOCMBIS Fa int *state
444The bits in the integer pointed to by
445.Fa state
446represent modem state as described above; however, the state is OR-ed
447in with the current state.
448.It Dv TIOCMBIC Fa int *state
449The bits in the integer pointed to by
450.Fa state
451represent modem state as described above; however, each bit which is on
452in
453.Fa state
454is cleared in the terminal.
455.It Dv TIOCGTSTAMP Fa struct timeval *timeval
456Return the (single) timestamp.
457.It Dv TIOCSTSTAMP Fa struct tstamps *tstamps
458Chooses the conditions which will cause the current system time to be
459immediately copied to the terminal timestamp storage.
460This is often used to determine exactly the moment at which one or
461more of these events occurred, though only one can be monitored.
462Only
463.Dv TIOCM_CTS
464and
465.Dv TIOCM_CAR
466are honoured in
467.Va tstamps.ts_set
468and
469.Va tstamps.ts_clr ;
470these indicate which raising and lowering events on the respective lines
471should cause a timestamp capture.
472.It Dv TIOCSFLAGS Fa int *state
473The bits in the integer pointed to by
474.Fa state
475contain bits that correspond to serial port state.
476Following is a list of defined variables and the serial port state they
477represent:
478.Pp
479.Bl -tag -width TIOCFLAG_SOFTCAR -compact
480.It TIOCFLAG_SOFTCAR
481Ignore hardware carrier.
482.It TIOCFLAG_CLOCAL
483Set clocal on open.
484.It TIOCFLAG_CRTSCTS
485Set crtscts on open.
486.It TIOCFLAG_MDMBUF
487Set mdmbuf on open.
488.El
489.Pp
490This call sets the serial port state to that represented by
491.Fa state .
492Not all serial ports may support this.
493.It Dv TIOCGFLAGS Fa int *state
494Return the current state of the serial port as represented
495above in the integer pointed to by
496.Fa state .
497.El
498.Sh FILES
499.Bl -tag -width /dev/tty -compact
500.It Pa /dev/tty
501controlling terminal, if any
502.El
503.Sh SEE ALSO
504.Xr cu 1 ,
505.Xr stty 1 ,
506.Xr tty 1 ,
507.Xr ioctl 2 ,
508.Xr pty 4 ,
509.Xr termios 4 ,
510.Xr ttys 5 ,
511.Xr getty 8
512.Sh HISTORY
513The cua support is inspired by similar support in SunOS.
514