Skip to content

Commit

Permalink
Disable the judgehost instead of killing for local actions
Browse files Browse the repository at this point in the history
We will only terminate on either:
- failure in startup
- when communiation with the domserver fails as we can't communicate at that point.

Implement Tobi his feedback
  • Loading branch information
Michael Vasseur committed Oct 27, 2024
1 parent d02a6cd commit 9e00e09
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions judge/judgedaemon.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ function fetch_executable_internal(
$hash
]);
global $langexts;
global $myhost;
$execdeploypath = $execdir . '/.deployed';
$execbuilddir = $execdir . '/build';
$execbuildpath = $execbuilddir . '/build';
Expand All @@ -336,11 +337,11 @@ function fetch_executable_internal(
if (!is_dir($execdir) || !file_exists($execdeploypath)) {
system('rm -rf ' . dj_escapeshellarg($execdir) . ' ' . dj_escapeshellarg($execbuilddir), $retval);
if ($retval !== 0) {
error("Deleting '$execdir' or '$execbuilddir' was unsuccessful.");
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 @@ -389,7 +390,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 @@ -434,7 +435,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 @@ -466,10 +467,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 @@ -841,14 +842,14 @@ function fetch_executable_internal(
);
if (isset($error)) {
$scriptId = $judgeTask['run_script_id'];
error("Retrieving/storing debug script '$scriptId' failed.");
disable('judgehost', 'hostname', $myhost, "Retrieving/storing debug script '$scriptId' failed.");
}

$debug_cmd = implode(' ', array_map('dj_escapeshellarg',
[$runpath, $workdir, $tmpfile]));
system($debug_cmd, $retval);
if ($retval !== 0) {
error("Running '$runpath' failed.");
disable('judgehost', 'hostname', $myhost, "Running '$runpath' failed.");
}

request(
Expand Down

0 comments on commit 9e00e09

Please sign in to comment.