Skip to content

Commit

Permalink
Add /proc/[pid]/cmdline support
Browse files Browse the repository at this point in the history
  • Loading branch information
Weijie Liu committed Jun 1, 2024
1 parent 8e874e6 commit b869c33
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
26 changes: 26 additions & 0 deletions kernel/aster-nix/src/fs/procfs/pid/cmdline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MPL-2.0

use super::*;

/// Represents the inode at `/proc/[pid]/cmdline`.
pub struct CmdlineFileOps(Arc<Process>);

impl CmdlineFileOps {
pub fn new_inode(process_ref: Arc<Process>, parent: Weak<dyn Inode>) -> Arc<dyn Inode> {
ProcFileBuilder::new(Self(process_ref))
.parent(parent)
.build()
.unwrap()
}
}

impl FileOps for CmdlineFileOps {
fn data(&self) -> Result<Vec<u8>> {
let exe_path = self.0.executable_path();

let mut cmdline_output = exe_path.into_bytes();
cmdline_output.push(0); // Append a single NUL character at the end

Ok(cmdline_output)
}
}
9 changes: 7 additions & 2 deletions kernel/aster-nix/src/fs/procfs/pid/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0

use self::{comm::CommFileOps, exe::ExeSymOps, fd::FdDirOps};
use self::{cmdline::CmdlineFileOps, comm::CommFileOps, exe::ExeSymOps, fd::FdDirOps};
use super::template::{
DirOps, FileOps, ProcDir, ProcDirBuilder, ProcFileBuilder, ProcSymBuilder, SymOps,
};
Expand All @@ -14,6 +14,7 @@ use crate::{
process::Process,
};

mod cmdline;
mod comm;
mod exe;
mod fd;
Expand Down Expand Up @@ -51,6 +52,7 @@ impl DirOps for PidDirOps {
"exe" => ExeSymOps::new_inode(self.0.clone(), this_ptr.clone()),
"comm" => CommFileOps::new_inode(self.0.clone(), this_ptr.clone()),
"fd" => FdDirOps::new_inode(self.0.clone(), this_ptr.clone()),
"cmdline" => CmdlineFileOps::new_inode(self.0.clone(), this_ptr.clone()),
_ => return_errno!(Errno::ENOENT),
};
Ok(inode)
Expand All @@ -70,6 +72,9 @@ impl DirOps for PidDirOps {
});
cached_children.put_entry_if_not_found("fd", || {
FdDirOps::new_inode(self.0.clone(), this_ptr.clone())
})
});
cached_children.put_entry_if_not_found("cmdline", || {
CmdlineFileOps::new_inode(self.0.clone(), this_ptr.clone())
});
}
}

0 comments on commit b869c33

Please sign in to comment.