User`s guide
4-28
Guide to Printers and Printing
Understanding the Interaction between qdaemon and the
Backend
Besides reading files and writing to devices, a backend must cooperate with the qdaemon
in several ways:
• Print extra pages as requested.
• Periodically update status information (such as pages printed, percentage done, and
waiting state).
• Supply charges (accounting data) for the completed job.
• Exit with some agreed–on codes.
• Pass error messages through a special routine.
• Set queue states as appropriate.
• Terminate cleanly on receipt of SIGTERM.
The qdaemon and the backend communicate through a status file. ”Understanding
Backend Routines in libqb”, on page 4-33 explains the set of library routines that the
backend should use to fulfill these communication requirements. These routines are in the
/usr/lib/libqb.a library.
Using the Status File
When the qdaemon process invokes a backend, it passes the following parameters, in
order:
1. The parameters appearing in the /etc/qconfig file.
2. The flags that the enq command did not recognize, in the order they were given. These
flags will be preceded by the –o option on the command line.
3. The names of one or more files to be printed.
There is a status file for each device and its associated queue. These files are found in the
/var/spool/lpd/stat directory.
The status file provides a means of communication for the qdaemon process and the
backend. The qdaemon passes information such as the date of the file, whether to print
burst pages, and the number of copies to be printed. The backend passes back the charge
for the job it has just finished running. In addition, the backend periodically updates the
number of pages it has printed and what percent of the job is finished. This information is
read by the qchk command.
Note: Backends should never explicitly write into their status file. They should call the
libqb library routines to do this.
There are two reasons for calling the routines:
• The backend is spared the trouble of accessing the status file directly.
• The format of the status file can be changed without requiring backends to be rewritten.
Should the format of the status file change, the backend only needs to be re–linked.
To initialize certain data common to the library routines, the backend must call the routine
log_init. The call is:
log_init();
This routine should be called to initialize the status file interface. The log_init routine, like all
log_ routines in the library, returns a value of –1 if it fails.