public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RE: [PATCH] getrusage sucks
@ 2005-11-10 23:47 Hua Zhong (hzhong)
  2005-11-11  0:23 ` Claudio Scordino
  0 siblings, 1 reply; 30+ messages in thread
From: Hua Zhong (hzhong) @ 2005-11-10 23:47 UTC (permalink / raw)
  To: Claudio Scordino, linux-kernel, kernelnewbies

The reason is what if tsk is no longer available when you call
getrusage? 

> -----Original Message-----
> From: linux-kernel-owner@vger.kernel.org 
> [mailto:linux-kernel-owner@vger.kernel.org] On Behalf Of 
> Claudio Scordino
> Sent: Thursday, November 10, 2005 2:34 PM
> To: linux-kernel@vger.kernel.org; kernelnewbies@nl.linux.org
> Subject: [PATCH] getrusage sucks
> 
> Does exist any _real_ reason why getrusage can't be invoked 
> by a task to know 
> statistics of another task ?
> 
> The changes would be very trivial, as shown by the following patch.
> 
>               Claudio
> 
> 
> diff --git a/kernel/sys.c b/kernel/sys.c
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -1746,9 +1746,13 @@ 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 = find_task_by_pid(who);
> +      if (tsk == NULL)
> +        return -EINVAL;
> +     return getrusage(tsk, RUSAGE_SELF, ru);
> +   } 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/

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: [PATCH] getrusage sucks
@ 2005-11-15 18:25 linux
  0 siblings, 0 replies; 30+ messages in thread
From: linux @ 2005-11-15 18:25 UTC (permalink / raw)
  To: cloud.of.andor; +Cc: linux-kernel

I might mention that ESRCH is the usual "that process does not exist"
error return, not EINVAL.  (See kill(2), ptrace(2), setpgrp(2), etc.)

^ permalink raw reply	[flat|nested] 30+ messages in thread
* RE: [PATCH] getrusage sucks
@ 2005-11-11 23:49 Hua Zhong (hzhong)
  0 siblings, 0 replies; 30+ messages in thread
From: Hua Zhong (hzhong) @ 2005-11-11 23:49 UTC (permalink / raw)
  To: Claudio Scordino, Alan Cox
  Cc: Chris Wright, Magnus Naeslund(f), linux-kernel, kernelnewbies,
	David Wagner

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)
> 

^ permalink raw reply	[flat|nested] 30+ messages in thread
* [PATCH] getrusage sucks
@ 2005-11-10 22:34 Claudio Scordino
  2005-11-11  5:06 ` David Wagner
  0 siblings, 1 reply; 30+ messages in thread
From: Claudio Scordino @ 2005-11-10 22:34 UTC (permalink / raw)
  To: linux-kernel, kernelnewbies

Does exist any _real_ reason why getrusage can't be invoked by a task to know 
statistics of another task ?

The changes would be very trivial, as shown by the following patch.

              Claudio


diff --git a/kernel/sys.c b/kernel/sys.c
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1746,9 +1746,13 @@ 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 = find_task_by_pid(who);
+      if (tsk == NULL)
+        return -EINVAL;
+     return getrusage(tsk, RUSAGE_SELF, ru);
+   } else
+     return getrusage(current, who, ru);
 }

 asmlinkage long sys_umask(int mask)

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2005-11-15 18:26 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-10 23:47 [PATCH] getrusage sucks Hua Zhong (hzhong)
2005-11-11  0:23 ` Claudio Scordino
2005-11-11  0:32   ` Magnus Naeslund(f)
2005-11-11  1:11     ` Claudio Scordino
2005-11-11 13:30       ` Alan Cox
2005-11-11 22:38         ` Claudio Scordino
2005-11-11 23:23           ` Alan Cox
2005-11-11 23:02             ` Chris Wright
2005-11-11 23:44               ` David Wagner
2005-11-12  0:53                 ` Chris Wright
2005-11-12  6:37                   ` David Wagner
2005-11-11 23:58               ` Alan Cox
2005-11-11 23:43                 ` Claudio Scordino
2005-11-11 23:49                   ` dean gaudet
2005-11-12  1:10                     ` Chris Wright
2005-11-12 15:10                       ` making makefile for 2.6 kernel anil dahiya
2005-11-12 15:16                       ` anil dahiya
2005-11-12 22:19                         ` Sam Ravnborg
2005-11-13  1:34                       ` [PATCH] getrusage sucks Claudio Scordino
2005-11-15 16:56                       ` Claudio Scordino
2005-11-15 17:00                       ` New getrusage Claudio Scordino
2005-11-11 23:08             ` [PATCH] getrusage sucks Claudio Scordino
2005-11-11 23:41           ` David Wagner
2005-11-15  1:08       ` Peter Chubb
  -- strict thread matches above, loose matches on Subject: below --
2005-11-15 18:25 linux
2005-11-11 23:49 Hua Zhong (hzhong)
2005-11-10 22:34 Claudio Scordino
2005-11-11  5:06 ` David Wagner
2005-11-11 19:09   ` Lee Revell
2005-11-11 19:13     ` David Wagner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox