From 8e75daf5abec2e008b7d2e21876bc60cf0f95ece Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Fri, 27 Nov 2009 15:25:03 +0100 Subject: [PATCH] FS: proc, switch limits reading to fops References: FATE#305733 Patch-mainline: no (later) Use fops instead of proc_info_read. We will need fops for limits writing and the code would look ugly if we used NOD("limits", S_IFREG|S_IRUSR|S_IWUSR, NULL, &proc_pid_limits_operations, { .proc_read = proc_pid_limits }), We will just use REG("limits", S_IRUSR|S_IWUSR, proc_pid_limits_operations), Signed-off-by: Jiri Slaby --- fs/proc/base.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -477,19 +477,30 @@ static const struct limit_names lnames[R }; /* Display limits for a process */ -static int proc_pid_limits(struct task_struct *task, char *buffer) +static ssize_t limits_read(struct file *file, char __user *buf, size_t rcount, + loff_t *ppos) { - unsigned int i; - int count = 0; - unsigned long flags; - char *bufptr = buffer; - struct rlimit rlim[RLIM_NLIMITS]; + struct task_struct *task; + unsigned long flags; + unsigned int i; + ssize_t count = 0; + char *bufptr; - if (!lock_task_sighand(task, &flags)) + task = get_proc_task(file->f_path.dentry->d_inode); + if (!task) + return -ESRCH; + if (!lock_task_sighand(task, &flags)) { + put_task_struct(task); return 0; + } memcpy(rlim, task->signal->rlim, sizeof(struct rlimit) * RLIM_NLIMITS); unlock_task_sighand(task, &flags); + put_task_struct(task); + + bufptr = (char *)__get_free_page(GFP_TEMPORARY); + if (!bufptr) + return -ENOMEM; /* * print the file header @@ -518,9 +529,17 @@ static int proc_pid_limits(struct task_s count += sprintf(&bufptr[count], "\n"); } + count = simple_read_from_buffer(buf, rcount, ppos, bufptr, count); + + free_page((unsigned long)bufptr); + return count; } +static const struct file_operations proc_pid_limits_operations = { + .read = limits_read, +}; + #ifdef CONFIG_HAVE_ARCH_TRACEHOOK static int proc_pid_syscall(struct task_struct *task, char *buffer) { @@ -2577,7 +2596,7 @@ static const struct pid_entry tgid_base_ INF("auxv", S_IRUSR, proc_pid_auxv), ONE("status", S_IRUGO, proc_pid_status), ONE("personality", S_IRUSR, proc_pid_personality), - INF("limits", S_IRUSR, proc_pid_limits), + REG("limits", S_IRUSR, proc_pid_limits_operations), #ifdef CONFIG_SCHED_DEBUG REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), #endif @@ -2912,7 +2931,7 @@ static const struct pid_entry tid_base_s INF("auxv", S_IRUSR, proc_pid_auxv), ONE("status", S_IRUGO, proc_pid_status), ONE("personality", S_IRUSR, proc_pid_personality), - INF("limits", S_IRUSR, proc_pid_limits), + REG("limits", S_IRUSR, proc_pid_limits_operations), #ifdef CONFIG_SCHED_DEBUG REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), #endif