From 1c1c88a417ea4cb4918f59e556a2aa6e117872be Mon Sep 17 00:00:00 2001 From: Jonas Schroeder Date: Mon, 20 Sep 2021 15:27:22 +0000 Subject: [PATCH] dont respond to terminal resize when output is redirected Signed-off-by: Jonas Schroeder --- common/lib/terminal.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/common/lib/terminal.cpp b/common/lib/terminal.cpp index 93cd08bc9..de22af879 100644 --- a/common/lib/terminal.cpp +++ b/common/lib/terminal.cpp @@ -37,11 +37,11 @@ Terminal::Terminal() window.ws_row = 0; window.ws_col = 0; - isTty = isatty(fileno(stdin)); + isTty = isatty(STDERR_FILENO); + + Logger logger = logging.get("terminal"); if (isTty) { - Logger logger = logging.get("terminal"); - struct sigaction sa_resize; sa_resize.sa_flags = SA_SIGINFO; sa_resize.sa_sigaction = resize; @@ -56,6 +56,8 @@ Terminal::Terminal() ret = ioctl(STDERR_FILENO, TIOCGWINSZ, &window); if (ret) logger->warn("Failed to get terminal dimensions"); + } else { + logger->info("stderr is not associated with a terminal! Using fallback values for window size..."); } /* Fallback if for some reason we can not determine a prober window size */ @@ -68,13 +70,16 @@ Terminal::Terminal() void Terminal::resize(int, siginfo_t *, void *) { + if (!current) + current = new Terminal(); + + Logger logger = logging.get("terminal"); + int ret; ret = ioctl(STDERR_FILENO, TIOCGWINSZ, ¤t->window); if (ret) throw SystemError("Failed to get terminal dimensions"); - Logger logger = logging.get("terminal"); - logger->debug("New terminal size: {}x{}", current->window.ws_row, current->window.ws_col); };