ptg10805159
822 Communicating with a Network Printer Chapter 21
284 /*
285 * Remove a job from the list of pending jobs.
286 *
287 * LOCKING: caller must hold joblock.
288 */
289 void
290 remove_job(struct job *target)
291 {
292 if (target->next != NULL)
293 target->next->prev=target->prev;
294 else
295 jobtail=target->prev;
296 if (target->prev != NULL)
297 target->prev->next=target->next;
298 else
299 jobhead=target->next;
300 }
301 /*
302 * Check the spool directory for pending jobs on start-up.
303 *
304 * LOCKING: none.
305 */
306 void
307 build_qonstart(void)
308 {
309 int fd, err, nr;
310 int32_t jobid;
311 DIR *dirp;
312 struct dirent *entp;
313 struct printreq req;
314 char dname[FILENMSZ], fname[FILENMSZ];
315 sprintf(dname, "%s/%s", SPOOLDIR, REQDIR);
316 if ((dirp = opendir(dname)) == NULL)
317 return;
[284 – 300] remove_jobremoves a job from the list of pending jobs given a pointer to
the job to be removed. The caller must already hold thejoblockmutex. If
the next pointer is non-null, we set the next entry’s previous pointer to the
target’s previous pointer.Otherwise, the entry is the last one on the list, so
we setjobtailto the target’s previous pointer.Ifthe target’s previous
pointer is non-null, we set the previous entry’s next pointer equal to the
target’s next pointer.Otherwise, this is the first entry in the list, so we set
jobheadto point to the next entry in the list after the target.
[301 – 317] When the daemon starts, it callsbuild_qonstartto build an in-memory
list of print jobs from the disk files stored in/var/spool/printer/reqs.
If we can’t open the directory, no print jobs arepending, so we return.