Sie sind hier

ldattach(8), a new command to attach line disciplines to a tty

Gespeichert von Marc Balmer am Di., 01/08/2008 - 11:26

Line disciplines have been in Unix since a long time.  While they are not device drivers, they interact with tty devices in a very peculiar manner:  They attach to a tty device and can then look at, or manipulate, the data as it flows through the tty device.  Line disciplines are thus the natural choice when serial data is used in the kernel, e.g. to exchange TCP/IP packets over a serial link using the SLIP protocol or decoding date and time information and provide a timedelta sensor.

There has not been much development in the last ten years or so in this area, probably because almost no one uses serial line IP anymore these days and serial tablets are mostly gone as well.  When I started working on timedelta sensors, I added a new line discipline, nmea(4), to decode the serial NMEA 0183 data that is sent by GPS receivers.  Another line discipline, msts(4), was added recently to decode the data sent by Meinberg radio-clocks.

Technically attaching a line discipline to a tty means that a process must open(2) a tty device.,attach the line discipline using an ioctl(2) call and then keep the file descriptor open for the rest of the time.  In the kernel, the line discipline provides a set of routines that are called for every operation on the tty device, like e.g. receiving or sending a character.  In the past, the attching has been done using a small line discipline specific daemon.  While slattach(8), the command to attach the sl(4) line discipline, was initially designed to also attach the (now gone) strip(4) line discipline, for nmea(4) a new utility, nmeaattach(8) was written, as the setup is slightly different than in the sl(4) case.

With the advent of more line disciplines the approach of having an attachment command for each and every line discipline became undesirable.  What I really wanted was a single command that can handle all line disciplines and that can easily be extended should a new line discipline being added.

The result is ldattach(8), call it the "ifconfig" of line-disciplines.  It can be used in "the old way" from the command line or from entries in the /etc/ttys file.  The new possibility to configure line discipline attaches in /etc/ttys allows you to configure the ttys in one single location, the attachment daemon no longer needs to be started in /etc/rc.local.  This is probably a cleaner way of doing it.

ldattach(8) and msts(8) are were introduced in OpenBSD 4.2-current and are part since the OpenBSD 4.3 release.