[comp.sys.sun] stty problem

mhickey@sherwood.prime.com (Mark E. Hickey x4149 x4417 ) (11/14/89)

>I can't seem to alter the options of /dev/ttya or /dev/ttyb on my SPARC
>station 1.  The command I use is
> 
>	 stty parodd cs8 > /dev/ttya
>	  
> [results of this command failing deleted]
>
>		      What am I doing wrong?

Just out of curiousity, I looked into this problem on our SPARCstation 1
(run- ning 4.0.3). I found that the device must be turned on in the file
/etc/ttytab (ie: the fourth field of the entry for ttya must read "on");
by default it is turned off.  Also, if you turn the port on while the
system is running, you must tell init to re-read the file by sending it
SIGHUP (eg: kill -1 1 on most systems, do a "ps -eax | grep init" to be
sure of the process id).  If the port is turned off, getty apparently
resets the parameters no matter what you set them to using stty.  Also, if
the port is turned on, the output from stty will look like:

speed 9600 baud, 0 rows, 0 columns
-parenb -parodd cs8 -cstopb hupcl cread -clocal -crtscts 
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -iuclc 
-ixon ixany -ixoff -imaxbel 
-isig -icanon -xcase -echo -echoe echok -echonl -noflsh -tostop 
-echoctl -echoprt -echoke 
-opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel 
min 1, time 0
erase  kill   werase rprnt  flush  lnext  susp   intr   quit   stop   eof
^?     ^U     ^W     ^R     ^O     ^V     ^Z/^Y  ^C     ^\     ^S/^Q  

Notice the extra fields "min 1, time 0" as well as the difference in the
default settings for ixon, ixany, etc. ( the defaults may be different on your
system, though).
			Good luck

Mark Hickey          Computervision Division
O/S Development      Prime Computer, Inc.
		     Bedford, MA     01730

UUCP    : {decvax|linus|sun}!cvbnet!mhickey
Internet: mhickey@cvbnet.prime.com

ghfeil@white.toronto.edu (Georg Feil) (11/22/89)

>X-Sun-Spots-Digest: Volume 8, Issue 198, message 11 of 18
>>I can't seem to alter the options of /dev/ttya or /dev/ttyb on my SPARC
>>station 1...
>
>Just out of curiousity, I looked into this problem on our SPARCstation 1
>(run- ning 4.0.3). I found that the device must be turned on in the file
>/etc/ttytab (ie: the fourth field of the entry for ttya must read "on");
>Mark Hickey          Computervision Division

I have recently been having a similar problem with a Sun 3/50 OS4.0.1.  I
want to set /dev/ttyb to use 8 bits/char no parity instead of the default
7 bits/even parity. Using 'stty -parenb cs8 >/dev/ttyb' gives no errors
but also has no effect. I tried changing the std.9600 entry for ttyb in
/etc/ttytab to something else, but this has no effect if the device is
'off'.  I guess the std.9600 is for the getty program only.

I finally resorted to writing a program that uses ioctl(2) to set the
device as required. The trick is that the updated settings persist *only
as long as the file to /dev/ttyb is open*. Ttyb is mysteriously reset to
the default state immediately afterwards. In my case I was using cat(1) to
dump files across a serial line, so now I use my own simple version of cat
that reconfigures the port first.

Anyone have any ideas on how to make changes persist? Where are the
default settings entered? (I'm not a sysadmin, so I have no clue.)

Thanks,
Georg.

jdp@uunet.uu.net (John Polstra) (11/22/89)

In article <3081@brazos.Rice.edu> mhickey@sherwood.prime.com (Mark E. Hickey x4149 x4417 ) writes:
>X-Sun-Spots-Digest: Volume 8, Issue 198, message 11 of 18
>
>>I can't seem to alter the options of /dev/ttya or /dev/ttyb on my SPARC
>>station 1.  The command I use is
>> 
>>	 stty parodd cs8 > /dev/ttya
>>	  
>> [results of this command failing deleted]
>>
>>		      What am I doing wrong?
>
>Just out of curiousity, I looked into this problem on our SPARCstation 1
>(run- ning 4.0.3). I found that the device must be turned on in the file
>/etc/ttytab (ie: the fourth field of the entry for ttya must read "on");
>by default it is turned off.  Also, if you turn the port on while the
>system is running, you must tell init to re-read the file by sending it
>SIGHUP (eg: kill -1 1 on most systems, do a "ps -eax | grep init" to be
>sure of the process id).  If the port is turned off, getty apparently
>resets the parameters no matter what you set them to using stty ...

Good guess, but that's not what is going on.

When you do an "stty" under Unix, the new modes stick only as long as the
tty port is held open (by one or more processes).  When the last process
closes the tty, the modes revert to some kernel-defined default.  You can
see this by comparing the effects of the following two lines:

    stty parodd cs8 >/dev/ttya; stty everything >/dev/ttya

    (stty parodd cs8; stty everything) >/dev/ttya

In the first line, the tty gets closed between the two "stty" commands,
and the second "stty" will show the default modes regardless of what was
set by the first "stty".

In the second line, the tty is held open from the beginning of the first
"stty" through the end of the second "stty".  Here, the second "stty" will
show the modes as set by the first "stty".

If you mark a tty as "on" in "/etc/ttytab", then "getty" will hold that
tty open all the time.  Then, any "stty" that you do will stick.  This has
the unfortunate side-effect that any incoming characters on the tty will
be swallowed by "getty".

If you want to change the tty modes for a single command (e.g., "foo"),
the easiest way is like this:

    (stty parodd cs8; foo) >/dev/ttya

If you want to change the modes more-or-less permanently, this trick will
work:

    sleep 100000000 >/dev/ttya &
    stty parodd cs8 >/dev/ttya

The "sleep" just holds the tty open for a few years, so that subsequent
"stty" commands will stick.

   John Polstra               jdp@polstra.UUCP
   Polstra & Co., Inc.        ...{uunet,sun}!practic!polstra!jdp
   Seattle, WA                (206) 932-6482

sysnmc@uunet.uu.net (Matt Cohen x7023) (12/03/89)

"It's not a bug, it's a feature."

In sun-spots v8n207, ghfeil@white.toronto.edu (Georg Feil) says:
>Using 'stty -parenb cs8 >/dev/ttyb' gives no errors
>but also has no effect....
>I tried changing the std.9600 entry for ttyb in
>/etc/ttytab to something else, but this has no effect if the device is
>'off'...
>I finally resorted to writing a program that uses ioctl(2) to set the
>device as required. The trick is that the updated settings persist *only
>as long as the file to /dev/ttyb is open*. Ttyb is mysteriously reset to
>the default state immediately afterwards...
>Anyone have any ideas on how to make changes persist?

The serial port device driver (I think) resets the port to its default
characteristics on the last close of the port.  The changes to /etc/ttytab
only work when the device is "on" because getty sets the port
characteristics and sleeps, leaving the port open.  With the entry "off",
there is no getty and the port never gets set.

The solution is to have some process always have the port open.
A simple solution is:
	prompt% sleep 10000000 > /dev/ttyb &
	[1] nnnn
	prompt% stty -parenb cs8 >/dev/ttyb

This isn't the best way to do this however. Unfortunately, there is no
great way. Better ways include writing a small program that opens the
port, then calls pause() or sends itself a SIGSTOP. Good luck!

                        Matt Cohen <...!uunet!chron!sysnmc>
                        Unix Systems Programmer
                        The Houston Chronicle
                        801 Texas Avenue, Houston, TX 77002 USA
                        +1 713 220 7023
                        "Houston's Leading Information Source"