From 855c963fb3cfed742c2a5f8e8cd31e63f38f6625 Mon Sep 17 00:00:00 2001 From: "roberto@fiorenzo" Date: Thu, 16 Sep 2010 18:39:33 +0200 Subject: [PATCH] working cgroup support --- utils.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ uwsgi.h | 1 + wsgi_headers.c | 10 +++---- 3 files changed, 78 insertions(+), 5 deletions(-) diff --git a/utils.c b/utils.c index 72eb2235..4d81be12 100644 --- a/utils.c +++ b/utils.c @@ -218,8 +218,59 @@ void internal_server_error(int fd, char *message) { void uwsgi_as_root() { +#ifdef __linux__ + char *cgroup_taskfile; + int i; + FILE *cgroup; + char *cgroup_opt; +#endif + if (!getuid()) { uwsgi_log("uWSGI running as root, you can use --uid/--gid/--chroot options\n"); + +#ifdef __linux__ + if (uwsgi.cgroup) { + cgroup_taskfile = uwsgi_concat2(uwsgi.cgroup, "/tasks"); + cgroup = fopen(cgroup_taskfile, "w"); + if (!cgroup) { + uwsgi_error("fopen"); + exit(1); + } + if (fprintf(cgroup, "%d\n", (int) getpid()) < 0) { + uwsgi_log( "could not set cgroup\n"); + exit(1); + } + fclose(cgroup); + free(cgroup_taskfile); + + for(i=0;i