This implements the actual inheritance of the container id from the parent
as well as the actual modification to sys_getpid().
You can demonstrate that it works by doing the following with your shell:
echo 99 > /proc/$$/task/$$/child_container_id
And running the following (horribly buggy) program. The first and second
getpid() will return different values.
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
char bufa[1000];
char bufb[1000];
int main(void)
{
int i,j;
int pida, pidb;
int fd;
int res;
pida = getpid();
sprintf(bufb, "cat /proc/%d/task/%d/container_id", pida, pida);
system(bufb);
sprintf(bufa, "/proc/%d/task/%d/vpid", pida, pida);
fd = open(bufa, O_RDWR);
write(fd, "11179", 6);
close(fd);
pidb = getpid();
printf("pida: %d\n", pida);
printf("pidb: %d\n", pidb);
sprintf(bufb, "cat /proc/%d/task/%d/vpid", pida, pida);
system(bufb);
}
---
linux-2.6.14-rc5-dave/include/linux/sched.h | 6 ++++++
linux-2.6.14-rc5-dave/kernel/fork.c | 3 +++
linux-2.6.14-rc5-dave/kernel/timer.c | 2 +-
3 files changed, 10 insertions(+), 1 deletion(-)
diff -puN include/linux/sched.h~D0-use-vpid include/linux/sched.h
--- linux-2.6.14-rc5/include/linux/sched.h~D0-use-vpid 2005-10-24 17:55:41.000000000 +0200
+++ linux-2.6.14-rc5-dave/include/linux/sched.h 2005-10-24 17:55:41.000000000 +0200
@@ -841,6 +841,12 @@ static inline pid_t get_kernel_pid(const
{
return p->__pid;
}
+static inline pid_t get_user_pid(const struct task_struct *p)
+{
+ if (!p->container_id)
+ return p->__pid;
+ return p->vpid;
+}
static inline pid_t get_kernel_tgid(const struct task_struct *p)
{
diff -puN kernel/fork.c~D0-use-vpid kernel/fork.c
--- linux-2.6.14-rc5/kernel/fork.c~D0-use-vpid 2005-10-24 17:55:41.000000000 +0200
+++ linux-2.6.14-rc5-dave/kernel/fork.c 2005-10-24 17:55:41.000000000 +0200
@@ -937,6 +937,7 @@ static task_t *copy_process(unsigned lon
p->did_exec = 0;
copy_flags(clone_flags, p);
p->__pid = pid;
+ p->vpid = p->__pid;
retval = -EFAULT;
if (clone_flags & CLONE_PARENT_SETTID)
if (put_user(get_kernel_pid(p), parent_tidptr))
@@ -987,6 +988,8 @@ static task_t *copy_process(unsigned lon
p->__tgid = get_kernel_pid(p);
if (clone_flags & CLONE_THREAD)
p->__tgid = get_kernel_tgid(current);
+ p->container_id = current->child_container_id;
+ p->child_container_id = current->child_container_id;
if ((retval = security_task_alloc(p)))
goto bad_fork_cleanup_policy;
diff -puN kernel/timer.c~D0-use-vpid kernel/timer.c
--- linux-2.6.14-rc5/kernel/timer.c~D0-use-vpid 2005-10-24 17:55:41.000000000 +0200
+++ linux-2.6.14-rc5-dave/kernel/timer.c 2005-10-24 17:55:41.000000000 +0200
@@ -996,7 +996,7 @@ asmlinkage unsigned long sys_alarm(unsig
*/
asmlinkage long sys_getpid(void)
{
- return get_kernel_pid(current);
+ return get_user_pid(current);
}
/*
_
_______________________________________________
Vserver mailing list
Vserver@list.linux-vserver.org
http://list.linux-vserver.org/mailman/listinfo/vserver
Received on Mon Oct 24 17:28:36 2005