lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Oct 10, 2003 at 12:03:02AM +0930, Mark Pulford wrote:
> I've recently been toying with Lua for use in a system where 3rd
> parties can submit scripts to be executed. I need to be able to catch
> scripts that accidentally run away. CPU usage can be monitored through
> HOOKCOUNT (which works for my purposes), however there doesn't appear
> to be any way to limit memory usage easily under the interpreter.

if you run each 3rd party script in a separate process, then you may
be able to use your operating system's resource limits api (if it has
one) as a coarse sandbox without having to modify lua.

e.g. under unix, if i want to limit a lua script to approx 8MB of
address space and approx 30 seconds of cpu time, i do

	% softlimit -a 8000000 -t 30 lua ...

softlimit is at http://cr.yp.to/daemontools/softlimit.html.  it uses
setrlimit() to set resource limits before running a program.  of course,
you could also call setrlimit() directly (either in C, or via exporting
it to lua).

this doesn't give you as fine-grained control as modifying the
interpreter, using HOOKCOUNT etc., but it may be "good enough" if it
fits your application model.

-taj