]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: give better error messages when failing to attach devices to seats
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Sep 2023 11:57:42 +0000 (13:57 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 5 Sep 2023 16:57:57 +0000 (17:57 +0100)
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

index b3a36d0d058df4682387d70e3eba5f8564b932be..2d1af602c0b81cc9af0717c2cc53e9b38680203e 100644 (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;