]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: show Environment entries with whitespace 15345/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 6 Apr 2020 07:57:07 +0000 (09:57 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 9 Apr 2020 07:58:17 +0000 (09:58 +0200)
This makes the Environment entries more round-trippable: a similar format is
used for input and output. It is certainly more useful for users, because
showing [unprintable] on anything non-trivial makes systemctl show -p Environment
useless in many cases.

Fixes: #14723 and https://bugzilla.redhat.com/show_bug.cgi?id=1525593.
$ systemctl --user show -p Environment run-*.service
Environment=ASDF=asfd "SPACE= "
Environment=ASDF=asfd "SPACE=\n\n\n"
Environment=ASDF=asfd "TAB=\t\\" "FOO=X X"

src/shared/bus-util.c

index 4b0a3a3e317e23863a37dbdcbf67309b8291f96a..b4023dfbd4d3d4092e62b0e8e517de08ac22b8c2 100644 (file)
@@ -21,6 +21,7 @@
 #include "bus-util.h"
 #include "cap-list.h"
 #include "cgroup-util.h"
+#include "escape.h"
 #include "mountpoint-util.h"
 #include "nsflags.h"
 #include "parse-util.h"
@@ -500,18 +501,20 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
                                 return r;
 
                         while ((r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &str)) > 0) {
-                                bool good;
+                                _cleanup_free_ char *e = NULL;
 
-                                if (first && !value)
-                                        printf("%s=", name);
-
-                                /* This property has multiple space-separated values, so
-                                 * neither spaces nor newlines can be allowed in a value. */
-                                good = str[strcspn(str, " \n")] == '\0';
+                                e = shell_maybe_quote(str, ESCAPE_BACKSLASH_ONELINE);
+                                if (!e)
+                                        return -ENOMEM;
 
-                                printf("%s%s", first ? "" : " ", good ? str : "[unprintable]");
+                                if (first) {
+                                        if (!value)
+                                                printf("%s=", name);
+                                        first = false;
+                                } else
+                                        fputs(" ", stdout);
 
-                                first = false;
+                                fputs(e, stdout);
                         }
                         if (r < 0)
                                 return r;