summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/home/pam_systemd_home.c4
-rw-r--r--src/shared/bus-polkit.c6
-rw-r--r--src/shared/bus-util.c10
-rw-r--r--src/shared/bus-util.h1
-rw-r--r--src/sleep/sleep.c7
5 files changed, 16 insertions, 12 deletions
diff --git a/src/home/pam_systemd_home.c b/src/home/pam_systemd_home.c
index 2c2c7a0819..13b164ecfc 100644
--- a/src/home/pam_systemd_home.c
+++ b/src/home/pam_systemd_home.c
@@ -7,6 +7,7 @@
#include "bus-common-errors.h"
#include "bus-locator.h"
+#include "bus-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "home-util.h"
@@ -153,8 +154,7 @@ static int acquire_user_record(
r = bus_call_method(bus, bus_home_mgr, "GetUserRecordByName", &error, &reply, "s", username);
if (r < 0) {
- if (sd_bus_error_has_name(&error, SD_BUS_ERROR_SERVICE_UNKNOWN) ||
- sd_bus_error_has_name(&error, SD_BUS_ERROR_NAME_HAS_NO_OWNER)) {
+ if (bus_error_is_unknown_service(&error)) {
pam_syslog(handle, LOG_DEBUG, "systemd-homed is not available: %s", bus_error_message(&error, r));
goto user_unknown;
}
diff --git a/src/shared/bus-polkit.c b/src/shared/bus-polkit.c
index 9b0a4552be..0722b1a118 100644
--- a/src/shared/bus-polkit.c
+++ b/src/shared/bus-polkit.c
@@ -3,6 +3,7 @@
#include "bus-internal.h"
#include "bus-message.h"
#include "bus-polkit.h"
+#include "bus-util.h"
#include "strv.h"
#include "user-util.h"
@@ -123,7 +124,7 @@ int bus_test_polkit(
r = sd_bus_call(call->bus, request, 0, ret_error, &reply);
if (r < 0) {
/* Treat no PK available as access denied */
- if (sd_bus_error_has_name(ret_error, SD_BUS_ERROR_SERVICE_UNKNOWN)) {
+ if (bus_error_is_unknown_service(ret_error)) {
sd_bus_error_free(ret_error);
return -EACCES;
}
@@ -296,8 +297,7 @@ int bus_verify_polkit_async(
e = sd_bus_message_get_error(q->reply);
/* Treat no PK available as access denied */
- if (sd_bus_error_has_name(e, SD_BUS_ERROR_SERVICE_UNKNOWN) ||
- sd_bus_error_has_name(e, SD_BUS_ERROR_NAME_HAS_NO_OWNER))
+ if (bus_error_is_unknown_service(e))
return -EACCES;
/* Copy error from polkit reply */
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index 77c1c62182..9a306daa03 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -14,14 +14,13 @@
#include "sd-event.h"
#include "sd-id128.h"
-/* #include "alloc-util.h" */
+#include "bus-common-errors.h"
#include "bus-internal.h"
#include "bus-label.h"
#include "bus-util.h"
#include "path-util.h"
#include "socket-util.h"
#include "stdio-util.h"
-/* #include "string-util.h" */
static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
sd_event *e = userdata;
@@ -153,6 +152,13 @@ int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error) {
return has_owner;
}
+bool bus_error_is_unknown_service(const sd_bus_error *error) {
+ return sd_bus_error_has_names(error,
+ SD_BUS_ERROR_SERVICE_UNKNOWN,
+ SD_BUS_ERROR_NAME_HAS_NO_OWNER,
+ BUS_ERROR_NO_SUCH_UNIT);
+}
+
int bus_check_peercred(sd_bus *c) {
struct ucred ucred;
int fd, r;
diff --git a/src/shared/bus-util.h b/src/shared/bus-util.h
index d98e0040f3..9b86f9526e 100644
--- a/src/shared/bus-util.h
+++ b/src/shared/bus-util.h
@@ -28,6 +28,7 @@ typedef bool (*check_idle_t)(void *userdata);
int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout, check_idle_t check_idle, void *userdata);
int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error);
+bool bus_error_is_unknown_service(const sd_bus_error *error);
int bus_check_peercred(sd_bus *c);
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 7029352ca5..cf7e238ad4 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -160,11 +160,8 @@ static int lock_all_homes(void) {
r = sd_bus_call(bus, m, DEFAULT_TIMEOUT_USEC, &error, NULL);
if (r < 0) {
- if (sd_bus_error_has_name(&error, SD_BUS_ERROR_SERVICE_UNKNOWN) ||
- sd_bus_error_has_name(&error, SD_BUS_ERROR_NAME_HAS_NO_OWNER)) {
- log_debug("systemd-homed is not running, skipping locking of home directories.");
- return 0;
- }
+ if (bus_error_is_unknown_service(&error))
+ return log_debug("systemd-homed is not running, skipping locking of home directories.");
return log_error_errno(r, "Failed to lock home directories: %s", bus_error_message(&error, r));
}