From 8b84788d089cbbf46e0a14f69db1f31b9e79e21d Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 2 Oct 2022 00:38:41 +0200 Subject: [PATCH] Fix error --- src/Client/ClientBase.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 566ee49fba3..936456c4c34 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -104,6 +104,7 @@ namespace ErrorCodes extern const int CANNOT_SET_SIGNAL_HANDLER; extern const int UNRECOGNIZED_ARGUMENTS; extern const int LOGICAL_ERROR; + extern const int CANNOT_OPEN_FILE; } } @@ -657,9 +658,22 @@ void ClientBase::initTtyBuffer() if (!ec && exists(tty) && is_character_file(tty) && (tty.permissions() & std::filesystem::perms::others_write) != std::filesystem::perms::none) { - tty_buf = std::make_unique(tty_file_name, buf_size); + try + { + tty_buf = std::make_unique(tty_file_name, buf_size); + return; + } + catch (const Exception & e) + { + if (e.code() != ErrorCodes::CANNOT_OPEN_FILE) + throw; + + /// It is normal if file exists, indicated as writeable but still cannot be opened. + /// Fallback to other options. + } } - else if (stderr_is_a_tty) + + if (stderr_is_a_tty) { tty_buf = std::make_unique(STDERR_FILENO, buf_size); }