diff options
author | Gowtham Thommandra <Gowtham.Thommandra@Sun.COM> | 2009-05-20 15:34:01 +0530 |
---|---|---|
committer | Gowtham Thommandra <Gowtham.Thommandra@Sun.COM> | 2009-05-20 15:34:01 +0530 |
commit | 375b28ffc40c6f03a644dc9310ae2000e73ffd5e (patch) | |
tree | ccbc371c60377e35c20634c5cb7e9f5c71959c27 /usr/src/cmd/print/bsd-sysv-commands | |
parent | 7a142be9307f4ef3f3dbe77bb364bea22cd33485 (diff) | |
download | illumos-gate-375b28ffc40c6f03a644dc9310ae2000e73ffd5e.tar.gz |
6751244 lpstat -p with a printer list as argument fails
Diffstat (limited to 'usr/src/cmd/print/bsd-sysv-commands')
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/Makefile | 8 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/lpstat.c | 133 |
2 files changed, 86 insertions, 55 deletions
diff --git a/usr/src/cmd/print/bsd-sysv-commands/Makefile b/usr/src/cmd/print/bsd-sysv-commands/Makefile index d4ec13c448..6be41d2f21 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/Makefile +++ b/usr/src/cmd/print/bsd-sysv-commands/Makefile @@ -19,10 +19,9 @@ # CDDL HEADER END # # -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" # include ../Makefile.sp @@ -55,11 +54,14 @@ MANIFEST= rfc1179.xml ROOTMANIFESTDIR= $(ROOTSVCAPPLICATIONPRINT) $(ROOTMANIFEST) := FILEMODE= 444 +LPLIB = $(SRC)/cmd/lp/lib +LIBLP = $(LPLIB)/lp/liblp.a CFLAGS += $(CCVERBOSE) CPPFLAGS += -I. CPPFLAGS += -I../../../lib/print/libpapi-common/common CPPFLAGS += -I$(ROOT)/usr/include -LDLIBS += -lpapi -lc +CPPFLAGS += -I../../lp/include +LDLIBS += $(LIBLP) -lpapi -lc in.lpd:= CFLAGS += -DSOLARIS_PRIVATE_POST_0_9 in.lpd:= LDLIBS += -lnsl -lsocket 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) |