File: no-kill-opt.patch

package info (click to toggle)
killer 0.90-15
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 764 kB
  • sloc: perl: 8,785; makefile: 35; sh: 1
file content (117 lines) | stat: -rw-r--r-- 2,873 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
Description: New option -n to not kill, just print out what would be killed.

--- killer-git.orig/killer	2014-09-28 09:00:39.831969617 +0200
+++ killer-git/killer	2014-09-28 09:00:40.207972731 +0200
@@ -36,7 +36,7 @@
 
 =head1 SYNOPSIS
 
-killer [B<-h>] [B<-V>]
+killer [B<-h>] [B<-V>] [B<-n>] [B<-d>]
 
 =head1 DESCRIPTION
 
@@ -66,6 +66,14 @@
 
 Display version number
 
+=item -n
+
+Do not kill, just print what would be killed
+
+=item -d
+
+Enable debug output
+
 =back
 
 =cut
@@ -145,6 +153,8 @@
 my %pid2nice = ();	# nice value
 my %pid2comm = ();	# Command name being executed
 my %remainingprocs = (); # The processes that have not been eliminated
+my $noop = 0;
+my $debug = 0;
 
 =head2 new
 
@@ -220,7 +230,7 @@
     # skip the first line of input
     <PS>;
     while (<PS>) {
-	#print "\t$_";
+	print "\t$_" if $debug;
 	chop;
 
 	# strip leading white space
@@ -805,11 +815,16 @@
     my $killcount = 0;
 
     foreach my $pid ( keys %remainingprocs ) {
-	if ( kill($signum, $pid) > 0 ) {
-	    $killcount ++;
-	    syslog('info', "kill($signum, $pid) user=%s command=%s nice=%d",
+        my $msg = sprintf("kill($signum, $pid) user=%s command=%s nice=%d",
 	                     $pid2ruser{$pid}, $pid2comm{$pid},
                              $pid2nice{$pid});
+        if ($noop) {
+            print "$msg\n";
+        } else {
+            if ( kill($signum, $pid) > 0 ) {
+                $killcount ++;
+                syslog('info', "%s", $msg);
+            }
 	}
     }
     return $killcount;
@@ -1020,6 +1035,14 @@
             print STDERR "Type \"perldoc $0\" for lots of help.\n";
             next;
         };
+        $opt eq '-n' && do {
+            $noop = 1;
+            next;
+        };
+        $opt eq '-d' && do {
+            $debug = 1;
+            next;
+        };
         $opt eq '-V' && do {
             print STDERR "killer version $version\n";
             next;
@@ -1027,7 +1050,7 @@
         print STDERR "killer: option \"$opt\" not recognized\n";
         print STDERR "Type \"perldoc $0\" for lots of help.\n";
     }
-    exit(1);
+    exit(1) unless ($noop || $debug);
 }
 
 =head1 PACKAGE main
@@ -1297,7 +1320,7 @@
 print $outfile "Attempt 1: Nicely killing the following processes\n";
 $ptable->printRemainingProcesses($outfile);
 $ptable->killAll(15);
-sleep(30);
+sleep(30) unless $noop;
 $ptable->killAll(9);
 
 # #########
@@ -1307,7 +1330,7 @@
 # be spawned.  This should catch fork() bombs as well
 # ##########
 
-sleep(5);
+sleep(5) unless $noop;
 ($ptable, $term) = gatherInfo();
 ( @remaining ) = $ptable->getRemainingProcesses();
 if ( $#remaining == -1 ) {
@@ -1329,7 +1352,7 @@
 # the processes.  Let's just whine through email.
 # ########
 
-sleep(5);
+sleep(5) unless $noop;
 ($ptable, $term) = gatherInfo();
 ( @remaining ) = $ptable->getRemainingProcesses();
 if ( $#remaining == -1 ) {