Skip to content

Commit

Permalink
Disable the judgehost when default system commands fail
Browse files Browse the repository at this point in the history
All of those actions are default system command like creating or cleaning up needed files/directories.
Those should never fail so if they do we can't really trust this judgehost anymore until we inspected the host.

Leftover is the disabling of debug_scripts when we can't run those as we don't have a dependant entity like for languages/problems
which we can disable in its place. The closest thing would be the `default_debug_script` key in the config which is a bit brittle.
A suggestion is to either store this as a fact with the executable or put in the work to remove this as the default option in the config.

Also swapped one function to the non-internal function which handles the disabling already.
  • Loading branch information
Michael Vasseur authored and vmcj committed Nov 22, 2024
1 parent 0c9c8a8 commit 1885c3f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
29 changes: 16 additions & 13 deletions judge/judgedaemon.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,21 @@ function fetch_executable_internal(
$hash
]);
global $langexts;
global $myhost;
$execdeploypath = $execdir . '/.deployed';
$execbuilddir = $execdir . '/build';
$execbuildpath = $execbuilddir . '/build';
$execrunpath = $execbuilddir . '/run';
$execrunjurypath = $execbuilddir . '/runjury';
if (!is_dir($execdir) || !file_exists($execdeploypath) ||
($combined_run_compare && file_get_contents(LIBJUDGEDIR . '/run-interactive.sh')!==file_get_contents($execrunpath))) {
system('rm -rf ' . dj_escapeshellarg($execdir) . ' ' . dj_escapeshellarg($execbuilddir));
system('rm -rf ' . dj_escapeshellarg($execdir) . ' ' . dj_escapeshellarg($execbuilddir), $retval);
if ($retval !== 0) {
disable('judgehost', 'hostname', $myhost, "Deleting '$execdir' or '$execbuilddir' was unsuccessful.");
}
system('mkdir -p ' . dj_escapeshellarg($execbuilddir), $retval);
if ($retval !== 0) {
error("Could not create directory '$execbuilddir'");
disable('judgehost', 'hostname', $myhost, "Could not create directory '$execbuilddir'");
}

logmsg(LOG_INFO, " 💾 Fetching new executable '$type/$execid' with hash '$hash'.");
Expand Down Expand Up @@ -387,7 +391,7 @@ function fetch_executable_internal(
$unescapedSource = "";
foreach ($langexts as $lang => $langext) {
if (($handle = opendir($execbuilddir)) === false) {
error("Could not open $execbuilddir");
disable('judgehost', 'hostname', $myhost, "Could not open $execbuilddir");
}
while (($file = readdir($handle)) !== false) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
Expand Down Expand Up @@ -432,7 +436,7 @@ function fetch_executable_internal(
break;
}
if (file_put_contents($execbuildpath, $buildscript) === false) {
error("Could not write file 'build' in $execbuilddir");
disable('judgehost', 'hostname', $myhost, "Could not write file 'build' in $execbuilddir");
}
chmod($execbuildpath, 0755);
}
Expand Down Expand Up @@ -464,10 +468,10 @@ function fetch_executable_internal(
# team submission and runjury programs and connects their pipes.
$runscript = file_get_contents(LIBJUDGEDIR . '/run-interactive.sh');
if (rename($execrunpath, $execrunjurypath) === false) {
error("Could not move file 'run' to 'runjury' in $execbuilddir");
disable('judgehost', 'hostname', $myhost, "Could not move file 'run' to 'runjury' in $execbuilddir");
}
if (file_put_contents($execrunpath, $runscript) === false) {
error("Could not write file 'run' in $execbuilddir");
disable('judgehost', 'hostname', $myhost, "Could not write file 'run' in $execbuilddir");
}
chmod($execrunpath, 0755);
}
Expand Down Expand Up @@ -831,21 +835,20 @@ function fetch_executable_internal(
// Full debug package requested.
$run_config = dj_json_decode($judgeTask['run_config']);
$tmpfile = tempnam(TMPDIR, 'full_debug_package_');
[$runpath, $error] = fetch_executable_internal(
[$runpath, $error] = fetch_executable(
$workdirpath,
'debug',
$judgeTask['run_script_id'],
$run_config['hash']
$run_config['hash'],
$judgeTask['judgetaskid']
);
if (isset($error)) {
// FIXME
continue;
}

$debug_cmd = implode(' ', array_map('dj_escapeshellarg',
[$runpath, $workdir, $tmpfile]));
system($debug_cmd, $retval);
// FIXME: check retval
if ($retval !== 0) {
disable('run_script', 'run_script_id', $judgeTask['run_script_id'], "Running '$runpath' failed.");
}

request(
sprintf('judgehosts/add-debug-info/%s/%s', urlencode($myhost),
Expand Down
1 change: 1 addition & 0 deletions webapp/src/Service/DOMJudgeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ public function setInternalError(array $disabled, ?Contest $contest, ?bool $enab
$contestProblem->setAllowJudge($enabled);
}
}
// FIXME: Also disable debug scripts
$this->em->flush();
if ($enabled) {
foreach ($executable->getLanguages() as $language) {
Expand Down

0 comments on commit 1885c3f

Please sign in to comment.