summaryrefslogtreecommitdiff
path: root/init/src/kmods/load.rs
blob: 8ff0a59a5e6fc6e3c4bcfcbc9cd2a7592a255916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use liblmod::{modprobe, Selection};
use std::fs;

fn parse_modules() -> Result<Vec<String>, Box<dyn std::error::Error>> {
    let raw_mods = fs::read_to_string("/etc/modules")?
        .split(',')
        .map(|s| s.trim().to_string())
        .collect();

    Ok(raw_mods)
}

pub fn load_modules() -> Result<(), Box<dyn std::error::Error>> {
    let modules = parse_modules()?;

    for kmod in &modules {
        modprobe(kmod.to_string(), "".to_string(), Selection::Current)?;
    }

    Ok(())
}

// TODO: Think, is `rmmod` needed?