Skip to content

Commit

Permalink
Merge pull request #298 from mahkoh/jorth/drm-blocking
Browse files Browse the repository at this point in the history
metal: unset O_NONBLOCK for DRM file descriptors
  • Loading branch information
mahkoh authored Oct 19, 2024
2 parents 2a3a924 + 3f00158 commit b7b3227
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/backends/metal/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use {
dbus::{DbusError, TRUE},
udev::UdevDevice,
utils::{
bitflags::BitflagsExt, cell_ext::CellExt, errorfmt::ErrorFmt, nonblock::set_nonblock,
bitflags::BitflagsExt,
cell_ext::CellExt,
errorfmt::ErrorFmt,
nonblock::{set_block, set_nonblock},
},
video::drm::DrmMaster,
wire_dbus::org::freedesktop::login1::session::{
Expand Down Expand Up @@ -236,6 +239,12 @@ impl MetalBackend {
return;
}
};
if let Err(e) = set_block(res.fd.raw()) {
log::error!(
"Could not set drm file descriptor to blocking: {}",
ErrorFmt(e),
);
}
let master = match DrmMaster::new(&slf.state.ring, res.fd.clone()) {
Ok(m) => Rc::new(m),
Err(e) => {
Expand Down
8 changes: 7 additions & 1 deletion src/utils/nonblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ use {crate::utils::oserror::OsError, uapi::c};

pub fn set_nonblock(fd: c::c_int) -> Result<(), OsError> {
let fl = uapi::fcntl_getfl(fd)?;
uapi::fcntl_setfl(fd, fl | c::SOCK_NONBLOCK)?;
uapi::fcntl_setfl(fd, fl | c::O_NONBLOCK)?;
Ok(())
}

pub fn set_block(fd: c::c_int) -> Result<(), OsError> {
let fl = uapi::fcntl_getfl(fd)?;
uapi::fcntl_setfl(fd, fl & !c::O_NONBLOCK)?;
Ok(())
}

0 comments on commit b7b3227

Please sign in to comment.