Skip to content

Commit

Permalink
Remove inappropriate 'use super::*'
Browse files Browse the repository at this point in the history
  • Loading branch information
StanPlatinum committed Jun 5, 2024
1 parent dab6a85 commit 0a798b1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
26 changes: 20 additions & 6 deletions kernel/aster-nix/src/fs/procfs/pid/cmdline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// SPDX-License-Identifier: MPL-2.0

use super::*;
use crate::{
fs::{
procfs::template::{FileOps, ProcFileBuilder},
utils::Inode,
},
prelude::*,
Process,
};

/// Represents the inode at `/proc/[pid]/cmdline`.
pub struct CmdlineFileOps(Arc<Process>);
Expand All @@ -16,11 +23,18 @@ impl CmdlineFileOps {

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

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)
}
}
9 changes: 8 additions & 1 deletion kernel/aster-nix/src/fs/procfs/pid/comm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// SPDX-License-Identifier: MPL-2.0

use super::*;
use crate::{
fs::{
procfs::template::{FileOps, ProcFileBuilder},
utils::Inode,
},
prelude::*,
Process,
};

/// Represents the inode at `/proc/[pid]/comm`.
pub struct CommFileOps(Arc<Process>);
Expand Down
9 changes: 8 additions & 1 deletion kernel/aster-nix/src/fs/procfs/pid/exe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// SPDX-License-Identifier: MPL-2.0

use super::*;
use crate::{
fs::{
procfs::{ProcSymBuilder, SymOps},
utils::Inode,
},
prelude::*,
Process,
};

/// Represents the inode at `/proc/[pid]/exe`.
pub struct ExeSymOps(Arc<Process>);
Expand Down
15 changes: 13 additions & 2 deletions kernel/aster-nix/src/fs/procfs/pid/fd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
// SPDX-License-Identifier: MPL-2.0

use super::*;
use crate::fs::{file_handle::FileLike, file_table::FileDesc, inode_handle::InodeHandle};
use crate::{
fs::{
file_handle::FileLike,
file_table::FileDesc,
inode_handle::InodeHandle,
procfs::{
pid::FdEvents, DirOps, Observer, ProcDir, ProcDirBuilder, ProcSymBuilder, SymOps,
},
utils::{DirEntryVecExt, Inode},
},
prelude::*,
Process,
};

/// Represents the inode at `/proc/[pid]/fd`.
pub struct FdDirOps(Arc<Process>);
Expand Down
4 changes: 1 addition & 3 deletions kernel/aster-nix/src/fs/procfs/pid/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// SPDX-License-Identifier: MPL-2.0

use self::{cmdline::CmdlineFileOps, comm::CommFileOps, exe::ExeSymOps, fd::FdDirOps};
use super::template::{
DirOps, FileOps, ProcDir, ProcDirBuilder, ProcFileBuilder, ProcSymBuilder, SymOps,
};
use super::template::{DirOps, ProcDir, ProcDirBuilder};
use crate::{
events::Observer,
fs::{
Expand Down

0 comments on commit 0a798b1

Please sign in to comment.