diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-30 03:53:42 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-30 03:53:42 +0100 |
commit | e3dd987cfc395848256fc6eae637ed0eaf5f1635 (patch) | |
tree | 5e265370b750c3f552f55f8a3417df8658a263b6 /src/libsystemd-bus/sd-bus.c | |
parent | 32f464809e8e487739fde53a2feb0afba70c8db7 (diff) |
core: allocate a kdbus bus for each systemd instance, if we can
Diffstat (limited to 'src/libsystemd-bus/sd-bus.c')
-rw-r--r-- | src/libsystemd-bus/sd-bus.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c index 8ffc9a9eff..0d5deb6c6d 100644 --- a/src/libsystemd-bus/sd-bus.c +++ b/src/libsystemd-bus/sd-bus.c @@ -986,15 +986,13 @@ _public_ int sd_bus_open_system(sd_bus **ret) { return r; e = secure_getenv("DBUS_SYSTEM_BUS_ADDRESS"); - if (e) { + if (e) r = sd_bus_set_address(b, e); - if (r < 0) - goto fail; - } else { - b->sockaddr.un.sun_family = AF_UNIX; - strncpy(b->sockaddr.un.sun_path, "/run/dbus/system_bus_socket", sizeof(b->sockaddr.un.sun_path)); - b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + sizeof("/run/dbus/system_bus_socket") - 1; - } + else + r = sd_bus_set_address(b, "kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket"); + + if (r < 0) + goto fail; b->bus_client = true; @@ -1013,7 +1011,6 @@ fail: _public_ int sd_bus_open_user(sd_bus **ret) { const char *e; sd_bus *b; - size_t l; int r; assert_return(ret, -EINVAL); @@ -1029,20 +1026,23 @@ _public_ int sd_bus_open_user(sd_bus **ret) { goto fail; } else { e = secure_getenv("XDG_RUNTIME_DIR"); - if (!e) { - r = -ENOENT; - goto fail; - } + if (e) { + _cleanup_free_ char *ee = NULL; + + ee = bus_address_escape(e); + if (!ee) { + r = -ENOENT; + goto fail; + } - l = strlen(e); - if (l + 4 > sizeof(b->sockaddr.un.sun_path)) { - r = -E2BIG; + asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus;unix:path=%s/bus", (unsigned long) getuid(), ee); + } else + asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus", (unsigned long) getuid()); + + if (!b->address) { + r = -ENOMEM; goto fail; } - - b->sockaddr.un.sun_family = AF_UNIX; - memcpy(mempcpy(b->sockaddr.un.sun_path, e, l), "/bus", 4); - b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + l + 4; } b->bus_client = true; |