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.
This commit is contained in:
Yu Watanabe 2020-03-04 00:52:40 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent fbd6ac2601
commit dd0395b565
5 changed files with 5 additions and 10 deletions

View File

@ -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; \

View File

@ -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)

View File

@ -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);

View File

@ -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;

View File

@ -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);