summaryrefslogtreecommitdiff
path: root/usr/src/cmd/print/bsd-sysv-commands
diff options
context:
space:
mode:
authorsonam gupta - Sun Microsystems - Bangalore India <Sonam.Gupta@Sun.COM>2008-12-07 21:56:43 -0800
committersonam gupta - Sun Microsystems - Bangalore India <Sonam.Gupta@Sun.COM>2008-12-07 21:56:43 -0800
commit4749ecc39647e1a68fd60bde2cea885c8bcf9ee7 (patch)
treecb134bbf1c12c2edd5c177a4827a8a6575227ebd /usr/src/cmd/print/bsd-sysv-commands
parentb424305435881ac456a9343be2898f1f86440f31 (diff)
downloadillumos-joyent-4749ecc39647e1a68fd60bde2cea885c8bcf9ee7.tar.gz
6752568 S10u5: lpstat -o reports "Failed to contact service for <printer>: not-found"
Diffstat (limited to 'usr/src/cmd/print/bsd-sysv-commands')
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lpstat.c135
1 files changed, 86 insertions, 49 deletions
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
index e32cddfd39..e3ba272bc9 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
@@ -710,68 +710,105 @@ job_query(char *request, int (*report)(papi_job_t, int, int),
int result = 0;
papi_status_t status;
papi_service_t svc = NULL;
- char *printer = NULL;
+ char *printer = request;
int32_t id = -1;
+ int flag1 = 0;
+ int flag = 1;
+ int print_flag = 0;
- get_printer_id(request, &printer, &id);
+ do {
+ status = papiServiceCreate(&svc, printer, NULL, NULL,
+ cli_auth_callback, encryption, NULL);
- status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback,
- encryption, NULL);
- if (status != PAPI_OK) {
- fprintf(stderr, gettext(
- "Failed to contact service for %s: %s\n"),
- (printer ? printer : "all"),
- verbose_papi_message(svc, status));
- return (-1);
- }
+ if ((status == PAPI_OK) && (printer != NULL))
+ print_flag = 1;
- if (printer == NULL) { /* all */
- char **interest = interest_list(svc);
+ /* <name>-# printer name does not exist */
+ if (status != PAPI_OK) {
+ /*
+ * Check if <name>-# is a request-id
+ * Once this check is done flag1 is set
+ */
+ if (flag1 == 1)
+ break;
+
+ get_printer_id(printer, &printer, &id);
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL,
+ cli_auth_callback, encryption, NULL);
+
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ (printer ? printer : "all"),
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+ }
- if (interest != NULL) {
- int i;
+ if (printer == NULL) { /* all */
+ char **interest = interest_list(svc);
- for (i = 0; interest[i] != NULL; i++)
- result += job_query(interest[i], report,
- encryption, show_rank, verbose);
- }
- } else if (id == -1) { /* a printer */
- papi_job_t *jobs = NULL;
+ if (interest != NULL) {
+ int i;
- status = papiPrinterListJobs(svc, printer, NULL, 0, 0, &jobs);
- if (status != PAPI_OK) {
- fprintf(stderr, gettext(
- "Failed to get job list: %s\n"),
- verbose_papi_message(svc, status));
- papiServiceDestroy(svc);
- return (-1);
- }
+ for (i = 0; interest[i] != NULL; i++)
+ result += job_query(interest[i], report,
+ encryption, show_rank, verbose);
+ }
+ } else if (id == -1) { /* a printer */
+ papi_job_t *jobs = NULL;
+
+ status = papiPrinterListJobs(svc, printer, NULL,
+ 0, 0, &jobs);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to get job list: %s\n"),
+ verbose_papi_message(svc, status));
+ papiServiceDestroy(svc);
+ return (-1);
+ }
- if (jobs != NULL) {
- int i;
+ if (jobs != NULL) {
+ int i;
- for (i = 0; jobs[i] != NULL; i++)
- result += report(jobs[i], show_rank, verbose);
- }
+ for (i = 0; jobs[i] != NULL; i++)
+ result += report(jobs[i],
+ show_rank, verbose);
+ }
+
+ papiJobListFree(jobs);
+ } else { /* a job */
+ papi_job_t job = NULL;
+
+ /* Once a job has been found stop processing */
+ flag = 0;
+
+ status = papiJobQuery(svc, printer, id, NULL, &job);
+ if (status != PAPI_OK) {
+ if (!print_flag)
+ fprintf(stderr, gettext(
+ "Failed to get job info for %s: %s\n"),
+ request, verbose_papi_message(svc, status));
+ papiServiceDestroy(svc);
+ return (-1);
+ }
- papiJobListFree(jobs);
- } else { /* a job */
- papi_job_t job = NULL;
+ if (job != NULL)
+ result = report(job, show_rank, verbose);
- status = papiJobQuery(svc, printer, id, NULL, &job);
- if (status != PAPI_OK) {
- fprintf(stderr, gettext(
- "Failed to get job info for %s: %s\n"),
- request, verbose_papi_message(svc, status));
- papiServiceDestroy(svc);
- return (-1);
+ papiJobFree(job);
}
- if (job != NULL)
- result = report(job, show_rank, verbose);
-
- papiJobFree(job);
- }
+ if (flag) {
+ id = -1;
+ get_printer_id(printer, &printer, &id);
+ if (id == -1)
+ flag = 0;
+ else
+ flag1 = 1;
+ }
+ } while (flag);
papiServiceDestroy(svc);