If you have a printer that is not supported by the standard printer interface program, you can furnish your own printer interface program. You can copy the standard program and then tell the LP print service to use it for a specified printer. First, you need to understand what is in the standard program. The following section describes the standard program.
A printer interface program should perform the following tasks:
Initialize the printer port, if necessary. The standard printer interface program uses the stty command to initialize the printer port.
Initialize the printer hardware. The standard printer interface program
receives the control sequences from the terminfo
database and
the TERM shell variable.
Print a banner page, if necessary.
Print the number of copies that are specified by the print request.
If you have a printer interface program from a release of UNIX System
V prior to release 3.2, it will probably work with the Solaris Express or compatible LP print service. However, several
o
options
have been standardized in the Solaris Express or
compatible LP print service. These options will be passed to every printer interface
program. These options might interfere with similarly named options used by the old
interface.
The LP print service, not a printer interface program, is responsible for opening the printer port. The printer port is given to the printer interface program as standard output. In addition, the printer is identified as the “controlling terminal” for the printer interface program so that a “hang-up” of the port causes a SIGHUP signal to be sent to the printer interface program.
The standard (model) printer interface program is /usr/lib/lp/model/standard
. This program is used by the LP print service to set the printing defaults
shown in the following table.
Table 6.5. Default Printer Port Characteristics
Characteristic |
Default Setting |
---|---|
Default filter |
|
Character pitch |
|
Line pitch |
|
Page width |
|
Page length |
|
Character set |
|
stty options |
|
|
If you need to change the terminal characteristics, such as baud rate or output options, find the section of the standard printer interface program that begins with the following comment:
## Initialize the printer port
For more information, see the Adjusting Printer Port Characteristics.
When printing is complete, your interface program should exit with a code that shows the status of the print job. The exit code is the last entry in the printer interface program.
The following table shows the exit codes and how they are interpreted by the LP print service.
Table 6.6. Printer Interface Program Exit Codes
Exit Code |
Meaning to the LP Print Service |
---|---|
|
The print request has been successfully completed. If a printer fault occurred, it has been cleared. |
|
A problem was encountered when printing a request. For example, there were too many nonprintable characters or the request exceeds the printer's capabilities. The LP print service notifies the person who submitted the request that an error occurred when printing it. This error does not affect future print requests. If a printer fault has occurred, it has been cleared. |
|
This code is reserved for use by the LP print service. Interface programs must not exit with this code. |
|
A printer fault was encountered when printing the request. This fault does affect future print requests. If the fault recovery for the printer directs the LP print service to wait for the administrator to correct the problem, the LP print service disables the printer. If the fault recovery is to continue printing, the LP print service does not disable the printer. However, the print service will try printing again in a few minutes. |
|
These codes are reserved for use by the LP print service. Interface programs must not exit with codes in this range. |
If the program exits with a code of 129, root
is alerted
of a printer fault. The LP print service must also reprint the request from the beginning,
after the fault has been cleared. If you do not want the entire request to be reprinted,
you can have the interface program send a fault message to the LP print service. (First
wait for the fault to be cleared.) When the fault is cleared, the interface program
can resume printing the file. When printing is finished, the printer interface program
can give a 0
exit code, just as if the fault had never occurred.
An added advantage of this approach: The interface program can detect when the fault
is cleared automatically. Thus, the administrator does not need to re-enable the printer.
You can use the lp.tell program to send fault messages to the LP print service. This program is referenced by the LPTELL shell variable in the standard printer interface code. The program takes standard input and sends it to the LP print service. The LP print service puts standard input into the message that alerts the administrator to the printer fault. If its standard input is empty, the lp.tell program does not initiate an alert. For an example of how the lp.tell program is used, examine the standard printer interface code immediately after the following comment:
# Set up the $LPTELL program to capture fault messages here
If you use the special exit code 129
or the lp.tell program, the printer interface program does not need to disable the printer
itself. The interface program can disable the printer directly. However, doing so
overrides the fault-alerting mechanism. Alerts are sent only if the LP print service
detects that the printer has a fault, and the special exit code and the lp.tell program are its main detection tools.
If the LP print service has to interrupt printing of a file at any time, it kills the interface program with a signal TERM (trap number 15). For more information, see the kill ( 1 ) and signal ( 3C ) man pages. If the printer interface program dies from receipt of any other signal, the LP print service assumes that future print requests will not be affected. As a result, the LP print service continues to use the printer. The LP print service notifies the user who submitted the request that the request has not been finished successfully.
When the interface is first invoked, the signals HUP, INT, QUIT, and PIPE (trap numbers 1, 2, 3, and 13) are ignored. The standard interface changes this default behavior, so that the signals are trapped at appropriate times. The standard interface interprets receipt of these signals as warnings that the printer has a problem. When the standard interface receives a signal, it issues a fault alert.
You can create a customized printer interface program and use it instead of the standard printer interface program on the print server. To do so, you use the lpadmin command to register the program with the LP print service for a specific printer.
How to Set Up a Custom Printer Interface Program
Log in as superuser, lp
, or
assume an equivalent role on the print server.
Copy the standard printer interface program.
#cp /var/spool/lp/model/standard
custom-interface
If you already have a custom printer interface program, go to Step 5
Change the copy of the standard printer interface program to meet your needs.
Refer to the description of the program in The Standard Printer Interface Program to determine what you need to change.
Set up the custom printer interface program for a specific printer.
#lpadmin -p
printer-name
-i
custom-interface
p
Specifies the printer that will use the custom printer interface program.
i
Is the name of the custom printer interface program.
The custom printer interface program is registered with the LP print service, and will be used by that printer when users submit print requests.
Verify that the custom printer interface program
has been added in the /etc/lp/printers/
printer-name
/configuration
file.