Skip to contentSkip to conversation

procfs: Fix hardlink counts for /proc/<PID>/task

PATCH New Daniel Drake 1 participant 1 message Apr 2, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 procfs: Fix hardlink counts for /proc/<PID>/task

The current logic assumes that a /proc/<PID>/task directory should have a hardlink count of 3, probably counting ".", "..", and a directory for a single child task.

It's fairly obvious that this doesn't work out correctly when a PID has more than one child task, which is quite often the case.

This should fix it up.

base.c renamed from base.c.orig +6 -2
@@ -1337,6 +1337,8 @@
 static struct inode_operations proc_tgid_attr_inode_operations;
 #endif
 
+static int get_tid_list(int index, unsigned int *tids, struct inode *dir);
+
 /* SMP-safe */
 static struct dentry *proc_pident_lookup(struct inode *dir, 
 					 struct dentry *dentry,
@@ -1376,7 +1378,7 @@
 	 */
 	switch(p->type) {
 		case PROC_TGID_TASK:
-			inode->i_nlink = 3;
+			inode->i_nlink = 2 + get_tid_list(2, NULL, dir);
 			inode->i_op = &proc_task_inode_operations;
 			inode->i_fop = &proc_task_operations;
 			break;
@@ -1845,7 +1847,8 @@
 
 		if (--index >= 0)
 			continue;
-		tids[nr_tids] = tid;
+		if (tids != NULL)
+			tids[nr_tids] = tid;
 		nr_tids++;
 		if (nr_tids >= PROC_MAXPIDS)
 			break;
@@ -1945,6 +1948,7 @@
 	}
 
 	nr_tids = get_tid_list(pos, tid_array, inode);
+	inode->i_nlink = pos + nr_tids;
 
 	for (i = 0; i < nr_tids; i++) {
 		unsigned long j = PROC_NUMBUF;