htop/CRT.h

190 lines
3.3 KiB
C
Raw Permalink Normal View History

2006-03-04 18:16:49 +00:00
#ifndef HEADER_CRT
#define HEADER_CRT
/*
htop - CRT.h
2011-05-26 16:35:07 +00:00
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
2006-03-04 18:16:49 +00:00
in the source distribution for its full text.
*/
#include "config.h"
#include <stdbool.h>
#include "Macros.h"
#include "ProvideCurses.h"
2021-01-27 16:14:15 +00:00
#include "Settings.h"
typedef enum TreeStr_ {
TREE_STR_VERT,
TREE_STR_RTEE,
TREE_STR_BEND,
TREE_STR_TEND,
TREE_STR_OPEN,
TREE_STR_SHUT,
TREE_STR_ASC,
TREE_STR_DESC,
2020-12-14 14:45:48 +00:00
LAST_TREE_STR
} TreeStr;
2020-12-14 14:45:48 +00:00
typedef enum ColorScheme_ {
COLORSCHEME_DEFAULT,
2020-10-05 15:24:59 +00:00
COLORSCHEME_MONOCHROME,
COLORSCHEME_BLACKONWHITE,
COLORSCHEME_LIGHTTERMINAL,
COLORSCHEME_MIDNIGHT,
COLORSCHEME_BLACKNIGHT,
COLORSCHEME_BROKENGRAY,
2020-12-14 14:45:48 +00:00
LAST_COLORSCHEME
} ColorScheme;
2006-03-04 18:16:49 +00:00
typedef enum ColorElements_ {
RESET_COLOR,
DEFAULT_COLOR,
FUNCTION_BAR,
FUNCTION_KEY,
FAILED_SEARCH,
2020-10-17 10:54:45 +00:00
FAILED_READ,
2020-10-05 13:14:54 +00:00
PAUSED,
2006-03-04 18:16:49 +00:00
PANEL_HEADER_FOCUS,
PANEL_HEADER_UNFOCUS,
PANEL_SELECTION_FOCUS,
PANEL_SELECTION_FOLLOW,
PANEL_SELECTION_UNFOCUS,
2006-03-04 18:16:49 +00:00
LARGE_NUMBER,
METER_SHADOW,
2006-03-04 18:16:49 +00:00
METER_TEXT,
METER_VALUE,
METER_VALUE_ERROR,
2020-10-16 17:44:53 +00:00
METER_VALUE_IOREAD,
METER_VALUE_IOWRITE,
2020-10-07 13:42:13 +00:00
METER_VALUE_NOTICE,
METER_VALUE_OK,
METER_VALUE_WARN,
2006-03-04 18:16:49 +00:00
LED_COLOR,
UPTIME,
BATTERY,
2006-03-04 18:16:49 +00:00
TASKS_RUNNING,
SWAP,
SWAP_CACHE,
2006-03-04 18:16:49 +00:00
PROCESS,
PROCESS_SHADOW,
PROCESS_TAG,
PROCESS_MEGABYTES,
PROCESS_GIGABYTES,
2006-03-04 18:16:49 +00:00
PROCESS_TREE,
PROCESS_RUN_STATE,
2014-10-14 01:30:17 +00:00
PROCESS_D_STATE,
2006-03-04 18:16:49 +00:00
PROCESS_BASENAME,
PROCESS_HIGH_PRIORITY,
PROCESS_LOW_PRIORITY,
2020-10-31 01:56:16 +00:00
PROCESS_NEW,
PROCESS_TOMB,
PROCESS_THREAD,
PROCESS_THREAD_BASENAME,
2020-10-17 10:54:45 +00:00
PROCESS_COMM,
PROCESS_THREAD_COMM,
2006-03-04 18:16:49 +00:00
BAR_BORDER,
BAR_SHADOW,
GRAPH_1,
GRAPH_2,
MEMORY_USED,
MEMORY_BUFFERS,
MEMORY_BUFFERS_TEXT,
2006-03-04 18:16:49 +00:00
MEMORY_CACHE,
MEMORY_SHARED,
HUGEPAGE_1,
HUGEPAGE_2,
HUGEPAGE_3,
HUGEPAGE_4,
2006-03-04 18:16:49 +00:00
LOAD,
LOAD_AVERAGE_FIFTEEN,
LOAD_AVERAGE_FIVE,
LOAD_AVERAGE_ONE,
CHECK_BOX,
2006-03-04 18:16:49 +00:00
CHECK_MARK,
CHECK_TEXT,
CLOCK,
DATE,
DATETIME,
HELP_BOLD,
HELP_SHADOW,
HOSTNAME,
2006-03-04 18:16:49 +00:00
CPU_NICE,
CPU_NICE_TEXT,
2006-03-04 18:16:49 +00:00
CPU_NORMAL,
2020-08-20 04:09:27 +00:00
CPU_SYSTEM,
CPU_IOWAIT,
CPU_IRQ,
CPU_SOFTIRQ,
CPU_STEAL,
CPU_GUEST,
2020-08-20 03:59:41 +00:00
PRESSURE_STALL_TEN,
PRESSURE_STALL_SIXTY,
PRESSURE_STALL_THREEHUNDRED,
ZFS_MFU,
ZFS_MRU,
ZFS_ANON,
ZFS_HEADER,
ZFS_OTHER,
ZFS_COMPRESSED,
ZFS_RATIO,
2020-09-22 11:54:15 +00:00
ZRAM,
Add a new DynamicMeter class for runtime Meter extension This commit is based on exploratory work by Sohaib Mohamed. The end goal is two-fold - to support addition of Meters we build via configuration files for both the PCP platform and for scripts ( https://github.com/htop-dev/htop/issues/526 ) Here, we focus on generic code and the PCP support. A new class DynamicMeter is introduced - it uses the special case 'param' field handling that previously was used only by the CPUMeter, such that every runtime-configured Meter is given a unique identifier. Unlike with the CPUMeter this is used internally only. When reading/writing to htoprc instead of CPU(N) - where N is an integer param (CPU number) - we use the string name for each meter. For example, if we have a configuration for a DynamicMeter for some Redis metrics, we might read and write "Dynamic(redis)". This identifier is subsequently matched (back) up to the configuration file so we're able to re-create arbitrary user configurations. The PCP platform configuration file format is fairly simple. We expand configs from several directories, including the users homedir alongside htoprc (below htop/meters/) and also /etc/pcp/htop/meters. The format will be described via a new pcp-htop(5) man page, but its basically ini-style and each Meter has one or more metric expressions associated, as well as specifications for labels, color and so on via a dot separated notation for individual metrics within the Meter. A few initial sample configuration files are provided below ./pcp/meters that give the general idea. The PCP "derived" metric specification - see pmRegisterDerived(3) - is used as the syntax for specifying metrics in PCP DynamicMeters.
2021-06-23 07:44:56 +00:00
DYNAMIC_GRAY,
DYNAMIC_DARKGRAY,
DYNAMIC_RED,
DYNAMIC_GREEN,
DYNAMIC_BLUE,
DYNAMIC_CYAN,
DYNAMIC_MAGENTA,
DYNAMIC_YELLOW,
DYNAMIC_WHITE,
2006-03-04 18:16:49 +00:00
LAST_COLORELEMENT
} ColorElements;
void CRT_fatalError(const char* note) ATTR_NORETURN;
2014-04-24 15:20:03 +00:00
void CRT_handleSIGSEGV(int signal) ATTR_NORETURN;
2020-10-05 15:24:59 +00:00
#define KEY_WHEELUP KEY_F(20)
#define KEY_WHEELDOWN KEY_F(21)
#define KEY_RECLICK KEY_F(22)
#define KEY_ALT(x) (KEY_F(64 - 26) + ((x) - 'A'))
extern const char* CRT_degreeSign;
2006-03-04 18:16:49 +00:00
#ifdef HAVE_LIBNCURSESW
extern bool CRT_utf8;
#endif
2020-10-31 22:28:02 +00:00
extern const char* const* CRT_treeStr;
2006-06-06 20:28:42 +00:00
2020-10-05 15:24:59 +00:00
extern const int* CRT_colors;
extern int CRT_cursorX;
2014-02-27 19:35:22 +00:00
extern int CRT_scrollHAmount;
extern int CRT_scrollWheelVAmount;
2020-12-14 14:45:48 +00:00
extern ColorScheme CRT_colorScheme;
2021-01-27 16:14:15 +00:00
void CRT_init(const Settings* settings, bool allowUnicode);
2006-03-04 18:16:49 +00:00
void CRT_done(void);
2006-03-04 18:16:49 +00:00
Reset the signal handlers at program exit The signal handler will access the Settings struct, which gets freed at normal program finalization. When using leak sanitizers with ASAN_OPTIONS=abort_on_error=1, which runs after program termination, any leak causes SIGABRT to be raised, calling the crash handler, which will derefernce the freed Settings. ==44741==ERROR: AddressSanitizer: heap-use-after-free on address 0x60d000000080 at pc 0x0000005680df bp 0x7fffe335e960 sp 0x7fffe335e958 READ of size 8 at 0x60d000000080 thread T0 #0 0x5680de in Settings_write /home/christian/Coding/workspaces/htop/Settings.c:329:26 #1 0x4f77b7 in CRT_handleSIGSEGV /home/christian/Coding/workspaces/htop/CRT.c:1020:4 #2 0x7f8a1120c13f (/lib/x86_64-linux-gnu/libpthread.so.0+0x1413f) #3 0x7f8a11042ce0 in __libc_signal_restore_set signal/../sysdeps/unix/sysv/linux/internal-signals.h:86:3 #4 0x7f8a11042ce0 in raise signal/../sysdeps/unix/sysv/linux/raise.c:48:3 #5 0x7f8a1102c536 in abort stdlib/abort.c:79:7 #6 0x4c3db6 in __sanitizer::Abort() (/home/christian/Coding/workspaces/htop/htop+0x4c3db6) #7 0x4c2090 in __sanitizer::Die() (/home/christian/Coding/workspaces/htop/htop+0x4c2090) #8 0x4d0a17 in __lsan::HandleLeaks() (/home/christian/Coding/workspaces/htop/htop+0x4d0a17) #9 0x4cd950 in __lsan::DoLeakCheck() (/home/christian/Coding/workspaces/htop/htop+0x4cd950) #10 0x7f8a110454d6 in __run_exit_handlers stdlib/exit.c:108:8 #11 0x7f8a11045679 in exit stdlib/exit.c:139:3 #12 0x7f8a1102dd10 in __libc_start_main csu/../csu/libc-start.c:342:3 #13 0x428a19 in _start (/home/christian/Coding/workspaces/htop/htop+0x428a19) 0x60d000000080 is located 64 bytes inside of 144-byte region [0x60d000000040,0x60d0000000d0) freed by thread T0 here: #0 0x4a4f72 in free (/home/christian/Coding/workspaces/htop/htop+0x4a4f72) #1 0x566693 in Settings_delete /home/christian/Coding/workspaces/htop/Settings.c:32:4 #2 0x4ede10 in CommandLine_run /home/christian/Coding/workspaces/htop/CommandLine.c:393:4 #3 0x4d6f32 in main /home/christian/Coding/workspaces/htop/htop.c:15:11 #4 0x7f8a1102dd09 in __libc_start_main csu/../csu/libc-start.c:308:16 previously allocated by thread T0 here: #0 0x4a5372 in __interceptor_calloc (/home/christian/Coding/workspaces/htop/htop+0x4a5372) #1 0x57f61a in xCalloc /home/christian/Coding/workspaces/htop/XUtils.c:55:17 #2 0x5688a6 in Settings_new /home/christian/Coding/workspaces/htop/Settings.c:392:21 #3 0x4ecb57 in CommandLine_run /home/christian/Coding/workspaces/htop/CommandLine.c:303:25 #4 0x4d6f32 in main /home/christian/Coding/workspaces/htop/htop.c:15:11 #5 0x7f8a1102dd09 in __libc_start_main csu/../csu/libc-start.c:308:16 SUMMARY: AddressSanitizer: heap-use-after-free /home/christian/Coding/workspaces/htop/Settings.c:329:26 in Settings_write
2021-08-14 17:52:26 +00:00
void CRT_resetSignalHandlers(void);
int CRT_readKey(void);
2006-03-04 18:16:49 +00:00
void CRT_disableDelay(void);
2006-06-06 20:28:42 +00:00
void CRT_enableDelay(void);
2006-06-06 20:28:42 +00:00
void CRT_setColors(int colorScheme);
2006-03-04 18:16:49 +00:00
#endif