handle rare shell i/o error

This commit is contained in:
Martin Michelsen
2024-07-10 19:48:51 -07:00
parent 55f1869125
commit 90efde7aa9
+15 -1
View File
@@ -82,7 +82,21 @@ void ServerShell::thread_fn() {
for (;;) {
fprintf(stdout, "newserv> ");
fflush(stdout);
string command = fgets(stdin);
string command;
uint64_t read_start_usecs = now();
try {
command = fgets(stdin);
} catch (const io_error& e) {
// Cygwin sometimes causes fgets() to fail with errno -1 when the
// terminal window is resized. We ignore these events unless the read
// failed immediately (which probably means it would fail again if we
// retried immediately).
if (now() - read_start_usecs < 1000000 || e.error != -1) {
throw;
}
log_warning("I/O error reading from terminal: %s (%d)", e.what(), e.error);
continue;
}
// If command is empty (not even a \n), it's probably EOF
if (command.empty()) {