Add a mock backend for testing (including on other compositors)
Should help determine which issues are cosmic-comp bugs.
This commit is contained in:
parent
170e102275
commit
c75a48535a
13 changed files with 397 additions and 184 deletions
51
src/utils.rs
Normal file
51
src/utils.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use rustix::{io::Errno, shm::ShmOFlags};
|
||||
use std::{
|
||||
os::fd::OwnedFd,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn create_memfd() -> rustix::io::Result<OwnedFd> {
|
||||
let fd = rustix::io::retry_on_intr(|| {
|
||||
rustix::fs::memfd_create(
|
||||
"cosmic-workspaces-shm",
|
||||
rustix::fs::MemfdFlags::CLOEXEC | rustix::fs::MemfdFlags::ALLOW_SEALING,
|
||||
)
|
||||
})?;
|
||||
let _ = rustix::fs::fcntl_add_seals(
|
||||
&fd,
|
||||
rustix::fs::SealFlags::SHRINK | rustix::fs::SealFlags::SEAL,
|
||||
);
|
||||
Ok(fd)
|
||||
}
|
||||
|
||||
pub fn create_memfile() -> rustix::io::Result<OwnedFd> {
|
||||
#[cfg(target_os = "linux")]
|
||||
if let Ok(fd) = create_memfd() {
|
||||
return Ok(fd);
|
||||
}
|
||||
|
||||
loop {
|
||||
let flags = ShmOFlags::CREATE | ShmOFlags::EXCL | ShmOFlags::RDWR;
|
||||
|
||||
let time = SystemTime::now();
|
||||
let name = format!(
|
||||
"/cosmic-workspaces-shm-{}",
|
||||
time.duration_since(UNIX_EPOCH).unwrap().subsec_nanos()
|
||||
);
|
||||
|
||||
match rustix::shm::shm_open(&name, flags, 0600.into()) {
|
||||
Ok(fd) => match rustix::shm::shm_unlink(&name) {
|
||||
Ok(_) => return Ok(fd),
|
||||
Err(errno) => {
|
||||
return Err(errno.into());
|
||||
}
|
||||
},
|
||||
#[allow(unreachable_patterns)]
|
||||
Err(Errno::EXIST | Errno::EXIST) => {
|
||||
continue;
|
||||
}
|
||||
Err(err) => return Err(err.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue