Skip to content

Commit

Permalink
renice: use clap for real
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jan 26, 2024
1 parent dc7f34c commit 5e5ded2
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/uu/renice/src/renice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@ use clap::{crate_version, Arg, Command};
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;

let nice_value = match matches.get_one::<i32>("nice_value") {
Some(number) => number,
_ => {
eprintln!("Invalid nice value");
process::exit(1);
}
};
let nice_value = *matches.get_one::<i32>("nice_value").unwrap_or_else(|| {
eprintln!("Invalid nice value");
process::exit(1);
});

let pid = match matches.get_one::<i32>("pid") {
Some(number) => number,
_ => {
eprintln!("Invalid PID");
process::exit(1);
}
};
let pid = *matches.get_one::<i32>("pid").unwrap_or_else(|| {
eprintln!("Invalid PID");
process::exit(1);
});

if unsafe { libc::setpriority(PRIO_PROCESS, (*pid).try_into().unwrap(), *nice_value) } == -1 {
if unsafe { libc::setpriority(PRIO_PROCESS, pid.try_into().unwrap(), nice_value) } == -1 {
eprintln!("Failed to set nice value: {}", Error::last_os_error());
process::exit(1);
}
Expand Down

0 comments on commit 5e5ded2

Please sign in to comment.