When integration-test get SIGKILLed, also SIGKILL the vuinputd-process

This commit is contained in:
Johannes Leupolz 2025-12-17 21:30:33 +00:00
parent d86a90e2b1
commit 01417e6934

View file

@ -3,22 +3,21 @@
// Author: Johannes Leupolz <dev@leupolz.eu>
use std::{
os::unix::process::CommandExt,
process::{Child, Command},
sync::OnceLock,
time::Duration,
thread,
time::Duration,
};
use nix::sys::signal::{self,Signal};
use nix::sys::signal::{self, Signal};
use nix::unistd::Pid;
/// Global singleton
static VUINPUTD: OnceLock<VuinputdGuard> = OnceLock::new();
pub fn ensure_vuinputd_running() {
VUINPUTD.get_or_init(|| {
VuinputdGuard::start()
});
VUINPUTD.get_or_init(|| VuinputdGuard::start());
}
struct VuinputdGuard {
@ -28,14 +27,31 @@ struct VuinputdGuard {
impl VuinputdGuard {
fn start() -> Self {
println!("Executing vuinputd located via cargo run");
let child = Command::new("cargo")
.args(["run", "-p", "vuinputd", "--","--major","120","--minor","414796","--devname","vuinputd-test"])
// adjust args/env if needed
.spawn()
.expect("failed to start vuinputd");
let child = unsafe {
Command::new("cargo")
.args([
"run",
"-p",
"vuinputd",
"--",
"--major",
"120",
"--minor",
"414796",
"--devname",
"vuinputd-test",
])
.pre_exec(|| {
// Last resort, if the parent just is killed.
libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGKILL);
Ok(())
})
.spawn()
.expect("failed to start vuinputd")
};
// Optional: give it time to create /dev/vuinput
thread::sleep(Duration::from_millis(300));
thread::sleep(Duration::from_millis(1000));
Self { child }
}