1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-18 06:03:42 +03:00

Merge pull request #1160 from dvdhrm/bus-user

sd-bus: derive uid from cgroup if possible
This commit is contained in:
Kay Sievers 2015-09-05 23:06:31 +02:00
commit 718909ec33

View File

@ -1241,6 +1241,8 @@ fail:
int bus_set_address_user(sd_bus *b) { int bus_set_address_user(sd_bus *b) {
const char *e; const char *e;
uid_t uid;
int r;
assert(b); assert(b);
@ -1248,6 +1250,10 @@ int bus_set_address_user(sd_bus *b) {
if (e) if (e)
return sd_bus_set_address(b, e); return sd_bus_set_address(b, e);
r = cg_pid_get_owner_uid(0, &uid);
if (r < 0)
uid = getuid();
e = secure_getenv("XDG_RUNTIME_DIR"); e = secure_getenv("XDG_RUNTIME_DIR");
if (e) { if (e) {
_cleanup_free_ char *ee = NULL; _cleanup_free_ char *ee = NULL;
@ -1256,9 +1262,9 @@ int bus_set_address_user(sd_bus *b) {
if (!ee) if (!ee)
return -ENOMEM; return -ENOMEM;
(void) asprintf(&b->address, KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT, getuid(), ee); (void) asprintf(&b->address, KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT, uid, ee);
} else } else
(void) asprintf(&b->address, KERNEL_USER_BUS_ADDRESS_FMT, getuid()); (void) asprintf(&b->address, KERNEL_USER_BUS_ADDRESS_FMT, uid);
if (!b->address) if (!b->address)
return -ENOMEM; return -ENOMEM;