From cfc74dc01f5ff9174d4f152116647c6b888b3c37 Mon Sep 17 00:00:00 2001 From: Michael Vasseur Date: Sun, 20 Oct 2024 11:29:28 +0200 Subject: [PATCH] Disable the judgehost when default system commands fail 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. --- judge/judgedaemon.main.php | 29 ++++++++++++++------------ webapp/src/Service/DOMJudgeService.php | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/judge/judgedaemon.main.php b/judge/judgedaemon.main.php index 262d3a1004..ae63c1dfd4 100644 --- a/judge/judgedaemon.main.php +++ b/judge/judgedaemon.main.php @@ -328,6 +328,7 @@ function fetch_executable_internal( $hash ]); global $langexts; + global $myhost; $execdeploypath = $execdir . '/.deployed'; $execbuilddir = $execdir . '/build'; $execbuildpath = $execbuilddir . '/build'; @@ -335,10 +336,13 @@ function fetch_executable_internal( $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'."); @@ -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); @@ -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); } @@ -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); } @@ -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), diff --git a/webapp/src/Service/DOMJudgeService.php b/webapp/src/Service/DOMJudgeService.php index 55c1bcbc39..f63e31ae3c 100644 --- a/webapp/src/Service/DOMJudgeService.php +++ b/webapp/src/Service/DOMJudgeService.php @@ -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) {