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