Skip to content

Commit

Permalink
fix(state): sort prefixes as soon as config is passed to state
Browse files Browse the repository at this point in the history
  • Loading branch information
arunanshub committed Sep 24, 2024
1 parent 7deeb91 commit 099db82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions crates/kernel/src/state/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ pub(crate) struct StateInner {
}

impl StateInner {
pub fn new(config: Config) -> Self {
pub fn new(mut config: Config) -> Self {
let system_refresh_kind = RefreshKind::new().with_processes(
ProcessRefreshKind::new()
.with_exe(UpdateKind::OnlyIfNotSet)
.with_memory(),
);
let sysinfo = System::new_with_specifics(system_refresh_kind);
// sort map and exeprefixes ahead of time: see `utils::accept_file` for
// more info
config.system.mapprefix.sort();
config.system.exeprefix.sort();

Self {
config,
Expand All @@ -74,8 +78,6 @@ impl StateInner {
// Because `running_process_callback` borrows `self` mutably, we can't
// borrow `self` immutably in the loop.
let sysinfo = std::mem::take(&mut self.sysinfo);
// sort exeprefixes first: see test for `accept_file` for more info.
self.config.system.exeprefix.sort();

for (pid, process) in sysinfo.processes() {
let pid = pid.as_u32();
Expand Down Expand Up @@ -155,6 +157,10 @@ impl StateInner {

pub fn reload_config(&mut self, path: impl AsRef<Path>) -> Result<(), Error> {
self.config = Config::load(path)?;
// sort map and exeprefixes ahead of time: see `utils::accept_file` for
// more info
self.config.system.mapprefix.sort();
self.config.system.exeprefix.sort();
debug!(?self.config, "loaded new config");
Ok(())
}
Expand Down

0 comments on commit 099db82

Please sign in to comment.