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
This commit is contained in:
Lennart Poettering
2023-09-05 13:57:42 +02:00
committed by Luca Boccassi
parent 6c22badfce
commit 08237f062e

View File

@@ -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;