dierbro <[EMAIL PROTECTED]> : [...] > 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 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/