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