ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/pack/freebsd/sysutils/psmisc/files/patch-src-killall.c
Revision: 455
Committed: 2011-08-06T22:25:30-07:00 (13 years, 10 months ago) by douglas
Content type: text/x-diff
File size: 4905 byte(s)
Log Message:
Upgrade sysutils/psmisc to 22.14; fixed the "-u,--user USER      kill only process(es) running as USER" option; made portlint happy.

File Contents

# Content
1 --- src/killall.c.orig 2011-06-20 04:43:24.000000000 -0700
2 +++ src/killall.c 2011-08-06 21:48:35.014330713 -0700
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 @@ -87,40 +89,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 -
38 - fflush (stdout);
39 + int ch, c;
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 @@ -197,7 +194,7 @@
78
79 while (fgets(buf, sizeof buf, f))
80 {
81 - if (sscanf (buf, "Uid:\t%d", &puid))
82 + if (sscanf (buf, "%*s %*d %*d %*d %*d %*s %*s %*s %*s %*s %*s %*s %d", &puid))
83 {
84 re = uid==puid;
85 break;
86 @@ -360,7 +357,7 @@
87 }
88 #endif /*WITH_SELINUX*/
89 /* load process name */
90 - if (asprintf (&path, PROC_BASE "/%d/stat", pid_table[i]) < 0)
91 + if (asprintf (&path, PROC_BASE "/%d/status", pid_table[i]) < 0)
92 continue;
93 if (!(file = fopen (path, "r")))
94 {
95 @@ -368,7 +365,7 @@
96 continue;
97 }
98 free (path);
99 - okay = fscanf (file, "%*d (%15[^)]", comm) == 1;
100 + okay = fscanf (file, "%s", comm) == 1;
101 if (!okay) {
102 fclose(file);
103 continue;
104 @@ -390,65 +387,6 @@
105 got_long = 0;
106 command = NULL; /* make gcc happy */
107 length = strlen (comm);
108 - if (length == COMM_LEN - 1)
109 - {
110 - if (asprintf (&path, PROC_BASE "/%d/cmdline", pid_table[i]) < 0)
111 - continue;
112 - if (!(file = fopen (path, "r"))) {
113 - free (path);
114 - continue;
115 - }
116 - free (path);
117 - while (1) {
118 - /* look for actual command so we skip over initial "sh" if any */
119 - char *p;
120 - int cmd_size = 128;
121 - command_buf = (char *)malloc (cmd_size);
122 - if (!command_buf)
123 - exit (1);
124 -
125 - /* 'cmdline' has arguments separated by nulls */
126 - for (p=command_buf; ; p++) {
127 - int c;
128 - if (p == (command_buf + cmd_size))
129 - {
130 - int cur_size = cmd_size;
131 - cmd_size *= 2;
132 - command_buf = (char *)realloc(command_buf, cmd_size);
133 - if (!command_buf)
134 - exit (1);
135 - p = command_buf + cur_size;
136 - }
137 - c = fgetc(file);
138 - if (c == EOF || c == '\0') {
139 - *p = '\0';
140 - break;
141 - } else {
142 - *p = c;
143 - }
144 - }
145 - if (strlen(command_buf) == 0) {
146 - okay = 0;
147 - break;
148 - }
149 - p = strrchr(command_buf,'/');
150 - p = p ? p+1 : command_buf;
151 - if (strncmp(p, comm, COMM_LEN-1) == 0) {
152 - okay = 1;
153 - command = p;
154 - break;
155 - }
156 - }
157 - (void) fclose(file);
158 - if (exact && !okay)
159 - {
160 - if (verbose)
161 - fprintf (stderr, _("skipping partial match %s(%d)\n"), comm,
162 - pid_table[i]);
163 - continue;
164 - }
165 - got_long = okay;
166 - }
167 /* mach by process name */
168 for (j = 0; j < names; j++)
169 {
170 @@ -499,7 +437,7 @@
171 {
172 int ok = 1;
173
174 - if (asprintf (&path, PROC_BASE "/%d/exe", pid_table[i]) < 0)
175 + if (asprintf (&path, PROC_BASE "/%d/file", pid_table[i]) < 0)
176 continue;
177
178 if (stat (path, &st) < 0)
179 @@ -693,7 +631,7 @@
180 struct stat isproc;
181 pid_t pid = getpid();
182
183 - snprintf(filename, sizeof(filename), PROC_BASE"/%d/stat", (int) pid);
184 + snprintf(filename, sizeof(filename), PROC_BASE"/%d/status", (int) pid);
185 return stat(filename, &isproc) == 0;
186 }
187

Properties

Name Value
svn:mime-type text/x-diff