1 |
--- src/killall.c.orig 2009-12-18 21:45:36.000000000 +0900 |
2 |
+++ src/killall.c 2010-01-03 00:37:34.818411284 +0900 |
3 |
@@ -36,6 +36,8 @@ |
4 |
#include <dirent.h> |
5 |
#include <signal.h> |
6 |
#include <errno.h> |
7 |
+#include <limits.h> |
8 |
+#include <locale.h> |
9 |
#include <sys/types.h> |
10 |
#include <sys/stat.h> |
11 |
#include <getopt.h> |
12 |
@@ -83,40 +85,35 @@ |
13 |
ignore_case = 0, pidof; |
14 |
static long younger_than = 0, older_than = 0; |
15 |
|
16 |
+ /* |
17 |
+ * This is based on the implementation from 21.5, as the one in 21.6 |
18 |
+ * and newer uses Linux specific functions getline() and rpmatch() |
19 |
+ */ |
20 |
static int |
21 |
ask (char *name, pid_t pid, const int signal) |
22 |
{ |
23 |
- int res; |
24 |
- size_t len; |
25 |
- char *line; |
26 |
- |
27 |
- line = NULL; |
28 |
- len = 0; |
29 |
- |
30 |
- do { |
31 |
- if (signal == SIGTERM) |
32 |
- printf (_("Kill %s(%s%d) ? (y/N) "), name, process_group ? "pgid " : "", |
33 |
- pid); |
34 |
- else |
35 |
- printf (_("Signal %s(%s%d) ? (y/N) "), name, process_group ? "pgid " : "", |
36 |
- pid); |
37 |
+ int ch, c; |
38 |
|
39 |
- fflush (stdout); |
40 |
- |
41 |
- if (getline (&line, &len, stdin) < 0) |
42 |
- return 0; |
43 |
- /* Check for default */ |
44 |
- if (line[0] == '\n') { |
45 |
- free(line); |
46 |
- return 0; |
47 |
- } |
48 |
- res = rpmatch(line); |
49 |
- if (res >= 0) { |
50 |
- free(line); |
51 |
- return res; |
52 |
+ do |
53 |
+ { |
54 |
+ if (signal == SIGTERM) |
55 |
+ printf (_("Kill %s(%s%d) ? (y/N) "), name, process_group ? "pgid " : "", |
56 |
+ pid); |
57 |
+ else |
58 |
+ printf (_("Signal %s(%s%d) ? (y/N) "), name, process_group ? "pgid " : "", |
59 |
+ pid); |
60 |
+ fflush (stdout); |
61 |
+ do |
62 |
+ if ((ch = getchar ()) == EOF) |
63 |
+ exit (0); |
64 |
+ while (ch == '\n' || ch == '\t' || ch == ' '); |
65 |
+ do |
66 |
+ if ((c = getchar ()) == EOF) |
67 |
+ exit (0); |
68 |
+ while (c != '\n'); |
69 |
} |
70 |
- } while(1); |
71 |
- /* Never should get here */ |
72 |
+ while (ch != 'y' && ch != 'n' && ch != 'Y' && ch != 'N'); |
73 |
+ return ch == 'y' || ch == 'Y'; |
74 |
} |
75 |
|
76 |
static double |
77 |
@@ -356,7 +353,7 @@ |
78 |
} |
79 |
#endif /*WITH_SELINUX*/ |
80 |
/* load process name */ |
81 |
- if (asprintf (&path, PROC_BASE "/%d/stat", pid_table[i]) < 0) |
82 |
+ if (asprintf (&path, PROC_BASE "/%d/status", pid_table[i]) < 0) |
83 |
continue; |
84 |
if (!(file = fopen (path, "r"))) |
85 |
{ |
86 |
@@ -364,7 +361,7 @@ |
87 |
continue; |
88 |
} |
89 |
free (path); |
90 |
- okay = fscanf (file, "%*d (%15[^)]", comm) == 1; |
91 |
+ okay = fscanf (file, "%s", comm) == 1; |
92 |
if (!okay) { |
93 |
fclose(file); |
94 |
continue; |
95 |
@@ -386,65 +383,6 @@ |
96 |
got_long = 0; |
97 |
command = NULL; /* make gcc happy */ |
98 |
length = strlen (comm); |
99 |
- if (length == COMM_LEN - 1) |
100 |
- { |
101 |
- if (asprintf (&path, PROC_BASE "/%d/cmdline", pid_table[i]) < 0) |
102 |
- continue; |
103 |
- if (!(file = fopen (path, "r"))) { |
104 |
- free (path); |
105 |
- continue; |
106 |
- } |
107 |
- free (path); |
108 |
- while (1) { |
109 |
- /* look for actual command so we skip over initial "sh" if any */ |
110 |
- char *p; |
111 |
- int cmd_size = 128; |
112 |
- command_buf = (char *)malloc (cmd_size); |
113 |
- if (!command_buf) |
114 |
- exit (1); |
115 |
- |
116 |
- /* 'cmdline' has arguments separated by nulls */ |
117 |
- for (p=command_buf; ; p++) { |
118 |
- int c; |
119 |
- if (p == (command_buf + cmd_size)) |
120 |
- { |
121 |
- int cur_size = cmd_size; |
122 |
- cmd_size *= 2; |
123 |
- command_buf = (char *)realloc(command_buf, cmd_size); |
124 |
- if (!command_buf) |
125 |
- exit (1); |
126 |
- p = command_buf + cur_size; |
127 |
- } |
128 |
- c = fgetc(file); |
129 |
- if (c == EOF || c == '\0') { |
130 |
- *p = '\0'; |
131 |
- break; |
132 |
- } else { |
133 |
- *p = c; |
134 |
- } |
135 |
- } |
136 |
- if (strlen(command_buf) == 0) { |
137 |
- okay = 0; |
138 |
- break; |
139 |
- } |
140 |
- p = strrchr(command_buf,'/'); |
141 |
- p = p ? p+1 : command_buf; |
142 |
- if (strncmp(p, comm, COMM_LEN-1) == 0) { |
143 |
- okay = 1; |
144 |
- command = p; |
145 |
- break; |
146 |
- } |
147 |
- } |
148 |
- (void) fclose(file); |
149 |
- if (exact && !okay) |
150 |
- { |
151 |
- if (verbose) |
152 |
- fprintf (stderr, _("skipping partial match %s(%d)\n"), comm, |
153 |
- pid_table[i]); |
154 |
- continue; |
155 |
- } |
156 |
- got_long = okay; |
157 |
- } |
158 |
/* mach by process name */ |
159 |
for (j = 0; j < names; j++) |
160 |
{ |
161 |
@@ -495,7 +433,7 @@ |
162 |
{ |
163 |
int ok = 1; |
164 |
|
165 |
- if (asprintf (&path, PROC_BASE "/%d/exe", pid_table[i]) < 0) |
166 |
+ if (asprintf (&path, PROC_BASE "/%d/file", pid_table[i]) < 0) |
167 |
continue; |
168 |
|
169 |
if (stat (path, &st) < 0) |
170 |
@@ -842,7 +780,7 @@ |
171 |
fprintf (stderr, _("Maximum number of names is %d\n"), MAX_NAMES); |
172 |
exit (1); |
173 |
} |
174 |
- if (stat("/proc/self/stat", &isproc)==-1) { |
175 |
+ if (stat("/proc/curproc/status", &isproc)==-1) { |
176 |
fprintf (stderr, _("%s is empty (not mounted ?)\n"), PROC_BASE); |
177 |
exit (1); |
178 |
} |