2 * "$Id: job.c 6365 2007-03-19 20:56:57Z 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
)
1704 cupsd_quota_t
*q
= cupsdUpdateQuota(job
->printer
, job
->username
,
1708 if (AppleQuotas
&& q
->page_count
== -3)
1711 * Quota limit exceeded, cancel job in progress immediately...
1714 cupsdLogMessage(CUPSD_LOG_INFO
,
1715 "Job %d canceled: pages exceed user %s quota "
1716 "limit on printer %s (%s).",
1717 job
->id
, job
->username
, job
->printer
->name
,
1718 job
->printer
->info
);
1720 cupsdCancelJob(job
, 1, IPP_JOB_CANCELED
);
1723 #endif /* __APPLE__ */
1727 cupsdLogPage(job
, message
);
1729 cupsdAddEvent(CUPSD_EVENT_JOB_PROGRESS
, job
->printer
, job
,
1730 "Printed %d page(s).", job
->sheets
->values
[0].integer
);
1732 else if (loglevel
== CUPSD_LOG_STATE
)
1734 cupsdSetPrinterReasons(job
->printer
, message
);
1735 cupsdAddPrinterHistory(job
->printer
);
1736 event
|= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
1738 else if (loglevel
== CUPSD_LOG_ATTR
)
1741 * Set attribute(s)...
1744 int num_attrs
; /* Number of attributes */
1745 cups_option_t
*attrs
; /* Attributes */
1746 const char *attr
; /* Attribute */
1749 num_attrs
= cupsParseOptions(message
, 0, &attrs
);
1751 if ((attr
= cupsGetOption("auth-info-required", num_attrs
,
1753 cupsdSetAuthInfoRequired(job
->printer
, attr
, NULL
);
1755 cupsFreeOptions(num_attrs
, attrs
);
1758 else if (!strncmp(message
, "recoverable:", 12))
1760 cupsdSetPrinterReasons(job
->printer
,
1761 "+com.apple.print.recoverable-warning");
1764 while (isspace(*ptr
& 255))
1767 cupsdSetString(&job
->printer
->recoverable
, ptr
);
1768 cupsdAddPrinterHistory(job
->printer
);
1769 event
|= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
1771 else if (!strncmp(message
, "recovered:", 10))
1773 cupsdSetPrinterReasons(job
->printer
,
1774 "-com.apple.print.recoverable-warning");
1777 while (isspace(*ptr
& 255))
1780 cupsdSetString(&job
->printer
->recoverable
, ptr
);
1781 cupsdAddPrinterHistory(job
->printer
);
1782 event
|= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
1784 #endif /* __APPLE__ */
1785 else if (loglevel
<= CUPSD_LOG_INFO
)
1788 * Some message to show in the printer-state-message attribute...
1791 strlcpy(job
->printer
->state_message
, message
,
1792 sizeof(job
->printer
->state_message
));
1793 cupsdAddPrinterHistory(job
->printer
);
1794 event
|= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
1797 if (!strchr(job
->status_buffer
->buffer
, '\n'))
1801 if ((event
& CUPSD_EVENT_PRINTER_STATE_CHANGED
))
1802 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED
, job
->printer
, NULL
,
1803 (job
->printer
->type
& CUPS_PRINTER_CLASS
) ?
1804 "Class \"%s\" state changed." :
1805 "Printer \"%s\" state changed.",
1806 job
->printer
->name
);
1808 if (ptr
== NULL
&& !job
->status_buffer
->bufused
)
1811 * See if all of the filters and the backend have returned their
1815 for (i
= 0; job
->filters
[i
] < 0; i
++);
1817 if (job
->filters
[i
])
1820 if (job
->current_file
>= job
->num_files
&& job
->backend
> 0)
1824 * Handle the end of job stuff...
1827 cupsdFinishJob(job
);
1833 * 'compare_active_jobs()' - Compare the job IDs and priorities of two jobs.
1836 static int /* O - Difference */
1837 compare_active_jobs(void *first
, /* I - First job */
1838 void *second
, /* I - Second job */
1839 void *data
) /* I - App data (not used) */
1841 int diff
; /* Difference */
1844 if ((diff
= ((cupsd_job_t
*)second
)->priority
-
1845 ((cupsd_job_t
*)first
)->priority
) != 0)
1848 return (((cupsd_job_t
*)first
)->id
- ((cupsd_job_t
*)second
)->id
);
1853 * 'compare_jobs()' - Compare the job IDs of two jobs.
1856 static int /* O - Difference */
1857 compare_jobs(void *first
, /* I - First job */
1858 void *second
, /* I - Second job */
1859 void *data
) /* I - App data (not used) */
1861 return (((cupsd_job_t
*)first
)->id
- ((cupsd_job_t
*)second
)->id
);
1866 * 'free_job()' - Free all memory used by a job.
1870 free_job(cupsd_job_t
*job
) /* I - Job */
1872 cupsdClearString(&job
->username
);
1873 cupsdClearString(&job
->dest
);
1875 cupsdClearString(&job
->ccname
);
1876 #endif /* HAVE_GSSAPI */
1878 if (job
->num_files
> 0)
1880 free(job
->compressions
);
1881 free(job
->filetypes
);
1884 ippDelete(job
->attrs
);
1891 * 'ipp_length()' - Compute the size of the buffer needed to hold
1892 * the textual IPP attributes.
1895 static int /* O - Size of attribute buffer */
1896 ipp_length(ipp_t
*ipp
) /* I - IPP request */
1898 int bytes
; /* Number of bytes */
1899 int i
; /* Looping var */
1900 ipp_attribute_t
*attr
; /* Current attribute */
1904 * Loop through all attributes...
1909 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1912 * Skip attributes that won't be sent to filters...
1915 if (attr
->value_tag
== IPP_TAG_MIMETYPE
||
1916 attr
->value_tag
== IPP_TAG_NAMELANG
||
1917 attr
->value_tag
== IPP_TAG_TEXTLANG
||
1918 attr
->value_tag
== IPP_TAG_URI
||
1919 attr
->value_tag
== IPP_TAG_URISCHEME
)
1922 if (strncmp(attr
->name
, "time-", 5) == 0)
1926 * Add space for a leading space and commas between each value.
1927 * For the first attribute, the leading space isn't used, so the
1928 * extra byte can be used as the nul terminator...
1931 bytes
++; /* " " separator */
1932 bytes
+= attr
->num_values
; /* "," separators */
1935 * Boolean attributes appear as "foo,nofoo,foo,nofoo", while
1936 * other attributes appear as "foo=value1,value2,...,valueN".
1939 if (attr
->value_tag
!= IPP_TAG_BOOLEAN
)
1940 bytes
+= strlen(attr
->name
);
1942 bytes
+= attr
->num_values
* strlen(attr
->name
);
1945 * Now add the size required for each value in the attribute...
1948 switch (attr
->value_tag
)
1950 case IPP_TAG_INTEGER
:
1953 * Minimum value of a signed integer is -2147483647, or 11 digits.
1956 bytes
+= attr
->num_values
* 11;
1959 case IPP_TAG_BOOLEAN
:
1961 * Add two bytes for each false ("no") value...
1964 for (i
= 0; i
< attr
->num_values
; i
++)
1965 if (!attr
->values
[i
].boolean
)
1969 case IPP_TAG_RANGE
:
1971 * A range is two signed integers separated by a hyphen, or
1972 * 23 characters max.
1975 bytes
+= attr
->num_values
* 23;
1978 case IPP_TAG_RESOLUTION
:
1980 * A resolution is two signed integers separated by an "x" and
1981 * suffixed by the units, or 26 characters max.
1984 bytes
+= attr
->num_values
* 26;
1987 case IPP_TAG_STRING
:
1990 case IPP_TAG_KEYWORD
:
1991 case IPP_TAG_CHARSET
:
1992 case IPP_TAG_LANGUAGE
:
1995 * Strings can contain characters that need quoting. We need
1996 * at least 2 * len + 2 characters to cover the quotes and
1997 * any backslashes in the string.
2000 for (i
= 0; i
< attr
->num_values
; i
++)
2001 bytes
+= 2 * strlen(attr
->values
[i
].string
.text
) + 2;
2005 break; /* anti-compiler-warning-code */
2014 * 'load_job_cache()' - Load jobs from the job.cache file.
2018 load_job_cache(const char *filename
) /* I - job.cache filename */
2020 cups_file_t
*fp
; /* job.cache file */
2021 char line
[1024], /* Line buffer */
2022 *value
; /* Value on line */
2023 int linenum
; /* Line number in file */
2024 cupsd_job_t
*job
; /* Current job */
2025 int jobid
; /* Job ID */
2026 char jobfile
[1024]; /* Job filename */
2030 * Open the job.cache file...
2033 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
2035 if (errno
!= ENOENT
)
2036 cupsdLogMessage(CUPSD_LOG_ERROR
,
2037 "Unable to open job cache file \"%s\": %s",
2038 filename
, strerror(errno
));
2040 load_request_root();
2046 * Read entries from the job cache file and create jobs as needed.
2049 cupsdLogMessage(CUPSD_LOG_INFO
, "Loading job cache file \"%s\"...",
2055 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2057 if (!strcasecmp(line
, "NextJobId"))
2060 NextJobId
= atoi(value
);
2062 else if (!strcasecmp(line
, "<Job"))
2066 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing </Job> directive on line %d!",
2073 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing job ID on line %d!", linenum
);
2077 jobid
= atoi(value
);
2081 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad job ID %d on line %d!", jobid
,
2086 snprintf(jobfile
, sizeof(jobfile
), "%s/c%05d", RequestRoot
, jobid
);
2087 if (access(jobfile
, 0))
2089 cupsdLogMessage(CUPSD_LOG_ERROR
, "Job %d files have gone away!", jobid
);
2093 job
= calloc(1, sizeof(cupsd_job_t
));
2096 cupsdLogMessage(CUPSD_LOG_EMERG
,
2097 "Unable to allocate memory for job %d!", jobid
);
2102 job
->back_pipes
[0] = -1;
2103 job
->back_pipes
[1] = -1;
2104 job
->print_pipes
[0] = -1;
2105 job
->print_pipes
[1] = -1;
2106 job
->side_pipes
[0] = -1;
2107 job
->side_pipes
[1] = -1;
2108 job
->status_pipes
[0] = -1;
2109 job
->status_pipes
[1] = -1;
2111 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading job %d from cache...", job
->id
);
2115 cupsdLogMessage(CUPSD_LOG_ERROR
,
2116 "Missing <Job #> directive on line %d!", linenum
);
2119 else if (!strcasecmp(line
, "</Job>"))
2121 cupsArrayAdd(Jobs
, job
);
2123 if (job
->state_value
<= IPP_JOB_STOPPED
)
2125 cupsArrayAdd(ActiveJobs
, job
);
2133 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d!", linenum
);
2136 else if (!strcasecmp(line
, "State"))
2138 job
->state_value
= (ipp_jstate_t
)atoi(value
);
2140 if (job
->state_value
< IPP_JOB_PENDING
)
2141 job
->state_value
= IPP_JOB_PENDING
;
2142 else if (job
->state_value
> IPP_JOB_COMPLETED
)
2143 job
->state_value
= IPP_JOB_COMPLETED
;
2145 else if (!strcasecmp(line
, "Priority"))
2147 job
->priority
= atoi(value
);
2149 else if (!strcasecmp(line
, "Username"))
2151 cupsdSetString(&job
->username
, value
);
2153 else if (!strcasecmp(line
, "Destination"))
2155 cupsdSetString(&job
->dest
, value
);
2157 else if (!strcasecmp(line
, "DestType"))
2159 job
->dtype
= (cups_ptype_t
)atoi(value
);
2161 else if (!strcasecmp(line
, "NumFiles"))
2163 job
->num_files
= atoi(value
);
2165 if (job
->num_files
< 0)
2167 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad NumFiles value %d on line %d!",
2168 job
->num_files
, linenum
);
2173 if (job
->num_files
> 0)
2175 snprintf(jobfile
, sizeof(jobfile
), "%s/d%05d-001", RequestRoot
,
2177 if (access(jobfile
, 0))
2179 cupsdLogMessage(CUPSD_LOG_INFO
,
2180 "Data files for job %d have gone away!", job
->id
);
2185 job
->filetypes
= calloc(job
->num_files
, sizeof(mime_type_t
*));
2186 job
->compressions
= calloc(job
->num_files
, sizeof(int));
2188 if (!job
->filetypes
|| !job
->compressions
)
2190 cupsdLogMessage(CUPSD_LOG_EMERG
,
2191 "Unable to allocate memory for %d files!",
2197 else if (!strcasecmp(line
, "File"))
2199 int number
, /* File number */
2200 compression
; /* Compression value */
2201 char super
[MIME_MAX_SUPER
], /* MIME super type */
2202 type
[MIME_MAX_TYPE
]; /* MIME type */
2205 if (sscanf(value
, "%d%*[ \t]%15[^/]/%255s%d", &number
, super
, type
,
2208 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad File on line %d!", linenum
);
2212 if (number
< 1 || number
> job
->num_files
)
2214 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad File number %d on line %d!",
2221 job
->compressions
[number
] = compression
;
2222 job
->filetypes
[number
] = mimeType(MimeDatabase
, super
, type
);
2224 if (!job
->filetypes
[number
])
2227 * If the original MIME type is unknown, auto-type it!
2230 cupsdLogMessage(CUPSD_LOG_ERROR
,
2231 "Unknown MIME type %s/%s for file %d of job %d!",
2232 super
, type
, number
+ 1, job
->id
);
2234 snprintf(jobfile
, sizeof(jobfile
), "%s/d%05d-%03d", RequestRoot
,
2235 job
->id
, number
+ 1);
2236 job
->filetypes
[number
] = mimeFileType(MimeDatabase
, jobfile
, NULL
,
2237 job
->compressions
+ number
);
2240 * If that didn't work, assume it is raw...
2243 if (!job
->filetypes
[number
])
2244 job
->filetypes
[number
] = mimeType(MimeDatabase
, "application",
2249 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown %s directive on line %d!",
2258 * 'load_next_job_id()' - Load the NextJobId value from the job.cache file.
2262 load_next_job_id(const char *filename
) /* I - job.cache filename */
2264 cups_file_t
*fp
; /* job.cache file */
2265 char line
[1024], /* Line buffer */
2266 *value
; /* Value on line */
2267 int linenum
; /* Line number in file */
2268 int next_job_id
; /* NextJobId value from line */
2272 * Read the NextJobId directive from the job.cache file and use
2273 * the value (if any).
2276 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
2278 if (errno
!= ENOENT
)
2279 cupsdLogMessage(CUPSD_LOG_ERROR
,
2280 "Unable to open job cache file \"%s\": %s",
2281 filename
, strerror(errno
));
2286 cupsdLogMessage(CUPSD_LOG_INFO
,
2287 "Loading NextJobId from job cache file \"%s\"...", filename
);
2291 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2293 if (!strcasecmp(line
, "NextJobId"))
2297 next_job_id
= atoi(value
);
2299 if (next_job_id
> NextJobId
)
2300 NextJobId
= next_job_id
;
2311 * 'load_request_root()' - Load jobs from the RequestRoot directory.
2315 load_request_root(void)
2317 cups_dir_t
*dir
; /* Directory */
2318 cups_dentry_t
*dent
; /* Directory entry */
2319 cupsd_job_t
*job
; /* New job */
2323 * Open the requests directory...
2326 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Scanning %s for jobs...", RequestRoot
);
2328 if ((dir
= cupsDirOpen(RequestRoot
)) == NULL
)
2330 cupsdLogMessage(CUPSD_LOG_ERROR
,
2331 "Unable to open spool directory \"%s\": %s",
2332 RequestRoot
, strerror(errno
));
2337 * Read all the c##### files...
2340 while ((dent
= cupsDirRead(dir
)) != NULL
)
2341 if (strlen(dent
->filename
) >= 6 && dent
->filename
[0] == 'c')
2344 * Allocate memory for the job...
2347 if ((job
= calloc(sizeof(cupsd_job_t
), 1)) == NULL
)
2349 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ran out of memory for jobs!");
2355 * Assign the job ID...
2358 job
->id
= atoi(dent
->filename
+ 1);
2359 job
->back_pipes
[0] = -1;
2360 job
->back_pipes
[1] = -1;
2361 job
->print_pipes
[0] = -1;
2362 job
->print_pipes
[1] = -1;
2363 job
->side_pipes
[0] = -1;
2364 job
->side_pipes
[1] = -1;
2365 job
->status_pipes
[0] = -1;
2366 job
->status_pipes
[1] = -1;
2368 if (job
->id
>= NextJobId
)
2369 NextJobId
= job
->id
+ 1;
2378 * Insert the job into the array, sorting by job priority and ID...
2381 cupsArrayAdd(Jobs
, job
);
2383 if (job
->state_value
<= IPP_JOB_STOPPED
)
2384 cupsArrayAdd(ActiveJobs
, job
);
2394 * 'set_time()' - Set one of the "time-at-xyz" attributes...
2398 set_time(cupsd_job_t
*job
, /* I - Job to update */
2399 const char *name
) /* I - Name of attribute */
2401 ipp_attribute_t
*attr
; /* Time attribute */
2404 if ((attr
= ippFindAttribute(job
->attrs
, name
, IPP_TAG_ZERO
)) != NULL
)
2406 attr
->value_tag
= IPP_TAG_INTEGER
;
2407 attr
->values
[0].integer
= time(NULL
);
2413 * 'set_hold_until()' - Set the hold time and update job-hold-until attribute...
2417 set_hold_until(cupsd_job_t
*job
, /* I - Job to update */
2418 time_t holdtime
) /* I - Hold until time */
2420 ipp_attribute_t
*attr
; /* job-hold-until attribute */
2421 struct tm
*holddate
; /* Hold date */
2422 char holdstr
[64]; /* Hold time */
2426 * Set the hold_until value and hold the job...
2429 cupsdLogMessage(CUPSD_LOG_DEBUG
, "set_hold_until: hold_until = %d",
2432 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
2433 job
->state_value
= IPP_JOB_HELD
;
2434 job
->hold_until
= holdtime
;
2437 * Update the job-hold-until attribute with a string representing GMT
2438 * time (HH:MM:SS)...
2441 holddate
= gmtime(&holdtime
);
2442 snprintf(holdstr
, sizeof(holdstr
), "%d:%d:%d", holddate
->tm_hour
,
2443 holddate
->tm_min
, holddate
->tm_sec
);
2445 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
2446 IPP_TAG_KEYWORD
)) == NULL
)
2447 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
2450 * Either add the attribute or update the value of the existing one
2454 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2455 "job-hold-until", NULL
, holdstr
);
2457 cupsdSetString(&attr
->values
[0].string
.text
, holdstr
);
2464 * 'start_job()' - Start a print job.
2468 start_job(cupsd_job_t
*job
, /* I - Job ID */
2469 cupsd_printer_t
*printer
) /* I - Printer to print job */
2471 int i
; /* Looping var */
2472 int slot
; /* Pipe slot */
2473 cups_array_t
*filters
, /* Filters for job */
2474 *prefilters
; /* Filters with prefilters */
2475 mime_filter_t
*filter
, /* Current filter */
2476 *prefilter
, /* Prefilter */
2477 port_monitor
; /* Port monitor filter */
2478 char method
[255], /* Method for output */
2479 *optptr
, /* Pointer to options */
2480 *valptr
; /* Pointer in value string */
2481 ipp_attribute_t
*attr
; /* Current attribute */
2482 struct stat backinfo
; /* Backend file information */
2483 int backroot
; /* Run backend as root? */
2484 int pid
; /* Process ID of new filter process */
2485 int banner_page
; /* 1 if banner page, 0 otherwise */
2486 int filterfds
[2][2];/* Pipes used between filters */
2487 int envc
; /* Number of environment variables */
2488 char **argv
, /* Filter command-line arguments */
2489 sani_uri
[1024], /* Sanitized DEVICE_URI env var */
2490 filename
[1024], /* Job filename */
2491 command
[1024], /* Full path to command */
2492 jobid
[255], /* Job ID string */
2493 title
[IPP_MAX_NAME
],
2494 /* Job title string */
2495 copies
[255], /* # copies string */
2496 *envp
[MAX_ENV
+ 12],
2497 /* Environment variables */
2498 charset
[255], /* CHARSET env variable */
2499 class_name
[255],/* CLASS env variable */
2500 classification
[1024],
2501 /* CLASSIFICATION env variable */
2503 /* CONTENT_TYPE env variable */
2505 /* DEVICE_URI env variable */
2506 final_content_type
[1024],
2507 /* FINAL_CONTENT_TYPE env variable */
2508 lang
[255], /* LANG env variable */
2509 ppd
[1024], /* PPD env variable */
2511 /* PRINTER env variable */
2513 /* RIP_MAX_CACHE env variable */
2514 static char *options
= NULL
;/* Full list of options */
2515 static int optlength
= 0; /* Length of option buffer */
2518 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_job: id = %d, file = %d/%d",
2519 job
->id
, job
->current_file
, job
->num_files
);
2521 if (job
->num_files
== 0)
2523 cupsdLogMessage(CUPSD_LOG_ERROR
, "Job ID %d has no files! Canceling it!",
2526 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2530 if (printer
->raw
&& !strncmp(printer
->device_uri
, "file:", 5))
2532 cupsdLogMessage(CUPSD_LOG_ERROR
,
2533 "Job ID %d cannot be printed to raw queue pointing to "
2537 strlcpy(printer
->state_message
, "Raw printers cannot use file: devices!",
2538 sizeof(printer
->state_message
));
2539 cupsdStopPrinter(printer
, 1);
2540 cupsdAddPrinterHistory(printer
);
2545 * Figure out what filters are required to convert from
2546 * the source to the destination type...
2555 * Remote jobs and raw queues go directly to the printer without
2559 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2560 "[Job %d] Sending job to queue tagged as raw...", job
->id
);
2567 * Local jobs get filtered...
2570 filters
= mimeFilter(MimeDatabase
, job
->filetypes
[job
->current_file
],
2571 printer
->filetype
, &(job
->cost
));
2575 cupsdLogMessage(CUPSD_LOG_ERROR
,
2576 "Unable to convert file %d to printable format for "
2578 job
->current_file
, job
->id
);
2579 cupsdLogMessage(CUPSD_LOG_INFO
,
2580 "Hint: Do you have ESP Ghostscript installed?");
2582 if (LogLevel
< CUPSD_LOG_DEBUG
)
2583 cupsdLogMessage(CUPSD_LOG_INFO
,
2584 "Hint: Try setting the LogLevel to \"debug\".");
2586 job
->current_file
++;
2588 if (job
->current_file
== job
->num_files
)
2589 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2595 * Remove NULL ("-") filters...
2598 for (filter
= (mime_filter_t
*)cupsArrayFirst(filters
);
2600 filter
= (mime_filter_t
*)cupsArrayNext(filters
))
2601 if (!strcmp(filter
->filter
, "-"))
2602 cupsArrayRemove(filters
, filter
);
2604 if (cupsArrayCount(filters
) == 0)
2606 cupsArrayDelete(filters
);
2611 * If this printer has any pre-filters, insert the required pre-filter
2612 * in the filters array...
2615 if (printer
->prefiltertype
&& filters
)
2617 prefilters
= cupsArrayNew(NULL
, NULL
);
2619 for (filter
= (mime_filter_t
*)cupsArrayFirst(filters
);
2621 filter
= (mime_filter_t
*)cupsArrayNext(filters
))
2623 if ((prefilter
= mimeFilterLookup(MimeDatabase
, filter
->src
,
2624 printer
->prefiltertype
)))
2626 cupsArrayAdd(prefilters
, prefilter
);
2627 job
->cost
+= prefilter
->cost
;
2630 cupsArrayAdd(prefilters
, filter
);
2633 cupsArrayDelete(filters
);
2634 filters
= prefilters
;
2639 * Set a minimum cost of 100 for all jobs so that FilterLimit
2640 * works with raw queues and other low-cost paths.
2643 if (job
->cost
< 100)
2647 * See if the filter cost is too high...
2650 if ((FilterLevel
+ job
->cost
) > FilterLimit
&& FilterLevel
> 0 &&
2654 * Don't print this job quite yet...
2657 cupsArrayDelete(filters
);
2659 cupsdLogMessage(CUPSD_LOG_INFO
,
2660 "Holding job %d because filter limit has been reached.",
2662 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2663 "start_job: id=%d, file=%d, cost=%d, level=%d, "
2665 job
->id
, job
->current_file
, job
->cost
, FilterLevel
,
2670 FilterLevel
+= job
->cost
;
2673 * Add decompression filters, if any...
2676 if (!printer
->raw
&& job
->compressions
[job
->current_file
])
2679 * Add gziptoany filter to the front of the list...
2683 filters
= cupsArrayNew(NULL
, NULL
);
2685 if (!cupsArrayInsert(filters
, &gziptoany_filter
))
2687 cupsdLogMessage(CUPSD_LOG_ERROR
,
2688 "Unable to add decompression filter - %s",
2691 cupsArrayDelete(filters
);
2693 job
->current_file
++;
2695 if (job
->current_file
== job
->num_files
)
2696 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2703 * Add port monitor, if any...
2706 if (printer
->port_monitor
)
2709 * Add port monitor to the end of the list...
2713 filters
= cupsArrayNew(NULL
, NULL
);
2715 if (!cupsArrayAdd(filters
, &port_monitor
))
2717 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to add port monitor - %s",
2720 cupsArrayDelete(filters
);
2722 job
->current_file
++;
2724 if (job
->current_file
== job
->num_files
)
2725 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2730 snprintf(port_monitor
.filter
, sizeof(port_monitor
.filter
),
2731 "%s/monitor/%s", ServerBin
, printer
->port_monitor
);
2735 * Update the printer and job state to "processing"...
2738 job
->state
->values
[0].integer
= IPP_JOB_PROCESSING
;
2739 job
->state_value
= IPP_JOB_PROCESSING
;
2741 job
->printer
= printer
;
2743 cupsdSetPrinterState(printer
, IPP_PRINTER_PROCESSING
, 0);
2745 if (job
->current_file
== 0)
2748 * Set the processing time...
2751 set_time(job
, "time-at-processing");
2754 * Create the backchannel pipes and make them non-blocking...
2757 cupsdOpenPipe(job
->back_pipes
);
2759 fcntl(job
->back_pipes
[0], F_SETFL
,
2760 fcntl(job
->back_pipes
[0], F_GETFL
) | O_NONBLOCK
);
2762 fcntl(job
->back_pipes
[1], F_SETFL
,
2763 fcntl(job
->back_pipes
[1], F_GETFL
) | O_NONBLOCK
);
2766 * Create the side-channel pipes and make them non-blocking...
2769 socketpair(AF_LOCAL
, SOCK_STREAM
, 0, job
->side_pipes
);
2771 fcntl(job
->side_pipes
[0], F_SETFL
,
2772 fcntl(job
->side_pipes
[0], F_GETFL
) | O_NONBLOCK
);
2774 fcntl(job
->side_pipes
[1], F_SETFL
,
2775 fcntl(job
->side_pipes
[1], F_GETFL
) | O_NONBLOCK
);
2779 * Determine if we are printing a banner page or not...
2782 if (job
->job_sheets
== NULL
)
2784 cupsdLogMessage(CUPSD_LOG_DEBUG
, "No job-sheets attribute.");
2785 if ((job
->job_sheets
=
2786 ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_ZERO
)) != NULL
)
2787 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2788 "... but someone added one without setting job_sheets!");
2790 else if (job
->job_sheets
->num_values
== 1)
2791 cupsdLogMessage(CUPSD_LOG_DEBUG
, "job-sheets=%s",
2792 job
->job_sheets
->values
[0].string
.text
);
2794 cupsdLogMessage(CUPSD_LOG_DEBUG
, "job-sheets=%s,%s",
2795 job
->job_sheets
->values
[0].string
.text
,
2796 job
->job_sheets
->values
[1].string
.text
);
2798 if (printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2800 else if (job
->job_sheets
== NULL
)
2802 else if (strcasecmp(job
->job_sheets
->values
[0].string
.text
, "none") != 0 &&
2803 job
->current_file
== 0)
2805 else if (job
->job_sheets
->num_values
> 1 &&
2806 strcasecmp(job
->job_sheets
->values
[1].string
.text
, "none") != 0 &&
2807 job
->current_file
== (job
->num_files
- 1))
2812 cupsdLogMessage(CUPSD_LOG_DEBUG
, "banner_page = %d", banner_page
);
2815 * Building the options string is harder than it needs to be, but
2816 * for the moment we need to pass strings for command-line args and
2817 * not IPP attribute pointers... :)
2819 * First allocate/reallocate the option buffer as needed...
2822 i
= ipp_length(job
->attrs
);
2829 optptr
= realloc(options
, i
);
2833 cupsdLogMessage(CUPSD_LOG_CRIT
,
2834 "Unable to allocate %d bytes for option buffer for "
2835 "job %d!", i
, job
->id
);
2837 cupsArrayDelete(filters
);
2839 FilterLevel
-= job
->cost
;
2841 cupsdCancelJob(job
, 0, IPP_JOB_ABORTED
);
2850 * Now loop through the attributes and convert them to the textual
2851 * representation used by the filters...
2857 snprintf(title
, sizeof(title
), "%s-%d", printer
->name
, job
->id
);
2858 strcpy(copies
, "1");
2860 for (attr
= job
->attrs
->attrs
; attr
!= NULL
; attr
= attr
->next
)
2862 if (!strcmp(attr
->name
, "copies") &&
2863 attr
->value_tag
== IPP_TAG_INTEGER
)
2866 * Don't use the # copies attribute if we are printing the job sheets...
2870 sprintf(copies
, "%d", attr
->values
[0].integer
);
2872 else if (!strcmp(attr
->name
, "job-name") &&
2873 (attr
->value_tag
== IPP_TAG_NAME
||
2874 attr
->value_tag
== IPP_TAG_NAMELANG
))
2875 strlcpy(title
, attr
->values
[0].string
.text
, sizeof(title
));
2876 else if (attr
->group_tag
== IPP_TAG_JOB
)
2879 * Filter out other unwanted attributes...
2882 if (attr
->value_tag
== IPP_TAG_MIMETYPE
||
2883 attr
->value_tag
== IPP_TAG_NAMELANG
||
2884 attr
->value_tag
== IPP_TAG_TEXTLANG
||
2885 (attr
->value_tag
== IPP_TAG_URI
&& strcmp(attr
->name
, "job-uuid")) ||
2886 attr
->value_tag
== IPP_TAG_URISCHEME
||
2887 attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
) /* Not yet supported */
2890 if (!strncmp(attr
->name
, "time-", 5))
2893 if (!strncmp(attr
->name
, "job-", 4) && strcmp(attr
->name
, "job-uuid") &&
2894 !(printer
->type
& CUPS_PRINTER_REMOTE
))
2897 if (!strncmp(attr
->name
, "job-", 4) &&
2898 strcmp(attr
->name
, "job-uuid") &&
2899 strcmp(attr
->name
, "job-billing") &&
2900 strcmp(attr
->name
, "job-sheets") &&
2901 strcmp(attr
->name
, "job-hold-until") &&
2902 strcmp(attr
->name
, "job-priority"))
2905 if ((!strcmp(attr
->name
, "page-label") ||
2906 !strcmp(attr
->name
, "page-border") ||
2907 !strncmp(attr
->name
, "number-up", 9) ||
2908 !strcmp(attr
->name
, "page-set") ||
2909 !strcasecmp(attr
->name
, "AP_FIRSTPAGE_InputSlot") ||
2910 !strcasecmp(attr
->name
, "AP_FIRSTPAGE_ManualFeed")) &&
2915 * Otherwise add them to the list...
2918 if (optptr
> options
)
2919 strlcat(optptr
, " ", optlength
- (optptr
- options
));
2921 if (attr
->value_tag
!= IPP_TAG_BOOLEAN
)
2923 strlcat(optptr
, attr
->name
, optlength
- (optptr
- options
));
2924 strlcat(optptr
, "=", optlength
- (optptr
- options
));
2927 for (i
= 0; i
< attr
->num_values
; i
++)
2930 strlcat(optptr
, ",", optlength
- (optptr
- options
));
2932 optptr
+= strlen(optptr
);
2934 switch (attr
->value_tag
)
2936 case IPP_TAG_INTEGER
:
2938 snprintf(optptr
, optlength
- (optptr
- options
),
2939 "%d", attr
->values
[i
].integer
);
2942 case IPP_TAG_BOOLEAN
:
2943 if (!attr
->values
[i
].boolean
)
2944 strlcat(optptr
, "no", optlength
- (optptr
- options
));
2946 case IPP_TAG_NOVALUE
:
2947 strlcat(optptr
, attr
->name
,
2948 optlength
- (optptr
- options
));
2951 case IPP_TAG_RANGE
:
2952 if (attr
->values
[i
].range
.lower
== attr
->values
[i
].range
.upper
)
2953 snprintf(optptr
, optlength
- (optptr
- options
) - 1,
2954 "%d", attr
->values
[i
].range
.lower
);
2956 snprintf(optptr
, optlength
- (optptr
- options
) - 1,
2957 "%d-%d", attr
->values
[i
].range
.lower
,
2958 attr
->values
[i
].range
.upper
);
2961 case IPP_TAG_RESOLUTION
:
2962 snprintf(optptr
, optlength
- (optptr
- options
) - 1,
2963 "%dx%d%s", attr
->values
[i
].resolution
.xres
,
2964 attr
->values
[i
].resolution
.yres
,
2965 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
2969 case IPP_TAG_STRING
:
2972 case IPP_TAG_KEYWORD
:
2973 case IPP_TAG_CHARSET
:
2974 case IPP_TAG_LANGUAGE
:
2976 for (valptr
= attr
->values
[i
].string
.text
; *valptr
;)
2978 if (strchr(" \t\n\\\'\"", *valptr
))
2980 *optptr
++ = *valptr
++;
2987 break; /* anti-compiler-warning-code */
2991 optptr
+= strlen(optptr
);
2996 * Build the command-line arguments for the filters. Each filter
2997 * has 6 or 7 arguments:
3001 * argv[2] = username
3003 * argv[4] = # copies
3005 * argv[6] = filename (optional; normally stdin)
3007 * This allows legacy printer drivers that use the old System V
3008 * printing interface to be used by CUPS.
3010 * For remote jobs, we send all of the files in the argument list.
3013 if (printer
->remote
&& job
->num_files
> 1)
3014 argv
= calloc(7 + job
->num_files
, sizeof(char *));
3016 argv
= calloc(8, sizeof(char *));
3018 sprintf(jobid
, "%d", job
->id
);
3020 argv
[0] = printer
->name
;
3022 argv
[2] = job
->username
;
3027 if (printer
->remote
&& job
->num_files
> 1)
3029 for (i
= 0; i
< job
->num_files
; i
++)
3031 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
,
3033 argv
[6 + i
] = strdup(filename
);
3038 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
,
3039 job
->id
, job
->current_file
+ 1);
3043 for (i
= 0; argv
[i
]; i
++)
3044 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3045 "[Job %d] argv[%d]=\"%s\"", job
->id
, i
, argv
[i
]);
3048 * Create environment variable strings for the filters...
3051 attr
= ippFindAttribute(job
->attrs
, "attributes-natural-language",
3054 switch (strlen(attr
->values
[0].string
.text
))
3058 * This is an unknown or badly formatted language code; use
3059 * the POSIX locale...
3062 strcpy(lang
, "LANG=C");
3067 * Just the language code (ll)...
3070 snprintf(lang
, sizeof(lang
), "LANG=%s",
3071 attr
->values
[0].string
.text
);
3076 * Language and country code (ll-cc)...
3079 snprintf(lang
, sizeof(lang
), "LANG=%c%c_%c%c",
3080 attr
->values
[0].string
.text
[0],
3081 attr
->values
[0].string
.text
[1],
3082 toupper(attr
->values
[0].string
.text
[3] & 255),
3083 toupper(attr
->values
[0].string
.text
[4] & 255));
3087 attr
= ippFindAttribute(job
->attrs
, "document-format",
3090 (optptr
= strstr(attr
->values
[0].string
.text
, "charset=")) != NULL
)
3091 snprintf(charset
, sizeof(charset
), "CHARSET=%s", optptr
+ 8);
3094 attr
= ippFindAttribute(job
->attrs
, "attributes-charset",
3096 snprintf(charset
, sizeof(charset
), "CHARSET=%s",
3097 attr
->values
[0].string
.text
);
3100 snprintf(content_type
, sizeof(content_type
), "CONTENT_TYPE=%s/%s",
3101 job
->filetypes
[job
->current_file
]->super
,
3102 job
->filetypes
[job
->current_file
]->type
);
3103 snprintf(device_uri
, sizeof(device_uri
), "DEVICE_URI=%s",
3104 printer
->device_uri
);
3105 cupsdSanitizeURI(printer
->device_uri
, sani_uri
, sizeof(sani_uri
));
3106 snprintf(ppd
, sizeof(ppd
), "PPD=%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
3107 snprintf(printer_name
, sizeof(printer_name
), "PRINTER=%s", printer
->name
);
3108 snprintf(rip_max_cache
, sizeof(rip_max_cache
), "RIP_MAX_CACHE=%s", RIPCache
);
3110 envc
= cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
3112 envp
[envc
++] = charset
;
3113 envp
[envc
++] = lang
;
3114 envp
[envc
++] = ppd
;
3115 envp
[envc
++] = rip_max_cache
;
3116 envp
[envc
++] = content_type
;
3117 envp
[envc
++] = device_uri
;
3118 envp
[envc
++] = printer_name
;
3120 if (!printer
->remote
&&
3121 (filter
= (mime_filter_t
*)cupsArrayLast(filters
)) != NULL
)
3123 snprintf(final_content_type
, sizeof(final_content_type
),
3124 "FINAL_CONTENT_TYPE=%s/%s",
3125 filter
->dst
->super
, filter
->dst
->type
);
3126 envp
[envc
++] = final_content_type
;
3129 if (Classification
&& !banner_page
)
3131 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
3132 IPP_TAG_NAME
)) == NULL
)
3133 snprintf(classification
, sizeof(classification
), "CLASSIFICATION=%s",
3135 else if (attr
->num_values
> 1 &&
3136 strcmp(attr
->values
[1].string
.text
, "none") != 0)
3137 snprintf(classification
, sizeof(classification
), "CLASSIFICATION=%s",
3138 attr
->values
[1].string
.text
);
3140 snprintf(classification
, sizeof(classification
), "CLASSIFICATION=%s",
3141 attr
->values
[0].string
.text
);
3143 envp
[envc
++] = classification
;
3146 if (job
->dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
3148 snprintf(class_name
, sizeof(class_name
), "CLASS=%s", job
->dest
);
3149 envp
[envc
++] = class_name
;
3154 envp
[envc
++] = job
->ccname
;
3155 #endif /* HAVE_GSSAPI */
3159 for (i
= 0; i
< envc
; i
++)
3160 if (strncmp(envp
[i
], "DEVICE_URI=", 11))
3161 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job %d] envp[%d]=\"%s\"",
3162 job
->id
, i
, envp
[i
]);
3164 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job %d] envp[%d]=\"DEVICE_URI=%s\"",
3165 job
->id
, i
, sani_uri
);
3167 if (printer
->remote
)
3168 job
->current_file
= job
->num_files
;
3170 job
->current_file
++;
3173 * Now create processes for all of the filters...
3176 filterfds
[0][0] = -1;
3177 filterfds
[0][1] = -1;
3178 filterfds
[1][0] = -1;
3179 filterfds
[1][1] = -1;
3181 if (!job
->status_buffer
)
3183 if (cupsdOpenPipe(job
->status_pipes
))
3185 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create job status pipes - %s.",
3187 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3188 "Unable to create status pipes - %s.", strerror(errno
));
3190 cupsdAddPrinterHistory(printer
);
3192 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3193 "Job canceled because the server could not create the job "
3199 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_job: status_pipes = [ %d %d ]",
3200 job
->status_pipes
[0], job
->status_pipes
[1]);
3202 job
->status_buffer
= cupsdStatBufNew(job
->status_pipes
[0], "[Job %d]",
3207 memset(job
->filters
, 0, sizeof(job
->filters
));
3209 for (i
= 0, slot
= 0, filter
= (mime_filter_t
*)cupsArrayFirst(filters
);
3211 i
++, filter
= (mime_filter_t
*)cupsArrayNext(filters
))
3213 if (filter
->filter
[0] != '/')
3214 snprintf(command
, sizeof(command
), "%s/filter/%s", ServerBin
,
3217 strlcpy(command
, filter
->filter
, sizeof(command
));
3219 if (i
< (cupsArrayCount(filters
) - 1))
3221 if (cupsdOpenPipe(filterfds
[slot
]))
3223 cupsdLogMessage(CUPSD_LOG_ERROR
,
3224 "Unable to create job filter pipes - %s.",
3226 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3227 "Unable to create filter pipes - %s.", strerror(errno
));
3228 cupsdAddPrinterHistory(printer
);
3230 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3231 "Job canceled because the server could not create the "
3239 if (job
->current_file
== 1)
3241 if (strncmp(printer
->device_uri
, "file:", 5) != 0)
3243 if (cupsdOpenPipe(job
->print_pipes
))
3245 cupsdLogMessage(CUPSD_LOG_ERROR
,
3246 "Unable to create job backend pipes - %s.",
3248 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3249 "Unable to create backend pipes - %s.", strerror(errno
));
3250 cupsdAddPrinterHistory(printer
);
3252 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3253 "Job canceled because the server could not create "
3254 "the backend pipes.");
3261 job
->print_pipes
[0] = -1;
3262 if (!strcmp(printer
->device_uri
, "file:/dev/null") ||
3263 !strcmp(printer
->device_uri
, "file:///dev/null"))
3264 job
->print_pipes
[1] = -1;
3267 if (!strncmp(printer
->device_uri
, "file:/dev/", 10))
3268 job
->print_pipes
[1] = open(printer
->device_uri
+ 5,
3270 else if (!strncmp(printer
->device_uri
, "file:///dev/", 12))
3271 job
->print_pipes
[1] = open(printer
->device_uri
+ 7,
3273 else if (!strncmp(printer
->device_uri
, "file:///", 8))
3274 job
->print_pipes
[1] = open(printer
->device_uri
+ 7,
3275 O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
3277 job
->print_pipes
[1] = open(printer
->device_uri
+ 5,
3278 O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
3280 if (job
->print_pipes
[1] < 0)
3282 cupsdLogMessage(CUPSD_LOG_ERROR
,
3283 "Unable to open output file \"%s\" - %s.",
3284 printer
->device_uri
, strerror(errno
));
3285 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3286 "Unable to open output file \"%s\" - %s.",
3287 printer
->device_uri
, strerror(errno
));
3289 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3290 "Job canceled because the server could not open the "
3296 fcntl(job
->print_pipes
[1], F_SETFD
,
3297 fcntl(job
->print_pipes
[1], F_GETFD
) | FD_CLOEXEC
);
3301 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3302 "start_job: print_pipes = [ %d %d ]",
3303 job
->print_pipes
[0], job
->print_pipes
[1]);
3306 filterfds
[slot
][0] = job
->print_pipes
[0];
3307 filterfds
[slot
][1] = job
->print_pipes
[1];
3310 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_job: filter=\"%s\"",
3312 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3313 "start_job: filterfds[%d]=[ %d %d ]",
3314 slot
, filterfds
[slot
][0], filterfds
[slot
][1]);
3316 pid
= cupsdStartProcess(command
, argv
, envp
, filterfds
[!slot
][0],
3317 filterfds
[slot
][1], job
->status_pipes
[1],
3318 job
->back_pipes
[0], job
->side_pipes
[0], 0,
3321 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3322 "start_job: Closing filter pipes for slot %d "
3324 !slot
, filterfds
[!slot
][0], filterfds
[!slot
][1]);
3326 cupsdClosePipe(filterfds
[!slot
]);
3330 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to start filter \"%s\" - %s.",
3331 filter
->filter
, strerror(errno
));
3332 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3333 "Unable to start filter \"%s\" - %s.",
3334 filter
->filter
, strerror(errno
));
3336 cupsdAddPrinterHistory(printer
);
3338 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3339 "Job canceled because the server could not execute a "
3345 cupsdLogMessage(CUPSD_LOG_INFO
, "Started filter %s (PID %d) for job %d.",
3346 command
, pid
, job
->id
);
3352 cupsArrayDelete(filters
);
3355 * Finally, pipe the final output into a backend process if needed...
3358 if (strncmp(printer
->device_uri
, "file:", 5) != 0)
3360 if (job
->current_file
== 1)
3362 sscanf(printer
->device_uri
, "%254[^:]", method
);
3363 snprintf(command
, sizeof(command
), "%s/backend/%s", ServerBin
, method
);
3366 * See if the backend needs to run as root...
3371 else if (stat(command
, &backinfo
))
3374 backroot
= !(backinfo
.st_mode
& (S_IRWXG
| S_IRWXO
));
3378 filterfds
[slot
][0] = -1;
3379 filterfds
[slot
][1] = -1;
3381 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_job: backend=\"%s\"",
3383 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3384 "start_job: filterfds[%d] = [ %d %d ]",
3385 slot
, filterfds
[slot
][0], filterfds
[slot
][1]);
3387 pid
= cupsdStartProcess(command
, argv
, envp
, filterfds
[!slot
][0],
3388 filterfds
[slot
][1], job
->status_pipes
[1],
3389 job
->back_pipes
[1], job
->side_pipes
[1],
3390 backroot
, &(job
->backend
));
3394 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to start backend \"%s\" - %s.",
3395 method
, strerror(errno
));
3396 snprintf(printer
->state_message
, sizeof(printer
->state_message
),
3397 "Unable to start backend \"%s\" - %s.", method
,
3400 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
3401 "Job canceled because the server could not execute "
3408 cupsdLogMessage(CUPSD_LOG_INFO
,
3409 "Started backend %s (PID %d) for job %d.",
3410 command
, pid
, job
->id
);
3414 if (job
->current_file
== job
->num_files
)
3416 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3417 "start_job: Closing print pipes [ %d %d ]...",
3418 job
->print_pipes
[0], job
->print_pipes
[1]);
3420 cupsdClosePipe(job
->print_pipes
);
3422 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3423 "start_job: Closing back pipes [ %d %d ]...",
3424 job
->back_pipes
[0], job
->back_pipes
[1]);
3426 cupsdClosePipe(job
->back_pipes
);
3428 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3429 "start_job: Closing side pipes [ %d %d ]...",
3430 job
->side_pipes
[0], job
->side_pipes
[1]);
3432 cupsdClosePipe(job
->side_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;
3444 filterfds
[slot
][0] = -1;
3445 filterfds
[slot
][1] = -1;
3447 if (job
->current_file
== job
->num_files
)
3449 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3450 "start_job: Closing print pipes [ %d %d ]...",
3451 job
->print_pipes
[0], job
->print_pipes
[1]);
3453 cupsdClosePipe(job
->print_pipes
);
3455 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3456 "start_job: Closing status output pipe %d...",
3457 job
->status_pipes
[1]);
3459 close(job
->status_pipes
[1]);
3460 job
->status_pipes
[1] = -1;
3464 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3465 "start_job: Closing filter pipes for slot %d "
3467 slot
, filterfds
[slot
][0], filterfds
[slot
][1]);
3468 cupsdClosePipe(filterfds
[slot
]);
3470 if (printer
->remote
&& job
->num_files
> 1)
3472 for (i
= 0; i
< job
->num_files
; i
++)
3478 cupsdAddSelect(job
->status_buffer
->fd
, (cupsd_selfunc_t
)cupsdUpdateJob
, NULL
,
3481 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
, "Job #%d started.",
3488 * If we get here, we need to abort the current job and close out all
3489 * files and pipes...
3494 for (slot
= 0; slot
< 2; slot
++)
3496 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3497 "start_job: Closing filter pipes for slot %d "
3499 slot
, filterfds
[slot
][0], filterfds
[slot
][1]);
3500 cupsdClosePipe(filterfds
[slot
]);
3503 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3504 "start_job: Closing status pipes [ %d %d ]...",
3505 job
->status_pipes
[0], job
->status_pipes
[1]);
3506 cupsdClosePipe(job
->status_pipes
);
3507 cupsdStatBufDelete(job
->status_buffer
);
3509 cupsArrayDelete(filters
);
3511 if (printer
->remote
&& job
->num_files
> 1)
3513 for (i
= 0; i
< job
->num_files
; i
++)
3519 cupsdStopJob(job
, 0);
3524 * 'unload_job()' - Unload a job from memory.
3528 unload_job(cupsd_job_t
*job
) /* I - Job */
3533 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Unloading job %d...", job
->id
);
3535 ippDelete(job
->attrs
);
3540 job
->job_sheets
= NULL
;
3545 * End of "$Id: job.c 6365 2007-03-19 20:56:57Z mike $".