From 68361b25d1032e1fd020aae630593108e84158af Mon Sep 17 00:00:00 2001 From: Ferdinand Schober Date: Mon, 5 Aug 2024 14:16:45 +0200 Subject: [PATCH] fix crash due to dropped fd (#167) --- input-capture/src/wayland.rs | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/input-capture/src/wayland.rs b/input-capture/src/wayland.rs index 90974ee..a667afc 100644 --- a/input-capture/src/wayland.rs +++ b/input-capture/src/wayland.rs @@ -1,11 +1,10 @@ use async_trait::async_trait; use futures_core::Stream; -use memmap::MmapOptions; use std::{ collections::VecDeque, env, io::{self, ErrorKind}, - os::fd::{AsFd, OwnedFd, RawFd}, + os::fd::{AsFd, RawFd}, pin::Pin, task::{ready, Context, Poll}, }; @@ -14,7 +13,7 @@ use tokio::io::unix::AsyncFd; use std::{ fs::File, io::{BufWriter, Write}, - os::unix::prelude::{AsRawFd, FromRawFd}, + os::unix::prelude::AsRawFd, sync::Arc, }; @@ -108,7 +107,7 @@ struct State { client_for_window: Vec<(Arc, CaptureHandle)>, focused: Option<(Arc, CaptureHandle)>, g: Globals, - wayland_fd: OwnedFd, + wayland_fd: RawFd, read_guard: Option, qh: QueueHandle, pending_events: VecDeque<(CaptureHandle, Event)>, @@ -123,7 +122,7 @@ struct Inner { impl AsRawFd for Inner { fn as_raw_fd(&self) -> RawFd { - self.state.wayland_fd.as_raw_fd() + self.state.wayland_fd } } @@ -308,10 +307,7 @@ impl WaylandInputCapture { // flush outgoing events queue.flush()?; - // prepare reading wayland events - let read_guard = queue.prepare_read().unwrap(); // there can not yet be events to dispatch - let wayland_fd = read_guard.connection_fd().try_clone_to_owned().unwrap(); - std::mem::drop(read_guard); + let wayland_fd = queue.as_fd().as_raw_fd(); let mut state = State { pointer: None, @@ -820,15 +816,6 @@ impl Dispatch for State { )); } } - wl_keyboard::Event::Keymap { - format: _, - fd, - size: _, - } => { - let fd = unsafe { &File::from_raw_fd(fd.as_raw_fd()) }; - let _mmap = unsafe { MmapOptions::new().map_copy(fd).unwrap() }; - // TODO keymap - } _ => (), } }