(socket_path: &Path, expected_uid: u32)
| 359 | |
| 360 | #[cfg(unix)] |
| 361 | fn remove_stale_socket(socket_path: &Path, expected_uid: u32) -> Result<()> { |
| 362 | let metadata = match std::fs::symlink_metadata(socket_path) { |
| 363 | Ok(metadata) => metadata, |
| 364 | Err(err) if err.kind() == ErrorKind::NotFound => return Ok(()), |
| 365 | Err(err) => { |
| 366 | return Err(Error::execution(format!( |
| 367 | "failed to stat vm compute driver socket '{}': {err}", |
| 368 | socket_path.display() |
| 369 | ))); |
| 370 | } |
| 371 | }; |
| 372 | let file_type = metadata.file_type(); |
| 373 | if file_type.is_symlink() { |
| 374 | return Err(Error::execution(format!( |
| 375 | "vm compute driver socket '{}' is a symlink; refusing to remove it", |
| 376 | socket_path.display() |
| 377 | ))); |
| 378 | } |
| 379 | if metadata.uid() != expected_uid { |
| 380 | return Err(Error::execution(format!( |
| 381 | "vm compute driver socket '{}' is owned by uid {} but current euid is {}", |
| 382 | socket_path.display(), |
| 383 | metadata.uid(), |
| 384 | expected_uid |
| 385 | ))); |
| 386 | } |
| 387 | if !file_type.is_socket() { |
| 388 | return Err(Error::execution(format!( |
| 389 | "vm compute driver socket path '{}' exists but is not a Unix socket", |
| 390 | socket_path.display() |
| 391 | ))); |
| 392 | } |
| 393 | std::fs::remove_file(socket_path).map_err(|err| { |
| 394 | Error::execution(format!( |
| 395 | "failed to remove stale vm compute driver socket '{}': {err}", |
| 396 | socket_path.display() |
| 397 | )) |
| 398 | }) |
| 399 | } |
| 400 | |
| 401 | #[cfg(unix)] |
| 402 | pub fn compute_driver_guest_tls_paths( |
no outgoing calls
no test coverage detected