changeset 12778:e64b5ecb0036

6946115 lpstat -o <remote jobID> return bad-argument error even when jobID is valid
author Keerthi Kondaka <Keerthi.Kondaka@Sun.COM>
date Tue, 06 Jul 2010 18:22:03 -0700
parents 6c0cc5cfe9a2
children 96016f1d9837
files usr/src/lib/print/libpapi-lpd/common/lpd-query.c
diffstat 1 files changed, 21 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/lib/print/libpapi-lpd/common/lpd-query.c	Tue Jul 06 18:04:43 2010 -0700
+++ b/usr/src/lib/print/libpapi-lpd/common/lpd-query.c	Tue Jul 06 18:22:03 2010 -0700
@@ -20,9 +20,7 @@
  */
 
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- *
+ * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 /* $Id: lpd-query.c 155 2006-04-26 02:34:54Z ktou $ */
@@ -404,11 +402,16 @@
 {
 	int fd;
 
-	if (svc->cache != NULL)	/* this should be time based */
+	if (svc == NULL)
 		return;
 
-	if (svc == NULL)
-		return;
+	if (svc->cache != NULL)	{ /* this should be time based */
+		if (svc->cache->jobs == NULL) {
+			free(svc->cache);
+			svc->cache = NULL;
+		} else
+			return;
+	}
 
 	if ((fd = lpd_open(svc, 'q', NULL, 15)) < 0)
 		return;
@@ -451,6 +454,17 @@
 		}
 	}
 
+	/*
+	 * cache jobs is free()-ed in
+	 * libpapi-dynamic/common/printer.c -
+	 * papiPrinterListJobs() cache printer is
+	 * free()-ed by the caller of
+	 * lpd_find_printer_info Invalidate the
+	 * cache by freeing the cache.
+	 */
+	free(svc->cache);
+	svc->cache = NULL;
+
 	return (result);
 }
 
@@ -460,7 +474,7 @@
 	papi_status_t result = PAPI_BAD_ARGUMENT;
 	job_t **jobs;
 
-	if (lpd_find_jobs_info(svc, &jobs) != PAPI_OK) {
+	if ((lpd_find_jobs_info(svc, &jobs) == PAPI_OK) && (jobs != NULL)) {
 		int i;
 
 		*job = NULL;