]> granicus.if.org Git - psmisc/commitdiff
fuser -m with sockets
authorCraig Small <csmall@users.sourceforge.net>
Mon, 12 Nov 2007 15:40:39 +0000 (15:40 +0000)
committerCraig Small <csmall@users.sourceforge.net>
Mon, 12 Nov 2007 15:40:39 +0000 (15:40 +0000)
ChangeLog
src/fuser.c

index 52a8ce77e0eb32ffdb78c542b77b81822db0f120..699198ee988d2ce8ea08213cf83afc6236c60d9e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@ Changes in ??
 ==============
 2007-11-13 Craig Small
        * Updated French and German po files
+       * Fuser -m detects more open sockets SF patch #1728412 Thnks marienz
 
 2007-11-07 Craig Small
        * Updated Italian, Chinese simplified, Dutch, Swedish and Polish po files
index b88b7a8108ea8728b78a15fcf68a6f39313da8da..b1fe21aaff356d9ed713cb3e578493eeded88ea5 100644 (file)
@@ -60,7 +60,8 @@
 #define NAME_FIELD 20          /* space reserved for file name */
 /* Function defines */
 static void add_matched_proc(struct names *name_list, const pid_t pid, const uid_t uid, const char access);
-static void check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, struct inode_list *ino_head, const uid_t uid, const char access);
+static void check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, struct inode_list *ino_head, const uid_t uid, const char access,
+                      struct unixsocket_list *sockets, dev_t netdev);
 static void check_map(const pid_t pid, const char *filename, struct device_list *dev_head, struct inode_list *ino_head, const uid_t uid, const char access);
 static struct stat *get_pidstat(const pid_t pid, const char *filename);
 static uid_t getpiduid(const pid_t pid);
@@ -72,7 +73,7 @@ static void add_device(struct device_list **dev_list, struct names  *this_name,
 void scan_mount_devices(const opt_type opts, struct mountdev_list **mount_devices);
 void fill_unix_cache(struct unixsocket_list **unixsocket_head);
 static dev_t find_net_dev(void);
-static void scan_procs(struct names *names_head, struct inode_list *ino_head, struct device_list *dev_head);
+static void scan_procs(struct names *names_head, struct inode_list *ino_head, struct device_list *dev_head, struct unixsocket_list *sockets, dev_t netdev);
 #ifdef NFS_CHECKS
 static void scan_knfsd(struct names *names_head, struct device_list *dev_head);
 #endif /* NFS_CHECKS */
@@ -127,7 +128,7 @@ void print_version()
     "For more information about these matters, see the files named COPYING.\n"));
 }
 
-static void scan_procs(struct names *names_head, struct inode_list *ino_head, struct device_list *dev_head)
+static void scan_procs(struct names *names_head, struct inode_list *ino_head, struct device_list *dev_head, struct unixsocket_list *sockets, dev_t netdev)
 {
        DIR *topproc_dir;
        struct dirent *topproc_dent;
@@ -187,9 +188,9 @@ static void scan_procs(struct names *names_head, struct inode_list *ino_head, st
                                }
                        }
                }
-               check_dir(pid, "lib", dev_head, ino_head, uid, ACCESS_MMAP);
-               check_dir(pid, "mmap", dev_head, ino_head, uid, ACCESS_MMAP);
-               check_dir(pid, "fd", dev_head, ino_head, uid, ACCESS_FILE);
+               check_dir(pid, "lib", dev_head, ino_head, uid, ACCESS_MMAP, sockets, netdev);
+               check_dir(pid, "mmap", dev_head, ino_head, uid, ACCESS_MMAP, sockets, netdev);
+               check_dir(pid, "fd", dev_head, ino_head, uid, ACCESS_FILE, sockets, netdev);
                check_map(pid, "maps", dev_head, ino_head, uid, ACCESS_MMAP);
 
        } /* while topproc_dent */
@@ -872,7 +873,7 @@ int main(int argc, char *argv[])
 #ifdef DEBUG
        debug_match_lists(names_head, match_inodes, match_devices);
 #endif
-       scan_procs(names_head, match_inodes, match_devices);
+       scan_procs(names_head, match_inodes, match_devices, unixsockets, netdev);
 #ifdef NFS_CHECKS
     scan_knfsd(names_head, match_devices);
 #endif /* NFS_CHECKS */
@@ -992,13 +993,15 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename)
                return st;
 }
 
-static void check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, struct inode_list *ino_head, const uid_t uid, const char access)
+static void check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, struct inode_list *ino_head, const uid_t uid, const char access,
+                      struct unixsocket_list *sockets, dev_t netdev)
 {
        char *dirpath, *filepath;
        DIR *dirp;
        struct dirent *direntry;
        struct inode_list *ino_tmp;
        struct device_list *dev_tmp;
+       struct unixsocket_list *sock_tmp;
        struct stat st, lst;
 
        if ( (dirpath = malloc(MAX_PATHNAME)) == NULL)
@@ -1018,6 +1021,15 @@ static void check_dir(const pid_t pid, const char *dirname, struct device_list *
                if (stat(filepath, &st) != 0) {
                        fprintf(stderr, _("Cannot stat file %s: %s\n"),filepath, strerror(errno));
                } else {
+                       if (st.st_dev == netdev) {
+                               for (sock_tmp = sockets; sock_tmp != NULL; sock_tmp = sock_tmp->next) {
+                                       if (sock_tmp->net_inode == st.st_ino) {
+                                               st.st_ino = sock_tmp->inode;
+                                               st.st_dev = sock_tmp->dev;
+                                               break;
+                                       }
+                               }
+                       }
                        for (dev_tmp = dev_head ; dev_tmp != NULL ; dev_tmp = dev_tmp->next) {
                                if (st.st_dev == dev_tmp->device) {
                                        if (access == ACCESS_FILE && (lstat(filepath, &lst)==0) && (lst.st_mode & S_IWUSR)) {