]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
The `lp` and `lpr` commands now provide better error messages when the default
authorMichael R Sweet <michaelrsweet@gmail.com>
Wed, 1 Nov 2017 19:45:50 +0000 (15:45 -0400)
committerMichael R Sweet <michaelrsweet@gmail.com>
Wed, 1 Nov 2017 19:45:50 +0000 (15:45 -0400)
printer cannot be found (Issue #5096)

- berkeley/lpr.c: Use cupsLastErrorMessage() for not-found errors.
- cups/dest.c: Set the last error message in cupsGetNamedDest().
- systemv/lp.c: Use cupsLastErrorMessage() for not-found errors.

CHANGES.md
berkeley/lpr.c
cups/dest.c
systemv/lp.c

index ff55182b5532a3748c5c905cd884a58dea8700cd..c67aba9305605a0d092b03b5ef077960710803ef 100644 (file)
@@ -5,13 +5,15 @@ CHANGES - 2.3b1 - 2017-11-01
 Changes in CUPS v2.3b1
 ----------------------
 
-- The lpstat command now reports when new jobs are being held (Issue #4761)
+- The `lpstat` command now reports when new jobs are being held (Issue #4761)
 - The scheduler now supports the "printer-id" attribute (Issue #4868)
 - No longer support backslash, question mark, or quotes in printer names
   (Issue #4966)
 - Dropped RSS subscription management from the web interface (Issue #5012)
-- The lpadmin command now provides a better error message when an unsupported
+- The `lp` and `lpr` commands now provide better error messages when the default
+  printer cannot be found (Issue #5096)
+- The `lpadmin` command now provides a better error message when an unsupported
   System V interface script is used (Issue #5111)
 - Dropped hard-coded CGI scripting language support (Issue #5124)
-- Fixed the ippserver sample code when threading is disabled or unavailable
+- Fixed the `ippserver` sample code when threading is disabled or unavailable
   (Issue #5154)
index e83f52e0b6257348879655d99a95995dfe8f5708..0081b795db01b6f6f49d24b2145e8404420b3078 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * "lpr" command for CUPS.
  *
- * Copyright 2007-2016 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products.
  *
  * These coded instructions, statements, and computer programs are the
@@ -32,8 +32,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
   char         *printer,               /* Destination printer or class */
                *instance,              /* Instance */
                *opt;                   /* Option pointer */
-  const char   *title,                 /* Job title */
-               *val;                   /* Environment variable name */
+  const char   *title;                 /* Job title */
   int          num_copies;             /* Number of copies per file */
   int          num_files;              /* Number of files to print */
   const char   *files[1000];           /* Files to print */
@@ -345,33 +344,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
   if (printer == NULL)
   {
-    val = NULL;
-
-    if ((printer = getenv("LPDEST")) == NULL)
-    {
-      if ((printer = getenv("PRINTER")) != NULL)
-      {
-        if (!strcmp(printer, "lp"))
-          printer = NULL;
-       else
-         val = "PRINTER";
-      }
-    }
-    else
-      val = "LPDEST";
-
-    if (printer && !cupsGetNamedDest(NULL, printer, NULL))
-      _cupsLangPrintf(stderr,
-                      _("%s: Error - %s environment variable names "
-                       "non-existent destination \"%s\"."), argv[0], val,
-                     printer);
-    else if (cupsLastError() == IPP_NOT_FOUND)
-      _cupsLangPrintf(stderr,
-                      _("%s: Error - no default destination available."),
-                     argv[0]);
+    if (!cupsGetNamedDest(NULL, NULL, NULL) && cupsLastError() == IPP_STATUS_ERROR_NOT_FOUND)
+      _cupsLangPrintf(stderr, _("%s: Error - %s"), argv[0], cupsLastErrorString());
     else
-      _cupsLangPrintf(stderr, _("%s: Error - scheduler not responding."),
-                     argv[0]);
+      _cupsLangPrintf(stderr, _("%s: Error - scheduler not responding."), argv[0]);
 
     return (1);
   }
index 57a8dc95cfac07367ee9318962bd249abeb16bc6..e91917ed2a3f37d5aaed5abc1e07687ce261f93a 100644 (file)
@@ -1883,6 +1883,9 @@ cupsGetNamedDest(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
       snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", home);
 
       dest_name = cups_get_default(filename, defname, sizeof(defname), &instance);
+
+      if (dest_name)
+        set_as_default = 2;
     }
 
     if (!dest_name)
@@ -1893,6 +1896,9 @@ cupsGetNamedDest(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
 
       snprintf(filename, sizeof(filename), "%s/lpoptions", cg->cups_serverroot);
       dest_name = cups_get_default(filename, defname, sizeof(defname), &instance);
+
+      if (dest_name)
+        set_as_default = 3;
     }
 
     if (!dest_name)
@@ -1901,7 +1907,8 @@ cupsGetNamedDest(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
       * No locally-set default destination, ask the server...
       */
 
-      op = IPP_OP_CUPS_GET_DEFAULT;
+      op             = IPP_OP_CUPS_GET_DEFAULT;
+      set_as_default = 4;
 
       DEBUG_puts("1cupsGetNamedDest: Asking server for default printer...");
     }
@@ -1932,7 +1939,36 @@ cupsGetNamedDest(http_t     *http,       /* I - Connection to server or @code CUPS_HTT
       dest = data.dest;
     }
     else
+    {
+      switch (set_as_default)
+      {
+        default :
+            break;
+
+        case 1 : /* Set from env vars */
+            if (getenv("LPDEST"))
+              _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, _("LPDEST environment variable names default destination that does not exist."), 1);
+           else if (getenv("PRINTER"))
+              _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, _("PRINTER environment variable names default destination that does not exist."), 1);
+           else
+              _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, _("No default destination."), 1);
+            break;
+
+        case 2 : /* Set from ~/.cups/lpoptions */
+           _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, _("~/.cups/lpoptions file names default destination that does not exist."), 1);
+            break;
+
+        case 3 : /* Set from /etc/cups/lpoptions */
+           _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, _("/etc/cups/lpoptions file names default destination that does not exist."), 1);
+            break;
+
+        case 4 : /* Set from server */
+           _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, _("No default destination."), 1);
+            break;
+      }
+
       return (NULL);
+    }
   }
 
   DEBUG_printf(("1cupsGetNamedDest: Got dest=%p", (void *)dest));
index 9672b080ae7990df0bebd024659b779afe8802b7..5033459d0b242d01ebcc1720056d0c980cfbd807 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * "lp" command for CUPS.
  *
- * Copyright 2007-2016 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products.
  *
  * These coded instructions, statements, and computer programs are the
@@ -586,33 +586,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
   if (printer == NULL)
   {
-    val = NULL;
-
-    if ((printer = getenv("LPDEST")) == NULL)
-    {
-      if ((printer = getenv("PRINTER")) != NULL)
-      {
-        if (!strcmp(printer, "lp"))
-          printer = NULL;
-       else
-         val = "PRINTER";
-      }
-    }
-    else
-      val = "LPDEST";
-
-    if (printer && !cupsGetNamedDest(NULL, printer, NULL))
-      _cupsLangPrintf(stderr,
-                     _("%s: Error - %s environment variable names "
-                       "non-existent destination \"%s\"."), argv[0], val,
-                     printer);
-    else if (cupsLastError() == IPP_NOT_FOUND)
-      _cupsLangPrintf(stderr,
-                     _("%s: Error - no default destination available."),
-                     argv[0]);
+    if (!cupsGetNamedDest(NULL, NULL, NULL) && cupsLastError() == IPP_STATUS_ERROR_NOT_FOUND)
+      _cupsLangPrintf(stderr, _("%s: Error - %s"), argv[0], cupsLastErrorString());
     else
-      _cupsLangPrintf(stderr, _("%s: Error - scheduler not responding."),
-                     argv[0]);
+      _cupsLangPrintf(stderr, _("%s: Error - scheduler not responding."), argv[0]);
 
     return (1);
   }