-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 346304 b: refs/heads/master c: e656d8a h: refs/heads/master v: v3
- Loading branch information
Eric W. Biederman
committed
Nov 19, 2012
1 parent
b5eb86d
commit 4ca022d
Showing
6 changed files
with
65 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: dd34ad35c32bb3d16789d8d4084aead7e68a7b09 | ||
refs/heads/master: e656d8a6f7fdf7612d2f5771f0ddfca9487f59d9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <linux/proc_fs.h> | ||
#include <linux/sched.h> | ||
#include <linux/namei.h> | ||
|
||
/* | ||
* /proc/self: | ||
*/ | ||
static int proc_self_readlink(struct dentry *dentry, char __user *buffer, | ||
int buflen) | ||
{ | ||
struct pid_namespace *ns = dentry->d_sb->s_fs_info; | ||
pid_t tgid = task_tgid_nr_ns(current, ns); | ||
char tmp[PROC_NUMBUF]; | ||
if (!tgid) | ||
return -ENOENT; | ||
sprintf(tmp, "%d", tgid); | ||
return vfs_readlink(dentry,buffer,buflen,tmp); | ||
} | ||
|
||
static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd) | ||
{ | ||
struct pid_namespace *ns = dentry->d_sb->s_fs_info; | ||
pid_t tgid = task_tgid_nr_ns(current, ns); | ||
char *name = ERR_PTR(-ENOENT); | ||
if (tgid) { | ||
/* 11 for max length of signed int in decimal + NULL term */ | ||
name = kmalloc(12, GFP_KERNEL); | ||
if (!name) | ||
name = ERR_PTR(-ENOMEM); | ||
else | ||
sprintf(name, "%d", tgid); | ||
} | ||
nd_set_link(nd, name); | ||
return NULL; | ||
} | ||
|
||
static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd, | ||
void *cookie) | ||
{ | ||
char *s = nd_get_link(nd); | ||
if (!IS_ERR(s)) | ||
kfree(s); | ||
} | ||
|
||
static const struct inode_operations proc_self_inode_operations = { | ||
.readlink = proc_self_readlink, | ||
.follow_link = proc_self_follow_link, | ||
.put_link = proc_self_put_link, | ||
}; | ||
|
||
void __init proc_self_init(void) | ||
{ | ||
struct proc_dir_entry *proc_self_symlink; | ||
mode_t mode; | ||
|
||
mode = S_IFLNK | S_IRWXUGO; | ||
proc_self_symlink = proc_create("self", mode, NULL, NULL ); | ||
proc_self_symlink->proc_iops = &proc_self_inode_operations; | ||
} |