Fix trying to become drm master on logind session

This commit is contained in:
Drakulix 2018-01-27 13:05:36 +01:00
parent 11c9f2b0fb
commit 495c492e50
1 changed files with 30 additions and 18 deletions

View File

@ -251,6 +251,7 @@ pub struct DrmDevice<A: ControlDevice + 'static> {
device_id: dev_t,
backends: HashMap<crtc::Handle, Weak<DrmBackendInternal<A>>>,
active: bool,
priviledged: bool,
logger: ::slog::Logger,
}
@ -319,13 +320,17 @@ impl<A: ControlDevice + 'static> DrmDevice<A> {
device_id,
old_state: HashMap::new(),
active: true,
priviledged: true,
logger: log.clone(),
};
info!(log, "DrmDevice initializing");
// we want to mode-set, so we better be the master
drm.set_master().chain_err(|| ErrorKind::DrmMasterFailed)?;
// we want to mode-set, so we better be the master, if we run via a tty session
if let Err(_) = drm.set_master() {
warn!(log, "Unable to become drm master, assuming unpriviledged mode");
drm.priviledged = false;
};
let res_handles = drm.resource_handles().chain_err(|| {
ErrorKind::DrmDev(format!(
@ -506,6 +511,7 @@ impl<A: ControlDevice + 'static> Drop for DrmDevice<A> {
);
}
}
if self.priviledged {
if let Err(err) = self.drop_master() {
error!(
self.logger,
@ -513,6 +519,7 @@ impl<A: ControlDevice + 'static> Drop for DrmDevice<A> {
);
}
}
}
}
/// Handler for drm node events
@ -606,6 +613,7 @@ impl<A: ControlDevice + 'static> SessionObserver for StateToken<DrmDevice<A>> {
}
}
device.active = false;
if device.priviledged {
if let Err(err) = device.drop_master() {
error!(
device.logger,
@ -613,6 +621,7 @@ impl<A: ControlDevice + 'static> SessionObserver for StateToken<DrmDevice<A>> {
);
}
}
}
fn activate<'a>(&mut self, state: &mut StateProxy<'a>, devnum: Option<(u32, u32, Option<RawFd>)>) {
let device = state.get_mut(self);
@ -622,10 +631,12 @@ impl<A: ControlDevice + 'static> SessionObserver for StateToken<DrmDevice<A>> {
{
return;
} else if let Some(fd) = fd {
info!(device.logger, "Replacing fd");
nix::unistd::dup2(device.as_raw_fd(), fd).expect("Failed to replace file descriptor of drm device");
}
}
device.active = true;
if device.priviledged {
if let Err(err) = device.set_master() {
crit!(
device.logger,
@ -633,6 +644,7 @@ impl<A: ControlDevice + 'static> SessionObserver for StateToken<DrmDevice<A>> {
err
);
}
}
let mut crtcs = Vec::new();
for (crtc, backend) in device.backends.iter() {
if let Some(backend) = backend.upgrade() {