mirror of
https://github.com/systemd/systemd
synced 2024-09-18 15:42:03 +00:00
sd-bus: internalize setting of bus is_system/is_user
Each of bus_set_address_{user,system} had two users, and each of the two users would set the internal flag manually. We should do that internally in the functions instead. While at it, only set the flag when setting the address is actually successful. This doesn't change anything for current users, but it seems more correct.
This commit is contained in:
parent
0406d1a843
commit
062ac2ea85
|
@ -110,13 +110,10 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) {
|
|||
switch (arg_transport) {
|
||||
|
||||
case BUS_TRANSPORT_LOCAL:
|
||||
if (arg_user) {
|
||||
bus->is_user = true;
|
||||
if (arg_user)
|
||||
r = bus_set_address_user(bus);
|
||||
} else {
|
||||
bus->is_system = true;
|
||||
else
|
||||
r = bus_set_address_system(bus);
|
||||
}
|
||||
break;
|
||||
|
||||
case BUS_TRANSPORT_REMOTE:
|
||||
|
|
|
@ -1266,10 +1266,16 @@ _public_ int sd_bus_open(sd_bus **ret) {
|
|||
|
||||
int bus_set_address_system(sd_bus *b) {
|
||||
const char *e;
|
||||
int r;
|
||||
|
||||
assert(b);
|
||||
|
||||
e = secure_getenv("DBUS_SYSTEM_BUS_ADDRESS");
|
||||
return sd_bus_set_address(b, e ?: DEFAULT_SYSTEM_BUS_ADDRESS);
|
||||
|
||||
r = sd_bus_set_address(b, e ?: DEFAULT_SYSTEM_BUS_ADDRESS);
|
||||
if (r >= 0)
|
||||
b->is_system = true;
|
||||
return r;
|
||||
}
|
||||
|
||||
_public_ int sd_bus_open_system_with_description(sd_bus **ret, const char *description) {
|
||||
|
@ -1293,7 +1299,6 @@ _public_ int sd_bus_open_system_with_description(sd_bus **ret, const char *descr
|
|||
return r;
|
||||
|
||||
b->bus_client = true;
|
||||
b->is_system = true;
|
||||
|
||||
/* Let's do per-method access control on the system bus. We
|
||||
* need the caller's UID and capability set for that. */
|
||||
|
@ -1316,6 +1321,7 @@ _public_ int sd_bus_open_system(sd_bus **ret) {
|
|||
int bus_set_address_user(sd_bus *b) {
|
||||
const char *a;
|
||||
_cleanup_free_ char *_a = NULL;
|
||||
int r;
|
||||
|
||||
assert(b);
|
||||
|
||||
|
@ -1337,7 +1343,10 @@ int bus_set_address_user(sd_bus *b) {
|
|||
a = _a;
|
||||
}
|
||||
|
||||
return sd_bus_set_address(b, a);
|
||||
r = sd_bus_set_address(b, a);
|
||||
if (r >= 0)
|
||||
b->is_user = true;
|
||||
return r;
|
||||
}
|
||||
|
||||
_public_ int sd_bus_open_user_with_description(sd_bus **ret, const char *description) {
|
||||
|
@ -1361,7 +1370,6 @@ _public_ int sd_bus_open_user_with_description(sd_bus **ret, const char *descrip
|
|||
return r;
|
||||
|
||||
b->bus_client = true;
|
||||
b->is_user = true;
|
||||
|
||||
/* We don't do any per-method access control on the user bus. */
|
||||
b->trusted = true;
|
||||
|
|
Loading…
Reference in a new issue