QingdaoU / OnlineJudge

Open source online judge based on Vue, Django and Docker. | 青岛大学开源 Online Judge | QQ群 496710125 | admin@qduoj.com
http://opensource.qduoj.com/
MIT License
6.05k stars 1.47k forks source link

使用FILE IO测资问题 #449

Closed judy8889107 closed 1 year ago

judy8889107 commented 1 year ago

使用FILE IO测资问题

想请问如何使用FILE IO的测资? 有没有任何说明或范例呢? 我建立完题目以后,将Code丢上去一直出现Runtime Error

image


这是我的测资

image

1.in

6
17
-1

1.out

00000000 00000000 00000000 0000110
00000000 00000000 00000000 0010001

答案程式码


#include <stdio.h>

#define BINARY_SIZE 31

/* Declaration */
void outputFile(FILE *fp, int binary[]);

void outputFile(FILE *fp, int binary[])
{
    fp = fopen("1.out", "a"); /* 写入档案 1.out */

    ...(省略)

    fclose(fp);
}

int main()
{
    int n = 0;

    FILE *fin;

    fin = fopen("1.in", "r"); /* 读取档案 1.in */
    if (fin == NULL)
        return -1;
    while (fscanf(fin, "%d\n", &n) && n != -1)
    {
        ...(省略)

        FILE *fp;
        outputFile(fp, binary);
    }
    fclose(fin);
}
virusdefender commented 1 year ago

dmesg -T 看下运行这个测试的时候的日志信息,31 是程序中出现了不允许的 syscall,可能是代码问题,也可能是评测的 bug。

judy8889107 commented 1 year ago

您好,因为我之前看到有人有开相关Issue,但是他评测cpp的档案好像有成功(#320),所以我先弄了一个cpp的题目,如下:

file_IO.cpp:

#include <iostream>
#include <fstream> // 添加此行
using namespace std;

int main() {
    int a, b;
    ifstream fin("1.in");
    fin >> a >> b;
    ofstream fout("1.out");
    fout << a + b << endl;
    return 0;
}

后台测资设定(1.zip): image

1.in

3
5

1.out

8

日志信息:

[二  九   5 17:52:34 2023] audit: type=1326 audit(1693907556.627:144): auid=4294967295 uid=12002 gid=12002 ses=4294967295 subj=docker-default pid=2735017 comm="main" exe="/judger/run/bca7e5cd9de3432b9df2e0d25635f697/main" sig=31 arch=c000003e syscall=257 compat=0 ip=0x7fb40d018ebd code=0x0

docker-compose.yml

version: "3"
services:

  oj-redis:
    image: redis:4.0-alpine
    container_name: oj-redis
    restart: always
    volumes:
      - ./data/redis:/data

  oj-postgres:
    image: postgres:10-alpine
    container_name: oj-postgres
    restart: always
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=onlinejudge
      - POSTGRES_USER=onlinejudge
      - POSTGRES_PASSWORD=onlinejudge

  judge-server:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/judge_server
    container_name: judge-server
    restart: always
    read_only: true
    cap_drop:
      - SETPCAP
      - MKNOD
      - NET_BIND_SERVICE
      - SYS_CHROOT
      - SETFCAP
      - FSETID
    tmpfs:
      - /tmp
    volumes:
      - ./data/backend/test_case:/test_case:ro
      - ./data/judge_server/log:/log
      - ./data/judge_server/run:/judger
    environment:
      - SERVICE_URL=http://judge-server:8080
      - BACKEND_URL=http://oj-backend:8000/api/judge_server_heartbeat/
      - TOKEN=secret
      # - judger_debug=1

  oj-backend:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/oj_backend
    container_name: oj-backend
    restart: always
    depends_on:
      - oj-redis
      - oj-postgres
      - judge-server
    volumes:
      - ./data/backend:/data
    environment:
      - POSTGRES_DB=onlinejudge
      - POSTGRES_USER=onlinejudge
      - POSTGRES_PASSWORD=onlinejudge
      - JUDGE_SERVER_TOKEN=secret
      # - FORCE_HTTPS=1
      # - STATIC_CDN_HOST=cdn.oj.com
    ports:
      - "0.0.0.0:80:8000"
      - "0.0.0.0:443:1443"

docker images

REPOSITORY                                                   TAG          IMAGE ID       CREATED         SIZE
postgres                                                     10-alpine    02c83b13f6ea   9 months ago    79.1MB
registry.cn-hangzhou.aliyuncs.com/onlinejudge/oj_backend     latest       d93611742834   23 months ago   247MB
registry.cn-hangzhou.aliyuncs.com/onlinejudge/judge_server   latest       e77651bea843   23 months ago   1.61GB
redis                                                        4.0-alpine   e3dd0e49bca5   3 years ago     20.4MB

但我看到有人好像改了镜像源的地址(#309),请问是哪里有问题呢? 如果有需要附上任何详细资讯请告诉我,非常感谢您!

virusdefender commented 1 year ago

看上去是 openat syscall 不被允许导致的,https://github.com/QingdaoU/Judger/blame/newnew/src/rules/c_cpp.c#L48 这里应该是少了一个 openat

judy8889107 commented 1 year ago

我们刚刚照着(#309)的方法,换了一个镜像源,就可以成功了! 谢谢您的回覆~

image image

virusdefender commented 1 year ago

嗯,那是第三方维护的 judge server,可能与本项目有些不同,注意到这一点就行。我刚才在 Judger 项目中改了下,但是整体的镜像还没有重新构建。