Skip to content

Commit baf1749

Browse files
committed
Fix several bugs
1 parent 394dfb4 commit baf1749

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void ParseConfig(const fs::path& conf_path) {
4141
SetPinnedCPU(ini[""]["pinned_cpus"] | "none");
4242
kMaxRSS = (ini[""]["max_rss_per_task_mb"] | (kMaxRSS / 1024)) * 1024;
4343
kMaxOutput = (ini[""]["max_output_per_task_mb"] | (kMaxRSS / 1024)) * 1024;
44-
kMaxQueue = ini[""]["max_submission_queue_size"] | kMaxQueue;
44+
kMaxQueue = ini[""]["max_submission_queue_size"] | (kMaxParallel + 2);
4545
kTimeMultiplier = ini[""]["time_multiplier"] | kTimeMultiplier;
4646
kTIOJUrl = ini[""]["tioj_url"] | kTIOJUrl;
4747
kTIOJKey = ini[""]["tioj_key"] | kTIOJKey;

src/tioj/submission.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ inline bool IsCancelled(long id, const std::vector<int>& groups) {
190190
}
191191

192192
inline long NormalizeScore(long double score) {
193-
constexpr long double kMax = 999999.999999L;
193+
constexpr long double kMax = 1'000'000;
194194
if (score > kMax) score = kMax;
195195
if (score < -kMax) score = -kMax;
196196
return std::lround(score * 1'000'000);
@@ -200,7 +200,7 @@ inline Compiler GetLang(const Submission& sub, CompileSubtask subtask) {
200200
switch (subtask) {
201201
case CompileSubtask::USERPROG: return sub.lang;
202202
case CompileSubtask::SPECJUDGE: return sub.specjudge_lang;
203-
case CompileSubtask::SUMMARY: return sub.specjudge_lang;
203+
case CompileSubtask::SUMMARY: return sub.summary_lang;
204204
}
205205
__builtin_unreachable();
206206
}
@@ -274,11 +274,15 @@ void FinalizeCompile(SubmissionAndResult& sub_and_result, const TaskEntry& task,
274274
sub_res.verdict = Verdict::JE;
275275
} else if (cjail_res.timekill || cjail_res.oomkill > 0 || cjail_res.info.si_status != 0 ||
276276
!fs::is_regular_file(CompileBoxOutput(id, subtask, lang))) {
277-
if (cjail_res.timekill || cjail_res.oomkill > 0) {
278-
sub_res.verdict = subtask == CompileSubtask::USERPROG ? Verdict::CLE : Verdict::ER;
277+
Verdict verd;
278+
if (subtask != CompileSubtask::USERPROG) {
279+
verd = Verdict::ER;
280+
} else if (cjail_res.timekill || cjail_res.oomkill > 0) {
281+
verd = Verdict::CLE;
279282
} else {
280-
sub_res.verdict = subtask == CompileSubtask::USERPROG ? Verdict::CE : Verdict::ER;
283+
verd = Verdict::CE;
281284
}
285+
sub_res.verdict = std::max(sub_res.verdict, verd);
282286
spdlog::info("Compilation failed: id={} subtask={} verdict={}",
283287
id, CompileSubtaskName(subtask), VerdictToAbr(sub_res.verdict));
284288

@@ -455,7 +459,13 @@ bool SetupScoring(SubmissionAndResult& sub_and_result, const TaskEntry& task) {
455459
return false;
456460
}
457461
CreateDirs(Workdir(ScoringBoxPath(id, subtask, stage)), fs::perms::all);
458-
{
462+
// special judge program
463+
fs::path specjudge_prog = sub.specjudge_type == SpecjudgeType::NORMAL ?
464+
DefaultScoringPath() : CompileBoxOutput(id, CompileSubtask::SPECJUDGE, sub.specjudge_lang);
465+
Copy(specjudge_prog, ScoringBoxProgram(id, subtask, stage, sub.specjudge_lang), fs::perms::all);
466+
// user code
467+
Copy(SubmissionUserCode(id), ScoringBoxUserCode(id, subtask, stage, sub.lang), kPerm666);
468+
{ // user output
459469
auto user_output = ExecuteBoxFinalOutput(id, subtask, stage);
460470
if (sub.specjudge_type == SpecjudgeType::SKIP) {
461471
Move(user_output, ScoringBoxOutput(id, subtask, stage));
@@ -471,16 +481,11 @@ bool SetupScoring(SubmissionAndResult& sub_and_result, const TaskEntry& task) {
471481
fs::permissions(scoring_user_output, kPerm666);
472482
}
473483
}
474-
{
484+
{ // input and answer
475485
std::lock_guard lck(td_file_lock[sub.problem_id]);
476486
Copy(sub.testdata[subtask].input_file, ScoringBoxTdInput(id, subtask, stage), kPerm666);
477487
Copy(sub.testdata[subtask].answer_file, ScoringBoxTdOutput(id, subtask, stage), kPerm666);
478488
}
479-
Copy(SubmissionUserCode(id), ScoringBoxUserCode(id, subtask, stage, sub.lang), kPerm666);
480-
// special judge program
481-
fs::path specjudge_prog = sub.specjudge_type == SpecjudgeType::NORMAL ?
482-
DefaultScoringPath() : CompileBoxOutput(id, CompileSubtask::SPECJUDGE, sub.specjudge_lang);
483-
Copy(specjudge_prog, ScoringBoxProgram(id, subtask, stage, sub.specjudge_lang), fs::perms::all);
484489
{ // write meta file
485490
std::ofstream fout(ScoringBoxMetaFile(id, subtask, stage));
486491
fout << sub_and_result.TestdataMeta(subtask, stage);
@@ -638,23 +643,21 @@ bool SetupSummary(SubmissionAndResult& sub_and_result, const TaskEntry& task) {
638643
if ((int)res.verdict < (int)td.verdict) res.verdict = td.verdict;
639644
}
640645
}
641-
if (sub.summary_type == SummaryType::NONE) return false;
646+
if (sub.summary_type == SummaryType::NONE || res.verdict == Verdict::ER) return false;
642647

643648
long id = sub.submission_internal_id;
644649
CreateDirs(Workdir(SummaryBoxPath(id)), fs::perms::all);
650+
Move(CompileBoxOutput(id, CompileSubtask::SUMMARY, sub.summary_lang),
651+
SummaryBoxProgram(id, sub.summary_lang), fs::perms::all);
645652
Copy(SubmissionUserCode(id), SummaryBoxUserCode(id, sub.lang), kPerm666);
646653
if (fs::path ce_message_src = CompileBoxMessage(id, CompileSubtask::USERPROG);
647654
fs::is_regular_file(ce_message_src)) {
648-
Copy(ce_message_src, SummaryBoxCEMessage(id), kPerm666);
655+
Move(ce_message_src, SummaryBoxCEMessage(id), kPerm666);
649656
} else {
650657
// touch file
651658
std::ofstream(SummaryBoxCEMessage(id)).close();
652659
fs::permissions(SummaryBoxCEMessage(id), kPerm666);
653660
}
654-
Copy(CompileBoxMessage(id, CompileSubtask::USERPROG),
655-
SummaryBoxCEMessage(id), kPerm666);
656-
Copy(CompileBoxOutput(id, CompileSubtask::SUMMARY, sub.summary_lang),
657-
SummaryBoxProgram(id, sub.summary_lang), fs::perms::all);
658661
{ // write meta file
659662
std::ofstream fout(SummaryBoxMetaFile(id));
660663
fout << sub_and_result.SummaryMeta();
@@ -696,13 +699,13 @@ void ReadSummaryResult(const fs::path& output_path, SubmissionResult& res) {
696699
}
697700

698701
/// Submission tasks env teardown
699-
void FinalizeSummary(SubmissionAndResult& sub_and_result, const TaskEntry& task, const struct cjail_result& cjail_res) {
702+
void FinalizeSummary(SubmissionAndResult& sub_and_result, const TaskEntry& task, const struct cjail_result& cjail_res, bool skipped) {
700703
const Submission& sub = sub_and_result.sub;
701704
SubmissionResult& res = sub_and_result.result;
702705
long id = sub.submission_internal_id;
703706

704707
if (res.verdict != Verdict::CE) {
705-
constexpr int64_t kInfScore = 2'000'000'000'000;
708+
constexpr int64_t kInfScore = 2'000'000'000'000L;
706709
res.total_memory = 0;
707710
res.total_time = 0;
708711
std::vector<int64_t> subtask_scores(sub.group_score.size(), kInfScore);
@@ -723,7 +726,7 @@ void FinalizeSummary(SubmissionAndResult& sub_and_result, const TaskEntry& task,
723726
}
724727
res.total_score = NormalizeScore((long double)total_score / (100'000'000LL * 1'000'000));
725728
}
726-
if (sub.summary_type == SummaryType::CUSTOM) {
729+
if (!skipped) {
727730
auto output_path = SummaryBoxOutput(id);
728731
if (!fs::is_regular_file(output_path) || cjail_res.info.si_status != 0) {
729732
res.verdict = Verdict::WA;
@@ -765,7 +768,7 @@ void FinalizeTask(long id, const struct cjail_result& res, bool skipped = false)
765768
case TaskType::COMPILE: FinalizeCompile(sub, entry, res); break;
766769
case TaskType::EXECUTE: FinalizeExecute(sub, entry, res); break;
767770
case TaskType::SCORING: FinalizeScoring(sub, entry, res); break;
768-
case TaskType::SUMMARY: FinalizeSummary(sub, entry, res); break;
771+
case TaskType::SUMMARY: FinalizeSummary(sub, entry, res, skipped); break;
769772
}
770773
}
771774
Remove(entry);

src/tioj/tasks.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct cjail_result RunCompile(const SubmissionAndResult& sub_and_result, const
136136
}
137137
if (char* path = getenv("PATH")) opt.envs.push_back(std::string("PATH=") + path);
138138
opt.workdir = Workdir("/");
139+
opt.input = "/dev/null";
139140
opt.fd_output = open(CompileBoxMessage(id, subtask).c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
140141
opt.fd_error = opt.fd_output;
141142
if (cpuid != -1) opt.cpu_set.push_back(cpuid);
@@ -250,6 +251,7 @@ struct cjail_result RunScoring(const SubmissionAndResult& sub_and_result, const
250251
}
251252
}
252253
opt.workdir = Workdir("/");
254+
opt.input = "/dev/null";
253255
opt.output = ScoringBoxOutput(-1, -1, -1, true);
254256
opt.error = "/dev/null";
255257
if (cpuid != -1) opt.cpu_set.push_back(cpuid);
@@ -275,6 +277,7 @@ struct cjail_result RunSummary(const SubmissionAndResult& sub_and_result, const
275277
opt.command = ExecuteCommand(sub.summary_lang, program);
276278
opt.command.push_back(SummaryBoxMetaFile(-1, true));
277279
opt.workdir = Workdir("/");
280+
opt.input = "/dev/null";
278281
opt.output = SummaryBoxOutput(-1, true);
279282
opt.error = "/dev/null";
280283
if (cpuid != -1) opt.cpu_set.push_back(cpuid);

0 commit comments

Comments
 (0)