Skip to content

Commit

Permalink
Add explicit statement to when one of sides of the interactions ran c…
Browse files Browse the repository at this point in the history
…losed their output.
  • Loading branch information
meisterT committed Mar 17, 2024
1 parent b19eb78 commit 5d04d16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 10 additions & 0 deletions judge/runpipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "lib.error.h"
#include "lib.misc.h"

#include <cstring>
#include <chrono>
#include <fcntl.h>
#include <fstream>
Expand Down Expand Up @@ -770,6 +771,15 @@ struct state_t {
// write an extra \n at its end.
ssize_t nread = read(from.process_to_proxy, buffer, BUF_SIZE - 1);
if (nread == 0) {
auto duration = chrono::steady_clock::now() - output_file.start;
auto time = duration.count() / 1000 / 1000; // ns -> ms
int time_sec = time / 1000;
int time_millis = time % 1000;
char direction = from.index == 0 ? ']' : '[';
char eofbuf[128];
sprintf(eofbuf, "[%3d.%03ds/%ld]%c", time_sec, time_millis, 0LL, direction);
write_all(output_file.output_file, eofbuf, strlen(eofbuf));

warning(0, "EOF from process #%ld", from.index);
// The process closed stdout, we need to close the pipe's file
// descriptors as well.
Expand Down
20 changes: 12 additions & 8 deletions webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,15 +740,19 @@ public function interactiveLog(string $log, bool $forTeam = false): string
if ($idx >= strlen($log)) {
break;
}
$is_validator = $log[$idx] == '>';
$content = substr($log, $idx + 3, $len);
if (empty($content)) {
break;
$is_validator = $log[$idx] == '>' || $log[$idx] == ']';
if ($log[$idx] == ']' || $log[$idx] == '[') {
$content = '<td style="font-style:italic; color: dimgrey;">EOF from program</td>';
} else {
$content = substr($log, $idx + 3, $len);
if (empty($content)) {
break;
}
$content = htmlspecialchars($content);
$content = '<td class="output_text">'
. str_replace("\n", "\u{21B5}<br/>", $content)
. '</td>';
}
$content = htmlspecialchars($content);
$content = '<td class="output_text">'
. str_replace("\n", "\u{21B5}<br/>", $content)
. '</td>';
$idx += $len + 4;
$team = $is_validator ? '<td/>' : $content;
$validator = $is_validator ? $content : '<td/>';
Expand Down

0 comments on commit 5d04d16

Please sign in to comment.