From: Lennart Poettering Date: Tue, 5 Sep 2023 11:57:42 +0000 (+0200) Subject: logind: give better error messages when failing to attach devices to seats X-Git-Tag: v255-rc1~580 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=08237f062e9a2020c6d457a4112e363ee9ff879d;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index b3a36d0d058..2d1af602c0b 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;