923a60
From f3b1b4ae42a2d0d6383c6587a842418abad645a9 Mon Sep 17 00:00:00 2001
923a60
From: Lukas Nykryn <lnykryn@redhat.com>
923a60
Date: Mon, 25 Jan 2016 15:21:28 +0100
923a60
Subject: [PATCH] systemctl: is-active/failed should return 0 if at least one
923a60
 unit is in given state
923a60
923a60
Previously we have return the not-found code, in the case that we found a
923a60
unit which does not belong to set active (resp. failed), which is the
923a60
opposite than what is written in man page.
923a60
923a60
Cherry-picked from: d60f6ad0cb690d920b8acbfb545bad29554609f1
923a60
Resolves: #1254650
923a60
---
923a60
 src/systemctl/systemctl.c | 9 ++++++---
923a60
 1 file changed, 6 insertions(+), 3 deletions(-)
923a60
923a60
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
923a60
index 5d3a85fd95..bf5bb398b7 100644
923a60
--- a/src/systemctl/systemctl.c
923a60
+++ b/src/systemctl/systemctl.c
923a60
@@ -3002,6 +3002,7 @@ static int check_unit_generic(sd_bus *bus, int code, const char *good_states, ch
923a60
         _cleanup_strv_free_ char **names = NULL;
923a60
         char **name;
923a60
         int r;
923a60
+        bool found = false;
923a60
 
923a60
         assert(bus);
923a60
         assert(args);
923a60
@@ -3016,11 +3017,13 @@ static int check_unit_generic(sd_bus *bus, int code, const char *good_states, ch
923a60
                 state = check_one_unit(bus, *name, good_states, arg_quiet);
923a60
                 if (state < 0)
923a60
                         return state;
923a60
-                if (state == 0)
923a60
-                        r = code;
923a60
+                if (state > 0)
923a60
+                        found = true;
923a60
         }
923a60
 
923a60
-        return r;
923a60
+        /* use the given return code for the case that we won't find
923a60
+         * any unit which matches the list */
923a60
+        return found ? 0 : code;
923a60
 }
923a60
 
923a60
 static int check_unit_active(sd_bus *bus, char **args) {