From: Eric W. Biederman Use getattr to get an accurate link count when needed. This is cheaper and more accurate than trying to derive it by walking the thread list of a process. Especially as it happens when needed stat instead of at readdir time. Signed-off-by: Eric W. Biederman Signed-off-by: Andrew Morton --- fs/proc/base.c | 21 +++++++++++++++++++-- 1 files changed, 19 insertions(+), 2 deletions(-) diff -puN fs/proc/base.c~proc-fix-the-link-count-for-proc-pid-task fs/proc/base.c --- devel/fs/proc/base.c~proc-fix-the-link-count-for-proc-pid-task 2006-02-27 20:58:55.000000000 -0800 +++ devel-akpm/fs/proc/base.c 2006-02-27 20:58:55.000000000 -0800 @@ -1518,6 +1518,7 @@ out: static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir); static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd); +static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat); static struct file_operations proc_fd_operations = { .read = generic_read_dir, @@ -1538,6 +1539,7 @@ static struct inode_operations proc_fd_i static struct inode_operations proc_task_inode_operations = { .lookup = proc_task_lookup, + .getattr = proc_task_getattr, }; #ifdef CONFIG_SECURITY @@ -1644,7 +1646,7 @@ static struct dentry *proc_pident_lookup */ switch(p->type) { case PROC_TGID_TASK: - inode->i_nlink = 2 + get_tid_list(2, NULL, dir); + inode->i_nlink = 2; inode->i_op = &proc_task_inode_operations; inode->i_fop = &proc_task_operations; break; @@ -2245,7 +2247,6 @@ static int proc_task_readdir(struct file } 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; @@ -2265,3 +2266,19 @@ out: filp->f_pos = pos; return retval; } + +static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) +{ + struct inode *inode = dentry->d_inode; + struct task_struct *p = proc_task(inode); + generic_fillattr(inode, stat); + + if (pid_alive(p)) { + task_lock(p); + if (p->signal) + stat->nlink += atomic_read(&p->signal->count); + task_unlock(p); + } + + return 0; +} _