From dd0395b5654c52e982adf6d354db9c7fdcf4b6c7 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 4 Mar 2020 00:52:40 +0900 Subject: make namespace_flags_to_string() not return empty string This improves the following debug log. Before: systemd[1162]: Restricting namespace to: . After: systemd[1162]: Restricting namespace to: n/a. --- src/core/dbus-util.h | 3 ++- src/core/execute.c | 2 +- src/shared/bus-util.c | 2 +- src/shared/nsflags.c | 6 ------ src/test/test-seccomp.c | 2 +- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/core/dbus-util.h b/src/core/dbus-util.h index a3316c6701..ec8c245fff 100644 --- a/src/core/dbus-util.h +++ b/src/core/dbus-util.h @@ -127,7 +127,8 @@ int bus_property_get_triggered_unit(sd_bus *bus, const char *path, const char *i if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \ *p = (cast_type) v; \ unit_write_settingf(u, flags, name, \ - "%s=%s", name, s); \ + "%s=%s", \ + name, strempty(s)); \ } \ \ return 1; \ diff --git a/src/core/execute.c b/src/core/execute.c index 76e1b28d37..4595bb12dc 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -4881,7 +4881,7 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) { r = namespace_flags_to_string(c->restrict_namespaces, &s); if (r >= 0) fprintf(f, "%sRestrictNamespaces: %s\n", - prefix, s); + prefix, strna(s)); } if (c->network_namespace_path) diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 15bc0ed71b..8e6a6e2ce2 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -406,7 +406,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b if (r < 0) return r; - result = s; + result = strempty(s); } bus_print_property_value(name, expected_value, value, result); diff --git a/src/shared/nsflags.c b/src/shared/nsflags.c index 8cc2d0873d..4dbd18b868 100644 --- a/src/shared/nsflags.c +++ b/src/shared/nsflags.c @@ -65,12 +65,6 @@ int namespace_flags_to_string(unsigned long flags, char **ret) { return -ENOMEM; } - if (!s) { - s = strdup(""); - if (!s) - return -ENOMEM; - } - *ret = TAKE_PTR(s); return 0; diff --git a/src/test/test-seccomp.c b/src/test/test-seccomp.c index 75566199e3..67900d85e9 100644 --- a/src/test/test-seccomp.c +++ b/src/test/test-seccomp.c @@ -190,7 +190,7 @@ static void test_restrict_namespace(void) { log_info("/* %s */", __func__); - assert_se(namespace_flags_to_string(0, &s) == 0 && streq(s, "")); + assert_se(namespace_flags_to_string(0, &s) == 0 && isempty(s)); s = mfree(s); assert_se(namespace_flags_to_string(CLONE_NEWNS, &s) == 0 && streq(s, "mnt")); s = mfree(s); -- cgit v1.2.1