From 241c4b6adae3ec015f69b34174511e6912d1f0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 6 Apr 2020 09:57:07 +0200 Subject: [PATCH] systemctl: show Environment entries with whitespace 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 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 4b0a3a3e317..b4023dfbd4d 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -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); + e = shell_maybe_quote(str, ESCAPE_BACKSLASH_ONELINE); + if (!e) + return -ENOMEM; - /* This property has multiple space-separated values, so - * neither spaces nor newlines can be allowed in a value. */ - good = str[strcspn(str, " \n")] == '\0'; + if (first) { + if (!value) + printf("%s=", name); + first = false; + } else + fputs(" ", stdout); - printf("%s%s", first ? "" : " ", good ? str : "[unprintable]"); - - first = false; + fputs(e, stdout); } if (r < 0) return r;