mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Francois Romieu <romieu@fr.zoreil.com>
To: dierbro <dierbro@gmail.com>
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org
Subject: Re: [PATCH] add rlimit file to /proc/PID
Date: Fri, 15 Jul 2005 22:12:21 +0200	[thread overview]
Message-ID: <20050715201221.GA10017@electric-eye.fr.zoreil.com> (raw)
In-Reply-To: <42D80BBC.3020301@gmail.com>

dierbro <dierbro@gmail.com> :
[...]
> with a friend i have made this patch that add rlimit file to /proc/PID
> directory.
> Trought this file you can set and get rlimit of a running process.

I am not sure that new proc-functions will be welcome, anyway...

[...]
> --- linux-2.6.13-rc3/fs/proc/base.c	2005-07-15 20:57:25.000000000 +0200
> +++ linux-2.6.13-rc3/fs/proc/base.c.rlimit	2005-07-15 20:57:05.000000000 +0200
> +static int rlimit_read(struct file * file, char __user * buf,
> +		                        size_t count, loff_t *ppos)
> +{
> +	struct task_struct *task = proc_task(file->f_dentry->d_inode);
> +	int res = 0, i;
> +	unsigned long len;
> +	char buffer[2048];
                    ^^^^
Ahem...

> +	if(task){
> +	
> +		for(i=0; i<RLIM_NLIMITS;i++)
> +			switch(i){
> +				case RLIMIT_AS:
> +					len = sprintf(buffer+res, "RLIMIT_AS %d %d\n",
> +							(int) task->signal->rlim[i].rlim_cur,
> +							(int)task->signal->rlim[i].rlim_max);
> +					res+=len;
> +					break;
[generous code duplication deleted]

You want an initialized array for the strings "RLIMIT_AS", "RLIMIT_CORE", etc.

[...]
> +static ssize_t rlimit_write(struct file * file, const char * buffer,
> +			 size_t count, loff_t *ppos)
> +{
> +	struct task_struct *task = proc_task(file->f_dentry->d_inode);
> +	unsigned long cur,max;
> +	char *c;
> +	char *endptr;
> +	char *buf=NULL;

Unneeded initialization

[...]
> +	if( (buf=kmalloc(GFP_KERNEL,count))==NULL){

GFP_XXX must be the second arg.

> +		return  -ENOMEM;
> +	}
> +
> +	memcpy(buf,buffer,count); 
> +
> +	
> +	c=strchr(buf,' ');
> +	if(!c) goto out_err;

CodingStyle (the whole patch is terrible).

> +	
> +	*c='\0';
> +	int resource=-1;
> +	
> +	if(strcmp("RLIMIT_AS",buf)==0)
> +		resource=RLIMIT_AS;
> +	else if(strcmp("RLIMIT_CORE",buf)==0)
> +		resource=RLIMIT_CORE;
> +	else if(strcmp("RLIMIT_CPU",buf)==0)
> +		resource=RLIMIT_CPU;
[...]

More code duplication. Use a loop instead.

[...]
> +	out_err:
> +		kfree(buf);
> +		return EINVAL;

-EINVAL

--
Ueimor

      reply	other threads:[~2005-07-15 20:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-15 19:17 dierbro
2005-07-15 20:12 ` Francois Romieu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050715201221.GA10017@electric-eye.fr.zoreil.com \
    --to=romieu@fr.zoreil.com \
    --cc=akpm@osdl.org \
    --cc=dierbro@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®