This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=8fcf649f9c8bd5bbc58ccd1527eca22892447045

commit 8fcf649f9c8bd5bbc58ccd1527eca22892447045
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Fri Feb 16 05:15:02 2024 +0100

    dpkg-query: Fix exit codes for --show
    
    The manual page states that (most) dpkg-query commands will return 0 for
    success, 1 for files or packages not being found, and 2 for fatal errors.
    But the code was coercing the return values from each function into a
    boolean, which meant that the --show command would not return 2 on parse
    errors for the --showformat.
    
    Move the coercion into each command function, and map the format error
    in --show into a proper 2.
    
    Closes: #1064036
---
 src/query/main.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/query/main.c b/src/query/main.c
index 7f8de5901..e237b9867 100644
--- a/src/query/main.c
+++ b/src/query/main.c
@@ -290,7 +290,7 @@ listpackages(const char *const *argv)
   pkg_array_destroy(&array);
   modstatdb_shutdown();
 
-  return rc;
+  return !!rc;
 }
 
 static int
@@ -388,7 +388,7 @@ searchfiles(const char *const *argv)
 
   varbuf_destroy(&path);
 
-  return failures;
+  return !!failures;
 }
 
 static int
@@ -435,7 +435,7 @@ print_status(const char *const *argv)
 
   modstatdb_shutdown();
 
-  return failures;
+  return !!failures;
 }
 
 static int
@@ -474,7 +474,7 @@ print_avail(const char *const *argv)
 
   modstatdb_shutdown();
 
-  return failures;
+  return !!failures;
 }
 
 static int
@@ -542,7 +542,7 @@ list_files(const char *const *argv)
 
   modstatdb_shutdown();
 
-  return failures;
+  return !!failures;
 }
 
 static void
@@ -572,8 +572,7 @@ showpackages(const char *const *argv)
   if (!fmt) {
     notice(_("error in show format: %s"), err.str);
     dpkg_error_destroy(&err);
-    rc++;
-    return rc;
+    return 2;
   }
 
   fmt_needs_db_fsys = pkg_format_needs_db_fsys(fmt);
@@ -612,7 +611,7 @@ showpackages(const char *const *argv)
   pkg_format_free(fmt);
   modstatdb_shutdown();
 
-  return rc;
+  return !!rc;
 }
 
 static bool
@@ -883,5 +882,5 @@ int main(int argc, const char *const *argv) {
   dpkg_program_done();
   dpkg_locales_done();
 
-  return !!ret;
+  return ret;
 }

-- 
Dpkg.Org's dpkg

Reply via email to