From 83690959c927103b05d3b1f289de84b0ea710048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8A=E5=86=B3=E2=95=87=D1=84?= Date: Thu, 24 Sep 2020 23:12:16 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E3=80=90=E6=A8=A1=E5=9D=97=EF=BC=9A?= =?UTF-8?q?=E5=88=A4=E9=A2=98=E5=99=A8=E3=80=91=E3=80=90=E6=94=B9=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E5=B0=86=E9=99=90=E5=88=B6=E9=80=89=E6=89=8B=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=E9=97=B4=E7=9A=84=E9=99=90=E5=88=B6=E7=94=B1?= =?UTF-8?q?=E9=99=90=E5=88=B6=E7=9C=9F=E5=AE=9E=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E4=BF=AE=E6=94=B9=E4=B8=BA=E9=99=90=E5=88=B6=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=80=81=E6=97=B6=E9=97=B4=E3=80=91=E3=80=90=E5=BD=B1?= =?UTF-8?q?=E5=93=8D=EF=BC=9A=E5=88=A4=E9=A2=98=E7=BB=93=E6=9E=9CTLE?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/judge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/judge.cpp b/src/judge.cpp index 4e61bd9..7883795 100644 --- a/src/judge.cpp +++ b/src/judge.cpp @@ -468,7 +468,7 @@ bool judge(const char *input_file, uint64_t real_time_limit = oj_solution.time_limit + time_limit_addtion; // time fix // set real time alarm - if (EXIT_SUCCESS != malarm(ITIMER_REAL, real_time_limit)) { + if (EXIT_SUCCESS != malarm(ITIMER_VIRTUAL, real_time_limit)) { FM_LOG_FATAL("malarm for executor failed: %s", strerror(errno)); exit(EXIT_PRE_JUDGE); } -- Gitee From b538ad009f285d25ce40dbf2c9be0eeaba31590a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B4=8B=E9=98=B3?= Date: Fri, 25 Sep 2020 23:41:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E3=80=90=E5=88=A4=E9=A2=98=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E3=80=91=E3=80=90=E6=94=B9=E5=8A=A8=EF=BC=9A?= =?UTF-8?q?=E5=B0=86=E5=AE=89=E5=85=A8=E9=98=9F=E5=88=97=E7=9A=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E7=9A=84=E5=AD=98=E5=82=A8=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88=E3=80=91=E3=80=90=E5=BD=B1=E5=93=8D=E9=9D=A2?= =?UTF-8?q?=EF=BC=9A=E4=BB=BB=E5=8A=A1=E8=B0=83=E5=BA=A6=EF=BC=8C=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E5=81=9C=E6=AD=A2=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/judged.cpp | 48 ++++++++++++++++++++++----------------- src/thread_safe_queue.hpp | 42 ++++++++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 30 deletions(-) diff --git a/src/judged.cpp b/src/judged.cpp index c64aa9a..6bb2d5f 100644 --- a/src/judged.cpp +++ b/src/judged.cpp @@ -30,22 +30,28 @@ ThreadSafeQueue > SendQueue; void ThreadWork() { while (isRunning) { - oj_solution_t oj_solution = ProcessQueue.GetFrontAndPop(); - pthread_t ptid = pthread_self(); - FM_LOG_TRACE("Thread id: %d", ptid); - run(oj_solution); + oj_solution_t *oj_solution = ProcessQueue.GetFrontAndPop(); + if (oj_solution) { + pthread_t ptid = pthread_self(); + FM_LOG_TRACE("Thread id: %d", ptid); + run(*oj_solution); + delete oj_solution; + } } } void SendWork() { while (isRunning) { auto item = SendQueue.GetFrontAndPop(); - pthread_t ptid = pthread_self(); - FM_LOG_TRACE("Send thread id: %d", ptid); - if (item.first == EXIT_OK) { - update_result(item.second); - } else { - update_system_error(item.first, item.second); + if (item) { + pthread_t ptid = pthread_self(); + FM_LOG_TRACE("Send thread id: %d", ptid); + if (item->first == EXIT_OK) { + update_result(item->second); + } else { + update_system_error(item->first, item->second); + } + delete item; } } } @@ -176,8 +182,8 @@ void work(int newsockfd, struct sockaddr_in cli_addr) { return; } FM_LOG_NOTICE("Here is the message: %s(%d)", buffer, n); - oj_solution_t oj_solution{}; - if (parse_arguments(buffer, oj_solution) < 0) { + oj_solution_t *oj_solution = new oj_solution_t; + if (parse_arguments(buffer, *oj_solution) < 0) { FM_LOG_WARNING("Missing some parameters."); n = write(newsockfd, "Missing some parameters.", 24); if (n < 0) FM_LOG_WARNING("ERROR writing to socket"); @@ -215,7 +221,7 @@ void run(oj_solution_t &oj_solution) { pid_t pid = fork(); if (pid < 0) { FM_LOG_FATAL("fork judger failed: %s", strerror(errno)); - SendQueue.push(std::make_pair(EXIT_FORK_ERROR, oj_solution)); + SendQueue.push(new std::pair(EXIT_FORK_ERROR, oj_solution)); } else if (pid == 0) { execl("/usr/local/bin/powerjudge", "/usr/local/bin/powerjudge", @@ -230,7 +236,7 @@ void run(oj_solution_t &oj_solution) { NULL); stderr = freopen(stderr_file, "a+", stderr); FM_LOG_FATAL("exec error: %s", strerror(errno)); - SendQueue.push(std::make_pair(EXIT_EXEC_ERROR, oj_solution)); + SendQueue.push(new std::pair(EXIT_EXEC_ERROR, oj_solution)); } else { int status = 0; FM_LOG_TRACE("process ID=%d", pid); @@ -242,31 +248,31 @@ void run(oj_solution_t &oj_solution) { { if (EXIT_SUCCESS == WEXITSTATUS(status)) { FM_LOG_DEBUG("judge succeeded"); - SendQueue.push(std::make_pair(EXIT_OK, oj_solution)); + SendQueue.push(new std::pair(EXIT_OK, oj_solution)); } else if (EXIT_COMPILE_ERROR == WEXITSTATUS(status)) { FM_LOG_TRACE("compile error"); - SendQueue.push(std::make_pair(EXIT_OK, oj_solution)); + SendQueue.push(new std::pair(EXIT_OK, oj_solution)); } else if (EXIT_JUDGE == WEXITSTATUS(status)) { FM_LOG_TRACE("judge error"); - SendQueue.push(std::make_pair(OJ_SE, oj_solution)); + SendQueue.push(new std::pair(OJ_SE, oj_solution)); } else { FM_LOG_TRACE("judge error"); - SendQueue.push(std::make_pair(WEXITSTATUS(status), oj_solution)); + SendQueue.push(new std::pair(WEXITSTATUS(status), oj_solution)); } } else { if (WIFSIGNALED(status)) // killed by signal { int signo = WTERMSIG(status); FM_LOG_WARNING("judger killed by signal: %s", strsignal(signo)); - SendQueue.push(std::make_pair(signo, oj_solution)); + SendQueue.push(new std::pair(signo, oj_solution)); } else if (WIFSTOPPED(status)) // stopped by signal { int signo = WSTOPSIG(status); FM_LOG_FATAL("judger stopped by signal: %s\n", strsignal(signo)); - SendQueue.push(std::make_pair(signo, oj_solution)); + SendQueue.push(new std::pair(signo, oj_solution)); } else { FM_LOG_FATAL("judger stopped with unknown reason, status(%d)", status); - SendQueue.push(std::make_pair(EXIT_UNKNOWN, oj_solution)); + SendQueue.push(new std::pair(EXIT_UNKNOWN, oj_solution)); } } } diff --git a/src/thread_safe_queue.hpp b/src/thread_safe_queue.hpp index 3804fef..807555a 100644 --- a/src/thread_safe_queue.hpp +++ b/src/thread_safe_queue.hpp @@ -9,24 +9,48 @@ #include #include -template +template class ThreadSafeQueue { private: - std::queue q; + std::queue q; std::mutex mut; std::condition_variable data_cond; + bool m_bRunning; public: - T GetFrontAndPop() { + ThreadSafeQueue() { + m_bRunning = false; + } + + void start() { + m_bRunning = true; + } + + void stop() { + m_bRunning = false; + data_cond.notify_all(); + } + + T *GetFrontAndPop() { std::unique_lock lk(mut); - data_cond.wait(lk, [this] { return !this->q.empty(); }); - T ret = q.front(); - q.pop(); - return ret; + data_cond.wait(lk, [this] { + if (m_bRunning) { + return !this->q.empty(); + } else { + return true; + } + }); + if (m_bRunning) { + T *ret = q.front(); + q.pop(); + return ret; + } else { + return nullptr; + } } - void push(T x) { + void push(T *x) { std::unique_lock lk(mut); - q.push(x); + q.push(*x); data_cond.notify_one(); } }; -- Gitee From d703fe1950f8f55bad688cd0d15f3129cd70778b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B4=8B=E9=98=B3?= Date: Sat, 26 Sep 2020 23:41:40 +0800 Subject: [PATCH 3/3] syscall --- src/syscalls.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/syscalls.cpp b/src/syscalls.cpp index c8ea68c..4510e46 100644 --- a/src/syscalls.cpp +++ b/src/syscalls.cpp @@ -270,7 +270,8 @@ static int SC_C[512] = { SYS_write, SYSCALLS_INFINITE, SYS_writev, SYSCALLS_INFINITE, SYS_lseek, SYSCALLS_INFINITE, - SYSCALLS_END + SYS_arch_prctl, SYSCALLS_INFINITE, + SYSCALLS_END }; @@ -303,6 +304,7 @@ static int SC_CPP[512] = { SYS_write, SYSCALLS_INFINITE, SYS_writev, SYSCALLS_INFINITE, SYS_lseek, SYSCALLS_INFINITE, + SYS_arch_prctl, SYSCALLS_INFINITE, SYSCALLS_END }; @@ -337,7 +339,7 @@ static int SC_JAVA[512] = { 110, SYSCALLS_INFINITE, 111, SYSCALLS_INFINITE, 13, SYSCALLS_INFINITE, - SYS_arch_prctl, 1, + SYS_arch_prctl, SYSCALLS_INFINITE, 16, SYSCALLS_INFINITE, 22, SYSCALLS_INFINITE, 33, SYSCALLS_INFINITE, @@ -381,6 +383,7 @@ static int SC_JAVA[512] = { SYS_write, SYSCALLS_INFINITE, SYS_openat, SYSCALLS_INFINITE, SYS_prlimit64, SYSCALLS_INFINITE, + SYS_pread64, SYSCALLS_INFINITE, SYSCALLS_END }; @@ -432,6 +435,8 @@ static int SC_PYTHON[512] = { SYS_sysinfo, SYSCALLS_INFINITE, SYS_write, SYSCALLS_INFINITE, SYS_prlimit64, SYSCALLS_INFINITE, + SYS_pread64, SYSCALLS_INFINITE, + SYS_getdents64, SYSCALLS_INFINITE, SYSCALLS_END }; @@ -553,4 +558,4 @@ bool is_valid_syscall(int syscall_id) { return true; } -#endif \ No newline at end of file +#endif -- Gitee