mirror of
https://github.com/orhun/systeroid
synced 2024-10-15 03:42:18 +00:00
feat(sysctl): allow disabling cache via NOCACHE
variable
This commit is contained in:
parent
fa7a805214
commit
584e060aa4
|
@ -2,11 +2,12 @@ use crate::cache::{Cache, CacheData};
|
|||
use crate::config::Config;
|
||||
use crate::error::Result;
|
||||
use crate::parsers::{parse_kernel_docs, KERNEL_DOCS_PATH};
|
||||
use crate::sysctl::parameter::{Parameter, PARAMETERS_CACHE_LABEL};
|
||||
use crate::sysctl::parameter::Parameter;
|
||||
use crate::sysctl::section::Section;
|
||||
use crate::sysctl::PROC_PATH;
|
||||
use crate::sysctl::{DISABLE_CACHE_ENV, PARAMETERS_CACHE_LABEL, PROC_PATH};
|
||||
use rayon::prelude::*;
|
||||
use std::convert::TryFrom;
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::result::Result as StdResult;
|
||||
use sysctl::{CtlFlags, CtlIter, Sysctl as SysctlImpl};
|
||||
|
@ -90,10 +91,12 @@ impl Sysctl {
|
|||
}
|
||||
}
|
||||
self.update_docs(path)?;
|
||||
if env::var(DISABLE_CACHE_ENV).is_err() {
|
||||
cache.write(
|
||||
CacheData::new(&self.parameters, path)?,
|
||||
PARAMETERS_CACHE_LABEL,
|
||||
)?;
|
||||
}
|
||||
} else {
|
||||
eprintln!("warning: `Linux kernel documentation cannot be found. Please specify a path via '-D' argument`");
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ pub mod display;
|
|||
pub mod parameter;
|
||||
|
||||
/// Path of the kernel parameters.
|
||||
pub const PROC_PATH: &str = "/proc/sys/";
|
||||
pub(crate) const PROC_PATH: &str = "/proc/sys/";
|
||||
|
||||
/// Default configuration file to preload values from.
|
||||
pub const DEFAULT_PRELOAD: &str = "/etc/sysctl.conf";
|
||||
|
@ -32,3 +32,9 @@ pub const DEPRECATED_PARAMS: &[&str] = &["base_reachable_time", "retrans_time"];
|
|||
|
||||
/// Environment variable for setting the path of the Linux kernel documentation.
|
||||
pub const KERNEL_DOCS_ENV: &str = "KERNEL_DOCS";
|
||||
|
||||
/// Environment variable for disabling the cache.
|
||||
pub(crate) const DISABLE_CACHE_ENV: &str = "NOCACHE";
|
||||
|
||||
/// Label for caching the kernel parameters.
|
||||
pub(crate) const PARAMETERS_CACHE_LABEL: &str = "parameters";
|
||||
|
|
|
@ -8,9 +8,6 @@ use std::io::Write;
|
|||
use std::path::PathBuf;
|
||||
use sysctl::{Ctl, Sysctl as SysctlImpl};
|
||||
|
||||
/// Label for caching the kernel parameters.
|
||||
pub(crate) const PARAMETERS_CACHE_LABEL: &str = "parameters";
|
||||
|
||||
/// Representation of a kernel parameter.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Parameter {
|
||||
|
|
Loading…
Reference in a new issue