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