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

Updated CLI Argument Parsing (New) #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
174 changes: 143 additions & 31 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ license = "MIT"

[dependencies]
glob = { version = "0.3.0", optional = true }
libc = "0.2.97"
cfg-if = "1.0.0"
libc = "0.2.97"
cfg-if = "1.0.0"
daemonize = "0.4.1"
argh = "0.1.5"
clap = { version = "3.0.0-rc.7", features = ["derive"] }

[build-dependencies]
cc = "1.0.68"
cc = "1.0.68"
libc = "0.2.97"

[dev-dependencies]
Expand Down
23 changes: 23 additions & 0 deletions src/cfg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use clap::Parser;

#[derive(Parser, Debug)]
/// Lightweight Process-Killer Daemon for Out-of-Memory Scenarios
#[clap(author, version, about)]
pub struct Cli {
/// Log extra debugging information
#[clap(short, long)]
pub verbose: bool,
/// Do not fork a daemon process
#[clap(short, long)]
pub no_daemonize: bool,
/// Kill the entire process group of a target
#[clap(short, long)]
pub kill_pgroup: bool,
/// The cieling PSI value; All processes that surpass this will be killed
#[clap(short = 'p', long, value_name = "PSI", default_value = "25.0")]
pub cutoff_psi: f32,
// #[cfg(feature = "glob-ignore")]
/// A (tilde-separated) list of glob patterns matching process names which will never be killed
#[clap(short = 'u', long = "unkillable", value_name = "GLOB")]
pub ignored_globs: Option<Vec<String>>,
}
36 changes: 0 additions & 36 deletions src/cli.rs

This file was deleted.

8 changes: 2 additions & 6 deletions src/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ use libc::{EINVAL, EPERM, ESRCH, SIGKILL, SIGTERM};
use crate::errno::errno;
use crate::error::{Error, Result};
use crate::process::Process;
use crate::{cli, utils};
use crate::{cfg, utils};

pub fn choose_victim(
proc_buf: &mut [u8],
buf: &mut [u8],
args: &cli::CommandLineArgs,
) -> Result<Process> {
pub fn choose_victim(proc_buf: &mut [u8], buf: &mut [u8], args: &cfg::Cli) -> Result<Process> {
let now = Instant::now();

// `args` is currently only used when checking for unkillable patterns
Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// use uname::Uname;

use clap::Parser;
use uname::Uname;

use crate::{memory::lock_memory_pages, monitor::Monitor};

mod cli;
mod cfg;
mod daemon;
mod errno;
mod error;
Expand All @@ -17,7 +16,8 @@ mod uname;
mod utils;

fn main() -> error::Result<()> {
let args: cli::CommandLineArgs = argh::from_env();
let args = cfg::Cli::parse();
println!("{:?}", args);

// Show uname info and return the Linux version running
let _linux_version = {
Expand All @@ -35,7 +35,7 @@ fn main() -> error::Result<()> {
// Buffer for anything else
let buf = [0_u8; 100];

if !args.no_daemon {
if !args.no_daemonize {
// Daemonize current process
println!("\nStarting daemonization process!");
daemon::daemonize()?;
Expand Down
Loading