Skip to content

Commit

Permalink
New compiler proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
springhack committed Nov 11, 2016
1 parent 6ef699d commit 59e6b6e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
1 change: 1 addition & 0 deletions Install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ install()
cp -rvf ajcserver/ajcd /etc/init.d/
cp -rvf libs /home/AJC/
cp -rvf vj_root/* /var/www/html/alxwvj/
gcc src/compiler.c -o /home/AJC/ajcserver/compiler
chmod -R 777 /home/AJC
}

Expand Down
13 changes: 6 additions & 7 deletions ajcserver/main_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,12 @@ def compileCode(solution_id, language):
dir_work = os.path.join(config.work_dir, str(solution_id))
if language not in config.build_cmd.keys():
return False
p = subprocess.Popen(config.build_cmd[language], shell=True, cwd=dir_work, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
timer = threading.Timer(config.compile_timeout, kill_proc, [p])
try:
timer.start()
out, err = p.communicate()
finally:
timer.cancel()
if language == 'java':
flag = 1
else:
flag = 0
p = subprocess.Popen("/home/AJC/ajcserver/compiler %d %s" % (flag, config.build_cmd[language]), shell=True, cwd=dir_work, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
out, err = p.communicate()
if p.returncode == 0:
return True
update_compile_info(solution_id, err + out)
Expand Down
49 changes: 49 additions & 0 deletions src/compiler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/signal.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/user.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/ptrace.h>
#include <time.h>
#include <stdarg.h>
#include <fcntl.h>

#define STD_MB 1048576

int main(int argc, char *argv[])
{
int java = atoi(argv[1]);
struct rlimit LIM;
char *args[20];
int i;
for (i=2;i<argc;++i)
args[i - 2] = argv[i];
args[argc - 2] = (char *)NULL;
LIM.rlim_max = 60;
LIM.rlim_cur = 60;
setrlimit(RLIMIT_CPU, &LIM);
alarm(60);
LIM.rlim_max = 10 * STD_MB;
LIM.rlim_cur = 10 * STD_MB;
setrlimit(RLIMIT_FSIZE, &LIM);
if (java)
{
LIM.rlim_max = STD_MB<<11;
LIM.rlim_cur = STD_MB<<11;
} else {
LIM.rlim_max = STD_MB*256 ;
LIM.rlim_cur = STD_MB*256 ;
}
setrlimit(RLIMIT_AS, &LIM);
execvp(args[0], (char * const *)args);
fprintf(stderr, "%s\n", "Error while run compiler !");
return 1;
}

0 comments on commit 59e6b6e

Please sign in to comment.