diff --git a/.vscode/cspell.dictionaries/workspace.wordlist.txt b/.vscode/cspell.dictionaries/workspace.wordlist.txt index a5d245016c7..1ae6319c181 100644 --- a/.vscode/cspell.dictionaries/workspace.wordlist.txt +++ b/.vscode/cspell.dictionaries/workspace.wordlist.txt @@ -8,6 +8,7 @@ advapi32-sys aho-corasick backtrace blake2b_simd +rustix # * uutils project uutils diff --git a/Cargo.lock b/Cargo.lock index de54b50704f..8f6ac036b85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3783,8 +3783,7 @@ version = "0.8.0" dependencies = [ "clap", "fluent", - "libc", - "nix", + "rustix", "uucore", ] diff --git a/Cargo.toml b/Cargo.toml index db9c0c40523..f40ce378d3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -435,6 +435,7 @@ rstest = "0.26.0" rstest_reuse = "0.7.0" rustc-hash = "2.1.1" rust-ini = "0.21.0" +rustix = "1.1.4" same-file = "1.0.6" self_cell = "1.0.4" selinux = "=0.6.0" diff --git a/src/uu/nice/Cargo.toml b/src/uu/nice/Cargo.toml index 58dfb69f6af..45703c435d1 100644 --- a/src/uu/nice/Cargo.toml +++ b/src/uu/nice/Cargo.toml @@ -20,12 +20,11 @@ path = "src/nice.rs" [dependencies] clap = { workspace = true } -libc = { workspace = true } uucore = { workspace = true } fluent = { workspace = true } [target.'cfg(unix)'.dependencies] -nix = { workspace = true } +rustix = { workspace = true, features = ["process"] } [[bin]] name = "nice" diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index 1abb7e96ff1..298bef3ba03 100644 --- a/src/uu/nice/src/nice.rs +++ b/src/uu/nice/src/nice.rs @@ -6,9 +6,8 @@ // spell-checker:ignore (ToDO) getpriority setpriority nstr PRIO use clap::{Arg, ArgAction, Command}; -use libc::PRIO_PROCESS; use std::ffi::OsString; -use std::io::{Error, ErrorKind, Write, stdout}; +use std::io::{ErrorKind, Write, stdout}; use std::num::IntErrorKind; use std::os::unix::process::CommandExt; use std::process; @@ -110,14 +109,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 125)?; - nix::errno::Errno::clear(); - let mut niceness = unsafe { libc::getpriority(PRIO_PROCESS, 0) }; - if Error::last_os_error().raw_os_error().unwrap() != 0 { - return Err(USimpleError::new( - 125, - format!("getpriority: {}", Error::last_os_error()), - )); - } + let mut niceness = match rustix::process::getpriority_process(None) { + Ok(p) => p, + Err(e) => { + return Err(USimpleError::new(125, format!("getpriority: {e}"))); + } + }; let adjustment = if let Some(nstr) = matches.get_one::(options::ADJUSTMENT) { if !matches.contains_id(options::COMMAND) { @@ -152,8 +149,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // isn't writable. The GNU test suite checks specifically that the // exit code when failing to write the advisory is 125, but Rust // will produce an exit code of 101 when it panics. - if unsafe { libc::setpriority(PRIO_PROCESS, 0, niceness) } == -1 { - let warning_msg = translate!("nice-warning-setpriority", "util_name" => uucore::util_name(), "error" => Error::last_os_error()); + if let Err(e) = rustix::process::setpriority_process(None, niceness) { + let warning_msg = translate!("nice-warning-setpriority", "util_name" => "nice", "error" => e.to_string() ); if write!(std::io::stderr(), "{warning_msg}").is_err() { set_exit_code(125); @@ -179,13 +176,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> Command { - Command::new(uucore::util_name()) + Command::new("nice") .about(translate!("nice-about")) .override_usage(format_usage(&translate!("nice-usage"))) .trailing_var_arg(true) .infer_long_args(true) .version(uucore::crate_version!()) - .help_template(uucore::localized_help_template(uucore::util_name())) + .help_template(uucore::localized_help_template("nice")) .arg( Arg::new(options::ADJUSTMENT) .short('n')