daandemeyer / rpms / systemd

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