55
66// Pid utils
77use clap:: { arg, crate_version, Arg , ArgAction , ArgGroup , ArgMatches , Command } ;
8- #[ cfg( target_os = "linux" ) ]
9- use nix:: sys:: signal:: { self , Signal } ;
10- #[ cfg( target_os = "macos" ) ]
8+ #[ cfg( unix) ]
119use nix:: sys:: signal:: { self , Signal } ;
10+ #[ cfg( unix) ]
1211use nix:: unistd:: Pid ;
1312use regex:: Regex ;
1413use std:: io:: Error ;
@@ -126,6 +125,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
126125 // Send signal
127126 // TODO: Implement -q
128127 let echo = matches. get_flag ( "echo" ) ;
128+ #[ cfg( unix) ]
129129 kill ( & pids, sig, echo) ;
130130
131131 if matches. get_flag ( "count" ) {
@@ -304,7 +304,7 @@ fn parse_signal_value(signal_name: &str) -> UResult<usize> {
304304 }
305305}
306306
307- #[ cfg( target_os = "linux" ) ]
307+ #[ cfg( unix ) ]
308308fn kill ( pids : & Vec < ProcessInformation > , sig : Option < Signal > , echo : bool ) {
309309 for pid in pids {
310310 if let Err ( e) = signal:: kill ( Pid :: from_raw ( pid. pid as i32 ) , sig) {
@@ -320,25 +320,6 @@ fn kill(pids: &Vec<ProcessInformation>, sig: Option<Signal>, echo: bool) {
320320 }
321321}
322322
323- #[ cfg( target_os = "macos" ) ]
324- fn kill ( pids : & Vec < ProcessInformation > , sig : Option < Signal > , echo : bool ) {
325- for pid in pids {
326- if let Err ( e) = signal:: kill ( Pid :: from_raw ( pid. pid as i32 ) , sig) {
327- show ! ( Error :: from_raw_os_error( e as i32 )
328- . map_err_context( || format!( "killing pid {} failed" , pid. pid) ) ) ;
329- } else if echo {
330- println ! (
331- "{} killed (pid {})" ,
332- pid. cmdline. split( " " ) . next( ) . unwrap_or( "" ) ,
333- pid. pid
334- ) ;
335- }
336- }
337- }
338-
339- #[ cfg( target_os = "windows" ) ]
340- fn kill ( pids : & Vec < ProcessInformation > , sig : Option < Signal > , echo : bool ) { }
341-
342323#[ allow( clippy:: cognitive_complexity) ]
343324pub fn uu_app ( ) -> Command {
344325 Command :: new ( uucore:: util_name ( ) )
0 commit comments