diff --git a/core/daemons.c b/core/daemons.c index d1b11ba5..687c0750 100644 --- a/core/daemons.c +++ b/core/daemons.c @@ -291,6 +291,14 @@ void uwsgi_spawn_daemon(struct uwsgi_daemon *ud) { uwsgi_close_all_sockets(); uwsgi_close_all_fds(); +#if defined(__linux__) && !defined(OBSOLETE_LINUX_KERNEL) + if (ud->ns_pid) { + if (unshare(CLONE_NEWPID)) { + uwsgi_error("uwsgi_spawn_daemon()/unshare()"); + } + } +#endif + if (ud->gid) { if (setgid(ud->gid)) { uwsgi_error("uwsgi_spawn_daemon()/setgid()"); @@ -454,6 +462,7 @@ void uwsgi_opt_add_daemon2(char *opt, char *value, void *none) { char *d_stdin = NULL; char *d_uid = NULL; char *d_gid = NULL; + char *d_ns_pid = NULL; char *arg = uwsgi_str(value); @@ -474,6 +483,7 @@ void uwsgi_opt_add_daemon2(char *opt, char *value, void *none) { "stdin", &d_stdin, "uid", &d_uid, "gid", &d_gid, + "ns_pid", &d_ns_pid, NULL)) { uwsgi_log("invalid --%s keyval syntax\n", opt); exit(1); @@ -519,6 +529,7 @@ void uwsgi_opt_add_daemon2(char *opt, char *value, void *none) { #ifdef UWSGI_SSL uwsgi_ud->legion = d_legion; #endif + uwsgi_ud->ns_pid = d_ns_pid ? 1 : 0; if (d_touch) { size_t i,rlen = 0; diff --git a/uwsgi.h b/uwsgi.h index e3474bda..544292fe 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -602,6 +602,8 @@ struct uwsgi_daemon { char *legion; #endif + int ns_pid; + }; struct uwsgi_logger {