diff --git a/core/init.c b/core/init.c index 972092aa..f5c82acb 100644 --- a/core/init.c +++ b/core/init.c @@ -161,6 +161,10 @@ void uwsgi_init_default() { uwsgi.empty = ""; +#ifdef __linux__ + uwsgi.cgroup_dir_mode = "0700"; +#endif + uwsgi.wait_read_hook = uwsgi_simple_wait_read_hook; uwsgi.wait_write_hook = uwsgi_simple_wait_write_hook; diff --git a/core/utils.c b/core/utils.c index 9cdc5cb2..a48377f5 100644 --- a/core/utils.c +++ b/core/utils.c @@ -206,14 +206,20 @@ void uwsgi_set_cgroup() { usl = uwsgi.cgroup; while (usl) { - if (mkdir(usl->value, 0700)) { - uwsgi_log("using Linux cgroup %s\n", usl->value); + int mode = strtol(uwsgi.cgroup_dir_mode, 0, 8); + if (mkdir(usl->value, mode)) { if (errno != EEXIST) { uwsgi_error("mkdir()"); + exit(1); } + if (chmod(usl->value, mode)) { + uwsgi_error("chmod()"); + exit(1); + } + uwsgi_log("using Linux cgroup %s with mode %o\n", usl->value, mode); } else { - uwsgi_log("created Linux cgroup %s\n", usl->value); + uwsgi_log("created Linux cgroup %s with mode %o\n", usl->value, mode); } cgroup_taskfile = uwsgi_concat2(usl->value, "/tasks"); diff --git a/core/uwsgi.c b/core/uwsgi.c index 9ccc8680..907460bd 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -593,6 +593,7 @@ static struct uwsgi_option uwsgi_base_options[] = { #ifdef __linux__ {"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}, + {"cgroup-dir-mode", required_argument, 0, "set permission for cgroup directory (default is 700)", uwsgi_opt_set_str, &uwsgi.cgroup_dir_mode, 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}, diff --git a/uwsgi.h b/uwsgi.h index 2c485618..c3f34786 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2106,6 +2106,7 @@ struct uwsgi_server { #ifdef __linux__ struct uwsgi_string_list *cgroup; struct uwsgi_string_list *cgroup_opt; + char *cgroup_dir_mode; char *ns; char *ns_net; struct uwsgi_string_list *ns_keep_mount;