System Administration Guide: Advanced Administration

Customizing the Printer Interface Program

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. But first you need to understand what is in the standard program. The following section describes the standard program.

A printer interface program should:


Caution – Caution –

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 SunOS 5.9 or compatible LP print service. However, several -o options have been standardized in the SunOS 5.9 or compatible LP print service and 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, and the printer is identified as the “controlling terminal” for the printer interface program so that a “hang-up” of the port will cause a SIGHUP signal to be sent to the printer interface program.

The Standard Printer Interface Program

The standard (model) printer interface program, /usr/lib/lp/model/standard, is used by the LP print service to set the printing defaults shown in Table 7–3.

Table 7–3 Default Printer Port Characteristics

Characteristic 

Default Setting 

Default filter 

None

Character pitch 

None

Line pitch 

None

Page width 

None

Page length 

None

Character set 

None

stty options

9600 cs8 -cstopb -parenb -parodd ixon -ixany opost -olcuc onlcr -ocrnl -onocr -onlret -ofill nl0 cr0 tab0 bs0 vt0 ff0

Exit code

0

Customizing stty Modes

If you need to change the terminal characteristics, like baud rate or output options, look for the section of the standard printer interface program that begins with the following comment:

## Initialize the printer port

Exit Codes

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 7–4 Printer Interface Program Exit Codes

Code 

Meaning to the LP Print Service 

0

The print request has been successfully completed. If a printer fault occurred, it has been cleared. 

1 to 127

A problem was encountered when printing a request (for example, too many nonprintable characters or the request exceeds the printer capabilities). The LP print service notifies the person who submitted the request that there was an error when printing it. This error will not affect future print requests. If a printer fault has occurred, it has been cleared. 

128

This code is reserved for internal use by the LP print service. Interface programs must not exit with this code. 

129

A printer fault was encountered when printing the request. This fault will 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 will not disable the printer, but it will try printing again in a few minutes. 

>129

These codes are reserved for internal 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, but 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 zero exit code, just as if the fault had never occurred. An added advantage of this approach is that the interface program can detect when the fault is cleared automatically, so that the administrator does not need to re-enable the printer.

Fault Messages

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, where it is put into the message that alerts the administrator to the printer fault. If its standard input is empty, lp.tell 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, but doing so will override 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 kill(1) and signal(3C).) 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, and 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 so the signals are trapped at appropriate times. The standard interface interprets receipt of these signals as warnings that the printer has a problem; when it receives a signal, it issues a fault alert.

Using a Customized Printer Interface Program

You can create a customized printer interface program and use it in place 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

  1. Log in as superuser, lp, or assume an equivalent role on the print server.

  2. Determine your next step based on whether you have a custom printer interface program.

    Custom Printer Interface Status 

    Action 

    Need to create a custom printer interface program 

    Go to Step 3.

    Already have a custom printer interface program 

    Go to Step 5.

  3. Copy the standard printer interface program.


    # cp /var/spool/lp/model/standard custom-interface
    
  4. 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.

  5. Set up the custom printer interface program for a specific printer.


    # lpadmin -p printer-name -i custom-interface
    

    -p printer-name

    The printer that will use the custom printer interface program. 

    -i custom-interface

    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.

  6. Verify that the custom printer interface program has been added in the /etc/lp/printers/printer-name/configuration file.

Examples—Setting Up a Custom Printer Interface Program

The following example shows how to set up a custom printer interface program named custom for the printer luna.


# lpadmin -p luna -i custom

The following example shows how to set up a custom printer interface program that the system venus is using on the printer asteroid.


# lpadmin -p asteroid -e venus