Skip to content

Commit 1e8ebd9

Browse files
poetteringbluca
authored andcommitted
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 (cherry picked from commit 08237f0) (cherry picked from commit 3126a5a) (cherry picked from commit 98584e8)
1 parent 29c801d commit 1e8ebd9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/login/logind-dbus.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ static int trigger_device(Manager *m, sd_device *d) {
13251325
return 0;
13261326
}
13271327

1328-
static int attach_device(Manager *m, const char *seat, const char *sysfs) {
1328+
static int attach_device(Manager *m, const char *seat, const char *sysfs, sd_bus_error *error) {
13291329
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
13301330
_cleanup_free_ char *rule = NULL, *file = NULL;
13311331
const char *id_for_seat;
@@ -1337,13 +1337,13 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) {
13371337

13381338
r = sd_device_new_from_syspath(&d, sysfs);
13391339
if (r < 0)
1340-
return r;
1340+
return sd_bus_error_set_errnof(error, r, "Failed to open device '%s': %m", sysfs);
13411341

13421342
if (sd_device_has_current_tag(d, "seat") <= 0)
1343-
return -ENODEV;
1343+
return sd_bus_error_set_errnof(error, ENODEV, "Device '%s' lacks 'seat' udev tag.", sysfs);
13441344

13451345
if (sd_device_get_property_value(d, "ID_FOR_SEAT", &id_for_seat) < 0)
1346-
return -ENODEV;
1346+
return sd_bus_error_set_errnof(error, ENODEV, "Device '%s' lacks 'ID_FOR_SEAT' udev property.", sysfs);
13471347

13481348
if (asprintf(&file, "/etc/udev/rules.d/72-seat-%s.rules", id_for_seat) < 0)
13491349
return -ENOMEM;
@@ -1428,7 +1428,7 @@ static int method_attach_device(sd_bus_message *message, void *userdata, sd_bus_
14281428
if (r == 0)
14291429
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
14301430

1431-
r = attach_device(m, seat, sysfs);
1431+
r = attach_device(m, seat, sysfs, error);
14321432
if (r < 0)
14331433
return r;
14341434

0 commit comments

Comments
 (0)