-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Weijie Liu
committed
Jun 12, 2024
1 parent
c6aa9f9
commit 5a12f11
Showing
5 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
use crate::{ | ||
fs::{ | ||
procfs::template::{FileOps, ProcFileBuilder}, | ||
utils::Inode, | ||
}, | ||
prelude::*, | ||
Process, | ||
}; | ||
|
||
/// 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 cmdline_output = if self.0.is_zombie() { | ||
// Returns 0 characters for zombie process. | ||
Vec::new() | ||
} else { | ||
let Ok(argv_cstrs) = self.0.vm().init_stack_reader().argv() else { | ||
return Ok(Vec::new()); | ||
}; | ||
argv_cstrs | ||
.into_iter() | ||
.flat_map(|c_str| c_str.into_bytes_with_nul().into_iter()) | ||
.collect() | ||
}; | ||
Ok(cmdline_output) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters