From c0876672faa194ddd9f02c7c8b154793c2a89ad1 Mon Sep 17 00:00:00 2001 From: Joe Turgeon Date: Sun, 23 Oct 2016 10:54:50 -0500 Subject: [PATCH 1/2] Fixing floating point exception caused by metrics. Using default column width unless in a TTY. --- src/metrics.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index 32fc4ba05..8c4de496a 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -192,16 +192,22 @@ void ThreadShowMetricsScreen() while (true) { // Number of lines that are always displayed int lines = 1; + int cols = 80; // Get current window size - struct winsize w; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + if (isatty(STDOUT_FILENO)) { + struct winsize w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + if (w.ws_col) { + cols = w.ws_col; + } + } // Erase below current position std::cout << "\e[J"; - lines += printMetrics(w.ws_col, nStart, mining); - lines += printMessageBox(w.ws_col); + lines += printMetrics(cols, nStart, mining); + lines += printMessageBox(cols); lines += printInitMessage(); // Explain how to exit From 1da44b346cf02b4a77c830ad79b73c9f485e14ea Mon Sep 17 00:00:00 2001 From: Joe Turgeon Date: Sun, 23 Oct 2016 21:23:56 -0500 Subject: [PATCH 2/2] Adding handling for ioctl failure. Updates from code review in PR #1615. --- src/metrics.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index 8c4de496a..a5480838e 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -13,6 +13,7 @@ #include #include #include +#include AtomicCounter transactionsValidated; AtomicCounter ehSolverRuns; @@ -196,11 +197,11 @@ void ThreadShowMetricsScreen() // Get current window size if (isatty(STDOUT_FILENO)) { - struct winsize w; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); - if (w.ws_col) { - cols = w.ws_col; - } + struct winsize w; + w.ws_col = 0; + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1 && w.ws_col != 0) { + cols = w.ws_col; + } } // Erase below current position