summaryrefslogtreecommitdiff
path: root/init/src/processes/udev.rs
blob: 7cb6a5d78094bd273ebd489ce2281b6f7ea108ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::process::Command;

// TODO: Rewrite this bad fn
pub fn spawn_udev() -> Result<(), Box<dyn std::error::Error>> {
    let udevd_paths = [
        "/sbin/udevd",
        "/usr/sbin/udevd",
        "/bin/udevd",
        "/usr/bin/udevd",
    ];
    let udevd_path = udevd_paths
        .iter()
        .find(|path| std::path::Path::new(path).exists())
        .ok_or_else(|| -> Box<dyn std::error::Error> {
            "udevd not found in standard locations".into()
        })?;

    let mut child = Command::new(udevd_path).arg("--daemon").spawn().map_err(
        |e| -> Box<dyn std::error::Error> { format!("Failed to spawn udevd: {}", e).into() },
    )?;

    child.wait()?;

    Command::new(udevd_path).arg("--trigger").output().map_err(
        |e| -> Box<dyn std::error::Error> { format!("Failed to trigger udev: {}", e).into() },
    )?;

    Ok(())
}