diff options
-rw-r--r-- | fs/proc/base.c | 43 | ||||
-rw-r--r-- | include/linux/proc_fs.h | 3 |
2 files changed, 46 insertions, 0 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index c59852b38787..f4b1e14bd95b 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -121,6 +121,10 @@ struct pid_entry { | |||
121 | NOD(NAME, (S_IFREG|(MODE)), \ | 121 | NOD(NAME, (S_IFREG|(MODE)), \ |
122 | NULL, &proc_info_file_operations, \ | 122 | NULL, &proc_info_file_operations, \ |
123 | { .proc_read = &proc_##OTYPE } ) | 123 | { .proc_read = &proc_##OTYPE } ) |
124 | #define ONE(NAME, MODE, OTYPE) \ | ||
125 | NOD(NAME, (S_IFREG|(MODE)), \ | ||
126 | NULL, &proc_single_file_operations, \ | ||
127 | { .proc_show = &proc_##OTYPE } ) | ||
124 | 128 | ||
125 | int maps_protect; | 129 | int maps_protect; |
126 | EXPORT_SYMBOL(maps_protect); | 130 | EXPORT_SYMBOL(maps_protect); |
@@ -658,6 +662,45 @@ static const struct file_operations proc_info_file_operations = { | |||
658 | .read = proc_info_read, | 662 | .read = proc_info_read, |
659 | }; | 663 | }; |
660 | 664 | ||
665 | static int proc_single_show(struct seq_file *m, void *v) | ||
666 | { | ||
667 | struct inode *inode = m->private; | ||
668 | struct pid_namespace *ns; | ||
669 | struct pid *pid; | ||
670 | struct task_struct *task; | ||
671 | int ret; | ||
672 | |||
673 | ns = inode->i_sb->s_fs_info; | ||
674 | pid = proc_pid(inode); | ||
675 | task = get_pid_task(pid, PIDTYPE_PID); | ||
676 | if (!task) | ||
677 | return -ESRCH; | ||
678 | |||
679 | ret = PROC_I(inode)->op.proc_show(m, ns, pid, task); | ||
680 | |||
681 | put_task_struct(task); | ||
682 | return ret; | ||
683 | } | ||
684 | |||
685 | static int proc_single_open(struct inode *inode, struct file *filp) | ||
686 | { | ||
687 | int ret; | ||
688 | ret = single_open(filp, proc_single_show, NULL); | ||
689 | if (!ret) { | ||
690 | struct seq_file *m = filp->private_data; | ||
691 | |||
692 | m->private = inode; | ||
693 | } | ||
694 | return ret; | ||
695 | } | ||
696 | |||
697 | static const struct file_operations proc_single_file_operations = { | ||
698 | .open = proc_single_open, | ||
699 | .read = seq_read, | ||
700 | .llseek = seq_lseek, | ||
701 | .release = single_release, | ||
702 | }; | ||
703 | |||
661 | static int mem_open(struct inode* inode, struct file* file) | 704 | static int mem_open(struct inode* inode, struct file* file) |
662 | { | 705 | { |
663 | file->private_data = (void*)((long)current->self_exec_id); | 706 | file->private_data = (void*)((long)current->self_exec_id); |
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index e43551516831..b04ebf09fb91 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h | |||
@@ -262,6 +262,9 @@ extern void kclist_add(struct kcore_list *, void *, size_t); | |||
262 | union proc_op { | 262 | union proc_op { |
263 | int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **); | 263 | int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **); |
264 | int (*proc_read)(struct task_struct *task, char *page); | 264 | int (*proc_read)(struct task_struct *task, char *page); |
265 | int (*proc_show)(struct seq_file *m, | ||
266 | struct pid_namespace *ns, struct pid *pid, | ||
267 | struct task_struct *task); | ||
265 | }; | 268 | }; |
266 | 269 | ||
267 | struct proc_inode { | 270 | struct proc_inode { |