summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-03-04 00:52:40 +0900
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-03-03 21:17:38 +0100
commitdd0395b5654c52e982adf6d354db9c7fdcf4b6c7 (patch)
treea83a6f7757a495b3365bc32a38d0d14df7b28cb4
parentfbd6ac2601d628edf60c99cdf214e243b0b025ad (diff)
downloadsystemd-dd0395b5654c52e982adf6d354db9c7fdcf4b6c7.tar.gz
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.
-rw-r--r--src/core/dbus-util.h3
-rw-r--r--src/core/execute.c2
-rw-r--r--src/shared/bus-util.c2
-rw-r--r--src/shared/nsflags.c6
-rw-r--r--src/test/test-seccomp.c2
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);