From d586fe2fb3233807940cb6c3ac63f6f91a21d5fa Mon Sep 17 00:00:00 2001 From: "roberto@fedora64" Date: Sun, 2 Jan 2011 17:51:50 +0000 Subject: [PATCH] another test for linux namespace. They works perfectly --- uwsgi.c | 8 ++++++-- uwsgi.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/uwsgi.c b/uwsgi.c index 3ae536f9..379027b8 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -663,7 +663,6 @@ options_parsed: #ifndef CLONE_NEWIPC #define CLONE_NEWIPC 0x08000000 #endif - uwsgi.ns = "/ns/001"; if (uwsgi.ns) { void *linux_clone_stack = alloca(uwsgi.page_size); pid_t pid = clone(uwsgi_start, linux_clone_stack+uwsgi.page_size, SIGCHLD|CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS, (void *)argv); @@ -710,6 +709,9 @@ int uwsgi_start(void *v_argv) { uwsgi_log("my PID is %d\n", (int) getpid()); if (getpid() == 1) { + if (sethostname("uwsgifakehost", strlen("uwsgifakehost"))) { + uwsgi_error("sethostname()"); + } uwsgi_log("unmounting /proc\n"); if (umount("/proc/bus/usb")) { uwsgi_error("umount()"); @@ -731,7 +733,7 @@ int uwsgi_start(void *v_argv) { umount("/home/roberto/.gvfs"); umount("/sys"); umount("/"); - if (mount("/ns/001", "/ns/001_", "none", MS_BIND| MS_REC, NULL)) { + if (mount(uwsgi.ns, "/ns/001_", "none", MS_BIND, NULL)) { uwsgi_error("mount()"); } if (chdir("/ns/001_")) { @@ -740,6 +742,8 @@ int uwsgi_start(void *v_argv) { if (pivot_root(".", "/ns/001_/mnt2")) { uwsgi_error("pivot_root()"); } + + umount("/ns/001_/mnt2"); if (mount("proc","/proc", "proc", 0, NULL)) { uwsgi_error("mount()"); diff --git a/uwsgi.h b/uwsgi.h index 2ed604ea..f3bf1ade 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -272,6 +272,7 @@ struct uwsgi_opt { #define LONG_ARGS_CLUSTER_RELOAD 17063 #define LONG_ARGS_CLUSTER_LOG 17064 #define LONG_ARGS_CACHE 17065 +#define LONG_ARGS_NS 17066