X-Git-Url: http://git.annexia.org/?p=xavierbot.git;a=blobdiff_plain;f=ocamlbotwrapper.c;h=c852850332aa26dba489a9f97bf2a7fd0f5b5601;hp=d5f71278cac456dabfce8853c36d3ecac6f8862c;hb=1ddb7873d30b80c638d22ec43a771bdb3fc5cb4c;hpb=1e6d6c08bec29a317316f107b7d9bde285c1f798 diff --git a/ocamlbotwrapper.c b/ocamlbotwrapper.c index d5f7127..c852850 100644 --- a/ocamlbotwrapper.c +++ b/ocamlbotwrapper.c @@ -1,5 +1,5 @@ /* -*- C -*- - * $Id: ocamlbotwrapper.c,v 1.2 2007/06/28 20:49:10 rjones Exp $ + * $Id: ocamlbotwrapper.c,v 1.4 2007/06/29 07:55:47 rjones Exp $ * SUID wrapper around ocaml program. */ @@ -7,6 +7,8 @@ #include #include #include +#include +#include const char *new_environ[] = { "PATH=/usr/bin", @@ -16,6 +18,8 @@ const char *new_environ[] = { int main () { + struct rlimit lim; + /* Don't worry about races here because we're just checking that * the installation looks reasonable. * @@ -37,6 +41,44 @@ main () exit (1); } + /* Set some limits. */ +#ifdef RLIMIT_AS + lim.rlim_cur = lim.rlim_max = 32 * 1024 * 1024; /* bytes!?! */ + setrlimit (RLIMIT_AS, &lim); +#endif +#ifdef RLIMIT_CORE + lim.rlim_cur = lim.rlim_max = 0; + setrlimit (RLIMIT_CORE, &lim); +#endif +#ifdef RLIMIT_CPU + lim.rlim_cur = lim.rlim_max = 60; /* seconds */ + setrlimit (RLIMIT_CPU, &lim); +#endif +#ifdef RLIMIT_MEMLOCK + lim.rlim_cur = lim.rlim_max = 0; + setrlimit (RLIMIT_MEMLOCK, &lim); +#endif +#ifdef RLIMIT_MSGQUEUE + lim.rlim_cur = lim.rlim_max = 0; + setrlimit (RLIMIT_MSGQUEUE, &lim); +#endif +#ifdef RLIMIT_NOFILE + lim.rlim_cur = lim.rlim_max = 10; + setrlimit (RLIMIT_NOFILE, &lim); +#endif +#ifdef RLIMIT_NPROC + lim.rlim_cur = lim.rlim_max = 2; + setrlimit (RLIMIT_NPROC, &lim); +#endif +#ifdef RLIMIT_SIGPENDING + lim.rlim_cur = lim.rlim_max = 5; + setrlimit (RLIMIT_SIGPENDING, &lim); +#endif +#ifdef RLIMIT_STACK + lim.rlim_cur = lim.rlim_max = 8 * 1024 * 1024; /* bytes */ + setrlimit (RLIMIT_STACK, &lim); +#endif + /* Run the ocaml program with the correct args. */ execle ("/usr/bin/ocaml", "@OCAML@", "-init", "init",