redox-drm: graceful exit when scheme:drm already registered
When pcid-spawner launches redox-drm for a GPU device, the init service (10_redox-drm.service) may also start a second instance. The guard check in the service file (head -c 1 /scheme/drm/card0) has a race condition with pcid-spawner's scheme registration. Move the scheme:drm existence check into the binary itself. If scheme:drm is already registered when run() starts, log and exit gracefully with daemon.ready() instead of crashing with a fatal "no GPU found" error.
This commit is contained in:
@@ -59,6 +59,12 @@ fn init_logging(level: LevelFilter) {
|
||||
}
|
||||
|
||||
fn run(daemon: daemon::Daemon) -> Result<()> {
|
||||
if is_scheme_registered("drm") {
|
||||
info!("redox-drm: scheme:drm already registered, another instance is active");
|
||||
daemon.ready();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let info = select_gpu_from_args()?;
|
||||
verify_supported_gpu(&info)?;
|
||||
|
||||
@@ -174,6 +180,10 @@ fn create_drm_socket() -> Result<Socket> {
|
||||
.map_err(|e| DriverError::Initialization(format!("failed to register drm scheme: {e}")))
|
||||
}
|
||||
|
||||
fn is_scheme_registered(name: &str) -> bool {
|
||||
std::fs::read_dir(format!("/scheme/{}", name)).is_ok()
|
||||
}
|
||||
|
||||
fn select_gpu_from_args() -> Result<PciDeviceInfo> {
|
||||
let mut args = env::args().skip(1);
|
||||
let parsed = match (args.next(), args.next(), args.next()) {
|
||||
|
||||
Reference in New Issue
Block a user