tests: fix env guard and pipe read for tab dnd

This commit is contained in:
Stephan Buys 2025-11-20 11:23:49 +02:00 committed by Michael Murphy
parent 7f321cb0a3
commit ce0868582b
2 changed files with 27 additions and 14 deletions

View file

@ -9,18 +9,28 @@ use std::process::{Command, Stdio, exit};
#[cfg(feature = "tokio")]
use tokio::io::AsyncReadExt;
#[cfg(feature = "tokio")]
async fn read_from_pipe(read: OwnedFd) -> Option<u32> {
let mut read = tokio::net::unix::pipe::Receiver::from_owned_fd(read).unwrap();
read.read_u32().await.ok()
}
#[cfg(feature = "tokio")]
{
let mut read = tokio::net::unix::pipe::Receiver::from_owned_fd(read).unwrap();
return read.read_u32().await.ok();
}
#[cfg(all(feature = "smol", not(feature = "tokio")))]
async fn read_from_pipe(read: OwnedFd) -> Option<u32> {
let mut read = smol::Async::new(std::fs::File::from(read)).unwrap();
let mut bytes = [0; 4];
read.read_exact(&mut bytes).await.ok()?;
Some(u32::from_be_bytes(bytes))
#[cfg(all(feature = "smol", not(feature = "tokio")))]
{
let mut read = smol::Async::new(std::fs::File::from(read)).unwrap();
let mut bytes = [0; 4];
read.read_exact(&mut bytes).await.ok()?;
return Some(u32::from_be_bytes(bytes));
}
#[cfg(not(any(feature = "tokio", feature = "smol")))]
{
use rustix::fd::AsFd;
let mut bytes = [0u8; 4];
rustix::io::read(&read, &mut bytes).ok()?;
return Some(u32::from_be_bytes(bytes));
}
}
/// Performs a double fork with setsid to spawn and detach a command.