From f4ac0102b7ecca8686eb2c70d20d12978ea5d880 Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Tue, 8 Jun 2021 12:29:46 +0200 Subject: [PATCH] driverless: Changed way to emit exit code 0 when no printer found --- utils/driverless.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/utils/driverless.c b/utils/driverless.c index 8d500dd77..125600f30 100644 --- a/utils/driverless.c +++ b/utils/driverless.c @@ -532,13 +532,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; } @@ -573,7 +573,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) { @@ -583,7 +587,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); @@ -594,7 +598,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 -- 2.47.3