mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-06-14 14:32:57 -04:00
drm: Rework device removal signal
By moving the remove signal right before where we assert that the assert signal list is empty, we create a strict contract requiring the remove signals to remove themselves. We ensure this is true by calling `backend_destroy()` upon removal, making sure that we don't double free the device fd. Signed-off-by: liupeng <liupeng01@kylinos.cn>
This commit is contained in:
parent
36cd9344e1
commit
510cda868d
2 changed files with 14 additions and 7 deletions
|
|
@ -227,14 +227,19 @@ static int handle_udev_event(int fd, uint32_t mask, void *data) {
|
|||
}
|
||||
}
|
||||
} else if (strcmp(action, "remove") == 0) {
|
||||
bool found = false;
|
||||
struct wlr_device *dev;
|
||||
wl_list_for_each(dev, &session->devices, link) {
|
||||
if (dev->dev == devnum) {
|
||||
wlr_log(WLR_DEBUG, "DRM device %s removed", sysname);
|
||||
wl_signal_emit_mutable(&dev->events.remove, NULL);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
wlr_log(WLR_DEBUG, "DRM device %s removed", sysname);
|
||||
wlr_session_close_file(session, dev);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
|
|
@ -375,11 +380,10 @@ void wlr_session_close_file(struct wlr_session *session,
|
|||
wlr_log_errno(WLR_ERROR, "Failed to close device %d", dev->device_id);
|
||||
}
|
||||
|
||||
wl_signal_emit_mutable(&dev->events.remove, NULL);
|
||||
|
||||
assert(wl_list_empty(&dev->events.change.listener_list));
|
||||
// TODO: assert that the "remove" listener list is empty as well. Listeners
|
||||
// will typically call wlr_session_close_file() in response, and
|
||||
// wl_signal_emit_mutable() installs two phantom listeners, so we'd count
|
||||
// these two.
|
||||
assert(wl_list_empty(&dev->events.remove.listener_list));
|
||||
|
||||
close(dev->fd);
|
||||
wl_list_remove(&dev->link);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue