X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fbus-util.c;h=0b77d3f85d411548b2fbe91ccd714721d000908b;hp=4f1b68f6ea17e69f2a54623bdbdc3fbbe46ace8d;hb=a61ff8a1eea921800d6225ff137b24e0a0fb60e1;hpb=d46558812b735184c1c9b2a13c7b3587d6c1e271 diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 4f1b68f6e..0b77d3f85 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -679,7 +679,7 @@ int bus_connect_user_systemd(sd_bus **_bus) { if (r < 0) return r; - bus->address = strjoin("unix:path=", ee, "/systemd/private", NULL); + bus->address = strjoin("unix:path=", ee, "/systemd/private"); if (!bus->address) return -ENOMEM; @@ -773,6 +773,23 @@ int bus_print_property(const char *name, sd_bus_message *property, bool value, b char timespan[FORMAT_TIMESPAN_MAX]; print_property(name, "%s", format_timespan(timespan, sizeof(timespan), u, 0)); + } else if (streq(name, "RestrictNamespaces")) { + _cleanup_free_ char *s = NULL; + const char *result = NULL; + + if ((u & NAMESPACE_FLAGS_ALL) == 0) + result = "yes"; + else if ((u & NAMESPACE_FLAGS_ALL) == NAMESPACE_FLAGS_ALL) + result = "no"; + else { + r = namespace_flag_to_string_many(u, &s); + if (r < 0) + return r; + + result = s; + } + + print_property(name, "%s", result); } else print_property(name, "%"PRIu64, u); @@ -1236,12 +1253,13 @@ int bus_map_all_properties( return bus_message_map_all_properties(m, map, userdata); } -int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) { +int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **ret) { + _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL; int r; assert(transport >= 0); assert(transport < _BUS_TRANSPORT_MAX); - assert(bus); + assert(ret); assert_return((transport == BUS_TRANSPORT_LOCAL) == !host, -EINVAL); assert_return(transport == BUS_TRANSPORT_LOCAL || !user, -EOPNOTSUPP); @@ -1251,26 +1269,35 @@ int bus_connect_transport(BusTransport transport, const char *host, bool user, s case BUS_TRANSPORT_LOCAL: #if 0 /// elogind does not support a user bus if (user) - r = sd_bus_default_user(bus); + r = sd_bus_default_user(&bus); else #endif // 0 - r = sd_bus_default_system(bus); + r = sd_bus_default_system(&bus); break; case BUS_TRANSPORT_REMOTE: - r = sd_bus_open_system_remote(bus, host); + r = sd_bus_open_system_remote(&bus, host); break; case BUS_TRANSPORT_MACHINE: - r = sd_bus_open_system_machine(bus, host); + r = sd_bus_open_system_machine(&bus, host); break; default: assert_not_reached("Hmm, unknown transport type."); } + if (r < 0) + return r; - return r; + r = sd_bus_set_exit_on_disconnect(bus, true); + if (r < 0) + return r; + + *ret = bus; + bus = NULL; + + return 0; } #if 0 /// UNNEEDED by elogind @@ -1324,6 +1351,25 @@ int bus_property_get_bool( return sd_bus_message_append_basic(reply, 'b', &b); } +#if 0 /// UNNEEDED by elogind +int bus_property_get_id128( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + sd_id128_t *id = userdata; + + if (sd_id128_is_null(*id)) /* Add an empty array if the ID is zero */ + return sd_bus_message_append(reply, "ay", 0); + else + return sd_bus_message_append_array(reply, 'y', id->bytes, 16); +} +#endif // 0 + #if __SIZEOF_SIZE_T__ != 8 int bus_property_get_size( sd_bus *bus, @@ -1446,7 +1492,7 @@ int bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, if (!external_label) return -ENOMEM; - p = strjoin(prefix, "/", sender_label, "/", external_label, NULL); + p = strjoin(prefix, "/", sender_label, "/", external_label); if (!p) return -ENOMEM; @@ -1554,3 +1600,22 @@ int bus_property_get_rlimit( return sd_bus_message_append(reply, "t", u); } #endif // 0 + +int bus_track_add_name_many(sd_bus_track *t, char **l) { + int r = 0; + char **i; + + assert(t); + + /* Continues adding after failure, and returns the first failure. */ + + STRV_FOREACH(i, l) { + int k; + + k = sd_bus_track_add_name(t, *i); + if (k < 0 && r >= 0) + r = k; + } + + return r; +}