ethr-wake: can use ether_hostton on uclibc >= 0.9.30
[oweals/busybox.git] / procps / fuser.c
index 8afa958b63f268108d5f9ab62e84de4cd120598e..dc3d01bdaa918aaa219eddf8c8d3c2f4e754cf1c 100644 (file)
@@ -4,8 +4,7 @@
  *
  * Copyright 2004 Tony J. White
  *
- * May be distributed under the conditions of the
- * GNU Library General Public License
+ * Licensed under GPLv2, see file LICENSE in this tarball for details.
  */
 
 #include "libbb.h"
@@ -100,7 +99,6 @@ static inode_list *scan_proc_net(const char *proto,
                                unsigned port, inode_list *ilist)
 {
        char path[20], line[MAX_LINE + 1];
-       char addr[128];
        ino_t tmp_inode;
        dev_t tmp_dev;
        long long uint64_inode;
@@ -110,18 +108,20 @@ static inode_list *scan_proc_net(const char *proto,
        tmp_dev = find_socket_dev();
 
        sprintf(path, "/proc/net/%s", proto);
-       f = fopen(path, "r");
+       f = fopen_for_read(path);
        if (!f)
                return ilist;
 
        while (fgets(line, MAX_LINE, f)) {
+               char addr[68];
                if (sscanf(line, "%*d: %64[0-9A-Fa-f]:%x %*x:%*x %*x %*x:%*x "
                                "%*x:%*x %*x %*d %*d %llu",
                                addr, &tmp_port, &uint64_inode) == 3
                ) {
-                       if (strlen(addr) == 8 && (option_mask32 & OPT_IP6))
+                       int len = strlen(addr);
+                       if (len == 8 && (option_mask32 & OPT_IP6))
                                continue;
-                       if (strlen(addr) > 8 && (option_mask32 & OPT_IP4))
+                       if (len > 8 && (option_mask32 & OPT_IP4))
                                continue;
                        if (tmp_port == port) {
                                tmp_inode = uint64_inode;
@@ -157,7 +157,7 @@ static pid_list *scan_pid_maps(const char *fname, pid_t pid,
        long long uint64_inode;
        dev_t dev;
 
-       file = fopen(fname, "r");
+       file = fopen_for_read(fname);
        if (!file)
                return plist;
        while (fgets(line, MAX_LINE, file)) {
@@ -325,7 +325,7 @@ Find processes which use FILEs or PORTs
                        free(proto);
                } else { /* FILE */
                        if (!file_to_dev_inode(*pp, &dev, &inode))
-                               bb_perror_msg_and_die("can't open %s", *pp);
+                               bb_perror_msg_and_die("can't open '%s'", *pp);
                        ilist = add_inode(ilist, dev, inode);
                }
                pp++;