aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksym Kryzhanovskyy <xmaks@email.cz>2010-06-06 22:56:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-06-06 22:56:12 +0200
commite3657dcdd655ec96fc6bf38c40dd6a6f015a83de (patch)
tree53bd8c2b7437dc5940afbb0731a447bfa19d5ae1
parentc8aae0b2a0406b499ec8dea4a1e29b52be9da0d0 (diff)
downloadbusybox-e3657dcdd655ec96fc6bf38c40dd6a6f015a83de.tar.gz
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.c44
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 {
#define INIT_G() do { } while (0)
-static dev_t find_socket_dev(void)
-{
- int fd = socket(AF_INET, SOCK_DGRAM, 0);
- if (fd >= 0) {
- struct stat buf;
- int r = fstat(fd, &buf);
- close(fd);
- if (r == 0)
- return buf.st_dev;
- }
- return 0;
-}
-
-static char *parse_net_arg(const char *arg, unsigned *port)
-{
- char path[20], tproto[5];
-
- if (sscanf(arg, "%u/%4s", port, tproto) != 2)
- return NULL;
- sprintf(path, "/proc/net/%s", tproto);
- if (access(path, R_OK) != 0)
- return NULL;
- return xstrdup(path);
-}
-
static void add_pid(const pid_t pid)
{
pid_list **curr = &G.pid_list_head;
@@ -104,8 +79,15 @@ static void scan_proc_net(const char *path, unsigned port)
unsigned tmp_port;
FILE *f;
struct stat st;
+ int fd;
- st.st_dev = find_socket_dev();
+ /* find socket dev */
+ st.st_dev = 0;
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd >= 0) {
+ fstat(fd, &st);
+ close(fd);
+ }
f = fopen_for_read(path);
if (!f)
@@ -284,11 +266,15 @@ Find processes which use FILEs or PORTs
pp = argv;
while (*pp) {
- char *path = parse_net_arg(*pp, &port);
- if (path) { /* PORT/PROTO */
+ /* parse net arg */
+ char path[20], tproto[5];
+ if (sscanf(*pp, "%u/%4s", &port, tproto) != 2)
+ goto file;
+ sprintf(path, "/proc/net/%s", tproto);
+ if (access(path, R_OK) != 0) { /* PORT/PROTO */
scan_proc_net(path, port);
- free(path);
} else { /* FILE */
+ file:
xstat(*pp, &st);
add_inode(&st);
}