@@ -9,10 +9,10 @@ use clap::{Arg, ArgAction, Command, value_parser};
99use nix:: libc:: { S_IRGRP , S_IROTH , S_IRUSR , S_IWGRP , S_IWOTH , S_IWUSR , mode_t} ;
1010use nix:: sys:: stat:: { Mode , SFlag , dev_t, mknod as nix_mknod} ;
1111use std:: ffi:: { OsStr , OsString } ;
12- use std:: io:: { self , Write as _ } ;
12+ use std:: io;
1313
1414use uucore:: display:: Quotable ;
15- use uucore:: error:: { ExitCode , UResult , USimpleError , UUsageError , set_exit_code } ;
15+ use uucore:: error:: { ExitCode , FromIo , UResult , USimpleError , UUsageError } ;
1616use uucore:: format_usage;
1717use uucore:: fs:: makedev;
1818use uucore:: { show_warning, translate} ;
@@ -69,7 +69,7 @@ struct Config {
6969 context : Option < String > ,
7070}
7171
72- fn mknod ( file_name : & OsStr , config : Config ) -> i32 {
72+ fn mknod ( file_name : & OsStr , config : Config ) -> UResult < ( ) > {
7373 #[ cfg( all( feature = "selinux" , any( target_os = "android" , target_os = "linux" ) ) ) ]
7474 let selinux_enabled = uucore:: selinux:: is_selinux_enabled ( ) ;
7575 #[ cfg( not( all( feature = "selinux" , any( target_os = "android" , target_os = "linux" ) ) ) ) ]
@@ -93,10 +93,7 @@ fn mknod(file_name: &OsStr, config: Config) -> i32 {
9393 config. context . as_ref ( ) ,
9494 ) {
9595 Ok ( guard) => Some ( guard) ,
96- Err ( e) => {
97- let _ = writeln ! ( io:: stderr( ) , "mknod: {e}" ) ;
98- return 1 ;
99- }
96+ Err ( e) => return Err ( USimpleError :: new ( 1 , e. to_string ( ) ) ) ,
10097 }
10198 } else {
10299 None
@@ -109,23 +106,14 @@ fn mknod(file_name: &OsStr, config: Config) -> i32 {
109106 config. mode ,
110107 config. dev ,
111108 )
112- . err ( )
113109 } ;
114- let mknod_err = if config. use_umask {
110+ let res = if config. use_umask {
115111 create_node ( )
116112 } else {
117113 uucore:: mode:: with_umask ( 0 , create_node)
118114 } ;
119- let errno = if mknod_err. is_some ( ) { -1 } else { 0 } ;
120-
121- if let Some ( err) = mknod_err {
122- let _ = writeln ! (
123- io:: stderr( ) ,
124- "{}: {}" ,
125- uucore:: execution_phrase( ) ,
126- io:: Error :: from( err)
127- ) ;
128- }
115+ res. map_err ( io:: Error :: from)
116+ . map_err_context ( || file_name. maybe_quote ( ) . to_string ( ) ) ?;
129117
130118 // Apply SMACK context if requested
131119 #[ cfg( all( feature = "smack" , target_os = "linux" ) ) ]
@@ -136,11 +124,10 @@ fn mknod(file_name: &OsStr, config: Config) -> i32 {
136124 std:: fs:: remove_file ( p)
137125 } )
138126 {
139- let _ = writeln ! ( io:: stderr( ) , "mknod: {e}" ) ;
140- return 1 ;
127+ return Err ( USimpleError :: new ( 1 , e. to_string ( ) ) ) ;
141128 }
142129
143- errno
130+ Ok ( ( ) )
144131}
145132
146133#[ uucore:: main]
@@ -227,9 +214,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
227214 context,
228215 } ;
229216
230- let exit_code = mknod ( file_name, config) ;
231- set_exit_code ( exit_code) ;
232- Ok ( ( ) )
217+ mknod ( file_name, config)
233218}
234219
235220pub fn uu_app ( ) -> Command {
0 commit comments