Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static int child_fn(void *arg);
static int setup_rootfs_without_overlayfs(const ExecRequest *cfg, const char *ctr_dir);
static int setup_rootfs_with_overlayfs(const ExecRequest *cfg, const char *ctr_dir);
static int drop_all_caps(void);
static void set_limit(int resource, rlim_t lim);
static void set_limit(int resource, rlim_t soft, rlim_t hard);

// socket helpers
static int write_byte(int fd, char b);
Expand Down Expand Up @@ -909,11 +909,11 @@ static int child_fn(void *arg) {
}

// setrlimits
set_limit(RLIMIT_NOFILE, cfg->max_open_files);
set_limit(RLIMIT_STACK, cfg->stack_limit_bytes);
set_limit(RLIMIT_AS, cfg->memory_limit_bytes);
set_limit(RLIMIT_FSIZE, cfg->output_limit_bytes);
set_limit(RLIMIT_CPU, (cfg->cpu_time_limit_us + 999999) / 1000000);
set_limit(RLIMIT_NOFILE, cfg->max_open_files, cfg->max_open_files);
set_limit(RLIMIT_STACK, cfg->stack_limit_bytes, cfg->stack_limit_bytes);
set_limit(RLIMIT_AS, cfg->memory_limit_bytes, cfg->memory_limit_bytes);
set_limit(RLIMIT_FSIZE, cfg->output_limit_bytes, cfg->output_limit_bytes);
set_limit(RLIMIT_CPU, (cfg->cpu_time_limit_us + 999999) / 1000000, (cfg->cpu_time_limit_us + 999999) / 1000000);

// change root
char *new_root = join_paths(dir, "root");
Expand Down Expand Up @@ -1309,10 +1309,10 @@ static int drop_all_caps(void) {
return 0;
}

static void set_limit(int resource, rlim_t lim) {
static void set_limit(int resource, rlim_t soft, rlim_t hard) {
struct rlimit rl = {
.rlim_cur = lim,
.rlim_max = lim * 2,
.rlim_cur = soft,
.rlim_max = hard,
};
setrlimit(resource, &rl);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/test_files/time_limit_exceeded.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
while(1) {
volatile int t = 1;
t++;
}

return 0;
}