slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
return print_run_command( -1, sharename, False, lprm_command, NULL,
"%j", jobstr,
- "%T", http_timestring(pjob->starttime),
+ "%T", http_timestring(talloc_tos(), pjob->starttime),
NULL);
}
/* need to pause the spooled entry */
slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
- return print_run_command(snum, PRINTERNAME(snum), True,
+ return print_run_command(snum, lp_printername(snum), True,
lp_lppausecommand(snum), NULL,
"%j", jobstr,
NULL);
/* need to pause the spooled entry */
slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
- return print_run_command(snum, PRINTERNAME(snum), True,
+ return print_run_command(snum, lp_printername(snum), True,
lp_lpresumecommand(snum), NULL,
"%j", jobstr,
NULL);
}
+/****************************************************************************
+get the current list of queued jobs
+****************************************************************************/
+static int generic_queue_get(const char *printer_name,
+ enum printing_types printing_type,
+ char *lpq_command,
+ print_queue_struct **q,
+ print_status_struct *status)
+{
+ char **qlines;
+ int fd;
+ int numlines, i, qcount;
+ print_queue_struct *queue = NULL;
+
+ /* never do substitution when running the 'lpq command' since we can't
+ get it rigt when using the background update daemon. Make the caller
+ do it before passing off the command string to us here. */
+
+ print_run_command(-1, printer_name, False, lpq_command, &fd, NULL);
+
+ if (fd == -1) {
+ DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n",
+ printer_name ));
+ return 0;
+ }
+
+ numlines = 0;
+ qlines = fd_lines_load(fd, &numlines,0,NULL);
+ close(fd);
+
+ /* turn the lpq output into a series of job structures */
+ qcount = 0;
+ ZERO_STRUCTP(status);
+ if (numlines && qlines) {
+ queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
+ if (!queue) {
+ TALLOC_FREE(qlines);
+ *q = NULL;
+ return 0;
+ }
+ memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
+
+ for (i=0; i<numlines; i++) {
+ /* parse the line */
+ if (parse_lpq_entry(printing_type,qlines[i],
+ &queue[qcount],status,qcount==0)) {
+ qcount++;
+ }
+ }
+ }
+
+ TALLOC_FREE(qlines);
+ *q = queue;
+ return qcount;
+}
+
/****************************************************************************
Submit a file for printing - called from print_job_end()
****************************************************************************/
-static int generic_job_submit(int snum, struct printjob *pjob)
+static int generic_job_submit(int snum, struct printjob *pjob,
+ enum printing_types printing_type,
+ char *lpq_cmd)
{
int ret = -1;
char *current_directory = NULL;
char *jobname = NULL;
TALLOC_CTX *ctx = talloc_tos();
fstring job_page_count, job_size;
+ print_queue_struct *q;
+ print_status_struct status;
/* we print from the directory path to give the best chance of
parsing the lpq output */
- current_directory = TALLOC_ARRAY(ctx,
- char,
- PATH_MAX+1);
- if (!current_directory) {
- return -1;
- }
- wd = sys_getwd(current_directory);
+ wd = sys_getwd();
if (!wd) {
return -1;
}
+ current_directory = talloc_strdup(ctx, wd);
+ SAFE_FREE(wd);
+
+ if (!current_directory) {
+ return -1;
+ }
print_directory = talloc_strdup(ctx, pjob->filename);
if (!print_directory) {
return -1;
slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size);
/* send it to the system spooler */
- ret = print_run_command(snum, PRINTERNAME(snum), True,
+ ret = print_run_command(snum, lp_printername(snum), True,
lp_printcommand(snum), NULL,
"%s", p,
"%J", jobname,
"%z", job_size,
"%c", job_page_count,
NULL);
-
- out:
-
- chdir(wd);
- TALLOC_FREE(current_directory);
- return ret;
-}
-
-
-/****************************************************************************
-get the current list of queued jobs
-****************************************************************************/
-static int generic_queue_get(const char *printer_name,
- enum printing_types printing_type,
- char *lpq_command,
- print_queue_struct **q,
- print_status_struct *status)
-{
- char **qlines;
- int fd;
- int numlines, i, qcount;
- print_queue_struct *queue = NULL;
-
- /* never do substitution when running the 'lpq command' since we can't
- get it rigt when using the background update daemon. Make the caller
- do it before passing off the command string to us here. */
-
- print_run_command(-1, printer_name, False, lpq_command, &fd, NULL);
-
- if (fd == -1) {
- DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n",
- printer_name ));
- return 0;
+ if (ret != 0) {
+ ret = -1;
+ goto out;
}
-
- numlines = 0;
- qlines = fd_lines_load(fd, &numlines,0);
- close(fd);
- /* turn the lpq output into a series of job structures */
- qcount = 0;
- ZERO_STRUCTP(status);
- if (numlines && qlines) {
- queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
- if (!queue) {
- file_lines_free(qlines);
- *q = NULL;
- return 0;
- }
- memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
-
- for (i=0; i<numlines; i++) {
- /* parse the line */
- if (parse_lpq_entry(printing_type,qlines[i],
- &queue[qcount],status,qcount==0)) {
- qcount++;
+ /*
+ * check the queue for the newly submitted job, this allows us to
+ * determine the backend job identifier (sysjob).
+ */
+ pjob->sysjob = -1;
+ ret = generic_queue_get(lp_printername(snum), printing_type, lpq_cmd,
+ &q, &status);
+ if (ret > 0) {
+ int i;
+ for (i = 0; i < ret; i++) {
+ if (strcmp(q[i].fs_file, p) == 0) {
+ pjob->sysjob = q[i].sysjob;
+ DEBUG(5, ("new job %u (%s) matches sysjob %d\n",
+ pjob->jobid, jobname, pjob->sysjob));
+ break;
}
- }
+ }
+ SAFE_FREE(q);
+ ret = 0;
+ }
+ if (pjob->sysjob == -1) {
+ DEBUG(0, ("failed to get sysjob for job %u (%s), tracking as "
+ "Unix job\n", pjob->jobid, jobname));
}
- file_lines_free(qlines);
- *q = queue;
- return qcount;
+
+ out:
+
+ if (chdir(current_directory) == -1) {
+ smb_panic("chdir failed in generic_job_submit");
+ }
+ TALLOC_FREE(current_directory);
+ return ret;
}
/****************************************************************************
****************************************************************************/
static int generic_queue_pause(int snum)
{
- return print_run_command(snum, PRINTERNAME(snum), True, lp_queuepausecommand(snum), NULL, NULL);
+ return print_run_command(snum, lp_printername(snum), True,
+ lp_queuepausecommand(snum), NULL, NULL);
}
/****************************************************************************
****************************************************************************/
static int generic_queue_resume(int snum)
{
- return print_run_command(snum, PRINTERNAME(snum), True, lp_queueresumecommand(snum), NULL, NULL);
+ return print_run_command(snum, lp_printername(snum), True,
+ lp_queueresumecommand(snum), NULL, NULL);
}
/****************************************************************************