]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
driverless: Changed way to emit exit code 0 when no printer found
authorTill Kamppeter <till.kamppeter@gmail.com>
Tue, 8 Jun 2021 10:29:46 +0000 (12:29 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Tue, 15 Jun 2021 18:58:19 +0000 (20:58 +0200)
(cherry picked from commit f4ac0102b7ecca8686eb2c70d20d12978ea5d880)

utils/driverless.c

index 294d466f0dc1e99eeb5880c85fb22cd38ea161a6..c59cd8686412e106a79237363972ebe1ba476aa1 100644 (file)
@@ -531,13 +531,13 @@ list_printers (int mode, int reg_type_no, int isFax)
       if (errno != EAGAIN && errno != EINTR)
       {
        perror("ERROR: Unable to read ippfind output");
-       exit_status = -1;
+       exit_status = 1;
        goto error;
       }
     }
   } else {
     perror("ERROR: Unable to open ippfind output data stream");
-    exit_status = -1;
+    exit_status = 1;
     goto error;
   }
 
@@ -572,7 +572,11 @@ list_printers (int mode, int reg_type_no, int isFax)
   if (WIFEXITED(wait_status)) {
     /* Via exit() anywhere or return() in the main() function */
     exit_status = WEXITSTATUS(wait_status);
-    if (exit_status > 1)
+    /* if we get 1 from ippfind, it is actually a correct value, not an error,
+     * because CUPS backends return 0 if they don't find any queues */
+    if (exit_status == 1)
+      exit_status = 0;
+    if (exit_status)
       fprintf(stderr, "ERROR: ippfind (PID %d) stopped with status %d!\n",
              ippfind_pid, exit_status);
   } else if (WIFSIGNALED(wait_status) && WTERMSIG(wait_status) != SIGTERM) {
@@ -582,7 +586,7 @@ list_printers (int mode, int reg_type_no, int isFax)
       fprintf(stderr, "ERROR: ippfind (PID %d) stopped on signal %d!\n",
              ippfind_pid, exit_status);
   }
-  if (exit_status < 2 && debug)
+  if (!exit_status && debug)
     fprintf(stderr, "DEBUG: ippfind (PID %d) exited with no errors.\n",
            ippfind_pid);
 
@@ -593,7 +597,7 @@ list_printers (int mode, int reg_type_no, int isFax)
  error:
   cupsArrayDelete(service_uri_list_ipps);
   cupsArrayDelete(service_uri_list_ipp);
-  return (exit_status < 2 ? 0 : exit_status);
+  return (exit_status);
 }
 
 int