Skip to content
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
1 change: 1 addition & 0 deletions .vscode/cspell.dictionaries/workspace.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ advapi32-sys
aho-corasick
backtrace
blake2b_simd
rustix

# * uutils project
uutils
Expand Down
3 changes: 1 addition & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/uu/nice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 11 additions & 14 deletions src/uu/nice/src/nice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<String>(options::ADJUSTMENT) {
if !matches.contains_id(options::COMMAND) {
Expand Down Expand Up @@ -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);
Expand All @@ -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')
Expand Down
Loading