diff --git a/uwsgi.c b/uwsgi.c index a78da14b..3ae536f9 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -666,7 +666,7 @@ options_parsed: 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, (void *)argv); + pid_t pid = clone(uwsgi_start, linux_clone_stack+uwsgi.page_size, SIGCHLD|CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS, (void *)argv); if (pid == -1) { uwsgi_error("clone()"); exit(1); @@ -709,6 +709,43 @@ int uwsgi_start(void *v_argv) { uwsgi_log("my PID is %d\n", (int) getpid()); + if (getpid() == 1) { + uwsgi_log("unmounting /proc\n"); + if (umount("/proc/bus/usb")) { + uwsgi_error("umount()"); + } + if (umount("/proc/sys/fs/binfmt_misc")) { + uwsgi_error("umount()"); + } + if (umount("/proc")) { + uwsgi_error("umount()"); + } + umount("/dev/pts"); + umount("/dev/shm"); + umount("/dev"); + umount("/dev"); + umount("/sys/fs/fuse/connections"); + umount("/sys"); + umount("/boot"); + umount("/selinux"); + umount("/home/roberto/.gvfs"); + umount("/sys"); + umount("/"); + if (mount("/ns/001", "/ns/001_", "none", MS_BIND| MS_REC, NULL)) { + uwsgi_error("mount()"); + } + if (chdir("/ns/001_")) { + uwsgi_error("chdir()"); + } + if (pivot_root(".", "/ns/001_/mnt2")) { + uwsgi_error("pivot_root()"); + } + + if (mount("proc","/proc", "proc", 0, NULL)) { + uwsgi_error("mount()"); + } + } + uwsgi_as_root(); if (!uwsgi.no_initial_output) { diff --git a/uwsgi.h b/uwsgi.h index 9d696dc0..2ed604ea 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -84,6 +84,8 @@ #ifdef __linux #include #include +#include +extern int pivot_root(const char * new_root, const char * put_old); #else #include #endif diff --git a/uwsgiconfig.py b/uwsgiconfig.py index fdeebb48..7bada955 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -141,7 +141,11 @@ class uConf(object): self.config.read(filename) self.gcc_list = ['utils', 'protocol', 'socket', 'logging', 'master', 'plugins', 'lock', 'cache', 'event', 'signal', 'loop', 'uwsgi'] self.cflags = ['-O2', '-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split() - gcc_version = str(spcall2("%s -v" % GCC)).split('\n')[-1].split()[2] + try: + gcc_version = str(spcall2("%s -v" % GCC)).split('\n')[-1].split()[2] + except: + print("*** you need a c compiler to build uWSGI ***") + sys.exit(1) gcc_major = int(gcc_version.split('.')[0]) gcc_minor = int(gcc_version.split('.')[1]) if (sys.version_info[0] == 2) or (gcc_major < 4) or (gcc_major == 4 and gcc_minor < 3):