From 4ec9312b102c51136fd08e5d5a84e15e10e64d07 Mon Sep 17 00:00:00 2001 From: Unbit Date: Wed, 2 Oct 2013 16:52:14 +0200 Subject: [PATCH] pivot_root improvements --- core/utils.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/utils.c b/core/utils.c index f461e8c2..720e9f66 100644 --- a/core/utils.c +++ b/core/utils.c @@ -292,6 +292,12 @@ void uwsgi_set_cgroup() { #endif // drop privileges (as root) +/* + + here we manage jails/namespaces too + it is a pretty huge function... refactory is needed + +*/ void uwsgi_as_root() { @@ -595,6 +601,12 @@ void uwsgi_as_root() { exit(1); } *space = 0; +#if defined(MS_REC) && defined(MS_PRIVATE) + if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL)) { + uwsgi_error("mount()"); + exit(1); + } +#endif if (chdir(arg)) { uwsgi_error("pivot_root()/chdir()"); exit(1); @@ -610,6 +622,10 @@ void uwsgi_as_root() { uwsgi_log("*** Warning, on linux system you have to bind-mount the /proc fs in your chroot to get memory debug/report.\n"); } free(arg); + if (chdir("/")) { + uwsgi_error("chdir()"); + exit(1); + } } #endif