Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site cheviot.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!mcvax!ukc!cheviot!andy From: andy@cheviot.UUCP (Andy Linton) Newsgroups: net.bugs.4bsd Subject: Pseudo terminal problems Message-ID: <270@cheviot.UUCP> Date: Mon, 18-Feb-85 12:40:17 EST Article-I.D.: cheviot.270 Posted: Mon Feb 18 12:40:17 1985 Date-Received: Thu, 21-Feb-85 05:02:21 EST Expires: Thu, 28-Feb-85 20:00:00 EST Reply-To: andy@cheviot.UUCP (Andy Linton) Organization: U. of Newcastle upon Tyne, U.K. Lines: 110 Here at the Computing Lab we have attempted to connect one of our VAX to the campus network NUNET. The VAX is running BSD 4.2 UNIX. The interface software is taking advantage of 4.2's pseudo terminal feature. Our problem stems from how echoing is handled on both NUNET and UNIX: Terminal Network Interface UNIX 1 -------------- | 2 <------------- : ----- 3 -----> 4 -----------> <----------- 5 <---- 6 ------ 7 <------------- The user enters data at a terminal (1), which is echoed by the network (2). Eventually the user types a carriage return and the packet is forwarded by the network to the interface (3). The in- terface writes the data into the master end of a pseudo terminal (4). The user process can read the data from the slave end of the pseudo terminal, and (if ECHO is on), echoes the data just received back to the interface (5). The interface then dutifully sends the data back out to the network (6), which is then displayed on the user's terminal once again (7). NUNET does permit us to turn off echoing. However, this results in the user not seeing what has been typed until it is echoed by UNIX. This solution has not proven popular. Two other solutions have been tried, neither of which are satis- factory: Solution 1. Solution 1 involves turning off the Master pseudo terminal echo- ing (and everything else) by setting sg_flags=0 before the user's process is logged into UNIX. This results in everything typed at the terminal end being echoed twice, once by NUNET, and then once by the user's UNIX process. Although this method fails when the master pseudo terminal transmits to the slave pseudo terminal in the interface, it works in a 'C' program which forks a child process. Specifically, in the test program, the master writes to the slave (which performs a read). The master then performs its own read. If sg_flags is set to ECHO, the text is echoed back (and the mas- ter can read it). If sg_flags is set to 0, nothing is echoed and the master waits indefinitely (hangs). The major difference between the interface and the 'C' test pro- gram is the file numbers assigned to the slave pseudo terminal. In the interface, the slave pseudo terminal communicates with the master using file identifiers 0, 1, and 2 (the standard process I/O file identifiers). While in the test program, the slave is communicating using a higher file identifier number (in most cases it is 4). Additionally, the child process from the inter- face executes 'login', whereas the test program is simply a sub- process performing a read. Due to the lack of success with solution 1, a second solution has been tried: Solution 2 Solution 2 is written so that the master keeps the file identif- ier of the slave pseudo terminal which it spawned. Whenever the master attempts to write to the slave, it turns slave's the echo- ing off (using an ioctl). Once the write is done, the master checks an internal flag to determine if echoing should be re- stored. If slave echoing must be restored, another ioctl is per- formed. The algorithm is essentially: IOCTL(slave echo off); WRITE(message to slave); if SlaveWasEchoing then IOCTL(slave echo on); This method, although inelegant, works most of the time. Howev- er, every 48-72 hours or so, the ioctl (turning off slave echo- ing) hangs. Originally, the ioctl call turning the echo off used a TIOCSETP call, which caused the process to wait (hang). The current version (which still occasionally hangs) uses a TIOCSETN. Note that it is important that the UNIX process be allowed to set and reset the ECHO flag as it would do for a directly connected terminal. It is from the value of the ECHO flag that the inter- face informs NUNET when to echo (or suppress echoing) at the user's terminal. The most common example of this is the suppres- sion of echoing when prompting for the user's password. Has any other user of pseudo terminals had a similar problem? If so, how was it fixed? Thanks, Larry Hughes Computing Laboratory University of Newcastle upon Tyne England Aindrias Mac Giolla Fhionntain - Computing Lab., U of Newcastle upon Tyne ARPA : andy%cheviot%newcastle.mailnet@MIT-MULTICS.ARPA UUCP : UK!ukc!cheviot!andy *** Ni fui moran beagan d'aon rud, ach is fui moran beagan ceille. ***