惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
博客园_首页
美团技术团队
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
J
Java Code Geeks
T
Tailwind CSS Blog
Jina AI
Jina AI
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - Morya

不当心升级到 redis 7.4 怎么回到 valkey8 使用 cert-manager 为 traefik 自动申请和续约 https 证书 traefik学习 k8s 1.28 安装配置 knative-serving v1.15.2 + cert-manager v1.16.1 ssh端口映射玩法 golang echo group 用法的微妙注意点 使用docker最小化部署Git CI环境 使用mailpopbox构建个人独享EmailServer Influx cli cheetsheet 通过php docker快速验证简单代码 通过k8s service代理外部服务 run gitlab-runner in k8s K8S配置traefik ingressroutes支持TLS ucloud k8s部署traefik的forward-auth 使用nginx构建限频、限速、限并发的应用保护层 macos 更改罗技k810无线键盘的映射 - Morya - 博客园 C++11 thread condition_variable mutex 综合使用 goland scope pattern 设置 Go 1.11 Module 介绍 - Morya
hustOJ 添加 golang 支持
Morya · 2018-09-24 · via 博客园 - Morya

hustOJ 支持Go1.7.1

是否为docker环境不重要,此处所有内容均为docker中执行,普通主机手动安装则更加如此

建议在docker中执行,因为OJ为严控恶意权限,judge_client做了很多特殊指令

hustOJ 虽然有部分代码涉及到了golang
但,实际还无法正常执行。

本次支持的是go 1.7.1

关键改动都在core组件里面的judge_client

系统修改

  1. 配置apt使用清华大学镜像下载golang

文件 /etc/apt/sources.list

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ jessie main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ jessie main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ jessie-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ jessie-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ jessie-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ jessie-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security jessie/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security jessie/updates main contrib non-free

安装 golang

apt-get install golang-1.7.1

改动点:

  1. okcalls64.h

在数组里面增加 186 信号,baidu说,此信号实际对应值是:186 gettid

如果不增加,golang编译的程序会被judge_client fork 出的parent监控并停止。

int LANG_GOV[256]={0,1,9,11,13,14,56,59,131,158,186,202,204,228,231,0};
  1. judge_client.cc

copy_js_runtime 函数后,新增函数 copy_go_runtime


void copy_go_runtime(char *work_dir) {
    char envbuff[1024] = {0};

    copy_shell_runtime(work_dir);

    execute_cmd("/bin/mkdir %s/usr", work_dir);
    execute_cmd("/bin/mkdir %s/usr/lib", work_dir);
    execute_cmd("/bin/mkdir %s/usr/bin", work_dir);
    // execute_cmd("/bin/cp /usr/lib/go-1.7/bin/go %s/usr/bin/", work_dir);
    putenv((char *)"GOROOT=/usr/lib/go-1.7");
    sprintf(envbuff, "GOPATH=%s", work_dir);
    putenv(envbuff);
}
  1. 修改 int compile(int lang, char *work_dir) 函数
// 此处为方便,直接写死了go-1.7的绝对位置
// 主要judge_client在执行真正的程序前,会先执行很多环境准备
// 甚至包括chroot指令
// 最终导致环境混乱
const char *CP_GO[] = { "/usr/lib/go-1.7/bin/go", "build", "-o", "Main", "Main.go", NULL };
  1. 修改 main 函数
int main(int argc, char **argv) {
    // init_parameters
    // init mysql
    // get_solution_info
    // compile

    // 根据逻辑相关部分新增如下函数
    // copy_go_runtime
  1. make it
cd /home/judge/src/core/judge_client/
make
  1. 单独测试 golang 程序

可以用go源码提交一份其它语言的程序到题目中,此程序会被存储到数据库,
并分配一个solution_id,假设其为1008.

登录数据库,修改其语言为go

mysql -udebian-sys-maint -paaabbb

> use jol;
> update solution set language=17 where solution_id = 1008;
> commit;

以上sql为手写,假装正确

然后手动执行 judge_client

/home/judge/src/core/judge_client/judge_client 1008 1 /home/judge/ debug

如果,最后输出 result=4 则代表实际结果正确了。