allow usage of Linux namespace feautures

This commit is contained in:
roberto@sirius
2011-01-02 12:15:52 +01:00
parent 67666a1788
commit 9ef571b4fa
2 changed files with 53 additions and 16 deletions
+50 -16
View File
@@ -335,15 +335,9 @@ static void vacuum(void)
int main(int argc, char *argv[], char *envp[])
{
int i,
j;
int i;
int rlen;
int uwsgi_will_starts = 0;
pid_t pid;
FILE *pidfile;
char *env_reloads;
@@ -353,19 +347,11 @@ int main(int argc, char *argv[], char *envp[])
char *plugins_requested;
#ifdef UWSGI_HTTP
pid_t http_pid;
#endif
#ifdef UNBIT
//struct uidsec_struct us;
#endif
struct sockaddr_un usa;
struct sockaddr *gsa;
struct sockaddr_in *isa;
socklen_t socket_type_len;
#ifdef UWSGI_DEBUG
struct utsname uuts;
int so_bufsize;
@@ -663,6 +649,54 @@ options_parsed:
}
fclose(pidfile);
}
#ifdef __linux__
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);
if (pid == -1) {
uwsgi_error("clone()");
exit(1);
}
uwsgi_log("waiting for uwsgi end...\n");
pid = waitpid(pid, NULL, 0);
uwsgi_log("pid %d ended\n", (int) pid);
}
else {
#endif
uwsgi_start((void *)argv);
#ifdef __linux__
}
#endif
// never here
return 0;
}
int uwsgi_start(void *v_argv) {
char **argv = v_argv;
#ifdef UWSGI_HTTP
pid_t http_pid;
#endif
pid_t pid;
int i, j;
struct sockaddr_un usa;
struct sockaddr *gsa;
struct sockaddr_in *isa;
socklen_t socket_type_len;
FILE *pidfile;
int uwsgi_will_starts = 0;
uwsgi_log("my PID is %d\n", (int) getpid());
uwsgi_as_root();
if (!uwsgi.no_initial_output) {
@@ -1483,7 +1517,7 @@ end:
// never here
return 0;
}
}
#ifdef UWSGI_PROXY
pid_t proxy_start(int has_master) {
+3
View File
@@ -819,6 +819,7 @@ struct uwsgi_server {
char *cgroup;
char *cgroup_opt[64];
int cgroup_opt_cnt;
char *ns;
#endif
int sockets_cnt;
@@ -1330,3 +1331,5 @@ void uwsgi_register_timer(uint8_t, int, uint8_t, void *, uint8_t);
int uwsgi_signal_handler(uint8_t);
void uwsgi_route_signal(uint8_t);
int uwsgi_start(void *);