summaryrefslogtreecommitdiff
path: root/usr/src/cmd/print
diff options
context:
space:
mode:
authorsonam gupta - Sun Microsystems - Bangalore India <Sonam.Gupta@Sun.COM>2009-04-09 23:37:50 -0700
committersonam gupta - Sun Microsystems - Bangalore India <Sonam.Gupta@Sun.COM>2009-04-09 23:37:50 -0700
commitf0b87b902adb4cdfe4ad24ea596a7311ddbb2953 (patch)
treedf5d3435e267baa0cf0483c2ca43b499f51514b8 /usr/src/cmd/print
parent40e7ce05bde825a43b0db32ded62db8cc5b6ec9c (diff)
downloadillumos-gate-f0b87b902adb4cdfe4ad24ea596a7311ddbb2953.tar.gz
6815222 lpstat -o reports incorrect job# for general user
Diffstat (limited to 'usr/src/cmd/print')
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/cancel.c38
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/common.c40
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/common.h6
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lpstat.c15
4 files changed, 91 insertions, 8 deletions
diff --git a/usr/src/cmd/print/bsd-sysv-commands/cancel.c b/usr/src/cmd/print/bsd-sysv-commands/cancel.c
index 7fbdbb8db3..6efd95bda4 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/cancel.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/cancel.c
@@ -51,6 +51,17 @@ usage(char *program)
exit(1);
}
+static int32_t
+get_job_id_requested(papi_job_t job) {
+ int32_t rid = -1;
+
+ papi_attribute_t **list = papiJobGetAttributeList(job);
+ papiAttributeListGetInteger(list, NULL,
+ "job-id-requested", &rid);
+
+ return (rid);
+}
+
int
cancel_jobs_for_user(char *user, papi_encryption_t encryption, char *pname) {
@@ -101,6 +112,7 @@ main(int ac, char *av[])
char *user = NULL;
papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
int c;
+ int32_t rid = 0;
(void) setlocale(LC_ALL, "");
(void) textdomain("SUNW_OST_OSCMD");
@@ -143,7 +155,17 @@ main(int ac, char *av[])
if (id != -1) { /* it's a job */
char *mesg = "cancelled";
- status = papiJobCancel(svc, printer, id);
+ /*
+ * Check if the job-id is job-id-requested
+ * or job-id. If it is job-id-requested then find
+ * corresponding job-id and send it to cancel
+ */
+ rid = job_to_be_queried(svc, printer, id);
+ if (rid > 0)
+ status = papiJobCancel(svc, printer, rid);
+ else
+ status = papiJobCancel(svc, printer, id);
+
if (status == PAPI_NOT_AUTHORIZED) {
mesg = papiStatusString(status);
exit_code = 1;
@@ -183,9 +205,17 @@ main(int ac, char *av[])
svc, status);
exit_code = 1;
}
- fprintf(OUT, "%s-%d: %s\n", printer,
- id, mesg);
-
+ /*
+ * If job-id-requested exists for this
+ * job-id then that should be displayed
+ */
+ rid = get_job_id_requested(*jobs);
+ if (rid > 0)
+ fprintf(OUT, "%s-%d: %s\n",
+ printer, rid, mesg);
+ else
+ fprintf(OUT, "%s-%d: %s\n",
+ printer, id, mesg);
}
papiJobListFree(jobs);
diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.c b/usr/src/cmd/print/bsd-sysv-commands/common.c
index 8b4f50bdc8..ceb9177677 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/common.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.c
@@ -580,3 +580,43 @@ cli_auth_callback(papi_service_t svc, void *app_data)
return (0);
}
+
+int32_t
+job_to_be_queried(papi_service_t svc, char *printer, int32_t id)
+{
+ papi_job_t *jobs = NULL;
+ papi_status_t status;
+ char *jattrs[] = { "job-id",
+ "job-id-requested", NULL };
+
+ status = papiPrinterListJobs(svc, printer, jattrs, PAPI_LIST_JOBS_ALL,
+ 0, &jobs);
+
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("Failed to query service for %s: %s\n"),
+ printer, verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ if (jobs != NULL) {
+ int i = 0;
+
+ for (i = 0; jobs[i] != NULL; i++) {
+ int32_t rid = -1;
+ papi_attribute_t **list =
+ papiJobGetAttributeList(jobs[i]);
+
+ papiAttributeListGetInteger(list, NULL,
+ "job-id-requested", &rid);
+
+ /* check if this matches with id */
+ if (rid == id) {
+ /* get the actual id and return it */
+ papiAttributeListGetInteger(list, NULL,
+ "job-id", &id);
+ return (id);
+ }
+ }
+ }
+ return (id);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.h b/usr/src/cmd/print/bsd-sysv-commands/common.h
index 4a74be0abf..a729930bd5 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/common.h
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.h
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
@@ -30,8 +30,6 @@
/* $Id: common.h 162 2006-05-08 14:17:44Z njacobs $ */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <papi.h>
#include <config-site.h>
@@ -63,6 +61,8 @@ extern int is_postscript_stream(int fd, char *buf, int *len);
extern int cli_auth_callback(papi_service_t svc, void *app_data);
+extern int32_t job_to_be_queried(papi_service_t svc, char *printer, int32_t id);
+
#ifdef __cplusplus
}
#endif
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
index 94c3b7b98f..789661b2e0 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
@@ -797,6 +797,7 @@ report_job(char *printer, papi_job_t job, int show_rank, int verbose)
(void) papiAttributeListGetInteger(attrs, NULL,
"job-id-requested", &id);
+
snprintf(request, sizeof (request), "%s-%d", printer, id);
if (show_rank != 0) {
@@ -813,6 +814,7 @@ report_job(char *printer, papi_job_t job, int show_rank, int verbose)
(void) papiAttributeListGetInteger(attrs, NULL,
"job-state", &jstate);
+
if (jstate == 0x0001)
printf(gettext(" being held"));
else if (jstate == 0x0800)
@@ -930,11 +932,22 @@ job_query(char *request, int (*report)(char *, papi_job_t, int, int),
papiJobListFree(jobs);
} else { /* a job */
papi_job_t job = NULL;
+ int rid = id;
/* Once a job has been found stop processing */
flag = 0;
- status = papiJobQuery(svc, printer, id, NULL, &job);
+ /*
+ * Job-id could be the job-id requested
+ * Check if it is job-id or job-id-requested
+ */
+ id = job_to_be_queried(svc, printer, id);
+
+ if (id > 0)
+ status = papiJobQuery(svc, printer, id, NULL, &job);
+ else
+ status = papiJobQuery(svc, printer, rid, NULL, &job);
+
if (status != PAPI_OK) {
if (!print_flag)
fprintf(stderr, gettext(