Red Hat Bugzilla – Bug 1407
Not setting serial port setting correctly
Last modified: 2008-05-01 11:37:49 EDT
I have a Point Of Sale application which uses Tcl/Tk/TclX.
Part of its operation is to open a serial port and send/
receive data from it (example is a serial port printer).
With the default Red Hat 5.2 tcl-8.0.3-20 package, the Tcl
code is failing to notice that /dev/ttyS1 is a tty device
and therefore it doesn't set the termios settings to a nice
default. The end result is that icannon is left set which
means I don't get the return data from the printer (since
it is sending me control codes that are almost never a
newline). Also echo is left set so that everything I
receive from the printer (status information) is echoed
back to the printer which results in garbage all over the
The really odd thing is that if I rebuild the tcltk packages
myself using "rpm -ba tcltk-8.0.spec" and then use it, all
is fine! Why would my version generated from the same
sources as the one that ships with Red Hat 5.2 give a
I've tracked the code down and basically in the tcl
source code tcl8.0.3/unix/tclUnixChan.c there is code
that uses isatty to check if the file being opened is
a serial port. If so it calls TtyInit which sets up the
stty setting nicely. With the Tcl that Red Hat ships,
isatty is returning false for /dev/ttyS1 whereas when I
compile my own, it properly returns true.
I tracked the problem down a little using strace and found
that at the point the file is being opened, there is a
TCGETA systems call to get the current attributes. I
assume this is isatty doing this. Then in the good version
TCGETA is called again followed by a TCSETA which properly
sets the attributes (like -icanon -echo ... which are needed
for the serial printer). In the tcl that ships with Red
Hat 5.2, there is only the one TCGETA and then the code
carries on. The attributes are never set so my LinuxPOS
Can anyone shed any more light on this problem? I don't
want to have to tell all our customers running Red Hat 5.2
that they have to recompile the tcl package. I can add
code to my LinuxPOS product to set the tty attributes
which is what I guess I'll have to do but I would really
like to understand the problem. Also I hope the problem
will be fixed in the next Red Hat release.
I believe this problem may exist in all the 5.x Red Hat
releases since I've had this problem before and could never
figure it out. I always just went back to Red Hat 4.2
which worked correctly. Now that I've tracked it down
more, I hope it can get fixed!
I have assigned this report to a developer for further review.
isatty() should not be doing a TCSETA (really a tcsetattr()) call.
I suggest doing a "stty -g" on a working system, then give the
output of stty -g on the working system as an argument to stty
on the non-working system, and see if that fixes it. Please
report here. Thanks!
Closed because of lack of feedback. Please reopen if still valid.