aboutsummaryrefslogtreecommitdiffstats
path: root/CRT.c
diff options
context:
space:
mode:
Diffstat (limited to 'CRT.c')
-rw-r--r--CRT.c335
1 files changed, 266 insertions, 69 deletions
diff --git a/CRT.c b/CRT.c
index 85f2962..2533f61 100644
--- a/CRT.c
+++ b/CRT.c
@@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "CRT.h"
#include <errno.h>
+#include <fcntl.h>
#include <langinfo.h>
#include <signal.h>
#include <stdio.h>
@@ -24,6 +25,10 @@ in the source distribution for its full text.
#include <execinfo.h>
#endif
+#if !defined(NDEBUG) && defined(HAVE_MEMFD_CREATE)
+#include <sys/mman.h>
+#endif
+
#define ColorIndex(i,j) ((7-(i))*8+(j))
@@ -76,6 +81,7 @@ bool CRT_utf8 = false;
const char* const* CRT_treeStr = CRT_treeStrAscii;
+static const Settings* CRT_crashSettings;
static const int* CRT_delay;
const char* CRT_degreeSign;
@@ -114,6 +120,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[UPTIME] = A_BOLD | ColorPair(Cyan, Black),
[BATTERY] = A_BOLD | ColorPair(Cyan, Black),
[LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black),
+ [METER_SHADOW] = A_BOLD | ColorPairGrayBlack,
[METER_TEXT] = ColorPair(Cyan, Black),
[METER_VALUE] = A_BOLD | ColorPair(Cyan, Black),
[METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black),
@@ -131,7 +138,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_GIGABYTES] = ColorPair(Green, Black),
[PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Black),
[PROCESS_TREE] = ColorPair(Cyan, Black),
- [PROCESS_R_STATE] = ColorPair(Green, Black),
+ [PROCESS_RUN_STATE] = ColorPair(Green, Black),
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black),
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black),
[PROCESS_LOW_PRIORITY] = ColorPair(Green, Black),
@@ -144,17 +151,24 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[BAR_BORDER] = A_BOLD,
[BAR_SHADOW] = A_BOLD | ColorPairGrayBlack,
[SWAP] = ColorPair(Red, Black),
+ [SWAP_CACHE] = ColorPair(Yellow, Black),
[GRAPH_1] = A_BOLD | ColorPair(Cyan, Black),
[GRAPH_2] = ColorPair(Cyan, Black),
[MEMORY_USED] = ColorPair(Green, Black),
[MEMORY_BUFFERS] = ColorPair(Blue, Black),
[MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black),
[MEMORY_CACHE] = ColorPair(Yellow, Black),
+ [MEMORY_SHARED] = ColorPair(Magenta, Black),
+ [HUGEPAGE_1] = ColorPair(Green, Black),
+ [HUGEPAGE_2] = ColorPair(Yellow, Black),
+ [HUGEPAGE_3] = ColorPair(Red, Black),
+ [HUGEPAGE_4] = ColorPair(Blue, Black),
[LOAD_AVERAGE_FIFTEEN] = ColorPair(Cyan, Black),
[LOAD_AVERAGE_FIVE] = A_BOLD | ColorPair(Cyan, Black),
[LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White, Black),
[LOAD] = A_BOLD,
[HELP_BOLD] = A_BOLD | ColorPair(Cyan, Black),
+ [HELP_SHADOW] = A_BOLD | ColorPairGrayBlack,
[CLOCK] = A_BOLD,
[DATE] = A_BOLD,
[DATETIME] = A_BOLD,
@@ -182,6 +196,15 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[ZFS_COMPRESSED] = ColorPair(Blue, Black),
[ZFS_RATIO] = ColorPair(Magenta, Black),
[ZRAM] = ColorPair(Yellow, Black),
+ [DYNAMIC_GRAY] = ColorPairGrayBlack,
+ [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack,
+ [DYNAMIC_RED] = ColorPair(Red, Black),
+ [DYNAMIC_GREEN] = ColorPair(Green, Black),
+ [DYNAMIC_BLUE] = ColorPair(Blue, Black),
+ [DYNAMIC_CYAN] = ColorPair(Cyan, Black),
+ [DYNAMIC_MAGENTA] = ColorPair(Magenta, Black),
+ [DYNAMIC_YELLOW] = ColorPair(Yellow, Black),
+ [DYNAMIC_WHITE] = ColorPair(White, Black),
},
[COLORSCHEME_MONOCHROME] = {
[RESET_COLOR] = A_NORMAL,
@@ -199,6 +222,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[UPTIME] = A_BOLD,
[BATTERY] = A_BOLD,
[LARGE_NUMBER] = A_BOLD,
+ [METER_SHADOW] = A_DIM,
[METER_TEXT] = A_NORMAL,
[METER_VALUE] = A_BOLD,
[METER_VALUE_ERROR] = A_BOLD,
@@ -216,7 +240,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_GIGABYTES] = A_BOLD,
[PROCESS_BASENAME] = A_BOLD,
[PROCESS_TREE] = A_BOLD,
- [PROCESS_R_STATE] = A_BOLD,
+ [PROCESS_RUN_STATE] = A_BOLD,
[PROCESS_D_STATE] = A_BOLD,
[PROCESS_HIGH_PRIORITY] = A_BOLD,
[PROCESS_LOW_PRIORITY] = A_DIM,
@@ -229,17 +253,24 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[BAR_BORDER] = A_BOLD,
[BAR_SHADOW] = A_DIM,
[SWAP] = A_BOLD,
+ [SWAP_CACHE] = A_NORMAL,
[GRAPH_1] = A_BOLD,
[GRAPH_2] = A_NORMAL,
[MEMORY_USED] = A_BOLD,
[MEMORY_BUFFERS] = A_NORMAL,
[MEMORY_BUFFERS_TEXT] = A_NORMAL,
[MEMORY_CACHE] = A_NORMAL,
+ [MEMORY_SHARED] = A_NORMAL,
+ [HUGEPAGE_1] = A_BOLD,
+ [HUGEPAGE_2] = A_NORMAL,
+ [HUGEPAGE_3] = A_REVERSE | A_BOLD,
+ [HUGEPAGE_4] = A_REVERSE,
[LOAD_AVERAGE_FIFTEEN] = A_DIM,
[LOAD_AVERAGE_FIVE] = A_NORMAL,
[LOAD_AVERAGE_ONE] = A_BOLD,
[LOAD] = A_BOLD,
[HELP_BOLD] = A_BOLD,
+ [HELP_SHADOW] = A_DIM,
[CLOCK] = A_BOLD,
[DATE] = A_BOLD,
[DATETIME] = A_BOLD,
@@ -267,6 +298,15 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[ZFS_COMPRESSED] = A_BOLD,
[ZFS_RATIO] = A_BOLD,
[ZRAM] = A_NORMAL,
+ [DYNAMIC_GRAY] = A_DIM,
+ [DYNAMIC_DARKGRAY] = A_DIM,
+ [DYNAMIC_RED] = A_BOLD,
+ [DYNAMIC_GREEN] = A_NORMAL,
+ [DYNAMIC_BLUE] = A_NORMAL,
+ [DYNAMIC_CYAN] = A_BOLD,
+ [DYNAMIC_MAGENTA] = A_NORMAL,
+ [DYNAMIC_YELLOW] = A_NORMAL,
+ [DYNAMIC_WHITE] = A_BOLD,
},
[COLORSCHEME_BLACKONWHITE] = {
[RESET_COLOR] = ColorPair(Black, White),
@@ -284,6 +324,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[UPTIME] = ColorPair(Yellow, White),
[BATTERY] = ColorPair(Yellow, White),
[LARGE_NUMBER] = ColorPair(Red, White),
+ [METER_SHADOW] = ColorPair(Blue, White),
[METER_TEXT] = ColorPair(Blue, White),
[METER_VALUE] = ColorPair(Black, White),
[METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, White),
@@ -301,7 +342,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_GIGABYTES] = ColorPair(Green, White),
[PROCESS_BASENAME] = ColorPair(Blue, White),
[PROCESS_TREE] = ColorPair(Green, White),
- [PROCESS_R_STATE] = ColorPair(Green, White),
+ [PROCESS_RUN_STATE] = ColorPair(Green, White),
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, White),
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, White),
[PROCESS_LOW_PRIORITY] = ColorPair(Green, White),
@@ -314,17 +355,24 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[BAR_BORDER] = ColorPair(Blue, White),
[BAR_SHADOW] = ColorPair(Black, White),
[SWAP] = ColorPair(Red, White),
+ [SWAP_CACHE] = ColorPair(Yellow, White),
[GRAPH_1] = A_BOLD | ColorPair(Blue, White),
[GRAPH_2] = ColorPair(Blue, White),
[MEMORY_USED] = ColorPair(Green, White),
[MEMORY_BUFFERS] = ColorPair(Cyan, White),
[MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, White),
[MEMORY_CACHE] = ColorPair(Yellow, White),
+ [MEMORY_SHARED] = ColorPair(Magenta, White),
+ [HUGEPAGE_1] = ColorPair(Green, White),
+ [HUGEPAGE_2] = ColorPair(Yellow, White),
+ [HUGEPAGE_3] = ColorPair(Red, White),
+ [HUGEPAGE_4] = ColorPair(Blue, White),
[LOAD_AVERAGE_FIFTEEN] = ColorPair(Black, White),
[LOAD_AVERAGE_FIVE] = ColorPair(Black, White),
[LOAD_AVERAGE_ONE] = ColorPair(Black, White),
[LOAD] = ColorPair(Black, White),
[HELP_BOLD] = ColorPair(Blue, White),
+ [HELP_SHADOW] = A_BOLD | ColorPair(Black, White),
[CLOCK] = ColorPair(Black, White),
[DATE] = ColorPair(Black, White),
[DATETIME] = ColorPair(Black, White),
@@ -351,7 +399,16 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[ZFS_OTHER] = ColorPair(Magenta, White),
[ZFS_COMPRESSED] = ColorPair(Cyan, White),
[ZFS_RATIO] = ColorPair(Magenta, White),
- [ZRAM] = ColorPair(Yellow, White)
+ [ZRAM] = ColorPair(Yellow, White),
+ [DYNAMIC_GRAY] = ColorPair(Black, White),
+ [DYNAMIC_DARKGRAY] = A_BOLD | ColorPair(Black, White),
+ [DYNAMIC_RED] = ColorPair(Red, White),
+ [DYNAMIC_GREEN] = ColorPair(Green, White),
+ [DYNAMIC_BLUE] = ColorPair(Blue, White),
+ [DYNAMIC_CYAN] = ColorPair(Yellow, White),
+ [DYNAMIC_MAGENTA] = ColorPair(Magenta, White),
+ [DYNAMIC_YELLOW] = ColorPair(Yellow, White),
+ [DYNAMIC_WHITE] = A_BOLD | ColorPair(Black, White),
},
[COLORSCHEME_LIGHTTERMINAL] = {
[RESET_COLOR] = ColorPair(Black, Black),
@@ -369,6 +426,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[UPTIME] = ColorPair(Yellow, Black),
[BATTERY] = ColorPair(Yellow, Black),
[LARGE_NUMBER] = ColorPair(Red, Black),
+ [METER_SHADOW] = A_BOLD | ColorPairGrayBlack,
[METER_TEXT] = ColorPair(Blue, Black),
[METER_VALUE] = ColorPair(Black, Black),
[METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black),
@@ -386,7 +444,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_GIGABYTES] = ColorPair(Green, Black),
[PROCESS_BASENAME] = ColorPair(Green, Black),
[PROCESS_TREE] = ColorPair(Blue, Black),
- [PROCESS_R_STATE] = ColorPair(Green, Black),
+ [PROCESS_RUN_STATE] = ColorPair(Green, Black),
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black),
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black),
[PROCESS_LOW_PRIORITY] = ColorPair(Green, Black),
@@ -399,17 +457,24 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[BAR_BORDER] = ColorPair(Blue, Black),
[BAR_SHADOW] = ColorPairGrayBlack,
[SWAP] = ColorPair(Red, Black),
+ [SWAP_CACHE] = ColorPair(Yellow, Black),
[GRAPH_1] = A_BOLD | ColorPair(Cyan, Black),
[GRAPH_2] = ColorPair(Cyan, Black),
[MEMORY_USED] = ColorPair(Green, Black),
[MEMORY_BUFFERS] = ColorPair(Cyan, Black),
[MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, Black),
[MEMORY_CACHE] = ColorPair(Yellow, Black),
+ [MEMORY_SHARED] = ColorPair(Magenta, Black),
+ [HUGEPAGE_1] = ColorPair(Green, Black),
+ [HUGEPAGE_2] = ColorPair(Yellow, Black),
+ [HUGEPAGE_3] = ColorPair(Red, Black),
+ [HUGEPAGE_4] = ColorPair(Blue, Black),
[LOAD_AVERAGE_FIFTEEN] = ColorPair(Black, Black),
[LOAD_AVERAGE_FIVE] = ColorPair(Black, Black),
[LOAD_AVERAGE_ONE] = ColorPair(Black, Black),
[LOAD] = ColorPairWhiteDefault,
[HELP_BOLD] = ColorPair(Blue, Black),
+ [HELP_SHADOW] = A_BOLD | ColorPairGrayBlack,
[CLOCK] = ColorPairWhiteDefault,
[DATE] = ColorPairWhiteDefault,
[DATETIME] = ColorPairWhiteDefault,
@@ -437,6 +502,15 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[ZFS_COMPRESSED] = ColorPair(Cyan, Black),
[ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Black),
[ZRAM] = ColorPair(Yellow, Black),
+ [DYNAMIC_GRAY] = ColorPairGrayBlack,
+ [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack,
+ [DYNAMIC_RED] = ColorPair(Red, Black),
+ [DYNAMIC_GREEN] = ColorPair(Green, Black),
+ [DYNAMIC_BLUE] = ColorPair(Blue, Black),
+ [DYNAMIC_CYAN] = ColorPair(Cyan, Black),
+ [DYNAMIC_MAGENTA] = ColorPair(Magenta, Black),
+ [DYNAMIC_YELLOW] = ColorPair(Yellow, Black),
+ [DYNAMIC_WHITE] = ColorPairWhiteDefault,
},
[COLORSCHEME_MIDNIGHT] = {
[RESET_COLOR] = ColorPair(White, Blue),
@@ -454,6 +528,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[UPTIME] = A_BOLD | ColorPair(Yellow, Blue),
[BATTERY] = A_BOLD | ColorPair(Yellow, Blue),
[LARGE_NUMBER] = A_BOLD | ColorPair(Red, Blue),
+ [METER_SHADOW] = ColorPair(Cyan, Blue),
[METER_TEXT] = ColorPair(Cyan, Blue),
[METER_VALUE] = A_BOLD | ColorPair(Cyan, Blue),
[METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Blue),
@@ -471,7 +546,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_GIGABYTES] = ColorPair(Green, Blue),
[PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Blue),
[PROCESS_TREE] = ColorPair(Cyan, Blue),
- [PROCESS_R_STATE] = ColorPair(Green, Blue),
+ [PROCESS_RUN_STATE] = ColorPair(Green, Blue),
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Blue),
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, Blue),
[PROCESS_LOW_PRIORITY] = ColorPair(Green, Blue),
@@ -484,17 +559,24 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[BAR_BORDER] = A_BOLD | ColorPair(Yellow, Blue),
[BAR_SHADOW] = ColorPair(Cyan, Blue),
[SWAP] = ColorPair(Red, Blue),
+ [SWAP_CACHE] = A_BOLD | ColorPair(Yellow, Blue),
[GRAPH_1] = A_BOLD | ColorPair(Cyan, Blue),
[GRAPH_2] = ColorPair(Cyan, Blue),
[MEMORY_USED] = A_BOLD | ColorPair(Green, Blue),
[MEMORY_BUFFERS] = A_BOLD | ColorPair(Cyan, Blue),
[MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Cyan, Blue),
[MEMORY_CACHE] = A_BOLD | ColorPair(Yellow, Blue),
+ [MEMORY_SHARED] = A_BOLD | ColorPair(Magenta, Blue),
+ [HUGEPAGE_1] = A_BOLD | ColorPair(Green, Blue),
+ [HUGEPAGE_2] = A_BOLD | ColorPair(Yellow, Blue),
+ [HUGEPAGE_3] = A_BOLD | ColorPair(Red, Blue),
+ [HUGEPAGE_4] = A_BOLD | ColorPair(White, Blue),
[LOAD_AVERAGE_FIFTEEN] = A_BOLD | ColorPair(Black, Blue),
[LOAD_AVERAGE_FIVE] = A_NORMAL | ColorPair(White, Blue),
[LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White, Blue),
[LOAD] = A_BOLD | ColorPair(White, Blue),
[HELP_BOLD] = A_BOLD | ColorPair(Cyan, Blue),
+ [HELP_SHADOW] = A_BOLD | ColorPair(Black, Blue),
[CLOCK] = ColorPair(White, Blue),
[DATE] = ColorPair(White, Blue),
[DATETIME] = ColorPair(White, Blue),
@@ -522,6 +604,15 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[ZFS_COMPRESSED] = A_BOLD | ColorPair(White, Blue),
[ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Blue),
[ZRAM] = A_BOLD | ColorPair(Yellow, Blue),
+ [DYNAMIC_GRAY] = ColorPairGrayBlack,
+ [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack,
+ [DYNAMIC_RED] = ColorPair(Red, Blue),
+ [DYNAMIC_GREEN] = ColorPair(Green, Blue),
+ [DYNAMIC_BLUE] = ColorPair(Black, Blue),
+ [DYNAMIC_CYAN] = ColorPair(Cyan, Blue),
+ [DYNAMIC_MAGENTA] = ColorPair(Magenta, Blue),
+ [DYNAMIC_YELLOW] = ColorPair(Yellow, Blue),
+ [DYNAMIC_WHITE] = ColorPair(White, Blue),
},
[COLORSCHEME_BLACKNIGHT] = {
[RESET_COLOR] = ColorPair(Cyan, Black),
@@ -539,6 +630,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[UPTIME] = ColorPair(Green, Black),
[BATTERY] = ColorPair(Green, Black),
[LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black),
+ [METER_SHADOW] = A_BOLD | ColorPairGrayBlack,
[METER_TEXT] = ColorPair(Cyan, Black),
[METER_VALUE] = ColorPair(Green, Black),
[METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black),
@@ -560,7 +652,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black),
[PROCESS_COMM] = ColorPair(Magenta, Black),
[PROCESS_THREAD_COMM] = ColorPair(Yellow, Black),
- [PROCESS_R_STATE] = ColorPair(Green, Black),
+ [PROCESS_RUN_STATE] = ColorPair(Green, Black),
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black),
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black),
[PROCESS_LOW_PRIORITY] = ColorPair(Green, Black),
@@ -569,17 +661,24 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[BAR_BORDER] = A_BOLD | ColorPair(Green, Black),
[BAR_SHADOW] = ColorPair(Cyan, Black),
[SWAP] = ColorPair(Red, Black),
+ [SWAP_CACHE] = ColorPair(Yellow, Black),
[GRAPH_1] = A_BOLD | ColorPair(Green, Black),
[GRAPH_2] = ColorPair(Green, Black),
[MEMORY_USED] = ColorPair(Green, Black),
[MEMORY_BUFFERS] = ColorPair(Blue, Black),
[MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black),
[MEMORY_CACHE] = ColorPair(Yellow, Black),
+ [MEMORY_SHARED] = ColorPair(Magenta, Black),
+ [HUGEPAGE_1] = ColorPair(Green, Black),
+ [HUGEPAGE_2] = ColorPair(Yellow, Black),
+ [HUGEPAGE_3] = ColorPair(Red, Black),
+ [HUGEPAGE_4] = ColorPair(Blue, Black),
[LOAD_AVERAGE_FIFTEEN] = ColorPair(Green, Black),
[LOAD_AVERAGE_FIVE] = ColorPair(Green, Black),
[LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(Green, Black),
[LOAD] = A_BOLD,
[HELP_BOLD] = A_BOLD | ColorPair(Cyan, Black),
+ [HELP_SHADOW] = A_BOLD | ColorPairGrayBlack,
[CLOCK] = ColorPair(Green, Black),
[CHECK_BOX] = ColorPair(Green, Black),
[CHECK_MARK] = A_BOLD | ColorPair(Green, Black),
@@ -605,6 +704,15 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[ZFS_COMPRESSED] = ColorPair(Blue, Black),
[ZFS_RATIO] = ColorPair(Magenta, Black),
[ZRAM] = ColorPair(Yellow, Black),
+ [DYNAMIC_GRAY] = ColorPairGrayBlack,
+ [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack,
+ [DYNAMIC_RED] = ColorPair(Red, Black),
+ [DYNAMIC_GREEN] = ColorPair(Green, Black),
+ [DYNAMIC_BLUE] = ColorPair(Blue, Black),
+ [DYNAMIC_CYAN] = ColorPair(Cyan, Black),
+ [DYNAMIC_MAGENTA] = ColorPair(Magenta, Black),
+ [DYNAMIC_YELLOW] = ColorPair(Yellow, Black),
+ [DYNAMIC_WHITE] = ColorPair(White, Black),
},
[COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated.
};
@@ -618,53 +726,141 @@ int CRT_scrollWheelVAmount = 10;
ColorScheme CRT_colorScheme = COLORSCHEME_DEFAULT;
ATTR_NORETURN
-static void CRT_handleSIGTERM(int sgn) {
- (void) sgn;
+static void CRT_handleSIGTERM(ATTR_UNUSED int sgn) {
CRT_done();
- exit(0);
+ _exit(0);
}
-#ifdef HAVE_SETUID_ENABLED
+#ifndef NDEBUG
-static int CRT_euid = -1;
+static int stderrRedirectNewFd = -1;
+static int stderrRedirectBackupFd = -1;
-static int CRT_egid = -1;
+static int createStderrCacheFile(void) {
+#if defined(HAVE_MEMFD_CREATE)
+ return memfd_create("htop.stderr-redirect", 0);
+#elif defined(O_TMPFILE)
+ return open("/tmp", O_TMPFILE | O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
+#else
+ char tmpName[] = "htop.stderr-redirectXXXXXX";
+ mode_t curUmask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
+ int r = mkstemp(tmpName);
+ umask(curUmask);
+ if (r < 0)
+ return r;
-void CRT_dropPrivileges() {
- CRT_egid = getegid();
- CRT_euid = geteuid();
- if (setegid(getgid()) == -1) {
- CRT_fatalError("Fatal error: failed dropping group privileges");
- }
- if (seteuid(getuid()) == -1) {
- CRT_fatalError("Fatal error: failed dropping user privileges");
- }
+ (void) unlink(tmpName);
+
+ return r;
+#endif /* HAVE_MEMFD_CREATE */
}
-void CRT_restorePrivileges() {
- if (CRT_egid == -1 || CRT_euid == -1) {
- CRT_fatalError("Fatal error: internal inconsistency");
- }
- if (setegid(CRT_egid) == -1) {
- CRT_fatalError("Fatal error: failed restoring group privileges");
+static void redirectStderr(void) {
+ stderrRedirectNewFd = createStderrCacheFile();
+ if (stderrRedirectNewFd < 0) {
+ /* ignore failure */
+ return;
}
- if (seteuid(CRT_euid) == -1) {
- CRT_fatalError("Fatal error: failed restoring user privileges");
+
+ stderrRedirectBackupFd = dup(STDERR_FILENO);
+ dup2(stderrRedirectNewFd, STDERR_FILENO);
+}
+
+static void dumpStderr(void) {
+ if (stderrRedirectNewFd < 0)
+ return;
+
+ fsync(STDERR_FILENO);
+ dup2(stderrRedirectBackupFd, STDERR_FILENO);
+ close(stderrRedirectBackupFd);
+ stderrRedirectBackupFd = -1;
+ lseek(stderrRedirectNewFd, 0, SEEK_SET);
+
+ bool header = false;
+ char buffer[8192];
+ for (;;) {
+ errno = 0;
+ ssize_t res = read(stderrRedirectNewFd, buffer, sizeof(buffer));
+ if (res < 0) {
+ if (errno == EINTR)
+ continue;
+
+ break;
+ }
+
+ if (res == 0) {
+ break;
+ }
+
+ if (res > 0) {
+ if (!header) {
+ fprintf(stderr, ">>>>>>>>>> stderr output >>>>>>>>>>\n");
+ header = true;
+ }
+ (void)! write(STDERR_FILENO, buffer, res);
+ }
}
+
+ if (header)
+ fprintf(stderr, "\n<<<<<<<<<< stderr output <<<<<<<<<<\n");
+
+ close(stderrRedirectNewFd);
+ stderrRedirectNewFd = -1;
}
-#endif /* HAVE_SETUID_ENABLED */
+#else /* !NDEBUG */
+
+static void redirectStderr(void) {
+}
+
+static void dumpStderr(void) {
+}
+
+#endif /* !NDEBUG */
static struct sigaction old_sig_handler[32];
-// TODO: pass an instance of Settings instead.
+static void CRT_installSignalHandlers(void) {
+ struct sigaction act;
+ sigemptyset (&act.sa_mask);
+ act.sa_flags = (int)SA_RESETHAND | SA_NODEFER;
+ act.sa_handler = CRT_handleSIGSEGV;
+ sigaction (SIGSEGV, &act, &old_sig_handler[SIGSEGV]);
+ sigaction (SIGFPE, &act, &old_sig_handler[SIGFPE]);
+ sigaction (SIGILL, &act, &old_sig_handler[SIGILL]);
+ sigaction (SIGBUS, &act, &old_sig_handler[SIGBUS]);
+ sigaction (SIGPIPE, &act, &old_sig_handler[SIGPIPE]);
+ sigaction (SIGSYS, &act, &old_sig_handler[SIGSYS]);
+ sigaction (SIGABRT, &act, &old_sig_handler[SIGABRT]);
+
+ signal(SIGINT, CRT_handleSIGTERM);
+ signal(SIGTERM, CRT_handleSIGTERM);
+ signal(SIGQUIT, CRT_handleSIGTERM);
+}
+
+void CRT_resetSignalHandlers(void) {
+ sigaction (SIGSEGV, &old_sig_handler[SIGSEGV], NULL);
+ sigaction (SIGFPE, &old_sig_handler[SIGFPE], NULL);
+ sigaction (SIGILL, &old_sig_handler[SIGILL], NULL);
+ sigaction (SIGBUS, &old_sig_handler[SIGBUS], NULL);
+ sigaction (SIGPIPE, &old_sig_handler[SIGPIPE], NULL);
+ sigaction (SIGSYS, &old_sig_handler[SIGSYS], NULL);
+ sigaction (SIGABRT, &old_sig_handler[SIGABRT], NULL);
+
+ signal(SIGINT, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+ signal(SIGQUIT, SIG_DFL);
+}
+
+void CRT_init(const Settings* settings, bool allowUnicode) {
+ redirectStderr();
-void CRT_init(const int* delay, int colorScheme, bool allowUnicode) {
initscr();
noecho();
- CRT_delay = delay;
- CRT_colors = CRT_colorSchemes[colorScheme];
- CRT_colorScheme = colorScheme;
+ CRT_crashSettings = settings;
+ CRT_delay = &(settings->delay);
+ CRT_colors = CRT_colorSchemes[settings->colorScheme];
+ CRT_colorScheme = settings->colorScheme;
for (int i = 0; i < LAST_COLORELEMENT; i++) {
unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][i];
@@ -675,7 +871,9 @@ void CRT_init(const int* delay, int colorScheme, bool allowUnicode) {
nonl();
intrflush(stdscr, false);
keypad(stdscr, true);
+#ifdef HAVE_GETMOUSE
mouseinterval(0);
+#endif
curs_set(0);
if (has_colors()) {
@@ -690,6 +888,10 @@ void CRT_init(const int* delay, int colorScheme, bool allowUnicode) {
}
if (termType && (String_startsWith(termType, "xterm") || String_eq(termType, "vt220"))) {
+#ifdef HTOP_NETBSD
+#define define_key(s_, k_) define_key((char*)s_, k_)
+IGNORE_WCASTQUAL_BEGIN
+#endif
define_key("\033[H", KEY_HOME);
define_key("\033[F", KEY_END);
define_key("\033[7~", KEY_HOME);
@@ -698,6 +900,7 @@ void CRT_init(const int* delay, int colorScheme, bool allowUnicode) {
define_key("\033OQ", KEY_F(2));
define_key("\033OR", KEY_F(3));
define_key("\033OS", KEY_F(4));
+ define_key("\033O2R", KEY_F(15));
define_key("\033[11~", KEY_F(1));
define_key("\033[12~", KEY_F(2));
define_key("\033[13~", KEY_F(3));
@@ -709,22 +912,13 @@ void CRT_init(const int* delay, int colorScheme, bool allowUnicode) {
sequence[1] = c;
define_key(sequence, KEY_ALT('A' + (c - 'a')));
}
+#ifdef HTOP_NETBSD
+IGNORE_WCASTQUAL_END
+#undef define_key
+#endif
}
- struct sigaction act;
- sigemptyset (&act.sa_mask);
- act.sa_flags = (int)SA_RESETHAND | SA_NODEFER;
- act.sa_handler = CRT_handleSIGSEGV;
- sigaction (SIGSEGV, &act, &old_sig_handler[SIGSEGV]);
- sigaction (SIGFPE, &act, &old_sig_handler[SIGFPE]);
- sigaction (SIGILL, &act, &old_sig_handler[SIGILL]);
- sigaction (SIGBUS, &act, &old_sig_handler[SIGBUS]);
- sigaction (SIGPIPE, &act, &old_sig_handler[SIGPIPE]);
- sigaction (SIGSYS, &act, &old_sig_handler[SIGSYS]);
- sigaction (SIGABRT, &act, &old_sig_handler[SIGABRT]);
-
- signal(SIGTERM, CRT_handleSIGTERM);
- signal(SIGQUIT, CRT_handleSIGTERM);
+ CRT_installSignalHandlers();
use_default_colors();
if (!has_colors())
@@ -747,11 +941,13 @@ void CRT_init(const int* delay, int colorScheme, bool allowUnicode) {
#endif
CRT_treeStrAscii;
+#ifdef HAVE_GETMOUSE
#if NCURSES_MOUSE_VERSION > 1
mousemask(BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL);
#else
mousemask(BUTTON1_RELEASED, NULL);
#endif
+#endif
CRT_degreeSign = initDegreeSign();
}
@@ -759,6 +955,8 @@ void CRT_init(const int* delay, int colorScheme, bool allowUnicode) {
void CRT_done() {
curs_set(1);
endwin();
+
+ dumpStderr();
}
void CRT_fatalError(const char* note) {
@@ -818,15 +1016,14 @@ void CRT_handleSIGSEGV(int signal) {
"============================\n"
"Please check at https://htop.dev/issues whether this issue has already been reported.\n"
"If no similar issue has been reported before, please create a new issue with the following information:\n"
- "\n"
- "- Your htop version (htop --version)\n"
- "- Your OS and kernel version (uname -a)\n"
- "- Your distribution and release (lsb_release -a)\n"
- "- Likely steps to reproduce (How did it happened?)\n"
+ " - Your "PACKAGE" version: '"VERSION"'\n"
+ " - Your OS and kernel version (uname -a)\n"
+ " - Your distribution and release (lsb_release -a)\n"
+ " - Likely steps to reproduce (How did it happen?)\n"
);
#ifdef HAVE_EXECINFO_H
- fprintf(stderr, "- Backtrace of the issue (see below)\n");
+ fprintf(stderr, " - Backtrace of the issue (see below)\n");
#endif
fprintf(stderr,
@@ -845,46 +1042,46 @@ void CRT_handleSIGSEGV(int signal) {
signal, signal_str
);
+ fprintf(stderr,
+ "Setting information:\n"
+ "--------------------\n");
+ Settings_write(CRT_crashSettings, true);
+ fprintf(stderr, "\n\n");
+
#ifdef HAVE_EXECINFO_H
fprintf(stderr,
"Backtrace information:\n"
"----------------------\n"
- "The following function calls were active when the issue was detected:\n"
- "---\n"
);
- void *backtraceArray[256];
+ void* backtraceArray[256];
size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray));
- backtrace_symbols_fd(backtraceArray, size, 2);
+ backtrace_symbols_fd(backtraceArray, size, STDERR_FILENO);
fprintf(stderr,
- "---\n"
"\n"
- "To make the above information more practical to work with,\n"
- "you should provide a disassembly of your binary.\n"
+ "To make the above information more practical to work with, "
+ "please also provide a disassembly of your "PACKAGE" binary. "
"This can usually be done by running the following command:\n"
"\n"
);
#ifdef HTOP_DARWIN
- fprintf(stderr, " otool -tvV `which htop` > ~/htop.otool\n");
+ fprintf(stderr, " otool -tvV `which "PACKAGE"` > ~/htop.otool\n");
#else
- fprintf(stderr, " objdump -d -S -w `which htop` > ~/htop.objdump\n");
+ fprintf(stderr, " objdump -d -S -w `which "PACKAGE"` > ~/htop.objdump\n");
#endif
fprintf(stderr,
"\n"
"Please include the generated file in your report.\n"
- "\n"
);
#endif
fprintf(stderr,
"Running this program with debug symbols or inside a debugger may provide further insights.\n"
"\n"
- "Thank you for helping to improve htop!\n"
- "\n"
- "htop " VERSION " aborting.\n"
+ "Thank you for helping to improve "PACKAGE"!\n"
"\n"
);

© 2014-2024 Faster IT GmbH | imprint | privacy policy