66// spell-checker:ignore (ToDO) getpriority setpriority nstr PRIO
77
88use clap:: { Arg , ArgAction , Command } ;
9- use libc:: PRIO_PROCESS ;
109use std:: ffi:: OsString ;
11- use std:: io:: { Error , ErrorKind , Write , stdout} ;
10+ use std:: io:: { ErrorKind , Write , stdout} ;
1211use std:: num:: IntErrorKind ;
1312use std:: os:: unix:: process:: CommandExt ;
1413use std:: process;
@@ -110,14 +109,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
110109 let matches =
111110 uucore:: clap_localization:: handle_clap_result_with_exit_code ( uu_app ( ) , args, 125 ) ?;
112111
113- nix:: errno:: Errno :: clear ( ) ;
114- let mut niceness = unsafe { libc:: getpriority ( PRIO_PROCESS , 0 ) } ;
115- if Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) != 0 {
116- return Err ( USimpleError :: new (
117- 125 ,
118- format ! ( "getpriority: {}" , Error :: last_os_error( ) ) ,
119- ) ) ;
120- }
112+ let mut niceness = match rustix:: process:: getpriority_process ( None ) {
113+ Ok ( p) => p,
114+ Err ( e) => {
115+ return Err ( USimpleError :: new ( 125 , format ! ( "getpriority: {e}" ) ) ) ;
116+ }
117+ } ;
121118
122119 let adjustment = if let Some ( nstr) = matches. get_one :: < String > ( options:: ADJUSTMENT ) {
123120 if !matches. contains_id ( options:: COMMAND ) {
@@ -152,8 +149,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
152149 // isn't writable. The GNU test suite checks specifically that the
153150 // exit code when failing to write the advisory is 125, but Rust
154151 // will produce an exit code of 101 when it panics.
155- if unsafe { libc :: setpriority ( PRIO_PROCESS , 0 , niceness) } == - 1 {
156- let warning_msg = translate ! ( "nice-warning-setpriority" , "util_name" => uucore :: util_name ( ) , "error" => Error :: last_os_error ( ) ) ;
152+ if let Err ( e ) = rustix :: process :: setpriority_process ( None , niceness) {
153+ let warning_msg = translate ! ( "nice-warning-setpriority" , "util_name" => "nice" , "error" => e . to_string ( ) ) ;
157154
158155 if write ! ( std:: io:: stderr( ) , "{warning_msg}" ) . is_err ( ) {
159156 set_exit_code ( 125 ) ;
@@ -179,13 +176,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
179176}
180177
181178pub fn uu_app ( ) -> Command {
182- Command :: new ( uucore :: util_name ( ) )
179+ Command :: new ( "nice" )
183180 . about ( translate ! ( "nice-about" ) )
184181 . override_usage ( format_usage ( & translate ! ( "nice-usage" ) ) )
185182 . trailing_var_arg ( true )
186183 . infer_long_args ( true )
187184 . version ( uucore:: crate_version!( ) )
188- . help_template ( uucore:: localized_help_template ( uucore :: util_name ( ) ) )
185+ . help_template ( uucore:: localized_help_template ( "nice" ) )
189186 . arg (
190187 Arg :: new ( options:: ADJUSTMENT )
191188 . short ( 'n' )
0 commit comments