From 08237f062e9a2020c6d457a4112e363ee9ff879d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 5 Sep 2023 13:57:42 +0200 Subject: [PATCH] logind: give better error messages when failing to attach devices to seats When the user tries to attach a device lacking ID_FOR_SEAT they currently get a very cryptic error message. Let's improve the situation a bit. Still a bit cryptic maybe, but much less so. Inspired-by: https://lists.freedesktop.org/archives/systemd-devel/2023-September/049469.html Inspired-by: https://lists.freedesktop.org/archives/systemd-devel/2023-September/049484.html Also-see: https://lists.freedesktop.org/archives/systemd-devel/2023-September/049470.html Also-see: https://lists.freedesktop.org/archives/systemd-devel/2023-September/049489.html --- src/login/logind-dbus.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index b3a36d0d05..2d1af602c0 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1325,7 +1325,7 @@ static int trigger_device(Manager *m, sd_device *parent) { return 0; } -static int attach_device(Manager *m, const char *seat, const char *sysfs) { +static int attach_device(Manager *m, const char *seat, const char *sysfs, sd_bus_error *error) { _cleanup_(sd_device_unrefp) sd_device *d = NULL; _cleanup_free_ char *rule = NULL, *file = NULL; const char *id_for_seat; @@ -1337,13 +1337,13 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) { r = sd_device_new_from_syspath(&d, sysfs); if (r < 0) - return r; + return sd_bus_error_set_errnof(error, r, "Failed to open device '%s': %m", sysfs); if (sd_device_has_current_tag(d, "seat") <= 0) - return -ENODEV; + return sd_bus_error_set_errnof(error, ENODEV, "Device '%s' lacks 'seat' udev tag.", sysfs); if (sd_device_get_property_value(d, "ID_FOR_SEAT", &id_for_seat) < 0) - return -ENODEV; + return sd_bus_error_set_errnof(error, ENODEV, "Device '%s' lacks 'ID_FOR_SEAT' udev property.", sysfs); if (asprintf(&file, "/etc/udev/rules.d/72-seat-%s.rules", id_for_seat) < 0) return -ENOMEM; @@ -1428,7 +1428,7 @@ static int method_attach_device(sd_bus_message *message, void *userdata, sd_bus_ if (r == 0) return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ - r = attach_device(m, seat, sysfs); + r = attach_device(m, seat, sysfs, error); if (r < 0) return r; -- 2.25.1