lkml.org 
[lkml]   [2005]   [Mar]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH][4/5] Add inode_operations for proc sysctl
Date
From
Add getattr and permission inode_operations for base /proc/<pid> entries
that make sure the value of inode->i_mode is up-to-date with its
respective sysctl setting. This is achieved by calling the new function
proc_update_mode. It currently spares the init process.

diff -pur l1/fs/proc/base.c l2/fs/proc/base.c
--- l1/fs/proc/base.c 2005-03-19 20:08:30.000000000 +0100
+++ l2/fs/proc/base.c 2005-03-19 20:08:39.000000000 +0100
@@ -243,6 +243,40 @@ static struct pid_entry tid_attr_stuff[]
mode_t proc_base_permissions[] = {
S_IRUGO, /* PROC_CMDLINE */
};
+
+static void proc_update_mode(struct inode *inode)
+{
+ struct task_struct *task = proc_task(inode);
+ int ctl_name = proc_ctl_name(inode);
+
+ if (ctl_name == 0)
+ return;
+ if (task->pid == 1) /* Don't touch init. TODO: kernel threads? */
+ return;
+ inode->i_mode = (inode->i_mode & ~S_IALLUGO) |
+ proc_base_permissions[ctl_name-1];
+}
+
+static int proc_base_permission(struct inode *inode, int mask,
+ struct nameidata *nd)
+{
+ proc_update_mode(inode);
+ return generic_permission(inode, mask, NULL);
+}
+
+static int proc_base_getattr(struct vfsmount *mnt, struct dentry *dentry,
+ struct kstat *stat)
+{
+ struct inode *inode = dentry->d_inode;
+ proc_update_mode(inode);
+ generic_fillattr(inode, stat);
+ return 0;
+}
+
+static struct inode_operations proc_base_inode_operations = {
+ .getattr = proc_base_getattr,
+ .permission = proc_base_permission,
+};
#endif /* CONFIG_SYSCTL */

static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
@@ -1474,6 +1508,8 @@ static struct dentry *proc_pident_lookup
ei = PROC_I(inode);
#ifdef CONFIG_SYSCTL
ei->ctl_name = p->ctl_name;
+ proc_update_mode(inode);
+ inode->i_op = &proc_base_inode_operations;
#endif
inode->i_mode = p->mode;
/*
-
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/

\
 
 \ /
  Last update: 2005-03-22 14:11    [from the cache]
©2003-2011 Jasper Spaans