1
0
Fork 0
forked from wry/wry

xwayland: kill xwayland when wayland connection fails

This commit is contained in:
Julian Orth 2025-05-04 19:02:35 +02:00
parent 9840150e40
commit 8b9784bb15
6 changed files with 42 additions and 1 deletions

View file

@ -19,6 +19,7 @@ use {
numcell::NumCell,
pending_serial::PendingSerial,
pid_info::{PidInfo, get_pid_info, get_socket_creds},
pidfd_send_signal::pidfd_send_signal,
},
wire::WlRegistryId,
},
@ -251,6 +252,13 @@ impl Drop for ClientHolder {
self.data.surfaces_by_xwayland_serial.clear();
self.data.remove_activation_tokens();
self.data.commit_timelines.clear();
if self.data.is_xwayland {
if let Some(pidfd) = self.data.state.xwayland.pidfd.get() {
if let Err(e) = pidfd_send_signal(&pidfd, c::SIGKILL) {
log::error!("Could not kill Xwayland: {}", ErrorFmt(e));
}
}
}
}
}

View file

@ -218,6 +218,7 @@ fn start_compositor2(
run_args,
xwayland: XWaylandState {
enabled: Cell::new(true),
pidfd: Default::default(),
handler: Default::default(),
queue: Default::default(),
ipc_device_ids: Default::default(),

View file

@ -121,6 +121,7 @@ use {
time::Duration,
},
thiserror::Error,
uapi::OwnedFd,
};
pub struct State {
@ -261,6 +262,7 @@ pub struct ScreenlockState {
pub struct XWaylandState {
pub enabled: Cell<bool>,
pub pidfd: CloneCell<Option<Rc<OwnedFd>>>,
pub handler: RefCell<Option<SpawnedFuture<()>>>,
pub queue: Rc<AsyncQueue<XWaylandEvent>>,
pub ipc_device_ids: XIpcDeviceIds,

View file

@ -43,6 +43,7 @@ pub mod oserror;
pub mod page_size;
pub mod pending_serial;
pub mod pid_info;
pub mod pidfd_send_signal;
pub mod process_name;
pub mod ptr_ext;
pub mod queue;

View file

@ -0,0 +1,23 @@
use {
crate::utils::oserror::OsError,
c::{c_int, syscall},
std::{ptr, rc::Rc},
uapi::{
OwnedFd,
c::{self, SYS_pidfd_send_signal, siginfo_t},
map_err,
},
};
pub fn pidfd_send_signal(pidfd: &Rc<OwnedFd>, signal: c_int) -> Result<(), OsError> {
let res = unsafe {
syscall(
SYS_pidfd_send_signal,
pidfd.raw(),
signal,
ptr::null_mut::<siginfo_t>(),
0,
)
};
map_err!(res).map(drop).map_err(|e| e.into())
}

View file

@ -14,7 +14,9 @@ use {
io_uring::IoUringError,
state::State,
user_session::import_environment,
utils::{buf::Buf, errorfmt::ErrorFmt, line_logger::log_lines, oserror::OsError},
utils::{
buf::Buf, errorfmt::ErrorFmt, line_logger::log_lines, on_drop::OnDrop, oserror::OsError,
},
wire::WlSurfaceId,
xcon::XconError,
xwayland::{
@ -185,6 +187,10 @@ async fn run(
state.update_xwayland_wire_scale();
state.ring.readable(&Rc::new(dfdread)).await?;
state.xwayland.queue.clear();
state.xwayland.pidfd.set(Some(pidfd.clone()));
let _remove_pidfd = OnDrop(|| {
state.xwayland.pidfd.take();
});
{
let shared = Rc::new(XwmShared::default());
let wm = match Wm::get(state, client, wm1, &shared).await {