From 3c8ffd07ee8dbdd284c645332146c3fec2772ab2 Mon Sep 17 00:00:00 2001 From: pk4wt2yal <1330800687@qq.com> Date: Mon, 25 Nov 2024 12:18:52 +0800 Subject: [PATCH] Delete 'src/my-online-judge-master/MYOJ/compile_server/compile.hpp' --- .../MYOJ/compile_server/compile.hpp | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 src/my-online-judge-master/MYOJ/compile_server/compile.hpp diff --git a/src/my-online-judge-master/MYOJ/compile_server/compile.hpp b/src/my-online-judge-master/MYOJ/compile_server/compile.hpp deleted file mode 100644 index 7e7f42e..0000000 --- a/src/my-online-judge-master/MYOJ/compile_server/compile.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// 编译模块 -#pragma once -#include "./comm/util.hpp" - - -namespace ns_compile -{ - // 提供编译接口 - class Compiler - { - public: - Compiler() - {} - ~Compiler() - {} - - // 编译文件,并且返回编译结果 - bool compile(const std::string& file_name) - { - pid_t id = fork(); - if (id == -1) - { - // 创建失败 - lg(Error, "编译文件时创建子进程失败, errno:%d, strerror:%s\n",errno, strerror(errno)); - exit(1); - } - else if (id == 0) - { - // child - umask(0); - int _stderr = open(ns_util::pathUtil::compilerError(file_name).c_str(), O_CREAT | O_WRONLY, 0664); - if (_stderr < 0) - { - lg(Error, "子进程创建_stderr时出错, errno:%d, strerror:%s\n",errno, strerror(errno)); - exit(2); - } - - int ret = dup2(_stderr, 2); - if (ret == -1) - { - lg(Error, "子进程标准错误重定向错误, errno:%d, strerror:%s\n",errno, strerror(errno)); - exit(3); - } - - // 进程替换 - execlp("g++", "g++", "-o", ns_util::pathUtil::exe(file_name).c_str(), ns_util::pathUtil::src(file_name).c_str(), "-D", "COMPILER_ONLINE", "-std=c++11", nullptr); - - lg(Error, "进程替换错误, errno:%d, strerror:%s\n",errno, strerror(errno)); - exit(4); - } - else if (id > 0) - { - // parent - waitpid(id, nullptr, 0); - - if (ns_util::fileUtil::isFileExist(ns_util::pathUtil::exe(file_name))) - { - lg(Info, "%s 文件编译成功!\n", ns_util::pathUtil::src(file_name).c_str()); - return true; - } - lg(Error, "%s 文件编译失败!\n", ns_util::pathUtil::src(file_name).c_str()); - return false; - } - else - { - // 意料之外的情况 - lg(Debug, "compile创建子进程出现意料之外的情况\n"); - exit(5); - } - } - }; -}