Skip to content

Commit 5d04d16

Browse files
committed
Add explicit statement to when one of sides of the interactions ran closed their output.
1 parent b19eb78 commit 5d04d16

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

judge/runpipe.cc

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "lib.error.h"
6161
#include "lib.misc.h"
6262

63+
#include <cstring>
6364
#include <chrono>
6465
#include <fcntl.h>
6566
#include <fstream>
@@ -770,6 +771,15 @@ struct state_t {
770771
// write an extra \n at its end.
771772
ssize_t nread = read(from.process_to_proxy, buffer, BUF_SIZE - 1);
772773
if (nread == 0) {
774+
auto duration = chrono::steady_clock::now() - output_file.start;
775+
auto time = duration.count() / 1000 / 1000; // ns -> ms
776+
int time_sec = time / 1000;
777+
int time_millis = time % 1000;
778+
char direction = from.index == 0 ? ']' : '[';
779+
char eofbuf[128];
780+
sprintf(eofbuf, "[%3d.%03ds/%ld]%c", time_sec, time_millis, 0LL, direction);
781+
write_all(output_file.output_file, eofbuf, strlen(eofbuf));
782+
773783
warning(0, "EOF from process #%ld", from.index);
774784
// The process closed stdout, we need to close the pipe's file
775785
// descriptors as well.

webapp/src/Twig/TwigExtension.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -740,15 +740,19 @@ public function interactiveLog(string $log, bool $forTeam = false): string
740740
if ($idx >= strlen($log)) {
741741
break;
742742
}
743-
$is_validator = $log[$idx] == '>';
744-
$content = substr($log, $idx + 3, $len);
745-
if (empty($content)) {
746-
break;
743+
$is_validator = $log[$idx] == '>' || $log[$idx] == ']';
744+
if ($log[$idx] == ']' || $log[$idx] == '[') {
745+
$content = '<td style="font-style:italic; color: dimgrey;">EOF from program</td>';
746+
} else {
747+
$content = substr($log, $idx + 3, $len);
748+
if (empty($content)) {
749+
break;
750+
}
751+
$content = htmlspecialchars($content);
752+
$content = '<td class="output_text">'
753+
. str_replace("\n", "\u{21B5}<br/>", $content)
754+
. '</td>';
747755
}
748-
$content = htmlspecialchars($content);
749-
$content = '<td class="output_text">'
750-
. str_replace("\n", "\u{21B5}<br/>", $content)
751-
. '</td>';
752756
$idx += $len + 4;
753757
$team = $is_validator ? '<td/>' : $content;
754758
$validator = $is_validator ? $content : '<td/>';

0 commit comments

Comments
 (0)