PORT_HOLD(1M) (Line Printer Spooling Utilities) PORT_HOLD(1M)
NAME
port_hold - hold serial lines open
SYNOPSIS
/local/bin/porthold <stty_file >log_file 2>&1 &
DESCRIPTION
port_hold, which runs as a background process started by
/etc/rc2.d/S80porthold, opens and establishes initial
stty(1) modes for each port named in sttyfile. Signals are
trapped and ignored, so port_hold never terminates.
port_hold can be used to compensate for a "feature" of the
serial port subsystem. As soon as no process has a
particular serial port open, the line discipline for that
port immediately reverts to a default state (which does not
honor XON/XOFF flow control), even if data is still draining
to the port. If the serial device attempts to throttle the
system's output by transmitting an XOFF at a time when no
process has the port open, the XOFF is ignored; output
continues; and the device is usually overrun. This behavior
tends to cause problems for serial printers: the symptom is
missing and/or garbled printer output, especially near the
end of an otherwise correct print job. This symptom may be
observed only rarely, due to the narrow timing window in
which the "problem" occurs.
It should be noted that however troublesome this is, it
exists for good, although arcane, reasons. Likewise, the
default line discipline for a closed port is proper, if
somewhat inconvenient. port_hold overcomes the problems
inherent in this feature by making sure that at least one
process holds the port open at all times, with the correct
line discipline. port_hold accomplishes this at the lowest
possible cost: only one process is required to hold any
number of ports open perpetually; each port can have a
different "default" stty setting, as required.
sttyfile is an ASCII text file, each line of which is
either a comment or a stty(1) command line. Comment lines,
Page 1 May 1989
PORT_HOLD(1M) (Line Printer Spooling Utilities) PORT_HOLD(1M)
which must start with a pound sign (#), are ignored. All
other lines are expected to be valid stty commands, which
must start with the string stty and end with a standard
input redirection clause (i.e., </dev/ttyxx). The device
named in the redirection must be a character special device.
Lines which do not meet these requirements are ignored.
The following processing is done for each valid stty line in
sttyfile.
(1) Open the port specified by the input redirection clause.
NDELAY mode is used so that the open will not wait for
carrier (DCD).
(2) Set clocal mode on the port so that further processing will
not require carrier (DCD).
port.
(3) Fork the stty command to establish initial modes for the
When all of the above processing is completed, port_hold
executes a pause(2) system call. Since it never terminates,
the ports opened by port_hold will never be closed.
Good things to include always in the stty line are: ixon,
ixoff, -ixany, and clocal. Other items are appropriate if
the device expects a 7-bit character size, parity checking,
and so on.
NOTE
Because port_hold traps all signals, it must finish all
of its processing by the time /etc/rc2.d/S80porthold
terminates to avoid "interrupted system call" errors.
For this reason, execution of port_hold is typically
followed by a sleep(1) of sufficient duration to assure
that port_hold enters the pause state before the sleep
expires. Note also that the file system (usually
/usr/tmp) which is to contain the log file must be
mounted before port_hold is started.
EXAMPLES
Page 2 May 1989
PORTHOLD(1M) (Line Printer Spooling Utilities) PORTHOLD(1M)
A sample /etc/rc2.d/S80porthold is listed below:
if [ -s /etc/psttys ]
then
/local/bin/port_hold </etc/psttys >/usr/tmp/port_hold.log 2>&1 &
sleep 5
fi
where /etc/psttys might look like this:
# list of ports and stty lines for port_hold
stty ixon ixoff -ixany clocal </dev/tty01
stty ixon ixoff -ixany clocal cs7 evenp parenb </dev/tty02
port_hold is started only if the sttyfile, in this case
/etc/psttys, exists and has a non-zero length. Since there
is no reasonable set of defaults, no sttyfile is provided
with the operating system; this file must be constructed as
needed.
Note that port_hold will start running as the system enters
run level 2. There is no special provision for stopping
port_hold at any other run level (nor is there any need to
do so).
FILES
stty_file is best kept in /etc. Since it is a text file, it
can be maintained with any available editor. It should be
owned by root and have permissions set to octal 444.
logfile is best kept in /usr/tmp. See DIAGNOSTICS, below,
for information on contents.
SEE ALSO
init(1M), termio(7).
stty(1) in the User's Reference Manual.
intro(2) in the Programmer's Reference Manual.
DIAGNOSTICS
Messages concerning various problems which may occur in
reading stty_file, opening ports, forking sttys, etc. appear
Page 3 May 1989
PORT_HOLD(1M) (Line Printer Spooling Utilities) PORT_HOLD(1M)
in logfile. Most messages are self-explanatory, but one
deserves further clarification. The message:
error 4 from fork or exec of stty_command
indicates that /etc/rc2.d/S80porthold terminated before
port_hold completed all of its processing (error code 4
indicates an "interrupted system call"). In such cases, the
sleep(1) period should be increased.
Page 4 May 1989