lkml.org 
[lkml]   [2005]   [Nov]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRE: [PATCH] getrusage sucks
Date
From
I think it's better to use "goto" for error exit. Too many read_unlock
here..

> -----Original Message-----
> From: Claudio Scordino [mailto:cloud.of.andor@gmail.com]
> Sent: Friday, November 11, 2005 3:44 PM
> To: Alan Cox
> Cc: Chris Wright; Magnus Naeslund(f); Hua Zhong (hzhong);
> linux-kernel@vger.kernel.org; kernelnewbies@nl.linux.org; David Wagner
> Subject: Re: [PATCH] getrusage sucks
>
> >
> > In which case the only comment I have is the one about
> accuracy - and
> > that is true for procfs too so will only come up if someone gets the
> > urge to use perfctr timers for precision resource management
>
> According to your comments, this the final patch.
>
> Should it be committed ?
>
> Claudio
>
>
>
> diff --git a/kernel/sys.c b/kernel/sys.c
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -1746,9 +1746,26 @@ 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);
> + if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN) {
> + struct task_struct* tsk;
> + struct rusage r;
> + read_lock(&tasklist_lock);
> + tsk = find_task_by_pid(who);
> + if (tsk == NULL) {
> + read_unlock(&tasklist_lock);
> + return -EINVAL;
> + }
> + if ((current->euid != tsk->euid) &&
> + (current->euid != tsk->uid) &&
> + (!capable(CAP_SYS_ADMIN))){
> + read_unlock(&tasklist_lock);
> + return -EPERM;
> + }
> + k_getrusage(tsk, RUSAGE_SELF, &r);
> + read_unlock(&tasklist_lock);
> + return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
> + } else
> + return getrusage(current, who, ru);
> }
>
> 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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-11-12 00:52    [W:0.024 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site