]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/logind-device.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2011 Lennart Poettering
8 #include "alloc-util.h"
9 #include "logind-device.h"
12 Device
* device_new(Manager
*m
, const char *sysfs
, bool master
) {
22 d
->sysfs
= strdup(sysfs
);
26 if (hashmap_put(m
->devices
, d
->sysfs
, d
) < 0) {
33 dual_timestamp_get(&d
->timestamp
);
38 static void device_detach(Device
*d
) {
47 while ((sd
= d
->session_devices
))
48 session_device_free(sd
);
51 LIST_REMOVE(devices
, d
->seat
->devices
, d
);
54 if (!seat_has_master_device(s
)) {
55 seat_add_to_gc_queue(s
);
56 seat_send_changed(s
, "CanGraphical", NULL
);
60 void device_free(Device
*d
) {
65 hashmap_remove(d
->manager
->devices
, d
->sysfs
);
71 void device_attach(Device
*d
, Seat
*s
) {
85 had_master
= seat_has_master_device(s
);
87 /* We keep the device list sorted by the "master" flag. That is, master
88 * devices are at the front, other devices at the tail. As there is no
89 * way to easily add devices at the list-tail, we need to iterate the
90 * list to find the first non-master device when adding non-master
91 * devices. We assume there is only a few (normally 1) master devices
92 * per seat, so we iterate only a few times. */
94 if (d
->master
|| !s
->devices
)
95 LIST_PREPEND(devices
, s
->devices
, d
);
97 LIST_FOREACH(devices
, i
, s
->devices
) {
98 if (!i
->devices_next
|| !i
->master
) {
99 LIST_INSERT_AFTER(devices
, s
->devices
, i
, d
);
105 if (!had_master
&& d
->master
)
106 seat_send_changed(s
, "CanGraphical", NULL
);