rpms/psmisc/F-7 psmisc-22.3-fuser-nfs.patch, NONE, 1.1 psmisc.spec, 1.35, 1.36

Tomas Smetana (tsmetana) fedora-extras-commits at redhat.com
Mon Aug 20 13:37:03 UTC 2007


Author: tsmetana

Update of /cvs/pkgs/rpms/psmisc/F-7
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv6173

Modified Files:
	psmisc.spec 
Added Files:
	psmisc-22.3-fuser-nfs.patch 
Log Message:
* Mon Aug 20 2007 Tomas Smetana <tsmetana at redhat.com> 22.3-3
- fix #245538 - fuser incorrectly reports processess using nfs filesystems
- update license tag


psmisc-22.3-fuser-nfs.patch:

--- NEW FILE psmisc-22.3-fuser-nfs.patch ---
--- psmisc-22.3/src/fuser.c.nfs	2007-08-20 15:28:37.000000000 +0200
+++ psmisc-22.3/src/fuser.c	2007-08-20 15:30:50.000000000 +0200
@@ -57,7 +57,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, struct mountdev_list *mount_list, const uid_t uid, const char access);
 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);
@@ -69,7 +70,7 @@
 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 mountdev_list *mount_devices);
 #ifdef NFS_CHECKS
 static void scan_knfsd(struct names *names_head, struct device_list *dev_head);
 #endif /* NFS_CHECKS */
@@ -122,7 +123,7 @@
     "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 mountdev_list *mount_devices)
 {
 	DIR *topproc_dir;
 	struct dirent *topproc_dent;
@@ -182,9 +183,9 @@
 				}
 			}
 		}
-		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, mount_devices, uid, ACCESS_MMAP);
+		check_dir(pid, "mmap", dev_head, ino_head, mount_devices, uid, ACCESS_MMAP);
+		check_dir(pid, "fd", dev_head, ino_head, mount_devices, uid, ACCESS_FILE);
 		check_map(pid, "maps", dev_head, ino_head, uid, ACCESS_MMAP);
 
 	} /* while topproc_dent */
@@ -837,7 +838,7 @@
 #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, mount_devices);
 #ifdef NFS_CHECKS
     scan_knfsd(names_head, match_devices);
 #endif /* NFS_CHECKS */
@@ -951,19 +952,24 @@
 		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, struct mountdev_list *mount_list, const uid_t uid, const char access)
 {
-	char *dirpath, *filepath;
+	char *dirpath, *filepath, *realname;
 	DIR *dirp;
 	struct dirent *direntry;
 	struct inode_list *ino_tmp;
 	struct device_list *dev_tmp;
+	struct mountdev_list *mnt_tmp;
 	struct stat st, lst;
+	int realname_len, on_nfs, proc_added;
 
 	if ( (dirpath = malloc(MAX_PATHNAME)) == NULL)
 		return;
 	if ( (filepath = malloc(MAX_PATHNAME)) == NULL)
 		return;
+	if ( (realname = malloc(MAX_PATHNAME)) == NULL)
+		return;
 
 	snprintf(dirpath, MAX_PATHNAME, "/proc/%d/%s", pid, dirname);
 	if ( (dirp = opendir(dirpath)) == NULL)
@@ -974,24 +980,61 @@
 
 		snprintf(filepath, MAX_PATHNAME, "/proc/%d/%s/%s",
 			pid, dirname, direntry->d_name);
-		if (stat(filepath, &st) != 0) {
-			fprintf(stderr, _("Cannot stat file %s: %s\n"),filepath, strerror(errno));
-		} else {
-			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)) {
-						add_matched_proc(dev_tmp->name, pid,uid, ACCESS_FILEWR|access);
-					} else  {
-						add_matched_proc(dev_tmp->name, pid,uid, access);
+		if ((realname_len = readlink(filepath, realname, MAX_PATHNAME - 1)) == - 1)
+		{
+			fprintf(stderr, "Cannot read link %s\n", filepath);
+		}
+		realname[realname_len] = '\0';
+		on_nfs = 0;
+		proc_added = 0;
+		for (mnt_tmp = mount_list; mnt_tmp != NULL; mnt_tmp = mnt_tmp->next)
+		{
+			if (mnt_tmp->fstype == DEV_TYPE_NFS) {
+				if (!strncmp(mnt_tmp->dir, realname, strlen(mnt_tmp->dir))) {
+					on_nfs = 1;
+					for (dev_tmp = dev_head ; dev_tmp != NULL ; dev_tmp = dev_tmp->next) {
+						if ((!strncmp(mnt_tmp->dir, dev_tmp->name->filename, strlen(mnt_tmp->dir))) && 
+							(!strncmp(dev_tmp->name->filename, realname, strlen(mnt_tmp->dir)))) {
+							proc_added = 1;
+							if (access == ACCESS_FILE && (lstat(filepath, &lst)==0) && (lst.st_mode & S_IWUSR)) {
+								add_matched_proc(dev_tmp->name, pid,uid, ACCESS_FILEWR|access);
+							} else  {
+								add_matched_proc(dev_tmp->name, pid,uid, access);
+							}
+						}
+					}
+				}
+			}
+		}
+		if ((!proc_added) && (!on_nfs)) {
+			if (!on_nfs) {
+				if (stat(filepath, &st) != 0) {
+					fprintf(stderr, _("Cannot stat file %s: %s\n"),filepath, strerror(errno));
+				} else {
+					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)) {
+								add_matched_proc(dev_tmp->name, pid,uid, ACCESS_FILEWR|access);
+							} else  {
+								add_matched_proc(dev_tmp->name, pid,uid, access);
+							}
+							proc_added = 1;
+						}
 					}
 				}
 			}
