diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-08 17:07:07 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-08 17:07:42 +0100 |
commit | 41dd15e474accdeb643c8319e257e6414c1c498a (patch) | |
tree | 5757389744be5088baf215738493fbb15a2833d2 /src/libsystemd-bus | |
parent | 3f41e1e5955552a771748225334b3e8a7eb02b8a (diff) |
systemctl: restore ability to directly connect to PID1 from systemctl
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r-- | src/libsystemd-bus/bus-util.c | 75 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-util.h | 2 |
2 files changed, 77 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c index 2cf718b096..3dd208d0c1 100644 --- a/src/libsystemd-bus/bus-util.c +++ b/src/libsystemd-bus/bus-util.c @@ -440,6 +440,46 @@ int bus_open_system_systemd(sd_bus **_bus) { return 0; } +int bus_open_user_systemd(sd_bus **_bus) { + _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_free_ char *p = NULL; + const char *e; + int r; + + /* If we are supposed to talk to the instance, try via + * XDG_RUNTIME_DIR first, then fallback to normal bus + * access */ + + assert(_bus); + + e = secure_getenv("XDG_RUNTIME_DIR"); + if (e) { + if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) + return -ENOMEM; + } + + r = sd_bus_new(&bus); + if (r < 0) + return r; + + r = sd_bus_set_address(bus, p); + if (r < 0) + return r; + + r = sd_bus_start(bus); + if (r < 0) + return r; + + r = bus_check_peercred(bus); + if (r < 0) + return r; + + *_bus = bus; + bus = NULL; + + return 0; +} + int bus_print_property(const char *name, sd_bus_message *property, bool all) { char type; const char *contents; @@ -924,6 +964,41 @@ int bus_open_transport(BusTransport transport, const char *host, bool user, sd_b return r; } +int bus_open_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus) { + int r; + + assert(transport >= 0); + assert(transport < _BUS_TRANSPORT_MAX); + assert(bus); + + assert_return((transport == BUS_TRANSPORT_LOCAL) == !host, -EINVAL); + assert_return(transport == BUS_TRANSPORT_LOCAL || !user, -ENOTSUP); + + switch (transport) { + + case BUS_TRANSPORT_LOCAL: + if (user) + r = bus_open_user_systemd(bus); + else + r = bus_open_system_systemd(bus); + + break; + + case BUS_TRANSPORT_REMOTE: + r = sd_bus_open_system_remote(host, bus); + break; + + case BUS_TRANSPORT_CONTAINER: + r = sd_bus_open_system_container(host, bus); + break; + + default: + assert_not_reached("Hmm, unknown transport type."); + } + + return r; +} + int bus_property_get_bool( sd_bus *bus, const char *path, diff --git a/src/libsystemd-bus/bus-util.h b/src/libsystemd-bus/bus-util.h index 21a483fb01..314c2f7867 100644 --- a/src/libsystemd-bus/bus-util.h +++ b/src/libsystemd-bus/bus-util.h @@ -63,8 +63,10 @@ int bus_verify_polkit_async(sd_bus *bus, Hashmap **registry, sd_bus_message *m, void bus_verify_polkit_async_registry_free(sd_bus *bus, Hashmap *registry); int bus_open_system_systemd(sd_bus **_bus); +int bus_open_user_systemd(sd_bus **_bus); int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus); +int bus_open_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus); int bus_print_property(const char *name, sd_bus_message *property, bool all); int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all); |