33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
55
6- use clap:: { arg , crate_version, value_parser , Arg , Command } ;
6+ use clap:: { crate_version, Arg , Command } ;
77#[ cfg( unix) ]
88use nix:: { sys:: signal, sys:: signal:: Signal , unistd:: Pid } ;
99use uu_snice:: {
@@ -29,6 +29,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
2929 }
3030
3131 // Case1: Send signal
32+ let take_action = !settings. no_action ;
3233 if let Some ( targets) = settings. expressions {
3334 let pids = collect_pids ( & targets) ;
3435
@@ -43,7 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
4344 } ;
4445
4546 #[ cfg( unix) ]
46- let results = perform_action ( & pids, & signal) ;
47+ let results = perform_action ( & pids, & signal, take_action ) ;
4748 #[ cfg( not( unix) ) ]
4849 let results: Vec < Option < ActionResult > > = Vec :: new ( ) ;
4950
@@ -54,20 +55,22 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
5455 if settings. verbose {
5556 let output = construct_verbose_result ( & pids, & results) . trim ( ) . to_owned ( ) ;
5657 println ! ( "{output}" ) ;
58+ } else if !take_action {
59+ pids. iter ( ) . for_each ( |pid| println ! ( "{pid}" ) ) ;
5760 }
5861 }
5962
6063 Ok ( ( ) )
6164}
6265
6366#[ cfg( unix) ]
64- fn perform_action ( pids : & [ u32 ] , signal : & Signal ) -> Vec < Option < ActionResult > > {
67+ fn perform_action ( pids : & [ u32 ] , signal : & Signal , take_action : bool ) -> Vec < Option < ActionResult > > {
68+ let sig = if take_action { Some ( * signal) } else { None } ;
6569 pids. iter ( )
6670 . map ( |pid| {
6771 {
68- Some ( match signal:: kill ( Pid :: from_raw ( * pid as i32 ) , * signal ) {
72+ Some ( match signal:: kill ( Pid :: from_raw ( * pid as i32 ) , sig ) {
6973 Ok ( _) => ActionResult :: Success ,
70-
7174 Err ( _) => ActionResult :: PermissionDenied ,
7275 } )
7376 }
@@ -84,23 +87,5 @@ pub fn uu_app() -> Command {
8487 . infer_long_args ( true )
8588 . arg_required_else_help ( true )
8689 . arg ( Arg :: new ( "signal" ) )
87- . args ( [
88- // arg!(-f --fast "fast mode (not implemented)"),
89- // arg!(-i --interactive "interactive"),
90- arg ! ( -l --list "list all signal names" ) ,
91- arg ! ( -L --table "list all signal names in a nice table" ) ,
92- // arg!(-n --"no-action" "do not actually kill processes; just print what would happen"),
93- arg ! ( -v --verbose "explain what is being done" ) ,
94- // arg!(-w --warnings "enable warnings (not implemented)"),
95- // Expressions
96- arg ! ( -c --command <command> ... "expression is a command name" ) ,
97- arg ! ( -p --pid <pid> ... "expression is a process id number" )
98- . value_parser ( value_parser ! ( u32 ) ) ,
99- arg ! ( -t --tty <tty> ... "expression is a terminal" ) ,
100- arg ! ( -u --user <username> ... "expression is a username" ) ,
101- // arg!(--ns <PID> "match the processes that belong to the same namespace as <pid>"),
102- // arg!(--nslist <ns> "list which namespaces will be considered for the --ns option.")
103- // .value_delimiter(',')
104- // .value_parser(["ipc", "mnt", "net", "pid", "user", "uts"]),
105- ] )
90+ . args ( uu_snice:: clap_args ( ) )
10691}
0 commit comments