kanit

Toy init system
Log | Files | Refs | README | LICENSE

procfs.rs (1060B)


      1 use std::path::Path;
      2 
      3 use async_trait::async_trait;
      4 use blocking::unblock;
      5 use log::info;
      6 use nix::mount::{MsFlags, mount};
      7 
      8 use kanit_common::error::{Context, Result};
      9 use kanit_unit::Unit;
     10 
     11 use crate::mounts::try_mount_from_fstab;
     12 use crate::unit_name;
     13 
     14 pub struct ProcFs;
     15 
     16 #[async_trait]
     17 impl Unit for ProcFs {
     18     unit_name!("procfs");
     19 
     20     async fn start(&mut self) -> Result<()> {
     21         // check if proc is already mounted
     22         if Path::new("/proc/mounts").exists() {
     23             info!("procfs already mounted");
     24             return Ok(());
     25         }
     26 
     27         info!("mounting /proc");
     28 
     29         let path = Path::new("/proc");
     30 
     31         if try_mount_from_fstab(path).await? {
     32             return Ok(());
     33         }
     34 
     35         unblock(move || {
     36             mount(
     37                 Some("none"),
     38                 path,
     39                 Some("proc"),
     40                 MsFlags::MS_NODEV | MsFlags::MS_NOEXEC | MsFlags::MS_NOSUID,
     41                 Some(""),
     42             )
     43         })
     44         .await
     45         .context("failed to mount procfs")?;
     46 
     47         Ok(())
     48     }
     49 }