Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not panic when /proc/modules does not exist #139

Merged
merged 6 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/kernel/lkm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::util;
use bytesize::ByteSize;
use clap::ArgMatches;
use ratatui::text::{Line, Span, Text};
use std::error::Error;
use std::slice::Iter;

/* Type of the sorting of module list */
Expand Down Expand Up @@ -99,12 +100,14 @@ impl KernelModules<'_> {
args,
style,
};
kernel_modules.refresh();
if let Err(e) = kernel_modules.refresh() {
eprintln!("{e}");
}
kernel_modules
}

/* Parse kernel modules from '/proc/modules'. */
pub fn refresh(&mut self) {
pub fn refresh(&mut self) -> Result<(), Box<dyn Error>> {
let mut module_list: Vec<Vec<String>> = Vec::new();
/* Set the command for reading kernel modules and execute it. */
let mut module_read_cmd = String::from("cat /proc/modules");
Expand All @@ -114,8 +117,8 @@ impl KernelModules<'_> {
SortType::Dependent => module_read_cmd += " | sort -n -r -t ' ' -k3",
_ => {}
}
let modules_content = util::exec_cmd("sh", &["-c", &module_read_cmd])
.expect("failed to read /proc/modules");
let modules_content = util::exec_cmd("sh", &["-c", &module_read_cmd])?;

/* Parse content for module name, size and related information. */
for line in modules_content.lines() {
let columns: Vec<&str> = line.split_whitespace().collect();
Expand All @@ -138,6 +141,7 @@ impl KernelModules<'_> {
self.default_list = module_list.clone();
self.list = module_list;
self.scroll_list(ScrollDirection::Top);
Ok(())
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ impl Kernel {
pub fn refresh(&mut self) {
self.logs.refresh();
self.info.refresh();
self.modules.refresh();
let _ = self.modules.refresh();
}
}
Loading