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,11 +511,13 @@ impl<A: ControlDevice + 'static> Drop for DrmDevice<A> {
); );
} }
} }
if let Err(err) = self.drop_master() { if self.priviledged {
error!( if let Err(err) = self.drop_master() {
self.logger, error!(
"Failed to drop drm master state. Error: {}", err self.logger,
); "Failed to drop drm master state. Error: {}", err
);
}
} }
} }
} }
@ -606,11 +613,13 @@ impl<A: ControlDevice + 'static> SessionObserver for StateToken<DrmDevice<A>> {
} }
} }
device.active = false; device.active = false;
if let Err(err) = device.drop_master() { if device.priviledged {
error!( if let Err(err) = device.drop_master() {
device.logger, error!(
"Failed to drop drm master state. Error: {}", err device.logger,
); "Failed to drop drm master state. Error: {}", err
);
}
} }
} }
@ -622,16 +631,19 @@ 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 let Err(err) = device.set_master() { if device.priviledged {
crit!( if let Err(err) = device.set_master() {
device.logger, crit!(
"Failed to acquire drm master again. Error: {}", device.logger,
err "Failed to acquire drm master again. Error: {}",
); 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() {