-			for (ino_tmp = ino_head ; ino_tmp != NULL ; ino_tmp = ino_tmp->next) {
-				if (st.st_dev == ino_tmp->device && st.st_ino == ino_tmp->inode) {
-					if (access == ACCESS_FILE && (lstat(filepath, &lst)==0) && (lst.st_mode & S_IWUSR)) {
-						add_matched_proc(ino_tmp->name, pid,uid, ACCESS_FILEWR|access);
-					} else {
-						add_matched_proc(ino_tmp->name, pid,uid, access);
+			if (!proc_added) {
+				if (stat(filepath, &st) != 0) {
+					fprintf(stderr, _("Cannot stat file %s: %s\n"),filepath, strerror(errno));
+				} else {
+					for (ino_tmp = ino_head ; ino_tmp != NULL ; ino_tmp = ino_tmp->next) {
+						if (st.st_dev == ino_tmp->device && st.st_ino == ino_tmp->inode) {
+							if (access == ACCESS_FILE && (lstat(filepath, &lst)==0) && (lst.st_mode & S_IWUSR)) {
+								add_matched_proc(ino_tmp->name, pid,uid, ACCESS_FILEWR|access);
+							} else {
+								add_matched_proc(ino_tmp->name, pid,uid, access);
+							}
+						}
 					}
 				}
 			}
@@ -1041,7 +1084,7 @@
 	return st.st_uid;
 }
 
-void add_mount_device(struct mountdev_list **mount_head,const char *fsname, const char *dir, dev_t device)
+void add_mount_device(struct mountdev_list **mount_head,const char *fsname, const char *dir, dev_t device, DEVICE_TYPE fstype)
 {
 	struct mountdev_list *newmount;
 	/*printf("Adding mount Path: %s Dir:%s dev:%0x\n",dir, fsname, device);*/
@@ -1049,6 +1092,7 @@
 	if ( (newmount = malloc(sizeof(struct mountdev_list))) == NULL)
 		return;
 	newmount->fsname = strdup(fsname);
+	newmount->fstype = fstype;
 	newmount->dir = strdup(dir);
 	newmount->device = device;
 	newmount->next = *mount_head;
@@ -1103,6 +1147,7 @@
 	FILE *mntfp;
 	struct mntent *mnt_ptr;
 	struct stat st;
+	DEVICE_TYPE mnt_type;
 	
 	if ( (mntfp = setmntent("/etc/mtab","r")) == NULL) {
 		fprintf(stderr, _("Cannot open /etc/mtab: %s\n"),
@@ -1110,8 +1155,14 @@
 		return;
 	}
 	while ( (mnt_ptr = getmntent(mntfp)) != NULL) {
-		if (stat(mnt_ptr->mnt_dir, &st) == 0) {
-			add_mount_device(mount_devices, mnt_ptr->mnt_fsname, mnt_ptr->mnt_dir, st.st_dev);
+		if (!strcmp(mnt_ptr->mnt_type, "nfs")) {
+				mnt_type = DEV_TYPE_NFS;
+				add_mount_device(mount_devices, mnt_ptr->mnt_fsname, mnt_ptr->mnt_dir, -1, mnt_type);
+		} else {
+			if (stat(mnt_ptr->mnt_dir, &st) == 0) {
+				mnt_type = DEV_TYPE_OTHER;
+				add_mount_device(mount_devices, mnt_ptr->mnt_fsname, mnt_ptr->mnt_dir, st.st_dev, mnt_type);
+			}
 		}
 	}
 }
--- psmisc-22.3/src/fuser.h.nfs	2007-08-20 15:28:42.000000000 +0200
+++ psmisc-22.3/src/fuser.h	2007-08-20 15:30:50.000000000 +0200
@@ -58,8 +58,14 @@
 	struct inode_list *next;
 };
 
+typedef enum {
+	DEV_TYPE_NFS = 0,
+	DEV_TYPE_OTHER
+} DEVICE_TYPE;
+
 struct mountdev_list {
 	char *fsname;
+	DEVICE_TYPE fstype;
 	char *dir;
 	dev_t	device;
 	struct mountdev_list *next;


Index: psmisc.spec
===================================================================
RCS file: /cvs/pkgs/rpms/psmisc/F-7/psmisc.spec,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- psmisc.spec	2 Apr 2007 11:41:12 -0000	1.35
+++ psmisc.spec	20 Aug 2007 13:36:31 -0000	1.36
@@ -1,8 +1,8 @@
 Summary: Utilities for managing processes on your system
 Name: psmisc
 Version: 22.3
-Release: 2%{?dist}
-License: BSD/GPL
+Release: 3%{?dist}
+License: BSD and GPLv2+
 Group: Applications/System
 Source: ftp://ftp.sf.net/pub/sourceforge/psmisc/psmisc-%{version}.tar.gz
 URL: http://psmisc.sourceforge.net
@@ -16,6 +16,8 @@
 Patch0: psmisc-22.3-fuser-ipv6.patch
 # 214214: killall <path> misbehavior (prelink, etc)
 Patch1: psmisc-22.3-killall-ino.patch
+# 245538 - fuser incorrectly reports processess using nfs filesystems
+Patch2: psmisc-22.3-fuser-nfs.patch
 
 %description
 The psmisc package contains utilities for managing processes on your
@@ -61,6 +63,10 @@
 %{_mandir}/man1/pstree.1*
 
 %changelog
+* Mon Aug 20 2007 Tomas Smetana <tsmetana at redhat.com> 22.3-3
+- fix #245538 - fuser incorrectly reports processess using nfs filesystems
+- update license tag
+
 * Thu Mar  1 2007 Karel Zak <kzak at redhat.com> 22.3-2
 - fix #214214 - killall <path> misbehavior (prelink, etc)
 




More information about the fedora-extras-commits mailing list