(
mut monitor: event_monitor::Monitor,
seccomp_action: &SeccompAction,
landlock_enable: bool,
hypervisor_type: hypervisor::HypervisorType,
exit_event: EventFd,
)
| 388 | } |
| 389 | |
| 390 | pub fn start_event_monitor_thread( |
| 391 | mut monitor: event_monitor::Monitor, |
| 392 | seccomp_action: &SeccompAction, |
| 393 | landlock_enable: bool, |
| 394 | hypervisor_type: hypervisor::HypervisorType, |
| 395 | exit_event: EventFd, |
| 396 | ) -> Result<thread::JoinHandle<Result<()>>> { |
| 397 | // Retrieve seccomp filter |
| 398 | let seccomp_filter = get_seccomp_filter(seccomp_action, Thread::EventMonitor, hypervisor_type) |
| 399 | .map_err(Error::CreateSeccompFilter)?; |
| 400 | |
| 401 | thread::Builder::new() |
| 402 | .name("event-monitor".to_owned()) |
| 403 | .spawn(move || { |
| 404 | // Apply seccomp filter |
| 405 | if !seccomp_filter.is_empty() { |
| 406 | apply_filter(&seccomp_filter) |
| 407 | .map_err(Error::ApplySeccompFilter) |
| 408 | .inspect_err(|e| { |
| 409 | error!("Error applying seccomp filter: {e:?}"); |
| 410 | exit_event.write(1).ok(); |
| 411 | })?; |
| 412 | } |
| 413 | if landlock_enable { |
| 414 | Landlock::new() |
| 415 | .map_err(Error::CreateLandlock)? |
| 416 | .restrict_self() |
| 417 | .map_err(Error::ApplyLandlock) |
| 418 | .inspect_err(|e| { |
| 419 | error!("Error applying landlock to event monitor thread: {e:?}"); |
| 420 | exit_event.write(1).ok(); |
| 421 | })?; |
| 422 | } |
| 423 | |
| 424 | std::panic::catch_unwind(AssertUnwindSafe(move || { |
| 425 | while let Ok(event) = monitor.rx.recv() { |
| 426 | let event = Arc::new(event); |
| 427 | |
| 428 | if let Some(ref mut file) = monitor.file { |
| 429 | file.write_all(event.as_bytes().as_ref()).ok(); |
| 430 | file.write_all(b"\n\n").ok(); |
| 431 | } |
| 432 | |
| 433 | for tx in monitor.broadcast.iter() { |
| 434 | tx.send(event.clone()).ok(); |
| 435 | } |
| 436 | } |
| 437 | })) |
| 438 | .map_err(|_| { |
| 439 | error!("`event-monitor` thread panicked"); |
| 440 | exit_event.write(1).ok(); |
| 441 | }) |
| 442 | .ok(); |
| 443 | |
| 444 | Ok(()) |
| 445 | }) |
| 446 | .map_err(Error::EventMonitorThreadSpawn) |
| 447 | } |
no test coverage detected