From: Martin Mares Date: Fri, 31 Jul 2009 18:50:35 +0000 (+0200) Subject: Box: Added an option for controlling the stack size limit. X-Git-Tag: python-dummy-working~102 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=7e45f095c27e00114e57d97ea1b70a5900dd65af;p=moe.git Box: Added an option for controlling the stack size limit. Beware, the default has been changed to `unlimited' instead of inheriting the limit from the parent process. --- diff --git a/box/box.c b/box/box.c index 3f6ada1..b4f47ef 100644 --- a/box/box.c +++ b/box/box.c @@ -38,6 +38,7 @@ static int pass_environ; static int file_access; static int verbose; static int memory_limit; +static int stack_limit; static char *redir_stdin, *redir_stdout, *redir_stderr; static char *set_cwd; @@ -1031,15 +1032,22 @@ box_inside(int argc, char **argv) else dup2(1, 2); setpgrp(); + if (memory_limit) { rl.rlim_cur = rl.rlim_max = memory_limit * 1024; if (setrlimit(RLIMIT_AS, &rl) < 0) - die("setrlimit: %m"); + die("setrlimit(RLIMIT_AS): %m"); } + + rl.rlim_cur = rl.rlim_max = (stack_limit ? (rlim_t)stack_limit * 1024 : RLIM_INFINITY); + if (setrlimit(RLIMIT_STACK, &rl) < 0) + die("setrlimit(RLIMIT_STACK): %m"); + rl.rlim_cur = rl.rlim_max = 64; if (setrlimit(RLIMIT_NOFILE, &rl) < 0) - die("setrlimit: %m"); + die("setrlimit(RLIMIT_NOFILE): %m"); + char **env = setup_environment(); if (filter_syscalls) { @@ -1067,6 +1075,7 @@ Options:\n\ -E =\tSet the environment variable to ; unset it if is empty\n\ -f\t\tFilter system calls (-ff=very restricted)\n\ -i \tRedirect stdin from \n\ +-k \tLimit stack size to KB (default: 0=unlimited)\n\ -m \tLimit address space to KB\n\ -M \tOutput process information to (name:value)\n\ -o \tRedirect stdout to \n\ @@ -1091,7 +1100,7 @@ main(int argc, char **argv) int c; uid_t uid; - while ((c = getopt(argc, argv, "a:c:eE:fi:m:M:o:p:r:s:t:Tvw:x:")) >= 0) + while ((c = getopt(argc, argv, "a:c:eE:fi:k:m:M:o:p:r:s:t:Tvw:x:")) >= 0) switch (c) { case 'a': @@ -1110,6 +1119,9 @@ main(int argc, char **argv) case 'f': filter_syscalls++; break; + case 'k': + stack_limit = atol(optarg); + break; case 'i': redir_stdin = optarg; break;