2 * "$Id: job.c 6318 2007-03-06 04:36:55Z mike $"
4 * Job management routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdAddJob() - Add a new job to the job queue...
27 * cupsdCancelJob() - Cancel the specified print job.
28 * cupsdCancelJobs() - Cancel all jobs for the given
30 * cupsdCheckJobs() - Check the pending jobs and start any if
31 * the destination is available.
32 * cupsdCleanJobs() - Clean out old jobs.
33 * cupsdFinishJob() - Finish a job.
34 * cupsdFreeAllJobs() - Free all jobs from memory.
35 * cupsdFindJob() - Find the specified job.
36 * cupsdGetPrinterJobCount() - Get the number of pending, processing,
37 * cupsdGetUserJobCount() - Get the number of pending, processing,
38 * cupsdHoldJob() - Hold the specified job.
39 * cupsdLoadAllJobs() - Load all jobs from disk.
40 * cupsdLoadJob() - Load a single job...
41 * cupsdMoveJob() - Move the specified job to a different
43 * cupsdReleaseJob() - Release the specified job.
44 * cupsdRestartJob() - Restart the specified job.
45 * cupsdSaveAllJobs() - Save a summary of all jobs to disk.
46 * cupsdSaveJob() - Save a job to disk.
47 * cupsdSetJobHoldUntil() - Set the hold time for a job...
48 * cupsdSetJobPriority() - Set the priority of a job, moving it
49 * up/down in the list as needed.
50 * cupsdStopAllJobs() - Stop all print jobs.
51 * cupsdStopJob() - Stop a print job.
52 * cupsdUnloadCompletedJobs() - Flush completed job history from memory.
53 * cupsdUpdateJob() - Read a status update from a jobs filters.
54 * compare_active_jobs() - Compare the job IDs and priorities of two
56 * compare_jobs() - Compare the job IDs of two jobs.
57 * free_job() - Free all memory used by a job.
58 * ipp_length() - Compute the size of the buffer needed to
59 * hold the textual IPP attributes.
60 * load_job_cache() - Load jobs from the job.cache file.
61 * load_next_job_id() - Load the NextJobId value from the
63 * load_request_root() - Load jobs from the RequestRoot directory.
64 * set_time() - Set one of the "time-at-xyz" attributes...
65 * set_hold_until() - Set the hold time and update job-hold-until
67 * start_job() - Start a print job.
68 * unload_job() - Unload a job from memory.
72 * Include necessary headers...
77 #include <cups/backend.h>
85 static mime_filter_t gziptoany_filter
=
87 NULL
, /* Source type */
88 NULL
, /* Destination type */
90 "gziptoany" /* Filter program to run */
98 static int compare_active_jobs(void *first
, void *second
, void *data
);
99 static int compare_jobs(void *first
, void *second
, void *data
);
100 static void free_job(cupsd_job_t
*job
);
101 static int ipp_length(ipp_t
*ipp
);
102 static void load_job_cache(const char *filename
);
103 static void load_next_job_id(const char *filename
);
104 static void load_request_root(void);
105 static void set_time(cupsd_job_t
*job
, const char *name
);
106 static void set_hold_until(cupsd_job_t
*job
, time_t holdtime
);
107 static void start_job(cupsd_job_t
*job
, cupsd_printer_t
*printer
);
108 static void unload_job(cupsd_job_t
*job
);
112 * 'cupsdAddJob()' - Add a new job to the job queue...
115 cupsd_job_t
* /* O - New job record */
116 cupsdAddJob(int priority
, /* I - Job priority */
117 const char *dest
) /* I - Job destination */
119 cupsd_job_t
*job
; /* New job record */
122 job
= calloc(sizeof(cupsd_job_t
), 1);
124 job
->id
= NextJobId
++;
125 job
->priority
= priority
;
126 job
->back_pipes
[0] = -1;
127 job
->back_pipes
[1] = -1;
128 job
->print_pipes
[0] = -1;
129 job
->print_pipes
[1] = -1;
130 job
->side_pipes
[0] = -1;
131 job
->side_pipes
[1] = -1;
132 job
->status_pipes
[0] = -1;
133 job
->status_pipes
[1] = -1;
135 cupsdSetString(&job
->dest
, dest
);
138 * Add the new job to the "all jobs" and "active jobs" lists...
141 cupsArrayAdd(Jobs
, job
);
142 cupsArrayAdd(ActiveJobs
, job
);
149 * 'cupsdCancelJob()' - Cancel the specified print job.
153 cupsdCancelJob(cupsd_job_t
*job
, /* I - Job to cancel */
154 int purge
, /* I - Purge jobs? */
155 ipp_jstate_t newstate
) /* I - New job state */
157 int i
; /* Looping var */
158 char filename
[1024]; /* Job filename */
159 cupsd_printer_t
*printer
; /* Printer used by job */
162 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCancelJob: id = %d", job
->id
);
165 * Stop any processes that are working on the current job...
168 printer
= job
->printer
;
170 if (job
->state_value
== IPP_JOB_PROCESSING
)
171 cupsdStopJob(job
, 0);
176 job
->state
->values
[0].integer
= newstate
;
178 job
->state_value
= newstate
;
180 set_time(job
, "time-at-completed");
183 * Send any pending notifications and then expire them...
191 case IPP_JOB_CANCELED
:
192 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, printer
, job
,
193 purge
? "Job purged." : "Job canceled.");
196 case IPP_JOB_ABORTED
:
197 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, printer
, job
,
198 "Job aborted; please consult the error_log file "
202 case IPP_JOB_COMPLETED
:
204 * Clear the printer's state_message and state_reasons and move on...
207 printer
->state_message
[0] = '\0';
209 cupsdSetPrinterReasons(printer
, "");
210 cupsdSetPrinterState(printer
, IPP_PRINTER_IDLE
, 0);
212 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, printer
, job
,
217 cupsdExpireSubscriptions(NULL
, job
);
220 * Remove the job from the active list...
223 cupsArrayRemove(ActiveJobs
, job
);
226 * Remove any authentication data...
229 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
233 * Remove the print file for good if we aren't preserving jobs or
237 job
->current_file
= 0;
239 if (!JobHistory
|| !JobFiles
|| purge
|| (job
->dtype
& CUPS_PRINTER_REMOTE
))
241 for (i
= 1; i
<= job
->num_files
; i
++)
243 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
,
248 if (job
->num_files
> 0)
250 free(job
->filetypes
);
251 free(job
->compressions
);
254 job
->filetypes
= NULL
;
255 job
->compressions
= NULL
;
259 if (JobHistory
&& !purge
&& !(job
->dtype
& CUPS_PRINTER_REMOTE
))
262 * Save job state info...
270 * Remove the job info file...
273 snprintf(filename
, sizeof(filename
), "%s/c%05d", RequestRoot
,
278 * Remove the job from the "all jobs" list...
281 cupsArrayRemove(Jobs
, job
);
284 * Free all memory used...
293 * 'cupsdCancelJobs()' - Cancel all jobs for the given destination/user...
297 cupsdCancelJobs(const char *dest
, /* I - Destination to cancel */
298 const char *username
, /* I - Username or NULL */
299 int purge
) /* I - Purge jobs? */
301 cupsd_job_t
*job
; /* Current job */
304 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
306 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
307 if ((dest
== NULL
|| !strcmp(job
->dest
, dest
)) &&
308 (username
== NULL
|| !strcmp(job
->username
, username
)))
311 * Cancel all jobs matching this destination/user...
314 cupsdCancelJob(job
, purge
, IPP_JOB_CANCELED
);
322 * 'cupsdCheckJobs()' - Check the pending jobs and start any if the destination
329 cupsd_job_t
*job
; /* Current job in queue */
330 cupsd_printer_t
*printer
, /* Printer destination */
331 *pclass
; /* Printer class destination */
334 DEBUG_puts("cupsdCheckJobs()");
336 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
337 "cupsdCheckJobs: %d active jobs, sleeping=%d, reload=%d",
338 cupsArrayCount(ActiveJobs
), Sleeping
, NeedReload
);
340 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
342 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
345 * Start held jobs if they are ready...
348 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
349 "cupsdCheckJobs: Job %d: state_value=%d, loaded=%s",
350 job
->id
, job
->state_value
, job
->attrs
? "yes" : "no");
352 if (job
->state_value
== IPP_JOB_HELD
&&
354 job
->hold_until
< time(NULL
))
356 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
357 job
->state_value
= IPP_JOB_PENDING
;
361 * Start pending jobs if the destination is available...
364 if (job
->state_value
== IPP_JOB_PENDING
&& !NeedReload
&& !Sleeping
)
366 printer
= cupsdFindDest(job
->dest
);
370 (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)))
373 * If the class is remote, just pass it to the remote server...
378 if (!(pclass
->type
& CUPS_PRINTER_REMOTE
) &&
379 pclass
->state
!= IPP_PRINTER_STOPPED
)
380 printer
= cupsdFindAvailablePrinter(job
->dest
);
385 if (!printer
&& !pclass
)
388 * Whoa, the printer and/or class for this destination went away;
392 cupsdLogMessage(CUPSD_LOG_WARN
,
393 "Printer/class %s has gone away; canceling job %d!",
396 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
397 "Job canceled because the destination printer/class has "
400 cupsdCancelJob(job
, 1, IPP_JOB_ABORTED
);
405 * See if the printer is available or remote and not printing a job;
406 * if so, start the job...
412 * Add/update a job-actual-printer-uri attribute for this job
413 * so that we know which printer actually printed the job...
416 ipp_attribute_t
*attr
; /* job-actual-printer-uri attribute */
419 if ((attr
= ippFindAttribute(job
->attrs
, "job-actual-printer-uri",
420 IPP_TAG_URI
)) != NULL
)
421 cupsdSetString(&attr
->values
[0].string
.text
, printer
->uri
);
423 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
,
424 "job-actual-printer-uri", NULL
, printer
->uri
);
427 if ((!(printer
->type
& CUPS_PRINTER_REMOTE
) && /* Printer is local */
428 printer
->state
== IPP_PRINTER_IDLE
) || /* and idle */
429 ((printer
->type
& CUPS_PRINTER_REMOTE
) && /* Printer is remote */
430 !printer
->job
)) /* and not printing */
431 start_job(job
, printer
);
439 * 'cupsdCleanJobs()' - Clean out old jobs.
445 cupsd_job_t
*job
; /* Current job */
451 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
452 job
&& cupsArrayCount(Jobs
) >= MaxJobs
;
453 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
454 if (job
->state_value
>= IPP_JOB_CANCELED
)
455 cupsdCancelJob(job
, 1, IPP_JOB_CANCELED
);
460 * 'cupsdFinishJob()' - Finish a job.
464 cupsdFinishJob(cupsd_job_t
*job
) /* I - Job */
466 cupsd_printer_t
*printer
; /* Current printer */
469 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job %d] File %d is complete.",
470 job
->id
, job
->current_file
- 1);
472 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFinishJob: job->status is %d",
475 if (job
->status_buffer
&&
476 (job
->status
< 0 || job
->current_file
>= job
->num_files
))
479 * Close the pipe and clear the input bit.
482 cupsdRemoveSelect(job
->status_buffer
->fd
);
484 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
485 "cupsdFinishJob: Closing status pipes [ %d %d ]...",
486 job
->status_pipes
[0], job
->status_pipes
[1]);
488 cupsdClosePipe(job
->status_pipes
);
489 cupsdStatBufDelete(job
->status_buffer
);
491 job
->status_buffer
= NULL
;
494 printer
= job
->printer
;
499 * Backend had errors; stop it...
502 int exit_code
; /* Exit code from backend */
506 * Convert the status to an exit code. Due to the way the W* macros are
507 * implemented on MacOS X (bug?), we have to store the exit status in a
508 * variable first and then convert...
511 exit_code
= -job
->status
;
512 if (WIFEXITED(exit_code
))
513 exit_code
= WEXITSTATUS(exit_code
);
515 exit_code
= job
->status
;
517 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Backend returned status %d (%s)",
519 exit_code
== CUPS_BACKEND_FAILED
? "failed" :
520 exit_code
== CUPS_BACKEND_AUTH_REQUIRED
?
521 "authentication required" :
522 exit_code
== CUPS_BACKEND_HOLD
? "hold job" :
523 exit_code
== CUPS_BACKEND_STOP
? "stop printer" :
524 exit_code
== CUPS_BACKEND_CANCEL
? "cancel job" :
525 exit_code
< 0 ? "crashed" : "unknown");
528 * Do what needs to be done...
534 case CUPS_BACKEND_FAILED
:
536 * Backend failure, use the error-policy to determine how to
540 cupsdStopJob(job
, 0);
542 if (job
->dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
545 * Mark the job as pending again - we'll retry on another
549 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
550 job
->state_value
= IPP_JOB_PENDING
;
556 * If the job was queued to a class, try requeuing it... For
557 * faxes and retry-job queues, hold the current job for 5 minutes.
560 if (job
->dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
562 else if ((printer
->type
& CUPS_PRINTER_FAX
) ||
563 !strcmp(printer
->error_policy
, "retry-job"))
566 * See how many times we've tried to send the job; if more than
567 * the limit, cancel the job.
572 if (job
->tries
>= JobRetryLimit
)
578 cupsdLogMessage(CUPSD_LOG_ERROR
,
579 "Canceling job %d since it could not be sent "
581 job
->id
, JobRetryLimit
);
583 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
588 * Try again in N seconds...
591 set_hold_until(job
, time(NULL
) + JobRetryInterval
);
593 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
594 "Job held due to fax errors; please consult "
595 "the error_log file for details.");
596 cupsdSetPrinterState(printer
, IPP_PRINTER_IDLE
, 0);
599 else if (!strcmp(printer
->error_policy
, "abort-job"))
600 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
603 cupsdSetPrinterState(printer
, IPP_PRINTER_STOPPED
, 1);
605 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, printer
, job
,
606 "Job stopped due to backend errors; please consult "
607 "the error_log file for details.");
611 case CUPS_BACKEND_CANCEL
:
616 cupsdCancelJob(job
, 0, IPP_JOB_CANCELED
);
619 case CUPS_BACKEND_HOLD
:
624 cupsdStopJob(job
, 0);
626 cupsdSetJobHoldUntil(job
, "indefinite");
628 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
629 job
->state_value
= IPP_JOB_HELD
;
633 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, printer
, job
,
634 "Job held due to backend errors; please consult "
635 "the error_log file for details.");
638 case CUPS_BACKEND_STOP
:
640 * Stop the printer...
643 cupsdStopJob(job
, 0);
645 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
646 job
->state_value
= IPP_JOB_PENDING
;
649 cupsdSetPrinterState(printer
, IPP_PRINTER_STOPPED
, 1);
651 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, printer
, job
,
652 "Job stopped due to backend errors; please consult "
653 "the error_log file for details.");
656 case CUPS_BACKEND_AUTH_REQUIRED
:
657 cupsdStopJob(job
, 0);
659 cupsdSetJobHoldUntil(job
, "authenticated");
661 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
662 job
->state_value
= IPP_JOB_HELD
;
666 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, printer
, job
,
667 "Authentication is required for job %d.", job
->id
);
672 * Try printing another job...
677 else if (job
->status
> 0)
680 * Filter had errors; stop job...
683 cupsdStopJob(job
, 1);
685 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, printer
, job
,
686 "Job stopped due to filter errors; please consult the "
687 "error_log file for details.");
693 * Job printed successfully; cancel it...
696 if (job
->current_file
< job
->num_files
)
699 * Start the next file in the job...
702 FilterLevel
-= job
->cost
;
703 start_job(job
, printer
);
708 * Close out this job...
711 cupsdCancelJob(job
, 0, IPP_JOB_COMPLETED
);
719 * 'cupsdFreeAllJobs()' - Free all jobs from memory.
723 cupsdFreeAllJobs(void)
725 cupsd_job_t
*job
; /* Current job */
736 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
738 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
740 cupsArrayRemove(Jobs
, job
);
741 cupsArrayRemove(ActiveJobs
, job
);
746 cupsdReleaseSignals();
751 * 'cupsdFindJob()' - Find the specified job.
754 cupsd_job_t
* /* O - Job data */
755 cupsdFindJob(int id
) /* I - Job ID */
757 cupsd_job_t key
; /* Search key */
762 return ((cupsd_job_t
*)cupsArrayFind(Jobs
, &key
));
767 * 'cupsdGetPrinterJobCount()' - Get the number of pending, processing,
768 * or held jobs in a printer or class.
771 int /* O - Job count */
772 cupsdGetPrinterJobCount(
773 const char *dest
) /* I - Printer or class name */
775 int count
; /* Job count */
776 cupsd_job_t
*job
; /* Current job */
779 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
), count
= 0;
781 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
782 if (job
->dest
&& !strcasecmp(job
->dest
, dest
))
790 * 'cupsdGetUserJobCount()' - Get the number of pending, processing,
791 * or held jobs for a user.
794 int /* O - Job count */
795 cupsdGetUserJobCount(
796 const char *username
) /* I - Username */
798 int count
; /* Job count */
799 cupsd_job_t
*job
; /* Current job */
802 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
), count
= 0;
804 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
805 if (!strcasecmp(job
->username
, username
))
813 * 'cupsdHoldJob()' - Hold the specified job.
817 cupsdHoldJob(cupsd_job_t
*job
) /* I - Job data */
819 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdHoldJob: id = %d", job
->id
);
821 if (job
->state_value
== IPP_JOB_PROCESSING
)
822 cupsdStopJob(job
, 0);
826 DEBUG_puts("cupsdHoldJob: setting state to held...");
828 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
829 job
->state_value
= IPP_JOB_HELD
;
838 * 'cupsdLoadAllJobs()' - Load all jobs from disk.
842 cupsdLoadAllJobs(void)
844 char filename
[1024]; /* Full filename of job.cache file */
845 struct stat fileinfo
, /* Information on job.cache file */
846 dirinfo
; /* Information on RequestRoot dir */
851 * Create the job arrays as needed...
855 Jobs
= cupsArrayNew(compare_jobs
, NULL
);
858 ActiveJobs
= cupsArrayNew(compare_active_jobs
, NULL
);
861 * See whether the job.cache file is older than the RequestRoot directory...
864 snprintf(filename
, sizeof(filename
), "%s/job.cache", CacheDir
);
866 if (stat(filename
, &fileinfo
))
868 fileinfo
.st_mtime
= 0;
871 cupsdLogMessage(CUPSD_LOG_ERROR
,
872 "Unable to get file information for \"%s\" - %s",
873 filename
, strerror(errno
));
876 if (stat(RequestRoot
, &dirinfo
))
878 dirinfo
.st_mtime
= 0;
881 cupsdLogMessage(CUPSD_LOG_ERROR
,
882 "Unable to get directory information for \"%s\" - %s",
883 RequestRoot
, strerror(errno
));
887 * Load the most recent source for job data...
890 if (dirinfo
.st_mtime
> fileinfo
.st_mtime
)
894 load_next_job_id(filename
);
897 load_job_cache(filename
);
900 * Clean out old jobs as needed...
903 if (MaxJobs
> 0 && cupsArrayCount(Jobs
) >= MaxJobs
)
909 * 'cupsdLoadJob()' - Load a single job...
913 cupsdLoadJob(cupsd_job_t
*job
) /* I - Job */
915 char jobfile
[1024]; /* Job filename */
916 cups_file_t
*fp
; /* Job file */
917 int fileid
; /* Current file ID */
918 ipp_attribute_t
*attr
; /* Job attribute */
919 const char *dest
; /* Destination */
920 mime_type_t
**filetypes
; /* New filetypes array */
921 int *compressions
; /* New compressions array */
926 if (job
->state_value
> IPP_JOB_STOPPED
)
927 job
->access_time
= time(NULL
);
932 if ((job
->attrs
= ippNew()) == NULL
)
934 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ran out of memory for job attributes!");
939 * Load job attributes...
942 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading attributes for job %d...",
945 snprintf(jobfile
, sizeof(jobfile
), "%s/c%05d", RequestRoot
, job
->id
);
946 if ((fp
= cupsFileOpen(jobfile
, "r")) == NULL
)
948 cupsdLogMessage(CUPSD_LOG_ERROR
,
949 "Unable to open job control file \"%s\" - %s!",
950 jobfile
, strerror(errno
));
951 ippDelete(job
->attrs
);
956 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
, job
->attrs
) != IPP_DATA
)
958 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read job control file \"%s\"!",
961 ippDelete(job
->attrs
);
970 * Copy attribute data to the job object...
973 if ((job
->state
= ippFindAttribute(job
->attrs
, "job-state",
974 IPP_TAG_ENUM
)) == NULL
)
976 cupsdLogMessage(CUPSD_LOG_ERROR
,
977 "Missing or bad job-state attribute in control "
980 ippDelete(job
->attrs
);
986 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
990 if ((attr
= ippFindAttribute(job
->attrs
, "job-printer-uri",
991 IPP_TAG_URI
)) == NULL
)
993 cupsdLogMessage(CUPSD_LOG_ERROR
,
994 "No job-printer-uri attribute in control file \"%s\"!",
996 ippDelete(job
->attrs
);
1002 if ((dest
= cupsdValidateDest(attr
->values
[0].string
.text
, &(job
->dtype
),
1005 cupsdLogMessage(CUPSD_LOG_ERROR
,
1006 "Unable to queue job for destination \"%s\"!",
1007 attr
->values
[0].string
.text
);
1008 ippDelete(job
->attrs
);
1014 cupsdSetString(&job
->dest
, dest
);
1017 job
->sheets
= ippFindAttribute(job
->attrs
, "job-media-sheets-completed",
1019 job
->job_sheets
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
1023 if ((attr
= ippFindAttribute(job
->attrs
, "job-priority",
1024 IPP_TAG_INTEGER
)) == NULL
)
1026 cupsdLogMessage(CUPSD_LOG_ERROR
,
1027 "Missing or bad job-priority attribute in control "
1028 "file \"%s\"!", jobfile
);
1029 ippDelete(job
->attrs
);
1035 job
->priority
= attr
->values
[0].integer
;
1040 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-user-name",
1041 IPP_TAG_NAME
)) == NULL
)
1043 cupsdLogMessage(CUPSD_LOG_ERROR
,
1044 "Missing or bad job-originating-user-name attribute "
1045 "in control file \"%s\"!", jobfile
);
1046 ippDelete(job
->attrs
);
1052 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1056 * Set the job hold-until time and state...
1059 if (job
->state_value
== IPP_JOB_HELD
)
1061 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1062 IPP_TAG_KEYWORD
)) == NULL
)
1063 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1066 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1069 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1070 job
->state_value
= IPP_JOB_PENDING
;
1073 else if (job
->state_value
== IPP_JOB_PROCESSING
)
1075 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1076 job
->state_value
= IPP_JOB_PENDING
;
1079 if (!job
->num_files
)
1082 * Find all the d##### files...
1085 for (fileid
= 1; fileid
< 10000; fileid
++)
1087 snprintf(jobfile
, sizeof(jobfile
), "%s/d%05d-%03d", RequestRoot
,
1090 if (access(jobfile
, 0))
1093 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Auto-typing document file \"%s\"...",
1096 if (fileid
> job
->num_files
)
1098 if (job
->num_files
== 0)
1100 compressions
= (int *)calloc(fileid
, sizeof(int));
1101 filetypes
= (mime_type_t
**)calloc(fileid
, sizeof(mime_type_t
*));
1105 compressions
= (int *)realloc(job
->compressions
,
1106 sizeof(int) * fileid
);
1107 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1108 sizeof(mime_type_t
*) *
1112 if (!compressions
|| !filetypes
)
1114 cupsdLogMessage(CUPSD_LOG_ERROR
,
1115 "Ran out of memory for job file types!");
1119 job
->compressions
= compressions
;
1120 job
->filetypes
= filetypes
;
1121 job
->num_files
= fileid
;
1124 job
->filetypes
[fileid
- 1] = mimeFileType(MimeDatabase
, jobfile
, NULL
,
1125 job
->compressions
+ fileid
- 1);
1127 if (!job
->filetypes
[fileid
- 1])
1128 job
->filetypes
[fileid
- 1] = mimeType(MimeDatabase
, "application",
1133 job
->access_time
= time(NULL
);
1138 * 'cupsdMoveJob()' - Move the specified job to a different destination.
1142 cupsdMoveJob(cupsd_job_t
*job
, /* I - Job */
1143 cupsd_printer_t
*p
) /* I - Destination printer or class */
1145 ipp_attribute_t
*attr
; /* job-printer-uri attribute */
1146 const char *olddest
; /* Old destination */
1147 cupsd_printer_t
*oldp
; /* Old pointer */
1151 * Don't move completed jobs...
1154 if (job
->state_value
> IPP_JOB_STOPPED
)
1158 * Get the old destination...
1161 olddest
= job
->dest
;
1164 oldp
= job
->printer
;
1166 oldp
= cupsdFindDest(olddest
);
1169 * Change the destination information...
1174 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, oldp
, job
,
1175 "Job #%d moved from %s to %s.", job
->id
, olddest
,
1178 cupsdSetString(&job
->dest
, p
->name
);
1179 job
->dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
|
1180 CUPS_PRINTER_IMPLICIT
);
1182 if ((attr
= ippFindAttribute(job
->attrs
, "job-printer-uri",
1183 IPP_TAG_URI
)) != NULL
)
1184 cupsdSetString(&(attr
->values
[0].string
.text
), p
->uri
);
1186 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
1187 "Job #%d moved from %s to %s.", job
->id
, olddest
,
1195 * 'cupsdReleaseJob()' - Release the specified job.
1199 cupsdReleaseJob(cupsd_job_t
*job
) /* I - Job */
1201 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReleaseJob: id = %d", job
->id
);
1203 if (job
->state_value
== IPP_JOB_HELD
)
1205 DEBUG_puts("cupsdReleaseJob: setting state to pending...");
1207 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1208 job
->state_value
= IPP_JOB_PENDING
;
1216 * 'cupsdRestartJob()' - Restart the specified job.
1220 cupsdRestartJob(cupsd_job_t
*job
) /* I - Job */
1222 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdRestartJob: id = %d", job
->id
);
1224 if (job
->state_value
== IPP_JOB_STOPPED
|| job
->num_files
)
1226 ipp_jstate_t old_state
; /* Old job state */
1231 old_state
= job
->state_value
;
1234 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1235 job
->state_value
= IPP_JOB_PENDING
;
1239 if (old_state
> IPP_JOB_STOPPED
)
1240 cupsArrayAdd(ActiveJobs
, job
);
1248 * 'cupsdSaveAllJobs()' - Save a summary of all jobs to disk.
1252 cupsdSaveAllJobs(void)
1254 int i
; /* Looping var */
1255 cups_file_t
*fp
; /* Job cache file */
1256 char temp
[1024]; /* Temporary string */
1257 cupsd_job_t
*job
; /* Current job */
1258 time_t curtime
; /* Current time */
1259 struct tm
*curdate
; /* Current date */
1262 snprintf(temp
, sizeof(temp
), "%s/job.cache", CacheDir
);
1263 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1265 cupsdLogMessage(CUPSD_LOG_ERROR
,
1266 "Unable to create job cache file \"%s\" - %s",
1267 temp
, strerror(errno
));
1271 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving job cache file \"%s\"...", temp
);
1274 * Restrict access to the file...
1277 fchown(cupsFileNumber(fp
), getuid(), Group
);
1278 fchmod(cupsFileNumber(fp
), ConfigFilePerm
);
1281 * Write a small header to the file...
1284 curtime
= time(NULL
);
1285 curdate
= localtime(&curtime
);
1286 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1288 cupsFilePuts(fp
, "# Job cache file for " CUPS_SVERSION
"\n");
1289 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1290 cupsFilePrintf(fp
, "NextJobId %d\n", NextJobId
);
1293 * Write each job known to the system...
1296 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
1298 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
1300 cupsFilePrintf(fp
, "<Job %d>\n", job
->id
);
1301 cupsFilePrintf(fp
, "State %d\n", job
->state_value
);
1302 cupsFilePrintf(fp
, "Priority %d\n", job
->priority
);
1303 cupsFilePrintf(fp
, "Username %s\n", job
->username
);
1304 cupsFilePrintf(fp
, "Destination %s\n", job
->dest
);
1305 cupsFilePrintf(fp
, "DestType %d\n", job
->dtype
);
1306 cupsFilePrintf(fp
, "NumFiles %d\n", job
->num_files
);
1307 for (i
= 0; i
< job
->num_files
; i
++)
1308 cupsFilePrintf(fp
, "File %d %s/%s %d\n", i
+ 1, job
->filetypes
[i
]->super
,
1309 job
->filetypes
[i
]->type
, job
->compressions
[i
]);
1310 cupsFilePuts(fp
, "</Job>\n");
1318 * 'cupsdSaveJob()' - Save a job to disk.
1322 cupsdSaveJob(cupsd_job_t
*job
) /* I - Job */
1324 char filename
[1024]; /* Job control filename */
1325 cups_file_t
*fp
; /* Job file */
1328 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdSaveJob(job=%p(%d)): job->attrs=%p",
1329 job
, job
->id
, job
->attrs
);
1331 snprintf(filename
, sizeof(filename
), "%s/c%05d", RequestRoot
, job
->id
);
1333 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
1335 cupsdLogMessage(CUPSD_LOG_ERROR
,
1336 "Unable to create job control file \"%s\" - %s.",
1337 filename
, strerror(errno
));
1341 fchmod(cupsFileNumber(fp
), 0600);
1342 fchown(cupsFileNumber(fp
), RunUser
, Group
);
1344 job
->attrs
->state
= IPP_IDLE
;
1346 if (ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
,
1347 job
->attrs
) != IPP_DATA
)
1348 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to write job control file \"%s\"!",
1356 * 'cupsdSetJobHoldUntil()' - Set the hold time for a job...
1360 cupsdSetJobHoldUntil(cupsd_job_t
*job
, /* I - Job */
1361 const char *when
) /* I - When to resume */
1363 time_t curtime
; /* Current time */
1364 struct tm
*curdate
; /* Current date */
1365 int hour
; /* Hold hour */
1366 int minute
; /* Hold minute */
1367 int second
; /* Hold second */
1370 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdSetJobHoldUntil(%d, \"%s\")",
1375 if (!strcmp(when
, "indefinite") || !strcmp(when
, "authenticated"))
1378 * Hold indefinitely...
1381 job
->hold_until
= 0;
1383 else if (!strcmp(when
, "day-time"))
1386 * Hold to 6am the next morning unless local time is < 6pm.
1389 curtime
= time(NULL
);
1390 curdate
= localtime(&curtime
);
1392 if (curdate
->tm_hour
< 18)
1393 job
->hold_until
= curtime
;
1395 job
->hold_until
= curtime
+
1396 ((29 - curdate
->tm_hour
) * 60 + 59 -
1397 curdate
->tm_min
) * 60 + 60 - curdate
->tm_sec
;
1399 else if (!strcmp(when
, "evening") || !strcmp(when
, "night"))
1402 * Hold to 6pm unless local time is > 6pm or < 6am.
1405 curtime
= time(NULL
);
1406 curdate
= localtime(&curtime
);
1408 if (curdate
->tm_hour
< 6 || curdate
->tm_hour
>= 18)
1409 job
->hold_until
= curtime
;
1411 job
->hold_until
= curtime
+
1412 ((17 - curdate
->tm_hour
) * 60 + 59 -
1413 curdate
->tm_min
) * 60 + 60 - curdate
->tm_sec
;
1415 else if (!strcmp(when
, "second-shift"))
1418 * Hold to 4pm unless local time is > 4pm.
1421 curtime
= time(NULL
);
1422 curdate
= localtime(&curtime
);
1424 if (curdate
->tm_hour
>= 16)
1425 job
->hold_until
= curtime
;
1427 job
->hold_until
= curtime
+
1428 ((15 - curdate
->tm_hour
) * 60 + 59 -
1429 curdate
->tm_min
) * 60 + 60 - curdate
->tm_sec
;
1431 else if (!strcmp(when
, "third-shift"))
1434 * Hold to 12am unless local time is < 8am.
1437 curtime
= time(NULL
);
1438 curdate
= localtime(&curtime
);
1440 if (curdate
->tm_hour
< 8)
1441 job
->hold_until
= curtime
;
1443 job
->hold_until
= curtime
+
1444 ((23 - curdate
->tm_hour
) * 60 + 59 -
1445 curdate
->tm_min
) * 60 + 60 - curdate
->tm_sec
;
1447 else if (!strcmp(when
, "weekend"))
1450 * Hold to weekend unless we are in the weekend.
1453 curtime
= time(NULL
);
1454 curdate
= localtime(&curtime
);
1456 if (curdate
->tm_wday
|| curdate
->tm_wday
== 6)
1457 job
->hold_until
= curtime
;
1459 job
->hold_until
= curtime
+
1460 (((5 - curdate
->tm_wday
) * 24 +
1461 (17 - curdate
->tm_hour
)) * 60 + 59 -
1462 curdate
->tm_min
) * 60 + 60 - curdate
->tm_sec
;
1464 else if (sscanf(when
, "%d:%d:%d", &hour
, &minute
, &second
) >= 2)
1467 * Hold to specified GMT time (HH:MM or HH:MM:SS)...
1470 curtime
= time(NULL
);
1471 curdate
= gmtime(&curtime
);
1473 job
->hold_until
= curtime
+
1474 ((hour
- curdate
->tm_hour
) * 60 + minute
-
1475 curdate
->tm_min
) * 60 + second
- curdate
->tm_sec
;
1478 * Hold until next day as needed...
1481 if (job
->hold_until
< curtime
)
1482 job
->hold_until
+= 24 * 60 * 60;
1485 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdSetJobHoldUntil: hold_until = %d",
1486 (int)job
->hold_until
);
1491 * 'cupsdSetJobPriority()' - Set the priority of a job, moving it up/down in
1492 * the list as needed.
1496 cupsdSetJobPriority(
1497 cupsd_job_t
*job
, /* I - Job ID */
1498 int priority
) /* I - New priority (0 to 100) */
1500 ipp_attribute_t
*attr
; /* Job attribute */
1504 * Don't change completed jobs...
1507 if (job
->state_value
>= IPP_JOB_PROCESSING
)
1511 * Set the new priority and re-add the job into the active list...
1514 cupsArrayRemove(ActiveJobs
, job
);
1516 job
->priority
= priority
;
1518 if ((attr
= ippFindAttribute(job
->attrs
, "job-priority",
1519 IPP_TAG_INTEGER
)) != NULL
)
1520 attr
->values
[0].integer
= priority
;
1522 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1525 cupsArrayAdd(ActiveJobs
, job
);
1532 * 'cupsdStopAllJobs()' - Stop all print jobs.
1536 cupsdStopAllJobs(int force
) /* I - 1 = Force all filters to stop */
1538 cupsd_job_t
*job
; /* Current job */
1541 DEBUG_puts("cupsdStopAllJobs()");
1543 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
1545 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
1546 if (job
->state_value
== IPP_JOB_PROCESSING
)
1548 cupsdStopJob(job
, force
);
1549 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1550 job
->state_value
= IPP_JOB_PENDING
;
1556 * 'cupsdStopJob()' - Stop a print job.
1560 cupsdStopJob(cupsd_job_t
*job
, /* I - Job */
1561 int force
) /* I - 1 = Force all filters to stop */
1563 int i
; /* Looping var */
1566 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStopJob: id = %d, force = %d",
1569 if (job
->state_value
!= IPP_JOB_PROCESSING
)
1572 FilterLevel
-= job
->cost
;
1574 if (job
->printer
->state
== IPP_PRINTER_PROCESSING
)
1575 cupsdSetPrinterState(job
->printer
, IPP_PRINTER_IDLE
, 0);
1577 job
->state
->values
[0].integer
= IPP_JOB_STOPPED
;
1578 job
->state_value
= IPP_JOB_STOPPED
;
1579 job
->printer
->job
= NULL
;
1580 job
->printer
= NULL
;
1582 job
->current_file
--;
1584 for (i
= 0; job
->filters
[i
]; i
++)
1585 if (job
->filters
[i
] > 0)
1587 cupsdEndProcess(job
->filters
[i
], force
);
1588 job
->filters
[i
] = 0;
1591 if (job
->backend
> 0)
1593 cupsdEndProcess(job
->backend
, force
);
1597 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1598 "cupsdStopJob: Closing print pipes [ %d %d ]...",
1599 job
->print_pipes
[0], job
->print_pipes
[1]);
1601 cupsdClosePipe(job
->print_pipes
);
1603 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1604 "cupsdStopJob: Closing back pipes [ %d %d ]...",
1605 job
->back_pipes
[0], job
->back_pipes
[1]);
1607 cupsdClosePipe(job
->back_pipes
);
1609 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1610 "cupsdStopJob: Closing side pipes [ %d %d ]...",
1611 job
->side_pipes
[0], job
->side_pipes
[1]);
1613 cupsdClosePipe(job
->side_pipes
);
1615 if (job
->status_buffer
)
1618 * Close the pipe and clear the input bit.
1621 cupsdRemoveSelect(job
->status_buffer
->fd
);
1623 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1624 "cupsdStopJob: Closing status pipes [ %d %d ]...",
1625 job
->status_pipes
[0], job
->status_pipes
[1]);
1627 cupsdClosePipe(job
->status_pipes
);
1628 cupsdStatBufDelete(job
->status_buffer
);
1630 job
->status_buffer
= NULL
;
1636 * 'cupsdUnloadCompletedJobs()' - Flush completed job history from memory.
1640 cupsdUnloadCompletedJobs(void)
1642 cupsd_job_t
*job
; /* Current job */
1643 time_t expire
; /* Expiration time */
1646 expire
= time(NULL
) - 60;
1648 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
1650 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
1651 if (job
->attrs
&& job
->state_value
>= IPP_JOB_STOPPED
&&
1652 job
->access_time
< expire
)
1658 * 'cupsdUpdateJob()' - Read a status update from a job's filters.
1662 cupsdUpdateJob(cupsd_job_t
*job
) /* I - Job to check */
1664 int i
; /* Looping var */
1665 int copies
; /* Number of copies printed */
1666 char message
[1024], /* Message text */
1667 *ptr
; /* Pointer update... */
1668 int loglevel
, /* Log level for message */
1669 event
= 0; /* Events? */
1672 while ((ptr
= cupsdStatBufUpdate(job
->status_buffer
, &loglevel
,
1673 message
, sizeof(message
))) != NULL
)
1676 * Process page and printer state messages as needed...
1679 if (loglevel
== CUPSD_LOG_PAGE
)
1682 * Page message; send the message to the page_log file and update the
1683 * job sheet count...
1686 if (job
->sheets
!= NULL
)
1688 if (!strncasecmp(message
, "total ", 6))
1691 * Got a total count of pages from a backend or filter...
1694 copies
= atoi(message
+ 6);
1695 copies
-= job
->sheets
->values
[0].integer
; /* Just track the delta */
1697 else if (!sscanf(message
, "%*d%d", &copies
))
1700 job
->sheets
->values
[0].integer
+= copies
;
1702 if (job
->printer
->page_limit
)
1703 cupsdUpdateQuota(job
->printer
, job
->username
, copies
, 0);
1706 cupsdLogPage(job
, message
);
1708 cupsdAddEvent(CUPSD_EVENT_JOB_PROGRESS
, job
->printer
, job
,
1709 "Printed %d page(s).", job
->sheets
->values
[0].integer
);
1711 else if (loglevel
== CUPSD_LOG_STATE
)
1713 cupsdSetPrinterReasons(job
->printer
, message
);
1714 cupsdAddPrinterHistory(job
->printer
);
1715 event
|= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
1717 else if (loglevel
== CUPSD_LOG_ATTR
)
1720 * Set attribute(s)...
1723 int num_attrs
; /* Number of attributes */
1724 cups_option_t
*attrs
; /* Attributes */
1725 const char *attr
; /* Attribute */
1728 num_attrs
= cupsParseOptions(message
, 0, &attrs
);
1730 if ((attr
= cupsGetOption("auth-info-required", num_attrs
,
1732 cupsdSetAuthInfoRequired(job
->printer
, attr
, NULL
);
1734 cupsFreeOptions(num_attrs
, attrs
);
1737 else if (!strncmp(message
, "recoverable:", 12))
1739 cupsdSetPrinterReasons(job
->printer
,
1740 "+com.apple.print.recoverable-warning");
1743 while (isspace(*ptr
& 255))
1746 cupsdSetString(&job
->printer
->recoverable
, ptr
);
1747 cupsdAddPrinterHistory(job
->printer
);
1748 event
|= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
1750 else if (!strncmp(message
, "recovered:", 10))
1752 cupsdSetPrinterReasons(job
->printer
,
1753 "-com.apple.print.recoverable-warning");
1756 while (isspace(*ptr
& 255))
1759 cupsdSetString(&job
->printer
->recoverable
, ptr
);
1760 cupsdAddPrinterHistory(job
->printer
);
1761 event
|= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
1763 #endif /* __APPLE__ */
1764 else if (loglevel
<= CUPSD_LOG_INFO
)
1767 * Some message to show in the printer-state-message attribute...
1770 strlcpy(job
->printer
->state_message
, message
,
1771 sizeof(job
->printer
->state_message
));
1772 cupsdAddPrinterHistory(job
->printer
);
1773 event
|= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
1776 if (!strchr(job
->status_buffer
->buffer
, '\n'))
1780 if ((event
& CUPSD_EVENT_PRINTER_STATE_CHANGED
))
1781 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED
, job
->printer
, NULL
,
1782 (job
->printer
->type
& CUPS_PRINTER_CLASS
) ?
1783 "Class \"%s\" state changed." :
1784 "Printer \"%s\" state changed.",
1785 job
->printer
->name
);
1787 if (ptr
== NULL
&& !job
->status_buffer
->bufused
)
1790 * See if all of the filters and the backend have returned their
1794 for (i
= 0; job
->filters
[i
] < 0; i
++);
1796 if (job
->filters
[i
])
1799 if (job
->current_file
>= job
->num_files
&& job
->backend
> 0)
1803 * Handle the end of job stuff...
1806 cupsdFinishJob(job
);
1812 * 'compare_active_jobs()' - Compare the job IDs and priorities of two jobs.
1815 static int /* O - Difference */
1816 compare_active_jobs(void *first
, /* I - First job */
1817 void *second
, /* I - Second job */
1818 void *data
) /* I - App data (not used) */
1820 int diff
; /* Difference */
1823 if ((diff
= ((cupsd_job_t
*)second
)->priority
-
1824 ((cupsd_job_t
*)first
)->priority
) != 0)
1827 return (((cupsd_job_t
*)first
)->id
- ((cupsd_job_t
*)second
)->id
);
1832 * 'compare_jobs()' - Compare the job IDs of two jobs.
1835 static int /* O - Difference */
1836 compare_jobs(void *first
, /* I - First job */
1837 void *second
, /* I - Second job */
1838 void *data
) /* I - App data (not used) */
1840 return (((cupsd_job_t
*)first
)->id
- ((cupsd_job_t
*)second
)->id
);
1845 * 'free_job()' - Free all memory used by a job.
1849 free_job(cupsd_job_t
*job
) /* I - Job */
1851 cupsdClearString(&job
->username
);
1852 cupsdClearString(&job
->dest
);
1854 cupsdClearString(&job
->ccname
);
1855 #endif /* HAVE_GSSAPI */
1857 if (job
->num_files
> 0)
1859 free(job
->compressions
);
1860 free(job
->filetypes
);
1863 ippDelete(job
->attrs
);
1870 * 'ipp_length()' - Compute the size of the buffer needed to hold
1871 * the textual IPP attributes.
1874 static int /* O - Size of attribute buffer */
1875 ipp_length(ipp_t
*ipp
) /* I - IPP request */
1877 int bytes
; /* Number of bytes */
1878 int i
; /* Looping var */
1879 ipp_attribute_t
*attr
; /* Current attribute */
1883 * Loop through all attributes...
1888 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1891 * Skip attributes that won't be sent to filters...
1894 if (attr
->value_tag
== IPP_TAG_MIMETYPE
||
1895 attr
->value_tag
== IPP_TAG_NAMELANG
||
1896 attr
->value_tag
== IPP_TAG_TEXTLANG
||
1897 attr
->value_tag
== IPP_TAG_URI
||
1898 attr
->value_tag
== IPP_TAG_URISCHEME
)
1901 if (strncmp(attr
->name
, "time-", 5) == 0)
1905 * Add space for a leading space and commas between each value.
1906 * For the first attribute, the leading space isn't used, so the
1907 * extra byte can be used as the nul terminator...
1910 bytes
++; /* " " separator */
1911 bytes
+= attr
->num_values
; /* "," separators */
1914 * Boolean attributes appear as "foo,nofoo,foo,nofoo", while
1915 * other attributes appear as "foo=value1,value2,...,valueN".
1918 if (attr
->value_tag
!= IPP_TAG_BOOLEAN
)
1919 bytes
+= strlen(attr
->name
);
1921 bytes
+= attr
->num_values
* strlen(attr
->name
);
1924 * Now add the size required for each value in the attribute...
1927 switch (attr
->value_tag
)
1929 case IPP_TAG_INTEGER
:
1932 * Minimum value of a signed integer is -2147483647, or 11 digits.
1935 bytes
+= attr
->num_values
* 11;
1938 case IPP_TAG_BOOLEAN
:
1940 * Add two bytes for each false ("no") value...
1943 for (i
= 0; i
< attr
->num_values
; i
++)
1944 if (!attr
->values
[i
].boolean
)
1948 case IPP_TAG_RANGE
:
1950 * A range is two signed integers separated by a hyphen, or
1951 * 23 characters max.
1954 bytes
+= attr
->num_values
* 23;
1957 case IPP_TAG_RESOLUTION
:
1959 * A resolution is two signed integers separated by an "x" and
1960 * suffixed by the units, or 26 characters max.
1963 bytes
+= attr
->num_values
* 26;
1966 case IPP_TAG_STRING
:
1969 case IPP_TAG_KEYWORD
:
1970 case IPP_TAG_CHARSET
:
1971 case IPP_TAG_LANGUAGE
:
1974 * Strings can contain characters that need quoting. We need
1975 * at least 2 * len + 2 characters to cover the quotes and
1976 * any backslashes in the string.
1979 for (i
= 0; i
< attr
->num_values
; i
++)
1980 bytes
+= 2 * strlen(attr
->values
[i
].string
.text
) + 2;
1984 break; /* anti-compiler-warning-code */
1993 * 'load_job_cache()' - Load jobs from the job.cache file.
1997 load_job_cache(const char *filename
) /* I - job.cache filename */
1999 cups_file_t
*fp
; /* job.cache file */
2000 char line
[1024], /* Line buffer */
2001 *value
; /* Value on line */
2002 int linenum
; /* Line number in file */
2003 cupsd_job_t
*job
; /* Current job */
2004 int jobid
; /* Job ID */
2005 char jobfile
[1024]; /* Job filename */
2009 * Open the job.cache file...
2012 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
2014 if (errno
!= ENOENT
)
2015 cupsdLogMessage(CUPSD_LOG_ERROR
,
2016 "Unable to open job cache file \"%s\": %s",
2017 filename
, strerror(errno
));
2019 load_request_root();
2025 * Read entries from the job cache file and create jobs as needed.
2028 cupsdLogMessage(CUPSD_LOG_INFO
, "Loading job cache file \"%s\"...",
2034 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2036 if (!strcasecmp(line
, "NextJobId"))
2039 NextJobId
= atoi(value
);
2041 else if (!strcasecmp(line
, "<Job"))
2045 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing </Job> directive on line %d!",
2052 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing job ID on line %d!", linenum
);
2056 jobid
= atoi(value
);
2060 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad job ID %d on line %d!", jobid
,
2065 snprintf(jobfile
, sizeof(jobfile
), "%s/c%05d", RequestRoot
, jobid
);
2066 if (access(jobfile
, 0))
2068 cupsdLogMessage(CUPSD_LOG_ERROR
, "Job %d files have gone away!", jobid
);
2072 job
= calloc(1, sizeof(cupsd_job_t
));
2075 cupsdLogMessage(CUPSD_LOG_EMERG
,
2076 "Unable to allocate memory for job %d!", jobid
);
2081 job
->back_pipes
[0] = -1;
2082 job
->back_pipes
[1] = -1;
2083 job
->print_pipes
[0] = -1;
2084 job
->print_pipes
[1] = -1;
2085 job
->side_pipes
[0] = -1;
2086 job
->side_pipes
[1] = -1;
2087 job
->status_pipes
[0] = -1;
2088 job
->status_pipes
[1] = -1;
2090 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading job %d from cache...", job
->id
);
2094 cupsdLogMessage(CUPSD_LOG_ERROR
,
2095 "Missing <Job #> directive on line %d!", linenum
);
2098 else if (!strcasecmp(line
, "</Job>"))
2100 cupsArrayAdd(Jobs
, job
);
2102 if (job
->state_value
<= IPP_JOB_STOPPED
)
2104 cupsArrayAdd(ActiveJobs
, job
);
2112 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d!", linenum
);
2115 else if (!strcasecmp(line
, "State"))
2117 job
->state_value
= (ipp_jstate_t
)atoi(value
);
2119 if (job
->state_value
< IPP_JOB_PENDING
)
2120 job
->state_value
= IPP_JOB_PENDING
;
2121 else if (job
->state_value
> IPP_JOB_COMPLETED
)
2122 job
->state_value
= IPP_JOB_COMPLETED
;
2124 else if (!strcasecmp(line
, "Priority"))
2126 job
->priority
= atoi(value
);
2128 else if (!strcasecmp(line
, "Username"))
2130 cupsdSetString(&job
->username
, value
);
2132 else if (!strcasecmp(line
, "Destination"))
2134 cupsdSetString(&job
->dest
, value
);
2136 else if (!strcasecmp(line
, "DestType"))
2138 job
->dtype
= (cups_ptype_t
)atoi(value
);
2140 else if (!strcasecmp(line
, "NumFiles"))
2142 job
->num_files
= atoi(value
);
2144 if (job
->num_files
< 0)
2146 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad NumFiles value %d on line %d!",
2147 job
->num_files
, linenum
);
2152 if (job
->num_files
> 0)
2154 snprintf(jobfile
, sizeof(jobfile
), "%s/d%05d-001", RequestRoot
,
2156 if (access(jobfile
, 0))
2158 cupsdLogMessage(CUPSD_LOG_INFO
,
2159 "Data files for job %d have gone away!", job
->id
);
2164 job
->filetypes
= calloc(job
->num_files
, sizeof(mime_type_t
*));
2165 job
->compressions
= calloc(job
->num_files
, sizeof(int));
2167 if (!job
->filetypes
|| !job
->compressions
)
2169 cupsdLogMessage(CUPSD_LOG_EMERG
,
2170 "Unable to allocate memory for %d files!",
2176 else if (!strcasecmp(line
, "File"))
2178 int number
, /* File number */
2179 compression
; /* Compression value */
2180 char super
[MIME_MAX_SUPER
], /* MIME super type */
2181 type
[MIME_MAX_TYPE
]; /* MIME type */
2184 if (sscanf(value
, "%d%*[ \t]%15[^/]/%255s%d", &number
, super
, type
,
2187 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad File on line %d!", linenum
);
2191 if (number
< 1 || number
> job
->num_files
)
2193 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad File number %d on line %d!",
2200 job
->compressions
[number
] = compression
;
2201 job
->filetypes
[number
] = mimeType(MimeDatabase
, super
, type
);
2203 if (!job
->filetypes
[number
])
2206 * If the original MIME type is unknown, auto-type it!
2209 cupsdLogMessage(CUPSD_LOG_ERROR
,
2210 "Unknown MIME type %s/%s for file %d of job %d!",
2211 super
, type
, number
+ 1, job
->id
);
2213 snprintf(jobfile
, sizeof(jobfile
), "%s/d%05d-%03d", RequestRoot
,
2214 job
->id
, number
+ 1);
2215 job
->filetypes
[number
] = mimeFileType(MimeDatabase
, jobfile
, NULL
,
2216 job
->compressions
+ number
);
2219 * If that didn't work, assume it is raw...
2222 if (!job
->filetypes
[number
])
2223 job
->filetypes
[number
] = mimeType(MimeDatabase
, "application",
2228 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown %s directive on line %d!",
2237 * 'load_next_job_id()' - Load the NextJobId value from the job.cache file.
2241 load_next_job_id(const char *filename
) /* I - job.cache filename */
2243 cups_file_t
*fp
; /* job.cache file */
2244 char line
[1024], /* Line buffer */
2245 *value
; /* Value on line */
2246 int linenum
; /* Line number in file */
2247 int next_job_id
; /* NextJobId value from line */
2251 * Read the NextJobId directive from the job.cache file and use
2252 * the value (if any).
2255 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
2257 if (errno
!= ENOENT
)
2258 cupsdLogMessage(CUPSD_LOG_ERROR
,
2259 "Unable to open job cache file \"%s\": %s",
2260 filename
, strerror(errno
));
2265 cupsdLogMessage(CUPSD_LOG_INFO
,
2266 "Loading NextJobId from job cache file \"%s\"...", filename
);
2270 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2272 if (!strcasecmp(line
, "NextJobId"))
2276 next_job_id
= atoi(value
);
2278 if (next_job_id
> NextJobId
)
2279 NextJobId
= next_job_id
;
2290 * 'load_request_root()' - Load jobs from the RequestRoot directory.
2294 load_request_root(void)
2296 cups_dir_t
*dir
; /* Directory */
2297 cups_dentry_t
*dent
; /* Directory entry */
2298 cupsd_job_t
*job
; /* New job */
2302 * Open the requests directory...
2305 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Scanning %s for jobs...", RequestRoot
);
2307 if ((dir
= cupsDirOpen(RequestRoot
)) == NULL
)
2309 cupsdLogMessage(CUPSD_LOG_ERROR
,
2310 "Unable to open spool directory \"%s\": %s",
2311 RequestRoot
, strerror(errno
));
2316 * Read all the c##### files...
2319 while ((dent
= cupsDirRead(dir
)) != NULL
)
2320 if (strlen(dent
->filename
) >= 6 && dent
->filename
[0] == 'c')
2323 * Allocate memory for the job...
2326 if ((job
= calloc(sizeof(cupsd_job_t
), 1)) == NULL
)
2328 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ran out of memory for jobs!");
2334 * Assign the job ID...
2337 job
->id
= atoi(dent
->filename
+ 1);
2338 job
->back_pipes
[0] = -1;
2339 job
->back_pipes
[1] = -1;
2340 job
->print_pipes
[0] = -1;
2341 job
->print_pipes
[1] = -1;
2342 job
->side_pipes
[0] = -1;
2343 job
->side_pipes
[1] = -1;
2344 job
->status_pipes
[0] = -1;
2345 job
->status_pipes
[1] = -1;
2347 if (job
->id
>= NextJobId
)
2348 NextJobId
= job
->id
+ 1;
2357 * Insert the job into the array, sorting by job priority and ID...
2360 cupsArrayAdd(Jobs
, job
);
2362 if (job
->state_value
<= IPP_JOB_STOPPED
)
2363 cupsArrayAdd(ActiveJobs
, job
);
2373 * 'set_time()' - Set one of the "time-at-xyz" attributes...
2377 set_time(cupsd_job_t
*job
, /* I - Job to update */
2378 const char *name
) /* I - Name of attribute */
2380 ipp_attribute_t
*attr
; /* Time attribute */
2383 if ((attr
= ippFindAttribute(job
->attrs
, name
, IPP_TAG_ZERO
)) != NULL
)
2385 attr
->value_tag
= IPP_TAG_INTEGER
;
2386 attr
->values
[0].integer
= time(NULL
);
2392 * 'set_hold_until()' - Set the hold time and update job-hold-until attribute...
2396 set_hold_until(cupsd_job_t
*job
, /* I - Job to update */
2397 time_t holdtime
) /* I - Hold until time */
2399 ipp_attribute_t
*attr
; /* job-hold-until attribute */
2400 struct tm
*holddate
; /* Hold date */
2401 char holdstr
[64]; /* Hold time */
2405 * Set the hold_until value and hold the job...
2408 cupsdLogMessage(CUPSD_LOG_DEBUG
, "set_hold_until: hold_until = %d",
2411 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
2412 job
->state_value
= IPP_JOB_HELD
;
2413 job
->hold_until
= holdtime
;
2416 * Update the job-hold-until attribute with a string representing GMT
2417 * time (HH:MM:SS)...
2420 holddate
= gmtime(&holdtime
);
2421 snprintf(holdstr
, sizeof(holdstr
), "%d:%d:%d", holddate
->tm_hour
,
2422 holddate
->tm_min
, holddate
->tm_sec
);
2424 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
2425 IPP_TAG_KEYWORD
)) == NULL
)
2426 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
2429 * Either add the attribute or update the value of the existing one
2433 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2434 "job-hold-until", NULL
, holdstr
);
2436 cupsdSetString(&attr
->values
[0].string
.text
, holdstr
);
2443 * 'start_job()' - Start a print job.
2447 start_job(cupsd_job_t
*job
, /* I - Job ID */
2448 cupsd_printer_t
*printer
) /* I - Printer to print job */
2450 int i
; /* Looping var */
2451 int slot
; /* Pipe slot */
2452 cups_array_t
*filters
, /* Filters for job */
2453 *prefilters
; /* Filters with prefilters */
2454 mime_filter_t
*filter
, /* Current filter */
2455 *prefilter
, /* Prefilter */
2456 port_monitor
; /* Port monitor filter */
2457 char method
[255], /* Method for output */
2458 *optptr
, /* Pointer to options */
2459 *valptr
; /* Pointer in value string */
2460 ipp_attribute_t
*attr
; /* Current attribute */
2461 struct stat backinfo
; /* Backend file information */
2462 int backroot
; /* Run backend as root? */
2463 int pid
; /* Process ID of new filter process */
2464 int banner_page
; /* 1 if banner page, 0 otherwise */
2465 int filterfds
[2][2];/* Pipes used between filters */
2466 int envc
; /* Number of environment variables */
2467 char **argv
, /* Filter command-line arguments */
2468 sani_uri
[1024], /* Sanitized DEVICE_URI env var */
2469 filename
[1024], /* Job filename */
2470 command
[1024], /* Full path to command */
2471 jobid
[255], /* Job ID string */
2472 title
[IPP_MAX_NAME
],
2473 /* Job title string */
2474 copies
[255], /* # copies string */
2475 *envp
[MAX_ENV
+ 12],
2476 /* Environment variables */
2477 charset
[255], /* CHARSET env variable */
2478 class_name
[255],/* CLASS env variable */
2479 classification
[1024],
2480 /* CLASSIFICATION env variable */
2482 /* CONTENT_TYPE env variable */
2484 /* DEVICE_URI env variable */
2485 final_content_type
[1024],
2486 /* FINAL_CONTENT_TYPE env variable */
2487 lang
[255], /* LANG env variable */
2488 ppd
[1024], /* PPD env variable */
2490 /* PRINTER env variable */
2492 /* RIP_MAX_CACHE env variable */
2493 static char *options
= NULL
;/* Full list of options */
2494 static int optlength
= 0; /* Length of option buffer */
2497 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_job: id = %d, file = %d/%d",
2498 job
->id
, job
->current_file
, job
->num_files
);
2500 if (job
->num_files
== 0)
2502 cupsdLogMessage(CUPSD_LOG_ERROR
, "Job ID %d has no files! Canceling it!",
2505 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2509 if (printer
->raw
&& !strncmp(printer
->device_uri
, "file:", 5))
2511 cupsdLogMessage(CUPSD_LOG_ERROR
,
2512 "Job ID %d cannot be printed to raw queue pointing to "
2516 strlcpy(printer
->state_message
, "Raw printers cannot use file: devices!",
2517 sizeof(printer
->state_message
));
2518 cupsdStopPrinter(printer
, 1);
2519 cupsdAddPrinterHistory(printer
);
2524 * Figure out what filters are required to convert from
2525 * the source to the destination type...
2534 * Remote jobs and raw queues go directly to the printer without
2538 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2539 "[Job %d] Sending job to queue tagged as raw...", job
->id
);
2546 * Local jobs get filtered...
2549 filters
= mimeFilter(MimeDatabase
, job
->filetypes
[job
->current_file
],
2550 printer
->filetype
, &(job
->cost
));
2554 cupsdLogMessage(CUPSD_LOG_ERROR
,
2555 "Unable to convert file %d to printable format for "
2557 job
->current_file
, job
->id
);
2558 cupsdLogMessage(CUPSD_LOG_INFO
,
2559 "Hint: Do you have ESP Ghostscript installed?");
2561 if (LogLevel
< CUPSD_LOG_DEBUG
)
2562 cupsdLogMessage(CUPSD_LOG_INFO
,
2563 "Hint: Try setting the LogLevel to \"debug\".");
2565 job
->current_file
++;
2567 if (job
->current_file
== job
->num_files
)
2568 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2574 * Remove NULL ("-") filters...
2577 for (filter
= (mime_filter_t
*)cupsArrayFirst(filters
);
2579 filter
= (mime_filter_t
*)cupsArrayNext(filters
))
2580 if (!strcmp(filter
->filter
, "-"))
2581 cupsArrayRemove(filters
, filter
);
2583 if (cupsArrayCount(filters
) == 0)
2585 cupsArrayDelete(filters
);
2590 * If this printer has any pre-filters, insert the required pre-filter
2591 * in the filters array...
2594 if (printer
->prefiltertype
&& filters
)
2596 prefilters
= cupsArrayNew(NULL
, NULL
);
2598 for (filter
= (mime_filter_t
*)cupsArrayFirst(filters
);
2600 filter
= (mime_filter_t
*)cupsArrayNext(filters
))
2602 if ((prefilter
= mimeFilterLookup(MimeDatabase
, filter
->src
,
2603 printer
->prefiltertype
)))
2605 cupsArrayAdd(prefilters
, prefilter
);
2606 job
->cost
+= prefilter
->cost
;
2609 cupsArrayAdd(prefilters
, filter
);
2612 cupsArrayDelete(filters
);
2613 filters
= prefilters
;
2618 * Set a minimum cost of 100 for all jobs so that FilterLimit
2619 * works with raw queues and other low-cost paths.
2622 if (job
->cost
< 100)
2626 * See if the filter cost is too high...
2629 if ((FilterLevel
+ job
->cost
) > FilterLimit
&& FilterLevel
> 0 &&
2633 * Don't print this job quite yet...
2636 cupsArrayDelete(filters
);
2638 cupsdLogMessage(CUPSD_LOG_INFO
,
2639 "Holding job %d because filter limit has been reached.",
2641 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2642 "start_job: id=%d, file=%d, cost=%d, level=%d, "
2644 job
->id
, job
->current_file
, job
->cost
, FilterLevel
,
2649 FilterLevel
+= job
->cost
;
2652 * Add decompression filters, if any...
2655 if (!printer
->raw
&& job
->compressions
[job
->current_file
])
2658 * Add gziptoany filter to the front of the list...
2662 filters
= cupsArrayNew(NULL
, NULL
);
2664 if (!cupsArrayInsert(filters
, &gziptoany_filter
))
2666 cupsdLogMessage(CUPSD_LOG_ERROR
,
2667 "Unable to add decompression filter - %s",
2670 cupsArrayDelete(filters
);
2672 job
->current_file
++;
2674 if (job
->current_file
== job
->num_files
)
2675 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2682 * Add port monitor, if any...
2685 if (printer
->port_monitor
)
2688 * Add port monitor to the end of the list...
2692 filters
= cupsArrayNew(NULL
, NULL
);
2694 if (!cupsArrayAdd(filters
, &port_monitor
))
2696 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to add port monitor - %s",
2699 cupsArrayDelete(filters
);
2701 job
->current_file
++;
2703 if (job
->current_file
== job
->num_files
)
2704 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2709 snprintf(port_monitor
.filter
, sizeof(port_monitor
.filter
),
2710 "%s/monitor/%s", ServerBin
, printer
->port_monitor
);
2714 * Update the printer and job state to "processing"...
2717 job
->state
->values
[0].integer
= IPP_JOB_PROCESSING
;
2718 job
->state_value
= IPP_JOB_PROCESSING
;
2720 job
->printer
= printer
;
2722 cupsdSetPrinterState(printer
, IPP_PRINTER_PROCESSING
, 0);
2724 if (job
->current_file
== 0)
2727 * Set the processing time...
2730 set_time(job
, "time-at-processing");
2733 * Create the backchannel pipes and make them non-blocking...
2736 cupsdOpenPipe(job
->back_pipes
);
2738 fcntl(job
->back_pipes
[0], F_SETFL
,
2739 fcntl(job
->back_pipes
[0], F_GETFL
) | O_NONBLOCK
);
2741 fcntl(job
->back_pipes
[1], F_SETFL
,
2742 fcntl(job
->back_pipes
[1], F_GETFL
) | O_NONBLOCK
);
2745 * Create the side-channel pipes and make them non-blocking...
2748 socketpair(AF_LOCAL
, SOCK_STREAM
, 0, job
->side_pipes
);
2750 fcntl(job
->side_pipes
[0], F_SETFL
,
2751 fcntl(job
->side_pipes
[0], F_GETFL
) | O_NONBLOCK
);
2753 fcntl(job
->side_pipes
[1], F_SETFL
,
2754 fcntl(job
->side_pipes
[1], F_GETFL
) | O_NONBLOCK
);
2758 * Determine if we are printing a banner page or not...
2761 if (job
->job_sheets
== NULL
)
2763 cupsdLogMessage(CUPSD_LOG_DEBUG
, "No job-sheets attribute.");
2764 if ((job
->job_sheets
=
2765 ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_ZERO
)) != NULL
)
2766 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2767 "... but someone added one without setting job_sheets!");
2769 else if (job
->job_sheets
->num_values
== 1)
2770 cupsdLogMessage(CUPSD_LOG_DEBUG
, "job-sheets=%s",
2771 job
->job_sheets
->values
[0].string
.text
);
2773 cupsdLogMessage(CUPSD_LOG_DEBUG
, "job-sheets=%s,%s",
2774 job
->job_sheets
->values
[0].string
.text
,
2775 job
->job_sheets
->values
[1].string
.text
);
2777 if (printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2779 else if (job
->job_sheets
== NULL
)
2781 else if (strcasecmp(job
->job_sheets
->values
[0].string
.text
, "none") != 0 &&
2782 job
->current_file
== 0)
2784 else if (job
->job_sheets
->num_values
> 1 &&
2785 strcasecmp(job
->job_sheets
->values
[1].string
.text
, "none") != 0 &&
2786 job
->current_file
== (job
->num_files
- 1))
2791 cupsdLogMessage(CUPSD_LOG_DEBUG
, "banner_page = %d", banner_page
);
2794 * Building the options string is harder than it needs to be, but
2795 * for the moment we need to pass strings for command-line args and
2796 * not IPP attribute pointers... :)
2798 * First allocate/reallocate the option buffer as needed...
2801 i
= ipp_length(job
->attrs
);
2808 optptr
= realloc(options
, i
);
2812 cupsdLogMessage(CUPSD_LOG_CRIT
,
2813 "Unable to allocate %d bytes for option buffer for "
2814 "job %d!", i
, job
->id
);
2816 cupsArrayDelete(filters
);
2818 FilterLevel
-= job
->cost
;
2820 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2829 * Now loop through the attributes and convert them to the textual
2830 * representation used by the filters...
2836 snprintf(title
, sizeof(title
), "%s-%d", printer
->name
, job
->id
);
2837 strcpy(copies
, "1");
2839 for (attr
= job
->attrs
->attrs
; attr
!= NULL
; attr
= attr
->next
)
2841 if (!strcmp(attr
->name
, "copies") &&
2842 attr
->value_tag
== IPP_TAG_INTEGER
)
2845 * Don't use the # copies attribute if we are printing the job sheets...
2849 sprintf(copies
, "%d", attr
->values
[0].integer
);
2851 else if (!strcmp(attr
->name
, "job-name") &&
2852 (attr
->value_tag
== IPP_TAG_NAME
||
2853 attr
->value_tag
== IPP_TAG_NAMELANG
))
2854 strlcpy(title
, attr
->values
[0].string
.text
, sizeof(title
));
2855 else if (attr
->group_tag
== IPP_TAG_JOB
)
2858 * Filter out other unwanted attributes...
2861 if (attr
->value_tag
== IPP_TAG_MIMETYPE
||
2862 attr
->value_tag
== IPP_TAG_NAMELANG
||
2863 attr
->value_tag
== IPP_TAG_TEXTLANG
||
2864 (attr
->value_tag
== IPP_TAG_URI
&& strcmp(attr
->name
, "job-uuid")) ||
2865 attr
->value_tag
== IPP_TAG_URISCHEME
||
2866 attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
) /* Not yet supported */
2869 if (!strncmp(attr
->name
, "time-", 5))
2872 if (!strncmp(attr
->name
, "job-", 4) && strcmp(attr
->name
, "job-uuid") &&
2873 !(printer
->type
& CUPS_PRINTER_REMOTE
))
2876 if (!strncmp(attr
->name
, "job-", 4) &&
2877 strcmp(attr
->name
, "job-uuid") &&
2878 strcmp(attr
->name
, "job-billing") &&
2879 strcmp(attr
->name
, "job-sheets") &&
2880 strcmp(attr
->name
, "job-hold-until") &&
2881 strcmp(attr
->name
, "job-priority"))
2884 if ((!strcmp(attr
->name
, "page-label") ||
2885 !strcmp(attr
->name
, "page-border") ||
2886 !strncmp(attr
->name
, "number-up", 9) ||
2887 !strcmp(attr
->name
, "page-set") ||
2888 !strcasecmp(attr
->name
, "AP_FIRSTPAGE_InputSlot") ||
2889 !strcasecmp(attr
->name
, "AP_FIRSTPAGE_ManualFeed")) &&
2894 * Otherwise add them to the list...
2897 if (optptr
> options
)
2898 strlcat(optptr
, " ", optlength
- (optptr
- options
));
2900 if (attr
->value_tag
!= IPP_TAG_BOOLEAN
)
2902 strlcat(optptr
, attr
->name
, optlength
- (optptr
- options
));
2903 strlcat(optptr
, "=", optlength
- (optptr
- options
));
2906 for (i
= 0; i
< attr
->num_values
; i
++)
2909 strlcat(optptr
, ",", optlength
- (optptr
- options
));
2911 optptr
+= strlen(optptr
);
2913 switch (attr
->value_tag
)
2915 case IPP_TAG_INTEGER
:
2917 snprintf(optptr
, optlength
- (optptr
- options
),
2918 "%d", attr
->values
[i
].integer
);
2921 case IPP_TAG_BOOLEAN
:
2922 if (!attr
->values
[i
].boolean
)
2923 strlcat(optptr
, "no", optlength
- (optptr
- options
));
2925 case IPP_TAG_NOVALUE
:
2926 strlcat(optptr
, attr
->name
,
2927 optlength
- (optptr
- options
));
2930 case IPP_TAG_RANGE
:
2931 if (attr
->values
[i
].range
.lower
== attr
->values
[i
].range
.upper
)
2932 snprintf(optptr
, optlength
- (optptr
- options
) - 1,
2933 "%d", attr
->values
[i
].range
.lower
);
2935 snprintf(optptr
, optlength
- (optptr
- options
) - 1,
2936 "%d-%d", attr
->values
[i
].range
.lower
,
2937 attr
->values
[i
].range
.upper
);
2940 case IPP_TAG_RESOLUTION
:
2941 snprintf(optptr
, optlength
- (optptr
- options
) - 1,
2942 "%dx%d%s", attr
->values
[i
].resolution
.xres
,
2943 attr
->values
[i
].resolution
.yres
,
2944 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
2948 case IPP_TAG_STRING
:
2951 case IPP_TAG_KEYWORD
:
2952 case IPP_TAG_CHARSET
:
2953 case IPP_TAG_LANGUAGE
:
2955 for (valptr
= attr
->values
[i
].string
.text
; *valptr
;)
2957 if (strchr(" \t\n\\\'\"", *valptr
))
2959 *optptr
++ = *valptr
++;
2966 break; /* anti-compiler-warning-code */
2970 optptr
+= strlen(optptr
);
2975 * Build the command-line arguments for the filters. Each filter
2976 * has 6 or 7 arguments:
2980 * argv[2] = username
2982 * argv[4] = # copies
2984 * argv[6] = filename (optional; normally stdin)
2986 * This allows legacy printer drivers that use the old System V
2987 * printing interface to be used by CUPS.
2989 * For remote jobs, we send all of the files in the argument list.
2992 if (printer
->remote
&& job
->num_files
> 1)
2993 argv
= calloc(7 + job
->num_files
, sizeof(char *));
2995 argv
= calloc(8, sizeof(char *));
2997 sprintf(jobid
, "%d", job
->id
);
2999 argv
[0] = printer
->name
;
3001 argv
[2] = job
->username
;
3006 if (printer
->remote
&& job
->num_files
> 1)
3008 for (i
= 0; i
< job
->num_files
; i
++)
3010 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
,
3012 argv
[6 + i
] = strdup(filename
);
3017 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
,
3018 job
->id
, job
->current_file
+ 1);
3022 for (i
= 0; argv
[i
]; i
++)
3023 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3024 "[Job %d] argv[%d]=\"%s\"", job
->id
, i
, argv
[i
]);
3027 * Create environment variable strings for the filters...
3030 attr
= ippFindAttribute(job
->attrs
, "attributes-natural-language",
3033 switch (strlen(attr
->values
[0].string
.text
))
3037 * This is an unknown or badly formatted language code; use
3038 * the POSIX locale...
3041 strcpy(lang
, "LANG=C");
3046 * Just the language code (ll)...
3049 snprintf(lang
, sizeof(lang
), "LANG=%s",
3050 attr
->values
[0].string
.text
);
3055 * Language and country code (ll-cc)...
3058 snprintf(lang
, sizeof(lang
), "LANG=%c%c_%c%c",
3059 attr
->values
[0].string
.text
[0],
3060 attr
->values
[0].string
.text
[1],
3061 toupper(attr
->values
[0].string
.text
[3] & 255),
3062 toupper(attr
->values
[0].string
.text
[4] & 255));
3066 attr
= ippFindAttribute(job
->attrs
, "document-format",
3069 (optptr
= strstr(attr
->values
[0].string
.text
, "charset=")) != NULL
)
3070 snprintf(charset
, sizeof(charset
), "CHARSET=%s", optptr
+ 8);
3073 attr
= ippFindAttribute(job
->attrs
, "attributes-charset",
3075 snprintf(charset
, sizeof(charset
), "CHARSET=%s",
3076 attr
->values
[0].string
.text
);
3079 snprintf(content_type
, sizeof(content_type
), "CONTENT_TYPE=%s/%s",
3080 job
->filetypes
[job
->current_file
]->super
,
3081 job
->filetypes
[job
->current_file
]->type
);
3082 snprintf(device_uri
, sizeof(device_uri
), "DEVICE_URI=%s",
3083 printer
->device_uri
);
3084 cupsdSanitizeURI(printer
->device_uri
, sani_uri
, sizeof(sani_uri
));
3085 snprintf(ppd
, sizeof(ppd
), "PPD=%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
3086 snprintf(printer_name
, sizeof(printer_name
), "PRINTER=%s", printer
->name
);
3087 snprintf(rip_max_cache
, sizeof(rip_max_cache
), "RIP_MAX_CACHE=%s", RIPCache
);
3089 envc
= cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
3091 envp
[envc
++] = charset
;
3092 envp
[envc
++] = lang
;
3093 envp
[envc
++] = ppd
;
3094 envp
[envc
++] = rip_max_cache
;
3095 envp
[envc
++] = content_type
;
3096 envp
[envc
++] = device_uri
;
3097 envp
[envc
++] = printer_name
;
3099 if (!printer
->remote
&&
3100 (filter
= (mime_filter_t
*)cupsArrayLast(filters
)) != NULL
)
3102 snprintf(final_content_type
, sizeof(final_content_type
),
3103 "FINAL_CONTENT_TYPE=%s/%s",
3104 filter
->dst
->super
, filter
->dst
->type
);
3105 envp
[envc
++] = final_content_type
;
3108 if (Classification
&& !banner_page
)
3110 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
3111 IPP_TAG_NAME
)) == NULL
)
3112 snprintf(classification
, sizeof(classification
), "CLASSIFICATION=%s",
3114 else if (attr
->num_values
> 1 &&
3115 strcmp(attr
->values
[1].string
.text
, "none") != 0)
3116 snprintf(classification
, sizeof(classification
), "CLASSIFICATION=%s",
3117 attr
->values
[1].string
.text
);
3119 snprintf(classification
, sizeof(classification
), "CLASSIFICATION=%s",
3120 attr
->values
[0].string
.text
);
3122 envp
[envc
++] = classification
;
3125 if (job
->dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
3127 snprintf(class_name
, sizeof(class_name
), "CLASS=%s", job
->dest
);
3128 envp
[envc
++] = class_name
;
3133 envp
[envc
++] = job
->ccname
;
3134 #endif /* HAVE_GSSAPI */
3138 for (i
= 0; i
< envc
; i
++)
3139 if (strncmp(envp
[i
], "DEVICE_URI=", 11))
3140 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job %d] envp[%d]=\"%s\"",
3141 job
->id
, i
, envp
[i
]);
3143 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job %d] envp[%d]=\"DEVICE_URI=%s\"",
3144 job
->id
, i
, sani_uri
);
3146 if (printer
->remote
)
3147 job
->current_file
= job
->num_files
;
3149 job
->current_file
++;
3152 * Now create processes for all of the filters...
3155 filterfds
[0][0] = -1;
3156 filterfds
[0][1] = -1;
3157 filterfds
[1][0] = -1;
3158 filterfds
[1][1] = -1;
3160 if (!job
->status_buffer
)
3162 if (cupsdOpenPipe(job
->status_pipes
))
3164 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create job status pipes - %s.",
3166 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3167 "Unable to create status pipes - %s.", strerror(errno
));
3169 cupsdAddPrinterHistory(printer
);
3171 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3172 "Job canceled because the server could not create the job "
3178 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_job: status_pipes = [ %d %d ]",
3179 job
->status_pipes
[0], job
->status_pipes
[1]);
3181 job
->status_buffer
= cupsdStatBufNew(job
->status_pipes
[0], "[Job %d]",
3186 memset(job
->filters
, 0, sizeof(job
->filters
));
3188 for (i
= 0, slot
= 0, filter
= (mime_filter_t
*)cupsArrayFirst(filters
);
3190 i
++, filter
= (mime_filter_t
*)cupsArrayNext(filters
))
3192 if (filter
->filter
[0] != '/')
3193 snprintf(command
, sizeof(command
), "%s/filter/%s", ServerBin
,
3196 strlcpy(command
, filter
->filter
, sizeof(command
));
3198 if (i
< (cupsArrayCount(filters
) - 1))
3200 if (cupsdOpenPipe(filterfds
[slot
]))
3202 cupsdLogMessage(CUPSD_LOG_ERROR
,
3203 "Unable to create job filter pipes - %s.",
3205 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3206 "Unable to create filter pipes - %s.", strerror(errno
));
3207 cupsdAddPrinterHistory(printer
);
3209 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3210 "Job canceled because the server could not create the "
3218 if (job
->current_file
== 1)
3220 if (strncmp(printer
->device_uri
, "file:", 5) != 0)
3222 if (cupsdOpenPipe(job
->print_pipes
))
3224 cupsdLogMessage(CUPSD_LOG_ERROR
,
3225 "Unable to create job backend pipes - %s.",
3227 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3228 "Unable to create backend pipes - %s.", strerror(errno
));
3229 cupsdAddPrinterHistory(printer
);
3231 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3232 "Job canceled because the server could not create "
3233 "the backend pipes.");
3240 job
->print_pipes
[0] = -1;
3241 if (!strcmp(printer
->device_uri
, "file:/dev/null") ||
3242 !strcmp(printer
->device_uri
, "file:///dev/null"))
3243 job
->print_pipes
[1] = -1;
3246 if (!strncmp(printer
->device_uri
, "file:/dev/", 10))
3247 job
->print_pipes
[1] = open(printer
->device_uri
+ 5,
3249 else if (!strncmp(printer
->device_uri
, "file:///dev/", 12))
3250 job
->print_pipes
[1] = open(printer
->device_uri
+ 7,
3252 else if (!strncmp(printer
->device_uri
, "file:///", 8))
3253 job
->print_pipes
[1] = open(printer
->device_uri
+ 7,
3254 O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
3256 job
->print_pipes
[1] = open(printer
->device_uri
+ 5,
3257 O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
3259 if (job
->print_pipes
[1] < 0)
3261 cupsdLogMessage(CUPSD_LOG_ERROR
,
3262 "Unable to open output file \"%s\" - %s.",
3263 printer
->device_uri
, strerror(errno
));
3264 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3265 "Unable to open output file \"%s\" - %s.",
3266 printer
->device_uri
, strerror(errno
));
3268 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3269 "Job canceled because the server could not open the "
3275 fcntl(job
->print_pipes
[1], F_SETFD
,
3276 fcntl(job
->print_pipes
[1], F_GETFD
) | FD_CLOEXEC
);
3280 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3281 "start_job: print_pipes = [ %d %d ]",
3282 job
->print_pipes
[0], job
->print_pipes
[1]);
3285 filterfds
[slot
][0] = job
->print_pipes
[0];
3286 filterfds
[slot
][1] = job
->print_pipes
[1];
3289 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_job: filter=\"%s\"",
3291 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3292 "start_job: filterfds[%d]=[ %d %d ]",
3293 slot
, filterfds
[slot
][0], filterfds
[slot
][1]);
3295 pid
= cupsdStartProcess(command
, argv
, envp
, filterfds
[!slot
][0],
3296 filterfds
[slot
][1], job
->status_pipes
[1],
3297 job
->back_pipes
[0], job
->side_pipes
[0], 0,
3300 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3301 "start_job: Closing filter pipes for slot %d "
3303 !slot
, filterfds
[!slot
][0], filterfds
[!slot
][1]);
3305 cupsdClosePipe(filterfds
[!slot
]);
3309 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to start filter \"%s\" - %s.",
3310 filter
->filter
, strerror(errno
));
3311 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3312 "Unable to start filter \"%s\" - %s.",
3313 filter
->filter
, strerror(errno
));
3315 cupsdAddPrinterHistory(printer
);
3317 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3318 "Job canceled because the server could not execute a "
3324 cupsdLogMessage(CUPSD_LOG_INFO
, "Started filter %s (PID %d) for job %d.",
3325 command
, pid
, job
->id
);
3331 cupsArrayDelete(filters
);
3334 * Finally, pipe the final output into a backend process if needed...
3337 if (strncmp(printer
->device_uri
, "file:", 5) != 0)
3339 if (job
->current_file
== 1)
3341 sscanf(printer
->device_uri
, "%254[^:]", method
);
3342 snprintf(command
, sizeof(command
), "%s/backend/%s", ServerBin
, method
);
3345 * See if the backend needs to run as root...
3350 else if (stat(command
, &backinfo
))
3353 backroot
= !(backinfo
.st_mode
& (S_IRWXG
| S_IRWXO
));
3357 filterfds
[slot
][0] = -1;
3358 filterfds
[slot
][1] = -1;
3360 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_job: backend=\"%s\"",
3362 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3363 "start_job: filterfds[%d] = [ %d %d ]",
3364 slot
, filterfds
[slot
][0], filterfds
[slot
][1]);
3366 pid
= cupsdStartProcess(command
, argv
, envp
, filterfds
[!slot
][0],
3367 filterfds
[slot
][1], job
->status_pipes
[1],
3368 job
->back_pipes
[1], job
->side_pipes
[1],
3369 backroot
, &(job
->backend
));
3373 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to start backend \"%s\" - %s.",
3374 method
, strerror(errno
));
3375 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3376 "Unable to start backend \"%s\" - %s.", method
,
3379 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3380 "Job canceled because the server could not execute "
3387 cupsdLogMessage(CUPSD_LOG_INFO
,
3388 "Started backend %s (PID %d) for job %d.",
3389 command
, pid
, job
->id
);
3393 if (job
->current_file
== job
->num_files
)
3395 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3396 "start_job: Closing print pipes [ %d %d ]...",
3397 job
->print_pipes
[0], job
->print_pipes
[1]);
3399 cupsdClosePipe(job
->print_pipes
);
3401 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3402 "start_job: Closing back pipes [ %d %d ]...",
3403 job
->back_pipes
[0], job
->back_pipes
[1]);
3405 cupsdClosePipe(job
->back_pipes
);
3407 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3408 "start_job: Closing side pipes [ %d %d ]...",
3409 job
->side_pipes
[0], job
->side_pipes
[1]);
3411 cupsdClosePipe(job
->side_pipes
);
3413 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3414 "start_job: Closing status output pipe %d...",
3415 job
->status_pipes
[1]);
3417 close(job
->status_pipes
[1]);
3418 job
->status_pipes
[1] = -1;
3423 filterfds
[slot
][0] = -1;
3424 filterfds
[slot
][1] = -1;
3426 if (job
->current_file
== job
->num_files
)
3428 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3429 "start_job: Closing print pipes [ %d %d ]...",
3430 job
->print_pipes
[0], job
->print_pipes
[1]);
3432 cupsdClosePipe(job
->print_pipes
);
3434 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3435 "start_job: Closing status output pipe %d...",
3436 job
->status_pipes
[1]);
3438 close(job
->status_pipes
[1]);
3439 job
->status_pipes
[1] = -1;
3443 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3444 "start_job: Closing filter pipes for slot %d "
3446 slot
, filterfds
[slot
][0], filterfds
[slot
][1]);
3447 cupsdClosePipe(filterfds
[slot
]);
3449 if (printer
->remote
&& job
->num_files
> 1)
3451 for (i
= 0; i
< job
->num_files
; i
++)
3457 cupsdAddSelect(job
->status_buffer
->fd
, (cupsd_selfunc_t
)cupsdUpdateJob
, NULL
,
3460 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
, "Job #%d started.",
3467 * If we get here, we need to abort the current job and close out all
3468 * files and pipes...
3473 for (slot
= 0; slot
< 2; slot
++)
3475 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3476 "start_job: Closing filter pipes for slot %d "
3478 slot
, filterfds
[slot
][0], filterfds
[slot
][1]);
3479 cupsdClosePipe(filterfds
[slot
]);
3482 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3483 "start_job: Closing status pipes [ %d %d ]...",
3484 job
->status_pipes
[0], job
->status_pipes
[1]);
3485 cupsdClosePipe(job
->status_pipes
);
3486 cupsdStatBufDelete(job
->status_buffer
);
3488 cupsArrayDelete(filters
);
3490 if (printer
->remote
&& job
->num_files
> 1)
3492 for (i
= 0; i
< job
->num_files
; i
++)
3498 cupsdStopJob(job
, 0);
3503 * 'unload_job()' - Unload a job from memory.
3507 unload_job(cupsd_job_t
*job
) /* I - Job */
3512 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Unloading job %d...", job
->id
);
3514 ippDelete(job
->attrs
);
3519 job
->job_sheets
= NULL
;
3524 * End of "$Id: job.c 6318 2007-03-06 04:36:55Z mike $".