sd-bus: add custom return code when $XDG_RUNTIME_DIR is not set

We would return ENOENT, which is extremely confusing. Strace is not helpful because
no *file* is actually missing. So let's add some logs at debug level and also use
a custom return code. Let all user-facing utilities print a custom error message
in that case.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-10-14 18:28:30 +02:00
parent 165fee860a
commit ab4a88eb92
10 changed files with 28 additions and 14 deletions
+2 -1
View File
@@ -1340,7 +1340,8 @@ int bus_set_address_user(sd_bus *b) {
e = secure_getenv("XDG_RUNTIME_DIR");
if (!e)
return -ENOENT;
return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
"sd-bus: $XDG_RUNTIME_DIR not set, cannot connect to user bus.");
ee = bus_address_escape(e);
if (!ee)
+1 -1
View File
@@ -23,7 +23,7 @@ static int test_bus_open(void) {
int r;
r = sd_bus_open_user(&bus);
if (IN_SET(r, -ECONNREFUSED, -ENOENT)) {
if (IN_SET(r, -ECONNREFUSED, -ENOENT, -ENOMEDIUM)) {
r = sd_bus_open_system(&bus);
if (IN_SET(r, -ECONNREFUSED, -ENOENT))
return r;
+1 -1
View File
@@ -55,7 +55,7 @@ int main(int argc, char *argv[]) {
assert_se(r >= 0);
r = sd_bus_open_user(&a);
if (IN_SET(r, -ECONNREFUSED, -ENOENT)) {
if (IN_SET(r, -ECONNREFUSED, -ENOENT, -ENOMEDIUM)) {
r = sd_bus_open_system(&a);
if (IN_SET(r, -ECONNREFUSED, -ENOENT))
return log_tests_skipped("Failed to connect to bus");