From 92f90837dc0e9da685212954bc254e975b3adb48 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sat, 28 Dec 2019 12:29:19 +0100 Subject: [PATCH] systemctl: skip non-existent units in the 'cat' verb 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 (cherry picked from commit a25457f5b7689265bd2235c4da218896e7c5c1d0) (cherry picked from commit 8b1bd17469892de5838509c6794a8a38432c01b0) --- src/systemctl/systemctl.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 1a98bcbd92..44fb1acbe0 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -5877,7 +5877,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 */ @@ -5922,8 +5922,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; @@ -5949,7 +5953,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) { -- 2.25.1