aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/Config.in2
-rw-r--r--procps/fuser.c148
-rw-r--r--procps/kill.c2
-rw-r--r--procps/top.c10
4 files changed, 81 insertions, 81 deletions
diff --git a/procps/Config.in b/procps/Config.in
index 8a22a5dcf..52bfd3f43 100644
--- a/procps/Config.in
+++ b/procps/Config.in
@@ -17,7 +17,7 @@ config CONFIG_FUSER
17 bool "fuser" 17 bool "fuser"
18 default n 18 default n
19 help 19 help
20 fuser lists all PIDs (Process IDs) that currently have a given 20 fuser lists all PIDs (Process IDs) that currently have a given
21 file open. fuser can also list all PIDs that have a given network 21 file open. fuser can also list all PIDs that have a given network
22 (TCP or UDP) port open. 22 (TCP or UDP) port open.
23 23
diff --git a/procps/fuser.c b/procps/fuser.c
index 0258945ea..7ee56fbd9 100644
--- a/procps/fuser.c
+++ b/procps/fuser.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * tiny fuser implementation 2 * tiny fuser implementation
3 * 3 *
4 * Copyright 2004 Tony J. White 4 * Copyright 2004 Tony J. White
5 * 5 *
6 * May be distributed under the conditions of the 6 * May be distributed under the conditions of the
@@ -25,9 +25,9 @@
25 25
26#define FUSER_OPT_MOUNT 1 26#define FUSER_OPT_MOUNT 1
27#define FUSER_OPT_KILL 2 27#define FUSER_OPT_KILL 2
28#define FUSER_OPT_SILENT 4 28#define FUSER_OPT_SILENT 4
29#define FUSER_OPT_IP6 8 29#define FUSER_OPT_IP6 8
30#define FUSER_OPT_IP4 16 30#define FUSER_OPT_IP4 16
31 31
32typedef struct inode_list { 32typedef struct inode_list {
33 ino_t inode; 33 ino_t inode;
@@ -40,7 +40,7 @@ typedef struct pid_list {
40 struct pid_list *next; 40 struct pid_list *next;
41} pid_list; 41} pid_list;
42 42
43static int fuser_option(char *option) 43static int fuser_option(char *option)
44{ 44{
45 int opt = 0; 45 int opt = 0;
46 46
@@ -55,7 +55,7 @@ static int fuser_option(char *option)
55 else if(*option == '4') opt |= FUSER_OPT_IP4; 55 else if(*option == '4') opt |= FUSER_OPT_IP4;
56 else { 56 else {
57 bb_error_msg_and_die( 57 bb_error_msg_and_die(
58 "Unsupported option '%c'", *option); 58 "Unsupported option '%c'", *option);
59 } 59 }
60 ++option; 60 ++option;
61 } 61 }
@@ -69,13 +69,13 @@ static int fuser_file_to_dev_inode(const char *filename,
69 if((stat(filename, &f_stat)) < 0) return 0; 69 if((stat(filename, &f_stat)) < 0) return 0;
70 *inode = f_stat.st_ino; 70 *inode = f_stat.st_ino;
71 *dev = f_stat.st_dev; 71 *dev = f_stat.st_dev;
72 return 1; 72 return 1;
73} 73}
74 74
75static int fuser_find_socket_dev(dev_t *dev) { 75static int fuser_find_socket_dev(dev_t *dev) {
76 int fd = socket(PF_INET, SOCK_DGRAM,0); 76 int fd = socket(PF_INET, SOCK_DGRAM,0);
77 struct stat buf; 77 struct stat buf;
78 78
79 if (fd >= 0 && (fstat(fd, &buf)) == 0) { 79 if (fd >= 0 && (fstat(fd, &buf)) == 0) {
80 *dev = buf.st_dev; 80 *dev = buf.st_dev;
81 close(fd); 81 close(fd);
@@ -84,8 +84,8 @@ static int fuser_find_socket_dev(dev_t *dev) {
84 return 0; 84 return 0;
85} 85}
86 86
87static int fuser_parse_net_arg(const char *filename, 87static int fuser_parse_net_arg(const char *filename,
88 const char **proto, int *port) 88 const char **proto, int *port)
89{ 89{
90 char path[sizeof(FUSER_PROC_DIR)+12], tproto[5]; 90 char path[sizeof(FUSER_PROC_DIR)+12], tproto[5];
91 91
@@ -93,51 +93,51 @@ static int fuser_parse_net_arg(const char *filename,
93 sprintf(path, "%s/net/%s", FUSER_PROC_DIR, tproto); 93 sprintf(path, "%s/net/%s", FUSER_PROC_DIR, tproto);
94 if((access(path, R_OK)) != 0) return 0; 94 if((access(path, R_OK)) != 0) return 0;
95 *proto = bb_xstrdup(tproto); 95 *proto = bb_xstrdup(tproto);
96 return 1; 96 return 1;
97} 97}
98 98
99static int fuser_add_pid(pid_list *plist, pid_t pid) 99static int fuser_add_pid(pid_list *plist, pid_t pid)
100{ 100{
101 pid_list *curr = NULL, *last = NULL; 101 pid_list *curr = NULL, *last = NULL;
102 102
103 if(plist->pid == 0) plist->pid = pid; 103 if(plist->pid == 0) plist->pid = pid;
104 curr = plist; 104 curr = plist;
105 while(curr != NULL) { 105 while(curr != NULL) {
106 if(curr->pid == pid) return 1; 106 if(curr->pid == pid) return 1;
107 last = curr; 107 last = curr;
108 curr = curr->next; 108 curr = curr->next;
109 } 109 }
110 curr = xmalloc(sizeof(pid_list)); 110 curr = xmalloc(sizeof(pid_list));
111 last->next = curr; 111 last->next = curr;
112 curr->pid = pid; 112 curr->pid = pid;
113 curr->next = NULL; 113 curr->next = NULL;
114 return 1; 114 return 1;
115} 115}
116 116
117static int fuser_add_inode(inode_list *ilist, dev_t dev, ino_t inode) 117static int fuser_add_inode(inode_list *ilist, dev_t dev, ino_t inode)
118{ 118{
119 inode_list *curr = NULL, *last = NULL; 119 inode_list *curr = NULL, *last = NULL;
120 120
121 if(!ilist->inode && !ilist->dev) { 121 if(!ilist->inode && !ilist->dev) {
122 ilist->dev = dev; 122 ilist->dev = dev;
123 ilist->inode = inode; 123 ilist->inode = inode;
124 } 124 }
125 curr = ilist; 125 curr = ilist;
126 while(curr != NULL) { 126 while(curr != NULL) {
127 if(curr->inode == inode && curr->dev == dev) return 1; 127 if(curr->inode == inode && curr->dev == dev) return 1;
128 last = curr; 128 last = curr;
129 curr = curr->next; 129 curr = curr->next;
130 } 130 }
131 curr = xmalloc(sizeof(inode_list)); 131 curr = xmalloc(sizeof(inode_list));
132 last->next = curr; 132 last->next = curr;
133 curr->dev = dev; 133 curr->dev = dev;
134 curr->inode = inode; 134 curr->inode = inode;
135 curr->next = NULL; 135 curr->next = NULL;
136 return 1; 136 return 1;
137} 137}
138 138
139static int fuser_scan_proc_net(int opts, const char *proto, 139static int fuser_scan_proc_net(int opts, const char *proto,
140 int port, inode_list *ilist) 140 int port, inode_list *ilist)
141{ 141{
142 char path[sizeof(FUSER_PROC_DIR)+12], line[FUSER_MAX_LINE+1]; 142 char path[sizeof(FUSER_PROC_DIR)+12], line[FUSER_MAX_LINE+1];
143 char addr[128]; 143 char addr[128];
@@ -156,10 +156,10 @@ static int fuser_scan_proc_net(int opts, const char *proto,
156 "%*d: %64[0-9A-Fa-f]:%x %*x:%*x %*x %*x:%*x " 156 "%*d: %64[0-9A-Fa-f]:%x %*x:%*x %*x %*x:%*x "
157 "%*x:%*x %*x %*d %*d %llu", 157 "%*x:%*x %*x %*d %*d %llu",
158 addr, &tmp_port, &uint64_inode) == 3) { 158 addr, &tmp_port, &uint64_inode) == 3) {
159 if((strlen(addr) == 8) && 159 if((strlen(addr) == 8) &&
160 (opts & FUSER_OPT_IP6)) continue; 160 (opts & FUSER_OPT_IP6)) continue;
161 else if((strlen(addr) > 8) && 161 else if((strlen(addr) > 8) &&
162 (opts & FUSER_OPT_IP4)) continue; 162 (opts & FUSER_OPT_IP4)) continue;
163 if(tmp_port == port) { 163 if(tmp_port == port) {
164 tmp_inode = uint64_inode; 164 tmp_inode = uint64_inode;
165 fuser_add_inode(ilist, tmp_dev, tmp_inode); 165 fuser_add_inode(ilist, tmp_dev, tmp_inode);
@@ -171,24 +171,24 @@ static int fuser_scan_proc_net(int opts, const char *proto,
171 return 1; 171 return 1;
172} 172}
173 173
174static int fuser_search_dev_inode(int opts, inode_list *ilist, 174static int fuser_search_dev_inode(int opts, inode_list *ilist,
175 dev_t dev, ino_t inode) 175 dev_t dev, ino_t inode)
176{ 176{
177 inode_list *curr; 177 inode_list *curr;
178 curr = ilist; 178 curr = ilist;
179 179
180 while(curr) { 180 while(curr) {
181 if((opts & FUSER_OPT_MOUNT) && curr->dev == dev) 181 if((opts & FUSER_OPT_MOUNT) && curr->dev == dev)
182 return 1; 182 return 1;
183 if(curr->inode == inode && curr->dev == dev) 183 if(curr->inode == inode && curr->dev == dev)
184 return 1; 184 return 1;
185 curr = curr->next; 185 curr = curr->next;
186 } 186 }
187 return 0; 187 return 0;
188} 188}
189 189
190static int fuser_scan_pid_maps(int opts, const char *fname, pid_t pid, 190static int fuser_scan_pid_maps(int opts, const char *fname, pid_t pid,
191 inode_list *ilist, pid_list *plist) 191 inode_list *ilist, pid_list *plist)
192{ 192{
193 FILE *file; 193 FILE *file;
194 char line[FUSER_MAX_LINE + 1]; 194 char line[FUSER_MAX_LINE + 1];
@@ -199,28 +199,28 @@ static int fuser_scan_pid_maps(int opts, const char *fname, pid_t pid,
199 199
200 if (!(file = fopen(fname, "r"))) return 0; 200 if (!(file = fopen(fname, "r"))) return 0;
201 while (fgets(line, FUSER_MAX_LINE, file)) { 201 while (fgets(line, FUSER_MAX_LINE, file)) {
202 if(sscanf(line, "%*s %*s %*s %x:%x %llu", 202 if(sscanf(line, "%*s %*s %*s %x:%x %llu",
203 &major, &minor, &uint64_inode) != 3) continue; 203 &major, &minor, &uint64_inode) != 3) continue;
204 inode = uint64_inode; 204 inode = uint64_inode;
205 if(major == 0 && minor == 0 && inode == 0) continue; 205 if(major == 0 && minor == 0 && inode == 0) continue;
206 dev = makedev(major, minor); 206 dev = makedev(major, minor);
207 if(fuser_search_dev_inode(opts, ilist, dev, inode)) { 207 if(fuser_search_dev_inode(opts, ilist, dev, inode)) {
208 fuser_add_pid(plist, pid); 208 fuser_add_pid(plist, pid);
209 } 209 }
210 210
211 } 211 }
212 fclose(file); 212 fclose(file);
213 return 1; 213 return 1;
214} 214}
215 215
216static int fuser_scan_link(int opts, const char *lname, pid_t pid, 216static int fuser_scan_link(int opts, const char *lname, pid_t pid,
217 inode_list *ilist, pid_list *plist) 217 inode_list *ilist, pid_list *plist)
218{ 218{
219 ino_t inode; 219 ino_t inode;
220 dev_t dev; 220 dev_t dev;
221 221
222 if(!fuser_file_to_dev_inode(lname, &dev, &inode)) return 0; 222 if(!fuser_file_to_dev_inode(lname, &dev, &inode)) return 0;
223 if(fuser_search_dev_inode(opts, ilist, dev, inode)) 223 if(fuser_search_dev_inode(opts, ilist, dev, inode))
224 fuser_add_pid(plist, pid); 224 fuser_add_pid(plist, pid);
225 return 1; 225 return 1;
226} 226}
@@ -245,9 +245,9 @@ static int fuser_scan_dir_links(int opts, const char *dname, pid_t pid,
245 else return 0; 245 else return 0;
246 return 1; 246 return 1;
247 247
248} 248}
249 249
250static int fuser_scan_proc_pids(int opts, inode_list *ilist, pid_list *plist) 250static int fuser_scan_proc_pids(int opts, inode_list *ilist, pid_list *plist)
251{ 251{
252 DIR *d; 252 DIR *d;
253 struct dirent *de; 253 struct dirent *de;
@@ -261,7 +261,7 @@ static int fuser_scan_proc_pids(int opts, inode_list *ilist, pid_list *plist)
261 dname = concat_subpath_file(FUSER_PROC_DIR, de->d_name); 261 dname = concat_subpath_file(FUSER_PROC_DIR, de->d_name);
262 if(chdir(dname) < 0) { 262 if(chdir(dname) < 0) {
263 free(dname); 263 free(dname);
264 continue; 264 continue;
265 } 265 }
266 free(dname); 266 free(dname);
267 fuser_scan_link(opts, "cwd", pid, ilist, plist); 267 fuser_scan_link(opts, "cwd", pid, ilist, plist);
@@ -272,8 +272,8 @@ static int fuser_scan_proc_pids(int opts, inode_list *ilist, pid_list *plist)
272 fuser_scan_dir_links(opts, "mmap", pid, ilist, plist); 272 fuser_scan_dir_links(opts, "mmap", pid, ilist, plist);
273 fuser_scan_pid_maps(opts, "maps", pid, ilist, plist); 273 fuser_scan_pid_maps(opts, "maps", pid, ilist, plist);
274 chdir(".."); 274 chdir("..");
275 } 275 }
276 closedir(d); 276 closedir(d);
277 return 1; 277 return 1;
278} 278}
279 279
@@ -290,22 +290,22 @@ static int fuser_print_pid_list(pid_list *plist) {
290} 290}
291 291
292static int fuser_kill_pid_list(pid_list *plist, int sig) { 292static int fuser_kill_pid_list(pid_list *plist, int sig) {
293 pid_list *curr = plist; 293 pid_list *curr = plist;
294 pid_t mypid = getpid(); 294 pid_t mypid = getpid();
295 int success = 1; 295 int success = 1;
296 296
297 if(plist == NULL) return 0; 297 if(plist == NULL) return 0;
298 while(curr != NULL) { 298 while(curr != NULL) {
299 if(curr->pid > 0 && curr->pid != mypid) { 299 if(curr->pid > 0 && curr->pid != mypid) {
300 if (kill(curr->pid, sig) != 0) { 300 if (kill(curr->pid, sig) != 0) {
301 bb_perror_msg( 301 bb_perror_msg(
302 "Could not kill pid '%d'", curr->pid); 302 "Could not kill pid '%d'", curr->pid);
303 success = 0; 303 success = 0;
304 } 304 }
305 } 305 }
306 curr = curr->next; 306 curr = curr->next;
307 } 307 }
308 return success; 308 return success;
309} 309}
310 310
311extern int fuser_main(int argc, char **argv) { 311extern int fuser_main(int argc, char **argv) {
@@ -324,7 +324,7 @@ extern int fuser_main(int argc, char **argv) {
324 fni = xmalloc(sizeof(int)); 324 fni = xmalloc(sizeof(int));
325 for(i=1;i<argc;i++) { 325 for(i=1;i<argc;i++) {
326 optn = fuser_option(argv[i]); 326 optn = fuser_option(argv[i]);
327 if(optn) opt |= optn; 327 if(optn) opt |= optn;
328 else if(argv[i][0] == '-') { 328 else if(argv[i][0] == '-') {
329 if(!(u_signal_names(argv[i]+1, &killsig, 0))) 329 if(!(u_signal_names(argv[i]+1, &killsig, 0)))
330 killsig = SIGTERM; 330 killsig = SIGTERM;
@@ -368,4 +368,4 @@ extern int fuser_main(int argc, char **argv) {
368 free(inodes); 368 free(inodes);
369 /* return 0 on (success == 1) 1 otherwise */ 369 /* return 0 on (success == 1) 1 otherwise */
370 return (success != 1); 370 return (success != 1);
371} 371}
diff --git a/procps/kill.c b/procps/kill.c
index 6d7f083b8..2d4e6deb4 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -87,7 +87,7 @@ extern int kill_main(int argc, char **argv)
87 return EXIT_SUCCESS; 87 return EXIT_SUCCESS;
88 } 88 }
89 89
90#ifdef CONFIG_KILLALL 90#ifdef CONFIG_KILLALL
91 /* The -q quiet option */ 91 /* The -q quiet option */
92 if(argv[1][1]=='q' && argv[1][2]=='\0'){ 92 if(argv[1][1]=='q' && argv[1][2]=='\0'){
93 quiet++; 93 quiet++;
diff --git a/procps/top.c b/procps/top.c
index 5faeafb59..a2a44da7d 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -133,20 +133,20 @@ static unsigned long Hertz;
133#define FILE_TO_BUF(filename, fd) do{ \ 133#define FILE_TO_BUF(filename, fd) do{ \
134 if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \ 134 if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \
135 bb_perror_msg_and_die("/proc not be mounted?"); \ 135 bb_perror_msg_and_die("/proc not be mounted?"); \
136 } \ 136 } \
137 lseek(fd, 0L, SEEK_SET); \ 137 lseek(fd, 0L, SEEK_SET); \
138 if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \ 138 if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \
139 bb_perror_msg_and_die("%s", filename); \ 139 bb_perror_msg_and_die("%s", filename); \
140 } \ 140 } \
141 buf[local_n] = '\0'; \ 141 buf[local_n] = '\0'; \
142}while(0) 142}while(0)
143 143
144#define FILE_TO_BUF2(filename, fd) do{ \ 144#define FILE_TO_BUF2(filename, fd) do{ \
145 lseek(fd, 0L, SEEK_SET); \ 145 lseek(fd, 0L, SEEK_SET); \
146 if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \ 146 if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \
147 bb_perror_msg_and_die("%s", filename); \ 147 bb_perror_msg_and_die("%s", filename); \
148 } \ 148 } \
149 buf[local_n] = '\0'; \ 149 buf[local_n] = '\0'; \
150}while(0) 150}while(0)
151 151
152static void init_Hertz_value(void) { 152static void init_Hertz_value(void) {