]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: skip non-existent units in the 'cat' verb
authorFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 28 Dec 2019 11:29:19 +0000 (12:29 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 2 Jan 2020 14:27:25 +0000 (15:27 +0100)
When processing list of units (either provided manually or as a
wildcard), let's skip units for which we don't have an on-disk
counterpart, but note the -ENOENT error code and propagate it back to
the user.

Fixes: #14082
src/systemctl/systemctl.c

index 20e0d453d2a1f4f911d8a45a9407101dfd47d121..3e4fc46154de339639cb46070de9534eab28da55 100644 (file)
@@ -5937,7 +5937,7 @@ static int cat(int argc, char *argv[], void *userdata) {
         char **name;
         sd_bus *bus;
         bool first = true;
-        int r;
+        int r, rc = 0;
 
         /* Include all units by default — i.e. continue as if the --all
          * option was used */
@@ -5982,8 +5982,12 @@ static int cat(int argc, char *argv[], void *userdata) {
                 }
                 if (r < 0)
                         return r;
-                if (r == 0)
-                        return -ENOENT;
+                if (r == 0) {
+                        /* Skip units which have no on-disk counterpart, but
+                         * propagate the error to the user */
+                        rc = -ENOENT;
+                        continue;
+                }
 
                 if (first)
                         first = false;
@@ -6009,7 +6013,7 @@ static int cat(int argc, char *argv[], void *userdata) {
                         return r;
         }
 
-        return 0;
+        return rc;
 }
 
 static int set_property(int argc, char *argv[], void *userdata) {