1*61599Sbostic.\" Copyright (c) 1991, 1992, 1993 2*61599Sbostic.\" The Regents of the University of California. All rights reserved. 320632Smckusick.\" 455908Smarc.\" %sccs.include.redist.roff% 520632Smckusick.\" 6*61599Sbostic.\" @(#)tty.4 8.1 (Berkeley) 06/05/93 748410Sbostic.\" 855909Scael.Dd August 14, 1992 955908Smarc.Dt TTY 4 1055908Smarc.Os BSD 4 1155908Smarc.Sh NAME 1255908Smarc.Nm tty 1355908Smarc.Nd general terminal interface 1455908Smarc.Sh SYNOPSIS 1555908Smarc.Fd #include <sys/ioctl.h> 1655908Smarc.Sh DESCRIPTION 1755908SmarcThis section describes the interface to the terminal drivers 1855908Smarcin the system. 1955908Smarc.Ss Terminal Special Files 2055908SmarcEach hardware terminal port on the system usually has a terminal special device 2155908Smarcfile associated with it in the directory ``/dev/'' (for 2255908Smarcexample, ``/dev/tty03''). 2355908SmarcWhen a user logs into 2455908Smarcthe system on one of these hardware terminal ports, the system has already 2555908Smarcopened the associated device and prepared the line for normal interactive 2655908Smarcuse (see 2755908Smarc.Xr getty 8 .) 2855908SmarcThere is also a special case of a terminal file that connects not to 2955908Smarca hardware terminal port, but to another program on the other side. 3055908SmarcThese special terminal devices are called 3155908Smarc.Em ptys 3255908Smarcand provide the mechanism necessary to give users the same interface to the 3355908Smarcsystem when logging in over a network (using 3455908Smarc.Xr rlogin 1 , 3528263Skarelsor 3655908Smarc.Xr telnet 1 3755908Smarcfor example.) Even in these cases the details of how the terminal 3855908Smarcfile was opened and set up is already handled by special software 3955908Smarcin the system. 4055908SmarcThus, users do not normally need to worry about the details of 4155908Smarchow these lines are opened or used. Also, these lines are often used 4255908Smarcfor dialing out of a system (through an out-calling modem), but again 4355908Smarcthe system provides programs that hide the details of accessing 4455908Smarcthese terminal special files (see 4555908Smarc.Xr tip 2 .) 4655908Smarc.Pp 4755908SmarcWhen an interactive user logs in, the system prepares the line to 4855908Smarcbehave in a certain way (called a 4955908Smarc.Em "line discipline" ), 5055908Smarcthe particular details of which is described in 5155908Smarc.Xr stty 1 5255908Smarcat the command level, and in 5355908Smarc.Xr termios 4 5455908Smarcat the programming level. A user may be concerned with changing 5555908Smarcsettings associated with his particular login terminal and should refer 5655909Scaelto the preceding man pages for the common cases. The remainder of 5755908Smarcthis man page is concerned 5855908Smarcwith describing details of using and controlling terminal devices 5955908Smarcat a low level, such as that possibly required by a program wishing 6055908Smarcto provide features similar to those provided by the system. 6155908Smarc.Ss Line disciplines 6255908SmarcA terminal file is used like any other file in the system in that 6355908Smarcit can be opened, read, and written to using standard system 6455908Smarccalls. For each existing terminal file, a software processing module 6555908Smarccalled a 6655908Smarc.Em "line discipline" 6755908Smarcis associated with it. The 6855908Smarc.Em "line discipline" 6955908Smarcessentially glues the low level device driver code with the high 7055908Smarclevel generic interface routines (such as 7155908Smarc.Xr read 2 7220632Smckusickand 7355908Smarc.Xr write 2 ), 7455908Smarcand is responsible for implementing the semantics associated 7555908Smarcwith the device. When a terminal file is first opened by a program, 7655908Smarcthe default 7755908Smarc.Em "line discipline" 7855908Smarccalled the 7955908Smarc.Dv termios 8055908Smarcline discipline is associated with the file. This is the primary 8155908Smarcline discipline that is used in most cases and provides the semantics 8255908Smarcthat users normally associate with a terminal. When the 8355908Smarc.Dv termios 8455908Smarcline discipline is in effect, the terminal file behaves and is 8555908Smarcoperated according to the rules described in 8655908Smarc.Xr termios 4 . 8755908SmarcPlease refer to that man page for a full description of the terminal 8855908Smarcsemantics. 8955908SmarcThe operations described here 9055908Smarcgenerally represent features common 9155908Smarcacross all 9255909Scael.Em "line disciplines" 9355908Smarchowever, some of these calls may not 9455908Smarcmake sense in conjunction with a line discipline other than 9555908Smarc.Dv termios , 9655908Smarcand some may not be supported by the underlying 9755908Smarchardware or (lack thereof, as in the case of ptys). 9855908Smarc.Ss Terminal File Operations 9955908SmarcAll of the following operations are invoked using the 10055908Smarc.Xr ioctl 2 10155908Smarcsystem call. Refer to that man page for a description of 10255908Smarcthe 10355908Smarc.Em request 10455908Smarcand 10555908Smarc.Em argp 10655908Smarcparameter. 10755909ScaelIn addition to the ioctl 10855909Scael.Em requests 10955908Smarcdefined here, the specific line discipline 11055909Scaelin effect will define other 11155908Smarc.Em requests 11255908Smarcspecific to it (actually 11355908Smarc.Xr termios 4 11455909Scaeldefines them as function calls, not ioctl 11555908Smarc.Em requests .) 11655908SmarcThe following section lists the available ioctl requests. The 11755908Smarcname of the request and the typed 11855908Smarc.Em argp 11955908Smarcparameter (if any) 12055908Smarcis listed along with a description of its 12155908Smarcpurpose. For example, the first entry says 12255909Scael.Pp 12355909Scael.D1 Em "TIOCSETD int *ldisc" 12455909Scael.Pp 12555908Smarcand would be called on the terminal associated with 12655908Smarcfile discriptor zero by the following code fragment: 12755908Smarc.Bd -literal 12855908Smarc int ldisc; 12955908Smarc 13055908Smarc ldisc = TTYDISC; 13155908Smarc ioctl(0, TIOCSETD, &ldisc); 13255908Smarc.Ed 13355908Smarc.Ss Terminal File Request Descriptions 13455909Scael.Bl -tag -width TIOCGWINSZ 13555909Scael.It Dv TIOCSETD Fa int *ldisc 13655908SmarcChange to the new line discipline pointed to by 13755908Smarc.Fa ldisc . 13855909ScaelThe available line disciplines are listed in 13955909Scael.Pa Aq sys/termios.h 14055908Smarcand currently are: 14155909Scael.Pp 14255909Scael.Bl -tag -width TIOCGWINSZ -compact 14355908Smarc.It TTYDISC 14455908SmarcTermios interactive line discipline. 14555908Smarc.It TABLDISC 14655908SmarcTablet line discipline. 14755908Smarc.It SLIPDISC 14855908SmarcSerial IP line discipline. 14955908Smarc.El 15055909Scael.Pp 15155909Scael.It Dv TIOCGETD Fa int *ldisc 15255908SmarcReturn the current line discipline in the integer pointed to by 15355908Smarc.Fa ldisc . 15455909Scael.It Dv TIOCSBRK Fa void 15555908SmarcSet the terminal hardware into BREAK condition. 15655909Scael.It Dv TIOCCBRK Fa void 15755908SmarcClear the terminal hardware BREAK condition. 15855909Scael.It Dv TIOCSDTR Fa void 15955908SmarcAssert data terminal ready (DTR). 16055909Scael.It Dv TIOCCDTR Fa void 16155908SmarcClear data terminal ready (DTR). 16255909Scael.It Dv TIOCGPGRP Fa int *tpgrp 16355908SmarcReturn the current process group the terminal is associated 16455908Smarcwith in the integer pointed to by 16555908Smarc.Fa tpgrp . 16655908SmarcThis is the underlying call that implements the 16755908Smarc.Xr termios 4 16855908Smarc.Fn tcgetattr 16955908Smarccall. 17055909Scael.It Dv TIOCSPGRP Fa int *tpgrp 17155908SmarcAssociate the terminal with the process group (as an integer) pointed to by 17255908Smarc.Fa tpgrp . 17355908SmarcThis is the underlying call that implements the 17455908Smarc.Xr termios 4 17555908Smarc.Fn tcsetattr 17655908Smarccall. 17755909Scael.It Dv TIOCGETA Fa struct termios *term 17855908SmarcPlace the current value of the termios state associated with the 17955908Smarcdevice in the termios structure pointed to by 18055908Smarc.Fa term . 18155908SmarcThis is the underlying call that implements the 18255908Smarc.Xr termios 4 18355908Smarc.Fn tcgetattr 18455908Smarccall. 18555909Scael.It Dv TIOCSETA Fa struct termios *term 18655908SmarcSet the termios state associated with the device immediatly. 18755908SmarcThis is the underlying call that implements the 18855908Smarc.Xr termios 4 18955908Smarc.Fn tcsetattr 19055909Scaelcall with the 19155908Smarc.Dv TCSANOW 19255908Smarcoption. 19355909Scael.It Dv TIOCSETAW Fa struct termios *term 19455908SmarcFirst wait for any output to complete, then set the termios state 19555908Smarcassociated with the device. 19655908SmarcThis is the underlying call that implements the 19755908Smarc.Xr termios 4 19855908Smarc.Fn tcsetattr 19955909Scaelcall with the 20055908Smarc.Dv TCSADRAIN 20155908Smarcoption. 20255909Scael.It Dv TIOCSETAF Fa struct termios *term 20355908SmarcFirst wait for any output to complete, clear any pending input, 20455908Smarcthen set the termios state associated with the device. 20555908SmarcThis is the underlying call that implements the 20655908Smarc.Xr termios 4 20755908Smarc.Fn tcsetattr 20855909Scaelcall with the 20955908Smarc.Dv TCSAFLUSH 21055908Smarcoption. 21155909Scael.It Dv TIOCOUTQ Fa int *num 21255908SmarcPlace the current number of characters in the output queue in the 21355908Smarcinteger pointed to by 21455908Smarc.Fa num . 21555909Scael.It Dv TIOCSTI Fa char *cp 21655908SmarcSimulate typed input. Pretend as if the terminal recieved the 21755908Smarccharacter pointed to by 21855908Smarc.Fa cp . 21955909Scael.It Dv TIOCNOTTY Fa void 22055908SmarcThis call is obsolete but left for compatability. In the past, when 22155908Smarca process that didn't have a controlling terminal (see 22255908Smarc.Em The Controlling Terminal 22355908Smarcin 22455908Smarc.Xr termios 4 ) 22555908Smarcfirst opened a terminal device, it acquired that terminal as its 22655908Smarccontrolling terminal. For some programs this was a hazard as they 22755908Smarcdidn't want a controlling terminal in the first place, and this 22855908Smarcprovided a mechanism to disassociate the controlling terminal from 22955908Smarcthe calling process. It 23055908Smarc.Em must 23155908Smarcbe called by opening the file 23255908Smarc.Pa /dev/tty 23355908Smarcand calling 23455908Smarc.Dv TIOCNOTTY 23555908Smarcon that file descriptor. 23655908Smarc.Pp 23755908SmarcThe current system does not allocate a controlling terminal to 23855908Smarca process on an 23955908Smarc.Fn open 24055908Smarccall: there is a specific ioctl called 24155908Smarc.Dv TIOSCTTY 24255908Smarcto make a terminal the controlling 24355908Smarcterminal. 24455908SmarcIn addition, a program can 24555908Smarc.Fn fork 24655908Smarcand call the 24755908Smarc.Fn setsid 24855908Smarcsystem call which will place the process into its own session - which 24955908Smarchas the effect of disassociating it from the controlling terminal. This 25055908Smarcis the new and prefered method for programs to lose their controlling 25155908Smarcterminal. 25255909Scael.It Dv TIOCSTOP Fa void 25355908SmarcStop output on the terminal (like typing ^S at the keyboard). 25455909Scael.It Dv TIOCSTART Fa void 25555909ScaelStart output on the terminal (like typing ^Q at the kayboard). 25655909Scael.It Dv TIOCSCTTY Fa void 25755908SmarcMake the terminal the controlling terminal for the process (the process 25855908Smarcmust not currently have a controlling terminal). 25955909Scael.It Dv TIOCDRAIN Fa void 26055908SmarcWait until all output is drained. 26155909Scael.It Dv TIOCEXCL Fa void 26255908SmarcSet exclusive use on the terminal. No further opens are permitted 26355908Smarcexcept by root. Of course, this means that programs that are run by 26455909Scaelroot (or setuid) will not obey the exclusive setting - which limits 26555908Smarcthe usefullness of this feature. 26655909Scael.It Dv TIOCNXCL Fa void 26755908SmarcClear exclusive use of the terminal. Further opens are permitted. 26855909Scael.It Dv TIOCFLUSH Fa int *what 26955908SmarcIf the value of the int pointed to by 27055908Smarc.Fa what 27155908Smarccontains the 27255908Smarc.Dv FREAD 27355908Smarcbit as defined in 27455909Scael.Pa Aq sys/file.h , 27555908Smarcthen all characters in the input queue are cleared. If it contains 27655908Smarcthe 27755908Smarc.Dv FWRITE 27855908Smarcbit, then all characters in the output queue are cleared. If the 27955909Scaelvalue of the integer is zero, then it behaves as if both the 28055909Scael.Dv FREAD 28155909Scaeland 28255909Scael.Dv FWRITE 28355909Scaelbits were set (i.e. clears both queues). 28455909Scael.It Dv TIOCGWINSZ Fa struct winsize *ws 28555908SmarcPut the window size information associated with the terminal in the 28655908Smarc.Va winsize 28755908Smarcstructure pointed to by 28855908Smarc.Fa ws . 28955908SmarcThe window size structure contains the number of rows and columns (and pixels 29055908Smarcif appropiate) of the devices attached to the terminal. It is set by user software 29155908Smarcand is the means by which most full\&-screen oriented programs determine the 29255908Smarcscreen size. The 29355908Smarc.Va winsize 29455908Smarcstructure is defined in 29555909Scael.Pa Aq sys/ioctl.h . 29655909Scael.It Dv TIOCSWINSZ Fa struct winsize *ws 29755908SmarcSet the window size associated with the terminal to be the value in 29855908Smarcthe 29955908Smarc.Va winsize 30055908Smarcstructure pointed to by 30155908Smarc.Fa ws 30255908Smarc(see above). 30355909Scael.It Dv TIOCCONS Fa int *on 30455908SmarcIf 30555908Smarc.Fa on 30655908Smarcpoints to a non-zero integer, redirect kernel console output (kernel printf's) 30755908Smarcto this terminal. 30855908SmarcIf 30955908Smarc.Fa on 31055908Smarcpoints to a zero integer, redirect kernel console output back to the normal 31155908Smarcconsole. This is usually used on workstations to redirect kernel messages 31255908Smarcto a particular window. 31355909Scael.It Dv TIOCMSET Fa int *state 31455908SmarcThe integer pointed to by 31555908Smarc.Fa state 31655908Smarccontains bits that correspond to modem state. Following is a list 31755908Smarcof defined variables and the modem state they represent: 31855909Scael.Pp 31955909Scael.Bl -tag -width TIOCMXCTS -compact 32055908Smarc.It TIOCM_LE 32155908SmarcLine Enable. 32255908Smarc.It TIOCM_DTR 32355908SmarcData Terminal Ready. 32455908Smarc.It TIOCM_RTS 32555908SmarcRequest To Send. 32655908Smarc.It TIOCM_ST 32755908SmarcSecondary Transmit. 32855908Smarc.It TIOCM_SR 32955908SmarcSecondary Recieve. 33055908Smarc.It TIOCM_CTS 33155908SmarcClear To Send. 33255908Smarc.It TIOCM_CAR 33355908SmarcCarrier Detect. 33455908Smarc.It TIOCM_CD 33555908SmarcCarier Detect (synonym). 33655908Smarc.It TIOCM_RNG 33755908SmarcRing Indication. 33855908Smarc.It TIOCM_RI 33955908SmarcRing Indication (synonym). 34055908Smarc.It TIOCM_DSR 34155908SmarcData Set Ready. 34255908Smarc.El 34355909Scael.Pp 34455908SmarcThis call sets the terminal modem state to that represented by 34555908Smarc.Fa state . 34655908SmarcNot all terminals may support this. 34755909Scael.It Dv TIOCMGET Fa int *state 34855908SmarcReturn the current state of the terminal modem lines as represented 34955908Smarcabove in the integer pointed to by 35055908Smarc.Fa state . 35155909Scael.It Dv TIOCMBIS Fa int *state 35255908SmarcThe bits in the integer pointed to by 35355908Smarc.Fa state 35455908Smarcrepresent modem state as described above, however the state is OR-ed 35555908Smarcin with the current state. 35655909Scael.It Dv TIOCMBIC Fa int *state 35755908SmarcThe bits in the integer pointed to by 35855908Smarc.Fa state 35955908Smarcrepresent modem state as described above, however each bit which is on 36055908Smarcin 36155908Smarc.Fa state 36255908Smarcis cleared in the terminal. 36355908Smarc.El 36455908Smarc.Sh SEE ALSO 36555908Smarc.Xr getty 8 , 36655908Smarc.Xr ioctl 2 , 36755908Smarc.Xr pty 4 , 36855908Smarc.Xr stty 1 , 36955908Smarc.Xr termios 4 370