Skip to content

Commit 1544291

Browse files
author
David Herrmann
committed
sd-bus: do not connect to dbus-1 socket when kdbus is available
We should not fall back to dbus-1 and connect to the proxy when kdbus returns an error that indicates that kdbus is running but just does not accept new connections because of quota limits or something similar. Based on a patch by Kay.
1 parent 057171e commit 1544291

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/libsystemd/sd-bus/sd-bus.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,8 @@ static int bus_parse_next_address(sd_bus *b) {
10021002
}
10031003

10041004
static int bus_start_address(sd_bus *b) {
1005+
bool container_kdbus_available = false;
1006+
bool kdbus_available = false;
10051007
int r;
10061008

10071009
assert(b);
@@ -1011,15 +1013,29 @@ static int bus_start_address(sd_bus *b) {
10111013

10121014
bus_close_fds(b);
10131015

1016+
/*
1017+
* Usually, if you provide multiple different bus-addresses, we
1018+
* try all of them in order. We use the first one that
1019+
* succeeds. However, if you mix kernel and unix addresses, we
1020+
* never try unix-addresses if a previous kernel address was
1021+
* tried and kdbus was available. This is required to prevent
1022+
* clients to fallback to the bus-proxy if kdbus is available
1023+
* but failed (eg., too many connections).
1024+
*/
1025+
10141026
if (b->exec_path)
10151027
r = bus_socket_exec(b);
1016-
else if ((b->nspid > 0 || b->machine) && b->kernel)
1028+
else if ((b->nspid > 0 || b->machine) && b->kernel) {
10171029
r = bus_container_connect_kernel(b);
1018-
else if ((b->nspid > 0 || b->machine) && b->sockaddr.sa.sa_family != AF_UNSPEC)
1030+
if (r < 0 && !IN_SET(r, -ENOENT, -ESOCKTNOSUPPORT))
1031+
container_kdbus_available = true;
1032+
} else if (!container_kdbus_available && (b->nspid > 0 || b->machine) && b->sockaddr.sa.sa_family != AF_UNSPEC)
10191033
r = bus_container_connect_socket(b);
1020-
else if (b->kernel)
1034+
else if (b->kernel) {
10211035
r = bus_kernel_connect(b);
1022-
else if (b->sockaddr.sa.sa_family != AF_UNSPEC)
1036+
if (r < 0 && !IN_SET(r, -ENOENT, -ESOCKTNOSUPPORT))
1037+
kdbus_available = true;
1038+
} else if (!kdbus_available && b->sockaddr.sa.sa_family != AF_UNSPEC)
10231039
r = bus_socket_connect(b);
10241040
else
10251041
skipped = true;

0 commit comments

Comments
 (0)