Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Archaic terminal API support

Closed / Fixed3606258fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 14 years ago
Descriptionplain2013-02-27 19:33:56
Background: unix/tclUnixChan.c still includes conditional support for the archaic sgtty and termio terminal APIs.  Since all major Unix platforms long ago standardized on the POSIX termios API, this code is largely untested, unmaintained, and moreover unnecessary.

Fossil branch jenglish-termios-cleanup created for the purpose of retiring this code and subsequent simplification; will record any findings in this tracker item.
jenglishplain2013-02-28 03:23:03
Concerning DIRECT_BAUD:
termios has cf[sg]et[io]speed() routines; termio encodes the baud rate in struct termio.c_cflag masked by CBAUD (same baud rate for input and output); sgtty puts it in struct sgttyb.sg_ispeed and sgttyb.sg_ospeed.

In all three cases, symbolic constants B50 .. B9600 are used instead of specifying the baud rate directly as an integer.   (DIRECT_BAUD might have been applicable in *very* old Unixes, though I cannot find any evidence for this).

For termios, we definitely want to use the symbolic constants; hence the DIRECT_BAUD code paths should be removed.
jenglishplain2013-02-28 03:30:19
More re: DIRECT_BAUD: original test had:

#ifdef B4800
#   if (B4800 == 4800)
#      define DIRECT_BAUD
#   endif /* B4800 == 4800 */
#endif /* B4800 */

This is almost certainly wrong -- even if the symbolic constant B4800 hapens to be equal to 4800 as an integer, that may very well be by accident and does not imply that Bnnn == nnn for all values of nnn, or that arbitrary baud rates are possible.  Nuking this, it's definitely not portable.
jenglishplain2013-02-28 05:30:31
Side note: it looks like tclUnixChan.c never checks the return value of tcgetattr() or tcsetattr(), nor various ioctl()s; it probably should.

Will not change that now, since raising errors for conditions that were previously silently ignored would be an incompatible change, but this should be revisited later.
jenglishplain2013-03-01 02:33:18
Concerning TIOCMGET and TIOCMSET (modem control ioctls, introduced with TIP#35): These are not specified by POSIX, but appear to be fairly widely supported (tested on Linux, IRIX, AIX, and HP-UX; googling indicates that it's also available on Solaris and OpenBSD.)

HP-UX requres #include <sys/modem.h> to make these ioctls available (confirmed by aku via the chat); on all other known systems <sys/ioctl.h> suffices.
jenglishplain2013-03-01 02:41:29
Concerning PAREXT: (space/mark parity): POSIX only specifies PARENB (parity enable) and PARODD (odd parity; default is even).  PAREXT appears to be supported on AIX, and possibly Solaris; googling indicates that it it not present, or present but not supported, on many other Unices.

Quoting http://www.linuxmisc.com/3-solaris/112d4028904df8f0.htm --| The Solaris stty(1) page has this to say:

| parext (-parext)
| Enable (disable) extended parity generation and detection for mark
| and space parity.
| parodd (- parodd)
| Select odd (even) parity, or mark (space) parity if parext is enabled.
|
| which if we assume that these two options just toggle the flags of the
| same name, implies:
|
| PAREXT|PARODD       ->  Mark parity  ( parity bit always a mark )
| PAREXT              ->  Space parity ( parity bit always a space )
|
| After a bit of poking around at other flavors, in the (vain) hope that
| someone else's man page was less cryptic, it looks like this particular
| flag was probably a holdover from SVR3.  It's certainly not portable.
|
| OpenServer's termio page claims that this flag only works when the terminal
| driver is set for SVID3 line discipline.  SGI's page lists the flag, but
| says it's not supported.  Solaris and AIX simply have the statement you've
| quoted above.  Linux, HP-UX, and OpenBSD (and presumably the other 4.4Lite
| derivatives) don't even define it, nor does the SUS.
jenglishplain2013-03-02 04:05:31
An infelicity in the TIP#35 specification: the write-only option -ttycontrol is used to set the modem control lines DTR and RTS, as well as for sending a BREAK.  These are logically separate functions (and, in Unix, using two different ioctls).  

POSIX provides a tcsendbreak() routine, but that doesn't fit well with the TIP#35 API (it's a one-shot call specifying a duration, not an on/off flag).
jenglishplain2013-03-02 04:06:19
Note concerning error messages:

When a feature is known missing at compile-time, in some cases tclUnixChan.c leaves an error message including all possible values whether supported or not, and in other cases it only lists the values that are available on that platform.

In the interest of reducing the massive amounts of ifdeffery present in that file, branch jenglish-termios-cleanup generally favors the first approach.
jenglishplain2013-03-02 06:10:43
Autoconf macro SC_SERIAL_PORT uses AC_TRY_RUN on a program that calls tcgetattr() on FD 0.  This leads to false negatives if ./configure is run in an environment where stdin is not a terminal.

Then it tries termio, followed by sgtty, with the same results.

THEN it tries termios, termio, and sgtty *again*, this time accounting for the possibilities of ENOTTY, ENXIO, and ENODEV.

Words fail me.

See also: SF#219194
See also: SF#227412
See also: SF#402923
See also: SF#403639
See also: SF#497147
jenglishplain2013-03-04 00:44:10
More re: PAREXT: Linux has a CMSPAR flag, with the same meaning as PAREXT.

CRTSCSTS is not in POSIX either, but it appears to be fairly widely available (some systems spell it CNEW_RTSCTS, others CRTSCTS).
jenglishplain2013-03-04 01:18:00
Branch jenglish-termios-cleanup merged to trunk.  Code is still pretty ifdef-heavy, but it's better than before.

Other notes: autogoo has changed, USE_TERMIOS replaced with  HAVE_TERMIOS_H; people will need to reconfgure.

It might be worthwhile backporting these changes to core-8-5-branch, however core-8-5-branch and trunk had already diverged quite a bit.

Leaving this bug open for now in case any new problems surface.
jenglishplain2013-04-05 10:41:09
It's been a month and nobody has complained that I've seen; closing.
Log in (anonymous is fine) to add a comment.