]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/logind-device.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "alloc-util.h"
6 #include "logind-device.h"
7 #include "logind-seat-dbus.h"
10 Device
* device_new(Manager
*m
, const char *sysfs
, bool master
) {
20 d
->sysfs
= strdup(sysfs
);
24 if (hashmap_put(m
->devices
, d
->sysfs
, d
) < 0) {
31 dual_timestamp_get(&d
->timestamp
);
36 static void device_detach(Device
*d
) {
45 while ((sd
= d
->session_devices
))
46 session_device_free(sd
);
49 LIST_REMOVE(devices
, d
->seat
->devices
, d
);
52 if (!seat_has_master_device(s
)) {
53 seat_add_to_gc_queue(s
);
54 seat_send_changed(s
, "CanGraphical", NULL
);
58 void device_free(Device
*d
) {
63 hashmap_remove(d
->manager
->devices
, d
->sysfs
);
69 void device_attach(Device
*d
, Seat
*s
) {
83 had_master
= seat_has_master_device(s
);
85 /* We keep the device list sorted by the "master" flag. That is, master
86 * devices are at the front, other devices at the tail. As there is no
87 * way to easily add devices at the list-tail, we need to iterate the
88 * list to find the first non-master device when adding non-master
89 * devices. We assume there is only a few (normally 1) master devices
90 * per seat, so we iterate only a few times. */
92 if (d
->master
|| !s
->devices
)
93 LIST_PREPEND(devices
, s
->devices
, d
);
95 LIST_FOREACH(devices
, i
, s
->devices
) {
96 if (!i
->devices_next
|| !i
->master
) {
97 LIST_INSERT_AFTER(devices
, s
->devices
, i
, d
);
102 if (!had_master
&& d
->master
&& s
->started
) {
104 seat_send_changed(s
, "CanGraphical", NULL
);