mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Contract process resource limits. (#243)
This commit is contained in:
@@ -98,6 +98,13 @@ namespace sc
|
||||
|
||||
// Set up the process environment and overlay the contract binary program with execv().
|
||||
|
||||
// Set process resource limits.
|
||||
if (set_process_rlimits() == -1)
|
||||
{
|
||||
std::cerr << errno << ": Failed to set contract process resource limits." << (ctx.args.readonly ? " (rdonly)" : "") << "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Close all fds unused by SC process.
|
||||
close_unused_fds(ctx, false);
|
||||
|
||||
@@ -153,6 +160,33 @@ namespace sc
|
||||
return ret;
|
||||
}
|
||||
|
||||
int set_process_rlimits()
|
||||
{
|
||||
rlimit lim;
|
||||
if (conf::cfg.contract.round_limits.proc_cpu_seconds > 0)
|
||||
{
|
||||
lim.rlim_cur = lim.rlim_max = conf::cfg.contract.round_limits.proc_cpu_seconds;
|
||||
if (setrlimit(RLIMIT_CPU, &lim) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (conf::cfg.contract.round_limits.proc_mem_bytes > 0)
|
||||
{
|
||||
lim.rlim_cur = lim.rlim_max = conf::cfg.contract.round_limits.proc_mem_bytes;
|
||||
if (setrlimit(RLIMIT_DATA, &lim) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (conf::cfg.contract.round_limits.proc_ofd_count > 0)
|
||||
{
|
||||
lim.rlim_cur = lim.rlim_max = conf::cfg.contract.round_limits.proc_ofd_count;
|
||||
if (setrlimit(RLIMIT_NOFILE, &lim) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the contract process has exited.
|
||||
* @param ctx Contract execution context.
|
||||
@@ -185,7 +219,7 @@ namespace sc
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR << "Contract process" << (ctx.args.readonly ? " (rdonly)" : "") << " ended with code " << WEXITSTATUS(scstatus);
|
||||
LOG_ERROR << "Contract process" << (ctx.args.readonly ? " (rdonly)" : "") << " ended prematurely with code " << WEXITSTATUS(scstatus);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user