mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
nice: Remove use of show_warning
This is required to pass the GNU nice test suite. Failure to produce the advisory message when unable to change the process priority must be fatal, and without this commit our version of nice will exit, but before the commit the exit code will be 101 (due to eprintln! panicking), and it must be 125 to pass the test suite. Signed-off-by: Ed Smith <ed.smith@collabora.com>
This commit is contained in:
parent
07e7372311
commit
34e10f9aa8
1 changed files with 17 additions and 4 deletions
|
@ -9,13 +9,13 @@
|
|||
|
||||
use libc::{c_char, c_int, execvp, PRIO_PROCESS};
|
||||
use std::ffi::{CString, OsString};
|
||||
use std::io::Error;
|
||||
use std::io::{Error, Write};
|
||||
use std::ptr;
|
||||
|
||||
use clap::{crate_version, Arg, ArgAction, Command};
|
||||
use uucore::{
|
||||
error::{set_exit_code, UClapError, UResult, USimpleError, UUsageError},
|
||||
format_usage, show_error, show_warning,
|
||||
format_usage, show_error,
|
||||
};
|
||||
|
||||
pub mod options {
|
||||
|
@ -152,8 +152,21 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
};
|
||||
|
||||
niceness += adjustment;
|
||||
if unsafe { libc::setpriority(PRIO_PROCESS, 0, niceness) } == -1 {
|
||||
show_warning!("setpriority: {}", Error::last_os_error());
|
||||
// We can't use `show_warning` because that will panic if stderr
|
||||
// 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
|
||||
&& write!(
|
||||
std::io::stderr(),
|
||||
"{}: warning: setpriority: {}",
|
||||
uucore::util_name(),
|
||||
Error::last_os_error()
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
set_exit_code(125);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let cstrs: Vec<CString> = matches
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue