summaryrefslogtreecommitdiff
path: root/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
diff options
context:
space:
mode:
authorGowtham Thommandra <Gowtham.Thommandra@Sun.COM>2009-05-20 15:34:01 +0530
committerGowtham Thommandra <Gowtham.Thommandra@Sun.COM>2009-05-20 15:34:01 +0530
commit375b28ffc40c6f03a644dc9310ae2000e73ffd5e (patch)
treeccbc371c60377e35c20634c5cb7e9f5c71959c27 /usr/src/cmd/print/bsd-sysv-commands/lpstat.c
parent7a142be9307f4ef3f3dbe77bb364bea22cd33485 (diff)
downloadillumos-gate-375b28ffc40c6f03a644dc9310ae2000e73ffd5e.tar.gz
6751244 lpstat -p with a printer list as argument fails
Diffstat (limited to 'usr/src/cmd/print/bsd-sysv-commands/lpstat.c')
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lpstat.c133
1 files changed, 81 insertions, 52 deletions
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
index c66dd15720..3b82a87be5 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
@@ -39,6 +39,7 @@
#include <papi.h>
#include <uri.h>
#include "common.h"
+#include "lp.h"
static void
usage(char *program)
@@ -600,70 +601,96 @@ printer_query(char *name, int (*report)(papi_service_t, char *, papi_printer_t,
int, int), papi_encryption_t encryption,
int verbose, int description)
{
- int result = 0;
+ int result = 0, i = 0;
papi_status_t status;
papi_service_t svc = NULL;
+ char **list = getlist(name, LP_WS, LP_SEP);
- status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback,
- encryption, NULL);
- if (status != PAPI_OK) {
- if (status == PAPI_NOT_FOUND)
- fprintf(stderr, gettext("%s: unknown printer\n"),
- name ? name : "(NULL)");
- else
- fprintf(stderr, gettext(
- "Failed to contact service for %s: %s\n"),
- name ? name : "(NULL)",
- verbose_papi_message(svc, status));
- papiServiceDestroy(svc);
- return (-1);
+ if (list == NULL) {
+ list = (char **)malloc(sizeof (char *));
+ list[0] = name;
}
- if (name == NULL) { /* all */
- char **interest = interest_list(svc);
-
- if (interest != NULL) {
- int i;
+ /*
+ * The for loop executes once for every printer
+ * entry in list. If list is NULL that implies
+ * name is also NULL, the loop runs only one time.
+ */
- for (i = 0; interest[i] != NULL; i++)
- result += printer_query(interest[i], report,
- encryption, verbose,
- description);
- }
- } else {
- papi_printer_t printer = NULL;
- char **keys = NULL;
+ for (i = 0; name == NULL || list[i] != NULL; i++) {
+ name = list[i];
- /*
- * Limit the query to only required data to reduce the need
- * to go remote for information.
- */
- if (report == report_device)
- keys = report_device_keys;
- else if (report == report_class)
- keys = report_class_keys;
- else if (report == report_accepting)
- keys = report_accepting_keys;
- else if ((report == report_printer) && (verbose == 0))
- keys = report_printer_keys;
-
- status = papiPrinterQuery(svc, name, keys, NULL, &printer);
+ status = papiServiceCreate(&svc, name, NULL, NULL,
+ cli_auth_callback, encryption, NULL);
if (status != PAPI_OK) {
- fprintf(stderr, gettext(
- "Failed to get printer info for %s: %s\n"),
- name, verbose_papi_message(svc, status));
+ if (status == PAPI_NOT_FOUND)
+ fprintf(stderr,
+ gettext("%s: unknown printer\n"),
+ name ? name : "(NULL)");
+ else
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ name ? name : "(NULL)",
+ verbose_papi_message(svc, status));
papiServiceDestroy(svc);
- return (-1);
+ result--;
+ continue;
}
- if (printer != NULL)
- result = report(svc, name, printer, verbose,
- description);
+ if (name == NULL) { /* all */
+ char **interest = interest_list(svc);
- papiPrinterFree(printer);
+ if (interest != NULL) {
+ int i;
+
+ for (i = 0; interest[i] != NULL; i++)
+ result += printer_query(interest[i],
+ report, encryption, verbose,
+ description);
+ }
+ } else {
+ papi_printer_t printer = NULL;
+ char **keys = NULL;
+
+ /*
+ * Limit the query to only required data
+ * to reduce the need to go remote for
+ * information.
+ */
+ if (report == report_device)
+ keys = report_device_keys;
+ else if (report == report_class)
+ keys = report_class_keys;
+ else if (report == report_accepting)
+ keys = report_accepting_keys;
+ else if ((report == report_printer) && (verbose == 0))
+ keys = report_printer_keys;
+
+ status = papiPrinterQuery(svc, name, keys,
+ NULL, &printer);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to get printer info for %s: %s\n"),
+ name, verbose_papi_message(svc, status));
+ papiServiceDestroy(svc);
+ result--;
+ continue;
+ }
+
+ if (printer != NULL)
+ result += report(svc, name, printer, verbose,
+ description);
+
+ papiPrinterFree(printer);
+ }
+
+ papiServiceDestroy(svc);
+
+ if (name == NULL)
+ break;
}
- papiServiceDestroy(svc);
+ freelist(list);
return (result);
}
@@ -944,9 +971,11 @@ job_query(char *request, int (*report)(char *, papi_job_t, int, int),
id = job_to_be_queried(svc, printer, id);
if (id > 0)
- status = papiJobQuery(svc, printer, id, NULL, &job);
+ status = papiJobQuery(svc, printer, id,
+ NULL, &job);
else
- status = papiJobQuery(svc, printer, rid, NULL, &job);
+ status = papiJobQuery(svc, printer, rid,
+ NULL, &job);
if (status != PAPI_OK) {
if (!print_flag)