Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 45 additions & 22 deletions judge/judgedaemon.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,11 @@ private function loop(): void
// indicating that we didn't find any child to be
// reaped
if ($errno != 10) {
logmsg(LOG_WARNING,
logmsg(
LOG_WARNING,
"pcntl_waitpid returned $ret when trying to reap child processes: "
. pcntl_strerror($errno));
. pcntl_strerror($errno)
);
}
}

Expand Down Expand Up @@ -322,7 +324,7 @@ private function loop(): void
$judgehosts = $this->request('judgehosts', 'GET');
if ($judgehosts !== null) {
$judgehosts = dj_json_decode($judgehosts);
$judgehost = array_values(array_filter($judgehosts, fn($j) => $j['hostname'] === $this->myhost))[0];
$judgehost = array_values(array_filter($judgehosts, fn ($j) => $j['hostname'] === $this->myhost))[0];
if (!isset($judgehost['enabled']) || !$judgehost['enabled']) {
logmsg(LOG_WARNING, "Judgehost needs to be enabled in web interface.");
}
Expand Down Expand Up @@ -467,8 +469,11 @@ private function handleDebugInfoTask(array $row, ?string &$lastWorkdir, string $
}

$this->request(
sprintf('judgehosts/add-debug-info/%s/%s', urlencode($this->myhost),
urlencode((string)$judgeTask['judgetaskid'])),
sprintf(
'judgehosts/add-debug-info/%s/%s',
urlencode($this->myhost),
urlencode((string)$judgeTask['judgetaskid'])
),
'POST',
['full_debug' => $this->restEncodeFile($tmpfile, false)],
false
Expand All @@ -480,8 +485,11 @@ private function handleDebugInfoTask(array $row, ?string &$lastWorkdir, string $
// Retrieving full team output for a particular testcase.
$testcasedir = $workdir . "/testcase" . sprintf('%05d', $judgeTask['testcase_id']);
$this->request(
sprintf('judgehosts/add-debug-info/%s/%s', urlencode($this->myhost),
urlencode((string)$judgeTask['judgetaskid'])),
sprintf(
'judgehosts/add-debug-info/%s/%s',
urlencode($this->myhost),
urlencode((string)$judgeTask['judgetaskid'])
),
'POST',
['output_run' => $this->restEncodeFile($testcasedir . '/program.out', false)],
false
Expand Down Expand Up @@ -532,8 +540,10 @@ private function handleTask(string $type, array $row, ?string &$lastWorkdir, str
}
$this->endpoint['retrying'] = false;

logmsg(LOG_INFO,
"⇝ Received " . sizeof($row) . " '" . $type . "' judge tasks (endpoint " . $this->endpoint['id'] . ")");
logmsg(
LOG_INFO,
"⇝ Received " . sizeof($row) . " '" . $type . "' judge tasks (endpoint " . $this->endpoint['id'] . ")"
);

if ($type == 'prefetch') {
$this->handlePrefetchTask($row, $lastWorkdir, $workdirpath);
Expand Down Expand Up @@ -574,10 +584,12 @@ private function checkDiskSpace(string $workdirpath): void
$candidateDirs[] = $workdirpath . "/" . $subdir;
}
}
uasort($candidateDirs, fn($a, $b) => filemtime($a) <=> filemtime($b));
uasort($candidateDirs, fn ($a, $b) => filemtime($a) <=> filemtime($b));
$after = $before = disk_free_space(JUDGEDIR);
logmsg(LOG_INFO,
"🗑 Low on diskspace, cleaning up (" . count($candidateDirs) . " potential candidates).");
logmsg(
LOG_INFO,
"🗑 Low on diskspace, cleaning up (" . count($candidateDirs) . " potential candidates)."
);
$cnt = 0;
foreach ($candidateDirs as $d) {
$cnt++;
Expand All @@ -590,7 +602,9 @@ private function checkDiskSpace(string $workdirpath): void
break;
}
}
logmsg(LOG_INFO, "🗑 Cleaned up $cnt old judging directories; reduced disk space by " .
logmsg(
LOG_INFO,
"🗑 Cleaned up $cnt old judging directories; reduced disk space by " .
sprintf("%01.2fMB.", ($after - $before) / (1024 * 1024))
);
}
Expand Down Expand Up @@ -851,7 +865,9 @@ private function runCommandSafe(array $command_parts, &$retval = DONT_CARE, $log

logmsg(LOG_DEBUG, "Executing command: $command");
system($command, $retval_local);
if ($retval !== DONT_CARE) $retval = $retval_local; // phpcs:ignore Generic.ControlStructures.InlineControlStructure.NotAllowed
if ($retval !== DONT_CARE) {
$retval = $retval_local;
} // phpcs:ignore Generic.ControlStructures.InlineControlStructure.NotAllowed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was explicitly marked to not get reformatted, so I wonder what happened here.
I'd prefer the old way, but at least the comment should not be left like this.


if ($retval_local !== 0) {
if ($log_nonzero_exitcode) {
Expand All @@ -877,8 +893,10 @@ private function fetchExecutable(
if ($buildlogpath !== null) {
$extra_log = dj_file_get_contents($buildlogpath, 4096);
}
logmsg(LOG_ERR,
"Fetching executable failed for $type script '$execid': " . $error);
logmsg(
LOG_ERR,
"Fetching executable failed for $type script '$execid': " . $error
);
$description = "$execid: fetch, compile, or deploy of $type script failed.";
$this->disable(
$type . '_script',
Expand Down Expand Up @@ -939,11 +957,11 @@ private function fetchExecutableInternal(
];
}
unset($files);
uasort($filesArray, fn(array $a, array $b) => strcmp($a['filename'], $b['filename']));
uasort($filesArray, fn (array $a, array $b) => strcmp($a['filename'], $b['filename']));
$computedHash = md5(
join(
array_map(
fn($file) => $file['hash'] . $file['filename'] . $file['is_executable'],
fn ($file) => $file['hash'] . $file['filename'] . $file['is_executable'],
$filesArray
)
)
Expand Down Expand Up @@ -1448,7 +1466,8 @@ private function runTestcase(
$judgeTask['run_script_id'],
$run_config['hash'],
$judgeTask['judgetaskid'],
$combined_run_compare);
$combined_run_compare
);
if (isset($error)) {
return false;
}
Expand Down Expand Up @@ -1532,7 +1551,8 @@ private function runTestcase(
$run_command_parts[] = '-n';
$run_command_parts[] = $this->options['daemonid'];
}
array_push($run_command_parts,
array_push(
$run_command_parts,
$input,
$output,
$timelimit_str,
Expand Down Expand Up @@ -1677,8 +1697,11 @@ private function reportJudgingRun(array $judgeTask, array $new_judging_run, bool
dj_sleep(0.001 * $sleep_ms);
}
$response = $this->request(
sprintf('judgehosts/add-judging-run/%s/%s', $new_judging_run['hostname'],
urlencode((string)$judgeTaskId)),
sprintf(
'judgehosts/add-judging-run/%s/%s',
$new_judging_run['hostname'],
urlencode((string)$judgeTaskId)
),
'POST',
$new_judging_run,
false
Expand Down
Loading