From mboxrd@z Thu Jan 1 00:00:00 1970 From: normalperson at yhbt.net (Eric Wong) Date: Wed, 21 Mar 2012 01:52:54 +0000 Subject: [PATCH (WIP)] limit CPU usage of cgit processes Message-ID: <20120321015254.GA23083@dcvr.yhbt.net> Here's a work-in-progress patch which I've been running to prevent crawlers/bots from using up all the CPU on my system when doing expensive queries. If it's interesting, it should be wired up to appropriate config option... Signed-off-by: Eric Wong --- cgit.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cgit.c b/cgit.c index 1d50129..285467c 100644 --- a/cgit.c +++ b/cgit.c @@ -768,12 +768,25 @@ static int calc_ttl() return ctx.cfg.cache_repo_ttl; } +#include +#include +static void init_rlimit(void) +{ + struct rlimit rlim = { .rlim_cur = 10, .rlim_max = 10 }; + if (setrlimit(RLIMIT_CPU, &rlim) != 0) { + perror("setrlimit"); + exit(EXIT_FAILURE); + } +} + int main(int argc, const char **argv) { const char *path; char *qry; int err, ttl; + init_rlimit(); + prepare_context(&ctx); cgit_repolist.length = 0; cgit_repolist.count = 0; -- Eric Wong