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