tsol_standard revision f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# CDDL HEADER START
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# The contents of this file are subject to the terms of the
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Common Development and Distribution License (the "License").
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# You may not use this file except in compliance with the License.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# See the License for the specific language governing permissions
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# and limitations under the License.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# When distributing Covered Code, include this CDDL HEADER in each
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# If applicable, add the following below this CDDL HEADER, with the
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# fields enclosed by brackets "[]" replaced with your own identifying
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# information: Portions Copyright [yyyy] [name of copyright owner]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# CDDL HEADER END
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Use is subject to license terms.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews#pragma ident "%Z%%M% %I% %E% SMI"
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews## Standard printer interface program.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Until we get to the point below where the printer port
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# and physical printer are initialized, we can't do much
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# except exit if the Spooler/Scheduler cancels us.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewstrap 'exit' 15
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# We can be clever about getting a hangup or interrupt, though, at least
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# until the filter runs. Do this early, even though $LPTELL
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# isn't defined, so that we're covered.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewscatch_hangup () {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews if [ -n "${LPTELL}" ]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews"The connection to the printer dropped; perhaps the printer went off-line?" \
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews | ${LPTELL} ${printer}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewscatch_interrupt () {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews if [ -n "${LPTELL}" ]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews"Received an interrupt from the printer. The reason is unknown,
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsalthough a common cause is that the baud rate is too high." \
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews | ${LPTELL} ${printer}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewstrap 'catch_hangup; exit_code=129 exit 129' 1
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewstrap 'catch_interrupt; exit_code=129 exit 129' 2 3
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Most of the time we don't want the standard error to be captured
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# by the Spooler, mainly to avoid "Terminated" messages that the
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# shell puts out when we get a SIGTERM. We'll save the standard
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# error channel under another number, so we can use it when it
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# should be captured.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Open another channel to the printer port, for use when the
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# regular standard output won't be directed there, such as in
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# command substitution (`cmd`).
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsexec 5>&2 2>/dev/null 3>&1
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Set some globally used variables and functions.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews: ${TMPDIR:=/tmp}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews: ${LOCALPATH:=${SPOOLDIR}/bin}
db725ebe2b5d913949246b02573df01bd29f5412Mark AndrewsPATH="/bin:/usr/bin:${LOCALPATH}"
db725ebe2b5d913949246b02573df01bd29f5412Mark AndrewsMAX_COLS_SMALL_BANNER=40
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# On the 3.2 release of the 386unix product, the parallel port does
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# not support any ioctl calls. As a result, we cannot set the opost
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# and onlcr attributes to have <NL>'s expanded to <CR><NL>. This
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# "filter" gets the job done for us.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews: ${FIX386BD:=${LOCALPATH}/386parallel}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsif [ -n "${FIX386BD}" -a -x "${FIX386BD}" ]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews FIX386BD="| ${FIX386BD}"
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Use ${TMPPREFIX} as the prefix for all temporary files, so
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# that cleanup is easy. The prefix may be up to 13 characters
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# long, so you only have space for one more character to make
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# a file name. If necessary, make a directory using this prefix
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# for better management of unique temporary file names.
db725ebe2b5d913949246b02573df01bd29f5412Mark AndrewsTMPPREFIX=${TMPDIR}/`uname -n`$$
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Before exiting, set ${exit_code} to the value with which to exit.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# Otherwise, the exit from this script will be 0.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewstrap 'rm -fr ${TMPPREFIX}*; exit ${exit_code}' 0
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# ${LPTELL} is the name of a program that will send its
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# standard input to the Spooler. It is used to forward
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# the description of a printer fault to the Spooler,
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# which uses it in an alert to the administrator.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsif [ ! -x "${LPTELL:=${LOCALPATH}/lp.tell}" ]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews fake_lptell () {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews while read line
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews if [ "no" = "${header}" ]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews errmsg ERROR ${E_IP_UNKNOWN} \
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews "unknown printer/interface failure" \
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews "consult your system administrator;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews reasons for failure (if any) follow:"
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews echo "${line}" >&2
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews LPTELL=fake_lptell
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# ${DRAIN} is the name of a program that will wait
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# long enough for data sent to the printer to print.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsif [ -x "${LOCALPATH}/drain.output" ]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews DRAIN="${LOCALPATH}/drain.output 5" # wait only five seconds
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# ${LPTSOLSEPARATOR} is the name of a program to put banner and trailer
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# pages around the job.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsif [ -x ${LOCALPATH}/lp.tsol_separator ]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews LPTSOLSEPARATOR=${LOCALPATH}/lp.tsol_separator
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews echo "${LOCALPATH}/lp.tsol_separator not found." >&2
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# ${LPCAT} is the name of a program to use as a default
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# filter. Minimally it should copy its standard input to
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# the standard output, but it should also trap printer
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# faults. The current LPCAT traps hangups (DCD dropping, SIGHUP),
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# interrupts (SIGINT, SIGQUIT), broken pipe (SIGPIPE), and
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# excess delays in sending data to the printer, interpreting all
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# as printer faults.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsif [ ! -x "${LPCAT:=${LOCALPATH}/lp.cat}" ]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# ${LPSET} is the name of a program that will set the
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# character pitch, line pitch, page width, page length,
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# and character set. It helps to have this in a single
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# binary program so that (1) it's faster than calls
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# to "tput"; and (2) it can access the new Terminfo
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews# capabilities for printers (on pre SVR3.2 machines, tput can't).
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsif [ ! -x "${LPSET:=${LOCALPATH}/lp.set}" ]
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews fake_lpset () {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews echo H V W L S >&2
# you'll see "2>/dev/null" being used to avoid ugly error messages.
E_IP_ERRORS=12 # (in slow.filter)
# If you want to add simple options (e.g. -o simple)
# If you want to add simple-value options (e.g. -o value=a)
# take a list (e.g. -o lopt='a b c'), identify
tput lines 1>/dev/null 2>&1 || TPUT=:
FILTER="/usr/lib/lp/postscript/postio"
FILTER="/usr/lib/lp/postscript/postreverse | \
if [ `basename "${LPCAT}"` = "lp.cat" ] ; then
# FILTER="${LPCAT} 120" # e.g. 120 CPS
# FILTER="${LPCAT} -r 0 2>/tmp/delays"
tty 0<&1 1>/dev/null 2>&1 && {
0<&1 2>/dev/null 1>&2
0<&1 2>/dev/null 1>&2
if stty ${stty} 0<&1 1>/dev/null 2>&5
# carriage-return/linefeed pair. An example of the latter is the
expr "${cur_stty}" : '.*-opost' 1>/dev/null 2>&1 \
expr "${cur_stty}" : '.*-clocal' 1>/dev/null 2>&1 \
expr "${cur_stty}" : '.* opost.*' 1>/dev/null 2>&1 \
# "tput init" will return an "^M" in many cases to "stdout", i.e., printer!
elif ${TPUT} init 2>/dev/null
stty tab3 0<&1 1>/dev/null 2>&1
elif `${TPUT} ht >/dev/null`
tabset="/usr/lib/tabset/${TERM}"
stty tab3 0<&1 1>/dev/null 2>&1
${TPUT} scs 0 2>/dev/null
BANNER_EXIT_CODE=${TMPPREFIX}.banner.exit_code
TSOLSEPARATOR_LOG=${TMPPREFIX}.banner.errmsg
# if lp.tsol_separator had an error, send its logged
# Skip this for TSOL, since lp.tsol_separator handles the banners