diff options
author | Maksym Kryzhanovskyy <xmaks@email.cz> | 2010-06-06 22:56:12 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-06 22:56:12 +0200 |
commit | e3657dcdd655ec96fc6bf38c40dd6a6f015a83de (patch) | |
tree | 53bd8c2b7437dc5940afbb0731a447bfa19d5ae1 | |
parent | c8aae0b2a0406b499ec8dea4a1e29b52be9da0d0 (diff) | |
download | busybox-w32-e3657dcdd655ec96fc6bf38c40dd6a6f015a83de.tar.gz busybox-w32-e3657dcdd655ec96fc6bf38c40dd6a6f015a83de.tar.bz2 busybox-w32-e3657dcdd655ec96fc6bf38c40dd6a6f015a83de.zip |
fuser: code shrink
function old new delta
fuser_main 918 871 -47
Signed-off-by: Maksym Kryzhanovskyy <xmaks@email.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/fuser.c | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/procps/fuser.c b/procps/fuser.c index 7465d4554..85523c31c 100644 --- a/procps/fuser.c +++ b/procps/fuser.c | |||
@@ -40,31 +40,6 @@ struct globals { | |||
40 | #define INIT_G() do { } while (0) | 40 | #define INIT_G() do { } while (0) |
41 | 41 | ||
42 | 42 | ||
43 | static dev_t find_socket_dev(void) | ||
44 | { | ||
45 | int fd = socket(AF_INET, SOCK_DGRAM, 0); | ||
46 | if (fd >= 0) { | ||
47 | struct stat buf; | ||
48 | int r = fstat(fd, &buf); | ||
49 | close(fd); | ||
50 | if (r == 0) | ||
51 | return buf.st_dev; | ||
52 | } | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | static char *parse_net_arg(const char *arg, unsigned *port) | ||
57 | { | ||
58 | char path[20], tproto[5]; | ||
59 | |||
60 | if (sscanf(arg, "%u/%4s", port, tproto) != 2) | ||
61 | return NULL; | ||
62 | sprintf(path, "/proc/net/%s", tproto); | ||
63 | if (access(path, R_OK) != 0) | ||
64 | return NULL; | ||
65 | return xstrdup(path); | ||
66 | } | ||
67 | |||
68 | static void add_pid(const pid_t pid) | 43 | static void add_pid(const pid_t pid) |
69 | { | 44 | { |
70 | pid_list **curr = &G.pid_list_head; | 45 | pid_list **curr = &G.pid_list_head; |
@@ -104,8 +79,15 @@ static void scan_proc_net(const char *path, unsigned port) | |||
104 | unsigned tmp_port; | 79 | unsigned tmp_port; |
105 | FILE *f; | 80 | FILE *f; |
106 | struct stat st; | 81 | struct stat st; |
82 | int fd; | ||
107 | 83 | ||
108 | st.st_dev = find_socket_dev(); | 84 | /* find socket dev */ |
85 | st.st_dev = 0; | ||
86 | fd = socket(AF_INET, SOCK_DGRAM, 0); | ||
87 | if (fd >= 0) { | ||
88 | fstat(fd, &st); | ||
89 | close(fd); | ||
90 | } | ||
109 | 91 | ||
110 | f = fopen_for_read(path); | 92 | f = fopen_for_read(path); |
111 | if (!f) | 93 | if (!f) |
@@ -284,11 +266,15 @@ Find processes which use FILEs or PORTs | |||
284 | 266 | ||
285 | pp = argv; | 267 | pp = argv; |
286 | while (*pp) { | 268 | while (*pp) { |
287 | char *path = parse_net_arg(*pp, &port); | 269 | /* parse net arg */ |
288 | if (path) { /* PORT/PROTO */ | 270 | char path[20], tproto[5]; |
271 | if (sscanf(*pp, "%u/%4s", &port, tproto) != 2) | ||
272 | goto file; | ||
273 | sprintf(path, "/proc/net/%s", tproto); | ||
274 | if (access(path, R_OK) != 0) { /* PORT/PROTO */ | ||
289 | scan_proc_net(path, port); | 275 | scan_proc_net(path, port); |
290 | free(path); | ||
291 | } else { /* FILE */ | 276 | } else { /* FILE */ |
277 | file: | ||
292 | xstat(*pp, &st); | 278 | xstat(*pp, &st); |
293 | add_inode(&st); | 279 | add_inode(&st); |
294 | } | 280 | } |