Re: [PATCH] getrusage sucks

From: Claudio Scordino
Date: Thu Nov 10 2005 - 20:11:06 EST


> You need to wrap this with a read_lock(&tasklist_lock) to be safe, I think.

Right. Probably this was the meaning also of Hua's mail. Sorry, but I didn't
get it immediately.

So, what if I do as follows ? Do you see any problem with this solution ?

Many thanks,

Claudio



diff --git a/kernel/sys.c b/kernel/sys.c
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1746,9 +1746,22 @@ int getrusage(struct task_struct *p, int

asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
{
- if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
- return -EINVAL;
- return getrusage(current, who, ru);
+ int res;
+ if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN) {
+ struct task_struct* tsk;
+ read_lock(&tasklist_lock);
+ tsk = find_task_by_pid(who);
+ if (tsk == NULL) {
+ read_unlock(&tasklist_lock);
+ return -EINVAL;
+ }
+ res = getrusage(tsk, RUSAGE_SELF, ru);
+ read_unlock(&tasklist_lock);
+ return res;
+ } else {
+ res = getrusage(current, who, ru);
+ return res;
+ }
}

asmlinkage long sys_umask(int mask)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/