chiark / gitweb /
systemctl: return an error code is status fails
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 10 May 2014 01:44:25 +0000 (03:44 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 10 May 2014 01:44:41 +0000 (03:44 +0200)
This got lost in the refactoring in f74294c1dabb4.

Also make sure that the return code corresponds to the *first* failure,
not the last.

https://lists.fedoraproject.org/pipermail/devel/2014-May/199080.html

src/systemctl/systemctl.c

index 7bc8ece0424c3f063caebe822424e292d0e58836..e1e4640ae8f47ef6d3419360eb73ba5f157dae92 100644 (file)
@@ -4285,7 +4285,7 @@ static int show_all(
         _cleanup_free_ UnitInfo *unit_infos = NULL;
         const UnitInfo *u;
         unsigned c;
-        int r;
+        int r, ret = 0;
 
         r = get_unit_list(bus, NULL, NULL, &unit_infos, 0, &reply);
         if (r < 0)
@@ -4307,9 +4307,11 @@ static int show_all(
                 r = show_one(verb, bus, p, show_properties, new_line, ellipsized);
                 if (r < 0)
                         return r;
+                else if (r > 0 && ret == 0)
+                        ret = r;
         }
 
-        return 0;
+        return ret;
 }
 
 static int show_system_status(sd_bus *bus) {
@@ -4431,7 +4433,12 @@ static int show(sd_bus *bus, char **args) {
                                 }
                         }
 
-                        show_one(args[0], bus, unit, show_properties, &new_line, &ellipsized);
+                        r = show_one(args[0], bus, unit, show_properties,
+                                     &new_line, &ellipsized);
+                        if (r < 0)
+                                return r;
+                        else if (r > 0 && ret == 0)
+                                ret = r;
                 }
 
                 if (!strv_isempty(patterns)) {
@@ -4448,7 +4455,12 @@ static int show(sd_bus *bus, char **args) {
                                 if (!unit)
                                         return log_oom();
 
-                                show_one(args[0], bus, unit, show_properties, &new_line, &ellipsized);
+                                r = show_one(args[0], bus, unit, show_properties,
+                                             &new_line, &ellipsized);
+                                if (r < 0)
+                                        return r;
+                                else if (r > 0 && ret == 0)
+                                        ret = r;
                         }
                 }
         }