#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "util.h" struct params { char* shared_folder; int fd[2]; int out_fd; char **argv; }; struct limits { size_t memory; int core; int time; int processes; }; struct killparams{ int time; int pid; }; #include "ns_exec.c" #include "cgroup_prepare.c" uint64_t time_start; // get time in milliseconds uint64_t getmstime() { struct timeval tm; gettimeofday(&tm, NULL); return (uint64_t) tm.tv_sec * 1000 + (uint64_t) tm.tv_usec / 1000; } // time limit realisation static int killafter(void *arg) { // die when parent dies if (prctl(PR_SET_PDEATHSIG, SIGKILL)) die("cannot PR_SET_PDEATHSIG for child process: %m\n"); struct killparams* params = (struct killparams*) arg; struct timespec tw = {params -> time / 1000, ((params->time) % 1000+5) * 1000000}; struct timespec tr; nanosleep(&tw, &tr); kill(params->pid, SIGKILL); return 0; } #define STACK_SIZE 1000000 static char nmstack[STACK_SIZE]; static char killstack[STACK_SIZE]; static void parse_args(int argc, char **argv, struct params *params, struct limits *limits){ if (argc < 7) { puts("usage:\n starter