From d8ae89825c852d6bc7e22600cf4a7fcc2d4c20b8 Mon Sep 17 00:00:00 2001 From: nobounce Date: Fri, 22 Sep 2023 20:58:21 +0200 Subject: [PATCH] Try get terminal size of "/dev/tty" of stdout fails LLDB does not set the terminal sizes for stdout so try to get them for "/dev/tty". This helps to get back traces on arm64 where gdb is not supported --- src/btop_tools.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/btop_tools.cpp b/src/btop_tools.cpp index f6be1741d..2b8f5aa71 100644 --- a/src/btop_tools.cpp +++ b/src/btop_tools.cpp @@ -26,9 +26,10 @@ tab-size = 4 #include #include -#include -#include +#include #include +#include +#include #include "robin_hood.h" #include "widechar_width.hpp" @@ -86,12 +87,23 @@ namespace Term { } bool refresh(bool only_check) { - struct winsize w; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) < 0) return false; - if (width != w.ws_col or height != w.ws_row) { + struct winsize wsize {}; + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &wsize) < 0 || wsize.ws_col == 0 || wsize.ws_row == 0) { + Logger::error(R"(Couldn't determine terminal size of "STDOUT_FILENO"!)"); + auto dev_tty = open("/dev/tty", O_RDONLY); + if (dev_tty != -1) { + ioctl(dev_tty, TIOCGWINSZ, &wsize); + close(dev_tty); + } + else { + Logger::error(R"(Couldn't determine terminal size of "/dev/tty"!)"); + return false; + } + } + if (width != wsize.ws_col or height != wsize.ws_row) { if (not only_check) { - width = w.ws_col; - height = w.ws_row; + width = wsize.ws_col; + height = wsize.ws_row; } return true; }