teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0409-systemctl-suppress-errors-with-show-for-nonexistent-.patch

923a60
From 6d590cc99d696e9b0bf5b6edf7582b824f5177ab Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Sat, 24 Sep 2016 20:58:04 -0400
923a60
Subject: [PATCH] systemctl: suppress errors with "show" for nonexistent units
923a60
 and properties
923a60
923a60
Show is documented to be program-parseable, and printing the warning about
923a60
about a non-existent unit, while useful for humans, broke a lot of scripts.
923a60
Restore previous behaviour of returning success and printing empty or useless
923a60
stuff for units which do not exist, and printing empty values for properties
923a60
which do not exists.
923a60
923a60
With SYSTEMD_LOG_LEVEL=debug, hints are printed, but the return value is
923a60
still 0.
923a60
923a60
This undoes parts of e33a06a and 3dced37b7 and fixes #3856.
923a60
923a60
We might consider adding an explicit switch to fail on missing units/properties
923a60
(e.g. --ensure-exists or similar), and make -P foobar equivalent to
923a60
--ensure-exists --property=foobar.
923a60
923a60
Cherry-picked from: bd5b9f0a12dd9c1947b11534e99c395ddf44caa9
923a60
Resolves: #1380259
923a60
---
923a60
 src/systemctl/systemctl.c | 9 ++++++---
923a60
 1 file changed, 6 insertions(+), 3 deletions(-)
923a60
923a60
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
923a60
index 0644784a55..a578897d9e 100644
923a60
--- a/src/systemctl/systemctl.c
923a60
+++ b/src/systemctl/systemctl.c
923a60
@@ -4272,12 +4272,14 @@ static int show_one(
923a60
                         return log_error_errno(r, "Failed to map properties: %s", bus_error_message(&error, r));
923a60
 
923a60
                 if (streq_ptr(info.load_state, "not-found") && streq_ptr(info.active_state, "inactive")) {
923a60
-                        log_error("Unit %s could not be found.", unit);
923a60
+                        log_full(streq(verb, "status") ? LOG_ERR : LOG_DEBUG,
923a60
+                                 "Unit %s could not be found.", unit);
923a60
 
923a60
                         if (streq(verb, "status"))
923a60
                                 return EXIT_PROGRAM_OR_SERVICES_STATUS_UNKNOWN;
923a60
 
923a60
-                        return -ENOENT;
923a60
+                        if (!streq(verb, "show"))
923a60
+                                return -ENOENT;
923a60
                 }
923a60
 
923a60
                 r = sd_bus_message_rewind(reply, true);
923a60
@@ -4343,10 +4345,11 @@ static int show_one(
923a60
 
923a60
         if (show_properties) {
923a60
                 char **pp;
923a60
+                int not_found_level = streq(verb, "show") ? LOG_DEBUG : LOG_WARNING;
923a60
 
923a60
                 STRV_FOREACH(pp, arg_properties) {
923a60
                         if (!set_contains(found_properties, *pp)) {
923a60
-                                log_warning("Property %s does not exist.", *pp);
923a60
+                                log_full(not_found_level, "Property %s does not exist.", *pp);
923a60
                                 r = -ENXIO;
923a60
                         }
923a60
                 }