@@ -282,17 +282,17 @@ def cmd_kill(*args)
282
282
end
283
283
284
284
# validate all the proposed pids first so we can bail if one is bogus
285
- clean_pids = validate_pids ( args )
285
+ valid_pids = validate_pids ( args )
286
286
args . uniq!
287
- diff = args - clean_pids . map { |e | e . to_s }
287
+ diff = args - valid_pids . map { |e | e . to_s }
288
288
if not diff . empty? # then we had an invalid pid
289
289
print_error ( "The following pids are not valid:#{ diff . join ( ", " ) . to_s } , quitting" )
290
290
return false
291
291
end
292
292
293
293
# kill kill kill
294
- print_line ( "Killing: #{ clean_pids . join ( ", " ) . to_s } " )
295
- client . sys . process . kill ( *( clean_pids . map { |x | x } ) )
294
+ print_line ( "Killing: #{ valid_pids . join ( ", " ) . to_s } " )
295
+ client . sys . process . kill ( *( valid_pids . map { |x | x } ) )
296
296
return true
297
297
end
298
298
@@ -320,8 +320,7 @@ def cmd_kill_help
320
320
def validate_pids ( arr_pids , allow_pid_0 = false , allow_session_pid = false )
321
321
322
322
return [ ] if ( arr_pids . class != Array or arr_pids . empty? )
323
- pids = arr_pids . dup
324
- clean_pids = [ ]
323
+ valid_pids = [ ]
325
324
# to minimize network traffic, we only get host processes once
326
325
host_processes = client . sys . process . get_processes
327
326
if host_processes . length < 1
@@ -332,28 +331,22 @@ def validate_pids(arr_pids, allow_pid_0 = false, allow_session_pid = false)
332
331
# get the current session pid so we don't suspend it later
333
332
mypid = client . sys . process . getpid . to_i
334
333
335
- # we convert to integers here separately because we want to uniq this array first so we
336
- # can avoid redundant lookups later
337
- pids . each_with_index do |pid , idx |
338
- next if pid . nil?
339
- pids [ idx ] = pid . to_i
340
- end
341
- # uniq'ify
342
- pids . uniq!
334
+ # remove nils & redundant pids, conver to int
335
+ clean_pids = pids . compact . uniq . map { |x | x . to_i }
343
336
# now we look up the pids & remove bad stuff if nec
344
- pids . delete_if do |p |
337
+ clean_pids . delete_if do |p |
345
338
( ( p == 0 and not allow_pid_0 ) or ( p == mypid and not allow_session_pid ) )
346
339
end
347
- pids . each do |pid |
340
+ clean_pids . each do |pid |
348
341
# find the process with this pid
349
342
theprocess = host_processes . select { |x | x [ "pid" ] == pid } . first
350
343
if ( theprocess . nil? )
351
344
next
352
345
else
353
- clean_pids << pid
346
+ valid_pids << pid
354
347
end
355
348
end
356
- return clean_pids
349
+ return valid_pids
357
350
end
358
351
359
352
#
@@ -740,12 +733,14 @@ def cmd_shutdown(*args)
740
733
end
741
734
742
735
#
743
- # @param args [Array] Suspends a list of one or more pids
736
+ # Suspends or resumes a list of one or more pids
744
737
# args can optionally be -c to continue on error or -r to resume instead of suspend,
745
738
# followed by a list of one or more valid pids
746
739
# A suspend which will accept process names will be added later
747
- # @return [Boolean] Returns true if command was successful, else false
748
740
#
741
+ # @param args [Array] List of one of more pids
742
+ # @return [Boolean] Returns true if command was successful, else false
743
+
749
744
def cmd_suspend ( *args )
750
745
# give'em help if they want it, or seem confused
751
746
if ( args . length == 0 or ( args . length == 1 and args [ 0 ] . strip == "-h" ) )
@@ -757,9 +752,9 @@ def cmd_suspend(*args)
757
752
resume = args . delete ( "-r" ) || false
758
753
759
754
# validate all the proposed pids first so we can bail if one is bogus
760
- clean_pids = validate_pids ( args )
755
+ valid_pids = validate_pids ( args )
761
756
args . uniq!
762
- diff = args - clean_pids . map { |e | e . to_s }
757
+ diff = args - valid_pids . map { |e | e . to_s }
763
758
if not diff . empty? # then we had an invalid pid
764
759
print_error ( "The following pids are not valid:#{ diff . join ( ", " ) . to_s } " )
765
760
if continue
@@ -773,9 +768,9 @@ def cmd_suspend(*args)
773
768
#client.sys.process.kill(*(args.map { |x| x.to_i }))
774
769
targetprocess = nil
775
770
if resume
776
- print_status ( "Resuming: #{ clean_pids . join ( ", " ) . to_s } " )
771
+ print_status ( "Resuming: #{ valid_pids . join ( ", " ) . to_s } " )
777
772
begin
778
- clean_pids . each do |pid |
773
+ valid_pids . each do |pid |
779
774
print_status ( "Targeting process with PID #{ pid } ..." )
780
775
targetprocess = client . sys . process . open ( pid , PROCESS_ALL_ACCESS )
781
776
targetprocess . thread . each_thread do |x |
@@ -791,9 +786,9 @@ def cmd_suspend(*args)
791
786
return false unless continue
792
787
end
793
788
else # suspend
794
- print_status ( "Suspending: #{ clean_pids . join ( ", " ) . to_s } " )
789
+ print_status ( "Suspending: #{ valid_pids . join ( ", " ) . to_s } " )
795
790
begin
796
- clean_pids . each do |pid |
791
+ valid_pids . each do |pid |
797
792
print_status ( "Targeting process with PID #{ pid } ..." )
798
793
targetprocess = client . sys . process . open ( pid , PROCESS_ALL_ACCESS )
799
794
targetprocess . thread . each_thread do |x |
0 commit comments