From ce1b02202593af24cbabd3b2e1a1d5cb58ceb283 Mon Sep 17 00:00:00 2001 From: "roberto@precise64" Date: Tue, 29 May 2012 10:40:08 +0200 Subject: [PATCH] added --namespace-keep-mount --- lib/linux_ns.c | 12 ++++++++++++ utils.c | 13 +++++++++++++ uwsgi.c | 1 + uwsgi.h | 3 +++ 4 files changed, 29 insertions(+) diff --git a/lib/linux_ns.c b/lib/linux_ns.c index 361d72d4..d9ae1911 100644 --- a/lib/linux_ns.c +++ b/lib/linux_ns.c @@ -130,6 +130,17 @@ void linux_namespace_jail() { uwsgi_error("mount()"); } + struct uwsgi_string_list *usl = uwsgi.ns_keep_mount; + while(usl) { + // bind mounting keep-mount items + char *ks = uwsgi_concat2("/.uwsgi_ns_tmp_mountpoint", usl->value); + if (mount(ks, usl->value, "none", MS_BIND, NULL)) { + uwsgi_error("mount()"); + } + free(ks); + usl = usl->next; + } + while (unmounted) { unmounted = 0; @@ -139,6 +150,7 @@ void linux_namespace_jail() { delim0++; delim1 = strchr(delim0, ' '); *delim1 = 0; + if (uwsgi_string_list_has_item(uwsgi.ns_keep_mount, delim0, strlen(delim0))) continue; if (!strcmp(delim0, "/") || !strcmp(delim0, "/proc")) continue; if (!umount(delim0)) { diff --git a/utils.c b/utils.c index 22e51eb1..4c5674a7 100644 --- a/utils.c +++ b/utils.c @@ -385,6 +385,19 @@ void internal_server_error(struct wsgi_request *wsgi_req, char *message) { uwsgi.wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, message, strlen(message)); } +struct uwsgi_string_list *uwsgi_string_list_has_item(struct uwsgi_string_list *list, char *key, size_t keylen) { + struct uwsgi_string_list *usl = list; + while(usl) { + if (keylen == usl->len) { + if (!memcmp(key, usl->value, keylen)) { + return usl; + } + } + usl = usl->next; + } + return NULL; +} + #ifdef __linux__ void uwsgi_set_cgroup() { diff --git a/uwsgi.c b/uwsgi.c index 0fb458e6..89125207 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -410,6 +410,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"cgroup", required_argument, 0, "put the processes in the specified cgroup", uwsgi_opt_add_string_list, &uwsgi.cgroup, 0}, {"cgroup-opt", required_argument, 0, "set value in specified cgroup option", uwsgi_opt_add_string_list, &uwsgi.cgroup_opt, 0}, {"namespace", required_argument, 0, "run in a new namespace under the specified rootfs", uwsgi_opt_set_str, &uwsgi.ns, 0}, + {"namespace-keep-mount", required_argument, 0, "keep the specified mountpoint in your namespace", uwsgi_opt_add_string_list, &uwsgi.ns_keep_mount, 0}, {"ns", required_argument, 0, "run in a new namespace under the specified rootfs", uwsgi_opt_set_str, &uwsgi.ns, 0}, {"namespace-net", required_argument, 0, "add network namespace", uwsgi_opt_set_str, &uwsgi.ns_net, 0}, {"ns-net", required_argument, 0, "add network namespace", uwsgi_opt_set_str, &uwsgi.ns_net, 0}, diff --git a/uwsgi.h b/uwsgi.h index 641ee1bf..06a21b23 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1533,6 +1533,7 @@ struct uwsgi_server { struct uwsgi_string_list *cgroup_opt; char *ns; char *ns_net; + struct uwsgi_string_list *ns_keep_mount; #endif char *protocol; @@ -2891,6 +2892,8 @@ char *uwsgi_substitute(char *, char *, char *); void manage_cluster_message(char *, int); void uwsgi_opt_add_custom_option(char *, char *, void *); +struct uwsgi_string_list *uwsgi_string_list_has_item(struct uwsgi_string_list *, char *, size_t); + #ifdef UWSGI_SSL void uwsgi_ssl_init(void); SSL_CTX *uwsgi_ssl_new_server_context(char *, char *, char *, char *, char *);