Skip to content

Commit 1885c3f

Browse files
Michael Vasseurvmcj
authored andcommitted
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.
1 parent 0c9c8a8 commit 1885c3f

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

judge/judgedaemon.main.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,21 @@ function fetch_executable_internal(
328328
$hash
329329
]);
330330
global $langexts;
331+
global $myhost;
331332
$execdeploypath = $execdir . '/.deployed';
332333
$execbuilddir = $execdir . '/build';
333334
$execbuildpath = $execbuilddir . '/build';
334335
$execrunpath = $execbuilddir . '/run';
335336
$execrunjurypath = $execbuilddir . '/runjury';
336337
if (!is_dir($execdir) || !file_exists($execdeploypath) ||
337338
($combined_run_compare && file_get_contents(LIBJUDGEDIR . '/run-interactive.sh')!==file_get_contents($execrunpath))) {
338-
system('rm -rf ' . dj_escapeshellarg($execdir) . ' ' . dj_escapeshellarg($execbuilddir));
339+
system('rm -rf ' . dj_escapeshellarg($execdir) . ' ' . dj_escapeshellarg($execbuilddir), $retval);
340+
if ($retval !== 0) {
341+
disable('judgehost', 'hostname', $myhost, "Deleting '$execdir' or '$execbuilddir' was unsuccessful.");
342+
}
339343
system('mkdir -p ' . dj_escapeshellarg($execbuilddir), $retval);
340344
if ($retval !== 0) {
341-
error("Could not create directory '$execbuilddir'");
345+
disable('judgehost', 'hostname', $myhost, "Could not create directory '$execbuilddir'");
342346
}
343347

344348
logmsg(LOG_INFO, " 💾 Fetching new executable '$type/$execid' with hash '$hash'.");
@@ -387,7 +391,7 @@ function fetch_executable_internal(
387391
$unescapedSource = "";
388392
foreach ($langexts as $lang => $langext) {
389393
if (($handle = opendir($execbuilddir)) === false) {
390-
error("Could not open $execbuilddir");
394+
disable('judgehost', 'hostname', $myhost, "Could not open $execbuilddir");
391395
}
392396
while (($file = readdir($handle)) !== false) {
393397
$ext = pathinfo($file, PATHINFO_EXTENSION);
@@ -432,7 +436,7 @@ function fetch_executable_internal(
432436
break;
433437
}
434438
if (file_put_contents($execbuildpath, $buildscript) === false) {
435-
error("Could not write file 'build' in $execbuilddir");
439+
disable('judgehost', 'hostname', $myhost, "Could not write file 'build' in $execbuilddir");
436440
}
437441
chmod($execbuildpath, 0755);
438442
}
@@ -464,10 +468,10 @@ function fetch_executable_internal(
464468
# team submission and runjury programs and connects their pipes.
465469
$runscript = file_get_contents(LIBJUDGEDIR . '/run-interactive.sh');
466470
if (rename($execrunpath, $execrunjurypath) === false) {
467-
error("Could not move file 'run' to 'runjury' in $execbuilddir");
471+
disable('judgehost', 'hostname', $myhost, "Could not move file 'run' to 'runjury' in $execbuilddir");
468472
}
469473
if (file_put_contents($execrunpath, $runscript) === false) {
470-
error("Could not write file 'run' in $execbuilddir");
474+
disable('judgehost', 'hostname', $myhost, "Could not write file 'run' in $execbuilddir");
471475
}
472476
chmod($execrunpath, 0755);
473477
}
@@ -831,21 +835,20 @@ function fetch_executable_internal(
831835
// Full debug package requested.
832836
$run_config = dj_json_decode($judgeTask['run_config']);
833837
$tmpfile = tempnam(TMPDIR, 'full_debug_package_');
834-
[$runpath, $error] = fetch_executable_internal(
838+
[$runpath, $error] = fetch_executable(
835839
$workdirpath,
836840
'debug',
837841
$judgeTask['run_script_id'],
838-
$run_config['hash']
842+
$run_config['hash'],
843+
$judgeTask['judgetaskid']
839844
);
840-
if (isset($error)) {
841-
// FIXME
842-
continue;
843-
}
844845

845846
$debug_cmd = implode(' ', array_map('dj_escapeshellarg',
846847
[$runpath, $workdir, $tmpfile]));
847848
system($debug_cmd, $retval);
848-
// FIXME: check retval
849+
if ($retval !== 0) {
850+
disable('run_script', 'run_script_id', $judgeTask['run_script_id'], "Running '$runpath' failed.");
851+
}
849852

850853
request(
851854
sprintf('judgehosts/add-debug-info/%s/%s', urlencode($myhost),

webapp/src/Service/DOMJudgeService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ public function setInternalError(array $disabled, ?Contest $contest, ?bool $enab
605605
$contestProblem->setAllowJudge($enabled);
606606
}
607607
}
608+
// FIXME: Also disable debug scripts
608609
$this->em->flush();
609610
if ($enabled) {
610611
foreach ($executable->getLanguages() as $language) {

0 commit comments

Comments
 (0)