add tests, initial protobuf and rabbitmq support, ...
This commit is contained in:
parent
54adfcee2a
commit
7510c2a7b3
13 changed files with 421 additions and 39 deletions
|
@ -25,26 +25,6 @@ static int killafter(void *arg) {
|
|||
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 <max processes number> <core_id> <memory_amount> <time limit in ms> <shared folder> <command, arg1,arg2,...>");
|
||||
exit(0);
|
||||
}
|
||||
argc--; argv++;
|
||||
limits->processes = atoi(argv[0]);
|
||||
argc--; argv++;
|
||||
limits->core = atoi(argv[0]);
|
||||
argc--; argv++;
|
||||
limits->memory = atoi(argv[0]);
|
||||
argc--; argv++;
|
||||
limits->time = atoi(argv[0]);
|
||||
argc--; argv++;
|
||||
params->shared_folder = argv[0];
|
||||
argc--; argv++;
|
||||
|
||||
params->argv = argv;
|
||||
}
|
||||
|
||||
// setup user namespace
|
||||
static void prepare_userns(int pid) {
|
||||
char path[100];
|
||||
|
@ -68,26 +48,16 @@ static void prepare_userns(int pid) {
|
|||
write_file(path, line);
|
||||
}
|
||||
|
||||
static void get_real_path(char* path, char* call_str) {
|
||||
if (realpath (call_str, path) == 0) die("unable to resolve real path: %m");// get absolute path to executable
|
||||
for(int i = strlen(path); i > 0 && path[i] != '/';i--) path[i]=0;// cut filename to get directory name
|
||||
}
|
||||
|
||||
int main(int argc,char** argv) {
|
||||
int starter(char* working_path, struct limits limits, struct params params) {
|
||||
if(setuid(0)) die("must be run as root");
|
||||
if(setgid(0)) die("must be run as root");
|
||||
// get binary path
|
||||
char real_path[PATH_MAX];
|
||||
get_real_path(real_path, argv[0]);
|
||||
char* real_path=working_path;
|
||||
//get_real_path(real_path, argv[0]);
|
||||
if(chdir(real_path)) die("unable to chdir to binary path: %m");
|
||||
// set random seed
|
||||
srand(time(NULL));
|
||||
// setup parameters
|
||||
struct params params;
|
||||
memset(¶ms, 0, sizeof(struct params));
|
||||
struct limits limits;
|
||||
memset(&limits, 0, sizeof(struct limits));
|
||||
parse_args(argc, argv, ¶ms, &limits);
|
||||
prepare_cgroup(&limits);
|
||||
if (pipe(params.fd) < 0) die("can't open pipe: %m");// a pipe to report readiness
|
||||
int clone_flags = SIGCHLD | CLONE_NEWUTS | CLONE_NEWUSER | CLONE_NEWNS | CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWCGROUP;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue