From 724aae60d14c1721518c768a48e1e46e3391bb4e Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 6 Apr 2018 21:52:50 -0500 Subject: [PATCH 001/411] Add tree view flag to man page --- htop.1.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htop.1.in b/htop.1.in index 981645202..774bc0999 100644 --- a/htop.1.in +++ b/htop.1.in @@ -3,7 +3,7 @@ htop \- interactive process viewer .SH "SYNOPSIS" .LP -.B htop [\fI\-dChusv\fR] +.B htop [\fI\-dChustv\fR] .SH "DESCRIPTION" .LP Htop is a free (GPL) ncurses-based process viewer for Linux. @@ -41,6 +41,9 @@ Show only the processes of a given user .TP \fB\-v \-\-version Output version information and exit +.TP +\fB\-t \-\-tree +Show processes in tree view .PP .br .SH "INTERACTIVE COMMANDS" From 48b807b0ff892d41387f6cedfb3668e2bcc246ac Mon Sep 17 00:00:00 2001 From: Ian Sutton Date: Tue, 17 Jul 2018 08:43:50 -0500 Subject: [PATCH 002/411] Fix CPU meters Introduction of CP_SPIN sched state broke hard-coded state indexes resulting in the meters incorrectly reporting bogus intr data instead of CPU usage. Change hardcoded values to sched.h macros. --- openbsd/Platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 01b6c4786..cda424b6e 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -46,7 +46,7 @@ extern ProcessFieldData Process_fields[]; #define MAXCPU 256 // XXX: probably should be a struct member -static int64_t old_v[MAXCPU][5]; +static int64_t old_v[MAXCPU][CPUSTATES]; /* * Copyright (c) 1984, 1989, William LeFebvre, Rice University @@ -225,7 +225,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[i] = diff_v[i] / 10.; } - Meter_setItems(this, 4); + Meter_setItems(this, CP_IDLE); perc = v[0] + v[1] + v[2] + v[3]; From c005ffc3d70c14189952fa1041bab04462417308 Mon Sep 17 00:00:00 2001 From: Ian Sutton Date: Tue, 17 Jul 2018 08:50:22 -0500 Subject: [PATCH 003/411] Fix zero-index array bounds issue --- openbsd/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index cda424b6e..a3648f4e9 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -220,7 +220,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percentages(CPUSTATES, diff_v, new_v, (int64_t *)old_v[cpu-1], scratch_v); - for (i = 0; i < CPUSTATES; i++) { + for (i = 0; i < CPUSTATES - 1; i++) { old_v[cpu-1][i] = new_v[i]; v[i] = diff_v[i] / 10.; } From 3d79c72e9aceb883a6d065bb07ab4f955cd67b4a Mon Sep 17 00:00:00 2001 From: multiplexd Date: Tue, 17 Jul 2018 18:46:55 +0100 Subject: [PATCH 004/411] Update OpenBSD maximum PID The source code correctly states that the maximum PID number in the OpenBSD kernel is fixed in sys/sys/proc.h, however this was updated in revision 1.215 (two years ago!) from 32766 to 99999. --- openbsd/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 01b6c4786..18553c2d0 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -197,7 +197,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { int Platform_getMaxPid() { // this is hard-coded in sys/sys/proc.h - no sysctl exists - return 32766; + return 99999; } double Platform_setCPUValues(Meter* this, int cpu) { From 060aa2b20f88a7dbc1a8b77724df612d3b6fd9ea Mon Sep 17 00:00:00 2001 From: kremlin Date: Thu, 26 Jul 2018 04:17:06 -0500 Subject: [PATCH 005/411] remove wrongfix --- openbsd/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index a3648f4e9..cda424b6e 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -220,7 +220,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percentages(CPUSTATES, diff_v, new_v, (int64_t *)old_v[cpu-1], scratch_v); - for (i = 0; i < CPUSTATES - 1; i++) { + for (i = 0; i < CPUSTATES; i++) { old_v[cpu-1][i] = new_v[i]; v[i] = diff_v[i] / 10.; } From 67e368914a1b03cbf18c4c7b678f424f5e18ad2e Mon Sep 17 00:00:00 2001 From: Lion Yang Date: Sat, 25 Aug 2018 21:15:59 +0800 Subject: [PATCH 006/411] htop.c: remove unused "--io" / "-i" (#811) Introduced from https://github.com/hishamhm/htop/commit/3383d8e5561dfc6fb2b65e0a194df94ccb5e08af (2.0.0) but never used. --- htop.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htop.c b/htop.c index 678a3b8a3..8c88c782a 100644 --- a/htop.c +++ b/htop.c @@ -87,13 +87,12 @@ static CommandLineSettings parseArguments(int argc, char** argv) { {"no-colour",no_argument, 0, 'C'}, {"tree", no_argument, 0, 't'}, {"pid", required_argument, 0, 'p'}, - {"io", no_argument, 0, 'i'}, {0,0,0,0} }; int opt, opti=0; /* Parse arguments */ - while ((opt = getopt_long(argc, argv, "hvCs:td:u:p:i", long_opts, &opti))) { + while ((opt = getopt_long(argc, argv, "hvCs:td:u:p:", long_opts, &opti))) { if (opt == EOF) break; switch (opt) { case 'h': From c34be41e1ca89e81e43cfe3be01b52478461f70e Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Sun, 7 Oct 2018 11:16:12 +0200 Subject: [PATCH 007/411] Widen ST_UID (UID) column to 5 chars to allow UIDs > 9999 without breaking alignment Issue Github #841, Debian bug #910492 --- Process.c | 2 +- darwin/Platform.c | 2 +- dragonflybsd/DragonFlyBSDProcess.c | 2 +- freebsd/FreeBSDProcess.c | 2 +- linux/LinuxProcess.c | 2 +- openbsd/OpenBSDProcess.c | 2 +- solaris/SolarisProcess.c | 2 +- unsupported/Platform.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Process.c b/Process.c index 471f52996..d57a2e97c 100644 --- a/Process.c +++ b/Process.c @@ -466,7 +466,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) { } break; } - case ST_UID: xSnprintf(buffer, n, "%4d ", this->st_uid); break; + case ST_UID: xSnprintf(buffer, n, "%5d ", this->st_uid); break; case TIME: Process_printTime(str, this->time); return; case TGID: xSnprintf(buffer, n, Process_pidFormat, this->tgid); break; case TPGID: xSnprintf(buffer, n, Process_pidFormat, this->tpgid); break; diff --git a/darwin/Platform.c b/darwin/Platform.c index 1dce8b67a..27a7b850f 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -90,7 +90,7 @@ ProcessFieldData Process_fields[] = { [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, - [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, + [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index dade106d0..b7ef01d03 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -74,7 +74,7 @@ ProcessFieldData Process_fields[] = { [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, - [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, + [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index f81fadf50..73bba192b 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -73,7 +73,7 @@ ProcessFieldData Process_fields[] = { [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, - [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, + [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 5f697078f..b55d322c7 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -203,7 +203,7 @@ ProcessFieldData Process_fields[] = { [M_DRS] = { .name = "M_DRS", .title = " DATA ", .description = "Size of the data segment plus stack usage of the process", .flags = 0, }, [M_LRS] = { .name = "M_LRS", .title = " LIB ", .description = "The library size of the process", .flags = 0, }, [M_DT] = { .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process", .flags = 0, }, - [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, + [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 70f9653bc..f54c9111d 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -135,7 +135,7 @@ ProcessFieldData Process_fields[] = { .flags = 0, }, [ST_UID] = { .name = "ST_UID", - .title = " UID ", + .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index 31f488ef6..514453fd4 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -90,7 +90,7 @@ ProcessFieldData Process_fields[] = { [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, - [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, + [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, diff --git a/unsupported/Platform.c b/unsupported/Platform.c index ba8441913..e4c0e8cee 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -50,7 +50,7 @@ ProcessFieldData Process_fields[] = { [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, - [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, + [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, From c39f710b52e857c750d661ece97313a5aa26908c Mon Sep 17 00:00:00 2001 From: Alan Barr Date: Sat, 13 Oct 2018 19:04:59 +0100 Subject: [PATCH 008/411] Remove duplicated if condition The for loop already handles i being < nPanels Raised by cppcheck --- ScreenManager.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ScreenManager.c b/ScreenManager.c index 05e1c0249..06e901938 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -145,14 +145,12 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi } static void ScreenManager_drawPanels(ScreenManager* this, int focus) { - int nPanels = this->panelCount; + const int nPanels = this->panelCount; for (int i = 0; i < nPanels; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); Panel_draw(panel, i == focus); - if (i < nPanels) { - if (this->orientation == HORIZONTAL) { - mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1); - } + if (this->orientation == HORIZONTAL) { + mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1); } } } From 4cb58460e571832e5f80f7259f64dd6268fab1eb Mon Sep 17 00:00:00 2001 From: Alan Barr Date: Sat, 13 Oct 2018 19:10:12 +0100 Subject: [PATCH 009/411] Prevent possible NULL pointer deference Raised by cppcheck --- darwin/DarwinProcessList.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 4a580acc7..098844809 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -84,9 +84,8 @@ void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { if(0 != munmap(*p, vm_page_size)) { CRT_fatalError("Unable to free old CPU load information\n"); } + *p = NULL; } - - *p = NULL; } unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { From b7b4200f854f667a917b7da8f92b3e0426131bd7 Mon Sep 17 00:00:00 2001 From: Alan Barr Date: Sat, 13 Oct 2018 19:20:52 +0100 Subject: [PATCH 010/411] Fix printf() unsigned placeholders Unsigned numbers should be using "%u". Raised by cppcheck --- Process.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Process.c b/Process.c index 471f52996..d6e30ee7f 100644 --- a/Process.c +++ b/Process.c @@ -228,7 +228,7 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { if(number >= (10 * ONE_DECIMAL_M)) { #ifdef __LP64__ if(number >= (100 * ONE_DECIMAL_G)) { - len = snprintf(buffer, 10, "%4ldT ", number / ONE_G); + len = snprintf(buffer, 10, "%4luT ", number / ONE_G); RichString_appendn(str, largeNumberColor, buffer, len); return; } else if (number >= (1000 * ONE_DECIMAL_M)) { @@ -238,7 +238,7 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { } #endif if(number >= (100 * ONE_DECIMAL_M)) { - len = snprintf(buffer, 10, "%4ldG ", number / ONE_M); + len = snprintf(buffer, 10, "%4luG ", number / ONE_M); RichString_appendn(str, largeNumberColor, buffer, len); return; } @@ -246,11 +246,11 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { RichString_appendn(str, largeNumberColor, buffer, len); return; } else if (number >= 100000) { - len = snprintf(buffer, 10, "%4ldM ", number / ONE_K); + len = snprintf(buffer, 10, "%4luM ", number / ONE_K); RichString_appendn(str, processMegabytesColor, buffer, len); return; } else if (number >= 1000) { - len = snprintf(buffer, 10, "%2ld", number/1000); + len = snprintf(buffer, 10, "%2lu", number/1000); RichString_appendn(str, processMegabytesColor, buffer, len); number %= 1000; len = snprintf(buffer, 10, "%03lu ", number); @@ -278,7 +278,7 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori int len = snprintf(buffer, 13, " no perm "); RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len); } else if (number > 10000000000) { - xSnprintf(buffer, 13, "%11lld ", number / 1000); + xSnprintf(buffer, 13, "%11llu ", number / 1000); RichString_appendn(str, largeNumberColor, buffer, 5); RichString_appendn(str, processMegabytesColor, buffer+5, 3); RichString_appendn(str, processColor, buffer+8, 4); @@ -380,9 +380,9 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) { switch (field) { case PERCENT_CPU: { if (this->percent_cpu > 999.9) { - xSnprintf(buffer, n, "%4d ", (unsigned int)this->percent_cpu); + xSnprintf(buffer, n, "%4u ", (unsigned int)this->percent_cpu); } else if (this->percent_cpu > 99.9) { - xSnprintf(buffer, n, "%3d. ", (unsigned int)this->percent_cpu); + xSnprintf(buffer, n, "%3u. ", (unsigned int)this->percent_cpu); } else { xSnprintf(buffer, n, "%4.1f ", this->percent_cpu); } From 8d7afb33e2e35fc0a34c1b9b0e7ce4cb3b3d5f86 Mon Sep 17 00:00:00 2001 From: syrrim Date: Sat, 3 Nov 2018 15:59:55 -0400 Subject: [PATCH 011/411] added MainPanel actions n and N for find next and find prev. closes #601 --- Action.c | 13 +++++++++++++ IncSet.c | 44 ++++++++++++++++++++++++++++++++------------ IncSet.h | 6 ++++++ 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/Action.c b/Action.c index 9a7c3c560..5488fecf1 100644 --- a/Action.c +++ b/Action.c @@ -248,10 +248,21 @@ static Htop_Reaction actionIncFilter(State* st) { } static Htop_Reaction actionIncSearch(State* st) { + IncSet_reset(((MainPanel*)st->panel)->inc, INC_SEARCH); IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel); return HTOP_REFRESH | HTOP_KEEP_FOLLOWING; } +static Htop_Reaction actionIncNext(State* st) { + IncSet_next(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue); + return HTOP_REFRESH | HTOP_KEEP_FOLLOWING; +} + +static Htop_Reaction actionIncPrev(State* st) { + IncSet_prev(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue); + return HTOP_REFRESH | HTOP_KEEP_FOLLOWING; +} + static Htop_Reaction actionHigherPriority(State* st) { bool changed = changePriority((MainPanel*)st->panel, -1); return changed ? HTOP_REFRESH : HTOP_OK; @@ -559,6 +570,8 @@ void Action_setBindings(Htop_Action* keys) { keys['\\'] = actionIncFilter; keys[KEY_F(3)] = actionIncSearch; keys['/'] = actionIncSearch; + keys['n'] = actionIncNext; + keys['N'] = actionIncPrev; keys[']'] = actionHigherPriority; keys[KEY_F(7)] = actionHigherPriority; diff --git a/IncSet.c b/IncSet.c index bb9f9544d..eaab549c4 100644 --- a/IncSet.c +++ b/IncSet.c @@ -52,6 +52,10 @@ static void IncMode_reset(IncMode* mode) { mode->buffer[0] = 0; } +void IncSet_reset(IncSet* this, IncType type) { + IncMode_reset(&this->modes[type]); +} + static const char* const searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL}; static const char* const searchKeys[] = {"F3", "Esc", " "}; static int searchEvents[] = {KEY_F(3), 27, ERR}; @@ -132,6 +136,30 @@ static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa return found; } +static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) { + int size = Panel_size(panel); + int here = Panel_getSelectedIndex(panel); + int i = here; + for(;;) { + i+=step; + if (i == size) i = 0; + if (i == -1) i = size - 1; + if (i == here) return false; + if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { + Panel_setSelected(panel, i); + return true; + } + } +} + +bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue) { + return IncMode_find(&this->modes[type], panel, getPanelValue, 1); +} + +bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue) { + return IncMode_find(&this->modes[type], panel, getPanelValue, -1); +} + bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) { if (ch == ERR) return true; @@ -141,17 +169,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue bool doSearch = true; if (ch == KEY_F(3)) { if (size == 0) return true; - int here = Panel_getSelectedIndex(panel); - int i = here; - for(;;) { - i++; - if (i == size) i = 0; - if (i == here) break; - if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { - Panel_setSelected(panel, i); - break; - } - } + IncMode_find(mode, panel, getPanelValue, 1); doSearch = false; } else if (ch < 255 && isprint((char)ch)) { if (mode->index < INCMODE_MAX) { @@ -187,7 +205,9 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue IncMode_reset(mode); } } else { - IncMode_reset(mode); + if (ch == 27) { + IncMode_reset(mode); + } } this->active = NULL; Panel_setDefaultBar(panel); diff --git a/IncSet.h b/IncSet.h index 27538f4b8..12679a785 100644 --- a/IncSet.h +++ b/IncSet.h @@ -41,10 +41,16 @@ typedef struct IncSet_ { typedef const char* (*IncMode_GetPanelValue)(Panel*, int); +void IncSet_reset(IncSet* this, IncType type); + IncSet* IncSet_new(FunctionBar* bar); void IncSet_delete(IncSet* this); +bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue); + +bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue); + bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines); const char* IncSet_getListItemValue(Panel* panel, int i); From 41754e56329522dac9f05f4ebefb436908b27fdc Mon Sep 17 00:00:00 2001 From: Wataru Ashihara Date: Sat, 15 Dec 2018 22:06:00 +0900 Subject: [PATCH 012/411] Remove unnecessary HAVE_SYS_SYSMACROS_H check HAVE_SYS_SYSMACROS_H is always true if MAJOR_IN_SYSMACROS. This way of checking is recommended in autoconf 2.70 documentation: https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blobdiff;f=doc/autoconf.texi;h=4f041bd4e;hp=9ad7dc1c5f02c8ba25b2fe1218bf931c7113a5d5;hb=e17a30e987d7ee695fb4294a82d987ec3dc9b974;hpb=565a6dc50cfa01cec2fb4db894026689cdf4970c NOTE: currently https://www.gnu.org/software/autoconf/manual/autoconf.html is the doc for autoconf 2.69. --- Process.c | 3 +-- Process.h | 3 +-- linux/LinuxProcessList.c | 3 +-- linux/LinuxProcessList.h | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Process.c b/Process.c index d6e30ee7f..3fc90f7c0 100644 --- a/Process.c +++ b/Process.c @@ -30,8 +30,7 @@ in the source distribution for its full text. #include #ifdef MAJOR_IN_MKDEV #include -#elif defined(MAJOR_IN_SYSMACROS) || \ - (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H) +#elif defined(MAJOR_IN_SYSMACROS) #include #endif diff --git a/Process.h b/Process.h index f702ca006..9c15d06e7 100644 --- a/Process.h +++ b/Process.h @@ -10,8 +10,7 @@ in the source distribution for its full text. */ #ifdef MAJOR_IN_MKDEV -#elif defined(MAJOR_IN_SYSMACROS) || \ - (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H) +#elif defined(MAJOR_IN_SYSMACROS) #endif #ifdef __ANDROID__ diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 62bc0967f..027cca4f4 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -28,8 +28,7 @@ in the source distribution for its full text. #include #ifdef MAJOR_IN_MKDEV #include -#elif defined(MAJOR_IN_SYSMACROS) || \ - (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H) +#elif defined(MAJOR_IN_SYSMACROS) #include #endif diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index f30b487d6..9dbbce5e7 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -10,8 +10,7 @@ in the source distribution for its full text. */ #ifdef MAJOR_IN_MKDEV -#elif defined(MAJOR_IN_SYSMACROS) || \ - (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H) +#elif defined(MAJOR_IN_SYSMACROS) #endif #ifdef HAVE_DELAYACCT From 9197adf57e04875fe7fd5b768bc5201d5def2548 Mon Sep 17 00:00:00 2001 From: Antoine Motet Date: Sun, 16 Dec 2018 09:25:54 +0100 Subject: [PATCH 013/411] Fix CPU usage on OpenBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current OpenBSD-specific CPU usage code is broken. The `cpu` parameter of `Platform_setCPUValues` is an integer in the interval [0, cpuCount], not [0, cpuCount-1]: Actual CPUs are numbered from 1, the “zero” CPU is a “virtual” one which represents the average of actual CPUs (I guess it’s inherited from Linux’s `/proc/stats`). This off-by-one error leads to random crashes. Moreover, the displayed CPU usage is more detailed with system, user and nice times. I made the OpenBSD CPU code more similar to the Linux CPU code, removing a few old bits from OpenBSD’s top(1). I think it will be easier to understand, maintain and evolve. I’d love some feedback from experienced OpenBSD people. --- openbsd/Battery.c | 1 + openbsd/Battery.h | 1 - openbsd/OpenBSDProcessList.c | 142 +++++++++++++++++++++++++++++------ openbsd/OpenBSDProcessList.h | 18 ++++- openbsd/Platform.c | 103 ++++++------------------- openbsd/Platform.h | 15 ---- 6 files changed, 163 insertions(+), 117 deletions(-) diff --git a/openbsd/Battery.c b/openbsd/Battery.c index 3a0bae143..80511dc76 100644 --- a/openbsd/Battery.c +++ b/openbsd/Battery.c @@ -10,6 +10,7 @@ in the source distribution for its full text. #include #include #include +#include static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) { for (int devn = 0;; devn++) { diff --git a/openbsd/Battery.h b/openbsd/Battery.h index b1a4982ec..0f05af3a4 100644 --- a/openbsd/Battery.h +++ b/openbsd/Battery.h @@ -12,5 +12,4 @@ in the source distribution for its full text. void Battery_getData(double* level, ACPresence* isOnAC); - #endif diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index e49cbd71f..2d8951c3e 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -6,6 +6,7 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "CRT.h" #include "ProcessList.h" #include "OpenBSDProcessList.h" #include "OpenBSDProcess.h" @@ -17,6 +18,7 @@ in the source distribution for its full text. #include #include #include +#include #include #include #include @@ -31,7 +33,22 @@ in the source distribution for its full text. typedef struct CPUData_ { unsigned long long int totalTime; + unsigned long long int userTime; + unsigned long long int niceTime; + unsigned long long int sysTime; + unsigned long long int sysAllTime; + unsigned long long int spinTime; + unsigned long long int intrTime; + unsigned long long int idleTime; + unsigned long long int totalPeriod; + unsigned long long int userPeriod; + unsigned long long int nicePeriod; + unsigned long long int sysPeriod; + unsigned long long int sysAllPeriod; + unsigned long long int spinPeriod; + unsigned long long int intrPeriod; + unsigned long long int idlePeriod; } CPUData; typedef struct OpenBSDProcessList_ { @@ -79,16 +96,17 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui if (e == -1 || pl->cpuCount < 1) { pl->cpuCount = 1; } - opl->cpus = xRealloc(opl->cpus, pl->cpuCount * sizeof(CPUData)); + opl->cpus = xCalloc(pl->cpuCount + 1, sizeof(CPUData)); size = sizeof(fscale); if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0) { err(1, "fscale sysctl call failed"); } - for (i = 0; i < pl->cpuCount; i++) { - opl->cpus[i].totalTime = 1; - opl->cpus[i].totalPeriod = 1; + for (i = 0; i <= pl->cpuCount; i++) { + CPUData *d = opl->cpus + i; + d->totalTime = 1; + d->totalPeriod = 1; } opl->kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf); @@ -205,7 +223,7 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in /* * Taken from OpenBSD's ps(1). */ -double getpcpu(const struct kinfo_proc *kp) { +static double getpcpu(const struct kinfo_proc *kp) { if (fscale == 0) return (0.0); @@ -214,9 +232,8 @@ double getpcpu(const struct kinfo_proc *kp) { return (100.0 * fxtofl(kp->p_pctcpu)); } -void ProcessList_goThroughEntries(ProcessList* this) { - OpenBSDProcessList* opl = (OpenBSDProcessList*) this; - Settings* settings = this->settings; +static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { + Settings* settings = this->super.settings; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; struct kinfo_proc* kproc; @@ -228,10 +245,8 @@ void ProcessList_goThroughEntries(ProcessList* this) { int count = 0; int i; - OpenBSDProcessList_scanMemoryInfo(this); - // use KERN_PROC_KTHREAD to also include kernel threads - struct kinfo_proc* kprocs = kvm_getprocs(opl->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count); + struct kinfo_proc* kprocs = kvm_getprocs(this->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count); //struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count); gettimeofday(&tv, NULL); @@ -240,7 +255,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { kproc = &kprocs[i]; preExisting = false; - proc = ProcessList_getProcess(this, kproc->p_pid, &preExisting, (Process_New) OpenBSDProcess_new); + proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, (Process_New) OpenBSDProcess_new); fp = (OpenBSDProcess*) proc; proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) @@ -255,22 +270,22 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->pgrp = kproc->p__pgid; proc->st_uid = kproc->p_uid; proc->starttime_ctime = kproc->p_ustart_sec; - proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); - ProcessList_add((ProcessList*)this, proc); - proc->comm = OpenBSDProcessList_readProcessName(opl->kd, kproc, &proc->basenameOffset); + proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid); + ProcessList_add(&this->super, proc); + proc->comm = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->basenameOffset); (void) localtime_r((time_t*) &kproc->p_ustart_sec, &date); strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date); } else { if (settings->updateProcessNames) { free(proc->comm); - proc->comm = OpenBSDProcessList_readProcessName(opl->kd, kproc, &proc->basenameOffset); + proc->comm = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->basenameOffset); } } proc->m_size = kproc->p_vm_dsize; proc->m_resident = kproc->p_vm_rssize; - proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0; - proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->cpuCount*100.0); + proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->super.totalMem) * 100.0; + proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount*100.0); //proc->nlwp = kproc->p_numthreads; //proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 10); proc->nice = kproc->p_nice - 20; @@ -290,14 +305,99 @@ void ProcessList_goThroughEntries(ProcessList* this) { } if (Process_isKernelThread(proc)) { - this->kernelThreads++; + this->super.kernelThreads++; } - this->totalTasks++; + this->super.totalTasks++; // SRUN ('R') means runnable, not running if (proc->state == 'P') { - this->runningTasks++; + this->super.runningTasks++; } proc->updated = true; } } + +static unsigned long long saturatingSub(unsigned long long a, unsigned long long b) { + return a > b ? a - b : 0; +} + +static void getKernelCPUTimes(int cpuId, u_int64_t* times) { + int mib[] = { CTL_KERN, KERN_CPTIME2, cpuId }; + size_t length = sizeof(u_int64_t) * CPUSTATES; + if (sysctl(mib, 3, times, &length, NULL, 0) == -1 || + length != sizeof(u_int64_t) * CPUSTATES) { + CRT_fatalError("sysctl kern.cp_time2 failed"); + } +} + +static void kernelCPUTimesToHtop(const u_int64_t* times, CPUData* cpu) { + unsigned long long totalTime = 0; + for (int i = 0; i < CPUSTATES; i++) { + totalTime += times[i]; + } + + unsigned long long sysAllTime = times[CP_INTR] + times[CP_SYS]; + + // XXX Not sure if CP_SPIN should be added to sysAllTime. + // See https://github.com/openbsd/src/commit/531d8034253fb82282f0f353c086e9ad827e031c + #ifdef CP_SPIN + sysAllTime += times[CP_SPIN]; + #endif + + cpu->totalPeriod = saturatingSub(totalTime, cpu->totalTime); + cpu->userPeriod = saturatingSub(times[CP_USER], cpu->userTime); + cpu->nicePeriod = saturatingSub(times[CP_NICE], cpu->niceTime); + cpu->sysPeriod = saturatingSub(times[CP_SYS], cpu->sysTime); + cpu->sysAllPeriod = saturatingSub(sysAllTime, cpu->sysAllTime); + #ifdef CP_SPIN + cpu->spinPeriod = saturatingSub(times[CP_SPIN], cpu->spinTime); + #endif + cpu->intrPeriod = saturatingSub(times[CP_INTR], cpu->intrTime); + cpu->idlePeriod = saturatingSub(times[CP_IDLE], cpu->idleTime); + + cpu->totalTime = totalTime; + cpu->userTime = times[CP_USER]; + cpu->niceTime = times[CP_NICE]; + cpu->sysTime = times[CP_SYS]; + cpu->sysAllTime = sysAllTime; + #ifdef CP_SPIN + cpu->spinTime = times[CP_SPIN]; + #endif + cpu->intrTime = times[CP_INTR]; + cpu->idleTime = times[CP_IDLE]; +} + +static void OpenBSDProcessList_scanCPUTime(OpenBSDProcessList* this) { + u_int64_t kernelTimes[CPUSTATES] = {0}; + u_int64_t avg[CPUSTATES] = {0}; + + for (int i = 0; i < this->super.cpuCount; i++) { + getKernelCPUTimes(i, kernelTimes); + CPUData* cpu = this->cpus + i + 1; + kernelCPUTimesToHtop(kernelTimes, cpu); + + avg[CP_USER] += cpu->userTime; + avg[CP_NICE] += cpu->niceTime; + avg[CP_SYS] += cpu->sysTime; + #ifdef CP_SPIN + avg[CP_SPIN] += cpu->spinTime; + #endif + avg[CP_INTR] += cpu->intrTime; + avg[CP_IDLE] += cpu->idleTime; + } + + for (int i = 0; i < CPUSTATES; i++) { + avg[i] /= this->super.cpuCount; + } + + kernelCPUTimesToHtop(avg, this->cpus); +} + +void ProcessList_goThroughEntries(ProcessList* this) { + OpenBSDProcessList* opl = (OpenBSDProcessList*) this; + + OpenBSDProcessList_scanMemoryInfo(this); + OpenBSDProcessList_scanProcs(opl); + OpenBSDProcessList_scanCPUTime(opl); +} + diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index ba9e6d14b..ec9fab275 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -15,7 +15,22 @@ in the source distribution for its full text. typedef struct CPUData_ { unsigned long long int totalTime; + unsigned long long int userTime; + unsigned long long int niceTime; + unsigned long long int sysTime; + unsigned long long int sysAllTime; + unsigned long long int spinTime; + unsigned long long int intrTime; + unsigned long long int idleTime; + unsigned long long int totalPeriod; + unsigned long long int userPeriod; + unsigned long long int nicePeriod; + unsigned long long int sysPeriod; + unsigned long long int sysAllPeriod; + unsigned long long int spinPeriod; + unsigned long long int intrPeriod; + unsigned long long int idlePeriod; } CPUData; typedef struct OpenBSDProcessList_ { @@ -51,8 +66,7 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in /* * Taken from OpenBSD's ps(1). */ -double getpcpu(const struct kinfo_proc *kp); - void ProcessList_goThroughEntries(ProcessList* this); + #endif diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 4bb2e35ee..7e117a76a 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -38,6 +38,7 @@ in the source distribution for its full text. #include #include #include +#include /*{ #include "Action.h" @@ -48,54 +49,6 @@ extern ProcessFieldData Process_fields[]; }*/ -#define MAXCPU 256 -// XXX: probably should be a struct member -static int64_t old_v[MAXCPU][5]; - -/* - * Copyright (c) 1984, 1989, William LeFebvre, Rice University - * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University - * - * Taken directly from OpenBSD's top(1). - * - * percentages(cnt, out, new, old, diffs) - calculate percentage change - * between array "old" and "new", putting the percentages in "out". - * "cnt" is size of each array and "diffs" is used for scratch space. - * The array "old" is updated on each call. - * The routine assumes modulo arithmetic. This function is especially - * useful on BSD machines for calculating cpu state percentages. - */ -static int percentages(int cnt, int64_t *out, int64_t *new, int64_t *old, int64_t *diffs) { - int64_t change, total_change, *dp, half_total; - int i; - - /* initialization */ - total_change = 0; - dp = diffs; - - /* calculate changes for each state and the overall change */ - for (i = 0; i < cnt; i++) { - if ((change = *new - *old) < 0) { - /* this only happens when the counter wraps */ - change = INT64_MAX - *old + *new; - } - total_change += (*dp++ = change); - *old++ = *new++; - } - - /* avoid divide by zero potential */ - if (total_change == 0) - total_change = 1; - - /* calculate percentages based on overall change, rounding up */ - half_total = total_change / 2l; - for (i = 0; i < cnt; i++) - *out++ = ((*diffs++ * 1000 + half_total) / total_change); - - /* return the total in case the caller wants to use it */ - return (total_change); -} - ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; int Platform_numberOfFields = LAST_PROCESSFIELD; @@ -201,43 +154,37 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { int Platform_getMaxPid() { // this is hard-coded in sys/sys/proc.h - no sysctl exists - return 32766; + return 32766; // XXX Seems changed to 99999, what about using PID_MAX? } double Platform_setCPUValues(Meter* this, int cpu) { - int i; - double perc; - - OpenBSDProcessList* pl = (OpenBSDProcessList*) this->pl; - CPUData* cpuData = &(pl->cpus[cpu]); - int64_t new_v[CPUSTATES], diff_v[CPUSTATES], scratch_v[CPUSTATES]; + const OpenBSDProcessList* pl = (OpenBSDProcessList*) this->pl; + const CPUData* cpuData = &(pl->cpus[cpu]); + double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod; + double totalPercent; double *v = this->values; - size_t size = sizeof(double) * CPUSTATES; - int mib[] = { CTL_KERN, KERN_CPTIME2, cpu-1 }; - if (sysctl(mib, 3, new_v, &size, NULL, 0) == -1) { - return 0.; - } - - // XXX: why? - cpuData->totalPeriod = 1; - - percentages(CPUSTATES, diff_v, new_v, - (int64_t *)old_v[cpu-1], scratch_v); - for (i = 0; i < CPUSTATES; i++) { - old_v[cpu-1][i] = new_v[i]; - v[i] = diff_v[i] / 10.; - } - - Meter_setItems(this, 4); - - perc = v[0] + v[1] + v[2] + v[3]; - - if (perc <= 100. && perc >= 0.) { - return perc; + v[CPU_METER_NICE] = cpuData->nicePeriod / total * 100.0; + v[CPU_METER_NORMAL] = cpuData->userPeriod / total * 100.0; + if (this->pl->settings->detailedCPUTime) { + v[CPU_METER_KERNEL] = cpuData->sysPeriod / total * 100.0; + v[CPU_METER_IRQ] = cpuData->intrPeriod / total * 100.0; + v[CPU_METER_SOFTIRQ] = 0.0; + v[CPU_METER_STEAL] = 0.0; + v[CPU_METER_GUEST] = 0.0; + v[CPU_METER_IOWAIT] = 0.0; + Meter_setItems(this, 8); + totalPercent = v[0]+v[1]+v[2]+v[3]; } else { - return 0.; + v[2] = cpuData->sysAllPeriod / total * 100.0; + v[3] = 0.0; // No steal nor guest on OpenBSD + totalPercent = v[0]+v[1]+v[2]; + Meter_setItems(this, 4); } + + totalPercent = CLAMP(totalPercent, 0.0, 100.0); + if (isnan(totalPercent)) totalPercent = 0.0; + return totalPercent; } void Platform_setMemoryValues(Meter* this) { diff --git a/openbsd/Platform.h b/openbsd/Platform.h index e0da7b9ff..56e4c4000 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -17,21 +17,6 @@ in the source distribution for its full text. extern ProcessFieldData Process_fields[]; -#define MAXCPU 256 -// XXX: probably should be a struct member -/* - * Copyright (c) 1984, 1989, William LeFebvre, Rice University - * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University - * - * Taken directly from OpenBSD's top(1). - * - * percentages(cnt, out, new, old, diffs) - calculate percentage change - * between array "old" and "new", putting the percentages in "out". - * "cnt" is size of each array and "diffs" is used for scratch space. - * The array "old" is updated on each call. - * The routine assumes modulo arithmetic. This function is especially - * useful on BSD machines for calculating cpu state percentages. - */ extern ProcessField Platform_defaultFields[]; extern int Platform_numberOfFields; From 27fe307d2248c3ee79cbc212301031444d569610 Mon Sep 17 00:00:00 2001 From: Antoine Motet Date: Sun, 16 Dec 2018 11:34:15 +0100 Subject: [PATCH 014/411] Remove a few unnecessary #includes --- openbsd/Platform.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 7e117a76a..8203e721f 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -20,8 +20,6 @@ in the source distribution for its full text. #include "OpenBSDProcess.h" #include "OpenBSDProcessList.h" -#include -#include #include #include #include @@ -31,7 +29,6 @@ in the source distribution for its full text. #include #include #include -#include #include #include #include From f15d55c972afff12b934c2347d07fa8a2991c264 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Tue, 18 Dec 2018 21:05:09 +0800 Subject: [PATCH 015/411] Fix numbers larger than 100 terabytes --- Process.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Process.c b/Process.c index d6e30ee7f..0de1738c2 100644 --- a/Process.c +++ b/Process.c @@ -277,7 +277,11 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori if ((long long) number == -1LL) { int len = snprintf(buffer, 13, " no perm "); RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len); - } else if (number > 10000000000) { + } else if (number >= 100000000000000) { + xSnprintf(buffer, 13, "%11llu ", number / 1000000); + RichString_appendn(str, largeNumberColor, buffer, 8); + RichString_appendn(str, processMegabytesColor, buffer+8, 4); + } else if (number >= 10000000000) { xSnprintf(buffer, 13, "%11llu ", number / 1000); RichString_appendn(str, largeNumberColor, buffer, 5); RichString_appendn(str, processMegabytesColor, buffer+5, 3); From ecfd6f685e4694e3752c3a05e0db0c5bd24a1fcf Mon Sep 17 00:00:00 2001 From: Tobias Kortkamp Date: Mon, 24 Dec 2018 13:51:01 +0100 Subject: [PATCH 016/411] Fix memory statistics display on FreeBSD/powerpc Use the appropriate types when calling sysctl(). Currently, `unsigned long long int` is used for all sizes and on FreeBSD/powerpc this causes all sysctl() calls in scanMemoryInfo() to fail as they are actually of different sizes on powerpc, where (sizeof(unsigned long long int), sizeof(u_long)) == (8, 4) vs (8, 8) on amd64. This results in bogus memory sizes being reported by htop. Signed-off-by: Tobias Kortkamp --- freebsd/FreeBSDProcessList.c | 51 +++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 9fef324a5..0c8d028f0 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -296,31 +296,46 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { // // htop_used = active + (wired - arc) // htop_cache = buffers + cache + arc - size_t len = sizeof(pl->totalMem); + u_long totalMem; + u_int memActive, memWire, cachedMem; + long buffersMem; + uint64_t memZfsArc; + size_t len; //disabled for now, as it is always smaller than phycal amount of memory... //...to avoid "where is my memory?" questions //sysctl(MIB_vm_stats_vm_v_page_count, 4, &(pl->totalMem), &len, NULL, 0); //pl->totalMem *= pageSizeKb; - sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0); - pl->totalMem /= 1024; - - sysctl(MIB_vm_stats_vm_v_active_count, 4, &(fpl->memActive), &len, NULL, 0); - fpl->memActive *= pageSizeKb; - - sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(fpl->memWire), &len, NULL, 0); - fpl->memWire *= pageSizeKb; - - sysctl(MIB_vfs_bufspace, 2, &(pl->buffersMem), &len, NULL, 0); - pl->buffersMem /= 1024; - - sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(pl->cachedMem), &len, NULL, 0); - pl->cachedMem *= pageSizeKb; + len = sizeof(totalMem); + sysctl(MIB_hw_physmem, 2, &(totalMem), &len, NULL, 0); + totalMem /= 1024; + pl->totalMem = totalMem; + + len = sizeof(memActive); + sysctl(MIB_vm_stats_vm_v_active_count, 4, &(memActive), &len, NULL, 0); + memActive *= pageSizeKb; + fpl->memActive = memActive; + + len = sizeof(memWire); + sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(memWire), &len, NULL, 0); + memWire *= pageSizeKb; + fpl->memWire = memWire; + + len = sizeof(buffersMem); + sysctl(MIB_vfs_bufspace, 2, &(buffersMem), &len, NULL, 0); + buffersMem /= 1024; + pl->buffersMem = buffersMem; + + len = sizeof(cachedMem); + sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(cachedMem), &len, NULL, 0); + cachedMem *= pageSizeKb; + pl->cachedMem = cachedMem; if (fpl->zfsArcEnabled) { - len = sizeof(fpl->memZfsArc); - sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(fpl->memZfsArc), &len , NULL, 0); - fpl->memZfsArc /= 1024; + len = sizeof(memZfsArc); + sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(memZfsArc), &len , NULL, 0); + memZfsArc /= 1024; + fpl->memZfsArc = memZfsArc; fpl->memWire -= fpl->memZfsArc; pl->cachedMem += fpl->memZfsArc; // maybe when we learn how to make custom memory meter From 536941fb238a63961828300eb4cfa303c6664f63 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Sun, 30 Dec 2018 20:18:35 +0800 Subject: [PATCH 017/411] Deal with larger numbers in colorNumber and outputRate --- Process.c | 24 ++++++++++++++++-------- Process.h | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Process.c b/Process.c index 0de1738c2..7a5661dda 100644 --- a/Process.c +++ b/Process.c @@ -191,10 +191,12 @@ static int Process_getuid = -1; #define ONE_K 1024L #define ONE_M (ONE_K * ONE_K) #define ONE_G (ONE_M * ONE_K) +#define ONE_T ((long long)ONE_G * ONE_K) #define ONE_DECIMAL_K 1000L #define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K) #define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K) +#define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K) char Process_pidFormat[20] = "%7d "; @@ -277,12 +279,15 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori if ((long long) number == -1LL) { int len = snprintf(buffer, 13, " no perm "); RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len); - } else if (number >= 100000000000000) { - xSnprintf(buffer, 13, "%11llu ", number / 1000000); + } else if (number >= 100000LL * ONE_DECIMAL_T) { + xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_G); + RichString_appendn(str, largeNumberColor, buffer, 12); + } else if (number >= 100LL * ONE_DECIMAL_T) { + xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_M); RichString_appendn(str, largeNumberColor, buffer, 8); RichString_appendn(str, processMegabytesColor, buffer+8, 4); - } else if (number >= 10000000000) { - xSnprintf(buffer, 13, "%11llu ", number / 1000); + } else if (number >= 10LL * ONE_DECIMAL_G) { + xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_K); RichString_appendn(str, largeNumberColor, buffer, 5); RichString_appendn(str, processMegabytesColor, buffer+5, 3); RichString_appendn(str, processColor, buffer+8, 4); @@ -362,14 +367,17 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c } else if (rate < ONE_K) { int len = snprintf(buffer, n, "%7.2f B/s ", rate); RichString_appendn(str, processColor, buffer, len); - } else if (rate < ONE_K * ONE_K) { + } else if (rate < ONE_M) { int len = snprintf(buffer, n, "%7.2f K/s ", rate / ONE_K); RichString_appendn(str, processColor, buffer, len); - } else if (rate < ONE_K * ONE_K * ONE_K) { - int len = snprintf(buffer, n, "%7.2f M/s ", rate / ONE_K / ONE_K); + } else if (rate < ONE_G) { + int len = snprintf(buffer, n, "%7.2f M/s ", rate / ONE_M); RichString_appendn(str, processMegabytesColor, buffer, len); + } else if (rate < ONE_T) { + int len = snprintf(buffer, n, "%7.2f G/s ", rate / ONE_G); + RichString_appendn(str, largeNumberColor, buffer, len); } else { - int len = snprintf(buffer, n, "%7.2f G/s ", rate / ONE_K / ONE_K / ONE_K); + int len = snprintf(buffer, n, "%7.2f T/s ", rate / ONE_T); RichString_appendn(str, largeNumberColor, buffer, len); } } diff --git a/Process.h b/Process.h index f702ca006..26e93803f 100644 --- a/Process.h +++ b/Process.h @@ -166,10 +166,12 @@ typedef struct ProcessClass_ { #define ONE_K 1024L #define ONE_M (ONE_K * ONE_K) #define ONE_G (ONE_M * ONE_K) +#define ONE_T ((long long)ONE_G * ONE_K) #define ONE_DECIMAL_K 1000L #define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K) #define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K) +#define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K) extern char Process_pidFormat[20]; From 9139d29bbbd8b00fb43cb73ecd21aba4897b5e01 Mon Sep 17 00:00:00 2001 From: Ukiah Smith Date: Sat, 26 Jan 2019 09:56:19 -0500 Subject: [PATCH 018/411] chore: add clarification to the docs --- README | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README b/README index 33a8739eb..112da1c7d 100644 --- a/README +++ b/README @@ -38,7 +38,8 @@ Compilation instructions ------------------------ This program is distributed as a standard autotools-based package. -See the [INSTALL](/INSTALL) file for detailed instructions. +For detailed instructions see the [INSTALL](/INSTALL) file, which +is created after `./autogen.sh` is run. When compiling from a [release tarball](https://hisham.hm/htop/releases/), run: From a360a80d1608602f9b03abf14db630595488cb37 Mon Sep 17 00:00:00 2001 From: wurongxin Date: Tue, 29 Jan 2019 12:45:30 +0800 Subject: [PATCH 019/411] fix a bug about use of unitialised variable. refer to https://github.com/hishamhm/htop/issues/882 --- InfoScreen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InfoScreen.c b/InfoScreen.c index fab8daeaf..1823f3667 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -135,7 +135,7 @@ void InfoScreen_run(InfoScreen* this) { if (mevent.y >= panel->y && mevent.y < LINES - 1) { Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV); ch = 0; - } if (mevent.y == LINES - 1) + } else if (mevent.y == LINES - 1) ch = IncSet_synthesizeEvent(this->inc, mevent.x); } From 7c62db73fc8e544692a903e5f391751a3561a71b Mon Sep 17 00:00:00 2001 From: solanav Date: Thu, 31 Jan 2019 00:25:08 +0100 Subject: [PATCH 020/411] User option "-u" now defaults to $USER --- htop.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/htop.c b/htop.c index 8c88c782a..f38de6d0a 100644 --- a/htop.c +++ b/htop.c @@ -43,7 +43,7 @@ static void printHelpFlag() { "-h --help Print this help screen\n" "-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n" "-t --tree Show the tree view by default\n" - "-u --user=USERNAME Show only processes of a given user\n" + "-u --user=USERNAME Show only processes of a given user. If no username is given, it defaults to $USER.\n" "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n" "-v --version Print version info\n" "\n" @@ -82,7 +82,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { {"version", no_argument, 0, 'v'}, {"delay", required_argument, 0, 'd'}, {"sort-key", required_argument, 0, 's'}, - {"user", required_argument, 0, 'u'}, + {"user", optional_argument, 0, 'u'}, {"no-color", no_argument, 0, 'C'}, {"no-colour",no_argument, 0, 'C'}, {"tree", no_argument, 0, 't'}, @@ -92,7 +92,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { int opt, opti=0; /* Parse arguments */ - while ((opt = getopt_long(argc, argv, "hvCs:td:u:p:", long_opts, &opti))) { + while ((opt = getopt_long(argc, argv, "hvCs:td:u::p:", long_opts, &opti))) { if (opt == EOF) break; switch (opt) { case 'h': @@ -123,6 +123,15 @@ static CommandLineSettings parseArguments(int argc, char** argv) { } break; case 'u': + if(!optarg && optind < argc && argv[optind] != NULL && argv[optind][0] != '\0' && argv[optind][0] != '-') { + optarg = argv[optind++]; + } + + if (!optarg) { + optarg = getenv("USER"); + flags.userId = geteuid(); + } + if (!Action_setUserOnly(optarg, &(flags.userId))) { fprintf(stderr, "Error: invalid user \"%s\".\n", optarg); } From 6194c8dcc678a38abf34e5def18a47f6a80042aa Mon Sep 17 00:00:00 2001 From: Ricardo Nabinger Sanchez Date: Thu, 7 Feb 2019 10:39:08 -0200 Subject: [PATCH 021/411] Honour setting of counting CPUs from 0/1 when presenting meters In the listing of Available Meters for CPUs, the list of CPUs is always presented by counting them from one. However, if the user prefers to count CPUs from zero, this is sometimes confusing when fine-tuning the meters. --- AvailableMetersPanel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index ddb553679..40534bb7e 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -127,7 +127,7 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade Panel_add(super, (Object*) ListItem_new("CPU average", 0)); for (int i = 1; i <= cpus; i++) { char buffer[50]; - xSnprintf(buffer, 50, "%s %d", type->uiName, i); + xSnprintf(buffer, 50, "%s %d", type->uiName, Settings_cpuId(this->settings, i - 1)); Panel_add(super, (Object*) ListItem_new(buffer, i)); } } else { From 6f161e60e137730f3b04906e1d4cd3d2fbded1a7 Mon Sep 17 00:00:00 2001 From: wangqr Date: Sat, 10 Nov 2018 21:03:33 -0500 Subject: [PATCH 022/411] Restore meter name after used in Header_addMeterByName() Fix #852 --- Header.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Header.c b/Header.c index e048ee556..1f0028f73 100644 --- a/Header.c +++ b/Header.c @@ -120,6 +120,8 @@ MeterModeId Header_addMeterByName(Header* this, char* name, int column) { break; } } + if (paren) + *paren = '('; return mode; } From da60309fc9ed6f75dfa84d6cbfe58c703e2944f3 Mon Sep 17 00:00:00 2001 From: wangqr Date: Sun, 11 Nov 2018 00:48:08 -0500 Subject: [PATCH 023/411] Don't follow process when selecting non-process-specific options Disable the follow process logic in Action_pickFromVector(), when selecting sort order or user filter, since they don't apply on specific process. Fix #856 --- Action.c | 27 ++++++++++++++++----------- Action.h | 2 +- linux/Platform.c | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Action.c b/Action.c index 9a7c3c560..6c9a6b9a9 100644 --- a/Action.c +++ b/Action.c @@ -62,7 +62,7 @@ typedef struct State_ { }*/ -Object* Action_pickFromVector(State* st, Panel* list, int x) { +Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) { Panel* panel = st->panel; Header* header = st->header; Settings* settings = st->settings; @@ -75,8 +75,8 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) { Panel* panelFocus; int ch; bool unfollow = false; - int pid = MainPanel_selectedPid((MainPanel*)panel); - if (header->pl->following == -1) { + int pid = followProcess ? MainPanel_selectedPid((MainPanel*)panel) : -1; + if (followProcess && header->pl->following == -1) { header->pl->following = pid; unfollow = true; } @@ -88,11 +88,16 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) { Panel_move(panel, 0, y); Panel_resize(panel, COLS, LINES-y-1); if (panelFocus == list && ch == 13) { - Process* selected = (Process*)Panel_getSelected(panel); - if (selected && selected->pid == pid) + if (followProcess) { + Process* selected = (Process*)Panel_getSelected(panel); + if (selected && selected->pid == pid) + return Panel_getSelected(list); + else + beep(); + } else { return Panel_getSelected(list); - else - beep(); + } + } return NULL; } @@ -189,7 +194,7 @@ static Htop_Reaction sortBy(State* st) { Panel_setSelected(sortPanel, i); free(name); } - ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15); + ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false); if (field) { reaction |= Action_setSortKey(st->settings, field->key); } @@ -305,7 +310,7 @@ static Htop_Reaction actionSetAffinity(State* st) { Panel* affinityPanel = AffinityPanel_new(st->pl, affinity); Affinity_delete(affinity); - void* set = Action_pickFromVector(st, affinityPanel, 15); + void* set = Action_pickFromVector(st, affinityPanel, 15, true); if (set) { Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl); bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL); @@ -319,7 +324,7 @@ static Htop_Reaction actionSetAffinity(State* st) { static Htop_Reaction actionKill(State* st) { Panel* signalsPanel = (Panel*) SignalsPanel_new(); - ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15); + ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true); if (sgn) { if (sgn->key != 0) { Panel_setHeader(st->panel, "Sending..."); @@ -340,7 +345,7 @@ static Htop_Reaction actionFilterByUser(State* st) { Vector_insertionSort(usersPanel->items); ListItem* allUsers = ListItem_new("All users", -1); Panel_insert(usersPanel, 0, (Object*) allUsers); - ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20); + ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, false); if (picked) { if (picked == allUsers) { st->pl->userId = -1; diff --git a/Action.h b/Action.h index 1dfdcb476..144a44fdb 100644 --- a/Action.h +++ b/Action.h @@ -39,7 +39,7 @@ typedef struct State_ { } State; -Object* Action_pickFromVector(State* st, Panel* list, int x); +Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess); // ---------------------------------------- diff --git a/linux/Platform.c b/linux/Platform.c index ab90ca74b..13dec2776 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -93,7 +93,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) { if (!p) return HTOP_OK; IOPriority ioprio = p->ioPriority; Panel* ioprioPanel = IOPriorityPanel_new(ioprio); - void* set = Action_pickFromVector(st, ioprioPanel, 21); + void* set = Action_pickFromVector(st, ioprioPanel, 21, true); if (set) { IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel); bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio }, NULL); From 08feb8585bb4aa4bb9b1cc0025a57658f95ef437 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 11 Feb 2019 20:04:12 +0200 Subject: [PATCH 024/411] Add pressure stall information (PSI) meters on Linux The pressure stall information (PSI) metrics provide useful information on delays caused by waiting for CPU, IO and memory. Particularly on busy servers it can provide a quick overview of what's "slowing things down". This feature is supported on Linux >= 4.20. The interface is documented here: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/Documentation/accounting/psi.txt These links provide rationale: https://lwn.net/Articles/759781/ https://facebookmicrosites.github.io/psi/ The following metrics are added, corresponding to the currently exposed lines (see `head /proc/pressure/*`): - PressureStallCPUSome - PressureStallIOSome - PressureStallIOFull - PressureStallMemorySome - PressureStallMemoryFull The color scheme is the same as that used for Load Average, however I gave it separate entries just in case someone wants to change them specifically. Tested on 4.20.7-arch1-1-ARCH, on the linux platform. Also tested that other platforms still compile (changed configure to use the unsupported platform). Closes #879. --- CRT.c | 21 ++++++ CRT.h | 3 + Makefile.am | 6 +- linux/Platform.c | 24 +++++++ linux/Platform.h | 2 + linux/PressureStallMeter.c | 133 +++++++++++++++++++++++++++++++++++++ linux/PressureStallMeter.h | 25 +++++++ 7 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 linux/PressureStallMeter.c create mode 100644 linux/PressureStallMeter.h diff --git a/CRT.c b/CRT.c index ca9a10dd8..ab0081502 100644 --- a/CRT.c +++ b/CRT.c @@ -128,6 +128,9 @@ typedef enum ColorElements_ { CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, + PRESSURE_STALL_TEN, + PRESSURE_STALL_SIXTY, + PRESSURE_STALL_THREEHUNDRED, LAST_COLORELEMENT } ColorElements; @@ -232,6 +235,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Magenta,Black), [CPU_STEAL] = ColorPair(Cyan,Black), [CPU_GUEST] = ColorPair(Cyan,Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan,Black), + [PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan,Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Black), }, [COLORSCHEME_MONOCHROME] = { [RESET_COLOR] = A_NORMAL, @@ -291,6 +297,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = A_BOLD, [CPU_STEAL] = A_REVERSE, [CPU_GUEST] = A_REVERSE, + [PRESSURE_STALL_THREEHUNDRED] = A_DIM, + [PRESSURE_STALL_SIXTY] = A_NORMAL, + [PRESSURE_STALL_TEN] = A_BOLD, }, [COLORSCHEME_BLACKONWHITE] = { [RESET_COLOR] = ColorPair(Black,White), @@ -350,6 +359,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Blue,White), [CPU_STEAL] = ColorPair(Cyan,White), [CPU_GUEST] = ColorPair(Cyan,White), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,White), + [PRESSURE_STALL_SIXTY] = ColorPair(Black,White), + [PRESSURE_STALL_TEN] = ColorPair(Black,White), }, [COLORSCHEME_LIGHTTERMINAL] = { [RESET_COLOR] = ColorPair(Black,Black), @@ -409,6 +421,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Blue,Black), [CPU_STEAL] = ColorPair(Black,Black), [CPU_GUEST] = ColorPair(Black,Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Black,Black), + [PRESSURE_STALL_TEN] = ColorPair(Black,Black), }, [COLORSCHEME_MIDNIGHT] = { [RESET_COLOR] = ColorPair(White,Blue), @@ -468,6 +483,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Black,Blue), [CPU_STEAL] = ColorPair(White,Blue), [CPU_GUEST] = ColorPair(White,Blue), + [PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black,Blue), + [PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White,Blue), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Blue), }, [COLORSCHEME_BLACKNIGHT] = { [RESET_COLOR] = ColorPair(Cyan,Black), @@ -527,6 +545,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Blue,Black), [CPU_STEAL] = ColorPair(Cyan,Black), [CPU_GUEST] = ColorPair(Cyan,Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green,Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Green,Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green,Black), }, [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. }; diff --git a/CRT.h b/CRT.h index 933fe068e..2fdc66920 100644 --- a/CRT.h +++ b/CRT.h @@ -116,6 +116,9 @@ typedef enum ColorElements_ { CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, + PRESSURE_STALL_TEN, + PRESSURE_STALL_SIXTY, + PRESSURE_STALL_THREEHUNDRED, LAST_COLORELEMENT } ColorElements; diff --git a/Makefile.am b/Makefile.am index 7d19600f6..5602fde75 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,14 +48,16 @@ linux_platform_headers = \ linux/LinuxProcess.h \ linux/LinuxProcessList.h \ linux/LinuxCRT.h \ - linux/Battery.h + linux/Battery.h \ + linux/PressureStallMeter.h all_platform_headers += $(linux_platform_headers) if HTOP_LINUX AM_CFLAGS += -rdynamic myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ -linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c +linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \ +linux/PressureStallMeter.c myhtopplatheaders = $(linux_platform_headers) endif diff --git a/linux/Platform.c b/linux/Platform.c index ab90ca74b..45582f911 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -19,6 +19,7 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "LoadAverageMeter.h" #include "UptimeMeter.h" +#include "PressureStallMeter.h" #include "ClockMeter.h" #include "HostnameMeter.h" #include "LinuxProcess.h" @@ -126,6 +127,11 @@ MeterClass* Platform_meterTypes[] = { &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &BlankMeter_class, + &PressureStallCPUSomeMeter_class, + &PressureStallIOSomeMeter_class, + &PressureStallIOFullMeter_class, + &PressureStallMemorySomeMeter_class, + &PressureStallMemoryFullMeter_class, NULL }; @@ -237,3 +243,21 @@ char* Platform_getProcessEnv(pid_t pid) { } return env; } + +void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred) { + *ten = *sixty = *threehundred = 0; + char procname[128+1]; + xSnprintf(procname, 128, PROCDIR "/pressure/%s", file); + FILE *fd = fopen(procname, "r"); + if (!fd) { + *ten = *sixty = *threehundred = NAN; + return; + } + int total = fscanf(fd, "some avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred); + if (!some) { + total = fscanf(fd, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred); + } + (void) total; + assert(total == 3); + fclose(fd); +} diff --git a/linux/Platform.h b/linux/Platform.h index b0456e5b5..129bc07ba 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -45,4 +45,6 @@ void Platform_setSwapValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); + #endif diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c new file mode 100644 index 000000000..56055bff3 --- /dev/null +++ b/linux/PressureStallMeter.c @@ -0,0 +1,133 @@ +/* +htop - PressureStallMeter.c +(C) 2004-2011 Hisham H. Muhammad +(C) 2019 Ran Benita +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "PressureStallMeter.h" +#include "Platform.h" +#include "CRT.h" + +#include + +/*{ +#include "Meter.h" +}*/ + +static int PressureStallMeter_attributes[] = { + PRESSURE_STALL_TEN, PRESSURE_STALL_SIXTY, PRESSURE_STALL_THREEHUNDRED +}; + +static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) { + const char *file; + if (strstr(Meter_name(this), "CPU")) { + file = "cpu"; + } else if (strstr(Meter_name(this), "IO")) { + file = "io"; + } else { + file = "memory"; + } + + bool some; + if (strstr(Meter_name(this), "Some")) { + some = true; + } else { + some = false; + } + + Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]); + xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]); +} + +static void PressureStallMeter_display(Object* cast, RichString* out) { + Meter* this = (Meter*)cast; + char buffer[20]; + xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]); + RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer); + xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[1]); + RichString_append(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer); + xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[2]); + RichString_append(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer); +} + +MeterClass PressureStallCPUSomeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallCPUSome", + .uiName = "Pressure Stall Information, some CPU", + .caption = "Some CPU pressure: " +}; + +MeterClass PressureStallIOSomeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallIOSome", + .uiName = "Pressure Stall Information, some IO", + .caption = "Some IO pressure: " +}; + +MeterClass PressureStallIOFullMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallIOFull", + .uiName = "Pressure Stall Information, full IO", + .caption = "Full IO pressure: " +}; + +MeterClass PressureStallMemorySomeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallMemorySome", + .uiName = "Pressure Stall Information, some memory", + .caption = "Some Mem pressure: " +}; + +MeterClass PressureStallMemoryFullMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallMemoryFull", + .uiName = "Pressure Stall Information, full memory", + .caption = "Full Mem pressure: " +}; diff --git a/linux/PressureStallMeter.h b/linux/PressureStallMeter.h new file mode 100644 index 000000000..22b8b9724 --- /dev/null +++ b/linux/PressureStallMeter.h @@ -0,0 +1,25 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_PressureStallMeter +#define HEADER_PressureStallMeter +/* +htop - PressureStallMeter.h +(C) 2004-2011 Hisham H. Muhammad +(C) 2019 Ran Benita +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern MeterClass PressureStallCPUSomeMeter_class; + +extern MeterClass PressureStallIOSomeMeter_class; + +extern MeterClass PressureStallIOFullMeter_class; + +extern MeterClass PressureStallMemorySomeMeter_class; + +extern MeterClass PressureStallMemoryFullMeter_class; + +#endif From 43875d94c981e54181866d1c2109353ae8c181d9 Mon Sep 17 00:00:00 2001 From: scootergrisen Date: Tue, 19 Feb 2019 01:25:52 +0100 Subject: [PATCH 025/411] Add danish translation to htop.desktop --- htop.desktop | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htop.desktop b/htop.desktop index d59a26508..20bed4902 100644 --- a/htop.desktop +++ b/htop.desktop @@ -4,6 +4,7 @@ Version=1.0 Name=Htop GenericName=Process Viewer GenericName[ca]=Visualitzador de processos +GenericName[da]=Procesfremviser GenericName[de]=Prozessanzeige GenericName[en_GB]=Process Viewer GenericName[es]=Visor de procesos @@ -32,6 +33,7 @@ GenericName[zh_CN]=进程查看器 GenericName[zh_TW]=行程檢視器 Comment=Show System Processes Comment[ca]=Visualitzeu els processos del sistema +Comment[da]=Vis systemprocesser Comment[de]=Systemprozesse anzeigen Comment[en_GB]=Show System Processes Comment[es]=Mostrar procesos del sistema From fc0bf546c3ceb03fedb08253756cae63d15499b5 Mon Sep 17 00:00:00 2001 From: Alexander Schlarb Date: Tue, 9 Oct 2018 21:49:29 +0200 Subject: [PATCH 026/411] Linux: Add PSS (proportional set size), Swap and SwapPSS calculation Original code was written by *Craig M. Brandenburg* for htop 1.0.2 Many performance improvements by GitHub user *linvinus*, ported to htop 2.0.2 --- linux/LinuxProcess.c | 21 ++++++++++++- linux/LinuxProcess.h | 9 +++++- linux/LinuxProcessList.c | 67 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 5f697078f..6b48780b3 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -24,6 +24,7 @@ in the source distribution for its full text. #define PROCESS_FLAG_LINUX_VSERVER 0x0400 #define PROCESS_FLAG_LINUX_CGROUP 0x0800 #define PROCESS_FLAG_LINUX_OOM 0x1000 +#define PROCESS_FLAG_LINUX_SMAPS 0x2000 typedef enum UnsupportedProcessFields { FLAGS = 9, @@ -87,7 +88,10 @@ typedef enum LinuxProcessFields { PERCENT_IO_DELAY = 117, PERCENT_SWAP_DELAY = 118, #endif - LAST_PROCESSFIELD = 119, + M_PSS = 119, + M_SWAP = 120, + M_PSSWP = 121, + LAST_PROCESSFIELD = 122, } LinuxProcessField; #include "IOPriority.h" @@ -103,6 +107,9 @@ typedef struct LinuxProcess_ { unsigned long long int cutime; unsigned long long int cstime; long m_share; + long m_pss; + long m_swap; + long m_psswp; long m_trs; long m_drs; long m_lrs; @@ -239,6 +246,9 @@ ProcessFieldData Process_fields[] = { [PERCENT_IO_DELAY] = { .name = "PERCENT_IO_DELAY", .title = "IOD% ", .description = "Block I/O delay %", .flags = 0, }, [PERCENT_SWAP_DELAY] = { .name = "PERCENT_SWAP_DELAY", .title = "SWAPD% ", .description = "Swapin delay %", .flags = 0, }, #endif + [M_PSS] = { .name = "M_PSS", .title = " PSS ", .description = "proportional set size, same as M_RESIDENT but each page is divided by the number of processes sharing it.", .flags = PROCESS_FLAG_LINUX_SMAPS, }, + [M_SWAP] = { .name = "M_SWAP", .title = " SWAP ", .description = "Size of the process's swapped pages", .flags = PROCESS_FLAG_LINUX_SMAPS, }, + [M_PSSWP] = { .name = "M_PSSWP", .title = " PSSWP ", .description = "shows proportional swap share of this mapping, Unlike \"Swap\", this does not take into account swapped out page of underlying shmem objects.", .flags = PROCESS_FLAG_LINUX_SMAPS, }, [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, }; @@ -344,6 +354,9 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) case M_LRS: Process_humanNumber(str, lp->m_lrs * PAGE_SIZE_KB, coloring); return; case M_TRS: Process_humanNumber(str, lp->m_trs * PAGE_SIZE_KB, coloring); return; case M_SHARE: Process_humanNumber(str, lp->m_share * PAGE_SIZE_KB, coloring); return; + case M_PSS: Process_humanNumber(str, lp->m_pss, coloring); return; + case M_SWAP: Process_humanNumber(str, lp->m_swap, coloring); return; + case M_PSSWP: Process_humanNumber(str, lp->m_psswp, coloring); return; case UTIME: Process_printTime(str, lp->utime); return; case STIME: Process_printTime(str, lp->stime); return; case CUTIME: Process_printTime(str, lp->cutime); return; @@ -435,6 +448,12 @@ long LinuxProcess_compare(const void* v1, const void* v2) { return (p2->m_trs - p1->m_trs); case M_SHARE: return (p2->m_share - p1->m_share); + case M_PSS: + return (p2->m_pss - p1->m_pss); + case M_SWAP: + return (p2->m_swap - p1->m_swap); + case M_PSSWP: + return (p2->m_psswp - p1->m_psswp); case UTIME: diff = p2->utime - p1->utime; goto test_diff; case CUTIME: diff = p2->cutime - p1->cutime; goto test_diff; case STIME: diff = p2->stime - p1->stime; goto test_diff; diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 6ce3037d2..6b074ac98 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -15,6 +15,7 @@ in the source distribution for its full text. #define PROCESS_FLAG_LINUX_VSERVER 0x0400 #define PROCESS_FLAG_LINUX_CGROUP 0x0800 #define PROCESS_FLAG_LINUX_OOM 0x1000 +#define PROCESS_FLAG_LINUX_SMAPS 0x2000 typedef enum UnsupportedProcessFields { FLAGS = 9, @@ -78,7 +79,10 @@ typedef enum LinuxProcessFields { PERCENT_IO_DELAY = 117, PERCENT_SWAP_DELAY = 118, #endif - LAST_PROCESSFIELD = 119, + M_PSS = 119, + M_SWAP = 120, + M_PSSWP = 121, + LAST_PROCESSFIELD = 122, } LinuxProcessField; #include "IOPriority.h" @@ -94,6 +98,9 @@ typedef struct LinuxProcess_ { unsigned long long int cutime; unsigned long long int cstime; long m_share; + long m_pss; + long m_swap; + long m_psswp; long m_trs; long m_drs; long m_lrs; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5f38540c6..a02da072c 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -486,6 +486,58 @@ static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* di return (errno == 0); } +static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* dirname, const char* name) { + //http://elixir.free-electrons.com/linux/v4.10/source/fs/proc/task_mmu.c#L719 + //kernel will return data in chunks of size PAGE_SIZE or less. + + char buffer[PAGE_SIZE];// 4k + char *start,*end; + ssize_t nread=0; + int tmp=0; + snprintf(buffer, MAX_NAME, "%s/%s/smaps", dirname, name); + int fd = open(buffer, O_RDONLY); + if (fd == -1) + return false; + + process->m_pss = 0; + process->m_swap = 0; + process->m_psswp = 0; + + while ( ( nread = read(fd,buffer, sizeof(buffer)) ) > 0 ){ + start = (char *)&buffer; + end = start + nread; + do{//parse 4k block + + if( (tmp = (end - start)) > 0 && + (start = memmem(start,tmp,"\nPss:",5)) != NULL ) + { + process->m_pss += strtol(start+5, &start, 10); + start += 3;//now we must be at the end of line "Pss: 0 kB" + }else + break; //read next 4k block + + if( (tmp = (end - start)) > 0 && + (start = memmem(start,tmp,"\nSwap:",6)) != NULL ) + { + process->m_swap += strtol(start+6, &start, 10); + start += 3; + }else + break; + + if( (tmp = (end - start)) > 0 && + (start = memmem(start,tmp,"\nSwapPss:",9)) != NULL ) + { + process->m_psswp += strtol(start+9, &start, 10); + start += 3; + }else + break; + + }while(1); + }//while read + close(fd); + return true; +} + #ifdef HAVE_OPENVZ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* dirname, const char* name) { @@ -815,6 +867,21 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* if (! LinuxProcessList_readStatmFile(lp, dirname, name)) goto errorReadingProcess; + if ((settings->flags & PROCESS_FLAG_LINUX_SMAPS) && !Process_isKernelThread(proc)){ + if (!parent){ + // Read smaps file of each process only every second pass to improve performance + static int smaps_flag = 0; + if ((pid & 1) == smaps_flag){ + LinuxProcessList_readSmapsFile(lp, dirname, name); + } + if (pid == 1) { + smaps_flag = !smaps_flag; + } + } else { + lp->m_pss = ((LinuxProcess*)parent)->m_pss; + } + } + proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); char command[MAX_NAME+1]; From 078c2ddde5a64a8a9b3bcf40d62e1f81477db029 Mon Sep 17 00:00:00 2001 From: Alexander Schlarb Date: Tue, 16 Oct 2018 20:08:23 +0200 Subject: [PATCH 027/411] Linux: Use /proc/*/smaps_rollup for improved PSS parsing speed --- linux/LinuxProcessList.c | 20 +++++++++++++++++--- linux/LinuxProcessList.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index a02da072c..c1ccd4202 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -89,6 +89,7 @@ typedef struct LinuxProcessList_ { CPUData* cpus; TtyDriver* ttyDrivers; + bool haveSmapsRollup; #ifdef HAVE_DELAYACCT struct nl_sock *netlink_socket; @@ -240,8 +241,17 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui LinuxProcessList_initNetlinkSocket(this); #endif + // Check for /proc/*/smaps_rollup availability (improves smaps parsing speed, Linux 4.14+) + FILE* file = fopen(PROCDIR "/self/smaps_rollup", "r"); + if(file != NULL) { + this->haveSmapsRollup = true; + fclose(file); + } else { + this->haveSmapsRollup = false; + } + // Update CPU count: - FILE* file = fopen(PROCSTATFILE, "r"); + file = fopen(PROCSTATFILE, "r"); if (file == NULL) { CRT_fatalError("Cannot open " PROCSTATFILE); } @@ -486,7 +496,7 @@ static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* di return (errno == 0); } -static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* dirname, const char* name) { +static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* dirname, const char* name, bool haveSmapsRollup) { //http://elixir.free-electrons.com/linux/v4.10/source/fs/proc/task_mmu.c#L719 //kernel will return data in chunks of size PAGE_SIZE or less. @@ -494,7 +504,11 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di char *start,*end; ssize_t nread=0; int tmp=0; + if(haveSmapsRollup) {// only available in Linux 4.14+ + snprintf(buffer, MAX_NAME, "%s/%s/smaps_rollup", dirname, name); + } else { snprintf(buffer, MAX_NAME, "%s/%s/smaps", dirname, name); + } int fd = open(buffer, O_RDONLY); if (fd == -1) return false; @@ -872,7 +886,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* // Read smaps file of each process only every second pass to improve performance static int smaps_flag = 0; if ((pid & 1) == smaps_flag){ - LinuxProcessList_readSmapsFile(lp, dirname, name); + LinuxProcessList_readSmapsFile(lp, dirname, name, this->haveSmapsRollup); } if (pid == 1) { smaps_flag = !smaps_flag; diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index f30b487d6..59e83bcb1 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -62,6 +62,7 @@ typedef struct LinuxProcessList_ { CPUData* cpus; TtyDriver* ttyDrivers; + bool haveSmapsRollup; #ifdef HAVE_DELAYACCT struct nl_sock *netlink_socket; From fabe75685a8c1691d50bc2843ff0a49802997c04 Mon Sep 17 00:00:00 2001 From: Robert Crowston Date: Wed, 17 Apr 2019 10:06:37 +0100 Subject: [PATCH 028/411] Truncate overwide jail names on BSD. --- dragonflybsd/DragonFlyBSDProcess.c | 2 +- freebsd/FreeBSDProcess.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index dade106d0..11a86aada 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -121,7 +121,7 @@ void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField case PID: xSnprintf(buffer, n, Process_pidFormat, (fp->kernel ? -1 : this->pid)); break; case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break; case JAIL:{ - xSnprintf(buffer, n, "%-11s ", fp->jname); break; + xSnprintf(buffer, n, "%-11s ", fp->jname); if (buffer[11] != '\0') { buffer[11] = ' '; buffer[12] = '\0'; diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index f81fadf50..3d434eb78 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -119,7 +119,7 @@ void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel // add FreeBSD-specific fields here case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break; case JAIL:{ - xSnprintf(buffer, n, "%-11s ", fp->jname); break; + xSnprintf(buffer, n, "%-11s ", fp->jname); if (buffer[11] != '\0') { buffer[11] = ' '; buffer[12] = '\0'; From c3fadf6b695645175c557c3fc45c4c67137f4952 Mon Sep 17 00:00:00 2001 From: Mario Harjac Date: Mon, 29 Apr 2019 15:17:05 +0200 Subject: [PATCH 029/411] Add timestamps to the strace screen --- TraceScreen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TraceScreen.c b/TraceScreen.c index 91f71ae8b..b4b8436b1 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -101,7 +101,7 @@ bool TraceScreen_forkTracer(TraceScreen* this) { int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK); if (ok != -1) { xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid); - execlp("strace", "strace", "-s", "512", "-p", buffer, NULL); + execlp("strace", "strace", "-T", "-tt", "-s", "512", "-p", buffer, NULL); } const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH."; ssize_t written = write(this->fdpair[1], message, strlen(message)); From 131a6c6e2bf232ce4c1aca80e4a35a6175e059ba Mon Sep 17 00:00:00 2001 From: senjan Date: Sun, 26 May 2019 21:20:00 +0200 Subject: [PATCH 030/411] CPU_KERNEL redefined --- Action.c | 4 ++-- CPUMeter.c | 6 +++--- CRT.c | 14 +++++++------- CRT.h | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Action.c b/Action.c index 9a7c3c560..fbbeee2b9 100644 --- a/Action.c +++ b/Action.c @@ -463,7 +463,7 @@ static Htop_Reaction actionHelp(State* st) { if (settings->detailedCPUTime) { addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/"); addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/"); - addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/"); + addattrstr(CRT_colors[CPU_KRNL], "kernel"); addstr("/"); addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/"); addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/"); addattrstr(CRT_colors[CPU_STEAL], "steal"); addstr("/"); @@ -473,7 +473,7 @@ static Htop_Reaction actionHelp(State* st) { } else { addattrstr(CRT_colors[CPU_NICE_TEXT], "low-priority"); addstr("/"); addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/"); - addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/"); + addattrstr(CRT_colors[CPU_KRNL], "kernel"); addstr("/"); addattrstr(CRT_colors[CPU_GUEST], "virtualiz"); addattrstr(CRT_colors[BAR_SHADOW], " used%"); } diff --git a/CPUMeter.c b/CPUMeter.c index de5490df1..36c3b2ca4 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -34,7 +34,7 @@ typedef enum { }*/ int CPUMeter_attributes[] = { - CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT + CPU_NICE, CPU_NORMAL, CPU_KRNL, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT }; #ifndef MIN @@ -80,7 +80,7 @@ static void CPUMeter_display(Object* cast, RichString* out) { if (this->pl->settings->detailedCPUTime) { xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]); RichString_append(out, CRT_colors[METER_TEXT], "sy:"); - RichString_append(out, CRT_colors[CPU_KERNEL], buffer); + RichString_append(out, CRT_colors[CPU_KRNL], buffer); xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]); RichString_append(out, CRT_colors[METER_TEXT], "ni:"); RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer); @@ -106,7 +106,7 @@ static void CPUMeter_display(Object* cast, RichString* out) { } else { xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]); RichString_append(out, CRT_colors[METER_TEXT], "sys:"); - RichString_append(out, CRT_colors[CPU_KERNEL], buffer); + RichString_append(out, CRT_colors[CPU_KRNL], buffer); xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]); RichString_append(out, CRT_colors[METER_TEXT], "low:"); RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer); diff --git a/CRT.c b/CRT.c index ca9a10dd8..d46d389ce 100644 --- a/CRT.c +++ b/CRT.c @@ -122,7 +122,7 @@ typedef enum ColorElements_ { CPU_NICE, CPU_NICE_TEXT, CPU_NORMAL, - CPU_KERNEL, + CPU_KRNL, CPU_IOWAIT, CPU_IRQ, CPU_SOFTIRQ, @@ -226,7 +226,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE] = ColorPair(Blue,Black), [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black), [CPU_NORMAL] = ColorPair(Green,Black), - [CPU_KERNEL] = ColorPair(Red,Black), + [CPU_KRNL] = ColorPair(Red,Black), [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black), [CPU_IRQ] = ColorPair(Yellow,Black), [CPU_SOFTIRQ] = ColorPair(Magenta,Black), @@ -285,7 +285,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE] = A_NORMAL, [CPU_NICE_TEXT] = A_NORMAL, [CPU_NORMAL] = A_BOLD, - [CPU_KERNEL] = A_BOLD, + [CPU_KRNL] = A_BOLD, [CPU_IOWAIT] = A_NORMAL, [CPU_IRQ] = A_BOLD, [CPU_SOFTIRQ] = A_BOLD, @@ -344,7 +344,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE] = ColorPair(Cyan,White), [CPU_NICE_TEXT] = ColorPair(Cyan,White), [CPU_NORMAL] = ColorPair(Green,White), - [CPU_KERNEL] = ColorPair(Red,White), + [CPU_KRNL] = ColorPair(Red,White), [CPU_IOWAIT] = A_BOLD | ColorPair(Black, White), [CPU_IRQ] = ColorPair(Blue,White), [CPU_SOFTIRQ] = ColorPair(Blue,White), @@ -403,7 +403,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE] = ColorPair(Cyan,Black), [CPU_NICE_TEXT] = ColorPair(Cyan,Black), [CPU_NORMAL] = ColorPair(Green,Black), - [CPU_KERNEL] = ColorPair(Red,Black), + [CPU_KRNL] = ColorPair(Red,Black), [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black), [CPU_IRQ] = A_BOLD | ColorPair(Blue,Black), [CPU_SOFTIRQ] = ColorPair(Blue,Black), @@ -462,7 +462,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE] = A_BOLD | ColorPair(Cyan,Blue), [CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan,Blue), [CPU_NORMAL] = A_BOLD | ColorPair(Green,Blue), - [CPU_KERNEL] = A_BOLD | ColorPair(Red,Blue), + [CPU_KRNL] = A_BOLD | ColorPair(Red,Blue), [CPU_IOWAIT] = A_BOLD | ColorPair(Blue,Blue), [CPU_IRQ] = A_BOLD | ColorPair(Black,Blue), [CPU_SOFTIRQ] = ColorPair(Black,Blue), @@ -521,7 +521,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE] = ColorPair(Blue,Black), [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black), [CPU_NORMAL] = ColorPair(Green,Black), - [CPU_KERNEL] = ColorPair(Red,Black), + [CPU_KRNL] = ColorPair(Red,Black), [CPU_IOWAIT] = ColorPair(Yellow,Black), [CPU_IRQ] = A_BOLD | ColorPair(Blue,Black), [CPU_SOFTIRQ] = ColorPair(Blue,Black), diff --git a/CRT.h b/CRT.h index 933fe068e..003312233 100644 --- a/CRT.h +++ b/CRT.h @@ -110,7 +110,7 @@ typedef enum ColorElements_ { CPU_NICE, CPU_NICE_TEXT, CPU_NORMAL, - CPU_KERNEL, + CPU_KRNL, CPU_IOWAIT, CPU_IRQ, CPU_SOFTIRQ, From 423414937b0d1f13b991d6ae0792e0c576841bfb Mon Sep 17 00:00:00 2001 From: senjan Date: Sun, 26 May 2019 21:20:35 +0200 Subject: [PATCH 031/411] does not work within NGZ --- solaris/SolarisProcessList.c | 8 +++++--- solaris/SolarisProcessList.h | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 2c681852b..255f0096e 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -25,6 +25,8 @@ in the source distribution for its full text. #define MAXCMDLINE 255 +#define GZONE "global " +#define UZONE "unknown " /*{ #include @@ -62,12 +64,12 @@ typedef struct SolarisProcessList_ { char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { char* zname; if ( sproc->zoneid == 0 ) { - zname = xStrdup("global "); + zname = xStrdup(GZONE); } else if ( kd == NULL ) { - zname = xStrdup("unknown "); + zname = xStrdup(UZONE); } else { kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL ); - zname = xStrdup(ks->ks_name); + zname = xStrdup(ks == NULL ? UZONE : ks->ks_name); } return zname; } diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index a5f2fbc25..1729195c8 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -12,6 +12,8 @@ in the source distribution for its full text. #define MAXCMDLINE 255 +#define GZONE "global " +#define UZONE "unknown " #include #include From 01a1cc063f6bc5dd5b33d29013301073e3e159e9 Mon Sep 17 00:00:00 2001 From: senjan Date: Thu, 30 May 2019 16:34:30 +0200 Subject: [PATCH 032/411] fixed Linux build --- TasksMeter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TasksMeter.c b/TasksMeter.c index f56c86133..23ac83648 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -15,7 +15,7 @@ in the source distribution for its full text. }*/ int TasksMeter_attributes[] = { - CPU_KERNEL, PROCESS_THREAD, PROCESS, TASKS_RUNNING + CPU_KRNL, PROCESS_THREAD, PROCESS, TASKS_RUNNING }; static void TasksMeter_updateValues(Meter* this, char* buffer, int len) { From 351297108488d0a77f4ce666c1b7d82e6aae0831 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Sun, 30 Dec 2018 12:18:27 +0800 Subject: [PATCH 033/411] Fix configure 'major' workaround causing to miss. A logic mistake in pull request #746 causes to be *not* included when AC_HEADER_MAJOR (before autoconf-2.70) finds 'major' in . Though this would still build htop, it would still bring deprecation warning in systems using glibc 2.25-2.27. Fix the logic and suppress the warning. Also, include config.h in Process.c for the sake of strengthening the code. Signed-off-by: Kang-Che Sung --- Process.c | 2 ++ configure.ac | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Process.c b/Process.c index 54c41af4f..420311dca 100644 --- a/Process.c +++ b/Process.c @@ -8,6 +8,8 @@ in the source distribution for its full text. #include "Process.h" #include "Settings.h" +#include "config.h" + #include "CRT.h" #include "StringUtils.h" #include "RichString.h" diff --git a/configure.ac b/configure.ac index ffd8fedeb..4c7360e68 100644 --- a/configure.ac +++ b/configure.ac @@ -69,7 +69,7 @@ dnl glibc 2.25 deprecates 'major' and 'minor' in and requires to dnl include . However the logic in AC_HEADER_MAJOR has not yet dnl been updated in Autoconf 2.69, so use a workaround: m4_version_prereq([2.70], [], -[if test "x$ac_cv_header_sys_mkdev_h" = xno; then +[if test "x$ac_cv_header_sys_mkdev_h" != xyes; then AC_CHECK_HEADER(sys/sysmacros.h, [AC_DEFINE(MAJOR_IN_SYSMACROS, 1, [Define to 1 if `major', `minor', and `makedev' are declared in .])]) fi]) From 886eb681028a31d736c89f9331a8fe008e5fc5fc Mon Sep 17 00:00:00 2001 From: Jesin Date: Sun, 23 Jun 2019 13:13:05 -0400 Subject: [PATCH 034/411] Close pipe after lsof --- OpenFilesScreen.c | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 9ea333bf7..658b1866d 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -124,6 +124,7 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { item->data[cmd] = xStrdup(line + 1); free(line); } + fclose(fd); int wstatus; if (waitpid(child, &wstatus, 0) == -1) { pdata->error = 1; From 92258e99e639795f4119a86a1c44d5015b29ffdc Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Sat, 6 Jul 2019 04:27:00 +0000 Subject: [PATCH 035/411] Specify correct MIB length Could have resulted in a buffer overflow if the FreeBSD kernel returned more bytes than expected. --- freebsd/FreeBSDProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 9fef324a5..26019b689 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -121,7 +121,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui len = sizeof(fpl->memZfsArc); if (sysctlbyname("kstat.zfs.misc.arcstats.size", &fpl->memZfsArc, &len, NULL, 0) == 0 && fpl->memZfsArc != 0) { - sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); + len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); fpl->zfsArcEnabled = 1; } else { fpl->zfsArcEnabled = 0; From a93edde1a21e533472b5d443002032260b5bd066 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Sat, 6 Jul 2019 04:27:49 +0000 Subject: [PATCH 036/411] Support ZFS ARC stats on FreeBSD New meter displays same ARC stats as FreeBSD top(1). Can be extended to other platforms that support ZFS. Pulling kstat.zfs.misc.arcstats.c_max as the meter total, so the meter has a meaningful value to work up to. The Text meter displays, first, the maximum ARC size (Meter.total), then second, the total ARC used, using the difference between Meter.maxItems and Meter.curItems to "hide" the used value from the Bar and Graph drawing functions by using an index in Meter.values[] that is beyond curItems - 1, but less than maxItems - 1. --- CRT.c | 35 ++++++++++++++++ CRT.h | 5 +++ Makefile.am | 10 ++++- freebsd/FreeBSDProcessList.c | 48 ++++++++++++++++++++- freebsd/FreeBSDProcessList.h | 6 +++ freebsd/Platform.c | 19 +++++++++ freebsd/Platform.h | 2 + zfs/ZfsArcMeter.c | 81 ++++++++++++++++++++++++++++++++++++ zfs/ZfsArcMeter.h | 18 ++++++++ 9 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 zfs/ZfsArcMeter.c create mode 100644 zfs/ZfsArcMeter.h diff --git a/CRT.c b/CRT.c index ca9a10dd8..b9017aa48 100644 --- a/CRT.c +++ b/CRT.c @@ -128,6 +128,11 @@ typedef enum ColorElements_ { CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, + ZFS_MFU, + ZFS_MRU, + ZFS_ANON, + ZFS_HEADER, + ZFS_OTHER, LAST_COLORELEMENT } ColorElements; @@ -232,6 +237,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Magenta,Black), [CPU_STEAL] = ColorPair(Cyan,Black), [CPU_GUEST] = ColorPair(Cyan,Black), + [ZFS_MFU] = ColorPair(Blue,Black), + [ZFS_MRU] = ColorPair(Yellow,Black), + [ZFS_ANON] = ColorPair(Magenta,Black), + [ZFS_HEADER] = ColorPair(Cyan,Black), + [ZFS_OTHER] = ColorPair(Magenta,Black), }, [COLORSCHEME_MONOCHROME] = { [RESET_COLOR] = A_NORMAL, @@ -291,6 +301,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = A_BOLD, [CPU_STEAL] = A_REVERSE, [CPU_GUEST] = A_REVERSE, + [ZFS_MFU] = A_NORMAL, + [ZFS_MRU] = A_NORMAL, + [ZFS_ANON] = A_DIM, + [ZFS_HEADER] = A_BOLD, + [ZFS_OTHER] = A_DIM, }, [COLORSCHEME_BLACKONWHITE] = { [RESET_COLOR] = ColorPair(Black,White), @@ -350,6 +365,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Blue,White), [CPU_STEAL] = ColorPair(Cyan,White), [CPU_GUEST] = ColorPair(Cyan,White), + [ZFS_MFU] = ColorPair(Cyan,White), + [ZFS_MRU] = ColorPair(Yellow,White), + [ZFS_ANON] = ColorPair(Magenta,White), + [ZFS_HEADER] = ColorPair(Yellow,White), + [ZFS_OTHER] = ColorPair(Magenta,White), }, [COLORSCHEME_LIGHTTERMINAL] = { [RESET_COLOR] = ColorPair(Black,Black), @@ -409,6 +429,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Blue,Black), [CPU_STEAL] = ColorPair(Black,Black), [CPU_GUEST] = ColorPair(Black,Black), + [ZFS_MFU] = ColorPair(Cyan,Black), + [ZFS_MRU] = ColorPair(Yellow,Black), + [ZFS_ANON] = A_BOLD | ColorPair(Magenta,Black), + [ZFS_HEADER] = ColorPair(Black,Black), + [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black), }, [COLORSCHEME_MIDNIGHT] = { [RESET_COLOR] = ColorPair(White,Blue), @@ -468,6 +493,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Black,Blue), [CPU_STEAL] = ColorPair(White,Blue), [CPU_GUEST] = ColorPair(White,Blue), + [ZFS_MFU] = A_BOLD | ColorPair(White,Blue), + [ZFS_MRU] = A_BOLD | ColorPair(Yellow,Blue), + [ZFS_ANON] = A_BOLD | ColorPair(Magenta,Blue), + [ZFS_HEADER] = A_BOLD | ColorPair(Yellow,Blue), + [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Blue), }, [COLORSCHEME_BLACKNIGHT] = { [RESET_COLOR] = ColorPair(Cyan,Black), @@ -527,6 +557,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Blue,Black), [CPU_STEAL] = ColorPair(Cyan,Black), [CPU_GUEST] = ColorPair(Cyan,Black), + [ZFS_MFU] = ColorPair(Blue,Black), + [ZFS_MRU] = ColorPair(Yellow,Black), + [ZFS_ANON] = ColorPair(Magenta,Black), + [ZFS_HEADER] = ColorPair(Yellow,Black), + [ZFS_OTHER] = ColorPair(Magenta,Black), }, [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. }; diff --git a/CRT.h b/CRT.h index 933fe068e..2275349a0 100644 --- a/CRT.h +++ b/CRT.h @@ -116,6 +116,11 @@ typedef enum ColorElements_ { CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, + ZFS_MFU, + ZFS_MRU, + ZFS_ANON, + ZFS_HEADER, + ZFS_OTHER, LAST_COLORELEMENT } ColorElements; diff --git a/Makefile.am b/Makefile.am index 7d19600f6..ad23d19b2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,6 +36,10 @@ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \ EnvScreen.h InfoScreen.h XAlloc.h +zfs_platform_sources = zfs/ZfsArcMeter.c + +zfs_platform_headers = zfs/ZfsArcMeter.h + all_platform_headers = # Linux @@ -68,13 +72,15 @@ freebsd_platform_headers = \ freebsd/FreeBSDProcessList.h \ freebsd/FreeBSDProcess.h \ freebsd/FreeBSDCRT.h \ - freebsd/Battery.h + freebsd/Battery.h \ + $(zfs_platform_headers) all_platform_headers += $(freebsd_platform_headers) if HTOP_FREEBSD myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ -freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c +freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c \ +$(zfs_platform_sources) myhtopplatheaders = $(freebsd_platform_headers) endif diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 26019b689..94cbaa198 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -53,6 +53,12 @@ typedef struct FreeBSDProcessList_ { unsigned long long int memFree; unsigned long long int memZfsArc; + unsigned long long int zfsArcMax; + unsigned long long int zfsArcMFU; + unsigned long long int zfsArcMRU; + unsigned long long int zFsArcAnon; + unsigned long long int zFsArcHeader; + unsigned long long int zFsArcOther; CPUData* cpus; @@ -81,6 +87,12 @@ static int MIB_vm_stats_vm_v_free_count[4]; static int MIB_vfs_bufspace[2]; static int MIB_kstat_zfs_misc_arcstats_size[5]; +static int MIB_vfs_zfs_arc_max[3]; +static int MIB_kstat_zfs_misc_arcstats_mfu_size[5]; +static int MIB_kstat_zfs_misc_arcstats_mru_size[5]; +static int MIB_kstat_zfs_misc_arcstats_anon_size[5]; +static int MIB_kstat_zfs_misc_arcstats_hdr_size[5]; +static int MIB_kstat_zfs_misc_arcstats_other_size[5]; static int MIB_kern_cp_time[2]; static int MIB_kern_cp_times[2]; @@ -123,6 +135,16 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui NULL, 0) == 0 && fpl->memZfsArc != 0) { len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); fpl->zfsArcEnabled = 1; + + len = 3; + sysctlnametomib("vfs.zfs.arc_max", MIB_vfs_zfs_arc_max, &len); + + len = 5; + sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); } else { fpl->zfsArcEnabled = 0; } @@ -323,8 +345,30 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { fpl->memZfsArc /= 1024; fpl->memWire -= fpl->memZfsArc; pl->cachedMem += fpl->memZfsArc; - // maybe when we learn how to make custom memory meter - // we could do custom arc breakdown? + + len = sizeof(fpl->zfsArcMax); + sysctl(MIB_vfs_zfs_arc_max, 3, &(fpl->zfsArcMax), &len , NULL, 0); + fpl->zfsArcMax /= 1024; + + len = sizeof(fpl->zfsArcMFU); + sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(fpl->zfsArcMFU), &len , NULL, 0); + fpl->zfsArcMFU /= 1024; + + len = sizeof(fpl->zfsArcMRU); + sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(fpl->zfsArcMRU), &len , NULL, 0); + fpl->zfsArcMRU /= 1024; + + len = sizeof(fpl->zfsArcAnon); + sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(fpl->zfsArcAnon), &len , NULL, 0); + fpl->zfsArcAnon /= 1024; + + len = sizeof(fpl->zfsArcHeader); + sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(fpl->zfsArcHeader), &len , NULL, 0); + fpl->zfsArcHeader /= 1024; + + len = sizeof(fpl->zfsArcOther); + sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(fpl->zfsArcOther), &len , NULL, 0); + fpl->zfsArcOther /= 1024; } pl->usedMem = fpl->memActive + fpl->memWire; diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index af343fb0b..cf96a7025 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -42,6 +42,12 @@ typedef struct FreeBSDProcessList_ { unsigned long long int memFree; unsigned long long int memZfsArc; + unsigned long long int zfsArcMax; + unsigned long long int zfsArcMFU; + unsigned long long int zfsArcMRU; + unsigned long long int zfsArcAnon; + unsigned long long int zfsArcHeader; + unsigned long long int zfsArcOther; CPUData* cpus; diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 5dd6ca41a..d8d2ed06c 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -15,6 +15,7 @@ in the source distribution for its full text. #include "UptimeMeter.h" #include "ClockMeter.h" #include "HostnameMeter.h" +#include "zfs/ZfsArcMeter.h" #include "FreeBSDProcess.h" #include "FreeBSDProcessList.h" @@ -104,6 +105,7 @@ MeterClass* Platform_meterTypes[] = { &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &BlankMeter_class, + &ZfsArcMeter_class, NULL }; @@ -197,6 +199,23 @@ void Platform_setSwapValues(Meter* this) { this->values[0] = pl->usedSwap; } +void Platform_setZfsArcValues(Meter* this) { + FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl; + + this->total = fpl->zfsArcMax; + this->values[0] = fpl->zfsArcMFU; + this->values[1] = fpl->zfsArcMRU; + this->values[2] = fpl->zfsArcAnon; + this->values[3] = fpl->zfsArcHeader; + this->values[4] = fpl->zfsArcOther; + + // "Hide" the last value so it can + // only be accessed by index and is not + // displayed by the Bar or Graph style + Meter_setItems(this, 5); + this->values[5] = fpl->memZfsArc; +} + void Platform_setTasksValues(Meter* this) { // TODO } diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 1735e7e3b..3dc7ebf21 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -44,6 +44,8 @@ void Platform_setMemoryValues(Meter* this); void Platform_setSwapValues(Meter* this); +void Platform_setZfsArcValues(Meter* this); + void Platform_setTasksValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c new file mode 100644 index 000000000..e12c46e2c --- /dev/null +++ b/zfs/ZfsArcMeter.c @@ -0,0 +1,81 @@ +/* +htop - ZfsArcMeter.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "ZfsArcMeter.h" + +#include "CRT.h" +#include "Platform.h" + +#include +#include +#include +#include +#include + +/*{ +#include "Meter.h" +}*/ + +int ZfsArcMeter_attributes[] = { + ZFS_MFU, ZFS_MRU, ZFS_ANON, ZFS_HEADER, ZFS_OTHER +}; + +static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) { + int written; + Platform_setZfsArcValues(this); + + written = Meter_humanUnit(buffer, this->values[5], size); + buffer += written; + if ((size -= written) > 0) { + *buffer++ = '/'; + size--; + Meter_humanUnit(buffer, this->total, size); + } +} + +static void ZfsArcMeter_display(Object* cast, RichString* out) { + char buffer[50]; + Meter* this = (Meter*)cast; + + RichString_write(out, CRT_colors[METER_TEXT], ":"); + Meter_humanUnit(buffer, this->total, 50); + RichString_append(out, CRT_colors[METER_VALUE], buffer); + Meter_humanUnit(buffer, this->values[5], 50); + RichString_append(out, CRT_colors[METER_TEXT], " Used:"); + RichString_append(out, CRT_colors[METER_VALUE], buffer); + Meter_humanUnit(buffer, this->values[0], 50); + RichString_append(out, CRT_colors[METER_TEXT], " MFU:"); + RichString_append(out, CRT_colors[ZFS_MFU], buffer); + Meter_humanUnit(buffer, this->values[1], 50); + RichString_append(out, CRT_colors[METER_TEXT], " MRU:"); + RichString_append(out, CRT_colors[ZFS_MRU], buffer); + Meter_humanUnit(buffer, this->values[2], 50); + RichString_append(out, CRT_colors[METER_TEXT], " Anon:"); + RichString_append(out, CRT_colors[ZFS_ANON], buffer); + Meter_humanUnit(buffer, this->values[3], 50); + RichString_append(out, CRT_colors[METER_TEXT], " Hdr:"); + RichString_append(out, CRT_colors[ZFS_HEADER], buffer); + Meter_humanUnit(buffer, this->values[4], 50); + RichString_append(out, CRT_colors[METER_TEXT], " Oth:"); + RichString_append(out, CRT_colors[ZFS_OTHER], buffer); +} + +MeterClass ZfsArcMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = ZfsArcMeter_display, + }, + .updateValues = ZfsArcMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 6, + .total = 100.0, + .attributes = ZfsArcMeter_attributes, + .name = "ZFSARC", + .uiName = "ZFS ARC", + .caption = "ARC" +}; diff --git a/zfs/ZfsArcMeter.h b/zfs/ZfsArcMeter.h new file mode 100644 index 000000000..b89be2233 --- /dev/null +++ b/zfs/ZfsArcMeter.h @@ -0,0 +1,18 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_ZfsArcMeter +#define HEADER_ZfsArcMeter +/* +htop - ZfsArcMeter.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern int ZfsArcMeter_attributes[]; + +extern MeterClass ZfsArcMeter_class; + +#endif From 070fe90461182743fabb029415fc1bc59be14f3f Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Sun, 7 Jul 2019 02:37:02 +0000 Subject: [PATCH 037/411] ZFS arcstats for Linux If no pools are imported (ARC size == 0) or the ZFS module is not in the kernel (/proc/spl/kstat/zfs/arcstats does not exist), then the Meter reports "Unavailable". --- Makefile.am | 6 ++-- linux/LinuxProcessList.c | 66 ++++++++++++++++++++++++++++++++++++++++ linux/LinuxProcessList.h | 13 ++++++++ linux/Platform.c | 19 ++++++++++++ linux/Platform.h | 2 ++ zfs/ZfsArcMeter.c | 47 +++++++++++++++------------- 6 files changed, 130 insertions(+), 23 deletions(-) diff --git a/Makefile.am b/Makefile.am index ad23d19b2..b850815aa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -52,14 +52,16 @@ linux_platform_headers = \ linux/LinuxProcess.h \ linux/LinuxProcessList.h \ linux/LinuxCRT.h \ - linux/Battery.h + linux/Battery.h \ + $(zfs_platform_headers) all_platform_headers += $(linux_platform_headers) if HTOP_LINUX AM_CFLAGS += -rdynamic myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ -linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c +linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \ +$(zfs_platform_sources) myhtopplatheaders = $(linux_platform_headers) endif diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5f38540c6..4d19185cd 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -94,6 +94,15 @@ typedef struct LinuxProcessList_ { struct nl_sock *netlink_socket; int netlink_family; #endif + + int zfsArcEnabled; + unsigned long long int memZfsArc; + unsigned long long int zfsArcMax; + unsigned long long int zfsArcMFU; + unsigned long long int zfsArcMRU; + unsigned long long int zfsArcAnon; + unsigned long long int zfsArcHeader; + unsigned long long int zfsArcOther; } LinuxProcessList; #ifndef PROCDIR @@ -108,6 +117,10 @@ typedef struct LinuxProcessList_ { #define PROCMEMINFOFILE PROCDIR "/meminfo" #endif +#ifndef PROCARCSTATSFILE +#define PROCARCSTATSFILE PROCDIR "/spl/kstat/zfs/arcstats" +#endif + #ifndef PROCTTYDRIVERSFILE #define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers" #endif @@ -964,6 +977,58 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { fclose(file); } +static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { + unsigned long long int dbufSize; + unsigned long long int dnodeSize; + unsigned long long int bonusSize; + + FILE* file = fopen(PROCARCSTATSFILE, "r"); + if (file == NULL) { + lpl->zfsArcEnabled = 0; + return; + } + char buffer[128]; + while (fgets(buffer, 128, file)) { + #define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { break; } } while(0) + switch (buffer[0]) { + case 'c': + tryRead("c_max", &lpl->zfsArcMax); + break; + case 's': + tryRead("size", &lpl->memZfsArc); + break; + case 'h': + tryRead("hdr_size", &lpl->zfsArcHeader); + break; + case 'd': + tryRead("dbuf_size", &dbufSize); + tryRead("dnode_size", &dnodeSize); + break; + case 'b': + tryRead("bonus_size", &bonusSize); + break; + case 'a': + tryRead("anon_size", &lpl->zfsArcAnon); + break; + case 'm': + tryRead("mfu_size", &lpl->zfsArcMFU); + tryRead("mru_size", &lpl->zfsArcMRU); + break; + } + #undef tryRead + } + fclose(file); + + lpl->zfsArcEnabled = (lpl->memZfsArc > 0 ? 1 : 0); + lpl->memZfsArc /= 1024; + lpl->zfsArcMax /= 1024; + lpl->zfsArcMFU /= 1024; + lpl->zfsArcMRU /= 1024; + lpl->zfsArcAnon /= 1024; + lpl->zfsArcHeader /= 1024; + lpl->zfsArcOther = (dbufSize + dnodeSize + bonusSize) / 1024; +} + static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { FILE* file = fopen(PROCSTATFILE, "r"); @@ -1038,6 +1103,7 @@ void ProcessList_goThroughEntries(ProcessList* super) { LinuxProcessList* this = (LinuxProcessList*) super; LinuxProcessList_scanMemoryInfo(super); + LinuxProcessList_scanZfsArcstats(this); double period = LinuxProcessList_scanCPUTime(this); struct timeval tv; diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index f30b487d6..749231e17 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -67,6 +67,15 @@ typedef struct LinuxProcessList_ { struct nl_sock *netlink_socket; int netlink_family; #endif + + int zfsArcEnabled; + unsigned long long int memZfsArc; + unsigned long long int zfsArcMax; + unsigned long long int zfsArcMFU; + unsigned long long int zfsArcMRU; + unsigned long long int zfsArcAnon; + unsigned long long int zfsArcHeader; + unsigned long long int zfsArcOther; } LinuxProcessList; #ifndef PROCDIR @@ -81,6 +90,10 @@ typedef struct LinuxProcessList_ { #define PROCMEMINFOFILE PROCDIR "/meminfo" #endif +#ifndef PROCARCSTATSFILE +#define PROCARCSTATSFILE PROCDIR "/spl/kstat/zfs/arcstats" +#endif + #ifndef PROCTTYDRIVERSFILE #define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers" #endif diff --git a/linux/Platform.c b/linux/Platform.c index ab90ca74b..4e73c61e4 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -21,6 +21,7 @@ in the source distribution for its full text. #include "UptimeMeter.h" #include "ClockMeter.h" #include "HostnameMeter.h" +#include "zfs/ZfsArcMeter.h" #include "LinuxProcess.h" #include @@ -126,6 +127,7 @@ MeterClass* Platform_meterTypes[] = { &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &BlankMeter_class, + &ZfsArcMeter_class, NULL }; @@ -213,6 +215,23 @@ void Platform_setSwapValues(Meter* this) { this->values[0] = pl->usedSwap; } +void Platform_setZfsArcValues(Meter* this) { + LinuxProcessList* lpl = (LinuxProcessList*) this->pl; + + this->total = lpl->zfsArcMax; + this->values[0] = lpl->zfsArcMFU; + this->values[1] = lpl->zfsArcMRU; + this->values[2] = lpl->zfsArcAnon; + this->values[3] = lpl->zfsArcHeader; + this->values[4] = lpl->zfsArcOther; + + // "Hide" the last value so it can + // only be accessed by index and is not + // displayed by the Bar or Graph style + Meter_setItems(this, 5); + this->values[5] = lpl->memZfsArc; +} + char* Platform_getProcessEnv(pid_t pid) { char procname[32+1]; xSnprintf(procname, 32, "/proc/%d/environ", pid); diff --git a/linux/Platform.h b/linux/Platform.h index b0456e5b5..e775181e6 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -43,6 +43,8 @@ void Platform_setMemoryValues(Meter* this); void Platform_setSwapValues(Meter* this); +void Platform_setZfsArcValues(Meter* this); + char* Platform_getProcessEnv(pid_t pid); #endif diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index e12c46e2c..ebd809920 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -41,27 +41,32 @@ static void ZfsArcMeter_display(Object* cast, RichString* out) { char buffer[50]; Meter* this = (Meter*)cast; - RichString_write(out, CRT_colors[METER_TEXT], ":"); - Meter_humanUnit(buffer, this->total, 50); - RichString_append(out, CRT_colors[METER_VALUE], buffer); - Meter_humanUnit(buffer, this->values[5], 50); - RichString_append(out, CRT_colors[METER_TEXT], " Used:"); - RichString_append(out, CRT_colors[METER_VALUE], buffer); - Meter_humanUnit(buffer, this->values[0], 50); - RichString_append(out, CRT_colors[METER_TEXT], " MFU:"); - RichString_append(out, CRT_colors[ZFS_MFU], buffer); - Meter_humanUnit(buffer, this->values[1], 50); - RichString_append(out, CRT_colors[METER_TEXT], " MRU:"); - RichString_append(out, CRT_colors[ZFS_MRU], buffer); - Meter_humanUnit(buffer, this->values[2], 50); - RichString_append(out, CRT_colors[METER_TEXT], " Anon:"); - RichString_append(out, CRT_colors[ZFS_ANON], buffer); - Meter_humanUnit(buffer, this->values[3], 50); - RichString_append(out, CRT_colors[METER_TEXT], " Hdr:"); - RichString_append(out, CRT_colors[ZFS_HEADER], buffer); - Meter_humanUnit(buffer, this->values[4], 50); - RichString_append(out, CRT_colors[METER_TEXT], " Oth:"); - RichString_append(out, CRT_colors[ZFS_OTHER], buffer); + if (this->values[5] > 0) { + RichString_write(out, CRT_colors[METER_TEXT], ":"); + Meter_humanUnit(buffer, this->total, 50); + RichString_append(out, CRT_colors[METER_VALUE], buffer); + Meter_humanUnit(buffer, this->values[5], 50); + RichString_append(out, CRT_colors[METER_TEXT], " Used:"); + RichString_append(out, CRT_colors[METER_VALUE], buffer); + Meter_humanUnit(buffer, this->values[0], 50); + RichString_append(out, CRT_colors[METER_TEXT], " MFU:"); + RichString_append(out, CRT_colors[ZFS_MFU], buffer); + Meter_humanUnit(buffer, this->values[1], 50); + RichString_append(out, CRT_colors[METER_TEXT], " MRU:"); + RichString_append(out, CRT_colors[ZFS_MRU], buffer); + Meter_humanUnit(buffer, this->values[2], 50); + RichString_append(out, CRT_colors[METER_TEXT], " Anon:"); + RichString_append(out, CRT_colors[ZFS_ANON], buffer); + Meter_humanUnit(buffer, this->values[3], 50); + RichString_append(out, CRT_colors[METER_TEXT], " Hdr:"); + RichString_append(out, CRT_colors[ZFS_HEADER], buffer); + Meter_humanUnit(buffer, this->values[4], 50); + RichString_append(out, CRT_colors[METER_TEXT], " Oth:"); + RichString_append(out, CRT_colors[ZFS_OTHER], buffer); + } else { + RichString_write(out, CRT_colors[METER_TEXT], " "); + RichString_append(out, CRT_colors[FAILED_SEARCH], "Unavailable"); + } } MeterClass ZfsArcMeter_class = { From fc8e9a2d3e25e35c0f9903baa345b1744b12b6cb Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Sun, 7 Jul 2019 17:30:37 -0400 Subject: [PATCH 038/411] ZFS arcstats for Darwin (macOS / OS X) --- Makefile.am | 6 ++- darwin/DarwinProcessList.c | 80 ++++++++++++++++++++++++++++++++++++++ darwin/DarwinProcessList.h | 21 ++++++++++ darwin/Platform.c | 19 +++++++++ darwin/Platform.h | 2 + 5 files changed, 126 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index b850815aa..b6d2117bf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -134,14 +134,16 @@ darwin_platform_headers = \ darwin/DarwinProcess.h \ darwin/DarwinProcessList.h \ darwin/DarwinCRT.h \ - darwin/Battery.h + darwin/Battery.h \ + $(zfs_platform_headers) all_platform_headers += $(darwin_platform_headers) if HTOP_DARWIN AM_LDFLAGS += -framework IOKit -framework CoreFoundation myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \ -darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c +darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c \ +$(zfs_platform_sources) myhtopplatheaders = $(darwin_platform_headers) endif diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 098844809..267e8e947 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -54,6 +54,7 @@ int CompareKernelVersion(short int major, short int minor, short int component) /*{ #include "ProcessList.h" +#include "zfs/ZfsArcStats.h" #include #include @@ -67,10 +68,28 @@ typedef struct DarwinProcessList_ { uint64_t kernel_threads; uint64_t user_threads; uint64_t global_diff; + + int zfsArcEnabled; + unsigned long long int zfsArcMax; + unsigned long long int zfsArcSize; + unsigned long long int zfsArcMFU; + unsigned long long int zfsArcMRU; + unsigned long long int zfsArcAnon; + unsigned long long int zfsArcHeader; + unsigned long long int zfsArcOther; + } DarwinProcessList; }*/ +static int MIB_kstat_zfs_misc_arcstats_c_max[5]; +static int MIB_kstat_zfs_misc_arcstats_size[5]; +static int MIB_kstat_zfs_misc_arcstats_mfu_size[5]; +static int MIB_kstat_zfs_misc_arcstats_mru_size[5]; +static int MIB_kstat_zfs_misc_arcstats_anon_size[5]; +static int MIB_kstat_zfs_misc_arcstats_hdr_size[5]; +static int MIB_kstat_zfs_misc_arcstats_other_size[5]; + void ProcessList_getHostInfo(host_basic_info_data_t *p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; @@ -131,8 +150,50 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { return processes; } +static inline void DarwinProcessList_scanZfsArcstats(DarwinProcessList* dpl) { + size_t len; + + if (dpl->zfsArcEnabled) { + len = sizeof(dpl->zfsArcSize); + sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(dpl->zfsArcSize), &len , NULL, 0); + /* TODO: adjust reported memory in use to move ARC from wired to inactive + Like: + // In bytes + dpl->vm_stats.wire_count -= dpl->zfsArcSize / vm_page_size; + dpl->vm_stats.inactive_count += dpl->zfsArcSize / vm_page_size; + // Would purgable_count be more true? + // Then convert to KB: + */ + dpl->zfsArcSize /= 1024; + + len = sizeof(dpl->zfsArcMax); + sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(dpl->zfsArcMax), &len , NULL, 0); + dpl->zfsArcMax /= 1024; + + len = sizeof(dpl->zfsArcMFU); + sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(dpl->zfsArcMFU), &len , NULL, 0); + dpl->zfsArcMFU /= 1024; + + len = sizeof(dpl->zfsArcMRU); + sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(dpl->zfsArcMRU), &len , NULL, 0); + dpl->zfsArcMRU /= 1024; + + len = sizeof(dpl->zfsArcAnon); + sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(dpl->zfsArcAnon), &len , NULL, 0); + dpl->zfsArcAnon /= 1024; + + len = sizeof(dpl->zfsArcHeader); + sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(dpl->zfsArcHeader), &len , NULL, 0); + dpl->zfsArcHeader /= 1024; + + len = sizeof(dpl->zfsArcOther); + sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(dpl->zfsArcOther), &len , NULL, 0); + dpl->zfsArcOther /= 1024; + } +} ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { + size_t len; DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList)); ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId); @@ -145,6 +206,24 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui /* Initialize the VM statistics */ ProcessList_getVMStats(&this->vm_stats); + /* Initialize the ZFS kstats, if zfs.kext loaded */ + len = sizeof(this->zfsArcSize); + if (sysctlbyname("kstat.zfs.misc.arcstats.size", &this->zfsArcSize, &len, + NULL, 0) == 0 && this->zfsArcSize != 0) { + this->zfsArcEnabled = 1; + + len = 5; + sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); + } else { + this->zfsArcEnabled = 0; + } + this->super.kernelThreads = 0; this->super.userlandThreads = 0; this->super.totalTasks = 0; @@ -173,6 +252,7 @@ void ProcessList_goThroughEntries(ProcessList* super) { dpl->prev_load = dpl->curr_load; ProcessList_allocateCPULoadInfo(&dpl->curr_load); ProcessList_getVMStats(&dpl->vm_stats); + DarwinProcessList_scanZfsArcstats(dpl); /* Get the time difference */ dpl->global_diff = 0; diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index c216a8040..6686d05c7 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -9,6 +9,17 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +struct kern; + +void GetKernelVersion(struct kern *k); + +/* compare the given os version with the one installed returns: +0 if equals the installed version +positive value if less than the installed version +negative value if more than the installed version +*/ +int CompareKernelVersion(short int major, short int minor, short int component); + #include "ProcessList.h" #include #include @@ -23,6 +34,16 @@ typedef struct DarwinProcessList_ { uint64_t kernel_threads; uint64_t user_threads; uint64_t global_diff; + + int zfsArcEnabled; + unsigned long long int zfsArcMax; + unsigned long long int zfsArcSize; + unsigned long long int zfsArcMFU; + unsigned long long int zfsArcMRU; + unsigned long long int zfsArcAnon; + unsigned long long int zfsArcHeader; + unsigned long long int zfsArcOther; + } DarwinProcessList; diff --git a/darwin/Platform.c b/darwin/Platform.c index 1dce8b67a..52d60a9b7 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -15,6 +15,7 @@ in the source distribution for its full text. #include "ClockMeter.h" #include "HostnameMeter.h" #include "UptimeMeter.h" +#include "zfs/ZfsArcMeter.h" #include "DarwinProcessList.h" #include @@ -117,6 +118,7 @@ MeterClass* Platform_meterTypes[] = { &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &ZfsArcMeter_class, &BlankMeter_class, NULL }; @@ -241,6 +243,23 @@ void Platform_setSwapValues(Meter* mtr) { mtr->values[0] = swapused.xsu_used / 1024; } +void Platform_setZfsArcValues(Meter* this) { + DarwinProcessList* dpl = (DarwinProcessList*) this->pl; + + this->total = dpl->zfsArcMax; + this->values[0] = dpl->zfsArcMFU; + this->values[1] = dpl->zfsArcMRU; + this->values[2] = dpl->zfsArcAnon; + this->values[3] = dpl->zfsArcHeader; + this->values[4] = dpl->zfsArcOther; + + // "Hide" the last value so it can + // only be accessed by index and is not + // displayed by the Bar or Graph style + Meter_setItems(this, 5); + this->values[5] = dpl->zfsArcSize; +} + char* Platform_getProcessEnv(pid_t pid) { char* env = NULL; diff --git a/darwin/Platform.h b/darwin/Platform.h index 1231217b1..4acda2c40 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -48,6 +48,8 @@ void Platform_setMemoryValues(Meter* mtr); void Platform_setSwapValues(Meter* mtr); +void Platform_setZfsArcValues(Meter* mtr); + char* Platform_getProcessEnv(pid_t pid); #endif From a88d2e313df7f5f2b781d5b14ffe0e7710018c10 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Sun, 7 Jul 2019 23:27:00 +0000 Subject: [PATCH 039/411] Refactor common OpenZFS sysctl access Darwin and FreeBSD export zfs kstats through the same APIs, so moving functions into a common file. --- Makefile.am | 21 ++++----- darwin/DarwinProcessList.c | 82 +++--------------------------------- darwin/DarwinProcessList.h | 11 +---- darwin/Platform.c | 14 +++--- darwin/Platform.h | 2 +- freebsd/FreeBSDProcessList.c | 77 +++++---------------------------- freebsd/FreeBSDProcessList.h | 14 ++---- freebsd/Platform.c | 14 +++--- linux/LinuxProcessList.c | 40 ++++++++---------- linux/LinuxProcessList.h | 10 +---- linux/Platform.c | 14 +++--- zfs/ZfsArcStats.c | 19 +++++++++ zfs/ZfsArcStats.h | 23 ++++++++++ zfs/openzfs_sysctl.c | 81 +++++++++++++++++++++++++++++++++++ zfs/openzfs_sysctl.h | 18 ++++++++ 15 files changed, 216 insertions(+), 224 deletions(-) create mode 100644 zfs/ZfsArcStats.c create mode 100644 zfs/ZfsArcStats.h create mode 100644 zfs/openzfs_sysctl.c create mode 100644 zfs/openzfs_sysctl.h diff --git a/Makefile.am b/Makefile.am index b6d2117bf..5eee6315a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,10 +36,6 @@ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \ EnvScreen.h InfoScreen.h XAlloc.h -zfs_platform_sources = zfs/ZfsArcMeter.c - -zfs_platform_headers = zfs/ZfsArcMeter.h - all_platform_headers = # Linux @@ -53,7 +49,8 @@ linux_platform_headers = \ linux/LinuxProcessList.h \ linux/LinuxCRT.h \ linux/Battery.h \ - $(zfs_platform_headers) + zfs/ZfsArcMeter.h \ + zfs/ZfsArcStats.h all_platform_headers += $(linux_platform_headers) @@ -61,7 +58,7 @@ if HTOP_LINUX AM_CFLAGS += -rdynamic myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \ -$(zfs_platform_sources) +zfs/ZfsArcMeter.c zfs/ZfsArcStats.c myhtopplatheaders = $(linux_platform_headers) endif @@ -75,14 +72,16 @@ freebsd_platform_headers = \ freebsd/FreeBSDProcess.h \ freebsd/FreeBSDCRT.h \ freebsd/Battery.h \ - $(zfs_platform_headers) + zfs/ZfsArcMeter.h \ + zfs/ZfsArcStats.h \ + zfs/openzfs_sysctl.h all_platform_headers += $(freebsd_platform_headers) if HTOP_FREEBSD myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c \ -$(zfs_platform_sources) +zfs/ZfsArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c myhtopplatheaders = $(freebsd_platform_headers) endif @@ -135,7 +134,9 @@ darwin_platform_headers = \ darwin/DarwinProcessList.h \ darwin/DarwinCRT.h \ darwin/Battery.h \ - $(zfs_platform_headers) + zfs/ZfsArcMeter.h \ + zfs/ZfsArcStats.h \ + zfs/openzfs_sysctl.h all_platform_headers += $(darwin_platform_headers) @@ -143,7 +144,7 @@ if HTOP_DARWIN AM_LDFLAGS += -framework IOKit -framework CoreFoundation myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \ darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c \ -$(zfs_platform_sources) +zfs/ZfsArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c myhtopplatheaders = $(darwin_platform_headers) endif diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 267e8e947..122e0188a 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -9,6 +9,8 @@ in the source distribution for its full text. #include "DarwinProcess.h" #include "DarwinProcessList.h" #include "CRT.h" +#include "zfs/ZfsArcStats.h" +#include "zfs/openzfs_sysctl.h" #include #include @@ -69,27 +71,11 @@ typedef struct DarwinProcessList_ { uint64_t user_threads; uint64_t global_diff; - int zfsArcEnabled; - unsigned long long int zfsArcMax; - unsigned long long int zfsArcSize; - unsigned long long int zfsArcMFU; - unsigned long long int zfsArcMRU; - unsigned long long int zfsArcAnon; - unsigned long long int zfsArcHeader; - unsigned long long int zfsArcOther; - + ZfsArcStats zfs; } DarwinProcessList; }*/ -static int MIB_kstat_zfs_misc_arcstats_c_max[5]; -static int MIB_kstat_zfs_misc_arcstats_size[5]; -static int MIB_kstat_zfs_misc_arcstats_mfu_size[5]; -static int MIB_kstat_zfs_misc_arcstats_mru_size[5]; -static int MIB_kstat_zfs_misc_arcstats_anon_size[5]; -static int MIB_kstat_zfs_misc_arcstats_hdr_size[5]; -static int MIB_kstat_zfs_misc_arcstats_other_size[5]; - void ProcessList_getHostInfo(host_basic_info_data_t *p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; @@ -150,48 +136,6 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { return processes; } -static inline void DarwinProcessList_scanZfsArcstats(DarwinProcessList* dpl) { - size_t len; - - if (dpl->zfsArcEnabled) { - len = sizeof(dpl->zfsArcSize); - sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(dpl->zfsArcSize), &len , NULL, 0); - /* TODO: adjust reported memory in use to move ARC from wired to inactive - Like: - // In bytes - dpl->vm_stats.wire_count -= dpl->zfsArcSize / vm_page_size; - dpl->vm_stats.inactive_count += dpl->zfsArcSize / vm_page_size; - // Would purgable_count be more true? - // Then convert to KB: - */ - dpl->zfsArcSize /= 1024; - - len = sizeof(dpl->zfsArcMax); - sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(dpl->zfsArcMax), &len , NULL, 0); - dpl->zfsArcMax /= 1024; - - len = sizeof(dpl->zfsArcMFU); - sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(dpl->zfsArcMFU), &len , NULL, 0); - dpl->zfsArcMFU /= 1024; - - len = sizeof(dpl->zfsArcMRU); - sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(dpl->zfsArcMRU), &len , NULL, 0); - dpl->zfsArcMRU /= 1024; - - len = sizeof(dpl->zfsArcAnon); - sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(dpl->zfsArcAnon), &len , NULL, 0); - dpl->zfsArcAnon /= 1024; - - len = sizeof(dpl->zfsArcHeader); - sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(dpl->zfsArcHeader), &len , NULL, 0); - dpl->zfsArcHeader /= 1024; - - len = sizeof(dpl->zfsArcOther); - sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(dpl->zfsArcOther), &len , NULL, 0); - dpl->zfsArcOther /= 1024; - } -} - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { size_t len; DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList)); @@ -207,22 +151,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui ProcessList_getVMStats(&this->vm_stats); /* Initialize the ZFS kstats, if zfs.kext loaded */ - len = sizeof(this->zfsArcSize); - if (sysctlbyname("kstat.zfs.misc.arcstats.size", &this->zfsArcSize, &len, - NULL, 0) == 0 && this->zfsArcSize != 0) { - this->zfsArcEnabled = 1; - - len = 5; - sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); - } else { - this->zfsArcEnabled = 0; - } + this->zfs.enabled = openzfs_sysctl_init(); + openzfs_sysctl_updateArcStats(&this->zfs); this->super.kernelThreads = 0; this->super.userlandThreads = 0; @@ -252,7 +182,7 @@ void ProcessList_goThroughEntries(ProcessList* super) { dpl->prev_load = dpl->curr_load; ProcessList_allocateCPULoadInfo(&dpl->curr_load); ProcessList_getVMStats(&dpl->vm_stats); - DarwinProcessList_scanZfsArcstats(dpl); + openzfs_sysctl_updateArcStats(&dpl->zfs); /* Get the time difference */ dpl->global_diff = 0; diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index 6686d05c7..73fbd34fe 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -21,6 +21,7 @@ negative value if more than the installed version int CompareKernelVersion(short int major, short int minor, short int component); #include "ProcessList.h" +#include "zfs/ZfsArcStats.h" #include #include @@ -35,15 +36,7 @@ typedef struct DarwinProcessList_ { uint64_t user_threads; uint64_t global_diff; - int zfsArcEnabled; - unsigned long long int zfsArcMax; - unsigned long long int zfsArcSize; - unsigned long long int zfsArcMFU; - unsigned long long int zfsArcMRU; - unsigned long long int zfsArcAnon; - unsigned long long int zfsArcHeader; - unsigned long long int zfsArcOther; - + ZfsArcStats zfs; } DarwinProcessList; diff --git a/darwin/Platform.c b/darwin/Platform.c index 52d60a9b7..8fbb9c933 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -246,18 +246,18 @@ void Platform_setSwapValues(Meter* mtr) { void Platform_setZfsArcValues(Meter* this) { DarwinProcessList* dpl = (DarwinProcessList*) this->pl; - this->total = dpl->zfsArcMax; - this->values[0] = dpl->zfsArcMFU; - this->values[1] = dpl->zfsArcMRU; - this->values[2] = dpl->zfsArcAnon; - this->values[3] = dpl->zfsArcHeader; - this->values[4] = dpl->zfsArcOther; + this->total = dpl->zfs.max; + this->values[0] = dpl->zfs.MFU; + this->values[1] = dpl->zfs.MRU; + this->values[2] = dpl->zfs.anon; + this->values[3] = dpl->zfs.header; + this->values[4] = dpl->zfs.other; // "Hide" the last value so it can // only be accessed by index and is not // displayed by the Bar or Graph style Meter_setItems(this, 5); - this->values[5] = dpl->zfsArcSize; + this->values[5] = dpl->zfs.size; } char* Platform_getProcessEnv(pid_t pid) { diff --git a/darwin/Platform.h b/darwin/Platform.h index 4acda2c40..f83607754 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -48,7 +48,7 @@ void Platform_setMemoryValues(Meter* mtr); void Platform_setSwapValues(Meter* mtr); -void Platform_setZfsArcValues(Meter* mtr); +void Platform_setZfsArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 94cbaa198..1cbfdaab8 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -8,6 +8,8 @@ in the source distribution for its full text. #include "ProcessList.h" #include "FreeBSDProcessList.h" #include "FreeBSDProcess.h" +#include "zfs/ZfsArcStats.h" +#include "zfs/openzfs_sysctl.h" #include #include @@ -21,6 +23,8 @@ in the source distribution for its full text. /*{ +#include "zfs/ZfsArcStats.h" + #include #include #include @@ -45,20 +49,12 @@ typedef struct FreeBSDProcessList_ { ProcessList super; kvm_t* kd; - int zfsArcEnabled; - unsigned long long int memWire; unsigned long long int memActive; unsigned long long int memInactive; unsigned long long int memFree; - unsigned long long int memZfsArc; - unsigned long long int zfsArcMax; - unsigned long long int zfsArcMFU; - unsigned long long int zfsArcMRU; - unsigned long long int zFsArcAnon; - unsigned long long int zFsArcHeader; - unsigned long long int zFsArcOther; + ZfsArcStats zfs; CPUData* cpus; @@ -86,14 +82,6 @@ static int MIB_vm_stats_vm_v_free_count[4]; static int MIB_vfs_bufspace[2]; -static int MIB_kstat_zfs_misc_arcstats_size[5]; -static int MIB_vfs_zfs_arc_max[3]; -static int MIB_kstat_zfs_misc_arcstats_mfu_size[5]; -static int MIB_kstat_zfs_misc_arcstats_mru_size[5]; -static int MIB_kstat_zfs_misc_arcstats_anon_size[5]; -static int MIB_kstat_zfs_misc_arcstats_hdr_size[5]; -static int MIB_kstat_zfs_misc_arcstats_other_size[5]; - static int MIB_kern_cp_time[2]; static int MIB_kern_cp_times[2]; static int kernelFScale; @@ -130,25 +118,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui len = 2; sysctlnametomib("vfs.bufspace", MIB_vfs_bufspace, &len); - len = sizeof(fpl->memZfsArc); - if (sysctlbyname("kstat.zfs.misc.arcstats.size", &fpl->memZfsArc, &len, - NULL, 0) == 0 && fpl->memZfsArc != 0) { - len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); - fpl->zfsArcEnabled = 1; - - len = 3; - sysctlnametomib("vfs.zfs.arc_max", MIB_vfs_zfs_arc_max, &len); - - len = 5; - sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); - } else { - fpl->zfsArcEnabled = 0; - } - + fpl->zfs.enabled = openzfs_sysctl_init(); + openzfs_sysctl_updateArcStats(&fpl->zfs); int smp = 0; len = sizeof(smp); @@ -339,36 +310,9 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(pl->cachedMem), &len, NULL, 0); pl->cachedMem *= pageSizeKb; - if (fpl->zfsArcEnabled) { - len = sizeof(fpl->memZfsArc); - sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(fpl->memZfsArc), &len , NULL, 0); - fpl->memZfsArc /= 1024; - fpl->memWire -= fpl->memZfsArc; - pl->cachedMem += fpl->memZfsArc; - - len = sizeof(fpl->zfsArcMax); - sysctl(MIB_vfs_zfs_arc_max, 3, &(fpl->zfsArcMax), &len , NULL, 0); - fpl->zfsArcMax /= 1024; - - len = sizeof(fpl->zfsArcMFU); - sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(fpl->zfsArcMFU), &len , NULL, 0); - fpl->zfsArcMFU /= 1024; - - len = sizeof(fpl->zfsArcMRU); - sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(fpl->zfsArcMRU), &len , NULL, 0); - fpl->zfsArcMRU /= 1024; - - len = sizeof(fpl->zfsArcAnon); - sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(fpl->zfsArcAnon), &len , NULL, 0); - fpl->zfsArcAnon /= 1024; - - len = sizeof(fpl->zfsArcHeader); - sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(fpl->zfsArcHeader), &len , NULL, 0); - fpl->zfsArcHeader /= 1024; - - len = sizeof(fpl->zfsArcOther); - sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(fpl->zfsArcOther), &len , NULL, 0); - fpl->zfsArcOther /= 1024; + if (fpl->zfs.enabled) { + fpl->memWire -= fpl->zfs.size; + pl->cachedMem += fpl->zfs.size; } pl->usedMem = fpl->memActive + fpl->memWire; @@ -466,6 +410,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; + openzfs_sysctl_updateArcStats(&fpl->zfs); FreeBSDProcessList_scanMemoryInfo(this); FreeBSDProcessList_scanCPUTime(this); diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index cf96a7025..7c1b7ad40 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -10,6 +10,8 @@ in the source distribution for its full text. */ +#include "zfs/ZfsArcStats.h" + #include #include #include @@ -34,20 +36,12 @@ typedef struct FreeBSDProcessList_ { ProcessList super; kvm_t* kd; - int zfsArcEnabled; - unsigned long long int memWire; unsigned long long int memActive; unsigned long long int memInactive; unsigned long long int memFree; - unsigned long long int memZfsArc; - - unsigned long long int zfsArcMax; - unsigned long long int zfsArcMFU; - unsigned long long int zfsArcMRU; - unsigned long long int zfsArcAnon; - unsigned long long int zfsArcHeader; - unsigned long long int zfsArcOther; + + ZfsArcStats zfs; CPUData* cpus; diff --git a/freebsd/Platform.c b/freebsd/Platform.c index d8d2ed06c..05c0e9224 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -202,18 +202,18 @@ void Platform_setSwapValues(Meter* this) { void Platform_setZfsArcValues(Meter* this) { FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl; - this->total = fpl->zfsArcMax; - this->values[0] = fpl->zfsArcMFU; - this->values[1] = fpl->zfsArcMRU; - this->values[2] = fpl->zfsArcAnon; - this->values[3] = fpl->zfsArcHeader; - this->values[4] = fpl->zfsArcOther; + this->total = fpl->zfs.max; + this->values[0] = fpl->zfs.MFU; + this->values[1] = fpl->zfs.MRU; + this->values[2] = fpl->zfs.anon; + this->values[3] = fpl->zfs.header; + this->values[4] = fpl->zfs.other; // "Hide" the last value so it can // only be accessed by index and is not // displayed by the Bar or Graph style Meter_setItems(this, 5); - this->values[5] = fpl->memZfsArc; + this->values[5] = fpl->zfs.size; } void Platform_setTasksValues(Meter* this) { diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 4d19185cd..3e8891046 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -46,6 +46,7 @@ in the source distribution for its full text. /*{ #include "ProcessList.h" +#include "zfs/ZfsArcStats.h" extern long long btime; @@ -95,14 +96,7 @@ typedef struct LinuxProcessList_ { int netlink_family; #endif - int zfsArcEnabled; - unsigned long long int memZfsArc; - unsigned long long int zfsArcMax; - unsigned long long int zfsArcMFU; - unsigned long long int zfsArcMRU; - unsigned long long int zfsArcAnon; - unsigned long long int zfsArcHeader; - unsigned long long int zfsArcOther; + ZfsArcStats zfs; } LinuxProcessList; #ifndef PROCDIR @@ -984,7 +978,7 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { FILE* file = fopen(PROCARCSTATSFILE, "r"); if (file == NULL) { - lpl->zfsArcEnabled = 0; + lpl->zfs.enabled = 0; return; } char buffer[128]; @@ -992,13 +986,13 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { #define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { break; } } while(0) switch (buffer[0]) { case 'c': - tryRead("c_max", &lpl->zfsArcMax); + tryRead("c_max", &lpl->zfs.max); break; case 's': - tryRead("size", &lpl->memZfsArc); + tryRead("size", &lpl->zfs.size); break; case 'h': - tryRead("hdr_size", &lpl->zfsArcHeader); + tryRead("hdr_size", &lpl->zfs.header); break; case 'd': tryRead("dbuf_size", &dbufSize); @@ -1008,25 +1002,25 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { tryRead("bonus_size", &bonusSize); break; case 'a': - tryRead("anon_size", &lpl->zfsArcAnon); + tryRead("anon_size", &lpl->zfs.anon); break; case 'm': - tryRead("mfu_size", &lpl->zfsArcMFU); - tryRead("mru_size", &lpl->zfsArcMRU); + tryRead("mfu_size", &lpl->zfs.MFU); + tryRead("mru_size", &lpl->zfs.MRU); break; } #undef tryRead } fclose(file); - lpl->zfsArcEnabled = (lpl->memZfsArc > 0 ? 1 : 0); - lpl->memZfsArc /= 1024; - lpl->zfsArcMax /= 1024; - lpl->zfsArcMFU /= 1024; - lpl->zfsArcMRU /= 1024; - lpl->zfsArcAnon /= 1024; - lpl->zfsArcHeader /= 1024; - lpl->zfsArcOther = (dbufSize + dnodeSize + bonusSize) / 1024; + lpl->zfs.enabled = (lpl->zfs.size > 0 ? 1 : 0); + lpl->zfs.size /= 1024; + lpl->zfs.max /= 1024; + lpl->zfs.MFU /= 1024; + lpl->zfs.MRU /= 1024; + lpl->zfs.anon /= 1024; + lpl->zfs.header /= 1024; + lpl->zfs.other = (dbufSize + dnodeSize + bonusSize) / 1024; } static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 749231e17..353fe6039 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -19,6 +19,7 @@ in the source distribution for its full text. #include "ProcessList.h" +#include "zfs/ZfsArcStats.h" extern long long btime; @@ -68,14 +69,7 @@ typedef struct LinuxProcessList_ { int netlink_family; #endif - int zfsArcEnabled; - unsigned long long int memZfsArc; - unsigned long long int zfsArcMax; - unsigned long long int zfsArcMFU; - unsigned long long int zfsArcMRU; - unsigned long long int zfsArcAnon; - unsigned long long int zfsArcHeader; - unsigned long long int zfsArcOther; + ZfsArcStats zfs; } LinuxProcessList; #ifndef PROCDIR diff --git a/linux/Platform.c b/linux/Platform.c index 4e73c61e4..e2a3c6d3f 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -218,18 +218,18 @@ void Platform_setSwapValues(Meter* this) { void Platform_setZfsArcValues(Meter* this) { LinuxProcessList* lpl = (LinuxProcessList*) this->pl; - this->total = lpl->zfsArcMax; - this->values[0] = lpl->zfsArcMFU; - this->values[1] = lpl->zfsArcMRU; - this->values[2] = lpl->zfsArcAnon; - this->values[3] = lpl->zfsArcHeader; - this->values[4] = lpl->zfsArcOther; + this->total = lpl->zfs.max; + this->values[0] = lpl->zfs.MFU; + this->values[1] = lpl->zfs.MRU; + this->values[2] = lpl->zfs.anon; + this->values[3] = lpl->zfs.header; + this->values[4] = lpl->zfs.other; // "Hide" the last value so it can // only be accessed by index and is not // displayed by the Bar or Graph style Meter_setItems(this, 5); - this->values[5] = lpl->memZfsArc; + this->values[5] = lpl->zfs.size; } char* Platform_getProcessEnv(pid_t pid) { diff --git a/zfs/ZfsArcStats.c b/zfs/ZfsArcStats.c new file mode 100644 index 000000000..c33076a4b --- /dev/null +++ b/zfs/ZfsArcStats.c @@ -0,0 +1,19 @@ +/* +htop - ZfsArcStats.c +(C) 2014 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +/*{ +typedef struct ZfsArcStats_ { + int enabled; + unsigned long long int max; + unsigned long long int size; + unsigned long long int MFU; + unsigned long long int MRU; + unsigned long long int anon; + unsigned long long int header; + unsigned long long int other; +} ZfsArcStats; +}*/ diff --git a/zfs/ZfsArcStats.h b/zfs/ZfsArcStats.h new file mode 100644 index 000000000..3697af23d --- /dev/null +++ b/zfs/ZfsArcStats.h @@ -0,0 +1,23 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_ZfsArcStats +#define HEADER_ZfsArcStats +/* +htop - ZfsArcStats.h +(C) 2014 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +typedef struct ZfsArcStats_ { + int enabled; + unsigned long long int max; + unsigned long long int size; + unsigned long long int MFU; + unsigned long long int MRU; + unsigned long long int anon; + unsigned long long int header; + unsigned long long int other; +} ZfsArcStats; + +#endif diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c new file mode 100644 index 000000000..ce48f233e --- /dev/null +++ b/zfs/openzfs_sysctl.c @@ -0,0 +1,81 @@ +/* +htop - zfs/openzfs_sysctl.c +(C) 2014 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "zfs/openzfs_sysctl.h" +#include "zfs/ZfsArcStats.h" + +#include +#include +#include +#include + +static int MIB_kstat_zfs_misc_arcstats_size[5]; +static int MIB_kstat_zfs_misc_arcstats_c_max[5]; +static int MIB_kstat_zfs_misc_arcstats_mfu_size[5]; +static int MIB_kstat_zfs_misc_arcstats_mru_size[5]; +static int MIB_kstat_zfs_misc_arcstats_anon_size[5]; +static int MIB_kstat_zfs_misc_arcstats_hdr_size[5]; +static int MIB_kstat_zfs_misc_arcstats_other_size[5]; + +/*{ +#include "zfs/ZfsArcStats.h" +}*/ + +int openzfs_sysctl_init() { + size_t len; + unsigned long long int arcSize; + + len = sizeof(arcSize); + if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, + NULL, 0) == 0 && arcSize != 0) { + len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); + + sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); + return 1; + } else { + return 0; + } +} + +void openzfs_sysctl_updateArcStats(ZfsArcStats *stats) { + size_t len; + + if (stats->enabled) { + len = sizeof(stats->size); + sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(stats->size), &len , NULL, 0); + stats->size /= 1024; + + len = sizeof(stats->max); + sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(stats->max), &len , NULL, 0); + stats->max /= 1024; + + len = sizeof(stats->MFU); + sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(stats->MFU), &len , NULL, 0); + stats->MFU /= 1024; + + len = sizeof(stats->MRU); + sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(stats->MRU), &len , NULL, 0); + stats->MRU /= 1024; + + len = sizeof(stats->anon); + sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(stats->anon), &len , NULL, 0); + stats->anon /= 1024; + + len = sizeof(stats->header); + sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(stats->header), &len , NULL, 0); + stats->header /= 1024; + + len = sizeof(stats->other); + sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(stats->other), &len , NULL, 0); + stats->other /= 1024; + } +} diff --git a/zfs/openzfs_sysctl.h b/zfs/openzfs_sysctl.h new file mode 100644 index 000000000..7c04bd793 --- /dev/null +++ b/zfs/openzfs_sysctl.h @@ -0,0 +1,18 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_openzfs +#define HEADER_openzfs +/* +htop - zfs/openzfs_sysctl.h +(C) 2014 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "zfs/ZfsArcStats.h" + +int openzfs_sysctl_init(); + +void openzfs_sysctl_updateArcStats(ZfsArcStats *stats); + +#endif From ff6914e4ad4b78749bcee5471a33ef206b0a7d03 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Mon, 8 Jul 2019 02:43:39 +0000 Subject: [PATCH 040/411] ZFS arcstats for Solaris --- Makefile.am | 7 +++++-- solaris/Platform.c | 19 ++++++++++++++++++ solaris/Platform.h | 2 ++ solaris/SolarisProcessList.c | 37 ++++++++++++++++++++++++++++++++++++ solaris/SolarisProcessList.h | 3 +++ 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5eee6315a..204a8b7db 100644 --- a/Makefile.am +++ b/Makefile.am @@ -157,14 +157,17 @@ solaris_platform_headers = \ solaris/SolarisProcess.h \ solaris/SolarisProcessList.h \ solaris/SolarisCRT.h \ - solaris/Battery.h + solaris/Battery.h \ + zfs/ZfsArcMeter.h \ + zfs/ZfsArcStats.h all_platform_headers += $(solaris_platform_headers) if HTOP_SOLARIS myhtopplatsources = solaris/Platform.c \ solaris/SolarisProcess.c solaris/SolarisProcessList.c \ -solaris/SolarisCRT.c solaris/Battery.c +solaris/SolarisCRT.c solaris/Battery.c \ +zfs/ZfsArcMeter.c zfs/ZfsArcStats.c myhtopplatheaders = $(solaris_platform_headers) endif diff --git a/solaris/Platform.c b/solaris/Platform.c index a29fcb479..8084d1fd9 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -17,6 +17,7 @@ in the source distribution for its full text. #include "ClockMeter.h" #include "HostnameMeter.h" #include "UptimeMeter.h" +#include "zfs/ZfsArcMeter.h" #include "SolarisProcess.h" #include "SolarisProcessList.h" @@ -122,6 +123,7 @@ MeterClass* Platform_meterTypes[] = { &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &ZfsArcMeter_class, &BlankMeter_class, NULL }; @@ -220,6 +222,23 @@ void Platform_setSwapValues(Meter* this) { this->values[0] = pl->usedSwap; } +void Platform_setZfsArcValues(Meter* this) { + SolarisProcessList* spl = (SolarisProcessList*) this->pl; + + this->total = spl->zfs.max; + this->values[0] = spl->zfs.MFU; + this->values[1] = spl->zfs.MRU; + this->values[2] = spl->zfs.anon; + this->values[3] = spl->zfs.header; + this->values[4] = spl->zfs.other; + + // "Hide" the last value so it can + // only be accessed by index and is not + // displayed by the Bar or Graph style + Meter_setItems(this, 5); + this->values[5] = spl->zfs.size; +} + static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) { envAccum *accump = accum; (void) Phandle; diff --git a/solaris/Platform.h b/solaris/Platform.h index f961b913b..62757ff74 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -60,6 +60,8 @@ void Platform_setMemoryValues(Meter* this); void Platform_setSwapValues(Meter* this); +void Platform_setZfsArcValues(Meter* this); + char* Platform_getProcessEnv(pid_t pid); #endif diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 2c681852b..b6bc6f5dc 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -27,6 +27,8 @@ in the source distribution for its full text. /*{ +#include "zfs/ZfsArcStats.h" + #include #include #include @@ -55,6 +57,7 @@ typedef struct SolarisProcessList_ { ProcessList super; kstat_ctl_t* kd; CPUData* cpus; + ZfsArcStats zfs; } SolarisProcessList; }*/ @@ -230,6 +233,39 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { pl->usedSwap = pl->totalSwap - (totalfree * PAGE_SIZE_KB); } +static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { + SolarisProcessList* spl = (SolarisProcessList*) pl; + kstat_t *arcstats = NULL; + int ksrphyserr = -1; + kstat_named_t *cur_kstat = NULL; + + if (spl->kd != NULL) { arcstats = kstat_lookup(spl->kd,"zfs",0,"arcstats"); } + if (arcstats != NULL) { ksrphyserr = kstat_read(spl->kd,arcstats,NULL); } + if (ksrphyserr != -1) { + cur_kstat = kstat_data_lookup( arcstats, "size" ); + spl->zfs.size = cur_kstat->value.ui64 / 1024; + spl->zfs.enabled = spl->zfs.size > 0 ? 1 : 0; + + cur_kstat = kstat_data_lookup( arcstats, "c_max" ); + spl->zfs.max = cur_kstat->value.ui64 / 1024; + + cur_kstat = kstat_data_lookup( arcstats, "mfu_size" ); + spl->zfs.MFU = cur_kstat->value.ui64 / 1024; + + cur_kstat = kstat_data_lookup( arcstats, "mru_size" ); + spl->zfs.MRU = cur_kstat->value.ui64 / 1024; + + cur_kstat = kstat_data_lookup( arcstats, "anon_size" ); + spl->zfs.anon = cur_kstat->value.ui64 / 1024; + + cur_kstat = kstat_data_lookup( arcstats, "hdr_size" ); + spl->zfs.header = cur_kstat->value.ui64 / 1024; + + cur_kstat = kstat_data_lookup( arcstats, "other_size" ); + spl->zfs.other = cur_kstat->value.ui64 / 1024; + } +} + void ProcessList_delete(ProcessList* pl) { SolarisProcessList* spl = (SolarisProcessList*) pl; ProcessList_done(pl); @@ -367,6 +403,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * void ProcessList_goThroughEntries(ProcessList* this) { SolarisProcessList_scanCPUTime(this); SolarisProcessList_scanMemoryInfo(this); + SolarisProcessList_scanZfsArcstats(this); this->kernelThreads = 1; proc_walk(&SolarisProcessList_walkproc, this, PR_WALK_LWP); } diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index a5f2fbc25..26bf44917 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -13,6 +13,8 @@ in the source distribution for its full text. #define MAXCMDLINE 255 +#include "zfs/ZfsArcStats.h" + #include #include #include @@ -41,6 +43,7 @@ typedef struct SolarisProcessList_ { ProcessList super; kstat_ctl_t* kd; CPUData* cpus; + ZfsArcStats zfs; } SolarisProcessList; From b0e24cd5a577a8eca5590683ae6aca4df61be6bb Mon Sep 17 00:00:00 2001 From: MartinJM Date: Fri, 12 Jul 2019 21:41:09 +0200 Subject: [PATCH 041/411] Added an option to disable the mouse. --- ScreenManager.c | 8 ++++---- Settings.c | 21 +++++++++++++-------- Settings.h | 3 ++- htop.c | 37 +++++++++++++++++++++++-------------- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/ScreenManager.c b/ScreenManager.c index 06e901938..db117b65a 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -163,7 +163,7 @@ static Panel* setCurrentPanel(Panel* panel) { void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { bool quit = false; int focus = 0; - + Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); double oldTime = 0.0; @@ -181,7 +181,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (this->header) { checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut); } - + if (redraw) { ScreenManager_drawPanels(this, focus); } @@ -191,7 +191,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { ch = getch(); HandlerResult result = IGNORED; - if (ch == KEY_MOUSE) { + if (ch == KEY_MOUSE && this->settings->enableMouse) { ch = ERR; MEVENT mevent; int ok = getmouse(&mevent); @@ -269,7 +269,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { quit = true; continue; } - + switch (ch) { case KEY_RESIZE: { diff --git a/Settings.c b/Settings.c index db2fa0668..69a94a8bc 100644 --- a/Settings.c +++ b/Settings.c @@ -31,7 +31,7 @@ typedef struct { typedef struct Settings_ { char* filename; - + MeterColumnSettings columns[2]; ProcessField* fields; @@ -58,6 +58,7 @@ typedef struct Settings_ { bool updateProcessNames; bool accountGuestInCPUMeter; bool headerMargin; + bool enableMouse; bool changed; } Settings; @@ -114,7 +115,7 @@ static void Settings_defaultMeters(Settings* this) { this->columns[i].modes = xCalloc(sizes[i], sizeof(int)); this->columns[i].len = sizes[i]; } - + int r = 0; if (this->cpuCount > 8) { this->columns[0].names[0] = xStrdup("LeftCPUs2"); @@ -134,7 +135,7 @@ static void Settings_defaultMeters(Settings* this) { this->columns[0].modes[1] = BAR_METERMODE; this->columns[0].names[2] = xStrdup("Swap"); this->columns[0].modes[2] = BAR_METERMODE; - + this->columns[1].names[r] = xStrdup("Tasks"); this->columns[1].modes[r++] = TEXT_METERMODE; this->columns[1].names[r] = xStrdup("LoadAverage"); @@ -165,13 +166,13 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { static bool Settings_read(Settings* this, const char* fileName) { FILE* fd; - + CRT_dropPrivileges(); fd = fopen(fileName, "r"); CRT_restorePrivileges(); if (!fd) return false; - + bool didReadMeters = false; bool didReadFields = false; for (;;) { @@ -232,6 +233,8 @@ static bool Settings_read(Settings* this, const char* fileName) { } else if (String_eq(option[0], "color_scheme")) { this->colorScheme = atoi(option[1]); if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0; + } else if (String_eq(option[0], "enable_mouse")) { + this->enableMouse = atoi(option[1]); } else if (String_eq(option[0], "left_meters")) { Settings_readMeters(this, option[1], 0); didReadMeters = true; @@ -315,6 +318,7 @@ bool Settings_write(Settings* this) { fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames); fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->accountGuestInCPUMeter); fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme); + fprintf(fd, "enable_mouse=%d\n", (int) this->enableMouse); fprintf(fd, "delay=%d\n", (int) this->delay); fprintf(fd, "left_meters="); writeMeters(this, fd, 0); fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0); @@ -325,7 +329,7 @@ bool Settings_write(Settings* this) { } Settings* Settings_new(int cpuCount) { - + Settings* this = xCalloc(1, sizeof(Settings)); this->sortKey = PERCENT_CPU; @@ -344,7 +348,7 @@ Settings* Settings_new(int cpuCount) { this->cpuCount = cpuCount; this->showProgramPath = true; this->highlightThreads = true; - + this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); // TODO: turn 'fields' into a Vector, // (and ProcessFields into proper objects). @@ -375,7 +379,7 @@ Settings* Settings_new(int cpuCount) { htopDir = String_cat(home, "/.config/htop"); } legacyDotfile = String_cat(home, "/.htoprc"); - + CRT_dropPrivileges(); (void) mkdir(configDir, 0700); (void) mkdir(htopDir, 0700); @@ -390,6 +394,7 @@ Settings* Settings_new(int cpuCount) { CRT_restorePrivileges(); } this->colorScheme = 0; + this->enableMouse = true; this->changed = false; this->delay = DEFAULT_DELAY; bool ok = false; diff --git a/Settings.h b/Settings.h index d9dc0683c..4ea0742e6 100644 --- a/Settings.h +++ b/Settings.h @@ -22,7 +22,7 @@ typedef struct { typedef struct Settings_ { char* filename; - + MeterColumnSettings columns[2]; ProcessField* fields; @@ -49,6 +49,7 @@ typedef struct Settings_ { bool updateProcessNames; bool accountGuestInCPUMeter; bool headerMargin; + bool enableMouse; bool changed; } Settings; diff --git a/htop.c b/htop.c index 8c88c782a..aaddce98a 100644 --- a/htop.c +++ b/htop.c @@ -34,11 +34,12 @@ static void printVersionFlag() { stdout); exit(0); } - + static void printHelpFlag() { fputs("htop " VERSION " - " COPYRIGHT "\n" "Released under the GNU GPL.\n\n" "-C --no-color Use a monochrome color scheme\n" + "-m --no-mouse Disable the mouse\n" "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" "-h --help Print this help screen\n" "-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n" @@ -62,6 +63,7 @@ typedef struct CommandLineSettings_ { int sortKey; int delay; bool useColors; + bool enableMouse; bool treeView; } CommandLineSettings; @@ -73,6 +75,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { .sortKey = 0, .delay = -1, .useColors = true, + .enableMouse = true, .treeView = false, }; @@ -85,6 +88,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { {"user", required_argument, 0, 'u'}, {"no-color", no_argument, 0, 'C'}, {"no-colour",no_argument, 0, 'C'}, + {"no-mouse", no_argument, 0, 'm'}, {"tree", no_argument, 0, 't'}, {"pid", required_argument, 0, 'p'}, {0,0,0,0} @@ -92,7 +96,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { int opt, opti=0; /* Parse arguments */ - while ((opt = getopt_long(argc, argv, "hvCs:td:u:p:", long_opts, &opti))) { + while ((opt = getopt_long(argc, argv, "hvmCs:td:u:p:", long_opts, &opti))) { if (opt == EOF) break; switch (opt) { case 'h': @@ -130,6 +134,9 @@ static CommandLineSettings parseArguments(int argc, char** argv) { case 'C': flags.useColors = false; break; + case 'm': + flags.enableMouse = false; + break; case 't': flags.treeView = true; break; @@ -186,12 +193,12 @@ int main(int argc, char** argv) { exit(1); } #endif - + Process_setupColumnWidths(); - + UsersTable* ut = UsersTable_new(); ProcessList* pl = ProcessList_new(ut, flags.pidWhiteList, flags.userId); - + Settings* settings = Settings_new(pl->cpuCount); pl->settings = settings; @@ -201,18 +208,20 @@ int main(int argc, char** argv) { if (flags.delay != -1) settings->delay = flags.delay; - if (!flags.useColors) + if (!flags.useColors) settings->colorScheme = COLORSCHEME_MONOCHROME; + if (!flags.enableMouse) + settings->enableMouse = false; if (flags.treeView) settings->treeView = true; CRT_init(settings->delay, settings->colorScheme); - + MainPanel* panel = MainPanel_new(); ProcessList_setPanel(pl, (Panel*) panel); MainPanel_updateTreeFunctions(panel, settings->treeView); - + if (flags.sortKey > 0) { settings->sortKey = flags.sortKey; settings->treeView = false; @@ -228,7 +237,7 @@ int main(int argc, char** argv) { .header = header, }; MainPanel_setState(panel, &state); - + ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true); ScreenManager_add(scr, (Panel*) panel, -1); @@ -236,13 +245,13 @@ int main(int argc, char** argv) { millisleep(75); ProcessList_scan(pl); - ScreenManager_run(scr, NULL, NULL); - + ScreenManager_run(scr, NULL, NULL); + attron(CRT_colors[RESET_COLOR]); mvhline(LINES-1, 0, ' ', COLS); attroff(CRT_colors[RESET_COLOR]); refresh(); - + CRT_done(); if (settings->changed) Settings_write(settings); @@ -250,10 +259,10 @@ int main(int argc, char** argv) { ProcessList_delete(pl); ScreenManager_delete(scr); - + UsersTable_delete(ut); Settings_delete(settings); - + if(flags.pidWhiteList) { Hashtable_delete(flags.pidWhiteList); } From 7858ee6cee4c1633865fc70e037b56d0c9c8388e Mon Sep 17 00:00:00 2001 From: MartinJM Date: Fri, 12 Jul 2019 22:01:29 +0200 Subject: [PATCH 042/411] Added option to enable/disable the mouse. --- DisplayOptionsPanel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 0ff54e331..ece4c7c51 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -39,7 +39,7 @@ static void DisplayOptionsPanel_delete(Object* object) { static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { DisplayOptionsPanel* this = (DisplayOptionsPanel*) super; - + HandlerResult result = IGNORED; CheckItem* selected = (CheckItem*) Panel_getSelected(super); @@ -97,5 +97,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Enable the mouse"), &(settings->enableMouse))); return this; } From 4b0600d8f8f1f6aaae6fc2e59e8697ff8779cf64 Mon Sep 17 00:00:00 2001 From: Arnavion Date: Fri, 9 Aug 2019 21:34:48 -0700 Subject: [PATCH 043/411] Add new display option to also show CPU frequency in CPU meters. The option is only implemented on Linux. On other platforms, and on Linuxes that do not expose the relevant sysfs file, the frequency will be 0. The "CPU average" meter does not show a frequency, only the individual per-CPU meters. --- CPUMeter.c | 20 ++++++++++++++++++-- CPUMeter.h | 3 ++- DisplayOptionsPanel.c | 1 + Settings.c | 5 +++++ Settings.h | 1 + linux/Platform.c | 16 ++++++++++++++++ 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index de5490df1..6f9419b51 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -28,7 +28,8 @@ typedef enum { CPU_METER_STEAL = 5, CPU_METER_GUEST = 6, CPU_METER_IOWAIT = 7, - CPU_METER_ITEMCOUNT = 8, // number of entries in this enum + CPU_METER_FREQUENCY = 8, + CPU_METER_ITEMCOUNT = 9, // number of entries in this enum } CPUMeterValues; }*/ @@ -63,7 +64,22 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { } memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT); double percent = Platform_setCPUValues(this, cpu); - xSnprintf(buffer, size, "%5.1f%%", percent); + if (cpu != 0 && this->pl->settings->showCPUFrequency) { + /* Initial frequency is in KHz. Divide it by 1024 till it's less than 1024, and emit unit accordingly */ + double cpuFrequency = this->values[CPU_METER_FREQUENCY]; + char unit = 'K'; + if (cpuFrequency > 1024) { + cpuFrequency /= 1024; + unit = 'M'; + } + if (cpuFrequency > 1024) { + cpuFrequency /= 1024; + unit = 'G'; + } + xSnprintf(buffer, size, "%5.1f%% %.1f%cHz", percent, cpuFrequency, unit); + } else { + xSnprintf(buffer, size, "%5.1f%%", percent); + } } static void CPUMeter_display(Object* cast, RichString* out) { diff --git a/CPUMeter.h b/CPUMeter.h index 2f1639680..6f8599a8b 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -20,7 +20,8 @@ typedef enum { CPU_METER_STEAL = 5, CPU_METER_GUEST = 6, CPU_METER_IOWAIT = 7, - CPU_METER_ITEMCOUNT = 8, // number of entries in this enum + CPU_METER_FREQUENCY = 8, + CPU_METER_ITEMCOUNT = 9, // number of entries in this enum } CPUMeterValues; diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 0ff54e331..0c7416848 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -97,5 +97,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU frequency"), &(settings->showCPUFrequency))); return this; } diff --git a/Settings.c b/Settings.c index db2fa0668..a268ff4df 100644 --- a/Settings.c +++ b/Settings.c @@ -45,6 +45,7 @@ typedef struct Settings_ { bool countCPUsFromZero; bool detailedCPUTime; + bool showCPUFrequency; bool treeView; bool showProgramPath; bool hideThreads; @@ -223,6 +224,8 @@ static bool Settings_read(Settings* this, const char* fileName) { this->detailedCPUTime = atoi(option[1]); } else if (String_eq(option[0], "cpu_count_from_zero")) { this->countCPUsFromZero = atoi(option[1]); + } else if (String_eq(option[0], "show_cpu_frequency")) { + this->showCPUFrequency = atoi(option[1]); } else if (String_eq(option[0], "update_process_names")) { this->updateProcessNames = atoi(option[1]); } else if (String_eq(option[0], "account_guest_in_cpu_meter")) { @@ -312,6 +315,7 @@ bool Settings_write(Settings* this) { fprintf(fd, "header_margin=%d\n", (int) this->headerMargin); fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime); fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->countCPUsFromZero); + fprintf(fd, "show_cpu_frequency=%d\n", (int) this->showCPUFrequency); fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames); fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->accountGuestInCPUMeter); fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme); @@ -340,6 +344,7 @@ Settings* Settings_new(int cpuCount) { this->highlightMegabytes = false; this->detailedCPUTime = false; this->countCPUsFromZero = false; + this->showCPUFrequency = false; this->updateProcessNames = false; this->cpuCount = cpuCount; this->showProgramPath = true; diff --git a/Settings.h b/Settings.h index d9dc0683c..54b15fcef 100644 --- a/Settings.h +++ b/Settings.h @@ -36,6 +36,7 @@ typedef struct Settings_ { bool countCPUsFromZero; bool detailedCPUTime; + bool showCPUFrequency; bool treeView; bool showProgramPath; bool hideThreads; diff --git a/linux/Platform.c b/linux/Platform.c index ab90ca74b..e92d0c514 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -192,6 +192,22 @@ double Platform_setCPUValues(Meter* this, int cpu) { } percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; + + v[CPU_METER_FREQUENCY] = 0; + if (this->pl->settings->showCPUFrequency) { + char filename[63+1]; + xSnprintf(filename, 63, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cpu - 1); + FILE* fd = fopen(filename, "r"); + if (fd) { + unsigned int cpuFrequency; + int n = fscanf(fd, "%u", &cpuFrequency); + fclose(fd); + if (n > 0) { + v[CPU_METER_FREQUENCY] = cpuFrequency; + } + } + } + return percent; } From 9703a25d1b30a25aead4802fecd462dfac36e011 Mon Sep 17 00:00:00 2001 From: Arnavion Date: Fri, 9 Aug 2019 23:22:05 -0700 Subject: [PATCH 044/411] Divide by 1000, not 1024, and show more decimals. --- CPUMeter.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 6f9419b51..f9984ffa7 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -65,18 +65,18 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT); double percent = Platform_setCPUValues(this, cpu); if (cpu != 0 && this->pl->settings->showCPUFrequency) { - /* Initial frequency is in KHz. Divide it by 1024 till it's less than 1024, and emit unit accordingly */ + /* Initial frequency is in KHz. Divide it by 1000 till it's less than 1000, and emit unit accordingly */ double cpuFrequency = this->values[CPU_METER_FREQUENCY]; char unit = 'K'; - if (cpuFrequency > 1024) { - cpuFrequency /= 1024; + if (cpuFrequency > 1000) { + cpuFrequency /= 1000; unit = 'M'; } - if (cpuFrequency > 1024) { - cpuFrequency /= 1024; + if (cpuFrequency > 1000) { + cpuFrequency /= 1000; unit = 'G'; } - xSnprintf(buffer, size, "%5.1f%% %.1f%cHz", percent, cpuFrequency, unit); + xSnprintf(buffer, size, "%5.1f%% %.3f%cHz", percent, cpuFrequency, unit); } else { xSnprintf(buffer, size, "%5.1f%%", percent); } From 1d5e6a27a05ed44e6364a5b14c925503f8604a1f Mon Sep 17 00:00:00 2001 From: Arnavion Date: Sat, 10 Aug 2019 11:20:21 -0700 Subject: [PATCH 045/411] Add a display option to hide CPU usage number from CPU meter. --- CPUMeter.c | 10 ++++++++-- DisplayOptionsPanel.c | 1 + Settings.c | 5 +++++ Settings.h | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index f9984ffa7..ef01e0ffa 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -76,9 +76,15 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { cpuFrequency /= 1000; unit = 'G'; } - xSnprintf(buffer, size, "%5.1f%% %.3f%cHz", percent, cpuFrequency, unit); - } else { + if (this->pl->settings->showCPUUsage) { + xSnprintf(buffer, size, "%5.1f%% %.3f%cHz", percent, cpuFrequency, unit); + } else { + xSnprintf(buffer, size, "%.3f%cHz", cpuFrequency, unit); + } + } else if (this->pl->settings->showCPUUsage) { xSnprintf(buffer, size, "%5.1f%%", percent); + } else if (size > 0) { + buffer[0] = '\0'; } } diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 0c7416848..6c10eabe7 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -97,6 +97,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU percentage numerically"), &(settings->showCPUUsage))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU frequency"), &(settings->showCPUFrequency))); return this; } diff --git a/Settings.c b/Settings.c index a268ff4df..b9535e6b2 100644 --- a/Settings.c +++ b/Settings.c @@ -45,6 +45,7 @@ typedef struct Settings_ { bool countCPUsFromZero; bool detailedCPUTime; + bool showCPUUsage; bool showCPUFrequency; bool treeView; bool showProgramPath; @@ -224,6 +225,8 @@ static bool Settings_read(Settings* this, const char* fileName) { this->detailedCPUTime = atoi(option[1]); } else if (String_eq(option[0], "cpu_count_from_zero")) { this->countCPUsFromZero = atoi(option[1]); + } else if (String_eq(option[0], "show_cpu_usage")) { + this->showCPUUsage = atoi(option[1]); } else if (String_eq(option[0], "show_cpu_frequency")) { this->showCPUFrequency = atoi(option[1]); } else if (String_eq(option[0], "update_process_names")) { @@ -315,6 +318,7 @@ bool Settings_write(Settings* this) { fprintf(fd, "header_margin=%d\n", (int) this->headerMargin); fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime); fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->countCPUsFromZero); + fprintf(fd, "show_cpu_usage=%d\n", (int) this->showCPUUsage); fprintf(fd, "show_cpu_frequency=%d\n", (int) this->showCPUFrequency); fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames); fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->accountGuestInCPUMeter); @@ -344,6 +348,7 @@ Settings* Settings_new(int cpuCount) { this->highlightMegabytes = false; this->detailedCPUTime = false; this->countCPUsFromZero = false; + this->showCPUUsage = true; this->showCPUFrequency = false; this->updateProcessNames = false; this->cpuCount = cpuCount; diff --git a/Settings.h b/Settings.h index 54b15fcef..0490faef1 100644 --- a/Settings.h +++ b/Settings.h @@ -36,6 +36,7 @@ typedef struct Settings_ { bool countCPUsFromZero; bool detailedCPUTime; + bool showCPUUsage; bool showCPUFrequency; bool treeView; bool showProgramPath; From 1acfb0a75223068c676e06967003fe989400e21d Mon Sep 17 00:00:00 2001 From: Arnavion Date: Sat, 10 Aug 2019 11:37:35 -0700 Subject: [PATCH 046/411] Show N/A instead of 0KHz when CPU frequency is not available. --- CPUMeter.c | 24 +++++++++++++++--------- linux/Platform.c | 6 +++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index ef01e0ffa..561f51326 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -68,18 +68,24 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { /* Initial frequency is in KHz. Divide it by 1000 till it's less than 1000, and emit unit accordingly */ double cpuFrequency = this->values[CPU_METER_FREQUENCY]; char unit = 'K'; - if (cpuFrequency > 1000) { - cpuFrequency /= 1000; - unit = 'M'; - } - if (cpuFrequency > 1000) { - cpuFrequency /= 1000; - unit = 'G'; + char cpuFrequencyBuffer[16]; + if (cpuFrequency < 0) { + xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); + } else { + if (cpuFrequency > 1000) { + cpuFrequency /= 1000; + unit = 'M'; + } + if (cpuFrequency > 1000) { + cpuFrequency /= 1000; + unit = 'G'; + } + xSnprintf(cpuFrequencyBuffer, 15, "%.3f%cHz", cpuFrequency, unit); } if (this->pl->settings->showCPUUsage) { - xSnprintf(buffer, size, "%5.1f%% %.3f%cHz", percent, cpuFrequency, unit); + xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer); } else { - xSnprintf(buffer, size, "%.3f%cHz", cpuFrequency, unit); + xSnprintf(buffer, size, "%s", cpuFrequencyBuffer); } } else if (this->pl->settings->showCPUUsage) { xSnprintf(buffer, size, "%5.1f%%", percent); diff --git a/linux/Platform.c b/linux/Platform.c index e92d0c514..fc81d3bf9 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -193,10 +193,10 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; - v[CPU_METER_FREQUENCY] = 0; + v[CPU_METER_FREQUENCY] = -1; if (this->pl->settings->showCPUFrequency) { - char filename[63+1]; - xSnprintf(filename, 63, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cpu - 1); + char filename[64]; + xSnprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cpu - 1); FILE* fd = fopen(filename, "r"); if (fd) { unsigned int cpuFrequency; From 43728b37e76e4ed32b04c133ca55e27116cdfa06 Mon Sep 17 00:00:00 2001 From: Arnavion Date: Sat, 10 Aug 2019 11:46:21 -0700 Subject: [PATCH 047/411] Fix typo. --- CPUMeter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CPUMeter.c b/CPUMeter.c index 561f51326..edcd61d24 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -80,7 +80,7 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { cpuFrequency /= 1000; unit = 'G'; } - xSnprintf(cpuFrequencyBuffer, 15, "%.3f%cHz", cpuFrequency, unit); + xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.3f%cHz", cpuFrequency, unit); } if (this->pl->settings->showCPUUsage) { xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer); From 909bb86f05c20f0ec6f5d55994065a293932ce21 Mon Sep 17 00:00:00 2001 From: Arnavion Date: Sat, 10 Aug 2019 17:17:45 -0700 Subject: [PATCH 048/411] Show N/A on unsupported platforms instead of 0KHz --- darwin/Platform.c | 2 ++ dragonflybsd/Platform.c | 3 +++ freebsd/Platform.c | 3 +++ openbsd/Platform.c | 2 ++ solaris/Platform.c | 3 +++ unsupported/Platform.c | 5 ++++- 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/darwin/Platform.c b/darwin/Platform.c index 1dce8b67a..cd45bedf9 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -217,6 +217,8 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { /* Convert to percent and return */ total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL]; + mtr->values[CPU_METER_FREQUENCY] = -1; + return CLAMP(total, 0.0, 100.0); } diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 370943d7a..250e50e76 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -179,6 +179,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; + + v[CPU_METER_FREQUENCY] = -1; + return percent; } diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 5dd6ca41a..16d023291 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -178,6 +178,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; + + v[CPU_METER_FREQUENCY] = -1; + return percent; } diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 4bb2e35ee..e5a67d9f5 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -233,6 +233,8 @@ double Platform_setCPUValues(Meter* this, int cpu) { perc = v[0] + v[1] + v[2] + v[3]; + v[CPU_METER_FREQUENCY] = -1; + if (perc <= 100. && perc >= 0.) { return perc; } else { diff --git a/solaris/Platform.c b/solaris/Platform.c index a29fcb479..c180d9880 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -203,6 +203,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; + + v[CPU_METER_FREQUENCY] = -1; + return percent; } diff --git a/unsupported/Platform.c b/unsupported/Platform.c index ba8441913..b5e50c3f3 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -108,8 +108,11 @@ int Platform_getMaxPid() { } double Platform_setCPUValues(Meter* this, int cpu) { - (void) this; (void) cpu; + + double* v = this->values; + v[CPU_METER_FREQUENCY] = -1; + return 0.0; } From 81b64691a7ee55e5c665ac78290495b0aea946d7 Mon Sep 17 00:00:00 2001 From: Arnavion Date: Sat, 10 Aug 2019 22:19:32 -0700 Subject: [PATCH 049/411] Move sysfs-reading code to LinuxProcessList.c and add average frequency. This way the frequency is read from sysfs only once per update cycle instead of every time the UI is redrawn. This also changes the code to read from /proc/cpuinfo instead. This is because reading from scaling_cur_freq stalls for 10ms if the previous read for the file was more than one second ago. [1] Since htop's update cycle is longer than that, it would cause the read of each CPU's scaling_cur_freq file to block the UI for 20ms. This easily led to a noticeable half-second lag on a 20+ CPU machine. /proc/cpuinfo also has a 10ms delay, but this applies for the whole file so the delay does not scale with the number of CPUs. [2] [1]: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4815d3c56d1e10449a44089a47544d9ba84fad0d [2]: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=7d5905dc14a87805a59f3c5bf70173aac2bb18f8 --- CPUMeter.c | 10 ++---- linux/LinuxProcessList.c | 74 ++++++++++++++++++++++++++++++++++++++++ linux/LinuxProcessList.h | 6 ++++ linux/Platform.c | 15 +------- 4 files changed, 84 insertions(+), 21 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index edcd61d24..6785410e7 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -64,18 +64,14 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { } memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT); double percent = Platform_setCPUValues(this, cpu); - if (cpu != 0 && this->pl->settings->showCPUFrequency) { - /* Initial frequency is in KHz. Divide it by 1000 till it's less than 1000, and emit unit accordingly */ + if (this->pl->settings->showCPUFrequency) { + /* Initial frequency is in MHz. Emit it as GHz if it's larger than 1000MHz */ double cpuFrequency = this->values[CPU_METER_FREQUENCY]; - char unit = 'K'; + char unit = 'M'; char cpuFrequencyBuffer[16]; if (cpuFrequency < 0) { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); } else { - if (cpuFrequency > 1000) { - cpuFrequency /= 1000; - unit = 'M'; - } if (cpuFrequency > 1000) { cpuFrequency /= 1000; unit = 'G'; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5f38540c6..39f8405f7 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -75,6 +75,8 @@ typedef struct CPUData_ { unsigned long long int softIrqPeriod; unsigned long long int stealPeriod; unsigned long long int guestPeriod; + + double frequency; } CPUData; typedef struct TtyDriver_ { @@ -100,6 +102,10 @@ typedef struct LinuxProcessList_ { #define PROCDIR "/proc" #endif +#ifndef PROCCPUINFOFILE +#define PROCCPUINFOFILE PROCDIR "/cpuinfo" +#endif + #ifndef PROCSTATFILE #define PROCSTATFILE PROCDIR "/stat" #endif @@ -1028,18 +1034,86 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { cpuData->stealTime = steal; cpuData->guestTime = virtalltime; cpuData->totalTime = totaltime; + } double period = (double)this->cpus[0].totalPeriod / cpus; fclose(file); return period; } +static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { + ProcessList* pl = (ProcessList*) this; + Settings* settings = pl->settings; + + int cpus = this->super.cpuCount; + assert(cpus > 0); + + for (int i = 0; i <= cpus; i++) { + CPUData* cpuData = &(this->cpus[i]); + cpuData->frequency = -1; + } + + int numCPUsWithFrequency = 0; + double totalFrequency = 0; + + if (settings->showCPUFrequency) { + FILE* file = fopen(PROCCPUINFOFILE, "r"); + if (file == NULL) { + CRT_fatalError("Cannot open " PROCCPUINFOFILE); + } + + int cpuid = -1; + double frequency; + while (!feof(file)) { + char buffer[PROC_LINE_LENGTH]; + char *ok = fgets(buffer, PROC_LINE_LENGTH, file); + if (!ok) break; + + if ( + (sscanf(buffer, "processor : %d", &cpuid) == 1) || + (sscanf(buffer, "processor: %d", &cpuid) == 1) + ) { + if (cpuid < 0 || cpuid > (cpus - 1)) { + char buffer[64]; + xSnprintf(buffer, sizeof(buffer), PROCCPUINFOFILE " contains out-of-range CPU number %d", cpuid); + CRT_fatalError(buffer); + } + } else if ( + (sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) || + (sscanf(buffer, "cpu MHz: %lf", &frequency) == 1) + ) { + if (cpuid < 0) { + CRT_fatalError(PROCCPUINFOFILE " is malformed: cpu MHz line without corresponding processor line"); + } + + int cpu = cpuid + 1; + CPUData* cpuData = &(this->cpus[cpu]); + cpuData->frequency = frequency; + numCPUsWithFrequency++; + totalFrequency += frequency; + } else if (buffer[0] == '\n') { + cpuid = -1; + } + } + fclose(file); + + if (numCPUsWithFrequency > 0) { + this->cpus[0].frequency = totalFrequency / numCPUsWithFrequency; + } + } + + double period = (double)this->cpus[0].totalPeriod / cpus; + return period; +} + void ProcessList_goThroughEntries(ProcessList* super) { LinuxProcessList* this = (LinuxProcessList*) super; LinuxProcessList_scanMemoryInfo(super); double period = LinuxProcessList_scanCPUTime(this); + LinuxProcessList_scanCPUFrequency(this); + struct timeval tv; gettimeofday(&tv, NULL); LinuxProcessList_recurseProcTree(this, PROCDIR, NULL, period, tv); diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index f30b487d6..ae36b3542 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -48,6 +48,8 @@ typedef struct CPUData_ { unsigned long long int softIrqPeriod; unsigned long long int stealPeriod; unsigned long long int guestPeriod; + + double frequency; } CPUData; typedef struct TtyDriver_ { @@ -73,6 +75,10 @@ typedef struct LinuxProcessList_ { #define PROCDIR "/proc" #endif +#ifndef PROCCPUINFOFILE +#define PROCCPUINFOFILE PROCDIR "/cpuinfo" +#endif + #ifndef PROCSTATFILE #define PROCSTATFILE PROCDIR "/stat" #endif diff --git a/linux/Platform.c b/linux/Platform.c index fc81d3bf9..806d4c007 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -193,20 +193,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; - v[CPU_METER_FREQUENCY] = -1; - if (this->pl->settings->showCPUFrequency) { - char filename[64]; - xSnprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cpu - 1); - FILE* fd = fopen(filename, "r"); - if (fd) { - unsigned int cpuFrequency; - int n = fscanf(fd, "%u", &cpuFrequency); - fclose(fd); - if (n > 0) { - v[CPU_METER_FREQUENCY] = cpuFrequency; - } - } - } + v[CPU_METER_FREQUENCY] = cpuData->frequency; return percent; } From e450b586368750e771746ef3e2f5a070962dfd28 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Tue, 3 Sep 2019 18:21:33 +0000 Subject: [PATCH 050/411] Refactor openzfs_sysctl_init() and ZfsArcMeter... openzfs_sysctl_init() now returns void instead of int. The ZfsArcStats->enabled flag is set inside the init function now, instead of having to be set from its return value. Preparation for more flag setting in Compressed ARC commit. ZfsArcMeter_readStats() added and all Meter->values[] setting moved to it, eliminating duplicated code in {darwin,freebsd,linux,solaris}/Platform.c. --- darwin/DarwinProcessList.c | 2 +- darwin/Platform.c | 13 +------------ freebsd/FreeBSDProcessList.c | 2 +- freebsd/Platform.c | 13 +------------ linux/Platform.c | 13 +------------ solaris/Platform.c | 13 +------------ zfs/ZfsArcMeter.c | 18 ++++++++++++++++++ zfs/ZfsArcMeter.h | 4 ++++ zfs/openzfs_sysctl.c | 6 +++--- zfs/openzfs_sysctl.h | 6 +++--- 10 files changed, 34 insertions(+), 56 deletions(-) diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 122e0188a..9b4ba119d 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -151,7 +151,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui ProcessList_getVMStats(&this->vm_stats); /* Initialize the ZFS kstats, if zfs.kext loaded */ - this->zfs.enabled = openzfs_sysctl_init(); + openzfs_sysctl_init(&this->zfs); openzfs_sysctl_updateArcStats(&this->zfs); this->super.kernelThreads = 0; diff --git a/darwin/Platform.c b/darwin/Platform.c index 8fbb9c933..f9f09b5a4 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -246,18 +246,7 @@ void Platform_setSwapValues(Meter* mtr) { void Platform_setZfsArcValues(Meter* this) { DarwinProcessList* dpl = (DarwinProcessList*) this->pl; - this->total = dpl->zfs.max; - this->values[0] = dpl->zfs.MFU; - this->values[1] = dpl->zfs.MRU; - this->values[2] = dpl->zfs.anon; - this->values[3] = dpl->zfs.header; - this->values[4] = dpl->zfs.other; - - // "Hide" the last value so it can - // only be accessed by index and is not - // displayed by the Bar or Graph style - Meter_setItems(this, 5); - this->values[5] = dpl->zfs.size; + ZfsArcMeter_readStats(this, &(dpl->zfs)); } char* Platform_getProcessEnv(pid_t pid) { diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 1cbfdaab8..fd6941985 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -118,7 +118,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui len = 2; sysctlnametomib("vfs.bufspace", MIB_vfs_bufspace, &len); - fpl->zfs.enabled = openzfs_sysctl_init(); + openzfs_sysctl_init(&fpl->zfs); openzfs_sysctl_updateArcStats(&fpl->zfs); int smp = 0; diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 05c0e9224..b08a508ec 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -202,18 +202,7 @@ void Platform_setSwapValues(Meter* this) { void Platform_setZfsArcValues(Meter* this) { FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl; - this->total = fpl->zfs.max; - this->values[0] = fpl->zfs.MFU; - this->values[1] = fpl->zfs.MRU; - this->values[2] = fpl->zfs.anon; - this->values[3] = fpl->zfs.header; - this->values[4] = fpl->zfs.other; - - // "Hide" the last value so it can - // only be accessed by index and is not - // displayed by the Bar or Graph style - Meter_setItems(this, 5); - this->values[5] = fpl->zfs.size; + ZfsArcMeter_readStats(this, &(fpl->zfs)); } void Platform_setTasksValues(Meter* this) { diff --git a/linux/Platform.c b/linux/Platform.c index e2a3c6d3f..69f668804 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -218,18 +218,7 @@ void Platform_setSwapValues(Meter* this) { void Platform_setZfsArcValues(Meter* this) { LinuxProcessList* lpl = (LinuxProcessList*) this->pl; - this->total = lpl->zfs.max; - this->values[0] = lpl->zfs.MFU; - this->values[1] = lpl->zfs.MRU; - this->values[2] = lpl->zfs.anon; - this->values[3] = lpl->zfs.header; - this->values[4] = lpl->zfs.other; - - // "Hide" the last value so it can - // only be accessed by index and is not - // displayed by the Bar or Graph style - Meter_setItems(this, 5); - this->values[5] = lpl->zfs.size; + ZfsArcMeter_readStats(this, &(lpl->zfs)); } char* Platform_getProcessEnv(pid_t pid) { diff --git a/solaris/Platform.c b/solaris/Platform.c index 8084d1fd9..74ae14ec6 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -225,18 +225,7 @@ void Platform_setSwapValues(Meter* this) { void Platform_setZfsArcValues(Meter* this) { SolarisProcessList* spl = (SolarisProcessList*) this->pl; - this->total = spl->zfs.max; - this->values[0] = spl->zfs.MFU; - this->values[1] = spl->zfs.MRU; - this->values[2] = spl->zfs.anon; - this->values[3] = spl->zfs.header; - this->values[4] = spl->zfs.other; - - // "Hide" the last value so it can - // only be accessed by index and is not - // displayed by the Bar or Graph style - Meter_setItems(this, 5); - this->values[5] = spl->zfs.size; + ZfsArcMeter_readStats(this, &(spl->zfs)); } static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) { diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index ebd809920..9f7028bc9 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -6,6 +6,7 @@ in the source distribution for its full text. */ #include "ZfsArcMeter.h" +#include "ZfsArcStats.h" #include "CRT.h" #include "Platform.h" @@ -17,6 +18,8 @@ in the source distribution for its full text. #include /*{ +#include "ZfsArcStats.h" + #include "Meter.h" }*/ @@ -24,6 +27,21 @@ int ZfsArcMeter_attributes[] = { ZFS_MFU, ZFS_MRU, ZFS_ANON, ZFS_HEADER, ZFS_OTHER }; +void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats) { + this->total = stats->max; + this->values[0] = stats->MFU; + this->values[1] = stats->MRU; + this->values[2] = stats->anon; + this->values[3] = stats->header; + this->values[4] = stats->other; + + // "Hide" the last value so it can + // only be accessed by index and is not + // displayed by the Bar or Graph style + Meter_setItems(this, 5); + this->values[5] = stats->size; +} + static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) { int written; Platform_setZfsArcValues(this); diff --git a/zfs/ZfsArcMeter.h b/zfs/ZfsArcMeter.h index b89be2233..c52083df2 100644 --- a/zfs/ZfsArcMeter.h +++ b/zfs/ZfsArcMeter.h @@ -9,10 +9,14 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "ZfsArcStats.h" + #include "Meter.h" extern int ZfsArcMeter_attributes[]; +void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats); + extern MeterClass ZfsArcMeter_class; #endif diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c index ce48f233e..ceee4d109 100644 --- a/zfs/openzfs_sysctl.c +++ b/zfs/openzfs_sysctl.c @@ -25,13 +25,14 @@ static int MIB_kstat_zfs_misc_arcstats_other_size[5]; #include "zfs/ZfsArcStats.h" }*/ -int openzfs_sysctl_init() { +void openzfs_sysctl_init(ZfsArcStats *stats) { size_t len; unsigned long long int arcSize; len = sizeof(arcSize); if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) { + stats->enabled = 1; len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); @@ -40,9 +41,8 @@ int openzfs_sysctl_init() { sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); - return 1; } else { - return 0; + stats->enabled = 0; } } diff --git a/zfs/openzfs_sysctl.h b/zfs/openzfs_sysctl.h index 7c04bd793..6e44ac3b1 100644 --- a/zfs/openzfs_sysctl.h +++ b/zfs/openzfs_sysctl.h @@ -1,7 +1,7 @@ /* Do not edit this file. It was automatically generated. */ -#ifndef HEADER_openzfs -#define HEADER_openzfs +#ifndef HEADER_openzfs_sysctl +#define HEADER_openzfs_sysctl /* htop - zfs/openzfs_sysctl.h (C) 2014 Hisham H. Muhammad @@ -11,7 +11,7 @@ in the source distribution for its full text. #include "zfs/ZfsArcStats.h" -int openzfs_sysctl_init(); +void openzfs_sysctl_init(ZfsArcStats *stats); void openzfs_sysctl_updateArcStats(ZfsArcStats *stats); From 613556faebd16325da8c9057c81f39a2410d803f Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Tue, 3 Sep 2019 18:26:02 +0000 Subject: [PATCH 051/411] Support for ZFS Compressed ARC statistics --- CRT.c | 14 ++++++ CRT.h | 2 + Makefile.am | 12 +++-- darwin/Platform.c | 8 ++++ darwin/Platform.h | 2 + freebsd/Platform.c | 8 ++++ freebsd/Platform.h | 2 + linux/LinuxProcessList.c | 10 +++++ linux/Platform.c | 7 +++ linux/Platform.h | 2 + solaris/Platform.c | 8 ++++ solaris/Platform.h | 2 + solaris/SolarisProcessList.c | 10 +++++ zfs/ZfsArcStats.c | 3 ++ zfs/ZfsArcStats.h | 3 ++ zfs/ZfsCompressedArcMeter.c | 86 ++++++++++++++++++++++++++++++++++++ zfs/ZfsCompressedArcMeter.h | 22 +++++++++ zfs/openzfs_sysctl.c | 18 ++++++++ 18 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 zfs/ZfsCompressedArcMeter.c create mode 100644 zfs/ZfsCompressedArcMeter.h diff --git a/CRT.c b/CRT.c index b9017aa48..cb36b6c09 100644 --- a/CRT.c +++ b/CRT.c @@ -133,6 +133,8 @@ typedef enum ColorElements_ { ZFS_ANON, ZFS_HEADER, ZFS_OTHER, + ZFS_COMPRESSED, + ZFS_RATIO, LAST_COLORELEMENT } ColorElements; @@ -242,6 +244,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_ANON] = ColorPair(Magenta,Black), [ZFS_HEADER] = ColorPair(Cyan,Black), [ZFS_OTHER] = ColorPair(Magenta,Black), + [ZFS_COMPRESSED] = ColorPair(Blue,Black), + [ZFS_RATIO] = ColorPair(Magenta,Black), }, [COLORSCHEME_MONOCHROME] = { [RESET_COLOR] = A_NORMAL, @@ -306,6 +310,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_ANON] = A_DIM, [ZFS_HEADER] = A_BOLD, [ZFS_OTHER] = A_DIM, + [ZFS_COMPRESSED] = A_BOLD, + [ZFS_RATIO] = A_BOLD, }, [COLORSCHEME_BLACKONWHITE] = { [RESET_COLOR] = ColorPair(Black,White), @@ -370,6 +376,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_ANON] = ColorPair(Magenta,White), [ZFS_HEADER] = ColorPair(Yellow,White), [ZFS_OTHER] = ColorPair(Magenta,White), + [ZFS_COMPRESSED] = ColorPair(Cyan,White), + [ZFS_RATIO] = ColorPair(Magenta,White), }, [COLORSCHEME_LIGHTTERMINAL] = { [RESET_COLOR] = ColorPair(Black,Black), @@ -434,6 +442,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_ANON] = A_BOLD | ColorPair(Magenta,Black), [ZFS_HEADER] = ColorPair(Black,Black), [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black), + [ZFS_COMPRESSED] = ColorPair(Cyan,Black), + [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Black), }, [COLORSCHEME_MIDNIGHT] = { [RESET_COLOR] = ColorPair(White,Blue), @@ -498,6 +508,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_ANON] = A_BOLD | ColorPair(Magenta,Blue), [ZFS_HEADER] = A_BOLD | ColorPair(Yellow,Blue), [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Blue), + [ZFS_COMPRESSED] = A_BOLD | ColorPair(White,Blue), + [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Blue), }, [COLORSCHEME_BLACKNIGHT] = { [RESET_COLOR] = ColorPair(Cyan,Black), @@ -562,6 +574,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_ANON] = ColorPair(Magenta,Black), [ZFS_HEADER] = ColorPair(Yellow,Black), [ZFS_OTHER] = ColorPair(Magenta,Black), + [ZFS_COMPRESSED] = ColorPair(Blue,Black), + [ZFS_RATIO] = ColorPair(Magenta,Black), }, [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. }; diff --git a/CRT.h b/CRT.h index 2275349a0..d9eba556b 100644 --- a/CRT.h +++ b/CRT.h @@ -121,6 +121,8 @@ typedef enum ColorElements_ { ZFS_ANON, ZFS_HEADER, ZFS_OTHER, + ZFS_COMPRESSED, + ZFS_RATIO, LAST_COLORELEMENT } ColorElements; diff --git a/Makefile.am b/Makefile.am index 204a8b7db..2d159f026 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ linux_platform_headers = \ linux/LinuxCRT.h \ linux/Battery.h \ zfs/ZfsArcMeter.h \ + zfs/ZfsCompressedArcMeter.h \ zfs/ZfsArcStats.h all_platform_headers += $(linux_platform_headers) @@ -58,7 +59,7 @@ if HTOP_LINUX AM_CFLAGS += -rdynamic myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \ -zfs/ZfsArcMeter.c zfs/ZfsArcStats.c +zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c myhtopplatheaders = $(linux_platform_headers) endif @@ -73,6 +74,7 @@ freebsd_platform_headers = \ freebsd/FreeBSDCRT.h \ freebsd/Battery.h \ zfs/ZfsArcMeter.h \ + zfs/ZfsCompressedArcMeter.h \ zfs/ZfsArcStats.h \ zfs/openzfs_sysctl.h @@ -81,7 +83,7 @@ all_platform_headers += $(freebsd_platform_headers) if HTOP_FREEBSD myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c \ -zfs/ZfsArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c +zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c myhtopplatheaders = $(freebsd_platform_headers) endif @@ -135,6 +137,7 @@ darwin_platform_headers = \ darwin/DarwinCRT.h \ darwin/Battery.h \ zfs/ZfsArcMeter.h \ + zfs/ZfsCompressedArcMeter.h \ zfs/ZfsArcStats.h \ zfs/openzfs_sysctl.h @@ -144,7 +147,7 @@ if HTOP_DARWIN AM_LDFLAGS += -framework IOKit -framework CoreFoundation myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \ darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c \ -zfs/ZfsArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c +zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c myhtopplatheaders = $(darwin_platform_headers) endif @@ -159,6 +162,7 @@ solaris_platform_headers = \ solaris/SolarisCRT.h \ solaris/Battery.h \ zfs/ZfsArcMeter.h \ + zfs/ZfsCompressedArcMeter.h \ zfs/ZfsArcStats.h all_platform_headers += $(solaris_platform_headers) @@ -167,7 +171,7 @@ if HTOP_SOLARIS myhtopplatsources = solaris/Platform.c \ solaris/SolarisProcess.c solaris/SolarisProcessList.c \ solaris/SolarisCRT.c solaris/Battery.c \ -zfs/ZfsArcMeter.c zfs/ZfsArcStats.c +zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c myhtopplatheaders = $(solaris_platform_headers) endif diff --git a/darwin/Platform.c b/darwin/Platform.c index f9f09b5a4..286ff16b2 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -16,6 +16,7 @@ in the source distribution for its full text. #include "HostnameMeter.h" #include "UptimeMeter.h" #include "zfs/ZfsArcMeter.h" +#include "zfs/ZfsCompressedArcMeter.h" #include "DarwinProcessList.h" #include @@ -119,6 +120,7 @@ MeterClass* Platform_meterTypes[] = { &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &ZfsArcMeter_class, + &ZfsCompressedArcMeter_class, &BlankMeter_class, NULL }; @@ -249,6 +251,12 @@ void Platform_setZfsArcValues(Meter* this) { ZfsArcMeter_readStats(this, &(dpl->zfs)); } +void Platform_setZfsCompressedArcValues(Meter* this) { + DarwinProcessList* dpl = (DarwinProcessList*) this->pl; + + ZfsCompressedArcMeter_readStats(this, &(dpl->zfs)); +} + char* Platform_getProcessEnv(pid_t pid) { char* env = NULL; diff --git a/darwin/Platform.h b/darwin/Platform.h index f83607754..e17661d61 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -50,6 +50,8 @@ void Platform_setSwapValues(Meter* mtr); void Platform_setZfsArcValues(Meter* this); +void Platform_setZfsCompressedArcValues(Meter* this); + char* Platform_getProcessEnv(pid_t pid); #endif diff --git a/freebsd/Platform.c b/freebsd/Platform.c index b08a508ec..0986a3dd7 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -16,6 +16,7 @@ in the source distribution for its full text. #include "ClockMeter.h" #include "HostnameMeter.h" #include "zfs/ZfsArcMeter.h" +#include "zfs/ZfsCompressedArcMeter.h" #include "FreeBSDProcess.h" #include "FreeBSDProcessList.h" @@ -106,6 +107,7 @@ MeterClass* Platform_meterTypes[] = { &RightCPUs2Meter_class, &BlankMeter_class, &ZfsArcMeter_class, + &ZfsCompressedArcMeter_class, NULL }; @@ -205,6 +207,12 @@ void Platform_setZfsArcValues(Meter* this) { ZfsArcMeter_readStats(this, &(fpl->zfs)); } +void Platform_setZfsCompressedArcValues(Meter* this) { + FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl; + + ZfsCompressedArcMeter_readStats(this, &(fpl->zfs)); +} + void Platform_setTasksValues(Meter* this) { // TODO } diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 3dc7ebf21..0268f2c64 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -46,6 +46,8 @@ void Platform_setSwapValues(Meter* this); void Platform_setZfsArcValues(Meter* this); +void Platform_setZfsCompressedArcValues(Meter* this); + void Platform_setTasksValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 3e8891046..4596c3bcd 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -984,9 +984,14 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { char buffer[128]; while (fgets(buffer, 128, file)) { #define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { break; } } while(0) + #define tryReadFlag(label, variable, flag) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { flag = 1; break; } else { flag = 0; } } while(0) switch (buffer[0]) { case 'c': tryRead("c_max", &lpl->zfs.max); + tryReadFlag("compressed", &lpl->zfs.compressed, &lpl->zfs.isCompressed); + break; + case 'u': + tryRead("uncompressed", &lpl->zfs.uncompressed); break; case 's': tryRead("size", &lpl->zfs.size); @@ -1010,6 +1015,7 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { break; } #undef tryRead + #undef tryReadFlag } fclose(file); @@ -1021,6 +1027,10 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { lpl->zfs.anon /= 1024; lpl->zfs.header /= 1024; lpl->zfs.other = (dbufSize + dnodeSize + bonusSize) / 1024; + if ( lpl->zfs.isCompressed ) { + lpl->zfs.compressed /= 1024; + lpl->zfs.uncompressed /= 1024; + } } static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { diff --git a/linux/Platform.c b/linux/Platform.c index 69f668804..f7088cf41 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -22,6 +22,7 @@ in the source distribution for its full text. #include "ClockMeter.h" #include "HostnameMeter.h" #include "zfs/ZfsArcMeter.h" +#include "zfs/ZfsCompressedArcMeter.h" #include "LinuxProcess.h" #include @@ -128,6 +129,7 @@ MeterClass* Platform_meterTypes[] = { &RightCPUs2Meter_class, &BlankMeter_class, &ZfsArcMeter_class, + &ZfsCompressedArcMeter_class, NULL }; @@ -221,6 +223,11 @@ void Platform_setZfsArcValues(Meter* this) { ZfsArcMeter_readStats(this, &(lpl->zfs)); } +void Platform_setZfsCompressedArcValues(Meter* this) { + LinuxProcessList* lpl = (LinuxProcessList*) this->pl; + + ZfsCompressedArcMeter_readStats(this, &(lpl->zfs)); +} char* Platform_getProcessEnv(pid_t pid) { char procname[32+1]; xSnprintf(procname, 32, "/proc/%d/environ", pid); diff --git a/linux/Platform.h b/linux/Platform.h index e775181e6..5d85eb366 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -45,6 +45,8 @@ void Platform_setSwapValues(Meter* this); void Platform_setZfsArcValues(Meter* this); +void Platform_setZfsCompressedArcValues(Meter* this); + char* Platform_getProcessEnv(pid_t pid); #endif diff --git a/solaris/Platform.c b/solaris/Platform.c index 74ae14ec6..7dcfe323b 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -18,6 +18,7 @@ in the source distribution for its full text. #include "HostnameMeter.h" #include "UptimeMeter.h" #include "zfs/ZfsArcMeter.h" +#include "zfs/ZfsCompressedArcMeter.h" #include "SolarisProcess.h" #include "SolarisProcessList.h" @@ -124,6 +125,7 @@ MeterClass* Platform_meterTypes[] = { &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &ZfsArcMeter_class, + &ZfsCompressedArcMeter_class, &BlankMeter_class, NULL }; @@ -228,6 +230,12 @@ void Platform_setZfsArcValues(Meter* this) { ZfsArcMeter_readStats(this, &(spl->zfs)); } +void Platform_setZfsCompressedArcValues(Meter* this) { + SolarisProcessList* spl = (SolarisProcessList*) this->pl; + + ZfsCompressedArcMeter_readStats(this, &(spl->zfs)); +} + static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) { envAccum *accump = accum; (void) Phandle; diff --git a/solaris/Platform.h b/solaris/Platform.h index 62757ff74..3b5aef860 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -62,6 +62,8 @@ void Platform_setSwapValues(Meter* this); void Platform_setZfsArcValues(Meter* this); +void Platform_setZfsCompressedArcValues(Meter* this); + char* Platform_getProcessEnv(pid_t pid); #endif diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index b6bc6f5dc..d62ea1d4d 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -263,6 +263,16 @@ static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { cur_kstat = kstat_data_lookup( arcstats, "other_size" ); spl->zfs.other = cur_kstat->value.ui64 / 1024; + + if ((cur_kstat = kstat_data_lookup( arcstats, "compressed_size" )) != NULL) { + spl->zfs.compressed = cur_kstat->value.ui64 / 1024; + spl->zfs.isCompressed = 1; + + cur_kstat = kstat_data_lookup( arcstats, "uncompressed_size" ); + spl->zfs.uncompressed = cur_kstat->value.ui64 / 1024; + } else { + spl->zfs.isCompressed = 0; + } } } diff --git a/zfs/ZfsArcStats.c b/zfs/ZfsArcStats.c index c33076a4b..1bfaf47d8 100644 --- a/zfs/ZfsArcStats.c +++ b/zfs/ZfsArcStats.c @@ -8,6 +8,7 @@ in the source distribution for its full text. /*{ typedef struct ZfsArcStats_ { int enabled; + int isCompressed; unsigned long long int max; unsigned long long int size; unsigned long long int MFU; @@ -15,5 +16,7 @@ typedef struct ZfsArcStats_ { unsigned long long int anon; unsigned long long int header; unsigned long long int other; + unsigned long long int compressed; + unsigned long long int uncompressed; } ZfsArcStats; }*/ diff --git a/zfs/ZfsArcStats.h b/zfs/ZfsArcStats.h index 3697af23d..ee5d0eddd 100644 --- a/zfs/ZfsArcStats.h +++ b/zfs/ZfsArcStats.h @@ -11,6 +11,7 @@ in the source distribution for its full text. typedef struct ZfsArcStats_ { int enabled; + int isCompressed; unsigned long long int max; unsigned long long int size; unsigned long long int MFU; @@ -18,6 +19,8 @@ typedef struct ZfsArcStats_ { unsigned long long int anon; unsigned long long int header; unsigned long long int other; + unsigned long long int compressed; + unsigned long long int uncompressed; } ZfsArcStats; #endif diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c new file mode 100644 index 000000000..ac3944d34 --- /dev/null +++ b/zfs/ZfsCompressedArcMeter.c @@ -0,0 +1,86 @@ +/* +htop - ZfsCompressedArcMeter.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "ZfsCompressedArcMeter.h" +#include "ZfsArcStats.h" + +#include "CRT.h" +#include "Platform.h" + +#include +#include +#include +#include +#include + +/*{ +#include "ZfsArcStats.h" + +#include "Meter.h" +}*/ + +int ZfsCompressedArcMeter_attributes[] = { + ZFS_COMPRESSED +}; + +void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats) { + if ( stats->isCompressed ) { + this->total = stats->uncompressed; + this->values[0] = stats->compressed; + } else { + // For uncompressed ARC, report 1:1 ratio + this->total = stats->size; + this->values[0] = stats->size; + } +} + +static void ZfsCompressedArcMeter_printRatioString(Meter* this, char* buffer, int size) { + xSnprintf(buffer, size, "%.2f:1", this->total/this->values[0]); +} + +static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int size) { + Platform_setZfsCompressedArcValues(this); + + ZfsCompressedArcMeter_printRatioString(this, buffer, size); +} + +static void ZfsCompressedArcMeter_display(Object* cast, RichString* out) { + char buffer[50]; + Meter* this = (Meter*)cast; + + if (this->values[0] > 0) { + Meter_humanUnit(buffer, this->total, 50); + RichString_append(out, CRT_colors[METER_VALUE], buffer); + RichString_append(out, CRT_colors[METER_TEXT], " Uncompressed, "); + Meter_humanUnit(buffer, this->values[0], 50); + RichString_append(out, CRT_colors[METER_VALUE], buffer); + RichString_append(out, CRT_colors[METER_TEXT], " Compressed, "); + ZfsCompressedArcMeter_printRatioString(this, buffer, 50); + RichString_append(out, CRT_colors[METER_VALUE], buffer); + RichString_append(out, CRT_colors[METER_TEXT], " Ratio"); + } else { + RichString_write(out, CRT_colors[METER_TEXT], " "); + RichString_append(out, CRT_colors[FAILED_SEARCH], "Compression Unavailable"); + } +} + +MeterClass ZfsCompressedArcMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = ZfsCompressedArcMeter_display, + }, + .updateValues = ZfsCompressedArcMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 1, + .total = 100.0, + .attributes = ZfsCompressedArcMeter_attributes, + .name = "ZFSCARC", + .uiName = "ZFS CARC", + .description = "ZFS CARC: Compressed ARC statistics", + .caption = "ARC: " +}; diff --git a/zfs/ZfsCompressedArcMeter.h b/zfs/ZfsCompressedArcMeter.h new file mode 100644 index 000000000..5afcc99e6 --- /dev/null +++ b/zfs/ZfsCompressedArcMeter.h @@ -0,0 +1,22 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_ZfsCompressedArcMeter +#define HEADER_ZfsCompressedArcMeter +/* +htop - ZfsCompressedArcMeter.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "ZfsArcStats.h" + +#include "Meter.h" + +extern int ZfsCompressedArcMeter_attributes[]; + +void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats); + +extern MeterClass ZfsCompressedArcMeter_class; + +#endif diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c index ceee4d109..c1ab22394 100644 --- a/zfs/openzfs_sysctl.c +++ b/zfs/openzfs_sysctl.c @@ -20,6 +20,8 @@ static int MIB_kstat_zfs_misc_arcstats_mru_size[5]; static int MIB_kstat_zfs_misc_arcstats_anon_size[5]; static int MIB_kstat_zfs_misc_arcstats_hdr_size[5]; static int MIB_kstat_zfs_misc_arcstats_other_size[5]; +static int MIB_kstat_zfs_misc_arcstats_compressed_size[5]; +static int MIB_kstat_zfs_misc_arcstats_uncompressed_size[5]; /*{ #include "zfs/ZfsArcStats.h" @@ -41,6 +43,12 @@ void openzfs_sysctl_init(ZfsArcStats *stats) { sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); + if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) { + stats->isCompressed = 1; + sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len); + } else { + stats->isCompressed = 0; + } } else { stats->enabled = 0; } @@ -77,5 +85,15 @@ void openzfs_sysctl_updateArcStats(ZfsArcStats *stats) { len = sizeof(stats->other); sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(stats->other), &len , NULL, 0); stats->other /= 1024; + + if (stats->isCompressed) { + len = sizeof(stats->compressed); + sysctl(MIB_kstat_zfs_misc_arcstats_compressed_size, 5, &(stats->compressed), &len , NULL, 0); + stats->compressed /= 1024; + + len = sizeof(stats->uncompressed); + sysctl(MIB_kstat_zfs_misc_arcstats_uncompressed_size, 5, &(stats->uncompressed), &len , NULL, 0); + stats->uncompressed /= 1024; + } } } From a267003f2f38df5d52ae3f07658c1bbd20b5fb5e Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Tue, 3 Sep 2019 19:56:38 +0000 Subject: [PATCH 052/411] Linux fixes --- linux/LinuxProcessList.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 4596c3bcd..1d5700e5d 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -988,10 +988,10 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { switch (buffer[0]) { case 'c': tryRead("c_max", &lpl->zfs.max); - tryReadFlag("compressed", &lpl->zfs.compressed, &lpl->zfs.isCompressed); + tryReadFlag("compressed_size", &lpl->zfs.compressed, lpl->zfs.isCompressed); break; case 'u': - tryRead("uncompressed", &lpl->zfs.uncompressed); + tryRead("uncompressed_size", &lpl->zfs.uncompressed); break; case 's': tryRead("size", &lpl->zfs.size); From 1886117c721c4d66a61f58bbfe5367e6fc527367 Mon Sep 17 00:00:00 2001 From: smattie Date: Sat, 7 Sep 2019 15:21:04 +0100 Subject: [PATCH 053/411] Linux: fixes sysfs battery discovery --- linux/Battery.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/linux/Battery.c b/linux/Battery.c index aedacabc8..029eff59e 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -193,7 +193,18 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { char* entryName = (char *) dirEntry->d_name; const char filePath[50]; - if (entryName[0] == 'B' && entryName[1] == 'A' && entryName[2] == 'T') { + xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); + int fd = open(filePath, O_RDONLY); + if (fd == -1) + continue; + + char type[8]; + ssize_t typelen = xread(fd, type, 7); + close(fd); + if (typelen < 1) + continue; + + if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') { xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); int fd = open(filePath, O_RDONLY); From 18a60d668ddebae0982b6f952089d9260f582a6a Mon Sep 17 00:00:00 2001 From: duchampdev Date: Thu, 12 Sep 2019 22:45:34 +0200 Subject: [PATCH 054/411] MainPanel: add seventh char to main functions reason: currently, for example 'search' and 'filter' look very densely packed --- MainPanel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MainPanel.c b/MainPanel.c index 25023367f..7cd9228e0 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -36,7 +36,7 @@ typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg); }*/ -static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL}; +static const char* const MainFunctions[] = {"Help ", "Setup ", "Search ", "Filter ", "Tree ", "SortBy ", "Nice - ", "Nice + ", "Kill ", "Quit ", NULL}; void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) { FunctionBar* bar = MainPanel_getFunctionBar(this); From 12805f61d89f2869352ed83b98986cab730bd6fb Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 31 Oct 2019 11:20:55 -0500 Subject: [PATCH 055/411] Add simple vim mode This commit adds a "vim_mode" setting (false/`0` by default) that causes keys to be remapped in the following way by the `ScreenManager`: + h -> LEFT + j -> DOWN + k -> UP + l -> RIGHT + LEFT -> h (toggle help) + DOWN -> j (noop) + UP -> k (open kill menu) + RIGHT -> l (lsof current process) + K (Shift+K) -> k (open kill menu) + J (Shift+J) -> K (toggle show/hide kernel threads) + L (Shift+L) -> l (lsof current process) I couldn't figure out where the manpage documentation is in the repo, though I admittedly did not look particularly hard. I believe this change would be a welcome option for heavy vim users like myself who would like a familiar way to get around in htop. --- ScreenManager.c | 17 +++++++++++++++++ Settings.c | 20 ++++++++++++-------- Settings.h | 3 ++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/ScreenManager.c b/ScreenManager.c index 06e901938..81aa2960c 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -190,6 +190,23 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { set_escdelay(25); ch = getch(); + if (this->settings->vimMode) { + switch (ch) { + case 'h': ch = KEY_LEFT; break; + case 'j': ch = KEY_DOWN; break; + case 'k': ch = KEY_UP; break; + case 'l': ch = KEY_RIGHT; break; + case KEY_LEFT: ch = 'h'; break; + case KEY_DOWN: ch = 'j'; break; + case KEY_UP: ch = 'k'; break; + case KEY_RIGHT: ch = 'l'; break; + case 'K': ch = 'k'; break; + case 'J': ch = 'K'; break; + case 'L': ch = 'l'; break; + } + } + + HandlerResult result = IGNORED; if (ch == KEY_MOUSE) { ch = ERR; diff --git a/Settings.c b/Settings.c index db2fa0668..c07b2cf7e 100644 --- a/Settings.c +++ b/Settings.c @@ -31,7 +31,7 @@ typedef struct { typedef struct Settings_ { char* filename; - + MeterColumnSettings columns[2]; ProcessField* fields; @@ -58,6 +58,7 @@ typedef struct Settings_ { bool updateProcessNames; bool accountGuestInCPUMeter; bool headerMargin; + bool vimMode; bool changed; } Settings; @@ -114,7 +115,7 @@ static void Settings_defaultMeters(Settings* this) { this->columns[i].modes = xCalloc(sizes[i], sizeof(int)); this->columns[i].len = sizes[i]; } - + int r = 0; if (this->cpuCount > 8) { this->columns[0].names[0] = xStrdup("LeftCPUs2"); @@ -134,7 +135,7 @@ static void Settings_defaultMeters(Settings* this) { this->columns[0].modes[1] = BAR_METERMODE; this->columns[0].names[2] = xStrdup("Swap"); this->columns[0].modes[2] = BAR_METERMODE; - + this->columns[1].names[r] = xStrdup("Tasks"); this->columns[1].modes[r++] = TEXT_METERMODE; this->columns[1].names[r] = xStrdup("LoadAverage"); @@ -165,13 +166,13 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { static bool Settings_read(Settings* this, const char* fileName) { FILE* fd; - + CRT_dropPrivileges(); fd = fopen(fileName, "r"); CRT_restorePrivileges(); if (!fd) return false; - + bool didReadMeters = false; bool didReadFields = false; for (;;) { @@ -244,6 +245,8 @@ static bool Settings_read(Settings* this, const char* fileName) { } else if (String_eq(option[0], "right_meter_modes")) { Settings_readMeterModes(this, option[1], 1); didReadMeters = true; + } else if (String_eq(option[0], "vim_mode")) { + this->vimMode = atoi(option[1]); } String_freeArray(option); } @@ -320,12 +323,13 @@ bool Settings_write(Settings* this) { fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0); fprintf(fd, "right_meters="); writeMeters(this, fd, 1); fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1); + fprintf(fd, "vim_mode=%d\n", (int) this->vimMode); fclose(fd); return true; } Settings* Settings_new(int cpuCount) { - + Settings* this = xCalloc(1, sizeof(Settings)); this->sortKey = PERCENT_CPU; @@ -344,7 +348,7 @@ Settings* Settings_new(int cpuCount) { this->cpuCount = cpuCount; this->showProgramPath = true; this->highlightThreads = true; - + this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); // TODO: turn 'fields' into a Vector, // (and ProcessFields into proper objects). @@ -375,7 +379,7 @@ Settings* Settings_new(int cpuCount) { htopDir = String_cat(home, "/.config/htop"); } legacyDotfile = String_cat(home, "/.htoprc"); - + CRT_dropPrivileges(); (void) mkdir(configDir, 0700); (void) mkdir(htopDir, 0700); diff --git a/Settings.h b/Settings.h index d9dc0683c..6e3fb512c 100644 --- a/Settings.h +++ b/Settings.h @@ -22,7 +22,7 @@ typedef struct { typedef struct Settings_ { char* filename; - + MeterColumnSettings columns[2]; ProcessField* fields; @@ -49,6 +49,7 @@ typedef struct Settings_ { bool updateProcessNames; bool accountGuestInCPUMeter; bool headerMargin; + bool vimMode; bool changed; } Settings; From 9ed47a213bee9fe272e1cf16f4d45730e6b37331 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 31 Oct 2019 11:29:28 -0500 Subject: [PATCH 056/411] Fix whitespace --- Settings.c | 16 ++++++++-------- Settings.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Settings.c b/Settings.c index c07b2cf7e..bf78f0f89 100644 --- a/Settings.c +++ b/Settings.c @@ -31,7 +31,7 @@ typedef struct { typedef struct Settings_ { char* filename; - + MeterColumnSettings columns[2]; ProcessField* fields; @@ -115,7 +115,7 @@ static void Settings_defaultMeters(Settings* this) { this->columns[i].modes = xCalloc(sizes[i], sizeof(int)); this->columns[i].len = sizes[i]; } - + int r = 0; if (this->cpuCount > 8) { this->columns[0].names[0] = xStrdup("LeftCPUs2"); @@ -135,7 +135,7 @@ static void Settings_defaultMeters(Settings* this) { this->columns[0].modes[1] = BAR_METERMODE; this->columns[0].names[2] = xStrdup("Swap"); this->columns[0].modes[2] = BAR_METERMODE; - + this->columns[1].names[r] = xStrdup("Tasks"); this->columns[1].modes[r++] = TEXT_METERMODE; this->columns[1].names[r] = xStrdup("LoadAverage"); @@ -166,13 +166,13 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { static bool Settings_read(Settings* this, const char* fileName) { FILE* fd; - + CRT_dropPrivileges(); fd = fopen(fileName, "r"); CRT_restorePrivileges(); if (!fd) return false; - + bool didReadMeters = false; bool didReadFields = false; for (;;) { @@ -329,7 +329,7 @@ bool Settings_write(Settings* this) { } Settings* Settings_new(int cpuCount) { - + Settings* this = xCalloc(1, sizeof(Settings)); this->sortKey = PERCENT_CPU; @@ -348,7 +348,7 @@ Settings* Settings_new(int cpuCount) { this->cpuCount = cpuCount; this->showProgramPath = true; this->highlightThreads = true; - + this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); // TODO: turn 'fields' into a Vector, // (and ProcessFields into proper objects). @@ -379,7 +379,7 @@ Settings* Settings_new(int cpuCount) { htopDir = String_cat(home, "/.config/htop"); } legacyDotfile = String_cat(home, "/.htoprc"); - + CRT_dropPrivileges(); (void) mkdir(configDir, 0700); (void) mkdir(htopDir, 0700); diff --git a/Settings.h b/Settings.h index 6e3fb512c..ec119d1c7 100644 --- a/Settings.h +++ b/Settings.h @@ -22,7 +22,7 @@ typedef struct { typedef struct Settings_ { char* filename; - + MeterColumnSettings columns[2]; ProcessField* fields; From dd33444f7eace81115308eadb568020470c48b2b Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 31 Oct 2019 11:39:12 -0500 Subject: [PATCH 057/411] Clean up existing whitespace --- Action.c | 4 +-- AvailableMetersPanel.c | 4 +-- BatteryMeter.c | 2 +- CPUMeter.c | 14 +++++----- CRT.c | 4 +-- CheckItem.c | 4 +-- ColorsPanel.c | 2 +- ColumnsPanel.c | 4 +-- DisplayOptionsPanel.c | 2 +- FunctionBar.c | 2 +- Hashtable.c | 8 +++--- Header.c | 10 +++---- InfoScreen.c | 4 +-- MainPanel.c | 6 ++-- MemoryMeter.c | 2 +- Meter.c | 16 +++++------ Meter.h | 2 +- MetersPanel.c | 2 +- Object.c | 2 +- Object.h | 2 +- Panel.c | 4 +-- Process.c | 10 +++---- ProcessList.c | 10 +++---- RichString.c | 2 +- RichString.h | 2 +- ScreenManager.c | 6 ++-- Settings.c | 16 +++++------ Settings.h | 2 +- StringUtils.c | 2 +- TasksMeter.c | 6 ++-- Vector.c | 4 +-- darwin/DarwinProcess.c | 12 ++++---- dragonflybsd/DragonFlyBSDProcessList.c | 2 +- htop.c | 26 +++++++++--------- linux/Battery.c | 8 +++--- linux/IOPriority.c | 2 +- linux/IOPriority.h | 2 +- linux/LinuxProcess.c | 4 +-- linux/LinuxProcess.h | 2 +- linux/LinuxProcessList.c | 38 +++++++++++++------------- linux/LinuxProcessList.h | 6 ++-- openbsd/Battery.c | 6 ++-- solaris/Platform.c | 14 +++++----- solaris/Platform.h | 2 +- solaris/SolarisProcessList.c | 22 +++++++-------- solaris/SolarisProcessList.h | 2 +- unsupported/UnsupportedProcessList.c | 2 +- 47 files changed, 155 insertions(+), 155 deletions(-) diff --git a/Action.c b/Action.c index 9a7c3c560..dba775639 100644 --- a/Action.c +++ b/Action.c @@ -66,7 +66,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) { Panel* panel = st->panel; Header* header = st->header; Settings* settings = st->settings; - + int y = panel->y; ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, false); scr->allowFocusChange = false; @@ -297,7 +297,7 @@ static Htop_Reaction actionSetAffinity(State* st) { return HTOP_OK; #if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY) Panel* panel = st->panel; - + Process* p = (Process*) Panel_getSelected(panel); if (!p) return HTOP_OK; Affinity* affinity = Affinity_get(p, st->pl); diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index ddb553679..f670f6b74 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -52,7 +52,7 @@ static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, M static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { AvailableMetersPanel* this = (AvailableMetersPanel*) super; Header* header = this->header; - + ListItem* selected = (ListItem*) Panel_getSelected(super); int param = selected->key & 0xff; int type = selected->key >> 16; @@ -104,7 +104,7 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade Panel* super = (Panel*) this; FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done "); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); - + this->settings = settings; this->header = header; this->leftPanel = leftMeters; diff --git a/BatteryMeter.c b/BatteryMeter.c index 214248e2e..716b77506 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -35,7 +35,7 @@ int BatteryMeter_attributes[] = { static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) { ACPresence isOnAC; double percent; - + Battery_getData(&percent, &isOnAC); if (percent == -1) { diff --git a/CPUMeter.c b/CPUMeter.c index de5490df1..8fbd1d459 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -219,7 +219,7 @@ MeterClass CPUMeter_class = { .defaultMode = BAR_METERMODE, .maxItems = CPU_METER_ITEMCOUNT, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "CPU", .uiName = "CPU", .caption = "CPU", @@ -234,7 +234,7 @@ MeterClass AllCPUsMeter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "AllCPUs", .uiName = "CPUs (1/1)", .description = "CPUs (1/1): all CPUs", @@ -253,7 +253,7 @@ MeterClass AllCPUs2Meter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "AllCPUs2", .uiName = "CPUs (1&2/2)", .description = "CPUs (1&2/2): all CPUs in 2 shorter columns", @@ -272,7 +272,7 @@ MeterClass LeftCPUsMeter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "LeftCPUs", .uiName = "CPUs (1/2)", .description = "CPUs (1/2): first half of list", @@ -291,7 +291,7 @@ MeterClass RightCPUsMeter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "RightCPUs", .uiName = "CPUs (2/2)", .description = "CPUs (2/2): second half of list", @@ -310,7 +310,7 @@ MeterClass LeftCPUs2Meter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "LeftCPUs2", .uiName = "CPUs (1&2/4)", .description = "CPUs (1&2/4): first half in 2 shorter columns", @@ -329,7 +329,7 @@ MeterClass RightCPUs2Meter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "RightCPUs2", .uiName = "CPUs (3&4/4)", .description = "CPUs (3&4/4): second half in 2 shorter columns", diff --git a/CRT.c b/CRT.c index ca9a10dd8..b35a176d0 100644 --- a/CRT.c +++ b/CRT.c @@ -604,12 +604,12 @@ void CRT_init(int delay, int colorScheme) { } CRT_colors = CRT_colorSchemes[colorScheme]; CRT_colorScheme = colorScheme; - + for (int i = 0; i < LAST_COLORELEMENT; i++) { unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][i]; CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPairGrayBlack) ? ColorPair(White,Black) : color; } - + halfdelay(CRT_delay); nonl(); intrflush(stdscr, false); diff --git a/CheckItem.c b/CheckItem.c index b7ba6fec6..910981e86 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -66,14 +66,14 @@ CheckItem* CheckItem_newByVal(char* text, bool value) { } void CheckItem_set(CheckItem* this, bool value) { - if (this->ref) + if (this->ref) *(this->ref) = value; else this->value = value; } bool CheckItem_get(CheckItem* this) { - if (this->ref) + if (this->ref) return *(this->ref); else return this->value; diff --git a/ColorsPanel.c b/ColorsPanel.c index 2028335f9..b2d3500cc 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -56,7 +56,7 @@ static void ColorsPanel_delete(Object* object) { static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) { ColorsPanel* this = (ColorsPanel*) super; - + HandlerResult result = IGNORED; int mark = Panel_getSelectedIndex(super); diff --git a/ColumnsPanel.c b/ColumnsPanel.c index 8974ffdc3..f982292ef 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -40,7 +40,7 @@ static void ColumnsPanel_delete(Object* object) { static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { ColumnsPanel* const this = (ColumnsPanel*) super; - + int selected = Panel_getSelectedIndex(super); HandlerResult result = IGNORED; int size = Panel_size(super); @@ -87,7 +87,7 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { case ']': case '+': { - if (selected < size - 2) + if (selected < size - 2) Panel_moveSelectedDown(super); result = HANDLED; break; diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 0ff54e331..40b8d9877 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -39,7 +39,7 @@ static void DisplayOptionsPanel_delete(Object* object) { static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { DisplayOptionsPanel* this = (DisplayOptionsPanel*) super; - + HandlerResult result = IGNORED; CheckItem* selected = (CheckItem*) Panel_getSelected(super); diff --git a/FunctionBar.c b/FunctionBar.c index 4e4baaf3b..8661bf0c1 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -52,7 +52,7 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke this->functions[i] = xStrdup(functions[i]); } if (keys && events) { - this->staticData = false; + this->staticData = false; this->keys = xCalloc(15, sizeof(char*)); this->events = xCalloc(15, sizeof(int)); int i = 0; diff --git a/Hashtable.c b/Hashtable.c index b3eac8daa..3436dad62 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -63,7 +63,7 @@ int Hashtable_count(Hashtable* this) { static HashtableItem* HashtableItem_new(unsigned int key, void* value) { HashtableItem* this; - + this = xMalloc(sizeof(HashtableItem)); this->key = key; this->value = value; @@ -73,7 +73,7 @@ static HashtableItem* HashtableItem_new(unsigned int key, void* value) { Hashtable* Hashtable_new(int size, bool owner) { Hashtable* this; - + this = xMalloc(sizeof(Hashtable)); this->items = 0; this->size = size; @@ -119,10 +119,10 @@ void Hashtable_put(Hashtable* this, unsigned int key, void* value) { void* Hashtable_remove(Hashtable* this, unsigned int key) { unsigned int index = key % this->size; - + assert(Hashtable_isConsistent(this)); - HashtableItem** bucket; + HashtableItem** bucket; for (bucket = &(this->buckets[index]); *bucket; bucket = &((*bucket)->next) ) { if ((*bucket)->key == key) { void* value = (*bucket)->value; diff --git a/Header.c b/Header.c index e048ee556..7742289fa 100644 --- a/Header.c +++ b/Header.c @@ -76,17 +76,17 @@ void Header_populateFromSettings(Header* this) { void Header_writeBackToSettings(const Header* this) { Header_forEachColumn(this, col) { MeterColumnSettings* colSettings = &this->settings->columns[col]; - + String_freeArray(colSettings->names); free(colSettings->modes); - + Vector* vec = this->columns[col]; int len = Vector_size(vec); - + colSettings->names = xCalloc(len+1, sizeof(char*)); colSettings->modes = xCalloc(len, sizeof(int)); colSettings->len = len; - + for (int i = 0; i < len; i++) { Meter* meter = (Meter*) Vector_get(vec, i); char* name = xCalloc(64, sizeof(char)); @@ -186,7 +186,7 @@ void Header_draw(const Header* this) { } int width = COLS / this->nrColumns - (pad * this->nrColumns - 1) - 1; int x = pad; - + Header_forEachColumn(this, col) { Vector* meters = this->columns[col]; for (int y = (pad / 2), i = 0; i < Vector_size(meters); i++) { diff --git a/InfoScreen.c b/InfoScreen.c index fab8daeaf..0e7543a3b 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -120,7 +120,7 @@ void InfoScreen_run(InfoScreen* this) { } set_escdelay(25); int ch = getch(); - + if (ch == ERR) { if (As_InfoScreen(this)->onErr) { InfoScreen_onErr(this); @@ -143,7 +143,7 @@ void InfoScreen_run(InfoScreen* this) { IncSet_handleKey(this->inc, ch, panel, IncSet_getListItemValue, this->lines); continue; } - + switch(ch) { case ERR: continue; diff --git a/MainPanel.c b/MainPanel.c index 25023367f..b271162ae 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -69,7 +69,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { MainPanel* this = (MainPanel*) super; HandlerResult result = IGNORED; - + Htop_Reaction reaction = HTOP_OK; if (EVENT_IS_HEADER_CLICK(ch)) { @@ -84,7 +84,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { } else { reaction |= Action_setSortKey(settings, field); } - reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS; + reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS; result = HANDLED; } else if (ch != ERR && this->inc->active) { bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL); @@ -121,7 +121,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { } if (reaction & HTOP_REFRESH) { result |= REDRAW; - } + } if (reaction & HTOP_RECALCULATE) { result |= RESCAN; } diff --git a/MemoryMeter.c b/MemoryMeter.c index fbf5330c9..8d5d809e0 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -60,7 +60,7 @@ MeterClass MemoryMeter_class = { .delete = Meter_delete, .display = MemoryMeter_display, }, - .updateValues = MemoryMeter_updateValues, + .updateValues = MemoryMeter_updateValues, .defaultMode = BAR_METERMODE, .maxItems = 3, .total = 100.0, diff --git a/Meter.c b/Meter.c index 05a4eb239..e2a29a69c 100644 --- a/Meter.c +++ b/Meter.c @@ -78,7 +78,7 @@ typedef struct MeterClass_ { struct Meter_ { Object super; Meter_Draw draw; - + char* caption; int mode; int param; @@ -275,7 +275,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { attrset(CRT_colors[BAR_BORDER]); mvaddch(y, x, '['); mvaddch(y, x + w, ']'); - + w--; x++; @@ -284,7 +284,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { return; } char bar[w + 1]; - + int blockSizes[10]; xSnprintf(bar, w + 1, "%*.*s", w, w, buffer); @@ -378,7 +378,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { mvaddnstr(y, x, this->caption, captionLen); x += captionLen; w -= captionLen; - + struct timeval now; gettimeofday(&now, NULL); if (!timercmp(&now, &(data->time), <)) { @@ -387,10 +387,10 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { for (int i = 0; i < nValues - 1; i++) data->values[i] = data->values[i+1]; - + char buffer[nValues]; Meter_updateValues(this, buffer, nValues - 1); - + double value = 0.0; int items = Meter_getItems(this); for (int i = 0; i < items; i++) @@ -398,7 +398,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { value /= this->total; data->values[nValues - 1] = value; } - + int i = nValues - (w*2) + 2, k = 0; if (i < 0) { k = -i/2; @@ -459,7 +459,7 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { char buffer[METER_BUFFER_LEN]; Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1); - + RichString_begin(out); Meter_displayBuffer(this, buffer, &out); diff --git a/Meter.h b/Meter.h index d98c910ed..4a7ce4482 100644 --- a/Meter.h +++ b/Meter.h @@ -65,7 +65,7 @@ typedef struct MeterClass_ { struct Meter_ { Object super; Meter_Draw draw; - + char* caption; int mode; int param; diff --git a/MetersPanel.c b/MetersPanel.c index 3cf3e0758..397a6c7d5 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -93,7 +93,7 @@ static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { MetersPanel* this = (MetersPanel*) super; - + int selected = Panel_getSelectedIndex(super); HandlerResult result = IGNORED; bool sideMove = false; diff --git a/Object.c b/Object.c index 120d28c14..cf13b6485 100644 --- a/Object.c +++ b/Object.c @@ -28,7 +28,7 @@ typedef void(*Object_Delete)(Object*); #define Class(class_) ((ObjectClass*)(&(class_ ## _class))) #define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); - + typedef struct ObjectClass_ { const void* extends; const Object_Display display; diff --git a/Object.h b/Object.h index 19a667c8a..fdb9b37c3 100644 --- a/Object.h +++ b/Object.h @@ -29,7 +29,7 @@ typedef void(*Object_Delete)(Object*); #define Class(class_) ((ObjectClass*)(&(class_ ## _class))) #define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); - + typedef struct ObjectClass_ { const void* extends; const Object_Display display; diff --git a/Panel.c b/Panel.c index 1e53b4a4d..fc4fa3c2d 100644 --- a/Panel.c +++ b/Panel.c @@ -372,7 +372,7 @@ void Panel_draw(Panel* this, bool focus) { bool Panel_onKey(Panel* this, int key) { assert (this != NULL); - + int size = Vector_size(this->items); switch (key) { case KEY_DOWN: @@ -455,7 +455,7 @@ bool Panel_onKey(Panel* this, int key) { if (this->selected < 0 || size == 0) { this->selected = 0; this->needsRedraw = true; - } else if (this->selected >= size) { + } else if (this->selected >= size) { this->selected = size - 1; this->needsRedraw = true; } diff --git a/Process.c b/Process.c index 54c41af4f..1738d3b74 100644 --- a/Process.c +++ b/Process.c @@ -216,7 +216,7 @@ void Process_setupColumnWidths() { void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { char buffer[11]; int len; - + int largeNumberColor = CRT_colors[LARGE_NUMBER]; int processMegabytesColor = CRT_colors[PROCESS_MEGABYTES]; int processColor = CRT_colors[PROCESS]; @@ -224,7 +224,7 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { largeNumberColor = CRT_colors[PROCESS]; processMegabytesColor = CRT_colors[PROCESS]; } - + if(number >= (10 * ONE_DECIMAL_M)) { #ifdef __LP64__ if(number >= (100 * ONE_DECIMAL_G)) { @@ -380,9 +380,9 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) { switch (field) { case PERCENT_CPU: { if (this->percent_cpu > 999.9) { - xSnprintf(buffer, n, "%4u ", (unsigned int)this->percent_cpu); + xSnprintf(buffer, n, "%4u ", (unsigned int)this->percent_cpu); } else if (this->percent_cpu > 99.9) { - xSnprintf(buffer, n, "%3u. ", (unsigned int)this->percent_cpu); + xSnprintf(buffer, n, "%3u. ", (unsigned int)this->percent_cpu); } else { xSnprintf(buffer, n, "%4.1f ", this->percent_cpu); } @@ -390,7 +390,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) { } case PERCENT_MEM: { if (this->percent_mem > 99.9) { - xSnprintf(buffer, n, "100. "); + xSnprintf(buffer, n, "100. "); } else { xSnprintf(buffer, n, "%4.1f ", this->percent_mem); } diff --git a/ProcessList.c b/ProcessList.c index 7482b0377..edbc114cb 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -84,10 +84,10 @@ ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* this->usersTable = usersTable; this->pidWhiteList = pidWhiteList; this->userId = userId; - + // tree-view auxiliary buffer this->processes2 = Vector_new(klass, true, DEFAULT_SIZE); - + // set later by platform-specific code this->cpuCount = 0; @@ -138,10 +138,10 @@ void ProcessList_printHeader(ProcessList* this, RichString* header) { void ProcessList_add(ProcessList* this, Process* p) { assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1); assert(Hashtable_get(this->processTable, p->pid) == NULL); - + Vector_add(this->processes, p); Hashtable_put(this->processTable, p->pid, p); - + assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1); assert(Hashtable_get(this->processTable, p->pid) != NULL); assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); @@ -353,7 +353,7 @@ void ProcessList_scan(ProcessList* this) { this->runningTasks = 0; ProcessList_goThroughEntries(this); - + for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { Process* p = (Process*) Vector_get(this->processes, i); if (p->updated == false) diff --git a/RichString.c b/RichString.c index 370566a87..d246f1e1b 100644 --- a/RichString.c +++ b/RichString.c @@ -67,7 +67,7 @@ typedef struct RichString_ { #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #endif -#define charBytes(n) (sizeof(CharType) * (n)) +#define charBytes(n) (sizeof(CharType) * (n)) static void RichString_extendLen(RichString* this, int len) { if (this->chlen <= RICHSTRING_MAXLEN) { diff --git a/RichString.h b/RichString.h index f5b5cba10..17649d0f2 100644 --- a/RichString.h +++ b/RichString.h @@ -63,7 +63,7 @@ typedef struct RichString_ { #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #endif -#define charBytes(n) (sizeof(CharType) * (n)) +#define charBytes(n) (sizeof(CharType) * (n)) #define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0) diff --git a/ScreenManager.c b/ScreenManager.c index 06e901938..54d4ea45f 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -163,7 +163,7 @@ static Panel* setCurrentPanel(Panel* panel) { void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { bool quit = false; int focus = 0; - + Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); double oldTime = 0.0; @@ -181,7 +181,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (this->header) { checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut); } - + if (redraw) { ScreenManager_drawPanels(this, focus); } @@ -269,7 +269,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { quit = true; continue; } - + switch (ch) { case KEY_RESIZE: { diff --git a/Settings.c b/Settings.c index db2fa0668..fea6c3b73 100644 --- a/Settings.c +++ b/Settings.c @@ -31,7 +31,7 @@ typedef struct { typedef struct Settings_ { char* filename; - + MeterColumnSettings columns[2]; ProcessField* fields; @@ -114,7 +114,7 @@ static void Settings_defaultMeters(Settings* this) { this->columns[i].modes = xCalloc(sizes[i], sizeof(int)); this->columns[i].len = sizes[i]; } - + int r = 0; if (this->cpuCount > 8) { this->columns[0].names[0] = xStrdup("LeftCPUs2"); @@ -134,7 +134,7 @@ static void Settings_defaultMeters(Settings* this) { this->columns[0].modes[1] = BAR_METERMODE; this->columns[0].names[2] = xStrdup("Swap"); this->columns[0].modes[2] = BAR_METERMODE; - + this->columns[1].names[r] = xStrdup("Tasks"); this->columns[1].modes[r++] = TEXT_METERMODE; this->columns[1].names[r] = xStrdup("LoadAverage"); @@ -165,13 +165,13 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { static bool Settings_read(Settings* this, const char* fileName) { FILE* fd; - + CRT_dropPrivileges(); fd = fopen(fileName, "r"); CRT_restorePrivileges(); if (!fd) return false; - + bool didReadMeters = false; bool didReadFields = false; for (;;) { @@ -325,7 +325,7 @@ bool Settings_write(Settings* this) { } Settings* Settings_new(int cpuCount) { - + Settings* this = xCalloc(1, sizeof(Settings)); this->sortKey = PERCENT_CPU; @@ -344,7 +344,7 @@ Settings* Settings_new(int cpuCount) { this->cpuCount = cpuCount; this->showProgramPath = true; this->highlightThreads = true; - + this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); // TODO: turn 'fields' into a Vector, // (and ProcessFields into proper objects). @@ -375,7 +375,7 @@ Settings* Settings_new(int cpuCount) { htopDir = String_cat(home, "/.config/htop"); } legacyDotfile = String_cat(home, "/.htoprc"); - + CRT_dropPrivileges(); (void) mkdir(configDir, 0700); (void) mkdir(htopDir, 0700); diff --git a/Settings.h b/Settings.h index d9dc0683c..d662c3199 100644 --- a/Settings.h +++ b/Settings.h @@ -22,7 +22,7 @@ typedef struct { typedef struct Settings_ { char* filename; - + MeterColumnSettings columns[2]; ProcessField* fields; diff --git a/StringUtils.c b/StringUtils.c index 0578cdea4..2f5889f63 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -116,7 +116,7 @@ char* String_getToken(const char* line, const unsigned short int numMatch) { if (lastState == 0 && inWord == 1) count++; - + if(inWord == 1){ if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) { match[foundCount] = line[i]; diff --git a/TasksMeter.c b/TasksMeter.c index f56c86133..996109cf7 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -37,9 +37,9 @@ static void TasksMeter_display(Object* cast, RichString* out) { Meter* this = (Meter*)cast; Settings* settings = this->pl->settings; char buffer[20]; - + int processes = (int) this->values[2]; - + xSnprintf(buffer, sizeof(buffer), "%d", processes); RichString_write(out, CRT_colors[METER_VALUE], buffer); int threadValueColor = CRT_colors[METER_VALUE]; @@ -76,7 +76,7 @@ MeterClass TasksMeter_class = { .defaultMode = TEXT_METERMODE, .maxItems = 4, .total = 100.0, - .attributes = TasksMeter_attributes, + .attributes = TasksMeter_attributes, .name = "Tasks", .uiName = "Task counter", .caption = "Tasks: " diff --git a/Vector.c b/Vector.c index 6eb91ae69..819d9863d 100644 --- a/Vector.c +++ b/Vector.c @@ -195,7 +195,7 @@ void Vector_insert(Vector* this, int idx, void* data_) { if (idx > this->items) { idx = this->items; } - + Vector_checkArraySize(this); //assert(this->array[this->items] == NULL); for (int i = this->items; i > idx; i--) { @@ -302,7 +302,7 @@ inline int Vector_size(Vector* this) { static void Vector_merge(Vector* this, Vector* v2) { int i; assert(Vector_isConsistent(this)); - + for (i = 0; i < v2->items; i++) Vector_add(this, v2->array[i]); v2->items = 0; diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index e1a16f9cf..bf5fd5771 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -212,7 +212,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { ERROR_A: retval = xStrdup(k->kp_proc.p_comm); *basenameOffset = strlen(retval); - + return retval; } @@ -302,11 +302,11 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList void DarwinProcess_scanThreads(DarwinProcess *dp) { Process* proc = (Process*) dp; kern_return_t ret; - + if (!dp->taskAccess) { return; } - + if (proc->state == 'Z') { return; } @@ -317,7 +317,7 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) { dp->taskAccess = false; return; } - + task_info_data_t tinfo; mach_msg_type_number_t task_info_count = TASK_INFO_MAX; ret = task_info(port, TASK_BASIC_INFO, (task_info_t) tinfo, &task_info_count); @@ -325,7 +325,7 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) { dp->taskAccess = false; return; } - + thread_array_t thread_list; mach_msg_type_number_t thread_count; ret = task_threads(port, &thread_list, &thread_count); @@ -334,7 +334,7 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) { mach_port_deallocate(mach_task_self(), port); return; } - + integer_t run_state = 999; for (unsigned int i = 0; i < thread_count; i++) { thread_info_data_t thinfo; diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index a41af8544..5bc4b3841 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -565,7 +565,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { if (kproc->kp_flags & P_JAILED) { proc->state = 'J'; } - + if (Process_isKernelThread(dfp)) { this->kernelThreads++; } diff --git a/htop.c b/htop.c index 8c88c782a..07a4fdf9e 100644 --- a/htop.c +++ b/htop.c @@ -34,7 +34,7 @@ static void printVersionFlag() { stdout); exit(0); } - + static void printHelpFlag() { fputs("htop " VERSION " - " COPYRIGHT "\n" "Released under the GNU GPL.\n\n" @@ -186,12 +186,12 @@ int main(int argc, char** argv) { exit(1); } #endif - + Process_setupColumnWidths(); - + UsersTable* ut = UsersTable_new(); ProcessList* pl = ProcessList_new(ut, flags.pidWhiteList, flags.userId); - + Settings* settings = Settings_new(pl->cpuCount); pl->settings = settings; @@ -201,18 +201,18 @@ int main(int argc, char** argv) { if (flags.delay != -1) settings->delay = flags.delay; - if (!flags.useColors) + if (!flags.useColors) settings->colorScheme = COLORSCHEME_MONOCHROME; if (flags.treeView) settings->treeView = true; CRT_init(settings->delay, settings->colorScheme); - + MainPanel* panel = MainPanel_new(); ProcessList_setPanel(pl, (Panel*) panel); MainPanel_updateTreeFunctions(panel, settings->treeView); - + if (flags.sortKey > 0) { settings->sortKey = flags.sortKey; settings->treeView = false; @@ -228,7 +228,7 @@ int main(int argc, char** argv) { .header = header, }; MainPanel_setState(panel, &state); - + ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true); ScreenManager_add(scr, (Panel*) panel, -1); @@ -236,13 +236,13 @@ int main(int argc, char** argv) { millisleep(75); ProcessList_scan(pl); - ScreenManager_run(scr, NULL, NULL); - + ScreenManager_run(scr, NULL, NULL); + attron(CRT_colors[RESET_COLOR]); mvhline(LINES-1, 0, ' ', COLS); attroff(CRT_colors[RESET_COLOR]); refresh(); - + CRT_done(); if (settings->changed) Settings_write(settings); @@ -250,10 +250,10 @@ int main(int argc, char** argv) { ProcessList_delete(pl); ScreenManager_delete(scr); - + UsersTable_delete(ut); Settings_delete(settings); - + if(flags.pidWhiteList) { Hashtable_delete(flags.pidWhiteList); } diff --git a/linux/Battery.c b/linux/Battery.c index aedacabc8..7b9e79a15 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -78,7 +78,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short const unsigned long int foundNum = atoi(foundNumStr); free(foundNumStr); free(line); - + total += foundNum; } @@ -175,7 +175,7 @@ static inline ssize_t xread(int fd, void *buf, size_t count) { } static void Battery_getSysData(double* level, ACPresence* isOnAC) { - + *level = 0; *isOnAC = AC_ERROR; @@ -194,7 +194,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { const char filePath[50]; if (entryName[0] == 'B' && entryName[1] == 'A' && entryName[2] == 'T') { - + xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); int fd = open(filePath, O_RDONLY); if (fd == -1) { @@ -247,7 +247,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { if (*isOnAC != AC_ERROR) { continue; } - + xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); int fd = open(filePath, O_RDONLY); if (fd == -1) { diff --git a/linux/IOPriority.c b/linux/IOPriority.c index dd7c84a14..80007df07 100644 --- a/linux/IOPriority.c +++ b/linux/IOPriority.c @@ -4,7 +4,7 @@ htop - IOPriority.c Released under the GNU GPL, see the COPYING file in the source distribution for its full text. -Based on ionice, +Based on ionice, Copyright (C) 2005 Jens Axboe Released under the terms of the GNU General Public License version 2 */ diff --git a/linux/IOPriority.h b/linux/IOPriority.h index 148e344c5..1c9ca95b8 100644 --- a/linux/IOPriority.h +++ b/linux/IOPriority.h @@ -8,7 +8,7 @@ htop - IOPriority.h Released under the GNU GPL, see the COPYING file in the source distribution for its full text. -Based on ionice, +Based on ionice, Copyright (C) 2005 Jens Axboe Released under the terms of the GNU General Public License version 2 */ diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 5f697078f..3bedbf668 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -117,7 +117,7 @@ typedef struct LinuxProcess_ { unsigned long long io_write_bytes; unsigned long long io_cancelled_write_bytes; unsigned long long io_rate_read_time; - unsigned long long io_rate_write_time; + unsigned long long io_rate_write_time; double io_rate_read_bps; double io_rate_write_bps; #endif @@ -394,7 +394,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) attr = CRT_colors[PROCESS_HIGH_PRIORITY]; xSnprintf(buffer, n, "R%1d ", IOPriority_data(lp->ioPriority)); } else if (klass == IOPRIO_CLASS_IDLE) { - attr = CRT_colors[PROCESS_LOW_PRIORITY]; + attr = CRT_colors[PROCESS_LOW_PRIORITY]; xSnprintf(buffer, n, "id "); } else { xSnprintf(buffer, n, "?? "); diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 6ce3037d2..4b81539fd 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -108,7 +108,7 @@ typedef struct LinuxProcess_ { unsigned long long io_write_bytes; unsigned long long io_cancelled_write_bytes; unsigned long long io_rate_read_time; - unsigned long long io_rate_write_time; + unsigned long long io_rate_write_time; double io_rate_read_bps; double io_rate_write_bps; #endif diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5f38540c6..ec543be62 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -62,7 +62,7 @@ typedef struct CPUData_ { unsigned long long int softIrqTime; unsigned long long int stealTime; unsigned long long int guestTime; - + unsigned long long int totalPeriod; unsigned long long int userPeriod; unsigned long long int systemPeriod; @@ -86,10 +86,10 @@ typedef struct TtyDriver_ { typedef struct LinuxProcessList_ { ProcessList super; - + CPUData* cpus; TtyDriver* ttyDrivers; - + #ifdef HAVE_DELAYACCT struct nl_sock *netlink_socket; int netlink_family; @@ -319,7 +319,7 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, location += 2; char *end = strrchr(location, ')'); if (!end) return false; - + int commsize = end - location; memcpy(command, location, commsize); command[commsize] = '\0'; @@ -370,9 +370,9 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, location += 1; assert(location != NULL); process->processor = strtol(location, &location, 10); - + process->time = lp->utime + lp->stime; - + return true; } @@ -412,7 +412,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna process->io_rate_write_time = -1LL; return; } - + char buffer[1024]; ssize_t buflen = xread(fd, buffer, 1023); close(fd); @@ -429,7 +429,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna process->io_rchar = strtoull(line+7, NULL, 10); else if (strncmp(line+1, "ead_bytes: ", 11) == 0) { process->io_read_bytes = strtoull(line+12, NULL, 10); - process->io_rate_read_bps = + process->io_rate_read_bps = ((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000); process->io_rate_read_time = now; } @@ -439,7 +439,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna process->io_wchar = strtoull(line+7, NULL, 10); else if (strncmp(line+1, "rite_bytes: ", 12) == 0) { process->io_write_bytes = strtoull(line+13, NULL, 10); - process->io_rate_write_bps = + process->io_rate_write_bps = ((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000); process->io_rate_write_time = now; } @@ -661,7 +661,7 @@ static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProc process->cpu_delay_percent = -1LL; return; } - + if (nl_recvmsgs_default(this->netlink_socket) < 0) { return; } @@ -685,11 +685,11 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna int fd = open(filename, O_RDONLY); if (fd == -1) return false; - + char command[4096+1]; // max cmdline length on Linux int amtRead = xread(fd, command, sizeof(command) - 1); close(fd); - int tokenEnd = 0; + int tokenEnd = 0; int lastChar = 0; if (amtRead == 0) { ((LinuxProcess*)process)->isKernelThread = true; @@ -726,13 +726,13 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in i++; if ((!ttyDrivers[i].path) || maj < ttyDrivers[i].major) { break; - } + } if (maj > ttyDrivers[i].major) { continue; } if (min < ttyDrivers[i].minorFrom) { break; - } + } if (min > ttyDrivers[i].minorTo) { continue; } @@ -790,17 +790,17 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* // filename is a number: process directory int pid = atoi(name); - + if (parent && pid == parent->pid) continue; - if (pid <= 0) + if (pid <= 0) continue; bool preExisting = false; Process* proc = ProcessList_getProcess(pl, pid, &preExisting, (Process_New) LinuxProcess_new); proc->tgid = parent ? parent->pid : pid; - + LinuxProcess* lp = (LinuxProcess*) proc; char subdirname[MAX_NAME+1]; @@ -846,7 +846,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* LinuxProcessList_readOpenVZData(lp, dirname, name); } #endif - + #ifdef HAVE_VSERVER if (settings->flags & PROCESS_FLAG_LINUX_VSERVER) { LinuxProcessList_readVServerData(lp, dirname, name); @@ -874,7 +874,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* if (settings->flags & PROCESS_FLAG_LINUX_CGROUP) LinuxProcessList_readCGroupFile(lp, dirname, name); #endif - + if (settings->flags & PROCESS_FLAG_LINUX_OOM) LinuxProcessList_readOomData(lp, dirname, name); diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index f30b487d6..81f87a590 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -35,7 +35,7 @@ typedef struct CPUData_ { unsigned long long int softIrqTime; unsigned long long int stealTime; unsigned long long int guestTime; - + unsigned long long int totalPeriod; unsigned long long int userPeriod; unsigned long long int systemPeriod; @@ -59,10 +59,10 @@ typedef struct TtyDriver_ { typedef struct LinuxProcessList_ { ProcessList super; - + CPUData* cpus; TtyDriver* ttyDrivers; - + #ifdef HAVE_DELAYACCT struct nl_sock *netlink_socket; int netlink_family; diff --git a/openbsd/Battery.c b/openbsd/Battery.c index 3a0bae143..70fb62980 100644 --- a/openbsd/Battery.c +++ b/openbsd/Battery.c @@ -34,7 +34,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { size_t sdlen = sizeof(struct sensordev); bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen); - + *level = -1; if (found) { /* last full capacity */ @@ -57,9 +57,9 @@ void Battery_getData(double* level, ACPresence* isOnAC) { } } } - + found = findDevice("acpiac0", mib, &snsrdev, &sdlen); - + *isOnAC = AC_ERROR; if (found) { mib[3] = 9; diff --git a/solaris/Platform.c b/solaris/Platform.c index a29fcb479..396b502c7 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -48,7 +48,7 @@ typedef struct var kvar_t; typedef struct envAccum_ { size_t capacity; size_t size; - size_t bytes; + size_t bytes; char *env; } envAccum; @@ -136,7 +136,7 @@ extern char Process_pidFormat[20]; int Platform_getUptime() { int boot_time = 0; - int curr_time = time(NULL); + int curr_time = time(NULL); struct utmpx * ent; while (( ent = getutxent() )) { @@ -170,7 +170,7 @@ int Platform_getMaxPid() { vproc = ksvar->v_proc; } if (kc != NULL) { kstat_close(kc); } - return vproc; + return vproc; } double Platform_setCPUValues(Meter* this, int cpu) { @@ -223,7 +223,7 @@ void Platform_setSwapValues(Meter* this) { static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) { envAccum *accump = accum; (void) Phandle; - (void) addr; + (void) addr; size_t thissz = strlen(str); if ((thissz + 2) > (accump->capacity - accump->size)) accump->env = xRealloc(accump->env, accump->capacity *= 2); @@ -232,7 +232,7 @@ static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr strlcpy( accump->env + accump->size, str, (accump->capacity - accump->size)); strncpy( accump->env + accump->size + thissz + 1, "\n", 1); accump->size = accump->size + thissz + 1; - return 0; + return 0; } char* Platform_getProcessEnv(pid_t pid) { @@ -240,7 +240,7 @@ char* Platform_getProcessEnv(pid_t pid) { pid_t realpid = pid / 1024; int graberr; struct ps_prochandle *Phandle; - + if ((Phandle = Pgrab(realpid,PGRAB_RDONLY,&graberr)) == NULL) return "Unable to read process environment."; @@ -248,7 +248,7 @@ char* Platform_getProcessEnv(pid_t pid) { envBuilder.size = 0; envBuilder.env = xMalloc(envBuilder.capacity); - (void) Penv_iter(Phandle,Platform_buildenv,&envBuilder); + (void) Penv_iter(Phandle,Platform_buildenv,&envBuilder); Prelease(Phandle, 0); diff --git a/solaris/Platform.h b/solaris/Platform.h index f961b913b..ffec60c92 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -27,7 +27,7 @@ typedef struct var kvar_t; typedef struct envAccum_ { size_t capacity; size_t size; - size_t bytes; + size_t bytes; char *env; } envAccum; diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 2c681852b..f452fe79f 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -153,7 +153,7 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { idlebuf += cpuData->idlePercent; } } - + if (cpus > 1) { CPUData* cpuData = &(spl->cpus[0]); cpuData->userPercent = userbuf / cpus; @@ -177,7 +177,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { uint64_t totalswap = 0; uint64_t totalfree = 0; int nswap = 0; - char *spath = NULL; + char *spath = NULL; char *spathbase = NULL; // Part 1 - physical memory @@ -191,7 +191,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { pl->totalMem = totalmem_pgs->value.ui64 * PAGE_SIZE_KB; pl->usedMem = lockedmem_pgs->value.ui64 * PAGE_SIZE_KB; // Not sure how to implement this on Solaris - suggestions welcome! - pl->cachedMem = 0; + pl->cachedMem = 0; // Not really "buffers" but the best Solaris analogue that I can find to // "memory in use but not by programs or the kernel itself" pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * PAGE_SIZE_KB; @@ -202,12 +202,12 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { pl->cachedMem = 0; pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * PAGE_SIZE); } - + // Part 2 - swap nswap = swapctl(SC_GETNSWP, NULL); if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); } if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); } - if (spathbase != NULL) { + if (spathbase != NULL) { spath = spathbase; swapdev = sl->swt_ent; for (int i = 0; i < nswap; i++, swapdev++) { @@ -217,7 +217,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { sl->swt_n = nswap; } nswap = swapctl(SC_LIST, sl); - if (nswap > 0) { + if (nswap > 0) { swapdev = sl->swt_ent; for (int i = 0; i < nswap; i++, swapdev++) { totalswap += swapdev->ste_pages; @@ -227,7 +227,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { free(spathbase); free(sl); pl->totalSwap = totalswap * PAGE_SIZE_KB; - pl->usedSwap = pl->totalSwap - (totalfree * PAGE_SIZE_KB); + pl->usedSwap = pl->totalSwap - (totalfree * PAGE_SIZE_KB); } void ProcessList_delete(ProcessList* pl) { @@ -242,7 +242,7 @@ void ProcessList_delete(ProcessList* pl) { * and MUST conform to the appropriate definition in order * to work. See libproc(3LIB) on a Solaris or Illumos * system for more info. - */ + */ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr) { struct timeval tv; @@ -262,7 +262,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * getpid = _psinfo->pr_pid * 1024; } else { getpid = lwpid; - } + } Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, (Process_New) SolarisProcess_new); SolarisProcess *sproc = (SolarisProcess*) proc; @@ -293,7 +293,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * sproc->realpid = _psinfo->pr_pid; sproc->lwpid = lwpid_real; sproc->zoneid = _psinfo->pr_zoneid; - sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc); + sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc); proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid); proc->comm = xStrdup(_psinfo->pr_fname); proc->commLen = strnlen(_psinfo->pr_fname,PRFNSZ); @@ -332,7 +332,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu/(double)32768)*(double)100.0; proc->time = _lwpsinfo->pr_time.tv_sec; if (!preExisting) { // Tasks done only for NEW LWPs - sproc->is_lwp = true; + sproc->is_lwp = true; proc->basenameOffset = -1; proc->ppid = _psinfo->pr_pid * 1024; proc->tgid = _psinfo->pr_pid * 1024; diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index a5f2fbc25..9d2309ccc 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -54,7 +54,7 @@ void ProcessList_delete(ProcessList* pl); * and MUST conform to the appropriate definition in order * to work. See libproc(3LIB) on a Solaris or Illumos * system for more info. - */ + */ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr); diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index 9be4eee48..65749b18c 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -18,7 +18,7 @@ in the source distribution for its full text. ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { ProcessList* this = xCalloc(1, sizeof(ProcessList)); ProcessList_init(this, Class(Process), usersTable, pidWhiteList, userId); - + return this; } From 63fbc3b51704b4b122d2cab57de7e7f9dfcc03b1 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 31 Oct 2019 11:39:57 -0500 Subject: [PATCH 058/411] Add `trim_trailing_whitespace` to editorconfig --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index 188078926..dd881dd0a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,3 +14,4 @@ charset = utf-8 [*.{c,h}] indent_style = space indent_size = 3 +trim_trailing_whitespace = true From 37cc11253e68102ec636f24719d8ee13c60764a4 Mon Sep 17 00:00:00 2001 From: Stefan Date: Mon, 11 Nov 2019 00:54:51 +0100 Subject: [PATCH 059/411] Added missing option --- htop.1.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htop.1.in b/htop.1.in index 149b1465a..2450b5bbb 100644 --- a/htop.1.in +++ b/htop.1.in @@ -1,9 +1,10 @@ -.TH "HTOP" "1" "2015" "@PACKAGE_STRING@" "Utils" +.TH "HTOP" "1" "2019" "@PACKAGE_STRING@" "Utils" .SH "NAME" htop \- interactive process viewer .SH "SYNOPSIS" .LP -.B htop [\fI\-dChustv\fR] +.B htop +.RB [ \-dChpustv ] .SH "DESCRIPTION" .LP Htop is a free (GPL) ncurses-based process viewer for Linux. From 88c9ebb8f725a9430bbb82b810d8ac6373b86131 Mon Sep 17 00:00:00 2001 From: Jure Oder Date: Fri, 13 Dec 2019 13:05:28 +0100 Subject: [PATCH 060/411] Properly identify zombie processes This closes issue #930. --- linux/LinuxProcessList.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5f38540c6..b374ab409 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -692,7 +692,11 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna int tokenEnd = 0; int lastChar = 0; if (amtRead == 0) { - ((LinuxProcess*)process)->isKernelThread = true; + if (process->state == 'Z') { + process->basenameOffset = 0; + } else { + ((LinuxProcess*)process)->isKernelThread = true; + } return true; } else if (amtRead < 0) { return false; From ccf0e184149ff42d76a73214bed0b578c6dcb2ab Mon Sep 17 00:00:00 2001 From: Dave Marquardt Date: Mon, 16 Dec 2019 15:45:55 -0600 Subject: [PATCH 061/411] update man page text about delay --- htop.1.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htop.1.in b/htop.1.in index 149b1465a..01295ff46 100644 --- a/htop.1.in +++ b/htop.1.in @@ -22,7 +22,9 @@ Mandatory arguments to long options are mandatory for short options too. .LP .TP \fB\-d \-\-delay=DELAY\fR -Delay between updates, in tenths of seconds +Delay between updates, in tenths of seconds. If the delay value is +less than 1 it is increased to 1, i.e. 1/10 second. If the delay value +is greater than 100, it is decreased to 100, i.e. 10 seconds. .TP \fB\-C \-\-no-color \-\-no-colour\fR Start htop in monochrome mode From 87c05ac136ac31647282009f474b6f62b1cc0a17 Mon Sep 17 00:00:00 2001 From: Robert Crowston Date: Sun, 29 Dec 2019 02:10:36 +0000 Subject: [PATCH 062/411] Fix STARTTIME column on FreeBSD. --- freebsd/FreeBSDProcessList.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 9fef324a5..ccacf9d46 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -18,6 +18,7 @@ in the source distribution for its full text. #include #include #include +#include /*{ @@ -429,10 +430,14 @@ void ProcessList_goThroughEntries(ProcessList* this) { int count = 0; struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count); + struct timeval tv; + gettimeofday(&tv, NULL); + for (int i = 0; i < count; i++) { struct kinfo_proc* kproc = &kprocs[i]; bool preExisting = false; bool isIdleProcess = false; + struct tm date; Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, (Process_New) FreeBSDProcess_new); FreeBSDProcess* fp = (FreeBSDProcess*) proc; @@ -523,6 +528,9 @@ void ProcessList_goThroughEntries(ProcessList* this) { this->kernelThreads++; } + (void) localtime_r((time_t*) &proc->starttime_ctime, &date); + strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date); + this->totalTasks++; if (proc->state == 'R') this->runningTasks++; From 6b5b8bab2c68576416abffe56b254791d828cce3 Mon Sep 17 00:00:00 2001 From: fo40225 Date: Mon, 27 Apr 2020 12:31:17 +0800 Subject: [PATCH 063/411] fix "Broken Gray" didn't change the color of cpu-iowait --- CRT.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRT.c b/CRT.c index ca9a10dd8..15534f8fb 100644 --- a/CRT.c +++ b/CRT.c @@ -227,7 +227,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black), [CPU_NORMAL] = ColorPair(Green,Black), [CPU_KERNEL] = ColorPair(Red,Black), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black), + [CPU_IOWAIT] = A_BOLD | ColorPairGrayBlack, [CPU_IRQ] = ColorPair(Yellow,Black), [CPU_SOFTIRQ] = ColorPair(Magenta,Black), [CPU_STEAL] = ColorPair(Cyan,Black), From 05c974f6ccceee352db98862c62e55043d2e2ea3 Mon Sep 17 00:00:00 2001 From: fo40225 Date: Mon, 27 Apr 2020 12:32:58 +0800 Subject: [PATCH 064/411] format color --- CRT.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRT.c b/CRT.c index 15534f8fb..ea33ebb80 100644 --- a/CRT.c +++ b/CRT.c @@ -345,7 +345,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE_TEXT] = ColorPair(Cyan,White), [CPU_NORMAL] = ColorPair(Green,White), [CPU_KERNEL] = ColorPair(Red,White), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black, White), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black,White), [CPU_IRQ] = ColorPair(Blue,White), [CPU_SOFTIRQ] = ColorPair(Blue,White), [CPU_STEAL] = ColorPair(Cyan,White), @@ -404,7 +404,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE_TEXT] = ColorPair(Cyan,Black), [CPU_NORMAL] = ColorPair(Green,Black), [CPU_KERNEL] = ColorPair(Red,Black), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black,Black), [CPU_IRQ] = A_BOLD | ColorPair(Blue,Black), [CPU_SOFTIRQ] = ColorPair(Blue,Black), [CPU_STEAL] = ColorPair(Black,Black), From 1b4ed916b1eae12fc66ff95ce5c2dc1ff4b771e7 Mon Sep 17 00:00:00 2001 From: Jorge Pereira Date: Thu, 11 Jun 2020 13:30:24 -0300 Subject: [PATCH 065/411] Fix use of '-rdynamic' The option should be informed to the linker. --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 7d19600f6..7cf13a85f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,7 +53,7 @@ linux_platform_headers = \ all_platform_headers += $(linux_platform_headers) if HTOP_LINUX -AM_CFLAGS += -rdynamic +AM_LDFLAGS += -rdynamic myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c From 8de04986cf1fbb9d7555ae64e9f17ef5a43bec65 Mon Sep 17 00:00:00 2001 From: Jorge Pereira Date: Thu, 11 Jun 2020 13:41:13 -0300 Subject: [PATCH 066/411] Fix misleading indentation --- InfoScreen.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/InfoScreen.c b/InfoScreen.c index fab8daeaf..860e19836 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -131,12 +131,15 @@ void InfoScreen_run(InfoScreen* this) { if (ch == KEY_MOUSE) { MEVENT mevent; int ok = getmouse(&mevent); - if (ok == OK) + if (ok == OK) { if (mevent.y >= panel->y && mevent.y < LINES - 1) { Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV); ch = 0; - } if (mevent.y == LINES - 1) + } + if (mevent.y == LINES - 1){ ch = IncSet_synthesizeEvent(this->inc, mevent.x); + } + } } if (this->inc->active) { From 832e77c7547efe6605acbc5f0d7ea4cb1a0799e9 Mon Sep 17 00:00:00 2001 From: Jorge Pereira Date: Thu, 11 Jun 2020 13:44:14 -0300 Subject: [PATCH 067/411] Let the user know about their error If the user informed wrong value, then let them know about that. --- htop.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htop.c b/htop.c index 8c88c782a..d64755360 100644 --- a/htop.c +++ b/htop.c @@ -112,6 +112,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { flags.sortKey = ColumnsPanel_fieldNameToIndex(optarg); if (flags.sortKey == -1) { fprintf(stderr, "Error: invalid column \"%s\".\n", optarg); + exit(1); } break; case 'd': @@ -120,11 +121,13 @@ static CommandLineSettings parseArguments(int argc, char** argv) { if (flags.delay > 100) flags.delay = 100; } else { fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg); + exit(1); } break; case 'u': if (!Action_setUserOnly(optarg, &(flags.userId))) { fprintf(stderr, "Error: invalid user \"%s\".\n", optarg); + exit(1); } break; case 'C': From f74cde982fba7df515a02ff07a00df966da3eff4 Mon Sep 17 00:00:00 2001 From: Christoph Budziszewski Date: Thu, 11 Jun 2020 23:00:16 +0200 Subject: [PATCH 068/411] removed whitespace from end of lines --- CPUMeter.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index de5490df1..8fbd1d459 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -219,7 +219,7 @@ MeterClass CPUMeter_class = { .defaultMode = BAR_METERMODE, .maxItems = CPU_METER_ITEMCOUNT, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "CPU", .uiName = "CPU", .caption = "CPU", @@ -234,7 +234,7 @@ MeterClass AllCPUsMeter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "AllCPUs", .uiName = "CPUs (1/1)", .description = "CPUs (1/1): all CPUs", @@ -253,7 +253,7 @@ MeterClass AllCPUs2Meter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "AllCPUs2", .uiName = "CPUs (1&2/2)", .description = "CPUs (1&2/2): all CPUs in 2 shorter columns", @@ -272,7 +272,7 @@ MeterClass LeftCPUsMeter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "LeftCPUs", .uiName = "CPUs (1/2)", .description = "CPUs (1/2): first half of list", @@ -291,7 +291,7 @@ MeterClass RightCPUsMeter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "RightCPUs", .uiName = "CPUs (2/2)", .description = "CPUs (2/2): second half of list", @@ -310,7 +310,7 @@ MeterClass LeftCPUs2Meter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "LeftCPUs2", .uiName = "CPUs (1&2/4)", .description = "CPUs (1&2/4): first half in 2 shorter columns", @@ -329,7 +329,7 @@ MeterClass RightCPUs2Meter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "RightCPUs2", .uiName = "CPUs (3&4/4)", .description = "CPUs (3&4/4): second half in 2 shorter columns", From 7fdd8d3732354b3fcca2d0430731e8e33345ddda Mon Sep 17 00:00:00 2001 From: Christoph Budziszewski Date: Thu, 11 Jun 2020 23:21:52 +0200 Subject: [PATCH 069/411] adding support for more than 2 smaller cpumeter columns --- CPUMeter.c | 92 +++++++++++++++++++++++++++++++++++++++++++----- CPUMeter.h | 5 +++ linux/Platform.c | 3 ++ 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 8fbd1d459..9c63f41ee 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -137,6 +137,15 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) { } } +static int MapClassnameToColumncount(Meter* this){ + if (strchr(Meter_name(this), '4')) + return 4; + else if (strchr(Meter_name(this), '2')) + return 2; + else + return 1; +} + static void AllCPUsMeter_init(Meter* this) { int cpus = this->pl->cpuCount; if (!this->drawData) @@ -152,10 +161,8 @@ static void AllCPUsMeter_init(Meter* this) { if (this->mode == 0) this->mode = BAR_METERMODE; int h = Meter_modes[this->mode]->h; - if (strchr(Meter_name(this), '2')) - this->h = h * ((count+1) / 2); - else - this->h = h * count; + int ncol = MapClassnameToColumncount(this); + this->h = h * ((count + ncol - 1)/ ncol); } static void AllCPUsMeter_done(Meter* this) { @@ -175,10 +182,8 @@ static void AllCPUsMeter_updateMode(Meter* this, int mode) { for (int i = 0; i < count; i++) { Meter_setMode(meters[i], mode); } - if (strchr(Meter_name(this), '2')) - this->h = h * ((count+1) / 2); - else - this->h = h * count; + int ncol = MapClassnameToColumncount(this); + this->h = h * ((count + ncol - 1)/ ncol); } static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) { @@ -209,6 +214,21 @@ static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) { } } +static void MultiColCPUsMeter_draw(Meter* this, int x, int y, int w){ + Meter** meters = (Meter**) this->drawData; + int start, count; + AllCPUsMeter_getRange(this, &start, &count); + int ncol = MapClassnameToColumncount(this); + int colwidth = (w-ncol)/ncol + 1; + int diff = (w - (colwidth * ncol)); + for (int i = 0; i < count; i++){ + int d = (i%ncol) > diff ? diff : (i % ncol) ; // dynamic spacer + int xpos = x + ((i % ncol) * colwidth) + d; + int ypos = y + ((i / ncol) * meters[0]->h); + meters[i]->draw(meters[i], xpos, ypos, colwidth); + } +} + MeterClass CPUMeter_class = { .super = { .extends = Class(Meter), @@ -340,3 +360,59 @@ MeterClass RightCPUs2Meter_class = { .done = AllCPUsMeter_done }; +MeterClass AllCPUs4Meter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = CPUMeter_display + }, + .defaultMode = CUSTOM_METERMODE, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "AllCPUs4", + .uiName = "CPUs (1&2&3&4/4)", + .description = "CPUs (1&2&3&4/4): all CPUs in 4 shorter columns", + .caption = "CPU", + .draw = MultiColCPUsMeter_draw, + .init = AllCPUsMeter_init, + .updateMode = AllCPUsMeter_updateMode, + .done = AllCPUsMeter_done +}; + +MeterClass LeftCPUs4Meter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = CPUMeter_display + }, + .defaultMode = CUSTOM_METERMODE, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "LeftCPUs4", + .uiName = "CPUs (1-4/8)", + .description = "CPUs (1-4/8): first half in 4 shorter columns", + .caption = "CPU", + .draw = MultiColCPUsMeter_draw, + .init = AllCPUsMeter_init, + .updateMode = AllCPUsMeter_updateMode, + .done = AllCPUsMeter_done +}; + +MeterClass RightCPUs4Meter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = CPUMeter_display + }, + .defaultMode = CUSTOM_METERMODE, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "RightCPUs4", + .uiName = "CPUs (5-8/8)", + .description = "CPUs (5-8/8): second half in 4 shorter columns", + .caption = "CPU", + .draw = MultiColCPUsMeter_draw, + .init = AllCPUsMeter_init, + .updateMode = AllCPUsMeter_updateMode, + .done = AllCPUsMeter_done +}; diff --git a/CPUMeter.h b/CPUMeter.h index 2f1639680..5018028c9 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -47,5 +47,10 @@ extern MeterClass LeftCPUs2Meter_class; extern MeterClass RightCPUs2Meter_class; +extern MeterClass AllCPUs4Meter_class; + +extern MeterClass LeftCPUs4Meter_class; + +extern MeterClass RightCPUs4Meter_class; #endif diff --git a/linux/Platform.c b/linux/Platform.c index ab90ca74b..62222bc66 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -121,10 +121,13 @@ MeterClass* Platform_meterTypes[] = { &HostnameMeter_class, &AllCPUsMeter_class, &AllCPUs2Meter_class, + &AllCPUs4Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, &BlankMeter_class, NULL }; From b55f9320bc40a465cd33ddbf6e8c9b7223ae538d Mon Sep 17 00:00:00 2001 From: Christoph Budziszewski Date: Fri, 12 Jun 2020 23:53:05 +0200 Subject: [PATCH 070/411] fixed x/y coordinate mixup --- CPUMeter.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 9c63f41ee..99be44f82 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -221,10 +221,11 @@ static void MultiColCPUsMeter_draw(Meter* this, int x, int y, int w){ int ncol = MapClassnameToColumncount(this); int colwidth = (w-ncol)/ncol + 1; int diff = (w - (colwidth * ncol)); + int nrows = (count + ncol - 1) / ncol; for (int i = 0; i < count; i++){ - int d = (i%ncol) > diff ? diff : (i % ncol) ; // dynamic spacer - int xpos = x + ((i % ncol) * colwidth) + d; - int ypos = y + ((i / ncol) * meters[0]->h); + int d = (i/nrows) > diff ? diff : (i / nrows) ; // dynamic spacer + int xpos = x + ((i / nrows) * colwidth) + d; + int ypos = y + ((i % nrows) * meters[0]->h); meters[i]->draw(meters[i], xpos, ypos, colwidth); } } From dfd9279f87791e36a5212726781c31fbe7110361 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Fri, 10 Jul 2020 10:35:32 +1000 Subject: [PATCH 071/411] Resolve complation issues with -fno-common (default from gcc-10) Extends the MakeHeader script to auto-generate correct "extern" function declarations in some cases that it currently does not. Related to https://github.com/hishamhm/htop/pull/981 --- CRT.c | 4 ++-- CRT.h | 28 ++++++++++++++-------------- linux/LinuxProcess.c | 3 ++- linux/LinuxProcess.h | 19 ++++++++++--------- scripts/MakeHeader.py | 4 +++- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/CRT.c b/CRT.c index ca9a10dd8..088cd1a41 100644 --- a/CRT.c +++ b/CRT.c @@ -131,9 +131,9 @@ typedef enum ColorElements_ { LAST_COLORELEMENT } ColorElements; -void CRT_fatalError(const char* note) __attribute__ ((noreturn)); +extern void CRT_fatalError(const char* note) __attribute__ ((noreturn)); -void CRT_handleSIGSEGV(int sgn); +extern void CRT_handleSIGSEGV(int sgn); #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) diff --git a/CRT.h b/CRT.h index 933fe068e..bc3fb8b72 100644 --- a/CRT.h +++ b/CRT.h @@ -119,9 +119,9 @@ typedef enum ColorElements_ { LAST_COLORELEMENT } ColorElements; -void CRT_fatalError(const char* note) __attribute__ ((noreturn)); +extern void CRT_fatalError(const char* note) __attribute__ ((noreturn)); -void CRT_handleSIGSEGV(int sgn); +extern void CRT_handleSIGSEGV(int sgn); #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) @@ -140,7 +140,7 @@ extern const char **CRT_treeStr; extern int CRT_delay; -int* CRT_colors; +extern int* CRT_colors; extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT]; @@ -150,21 +150,21 @@ extern int CRT_scrollHAmount; extern int CRT_scrollWheelVAmount; -char* CRT_termType; +extern char* CRT_termType; // TODO move color scheme to Settings, perhaps? extern int CRT_colorScheme; -void *backtraceArray[128]; +extern void *backtraceArray[128]; #if HAVE_SETUID_ENABLED #define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0) -void CRT_dropPrivileges(); +extern void CRT_dropPrivileges(); -void CRT_restorePrivileges(); +extern void CRT_restorePrivileges(); #else @@ -179,18 +179,18 @@ void CRT_restorePrivileges(); // TODO: pass an instance of Settings instead. -void CRT_init(int delay, int colorScheme); +extern void CRT_init(int delay, int colorScheme); -void CRT_done(); +extern void CRT_done(); -void CRT_fatalError(const char* note); +extern void CRT_fatalError(const char* note); -int CRT_readKey(); +extern int CRT_readKey(); -void CRT_disableDelay(); +extern void CRT_disableDelay(); -void CRT_enableDelay(); +extern void CRT_enableDelay(); -void CRT_setColors(int colorScheme); +extern void CRT_setColors(int colorScheme); #endif diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 5f697078f..7fd7ddce5 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -154,7 +154,8 @@ typedef struct LinuxProcess_ { }*/ -long long btime; /* semi-global */ +/* semi-global */ +long long btime; ProcessFieldData Process_fields[] = { [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 6ce3037d2..586aa7171 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -144,7 +144,8 @@ typedef struct LinuxProcess_ { #endif -long long btime; /* semi-global */ +/* semi-global */ +extern long long btime; extern ProcessFieldData Process_fields[]; @@ -152,9 +153,9 @@ extern ProcessPidColumn Process_pidColumns[]; extern ProcessClass LinuxProcess_class; -LinuxProcess* LinuxProcess_new(Settings* settings); +extern LinuxProcess* LinuxProcess_new(Settings* settings); -void Process_delete(Object* cast); +extern void Process_delete(Object* cast); /* [1] Note that before kernel 2.6.26 a process that has not asked for @@ -166,19 +167,19 @@ extern io_priority; */ #define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->super.nice + 20) / 5) : p_->ioPriority) -IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this); +extern IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this); -bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio); +extern bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio); #ifdef HAVE_DELAYACCT -void LinuxProcess_printDelay(float delay_percent, char* buffer, int n); +extern void LinuxProcess_printDelay(float delay_percent, char* buffer, int n); #endif -void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field); +extern void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field); -long LinuxProcess_compare(const void* v1, const void* v2); +extern long LinuxProcess_compare(const void* v1, const void* v2); -bool Process_isThread(Process* this); +extern bool Process_isThread(Process* this); #endif diff --git a/scripts/MakeHeader.py b/scripts/MakeHeader.py index 349531b8e..3ef34b88c 100755 --- a/scripts/MakeHeader.py +++ b/scripts/MakeHeader.py @@ -54,8 +54,10 @@ elif line.startswith("typedef struct"): state = SKIP elif line[-1] == "{": - out.write( line[:-2].replace("inline", "extern") + ";\n" ) + out.write("extern " + line[:-2].replace("inline ", "") + ";\n") state = SKIP + elif line[-1] == ";": + out.write("extern " + line + "\n") else: out.write( line + "\n") is_blank = False From b3003f02fa235a128b497ba55024bd475ecf938c Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Mon, 17 Aug 2020 14:59:23 +1000 Subject: [PATCH 072/411] Create ci.yml Initial version of htop CI using github actions. --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..10ca129e8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: autogen + run: ./autogen.sh + - name: configure + run: ./configure + - name: make + run: make From c86ac5cf98427c1a917342aef13a84aa91768ae6 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Mon, 17 Aug 2020 15:16:49 +1000 Subject: [PATCH 073/411] Update ci.yml Install libncurses-dev package on the build system --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10ca129e8..acc195058 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: steps: - uses: actions/checkout@v2 + - name: prepare + run: sudo apt-get install libncurses-dev - name: autogen run: ./autogen.sh - name: configure From 6cd1615863730a64df3522855248b6332f789553 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Mon, 17 Aug 2020 15:40:47 +1000 Subject: [PATCH 074/411] Update ci.yml Attempt to fix Ubuntu dependencies, add macosx --- .github/workflows/ci.yml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index acc195058..69ad7aeca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,17 +7,23 @@ on: branches: [ master ] jobs: - build: - + build-ubuntu-latest: runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: make + run: | + sudo apt-get install libncurses-dev + ./autogen.sh + ./configure + make + build-macos-latest: + runs-on: macos-latest steps: - uses: actions/checkout@v2 - - name: prepare - run: sudo apt-get install libncurses-dev - - name: autogen - run: ./autogen.sh - - name: configure - run: ./configure - name: make - run: make + run: | + ./autogen.sh + ./configure + make From e1f48c7c7c93736d165c0e3267ef7819cdd41a22 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Mon, 17 Aug 2020 15:48:24 +1000 Subject: [PATCH 075/411] Update ci.yml Correction to deb package name --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69ad7aeca..21542cee1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v2 - name: make run: | - sudo apt-get install libncurses-dev + sudo apt-get install libncursesw5-dev ./autogen.sh ./configure make @@ -24,6 +24,5 @@ jobs: - uses: actions/checkout@v2 - name: make run: | - ./autogen.sh ./configure make From 7fbbf25afeb76baf1186181202d6d214d7a7936b Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Mon, 17 Aug 2020 15:53:49 +1000 Subject: [PATCH 076/411] Update ci.yml Comment out MacOSX for now - seems to be missing needed aclocal/m4 toolchain components. --- .github/workflows/ci.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21542cee1..74d0ece89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,18 +11,19 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: make + - name: Build run: | sudo apt-get install libncursesw5-dev ./autogen.sh ./configure make - build-macos-latest: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - name: make - run: | - ./configure - make +# build-macos-latest: +# runs-on: macos-latest +# steps: +# - uses: actions/checkout@v2 +# - name: make +# run: | +# ./autogen.sh +# ./configure +# make From 7ac1c709b727bd460889f2765db9e2a37535ef90 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 18 Aug 2020 17:41:49 +1000 Subject: [PATCH 077/411] Re-generate all headers with latest scripts/MakeHeader.py Sync-up missing extern declarations for many functions. --- Action.h | 10 ++++----- Affinity.h | 14 ++++++------ AffinityPanel.h | 4 ++-- AvailableColumnsPanel.h | 2 +- AvailableMetersPanel.h | 2 +- CategoriesPanel.h | 4 ++-- CheckItem.h | 8 +++---- ColorsPanel.h | 2 +- ColumnsPanel.h | 6 +++--- DisplayOptionsPanel.h | 2 +- EnvScreen.h | 8 +++---- FunctionBar.h | 14 ++++++------ Hashtable.h | 12 +++++------ Header.h | 26 +++++++++++------------ IncSet.h | 14 ++++++------ InfoScreen.h | 12 +++++------ ListItem.h | 8 +++---- MainPanel.h | 16 +++++++------- Meter.h | 12 +++++------ MetersPanel.h | 4 ++-- Object.h | 2 +- OpenFilesScreen.h | 8 +++---- Panel.h | 46 ++++++++++++++++++++-------------------- Process.h | 30 +++++++++++++------------- ProcessList.h | 28 ++++++++++++------------ RichString.h | 16 +++++++------- ScreenManager.h | 12 +++++------ Settings.h | 8 +++---- SignalsPanel.h | 2 +- StringUtils.h | 12 +++++------ TraceScreen.h | 12 +++++------ UsersTable.h | 6 +++--- Vector.h | 26 +++++++++++------------ XAlloc.h | 10 ++++----- htop.h | 2 +- linux/Battery.h | 2 +- linux/IOPriorityPanel.h | 4 ++-- linux/LinuxCRT.h | 2 +- linux/LinuxProcessList.h | 6 +++--- linux/Platform.h | 16 +++++++------- 40 files changed, 215 insertions(+), 215 deletions(-) diff --git a/Action.h b/Action.h index 1dfdcb476..a2920b686 100644 --- a/Action.h +++ b/Action.h @@ -39,20 +39,20 @@ typedef struct State_ { } State; -Object* Action_pickFromVector(State* st, Panel* list, int x); +extern Object* Action_pickFromVector(State* st, Panel* list, int x); // ---------------------------------------- -bool Action_setUserOnly(const char* userName, uid_t* userId); +extern bool Action_setUserOnly(const char* userName, uid_t* userId); -Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey); +extern Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey); // ---------------------------------------- -Htop_Reaction Action_follow(State* st); +extern Htop_Reaction Action_follow(State* st); -void Action_setBindings(Htop_Action* keys); +extern void Action_setBindings(Htop_Action* keys); #endif diff --git a/Affinity.h b/Affinity.h index fd2c599ee..818b905ef 100644 --- a/Affinity.h +++ b/Affinity.h @@ -29,23 +29,23 @@ typedef struct Affinity_ { } Affinity; -Affinity* Affinity_new(ProcessList* pl); +extern Affinity* Affinity_new(ProcessList* pl); -void Affinity_delete(Affinity* this); +extern void Affinity_delete(Affinity* this); -void Affinity_add(Affinity* this, int id); +extern void Affinity_add(Affinity* this, int id); #ifdef HAVE_LIBHWLOC -Affinity* Affinity_get(Process* proc, ProcessList* pl); +extern Affinity* Affinity_get(Process* proc, ProcessList* pl); -bool Affinity_set(Process* proc, Affinity* this); +extern bool Affinity_set(Process* proc, Affinity* this); #elif HAVE_LINUX_AFFINITY -Affinity* Affinity_get(Process* proc, ProcessList* pl); +extern Affinity* Affinity_get(Process* proc, ProcessList* pl); -bool Affinity_set(Process* proc, Affinity* this); +extern bool Affinity_set(Process* proc, Affinity* this); #endif diff --git a/AffinityPanel.h b/AffinityPanel.h index 2b6059b08..3a9c78078 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -16,8 +16,8 @@ in the source distribution for its full text. extern PanelClass AffinityPanel_class; -Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity); +extern Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity); -Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl); +extern Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl); #endif diff --git a/AvailableColumnsPanel.h b/AvailableColumnsPanel.h index 5a8371ddb..2d6daf4ba 100644 --- a/AvailableColumnsPanel.h +++ b/AvailableColumnsPanel.h @@ -19,6 +19,6 @@ typedef struct AvailableColumnsPanel_ { extern PanelClass AvailableColumnsPanel_class; -AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns); +extern AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns); #endif diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index e9b949b0c..00e0f5962 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -27,6 +27,6 @@ typedef struct AvailableMetersPanel_ { extern PanelClass AvailableMetersPanel_class; -AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl); +extern AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl); #endif diff --git a/CategoriesPanel.h b/CategoriesPanel.h index ccef0fae8..44c6842a0 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -24,10 +24,10 @@ typedef struct CategoriesPanel_ { } CategoriesPanel; -void CategoriesPanel_makeMetersPage(CategoriesPanel* this); +extern void CategoriesPanel_makeMetersPage(CategoriesPanel* this); extern PanelClass CategoriesPanel_class; -CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl); +extern CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl); #endif diff --git a/CheckItem.h b/CheckItem.h index 5847d4b2e..dbd1a039e 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -21,12 +21,12 @@ typedef struct CheckItem_ { extern ObjectClass CheckItem_class; -CheckItem* CheckItem_newByRef(char* text, bool* ref); +extern CheckItem* CheckItem_newByRef(char* text, bool* ref); -CheckItem* CheckItem_newByVal(char* text, bool value); +extern CheckItem* CheckItem_newByVal(char* text, bool value); -void CheckItem_set(CheckItem* this, bool value); +extern void CheckItem_set(CheckItem* this, bool value); -bool CheckItem_get(CheckItem* this); +extern bool CheckItem_get(CheckItem* this); #endif diff --git a/ColorsPanel.h b/ColorsPanel.h index ee3111e07..82b782b82 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -29,6 +29,6 @@ typedef struct ColorsPanel_ { extern PanelClass ColorsPanel_class; -ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); +extern ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); #endif diff --git a/ColumnsPanel.h b/ColumnsPanel.h index 0da674a87..46d20bbb2 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -22,11 +22,11 @@ typedef struct ColumnsPanel_ { extern PanelClass ColumnsPanel_class; -ColumnsPanel* ColumnsPanel_new(Settings* settings); +extern ColumnsPanel* ColumnsPanel_new(Settings* settings); -int ColumnsPanel_fieldNameToIndex(const char* name); +extern int ColumnsPanel_fieldNameToIndex(const char* name); -void ColumnsPanel_update(Panel* super); +extern void ColumnsPanel_update(Panel* super); #endif diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index 2a7509ae8..d9de40054 100644 --- a/DisplayOptionsPanel.h +++ b/DisplayOptionsPanel.h @@ -23,6 +23,6 @@ typedef struct DisplayOptionsPanel_ { extern PanelClass DisplayOptionsPanel_class; -DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr); +extern DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr); #endif diff --git a/EnvScreen.h b/EnvScreen.h index 7cdbb8652..025cb8d3b 100644 --- a/EnvScreen.h +++ b/EnvScreen.h @@ -11,12 +11,12 @@ typedef struct EnvScreen_ { extern InfoScreenClass EnvScreen_class; -EnvScreen* EnvScreen_new(Process* process); +extern EnvScreen* EnvScreen_new(Process* process); -void EnvScreen_delete(Object* this); +extern void EnvScreen_delete(Object* this); -void EnvScreen_draw(InfoScreen* this); +extern void EnvScreen_draw(InfoScreen* this); -void EnvScreen_scan(InfoScreen* this); +extern void EnvScreen_scan(InfoScreen* this); #endif diff --git a/FunctionBar.h b/FunctionBar.h index b60f6582a..ee5b9347c 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -22,18 +22,18 @@ typedef struct FunctionBar_ { -FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc); +extern FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc); -FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events); +extern FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events); -void FunctionBar_delete(FunctionBar* this); +extern void FunctionBar_delete(FunctionBar* this); -void FunctionBar_setLabel(FunctionBar* this, int event, const char* text); +extern void FunctionBar_setLabel(FunctionBar* this, int event, const char* text); -void FunctionBar_draw(const FunctionBar* this, char* buffer); +extern void FunctionBar_draw(const FunctionBar* this, char* buffer); -void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr); +extern void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr); -int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos); +extern int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos); #endif diff --git a/Hashtable.h b/Hashtable.h index 25608961c..32b02188b 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -30,20 +30,20 @@ struct Hashtable_ { #ifdef DEBUG -int Hashtable_count(Hashtable* this); +extern int Hashtable_count(Hashtable* this); #endif -Hashtable* Hashtable_new(int size, bool owner); +extern Hashtable* Hashtable_new(int size, bool owner); -void Hashtable_delete(Hashtable* this); +extern void Hashtable_delete(Hashtable* this); -void Hashtable_put(Hashtable* this, unsigned int key, void* value); +extern void Hashtable_put(Hashtable* this, unsigned int key, void* value); -void* Hashtable_remove(Hashtable* this, unsigned int key); +extern void* Hashtable_remove(Hashtable* this, unsigned int key); extern void* Hashtable_get(Hashtable* this, unsigned int key); -void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData); +extern void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData); #endif diff --git a/Header.h b/Header.h index 700ad354b..f51824540 100644 --- a/Header.h +++ b/Header.h @@ -31,30 +31,30 @@ typedef struct Header_ { #define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_)) #endif -Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns); +extern Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns); -void Header_delete(Header* this); +extern void Header_delete(Header* this); -void Header_populateFromSettings(Header* this); +extern void Header_populateFromSettings(Header* this); -void Header_writeBackToSettings(const Header* this); +extern void Header_writeBackToSettings(const Header* this); -MeterModeId Header_addMeterByName(Header* this, char* name, int column); +extern MeterModeId Header_addMeterByName(Header* this, char* name, int column); -void Header_setMode(Header* this, int i, MeterModeId mode, int column); +extern void Header_setMode(Header* this, int i, MeterModeId mode, int column); -Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column); +extern Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column); -int Header_size(Header* this, int column); +extern int Header_size(Header* this, int column); -char* Header_readMeterName(Header* this, int i, int column); +extern char* Header_readMeterName(Header* this, int i, int column); -MeterModeId Header_readMeterMode(Header* this, int i, int column); +extern MeterModeId Header_readMeterMode(Header* this, int i, int column); -void Header_reinit(Header* this); +extern void Header_reinit(Header* this); -void Header_draw(const Header* this); +extern void Header_draw(const Header* this); -int Header_calculateHeight(Header* this); +extern int Header_calculateHeight(Header* this); #endif diff --git a/IncSet.h b/IncSet.h index 27538f4b8..d873bb816 100644 --- a/IncSet.h +++ b/IncSet.h @@ -41,18 +41,18 @@ typedef struct IncSet_ { typedef const char* (*IncMode_GetPanelValue)(Panel*, int); -IncSet* IncSet_new(FunctionBar* bar); +extern IncSet* IncSet_new(FunctionBar* bar); -void IncSet_delete(IncSet* this); +extern void IncSet_delete(IncSet* this); -bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines); +extern bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines); -const char* IncSet_getListItemValue(Panel* panel, int i); +extern const char* IncSet_getListItemValue(Panel* panel, int i); -void IncSet_activate(IncSet* this, IncType type, Panel* panel); +extern void IncSet_activate(IncSet* this, IncType type, Panel* panel); -void IncSet_drawBar(IncSet* this); +extern void IncSet_drawBar(IncSet* this); -int IncSet_synthesizeEvent(IncSet* this, int x); +extern int IncSet_synthesizeEvent(IncSet* this, int x); #endif diff --git a/InfoScreen.h b/InfoScreen.h index 2e1599f90..b9387cda3 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -38,16 +38,16 @@ struct InfoScreen_ { Vector* lines; }; -InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader); +extern InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader); -InfoScreen* InfoScreen_done(InfoScreen* this); +extern InfoScreen* InfoScreen_done(InfoScreen* this); -void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...); +extern void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...); -void InfoScreen_addLine(InfoScreen* this, const char* line); +extern void InfoScreen_addLine(InfoScreen* this, const char* line); -void InfoScreen_appendLine(InfoScreen* this, const char* line); +extern void InfoScreen_appendLine(InfoScreen* this, const char* line); -void InfoScreen_run(InfoScreen* this); +extern void InfoScreen_run(InfoScreen* this); #endif diff --git a/ListItem.h b/ListItem.h index b48f0acd3..7fed92379 100644 --- a/ListItem.h +++ b/ListItem.h @@ -21,13 +21,13 @@ typedef struct ListItem_ { extern ObjectClass ListItem_class; -ListItem* ListItem_new(const char* value, int key); +extern ListItem* ListItem_new(const char* value, int key); -void ListItem_append(ListItem* this, const char* text); +extern void ListItem_append(ListItem* this, const char* text); -const char* ListItem_getRef(ListItem* this); +extern const char* ListItem_getRef(ListItem* this); -long ListItem_compare(const void* cast1, const void* cast2); +extern long ListItem_compare(const void* cast1, const void* cast2); #endif diff --git a/MainPanel.h b/MainPanel.h index 884965977..8d7533069 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -31,22 +31,22 @@ typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg); #define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar) -void MainPanel_updateTreeFunctions(MainPanel* this, bool mode); +extern void MainPanel_updateTreeFunctions(MainPanel* this, bool mode); -void MainPanel_pidSearch(MainPanel* this, int ch); +extern void MainPanel_pidSearch(MainPanel* this, int ch); -int MainPanel_selectedPid(MainPanel* this); +extern int MainPanel_selectedPid(MainPanel* this); -const char* MainPanel_getValue(MainPanel* this, int i); +extern const char* MainPanel_getValue(MainPanel* this, int i); -bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged); +extern bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged); extern PanelClass MainPanel_class; -MainPanel* MainPanel_new(); +extern MainPanel* MainPanel_new(); -void MainPanel_setState(MainPanel* this, State* state); +extern void MainPanel_setState(MainPanel* this, State* state); -void MainPanel_delete(Object* object); +extern void MainPanel_delete(Object* object); #endif diff --git a/Meter.h b/Meter.h index d98c910ed..36e0e815d 100644 --- a/Meter.h +++ b/Meter.h @@ -109,17 +109,17 @@ typedef struct GraphData_ { extern MeterClass Meter_class; -Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type); +extern Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type); -int Meter_humanUnit(char* buffer, unsigned long int value, int size); +extern int Meter_humanUnit(char* buffer, unsigned long int value, int size); -void Meter_delete(Object* cast); +extern void Meter_delete(Object* cast); -void Meter_setCaption(Meter* this, const char* caption); +extern void Meter_setCaption(Meter* this, const char* caption); -void Meter_setMode(Meter* this, int modeIndex); +extern void Meter_setMode(Meter* this, int modeIndex); -ListItem* Meter_toListItem(Meter* this, bool moving); +extern ListItem* Meter_toListItem(Meter* this, bool moving); /* ---------- TextMeterMode ---------- */ diff --git a/MetersPanel.h b/MetersPanel.h index e00169c8c..12eabbe60 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -34,10 +34,10 @@ struct MetersPanel_ { // In , arrows (U+2019..U+2199) are // considered "Ambiguous characters". -void MetersPanel_setMoving(MetersPanel* this, bool moving); +extern void MetersPanel_setMoving(MetersPanel* this, bool moving); extern PanelClass MetersPanel_class; -MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr); +extern MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr); #endif diff --git a/Object.h b/Object.h index 19a667c8a..bcf2c4813 100644 --- a/Object.h +++ b/Object.h @@ -46,7 +46,7 @@ extern ObjectClass Object_class; #ifdef DEBUG -bool Object_isA(Object* o, const ObjectClass* klass); +extern bool Object_isA(Object* o, const ObjectClass* klass); #endif diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index 8160cfe21..39c71d5b4 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -34,12 +34,12 @@ typedef struct OpenFilesScreen_ { extern InfoScreenClass OpenFilesScreen_class; -OpenFilesScreen* OpenFilesScreen_new(Process* process); +extern OpenFilesScreen* OpenFilesScreen_new(Process* process); -void OpenFilesScreen_delete(Object* this); +extern void OpenFilesScreen_delete(Object* this); -void OpenFilesScreen_draw(InfoScreen* this); +extern void OpenFilesScreen_draw(InfoScreen* this); -void OpenFilesScreen_scan(InfoScreen* this); +extern void OpenFilesScreen_scan(InfoScreen* this); #endif diff --git a/Panel.h b/Panel.h index 5253fc2e7..b7480c6ba 100644 --- a/Panel.h +++ b/Panel.h @@ -75,52 +75,52 @@ struct Panel_ { extern PanelClass Panel_class; -Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar); +extern Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar); -void Panel_delete(Object* cast); +extern void Panel_delete(Object* cast); -void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar); +extern void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar); -void Panel_done(Panel* this); +extern void Panel_done(Panel* this); -void Panel_setSelectionColor(Panel* this, int color); +extern void Panel_setSelectionColor(Panel* this, int color); -RichString* Panel_getHeader(Panel* this); +extern RichString* Panel_getHeader(Panel* this); extern void Panel_setHeader(Panel* this, const char* header); -void Panel_move(Panel* this, int x, int y); +extern void Panel_move(Panel* this, int x, int y); -void Panel_resize(Panel* this, int w, int h); +extern void Panel_resize(Panel* this, int w, int h); -void Panel_prune(Panel* this); +extern void Panel_prune(Panel* this); -void Panel_add(Panel* this, Object* o); +extern void Panel_add(Panel* this, Object* o); -void Panel_insert(Panel* this, int i, Object* o); +extern void Panel_insert(Panel* this, int i, Object* o); -void Panel_set(Panel* this, int i, Object* o); +extern void Panel_set(Panel* this, int i, Object* o); -Object* Panel_get(Panel* this, int i); +extern Object* Panel_get(Panel* this, int i); -Object* Panel_remove(Panel* this, int i); +extern Object* Panel_remove(Panel* this, int i); -Object* Panel_getSelected(Panel* this); +extern Object* Panel_getSelected(Panel* this); -void Panel_moveSelectedUp(Panel* this); +extern void Panel_moveSelectedUp(Panel* this); -void Panel_moveSelectedDown(Panel* this); +extern void Panel_moveSelectedDown(Panel* this); -int Panel_getSelectedIndex(Panel* this); +extern int Panel_getSelectedIndex(Panel* this); -int Panel_size(Panel* this); +extern int Panel_size(Panel* this); -void Panel_setSelected(Panel* this, int selected); +extern void Panel_setSelected(Panel* this, int selected); -void Panel_draw(Panel* this, bool focus); +extern void Panel_draw(Panel* this, bool focus); -bool Panel_onKey(Panel* this, int key); +extern bool Panel_onKey(Panel* this, int key); -HandlerResult Panel_selectByTyping(Panel* this, int ch); +extern HandlerResult Panel_selectByTyping(Panel* this, int ch); #endif diff --git a/Process.h b/Process.h index f702ca006..7ecd81c5d 100644 --- a/Process.h +++ b/Process.h @@ -173,36 +173,36 @@ typedef struct ProcessClass_ { extern char Process_pidFormat[20]; -void Process_setupColumnWidths(); +extern void Process_setupColumnWidths(); -void Process_humanNumber(RichString* str, unsigned long number, bool coloring); +extern void Process_humanNumber(RichString* str, unsigned long number, bool coloring); -void Process_colorNumber(RichString* str, unsigned long long number, bool coloring); +extern void Process_colorNumber(RichString* str, unsigned long long number, bool coloring); -void Process_printTime(RichString* str, unsigned long long totalHundredths); +extern void Process_printTime(RichString* str, unsigned long long totalHundredths); -void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring); +extern void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring); -void Process_writeField(Process* this, RichString* str, ProcessField field); +extern void Process_writeField(Process* this, RichString* str, ProcessField field); -void Process_display(Object* cast, RichString* out); +extern void Process_display(Object* cast, RichString* out); -void Process_done(Process* this); +extern void Process_done(Process* this); extern ProcessClass Process_class; -void Process_init(Process* this, struct Settings_* settings); +extern void Process_init(Process* this, struct Settings_* settings); -void Process_toggleTag(Process* this); +extern void Process_toggleTag(Process* this); -bool Process_setPriority(Process* this, int priority); +extern bool Process_setPriority(Process* this, int priority); -bool Process_changePriorityBy(Process* this, int delta); +extern bool Process_changePriorityBy(Process* this, int delta); -void Process_sendSignal(Process* this, int sgn); +extern void Process_sendSignal(Process* this, int sgn); -long Process_pidCompare(const void* v1, const void* v2); +extern long Process_pidCompare(const void* v1, const void* v2); -long Process_compare(const void* v1, const void* v2); +extern long Process_compare(const void* v1, const void* v2); #endif diff --git a/ProcessList.h b/ProcessList.h index 572d48431..ddc6f3fa8 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -71,32 +71,32 @@ void ProcessList_delete(ProcessList* pl); void ProcessList_goThroughEntries(ProcessList* pl); -ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +extern ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); -void ProcessList_done(ProcessList* this); +extern void ProcessList_done(ProcessList* this); -void ProcessList_setPanel(ProcessList* this, Panel* panel); +extern void ProcessList_setPanel(ProcessList* this, Panel* panel); -void ProcessList_printHeader(ProcessList* this, RichString* header); +extern void ProcessList_printHeader(ProcessList* this, RichString* header); -void ProcessList_add(ProcessList* this, Process* p); +extern void ProcessList_add(ProcessList* this, Process* p); -void ProcessList_remove(ProcessList* this, Process* p); +extern void ProcessList_remove(ProcessList* this, Process* p); -Process* ProcessList_get(ProcessList* this, int idx); +extern Process* ProcessList_get(ProcessList* this, int idx); -int ProcessList_size(ProcessList* this); +extern int ProcessList_size(ProcessList* this); -void ProcessList_sort(ProcessList* this); +extern void ProcessList_sort(ProcessList* this); -ProcessField ProcessList_keyAt(ProcessList* this, int at); +extern ProcessField ProcessList_keyAt(ProcessList* this, int at); -void ProcessList_expandTree(ProcessList* this); +extern void ProcessList_expandTree(ProcessList* this); -void ProcessList_rebuildPanel(ProcessList* this); +extern void ProcessList_rebuildPanel(ProcessList* this); -Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor); +extern Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor); -void ProcessList_scan(ProcessList* this); +extern void ProcessList_scan(ProcessList* this); #endif diff --git a/RichString.h b/RichString.h index f5b5cba10..a294a5507 100644 --- a/RichString.h +++ b/RichString.h @@ -71,24 +71,24 @@ typedef struct RichString_ { extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish); -int RichString_findChar(RichString* this, char c, int start); +extern int RichString_findChar(RichString* this, char c, int start); #else -void RichString_setAttrn(RichString* this, int attrs, int start, int finish); +extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish); -int RichString_findChar(RichString* this, char c, int start); +extern int RichString_findChar(RichString* this, char c, int start); #endif -void RichString_prune(RichString* this); +extern void RichString_prune(RichString* this); -void RichString_setAttr(RichString* this, int attrs); +extern void RichString_setAttr(RichString* this, int attrs); -void RichString_append(RichString* this, int attrs, const char* data); +extern void RichString_append(RichString* this, int attrs, const char* data); -void RichString_appendn(RichString* this, int attrs, const char* data, int len); +extern void RichString_appendn(RichString* this, int attrs, const char* data, int len); -void RichString_write(RichString* this, int attrs, const char* data); +extern void RichString_write(RichString* this, int attrs, const char* data); #endif diff --git a/ScreenManager.h b/ScreenManager.h index 3d02a8835..b7b5617b1 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -35,18 +35,18 @@ typedef struct ScreenManager_ { } ScreenManager; -ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner); +extern ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner); -void ScreenManager_delete(ScreenManager* this); +extern void ScreenManager_delete(ScreenManager* this); extern int ScreenManager_size(ScreenManager* this); -void ScreenManager_add(ScreenManager* this, Panel* item, int size); +extern void ScreenManager_add(ScreenManager* this, Panel* item, int size); -Panel* ScreenManager_remove(ScreenManager* this, int idx); +extern Panel* ScreenManager_remove(ScreenManager* this, int idx); -void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2); +extern void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2); -void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey); +extern void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey); #endif diff --git a/Settings.h b/Settings.h index d9dc0683c..4f8722b3a 100644 --- a/Settings.h +++ b/Settings.h @@ -58,12 +58,12 @@ typedef struct Settings_ { #endif -void Settings_delete(Settings* this); +extern void Settings_delete(Settings* this); -bool Settings_write(Settings* this); +extern bool Settings_write(Settings* this); -Settings* Settings_new(int cpuCount); +extern Settings* Settings_new(int cpuCount); -void Settings_invertSortOrder(Settings* this); +extern void Settings_invertSortOrder(Settings* this); #endif diff --git a/SignalsPanel.h b/SignalsPanel.h index da753546d..8720376a7 100644 --- a/SignalsPanel.h +++ b/SignalsPanel.h @@ -16,6 +16,6 @@ typedef struct SignalItem_ { } SignalItem; -Panel* SignalsPanel_new(); +extern Panel* SignalsPanel_new(); #endif diff --git a/StringUtils.h b/StringUtils.h index d3378b38e..c1070d4fe 100644 --- a/StringUtils.h +++ b/StringUtils.h @@ -19,18 +19,18 @@ in the source distribution for its full text. * at compile time (e.g. when they are immutable string literals). :) */ -char* String_cat(const char* s1, const char* s2); +extern char* String_cat(const char* s1, const char* s2); -char* String_trim(const char* in); +extern char* String_trim(const char* in); extern int String_eq(const char* s1, const char* s2); -char** String_split(const char* s, char sep, int* n); +extern char** String_split(const char* s, char sep, int* n); -void String_freeArray(char** s); +extern void String_freeArray(char** s); -char* String_getToken(const char* line, const unsigned short int numMatch); +extern char* String_getToken(const char* line, const unsigned short int numMatch); -char* String_readLine(FILE* fd); +extern char* String_readLine(FILE* fd); #endif diff --git a/TraceScreen.h b/TraceScreen.h index 8845c51aa..d43281d91 100644 --- a/TraceScreen.h +++ b/TraceScreen.h @@ -25,16 +25,16 @@ typedef struct TraceScreen_ { extern InfoScreenClass TraceScreen_class; -TraceScreen* TraceScreen_new(Process* process); +extern TraceScreen* TraceScreen_new(Process* process); -void TraceScreen_delete(Object* cast); +extern void TraceScreen_delete(Object* cast); -void TraceScreen_draw(InfoScreen* this); +extern void TraceScreen_draw(InfoScreen* this); -bool TraceScreen_forkTracer(TraceScreen* this); +extern bool TraceScreen_forkTracer(TraceScreen* this); -void TraceScreen_updateTrace(InfoScreen* super); +extern void TraceScreen_updateTrace(InfoScreen* super); -bool TraceScreen_onKey(InfoScreen* super, int ch); +extern bool TraceScreen_onKey(InfoScreen* super, int ch); #endif diff --git a/UsersTable.h b/UsersTable.h index 93ece0dcd..9eba59ad0 100644 --- a/UsersTable.h +++ b/UsersTable.h @@ -15,11 +15,11 @@ typedef struct UsersTable_ { Hashtable* users; } UsersTable; -UsersTable* UsersTable_new(); +extern UsersTable* UsersTable_new(); -void UsersTable_delete(UsersTable* this); +extern void UsersTable_delete(UsersTable* this); -char* UsersTable_getRef(UsersTable* this, unsigned int uid); +extern char* UsersTable_getRef(UsersTable* this, unsigned int uid); extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData); diff --git a/Vector.h b/Vector.h index 85939bf18..b48c83636 100644 --- a/Vector.h +++ b/Vector.h @@ -27,38 +27,38 @@ typedef struct Vector_ { } Vector; -Vector* Vector_new(ObjectClass* type, bool owner, int size); +extern Vector* Vector_new(ObjectClass* type, bool owner, int size); -void Vector_delete(Vector* this); +extern void Vector_delete(Vector* this); #ifdef DEBUG -int Vector_count(Vector* this); +extern int Vector_count(Vector* this); #endif -void Vector_prune(Vector* this); +extern void Vector_prune(Vector* this); // If I were to use only one sorting algorithm for both cases, it would probably be this one: /* */ -void Vector_quickSort(Vector* this); +extern void Vector_quickSort(Vector* this); -void Vector_insertionSort(Vector* this); +extern void Vector_insertionSort(Vector* this); -void Vector_insert(Vector* this, int idx, void* data_); +extern void Vector_insert(Vector* this, int idx, void* data_); -Object* Vector_take(Vector* this, int idx); +extern Object* Vector_take(Vector* this, int idx); -Object* Vector_remove(Vector* this, int idx); +extern Object* Vector_remove(Vector* this, int idx); -void Vector_moveUp(Vector* this, int idx); +extern void Vector_moveUp(Vector* this, int idx); -void Vector_moveDown(Vector* this, int idx); +extern void Vector_moveDown(Vector* this, int idx); -void Vector_set(Vector* this, int idx, void* data_); +extern void Vector_set(Vector* this, int idx, void* data_); #ifdef DEBUG @@ -84,7 +84,7 @@ extern int Vector_size(Vector* this); */ -void Vector_add(Vector* this, void* data_); +extern void Vector_add(Vector* this, void* data_); extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare); diff --git a/XAlloc.h b/XAlloc.h index 2ebee1a8d..97a1c0d08 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -11,11 +11,11 @@ #include #include -void* xMalloc(size_t size); +extern void* xMalloc(size_t size); -void* xCalloc(size_t nmemb, size_t size); +extern void* xCalloc(size_t nmemb, size_t size); -void* xRealloc(void* ptr, size_t size); +extern void* xRealloc(void* ptr, size_t size); #define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0) @@ -32,9 +32,9 @@ void* xRealloc(void* ptr, size_t size); #endif #if (__has_attribute(nonnull) || \ ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) -char* xStrdup_(const char* str) __attribute__((nonnull)); +extern char* xStrdup_(const char* str) __attribute__((nonnull)); #endif // __has_attribute(nonnull) || GNU C 3.3 or later -char* xStrdup_(const char* str); +extern char* xStrdup_(const char* str); #endif diff --git a/htop.h b/htop.h index 7faa6c64d..26c191806 100644 --- a/htop.h +++ b/htop.h @@ -14,6 +14,6 @@ in the source distribution for its full text. // ---------------------------------------- -int main(int argc, char** argv); +extern int main(int argc, char** argv); #endif diff --git a/linux/Battery.h b/linux/Battery.h index cfb6c3242..261cff056 100644 --- a/linux/Battery.h +++ b/linux/Battery.h @@ -29,6 +29,6 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat // READ FROM /sys // ---------------------------------------- -void Battery_getData(double* level, ACPresence* isOnAC); +extern void Battery_getData(double* level, ACPresence* isOnAC); #endif diff --git a/linux/IOPriorityPanel.h b/linux/IOPriorityPanel.h index 9f77a4d9c..0bf74f50e 100644 --- a/linux/IOPriorityPanel.h +++ b/linux/IOPriorityPanel.h @@ -13,9 +13,9 @@ in the source distribution for its full text. #include "IOPriority.h" #include "ListItem.h" -Panel* IOPriorityPanel_new(IOPriority currPrio); +extern Panel* IOPriorityPanel_new(IOPriority currPrio); -IOPriority IOPriorityPanel_getIOPriority(Panel* this); +extern IOPriority IOPriorityPanel_getIOPriority(Panel* this); #endif diff --git a/linux/LinuxCRT.h b/linux/LinuxCRT.h index f8c43e4d3..966dfecf4 100644 --- a/linux/LinuxCRT.h +++ b/linux/LinuxCRT.h @@ -12,6 +12,6 @@ in the source distribution for its full text. #ifdef HAVE_EXECINFO_H #endif -void CRT_handleSIGSEGV(int sgn); +extern void CRT_handleSIGSEGV(int sgn); #endif diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index f30b487d6..cf369e381 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -98,9 +98,9 @@ typedef struct LinuxProcessList_ { #endif -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +extern ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); -void ProcessList_delete(ProcessList* pl); +extern void ProcessList_delete(ProcessList* pl); #ifdef HAVE_TASKSTATS @@ -123,6 +123,6 @@ void ProcessList_delete(ProcessList* pl); #endif -void ProcessList_goThroughEntries(ProcessList* super); +extern void ProcessList_goThroughEntries(ProcessList* super); #endif diff --git a/linux/Platform.h b/linux/Platform.h index b0456e5b5..89b0a3015 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -27,22 +27,22 @@ extern const SignalItem Platform_signals[]; extern const unsigned int Platform_numberOfSignals; -void Platform_setBindings(Htop_Action* keys); +extern void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; -int Platform_getUptime(); +extern int Platform_getUptime(); -void Platform_getLoadAverage(double* one, double* five, double* fifteen); +extern void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(); +extern int Platform_getMaxPid(); -double Platform_setCPUValues(Meter* this, int cpu); +extern double Platform_setCPUValues(Meter* this, int cpu); -void Platform_setMemoryValues(Meter* this); +extern void Platform_setMemoryValues(Meter* this); -void Platform_setSwapValues(Meter* this); +extern void Platform_setSwapValues(Meter* this); -char* Platform_getProcessEnv(pid_t pid); +extern char* Platform_getProcessEnv(pid_t pid); #endif From 9a70e431296a0f96adda3501dfded8899ac16e82 Mon Sep 17 00:00:00 2001 From: Jonischkeit Clemens Date: Tue, 18 Aug 2020 11:46:10 +0200 Subject: [PATCH 078/411] fixed display of blank bars The buffer for blank bars was left uninitialized resulting in random looking characters sometimes even overwriting the end of the bar. --- Meter.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Meter.c b/Meter.c index 05a4eb239..d1c33c3b0 100644 --- a/Meter.c +++ b/Meter.c @@ -523,6 +523,9 @@ MeterMode* Meter_modes[] = { static void BlankMeter_updateValues(Meter* this, char* buffer, int size) { (void) this; (void) buffer; (void) size; + if (size > 0) { + *buffer = 0; + } } static void BlankMeter_display(Object* cast, RichString* out) { From eef6bc447d3c0ecaac8bd0b0e3d291d9688ff35e Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Wed, 19 Aug 2020 17:50:43 +1000 Subject: [PATCH 079/411] Correction to smaps buffer size passed to smaps path snprintf --- linux/LinuxProcessList.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index c1ccd4202..0f756b358 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -505,9 +505,9 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di ssize_t nread=0; int tmp=0; if(haveSmapsRollup) {// only available in Linux 4.14+ - snprintf(buffer, MAX_NAME, "%s/%s/smaps_rollup", dirname, name); + snprintf(buffer, PAGE_SIZE-1, "%s/%s/smaps_rollup", dirname, name); } else { - snprintf(buffer, MAX_NAME, "%s/%s/smaps", dirname, name); + snprintf(buffer, PAGE_SIZE-1, "%s/%s/smaps", dirname, name); } int fd = open(buffer, O_RDONLY); if (fd == -1) From 36ef4d4fb65413d998c6a6fb83b0ebc86c52b1a1 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Wed, 19 Aug 2020 18:10:16 +1000 Subject: [PATCH 080/411] Resolve compilation warning relating to dangling else in InfoScreen_run --- InfoScreen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/InfoScreen.c b/InfoScreen.c index 1823f3667..8ff33d0ba 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -131,12 +131,13 @@ void InfoScreen_run(InfoScreen* this) { if (ch == KEY_MOUSE) { MEVENT mevent; int ok = getmouse(&mevent); - if (ok == OK) + if (ok == OK) { if (mevent.y >= panel->y && mevent.y < LINES - 1) { Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV); ch = 0; } else if (mevent.y == LINES - 1) ch = IncSet_synthesizeEvent(this->inc, mevent.x); + } } if (this->inc->active) { From 5228f5d47a10d9194297a31bf4cf7dbbade6c868 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 20 Aug 2020 09:03:45 +1000 Subject: [PATCH 081/411] Ensure result buffer termination in String_cat utility routine --- StringUtils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/StringUtils.c b/StringUtils.c index 0578cdea4..84b69b648 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -30,8 +30,9 @@ char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); char* out = xMalloc(l1 + l2 + 1); - strncpy(out, s1, l1); - strncpy(out+l1, s2, l2+1); + memcpy(out, s1, l1); + memcpy(out+l1, s2, l2+1); + out[l1 + l2] = '\0'; return out; } From 500fb283e9b86a6580cedbf834aea9d7dd639a66 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 20 Aug 2020 09:35:24 +1000 Subject: [PATCH 082/411] Resolve compiler warnings and errors relating to the Arg union Promote the Arg union to a core data type in Object.c such that it is visible everywhere (many source files need it), and correct declarations of several functions that use it. The Process_sendSignal function is also corrected to have the expected return type (bool, not void) - an error being masked by ignoring this not-quite-harmless warning. I've also added error checking to the kill(2) call here, which was previously overlooked / missing (?). --- Affinity.c | 7 +++++-- Affinity.h | 5 +++-- MainPanel.c | 6 +----- MainPanel.h | 6 +----- Object.c | 6 ++++++ Object.h | 6 ++++++ Process.c | 10 ++++++---- Process.h | 5 +++-- linux/LinuxProcess.c | 7 ++++--- linux/LinuxProcess.h | 3 ++- 10 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Affinity.c b/Affinity.c index c928fec16..b6eafceed 100644 --- a/Affinity.c +++ b/Affinity.c @@ -1,6 +1,7 @@ /* htop - Affinity.c (C) 2004-2011 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -79,7 +80,8 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { return affinity; } -bool Affinity_set(Process* proc, Affinity* this) { +bool Affinity_set(Process* proc, Arg arg) { + Affinity *this = arg.v; hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); for (int i = 0; i < this->used; i++) { hwloc_bitmap_set(cpuset, this->cpus[i]); @@ -103,7 +105,8 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { return affinity; } -bool Affinity_set(Process* proc, Affinity* this) { +bool Affinity_set(Process* proc, Arg arg) { + Affinity *this = arg.v; cpu_set_t cpuset; CPU_ZERO(&cpuset); for (int i = 0; i < this->used; i++) { diff --git a/Affinity.h b/Affinity.h index 818b905ef..3c716034c 100644 --- a/Affinity.h +++ b/Affinity.h @@ -5,6 +5,7 @@ /* htop - Affinity.h (C) 2004-2011 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -39,13 +40,13 @@ extern void Affinity_add(Affinity* this, int id); extern Affinity* Affinity_get(Process* proc, ProcessList* pl); -extern bool Affinity_set(Process* proc, Affinity* this); +extern bool Affinity_set(Process* proc, Arg arg); #elif HAVE_LINUX_AFFINITY extern Affinity* Affinity_get(Process* proc, ProcessList* pl); -extern bool Affinity_set(Process* proc, Affinity* this); +extern bool Affinity_set(Process* proc, Arg arg); #endif diff --git a/MainPanel.c b/MainPanel.c index 25023367f..19b09ff11 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -1,6 +1,7 @@ /* htop - ColumnsPanel.c (C) 2004-2015 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -25,11 +26,6 @@ typedef struct MainPanel_ { pid_t pidSearch; } MainPanel; -typedef union { - int i; - void* v; -} Arg; - typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg); #define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar) diff --git a/MainPanel.h b/MainPanel.h index 8d7533069..6162d8e93 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -5,6 +5,7 @@ /* htop - ColumnsPanel.h (C) 2004-2015 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -21,11 +22,6 @@ typedef struct MainPanel_ { pid_t pidSearch; } MainPanel; -typedef union { - int i; - void* v; -} Arg; - typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg); #define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar) diff --git a/Object.c b/Object.c index 120d28c14..669463522 100644 --- a/Object.c +++ b/Object.c @@ -1,6 +1,7 @@ /* htop - Object.c (C) 2004-2012 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -40,6 +41,11 @@ struct Object_ { ObjectClass* klass; }; +typedef union { + int i; + void* v; +} Arg; + }*/ ObjectClass Object_class = { diff --git a/Object.h b/Object.h index bcf2c4813..3505708c8 100644 --- a/Object.h +++ b/Object.h @@ -5,6 +5,7 @@ /* htop - Object.h (C) 2004-2012 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -41,6 +42,11 @@ struct Object_ { ObjectClass* klass; }; +typedef union { + int i; + void* v; +} Arg; + extern ObjectClass Object_class; diff --git a/Process.c b/Process.c index 199263e23..391fbb3e3 100644 --- a/Process.c +++ b/Process.c @@ -1,6 +1,7 @@ /* htop - Process.c (C) 2004-2015 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -561,14 +562,15 @@ bool Process_setPriority(Process* this, int priority) { return (err == 0); } -bool Process_changePriorityBy(Process* this, int delta) { - return Process_setPriority(this, this->nice + delta); +bool Process_changePriorityBy(Process* this, Arg delta) { + return Process_setPriority(this, this->nice + delta.i); } -void Process_sendSignal(Process* this, int sgn) { +bool Process_sendSignal(Process* this, Arg sgn) { CRT_dropPrivileges(); - kill(this->pid, (int) sgn); + bool ok = (kill(this->pid, sgn.i) == 0); CRT_restorePrivileges(); + return ok; } long Process_pidCompare(const void* v1, const void* v2) { diff --git a/Process.h b/Process.h index c45751673..604c754a9 100644 --- a/Process.h +++ b/Process.h @@ -5,6 +5,7 @@ /* htop - Process.h (C) 2004-2015 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -199,9 +200,9 @@ extern void Process_toggleTag(Process* this); extern bool Process_setPriority(Process* this, int priority); -extern bool Process_changePriorityBy(Process* this, int delta); +extern bool Process_changePriorityBy(Process* this, Arg delta); -extern void Process_sendSignal(Process* this, int sgn); +extern bool Process_sendSignal(Process* this, Arg sgn); extern long Process_pidCompare(const void* v1, const void* v2); diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 76f42394a..70c3b5d10 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -1,6 +1,7 @@ /* htop - LinuxProcess.c (C) 2014 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -314,12 +315,12 @@ IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this) { return ioprio; } -bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio) { +bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio) { // Other OSes masquerading as Linux (NetBSD?) don't have this syscall #ifdef SYS_ioprio_set - syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->super.pid, ioprio); + syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->super.pid, ioprio.i); #endif - return (LinuxProcess_updateIOPriority(this) == ioprio); + return (LinuxProcess_updateIOPriority(this) == ioprio.i); } #ifdef HAVE_DELAYACCT diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index f99843304..44ae91c13 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -5,6 +5,7 @@ /* htop - LinuxProcess.h (C) 2014 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -176,7 +177,7 @@ extern io_priority; extern IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this); -extern bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio); +extern bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio); #ifdef HAVE_DELAYACCT extern void LinuxProcess_printDelay(float delay_percent, char* buffer, int n); From a7a5e356c2990e7288cb70ebe0b9991b8e4136ba Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 20 Aug 2020 13:16:31 +1000 Subject: [PATCH 083/411] Documentation updates to reflect community maintainership Document the htop.dev site, #htop and htop@groups.io for contacting the community maintainers, and the upcoming 3.0.0 release. --- README | 51 ++++++++++--------------------- configure.ac | 7 ++--- htop.1.in | 84 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 67 insertions(+), 75 deletions(-) diff --git a/README b/README index 112da1c7d..5e6575465 100644 --- a/README +++ b/README @@ -1,47 +1,28 @@ -[![Build Status](https://travis-ci.org/hishamhm/htop.svg?branch=master)](https://travis-ci.org/hishamhm/htop) -[![PayPal donate](https://img.shields.io/badge/paypal-donate-green.svg)](http://hisham.hm/htop/index.php?page=donate) +![htop](https://htop.dev) -[htop](http://hisham.hm/htop/) -==== - -by Hisham Muhammad (2004 - 2016) +[![CI](https://github.com/htop-dev/htop/workflows/CI/badge.svg)](https://github.com/htop-dev/htop/actions) +[![Coverity Scan Build Status](https://scan.coverity.com/projects/21617/badge.svg)](https://scan.coverity.com/projects/21617) +[![Mailing List](https://img.shields.io/badge/Mailing%20List-htop-blue.svg)](https://groups.io/g/htop) +[![IRC #htop](https://img.shields.io/badge/IRC-htop-blue.svg)](https://webchat.freenode.net/#htop) +[![Github Release](https://img.shields.io/github/release/htop-dev/htop.svg)](https://github.com/htop-dev/htop/releases/latest) Introduction ------------ -This is `htop`, an interactive process viewer. -It requires `ncurses`. It is developed primarily on Linux, -but we also have code for running under FreeBSD and Mac OS X -(help and testing are wanted for these platforms!) - -This software has evolved considerably over the years, -and is reasonably complete, but there is always room for improvement. - -Comparison between `htop` and classic `top` -------------------------------------------- - -* In `htop` you can scroll the list vertically and horizontally - to see all processes and full command lines. -* In `top` you are subject to a delay for each unassigned - key you press (especially annoying when multi-key escape - sequences are triggered by accident). -* `htop` starts faster (`top` seems to collect data for a while - before displaying anything). -* In `htop` you don't need to type the process number to - kill a process, in `top` you do. -* In `htop` you don't need to type the process number or - the priority value to renice a process, in `top` you do. -* In `htop` you can kill multiple processes at once. -* `top` is older, hence, more tested. - -Compilation instructions ------------------------- +`htop` is a cross-platform interactive process viewer. +It requires `ncurses`. + +For more information and details on how to contribute to `htop` +visit [htop.dev](https://htop.dev). + +Build instructions +------------------ This program is distributed as a standard autotools-based package. For detailed instructions see the [INSTALL](/INSTALL) file, which is created after `./autogen.sh` is run. -When compiling from a [release tarball](https://hisham.hm/htop/releases/), run: +When compiling from a [release tarball](https://github.com/htop-dev/htop/releases/), run: ./configure && make @@ -55,8 +36,6 @@ the path use `./configure --prefix=/some/path`. See the manual page (`man htop`) or the on-line help ('F1' or 'h' inside `htop`) for a list of supported key commands. -If not all keys work check your curses configuration. - ## License GNU General Public License, version 2 (GPL-2.0) diff --git a/configure.ac b/configure.ac index 4c7360e68..71a4f7998 100644 --- a/configure.ac +++ b/configure.ac @@ -2,10 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.65) -AC_INIT([htop],[2.2.0],[hisham@gobolinux.org]) - -SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}" -year=$(date -u -d "@$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u "+%Y") +AC_INIT([htop],[3.0.0],[htop@groups.io]) AC_CONFIG_SRCDIR([htop.c]) AC_CONFIG_AUX_DIR([.]) @@ -308,7 +305,7 @@ if test ! -z "$missing_headers"; then AC_MSG_ERROR([missing headers: $missing_headers]) fi -AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-$year Hisham Muhammad", [Copyright message.]) +AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-2018 Hisham Muhammad", [Copyright message.]) # We're done, let's go! # ---------------------------------------------------------------------- diff --git a/htop.1.in b/htop.1.in index 149b1465a..faac2036c 100644 --- a/htop.1.in +++ b/htop.1.in @@ -1,4 +1,4 @@ -.TH "HTOP" "1" "2015" "@PACKAGE_STRING@" "Utils" +.TH "HTOP" "1" "2020" "@PACKAGE_STRING@" "User Commands" .SH "NAME" htop \- interactive process viewer .SH "SYNOPSIS" @@ -6,12 +6,16 @@ htop \- interactive process viewer .B htop [\fI\-dChustv\fR] .SH "DESCRIPTION" .LP -Htop is a free (GPL) ncurses-based process viewer for Linux. +.B htop +is a cross-platform ncurses-based process viewer. .LP -It is similar to top, but allows you to scroll vertically and horizontally, -so you can see all the processes running on the system, along with their full -command lines, as well as viewing them as a process tree, selecting multiple -processes and acting on them all at once. +It is similar to +.BR top , +but allows you to scroll vertically and horizontally, and interact using +a pointing device (mouse). +You can observe all processes running on the system, along with their +command line arguments, as well as view them in a tree format, select +multiple processes and acting on them all at once. .LP Tasks related to processes (killing, renicing) can be done without entering their PIDs. @@ -25,7 +29,9 @@ Mandatory arguments to long options are mandatory for short options too. Delay between updates, in tenths of seconds .TP \fB\-C \-\-no-color \-\-no-colour\fR -Start htop in monochrome mode +Start +.B htop +in monochrome mode .TP \fB\-h \-\-help Display a help message and exit @@ -44,11 +50,10 @@ Output version information and exit .TP \fB\-t \-\-tree Show processes in tree view -.PP -.br .SH "INTERACTIVE COMMANDS" .LP -The following commands are supported while in htop: +The following commands are supported while in +.BR htop : .LP .TP 5 .B Up, Alt-k @@ -194,14 +199,17 @@ Refresh: redraw screen and recalculate values. .B Numbers PID search: type in process ID and the selection highlight will be moved to it. .PD - .SH "COLUMNS" .LP The following columns can display data about each process. A value of '\-' in all the rows indicates that a column is unsupported on your system, or -currently unimplemented in htop. The names below are the ones used in the +currently unimplemented in +.BR htop . +The names below are the ones used in the "Available Columns" section of the setup screen. If a different name is -shown in htop's main screen, it is shown below in parenthesis. +shown in +.BR htop 's +main screen, it is shown below in parenthesis. .LP .TP 5 .B Command @@ -389,36 +397,44 @@ The percentage of time spent swapping in pages. Requires CAP_NET_ADMIN. .TP .B All other flags Currently unsupported (always displays '-'). - .SH "CONFIG FILE" .LP -By default htop reads its configuration from the XDG-compliant path -~/.config/htop/htoprc -- the configuration file is overwritten by htop's -in-program Setup configuration, so it should not be hand-edited. If no -user configuration exists htop tries to read the system-wide configuration -from @sysconfdir@/htoprc and as a last resort, falls back to its -hard coded defaults. +By default +.B htop +reads its configuration from the XDG-compliant path +.IR ~/.config/htop/htoprc . +The configuration file is overwritten by +.BR htop 's +in-program Setup configuration, so it should not be hand-edited. +If no user configuration exists +.B htop +tries to read the system-wide configuration from +.I @sysconfdir@/htoprc +and as a last resort, falls back to its hard coded defaults. .LP You may override the location of the configuration file using the $HTOPRC environment variable (so you can have multiple configurations for different machines that share the same home directory, for example). - .SH "MEMORY SIZES" .LP -Memory sizes in htop are displayed as they are in tools from the GNU Coreutils -(when ran with the --human-readable option). This means that sizes are printed -in powers of 1024. (e.g., 1023M = 1072693248 Bytes) +Memory sizes in +.B htop +are displayed in a human-readable form. +Sizes are printed in powers of 1024. (e.g., 1023M = 1072693248 Bytes) .LP -The decision to use this convention was made in order to conserve screen space -and make memory size representations consistent throughout htop. - +The decision to use this convention was made in order to conserve screen +space and make memory size representations consistent throughout +.BR htop . .SH "SEE ALSO" -proc(5), top(1), free(1), ps(1), uptime(1), limits.conf(5) - +.BR proc (5), +.BR top (1), +.BR free (1), +.BR ps (1), +.BR uptime (1) +and +.BR limits.conf (5). .SH "AUTHORS" .LP -htop is developed by Hisham Muhammad . -.LP -This man page was written by Bartosz Fenski for the Debian -GNU/Linux distribution (but it may be used by others). It was updated by Hisham -Muhammad, and later by Vincent Launchbury, who wrote the 'Columns' section. +.B htop +was originally developed by Hisham Muhammad. +Nowadays it is maintained by the community at . From 2be099270046fbec993c450b20f94987d78406d4 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 20 Aug 2020 13:59:41 +1000 Subject: [PATCH 084/411] Merge branch 'hishamhm-pull-890' --- CRT.c | 21 ++++++ CRT.h | 3 + Makefile.am | 6 +- linux/Platform.c | 24 +++++++ linux/Platform.h | 2 + linux/PressureStallMeter.c | 133 +++++++++++++++++++++++++++++++++++++ linux/PressureStallMeter.h | 25 +++++++ 7 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 linux/PressureStallMeter.c create mode 100644 linux/PressureStallMeter.h diff --git a/CRT.c b/CRT.c index 088cd1a41..48a591a23 100644 --- a/CRT.c +++ b/CRT.c @@ -128,6 +128,9 @@ typedef enum ColorElements_ { CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, + PRESSURE_STALL_TEN, + PRESSURE_STALL_SIXTY, + PRESSURE_STALL_THREEHUNDRED, LAST_COLORELEMENT } ColorElements; @@ -232,6 +235,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Magenta,Black), [CPU_STEAL] = ColorPair(Cyan,Black), [CPU_GUEST] = ColorPair(Cyan,Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan,Black), + [PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan,Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Black), }, [COLORSCHEME_MONOCHROME] = { [RESET_COLOR] = A_NORMAL, @@ -291,6 +297,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = A_BOLD, [CPU_STEAL] = A_REVERSE, [CPU_GUEST] = A_REVERSE, + [PRESSURE_STALL_THREEHUNDRED] = A_DIM, + [PRESSURE_STALL_SIXTY] = A_NORMAL, + [PRESSURE_STALL_TEN] = A_BOLD, }, [COLORSCHEME_BLACKONWHITE] = { [RESET_COLOR] = ColorPair(Black,White), @@ -350,6 +359,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Blue,White), [CPU_STEAL] = ColorPair(Cyan,White), [CPU_GUEST] = ColorPair(Cyan,White), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,White), + [PRESSURE_STALL_SIXTY] = ColorPair(Black,White), + [PRESSURE_STALL_TEN] = ColorPair(Black,White), }, [COLORSCHEME_LIGHTTERMINAL] = { [RESET_COLOR] = ColorPair(Black,Black), @@ -409,6 +421,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Blue,Black), [CPU_STEAL] = ColorPair(Black,Black), [CPU_GUEST] = ColorPair(Black,Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Black,Black), + [PRESSURE_STALL_TEN] = ColorPair(Black,Black), }, [COLORSCHEME_MIDNIGHT] = { [RESET_COLOR] = ColorPair(White,Blue), @@ -468,6 +483,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Black,Blue), [CPU_STEAL] = ColorPair(White,Blue), [CPU_GUEST] = ColorPair(White,Blue), + [PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black,Blue), + [PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White,Blue), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Blue), }, [COLORSCHEME_BLACKNIGHT] = { [RESET_COLOR] = ColorPair(Cyan,Black), @@ -527,6 +545,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_SOFTIRQ] = ColorPair(Blue,Black), [CPU_STEAL] = ColorPair(Cyan,Black), [CPU_GUEST] = ColorPair(Cyan,Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green,Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Green,Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green,Black), }, [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. }; diff --git a/CRT.h b/CRT.h index bc3fb8b72..f5adb4cee 100644 --- a/CRT.h +++ b/CRT.h @@ -116,6 +116,9 @@ typedef enum ColorElements_ { CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, + PRESSURE_STALL_TEN, + PRESSURE_STALL_SIXTY, + PRESSURE_STALL_THREEHUNDRED, LAST_COLORELEMENT } ColorElements; diff --git a/Makefile.am b/Makefile.am index 7d19600f6..5602fde75 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,14 +48,16 @@ linux_platform_headers = \ linux/LinuxProcess.h \ linux/LinuxProcessList.h \ linux/LinuxCRT.h \ - linux/Battery.h + linux/Battery.h \ + linux/PressureStallMeter.h all_platform_headers += $(linux_platform_headers) if HTOP_LINUX AM_CFLAGS += -rdynamic myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ -linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c +linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \ +linux/PressureStallMeter.c myhtopplatheaders = $(linux_platform_headers) endif diff --git a/linux/Platform.c b/linux/Platform.c index 13dec2776..130403f29 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -19,6 +19,7 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "LoadAverageMeter.h" #include "UptimeMeter.h" +#include "PressureStallMeter.h" #include "ClockMeter.h" #include "HostnameMeter.h" #include "LinuxProcess.h" @@ -126,6 +127,11 @@ MeterClass* Platform_meterTypes[] = { &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &BlankMeter_class, + &PressureStallCPUSomeMeter_class, + &PressureStallIOSomeMeter_class, + &PressureStallIOFullMeter_class, + &PressureStallMemorySomeMeter_class, + &PressureStallMemoryFullMeter_class, NULL }; @@ -237,3 +243,21 @@ char* Platform_getProcessEnv(pid_t pid) { } return env; } + +void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred) { + *ten = *sixty = *threehundred = 0; + char procname[128+1]; + xSnprintf(procname, 128, PROCDIR "/pressure/%s", file); + FILE *fd = fopen(procname, "r"); + if (!fd) { + *ten = *sixty = *threehundred = NAN; + return; + } + int total = fscanf(fd, "some avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred); + if (!some) { + total = fscanf(fd, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred); + } + (void) total; + assert(total == 3); + fclose(fd); +} diff --git a/linux/Platform.h b/linux/Platform.h index 89b0a3015..bb2c4b091 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -45,4 +45,6 @@ extern void Platform_setSwapValues(Meter* this); extern char* Platform_getProcessEnv(pid_t pid); +extern void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); + #endif diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c new file mode 100644 index 000000000..56055bff3 --- /dev/null +++ b/linux/PressureStallMeter.c @@ -0,0 +1,133 @@ +/* +htop - PressureStallMeter.c +(C) 2004-2011 Hisham H. Muhammad +(C) 2019 Ran Benita +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "PressureStallMeter.h" +#include "Platform.h" +#include "CRT.h" + +#include + +/*{ +#include "Meter.h" +}*/ + +static int PressureStallMeter_attributes[] = { + PRESSURE_STALL_TEN, PRESSURE_STALL_SIXTY, PRESSURE_STALL_THREEHUNDRED +}; + +static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) { + const char *file; + if (strstr(Meter_name(this), "CPU")) { + file = "cpu"; + } else if (strstr(Meter_name(this), "IO")) { + file = "io"; + } else { + file = "memory"; + } + + bool some; + if (strstr(Meter_name(this), "Some")) { + some = true; + } else { + some = false; + } + + Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]); + xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]); +} + +static void PressureStallMeter_display(Object* cast, RichString* out) { + Meter* this = (Meter*)cast; + char buffer[20]; + xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]); + RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer); + xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[1]); + RichString_append(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer); + xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[2]); + RichString_append(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer); +} + +MeterClass PressureStallCPUSomeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallCPUSome", + .uiName = "Pressure Stall Information, some CPU", + .caption = "Some CPU pressure: " +}; + +MeterClass PressureStallIOSomeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallIOSome", + .uiName = "Pressure Stall Information, some IO", + .caption = "Some IO pressure: " +}; + +MeterClass PressureStallIOFullMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallIOFull", + .uiName = "Pressure Stall Information, full IO", + .caption = "Full IO pressure: " +}; + +MeterClass PressureStallMemorySomeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallMemorySome", + .uiName = "Pressure Stall Information, some memory", + .caption = "Some Mem pressure: " +}; + +MeterClass PressureStallMemoryFullMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallMemoryFull", + .uiName = "Pressure Stall Information, full memory", + .caption = "Full Mem pressure: " +}; diff --git a/linux/PressureStallMeter.h b/linux/PressureStallMeter.h new file mode 100644 index 000000000..22b8b9724 --- /dev/null +++ b/linux/PressureStallMeter.h @@ -0,0 +1,25 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_PressureStallMeter +#define HEADER_PressureStallMeter +/* +htop - PressureStallMeter.h +(C) 2004-2011 Hisham H. Muhammad +(C) 2019 Ran Benita +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern MeterClass PressureStallCPUSomeMeter_class; + +extern MeterClass PressureStallIOSomeMeter_class; + +extern MeterClass PressureStallIOFullMeter_class; + +extern MeterClass PressureStallMemorySomeMeter_class; + +extern MeterClass PressureStallMemoryFullMeter_class; + +#endif From bba8c3bb2ebc72c89af96dc64786a02c1467da26 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Fri, 21 Aug 2020 12:10:11 +1000 Subject: [PATCH 085/411] Update the changelog to reflect content in the 3.0.0 release --- ChangeLog | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/ChangeLog b/ChangeLog index 453b96306..35007618f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,58 @@ +What's new in version 3.0.0 + +* Support ZFS ARC statistics + (thanks to Ross Williams) +* Support more than 2 smaller CPU meter columns + (thanks to Christoph Budziszewski) +* Support Linux proportional set size metrics + (thanks to @linvinus, @ntninja and @himikof) +* Support Linux pressure stall information metrics + (thanks to Ran Benita) +* New display option to show CPU frequency in CPU meters + (thanks to Arnav Singh) +* Update Linux sysfs battery discovery for recent kernels + (thanks to @smattie) +* Add timestamp reporting to the strace screen + (thanks to Mario Harjac) +* Add simple, optional vim key mapping mode + (thanks to Daniel Flanagan) +* Added an option to disable the mouse + (thanks to MartinJM) +* Add Solaris11 compatibility + (thanks to Jan Senolt) +* Without an argument -u uses $USER value automatically + (thanks to @solanav) +* Support less(1) search navigation shortcuts + (thanks to @syrrim) +* Update the FreeBSD maximum PID to match FreeBSD change + (thanks to @multiplexd) +* Report values larger than 100 terabytes + (thanks to @adrien1018) +* Widen ST_UID (UID) column to allow for UIDs > 9999 + (thanks to DLange) +* BUGFIX: fix makefiles for building with clang + (thanks to Jorge Pereira) +* BUGFIX: fix major() usage + (thanks to @wataash and Kang-Che Sung) +* BUGFIX: fix the STARTTIME column on FreeBSD + (thanks to Rob Crowston) +* BUGFIX: truncate overwide jail names on FreeBSD + (thanks to Rob Crowston) +* BUGFIX: fix reported memory values on FreeBSD + (thanks to Tobias Kortkamp) +* BUGFIX: fix reported CPU meter values on OpenBSD + (thanks to @motet-a) +* BUGFIX: correctly identify other types of zombie process + (thanks to @joder) +* BUGFIX: improve follow-process handling in some situations + (thanks to @wangqr) +* BUGFIX: fix custom meters reverting to unexpected setting + (thanks to @wangqr) +* BUGFIX: close pipe after running lsof(1) + (thanks to Jesin) +* BUGFIX: meters honour setting of counting CPUs from 0/1 + (thanks to @rnsanchez) + What's new in version 2.2.0 * Solaris/Illumos/OpenIndiana support From 0b276f80f14959ff3e5c2ab04f816cd83f86dc7c Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Fri, 21 Aug 2020 16:42:06 +1000 Subject: [PATCH 086/411] Mention change of maintainership in ChangeLog Related to https://github.com/hishamhm/htop/issues/992 --- ChangeLog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 35007618f..5b9e75915 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ What's new in version 3.0.0 +* New maintainers - after a prolonged period of inactivity + from Hisham, the creator and original maintainer, a team + of community maintainers have volunteered to take over a + fork at https://htop.dev and https://github.com/htop-dev + to keep the project going. + * Support ZFS ARC statistics (thanks to Ross Williams) * Support more than 2 smaller CPU meter columns From 57254cdd05981a6d2c035f868316bbca2c5495f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 21 Aug 2020 10:37:20 +0200 Subject: [PATCH 087/411] configure: add option --enable-werror Adds the compiler flag -Werror to fail on warnings. Useful for CI runs. --- Makefile.am | 2 +- configure.ac | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 159e22a77..0cc47b695 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,7 @@ applications_DATA = htop.desktop pixmapdir = $(datadir)/pixmaps pixmap_DATA = htop.png -AM_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)" +AM_CFLAGS += -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)" AM_LDFLAGS = AM_CPPFLAGS = -DNDEBUG diff --git a/configure.ac b/configure.ac index 71a4f7998..4e357a31d 100644 --- a/configure.ac +++ b/configure.ac @@ -295,6 +295,9 @@ then ]) fi +AC_ARG_ENABLE([werror], [AS_HELP_STRING([--enable-werror], [Treat warnings as errors (default: warnings are not errors)])], [enable_werror="$enableval"], [enable_werror=no]) +AS_IF([test "x$enable_werror" = "xyes"], [AM_CFLAGS="$AM_CFLAGS -Werror"]) +AC_SUBST([AM_CFLAGS]) # Bail out on errors. # ---------------------------------------------------------------------- From d6adc2b68143b0baef5ad60f0cb0dea70c913ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 21 Aug 2020 10:37:25 +0200 Subject: [PATCH 088/411] github/ci: improve ci - split steps for readability - fail on compiler warnings - add whitespace check - run on all branches - run `make distcheck` --- .github/workflows/ci.yml | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74d0ece89..5cb69fe35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,22 +1,22 @@ name: CI -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] +on: [ push, pull_request ] jobs: build-ubuntu-latest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Install Dependencies + run: sudo apt-get install libncursesw5-dev + - name: Bootstrap + run: ./autogen.sh + - name: Configure + run: ./configure --enable-werror - name: Build - run: | - sudo apt-get install libncursesw5-dev - ./autogen.sh - ./configure - make + run: make + - name: Distcheck + run: make distcheck # build-macos-latest: # runs-on: macos-latest @@ -27,3 +27,12 @@ jobs: # ./autogen.sh # ./configure # make + + whitespace_check: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: check-whitespaces + run: git diff-tree --check $(git hash-object -t tree /dev/null) HEAD From 40ac7a88af5a2c7c0d03ca4ddb09cde01f7e80c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 21 Aug 2020 10:37:27 +0200 Subject: [PATCH 089/411] MakeHeader.py: use python3 shebang Also drop unused import --- scripts/MakeHeader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/MakeHeader.py b/scripts/MakeHeader.py index 3ef34b88c..24533a621 100755 --- a/scripts/MakeHeader.py +++ b/scripts/MakeHeader.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python -import os, sys, string, io +#!/usr/bin/env python3 +import os, sys, io try: from StringIO import StringIO except ImportError: From 3856bf574b6686418392e6e1ba2ed8525427b241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 21 Aug 2020 10:37:29 +0200 Subject: [PATCH 090/411] Introduce xAsprintf as checked version of asprintf --- XAlloc.c | 6 +++++- XAlloc.h | 6 ++++++ linux/LinuxProcessList.c | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/XAlloc.c b/XAlloc.c index fbc642cc4..4aa8e217d 100644 --- a/XAlloc.c +++ b/XAlloc.c @@ -14,7 +14,7 @@ #include }*/ -static inline void fail() { +void fail() { curs_set(1); endwin(); err(1, NULL); @@ -44,6 +44,10 @@ void* xRealloc(void* ptr, size_t size) { return data; } +#undef xAsprintf + +#define xAsprintf(strp, fmt, ...) do { int _r=asprintf(strp, fmt, __VA_ARGS__); if (_r < 0) { fail(); } } while(0) + #define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0) #undef xStrdup diff --git a/XAlloc.h b/XAlloc.h index 97a1c0d08..2d4640516 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -11,12 +11,18 @@ #include #include +extern void fail(void); + extern void* xMalloc(size_t size); extern void* xCalloc(size_t nmemb, size_t size); extern void* xRealloc(void* ptr, size_t size); +#undef xAsprintf + +#define xAsprintf(strp, fmt, ...) do { int _r=asprintf(strp, fmt, __VA_ARGS__); if (_r < 0) { fail(); } } while(0) + #define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0) #undef xStrdup diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index bcdd55150..0d25e365a 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -822,11 +822,11 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in struct stat sstat; char* fullPath; for(;;) { - asprintf(&fullPath, "%s/%d", ttyDrivers[i].path, idx); + xAsprintf(&fullPath, "%s/%d", ttyDrivers[i].path, idx); int err = stat(fullPath, &sstat); if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath; free(fullPath); - asprintf(&fullPath, "%s%d", ttyDrivers[i].path, idx); + xAsprintf(&fullPath, "%s%d", ttyDrivers[i].path, idx); err = stat(fullPath, &sstat); if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath; free(fullPath); @@ -837,7 +837,7 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in if (err == 0 && tty_nr == sstat.st_rdev) return strdup(ttyDrivers[i].path); } char* out; - asprintf(&out, "/dev/%u:%u", maj, min); + xAsprintf(&out, "/dev/%u:%u", maj, min); return out; } From b92f62f912d15b5db59483ea803fe1bb282ebc9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 21 Aug 2020 10:37:33 +0200 Subject: [PATCH 091/411] Remove trailing whitespaces --- Action.c | 1 - CONTRIBUTING.md | 3 +- COPYING | 1 - ChangeLog | 4 +- ColumnsPanel.c | 1 - ListItem.c | 1 - NEWS | 1 - TESTPLAN | 69 ++++++++++++++++---------------- configure.ac | 2 +- darwin/Battery.c | 1 - darwin/DarwinCRT.c | 1 - dragonflybsd/DragonFlyBSDCRT.c | 1 - freebsd/FreeBSDCRT.c | 1 - htop.1.in | 26 ++++++------ linux/IOPriority.c | 1 - linux/IOPriorityPanel.c | 1 - linux/LinuxProcess.c | 1 - openbsd/OpenBSDCRT.c | 1 - openbsd/OpenBSDProcessList.c | 1 - solaris/Battery.c | 1 - solaris/SolarisProcessList.c | 1 - test_spec.lua | 25 ++++++------ unsupported/Battery.c | 1 - unsupported/UnsupportedCRT.c | 1 - unsupported/UnsupportedProcess.c | 1 - zfs/ZfsArcMeter.c | 2 +- 26 files changed, 64 insertions(+), 86 deletions(-) diff --git a/Action.c b/Action.c index 825e743d9..645739389 100644 --- a/Action.c +++ b/Action.c @@ -615,4 +615,3 @@ void Action_setBindings(Htop_Action* keys) { keys['c'] = actionTagAllChildren; keys['e'] = actionShowEnvScreen; } - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 61b4ca0eb..b62834d39 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,5 +52,4 @@ Donations --------- If you like htop, feel free to [buy the author a -beer](http://hisham.hm/htop/index.php?page=donate). :-) - +beer](http://hisham.hm/htop/index.php?page=donate). :-) diff --git a/COPYING b/COPYING index 393445c42..1bd75b9fe 100644 --- a/COPYING +++ b/COPYING @@ -353,4 +353,3 @@ Public License instead of this License. applicable licenses of the version of PLPA used in your combined work, provided that you include the source code of such version of PLPA when and as the GNU GPL requires distribution of source code. - diff --git a/ChangeLog b/ChangeLog index 5b9e75915..da91c074c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -219,7 +219,7 @@ What's new in version 1.0.2 What's new in version 1.0.1 * Move .htoprc to XDG-compliant path ~/.config/htop/htoprc, - respecting $XDG_CONFIG_HOME + respecting $XDG_CONFIG_HOME (thanks to Hadzhimurad Ustarkhan for the suggestion.) * Safer behavior on the kill screen, to make it harder to kill the wrong process. * Fix for building in FreeBSD 8.2 @@ -607,7 +607,7 @@ What's new in version 0.3.1 What's new in version 0.3 -* BUGFIX: no dirt left on screen on horizontal scrolling +* BUGFIX: no dirt left on screen on horizontal scrolling * Signal selection on "kill" command * Color-coding for users, nice and process status * "Follow" function diff --git a/ColumnsPanel.c b/ColumnsPanel.c index f982292ef..de89fa249 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -164,4 +164,3 @@ void ColumnsPanel_update(Panel* super) { } this->settings->fields[size] = 0; } - diff --git a/ListItem.c b/ListItem.c index 05c5c0b37..abaf5d0ab 100644 --- a/ListItem.c +++ b/ListItem.c @@ -85,4 +85,3 @@ long ListItem_compare(const void* cast1, const void* cast2) { ListItem* obj2 = (ListItem*) cast2; return strcmp(obj1->value, obj2->value); } - diff --git a/NEWS b/NEWS index fef048b6e..27fd578ef 100644 --- a/NEWS +++ b/NEWS @@ -2,4 +2,3 @@ See the commit history for news of the past. See the bug tracker for news of the future. Run the program for news of the present. - diff --git a/TESTPLAN b/TESTPLAN index 8dc050104..7669485fb 100644 --- a/TESTPLAN +++ b/TESTPLAN @@ -4,47 +4,47 @@ Main screen: For all views, all modes: Mouse click header - nothing happens. - + Mouse click on ProcessList title bar - exit Tree view, update FunctionBar, title bar updates, sort by clicked field. *** FAILING: wrong FB update depending on mode; does not change sort in wip branch click on same entry - invert sort. click on another entry - sort another field. - + Mouse click on a process - select that process. - + for each entry in FunctionBar: Mouse click entry - perform action of associated key. - + In Normal mode, Sorted view: - + <+> or <-> - do nothing. - + - enter SortBy screen. - + In Normal mode, Tree view: select process - update F6 in FunctionBar if subtree is collapsed or expanded. - + , <+> or <-> - expand/collapse subtree. - + In Normal mode, either Sorted or Tree view: , - activate Search mode. - + , <\> - activate Filter mode. , <]> - as root only, decrease process NICE value. - + , <[> - increase process NICE value. - enter Affinity screen. - do nothing. - + - select process and all its children. - + , , , - do nothing. - + , , - enter Help screen. - on Linux, enter IOPriority screen. @@ -64,67 +64,67 @@ Main screen: - enter STrace screen. , - toggle between Tree and Sorted view, update F5 in FunctionBar, follow process - + - enter User screen. , , , , - do nothing. - + , - do nothing. - + , , - enter Setup screen. , - do nothing. - + - follow process. - do nothing. - + - toggle show/hide userland threads. - + - invert sort order. - + - do nothing. - + - toggle show/hide kernel threads. - do nothing. - enter Sorted view, update function bar, sort by MEM%. - + , - do nothing.

- enter Sorted view, update function bar, sort by CPU%. , - do nothing. - + - enter Sorted view, update function bar, sort by TIME. - + - untag all processes. - + , , , , - do nothing. - + <<>, <>>, <,>, <.> - enter SortBy screen. - + space - tag current process, move down cursor. numbers - incremental PID search. - + In Search mode: TODO - + In Filter mode: - + TODO Setup screen: TODO - + SortBy screen: TODO - + User screen: TODO @@ -136,7 +136,7 @@ Kill screen: Affinity screen: TODO - + Help screen: any key - back to Main screen. @@ -152,4 +152,3 @@ STrace screen: LSOF screen: TODO - diff --git a/configure.ac b/configure.ac index 4e357a31d..323a94e9a 100644 --- a/configure.ac +++ b/configure.ac @@ -223,7 +223,7 @@ else HTOP_CHECK_LIB([ncurses], [refresh], [HAVE_LIBNCURSES], missing_libraries="$missing_libraries libncurses" )))) - + AC_CHECK_HEADERS([curses.h],[:], [AC_CHECK_HEADERS([ncurses/curses.h],[:], [AC_CHECK_HEADERS([ncurses/ncurses.h],[:], diff --git a/darwin/Battery.c b/darwin/Battery.c index d197c049b..d52a5954a 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -72,4 +72,3 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFRelease(power_sources); } } - diff --git a/darwin/DarwinCRT.c b/darwin/DarwinCRT.c index 51725984f..5a82f3122 100644 --- a/darwin/DarwinCRT.c +++ b/darwin/DarwinCRT.c @@ -32,4 +32,3 @@ void CRT_handleSIGSEGV(int sgn) { #endif abort(); } - diff --git a/dragonflybsd/DragonFlyBSDCRT.c b/dragonflybsd/DragonFlyBSDCRT.c index ba311856f..0ccfef598 100644 --- a/dragonflybsd/DragonFlyBSDCRT.c +++ b/dragonflybsd/DragonFlyBSDCRT.c @@ -32,4 +32,3 @@ void CRT_handleSIGSEGV(int sgn) { #endif abort(); } - diff --git a/freebsd/FreeBSDCRT.c b/freebsd/FreeBSDCRT.c index 5c3a9de45..49cc5d0d6 100644 --- a/freebsd/FreeBSDCRT.c +++ b/freebsd/FreeBSDCRT.c @@ -18,4 +18,3 @@ void CRT_handleSIGSEGV(int sgn) { fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); abort(); } - diff --git a/htop.1.in b/htop.1.in index c9e6e829c..9ef0761bd 100644 --- a/htop.1.in +++ b/htop.1.in @@ -2,11 +2,11 @@ .SH "NAME" htop \- interactive process viewer .SH "SYNOPSIS" -.LP +.LP .B htop .RB [ \-dChpustv ] .SH "DESCRIPTION" -.LP +.LP .B htop is a cross-platform ncurses-based process viewer. .LP @@ -20,11 +20,11 @@ multiple processes and acting on them all at once. .LP Tasks related to processes (killing, renicing) can be done without entering their PIDs. -.br +.br .SH "COMMAND-LINE OPTIONS" .LP Mandatory arguments to long options are mandatory for short options too. -.LP +.LP .TP \fB\-d \-\-delay=DELAY\fR Delay between updates, in tenths of seconds. If the delay value is @@ -54,10 +54,10 @@ Output version information and exit \fB\-t \-\-tree Show processes in tree view .SH "INTERACTIVE COMMANDS" -.LP +.LP The following commands are supported while in .BR htop : -.LP +.LP .TP 5 .B Up, Alt-k Select (highlight) the previous process in the process list. Scroll the list @@ -159,7 +159,7 @@ Quit Invert the sort order: if sort order is increasing, switch to decreasing, and vice-versa. .TP -.B +, \- +.B +, \- When in tree view mode, expand or collapse subtree. When a subtree is collapsed a "+" sign shows to the left of the process name. .TP @@ -203,7 +203,7 @@ Refresh: redraw screen and recalculate values. PID search: type in process ID and the selection highlight will be moved to it. .PD .SH "COLUMNS" -.LP +.LP The following columns can display data about each process. A value of '\-' in all the rows indicates that a column is unsupported on your system, or currently unimplemented in @@ -213,11 +213,11 @@ The names below are the ones used in the shown in .BR htop 's main screen, it is shown below in parenthesis. -.LP +.LP .TP 5 .B Command The full command line of the process (i.e. program name and arguments). -.TP +.TP .B PID The process ID. .TP @@ -238,7 +238,7 @@ The process's group ID. .TP .B SESSION (SID) The process's session ID. -.TP +.TP .B TTY_NR (TTY) The controlling terminal of the process. .TP @@ -401,7 +401,7 @@ The percentage of time spent swapping in pages. Requires CAP_NET_ADMIN. .B All other flags Currently unsupported (always displays '-'). .SH "CONFIG FILE" -.LP +.LP By default .B htop reads its configuration from the XDG-compliant path @@ -437,7 +437,7 @@ space and make memory size representations consistent throughout and .BR limits.conf (5). .SH "AUTHORS" -.LP +.LP .B htop was originally developed by Hisham Muhammad. Nowadays it is maintained by the community at . diff --git a/linux/IOPriority.c b/linux/IOPriority.c index 80007df07..087f7f980 100644 --- a/linux/IOPriority.c +++ b/linux/IOPriority.c @@ -38,4 +38,3 @@ typedef int IOPriority; #define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 7) }*/ - diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index 2b315b828..22735bba2 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -41,4 +41,3 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { IOPriority IOPriorityPanel_getIOPriority(Panel* this) { return (IOPriority) ( ((ListItem*) Panel_getSelected(this))->key ); } - diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 50b4d2208..3a1504956 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -514,4 +514,3 @@ long LinuxProcess_compare(const void* v1, const void* v2) { bool Process_isThread(Process* this) { return (Process_isUserlandThread(this) || Process_isKernelThread(this)); } - diff --git a/openbsd/OpenBSDCRT.c b/openbsd/OpenBSDCRT.c index c5dcec4ae..233d30c99 100644 --- a/openbsd/OpenBSDCRT.c +++ b/openbsd/OpenBSDCRT.c @@ -19,4 +19,3 @@ void CRT_handleSIGSEGV(int sgn) { fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); abort(); } - diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 2d8951c3e..ea40fe17e 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -400,4 +400,3 @@ void ProcessList_goThroughEntries(ProcessList* this) { OpenBSDProcessList_scanProcs(opl); OpenBSDProcessList_scanCPUTime(opl); } - diff --git a/solaris/Battery.c b/solaris/Battery.c index 6d6e94bd2..080cf5400 100644 --- a/solaris/Battery.c +++ b/solaris/Battery.c @@ -5,4 +5,3 @@ void Battery_getData(double* level, ACPresence* isOnAC) { *level = -1; *isOnAC = AC_ERROR; } - diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 8faa49f3c..ab2cf68b4 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -419,4 +419,3 @@ void ProcessList_goThroughEntries(ProcessList* this) { this->kernelThreads = 1; proc_walk(&SolarisProcessList_walkproc, this, PR_WALK_LWP); } - diff --git a/test_spec.lua b/test_spec.lua index 7fd6c0c0d..2ae8015d6 100755 --- a/test_spec.lua +++ b/test_spec.lua @@ -1,7 +1,7 @@ #!/usr/bin/env lua local VISUALDELAY = os.getenv("VISUALDELAY") - + local visual = VISUALDELAY or false local visual_delay = VISUALDELAY and (tonumber(VISUALDELAY)) or 0.1 local short_delay = 0.3 @@ -70,7 +70,7 @@ local function show(key) term_win:mvaddstr(0, 0, tostring(key)) end term_win:refresh() - + delay(visual_delay) end end @@ -191,7 +191,7 @@ local function set_display_option(n) end describe("htop test suite", function() - + running_it("performs incremental filter", function() send("\\") send("x\127bux\127sted") -- test backspace @@ -397,13 +397,13 @@ describe("htop test suite", function() assert.not_equal(pair[1], pair[2]) end end) - + running_it("visits each setup screen", function() send("S") send(curses.KEY_DOWN, 3) send(curses.KEY_F10) end) - + running_it("adds and removes PPID column", function() send("S") send(curses.KEY_DOWN, 3) @@ -423,7 +423,7 @@ describe("htop test suite", function() assert.equal(check(ppid)) assert.not_equal(check(not_ppid)) end) - + running_it("changes CPU affinity for a process", function() send("a") send(" \n") @@ -468,7 +468,7 @@ describe("htop test suite", function() assert.equal(check(zerocpu)) assert.not_equal(check(nonzerocpu)) end) - + running_it("changes IO priority for a process", function() send("/") send("htop") @@ -502,7 +502,7 @@ describe("htop test suite", function() send("\n") send(curses.KEY_F10) end) - + local meters = { { name = "clock", down = 0, string = "Time" }, { name = "load", down = 2, string = "Load" }, @@ -558,7 +558,7 @@ describe("htop test suite", function() send("\n") send(curses.KEY_F10) end) - + local display_options = { { name = "tree view", down = 0 }, { name = "shadow other user's process", down = 1 }, @@ -574,7 +574,7 @@ describe("htop test suite", function() { name = "update process names", down = 11 }, { name = "guest time in CPU%", down = 12 }, } - + for _, item in ipairs(display_options) do running_it("checks display option to "..item.name, function() for _ = 1, 2 do @@ -641,7 +641,7 @@ describe("htop test suite", function() assert.equal(attrs.white_on_black, untaggedattr) end end) - + for i = 1, 62 do running_it("show column "..i, function() send("S") @@ -670,7 +670,7 @@ describe("htop test suite", function() end end) end - + it("finally quits", function() assert(not terminated()) send("q") @@ -685,4 +685,3 @@ describe("htop test suite", function() os.execute("make lcov && xdg-open lcov/index.html") end) end) - diff --git a/unsupported/Battery.c b/unsupported/Battery.c index 6d6e94bd2..080cf5400 100644 --- a/unsupported/Battery.c +++ b/unsupported/Battery.c @@ -5,4 +5,3 @@ void Battery_getData(double* level, ACPresence* isOnAC) { *level = -1; *isOnAC = AC_ERROR; } - diff --git a/unsupported/UnsupportedCRT.c b/unsupported/UnsupportedCRT.c index 5c3a9de45..49cc5d0d6 100644 --- a/unsupported/UnsupportedCRT.c +++ b/unsupported/UnsupportedCRT.c @@ -18,4 +18,3 @@ void CRT_handleSIGSEGV(int sgn) { fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); abort(); } - diff --git a/unsupported/UnsupportedProcess.c b/unsupported/UnsupportedProcess.c index ec1de78ec..e3b4689a5 100644 --- a/unsupported/UnsupportedProcess.c +++ b/unsupported/UnsupportedProcess.c @@ -30,4 +30,3 @@ void UnsupportedProcess_delete(Object* cast) { // free platform-specific fields here free(this); } - diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index 9f7028bc9..8042555c1 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -93,7 +93,7 @@ MeterClass ZfsArcMeter_class = { .delete = Meter_delete, .display = ZfsArcMeter_display, }, - .updateValues = ZfsArcMeter_updateValues, + .updateValues = ZfsArcMeter_updateValues, .defaultMode = TEXT_METERMODE, .maxItems = 6, .total = 100.0, From 9fde0835edd140e1d57361c2ce958bf106bc9d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 21 Aug 2020 10:38:44 +0200 Subject: [PATCH 092/411] Avoid empty translation unit warning zfs/ZfsArcStats.c:22: error: ISO C forbids an empty translation unit [-Werror=pedantic] 22 | }*/ | --- zfs/ZfsArcStats.c | 2 ++ zfs/ZfsArcStats.h | 1 + 2 files changed, 3 insertions(+) diff --git a/zfs/ZfsArcStats.c b/zfs/ZfsArcStats.c index 1bfaf47d8..bfed07d3c 100644 --- a/zfs/ZfsArcStats.c +++ b/zfs/ZfsArcStats.c @@ -20,3 +20,5 @@ typedef struct ZfsArcStats_ { unsigned long long int uncompressed; } ZfsArcStats; }*/ + +static int make_iso_compilers_happy __attribute__((unused)); diff --git a/zfs/ZfsArcStats.h b/zfs/ZfsArcStats.h index ee5d0eddd..9368ba9d2 100644 --- a/zfs/ZfsArcStats.h +++ b/zfs/ZfsArcStats.h @@ -23,4 +23,5 @@ typedef struct ZfsArcStats_ { unsigned long long int uncompressed; } ZfsArcStats; + #endif From 6aed2be24706ec6ccf7f68b11020142816dc49b4 Mon Sep 17 00:00:00 2001 From: Graham Inggs Date: Fri, 21 Aug 2020 16:49:28 +0200 Subject: [PATCH 093/411] Fix build on FreeBSD --- freebsd/FreeBSDProcessList.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 7bc42db61..8c892a021 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -325,17 +325,6 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { cachedMem *= pageSizeKb; pl->cachedMem = cachedMem; - if (fpl->zfsArcEnabled) { - len = sizeof(memZfsArc); - sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(memZfsArc), &len , NULL, 0); - memZfsArc /= 1024; - fpl->memZfsArc = memZfsArc; - fpl->memWire -= fpl->memZfsArc; - pl->cachedMem += fpl->memZfsArc; - // maybe when we learn how to make custom memory meter - // we could do custom arc breakdown? - } - if (fpl->zfs.enabled) { fpl->memWire -= fpl->zfs.size; pl->cachedMem += fpl->zfs.size; From 5dad65ac2a2a0aa5e1d71c2e78a5eac1f4eeb20f Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Sat, 22 Aug 2020 15:45:40 +1000 Subject: [PATCH 094/411] Update header files to match whitespace changes in source files --- Action.h | 1 - ColumnsPanel.h | 1 - ListItem.h | 1 - linux/IOPriority.h | 1 - linux/IOPriorityPanel.h | 1 - linux/LinuxProcess.h | 1 - zfs/ZfsArcMeter.h | 2 +- 7 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Action.h b/Action.h index c49e9dac7..4c5971b63 100644 --- a/Action.h +++ b/Action.h @@ -54,5 +54,4 @@ extern Htop_Reaction Action_follow(State* st); extern void Action_setBindings(Htop_Action* keys); - #endif diff --git a/ColumnsPanel.h b/ColumnsPanel.h index 46d20bbb2..669dc0272 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -28,5 +28,4 @@ extern int ColumnsPanel_fieldNameToIndex(const char* name); extern void ColumnsPanel_update(Panel* super); - #endif diff --git a/ListItem.h b/ListItem.h index 7fed92379..402c5c4ff 100644 --- a/ListItem.h +++ b/ListItem.h @@ -29,5 +29,4 @@ extern const char* ListItem_getRef(ListItem* this); extern long ListItem_compare(const void* cast1, const void* cast2); - #endif diff --git a/linux/IOPriority.h b/linux/IOPriority.h index 1c9ca95b8..a4733e890 100644 --- a/linux/IOPriority.h +++ b/linux/IOPriority.h @@ -39,5 +39,4 @@ typedef int IOPriority; #define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 7) - #endif diff --git a/linux/IOPriorityPanel.h b/linux/IOPriorityPanel.h index 0bf74f50e..906296ed0 100644 --- a/linux/IOPriorityPanel.h +++ b/linux/IOPriorityPanel.h @@ -17,5 +17,4 @@ extern Panel* IOPriorityPanel_new(IOPriority currPrio); extern IOPriority IOPriorityPanel_getIOPriority(Panel* this); - #endif diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 1e47ba287..7c0a11f86 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -189,5 +189,4 @@ extern long LinuxProcess_compare(const void* v1, const void* v2); extern bool Process_isThread(Process* this); - #endif diff --git a/zfs/ZfsArcMeter.h b/zfs/ZfsArcMeter.h index c52083df2..f2e322f94 100644 --- a/zfs/ZfsArcMeter.h +++ b/zfs/ZfsArcMeter.h @@ -15,7 +15,7 @@ in the source distribution for its full text. extern int ZfsArcMeter_attributes[]; -void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats); +extern void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats); extern MeterClass ZfsArcMeter_class; From 6900e57efde3fdb32cc1e8d1a8efc2bee8df73ba Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Sat, 22 Aug 2020 15:47:11 +1000 Subject: [PATCH 095/411] Updates to project URLs in docs and embedded in source code --- CONTRIBUTING.md | 53 ++++++++++------------------------ darwin/DarwinCRT.c | 2 +- dragonflybsd/DragonFlyBSDCRT.c | 2 +- linux/LinuxCRT.c | 2 +- solaris/SolarisCRT.c | 2 +- 5 files changed, 20 insertions(+), 41 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b62834d39..7110e44c8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,55 +1,34 @@ - Contributing Guide ================== -Hello, and thank you so much for taking your time to contribute in any way to -htop! There are many ways to contribute, and I'll try to list them below. The -support from the free software community has been amazing over the years and -it is the number one thing that keeps me going, maintaining and improving -something that started as a tiny pet project back in 2004 and that nowadays is -a piece of software used all over the world, in both reality [and -fiction!](http://hisham.hm/htop/index.php?page=sightings). Cheers! - --- Hisham Muhammad +Thank you so much for taking the time to contribute in to htop! Bug Reports ----------- Bug reports should be posted in the [Github issue -tracker](http://github.com/hishamhm/htop/issues). (I reply to them all, but I -usually do it in batches! :) ) Bug reports are extremely important since it's -impossible for me to test htop in every possible system, distribution and -scenario. Your feedback is what keeps the tool stable and always improving! -Thank you! +tracker](https://github.com/htop-dev/htop/issues). +Bug reports are extremely important since it's impossible for us to test +htop in every possible system, distribution and scenario. Your feedback +is what keeps the tool stable and always improving! Thank you! Pull Requests ------------- Code contributions are most welcome! Just [fork the -repo](http://github.com/hishamhm/htop) and send a [pull -request](https://github.com/hishamhm/htop/pulls). Help is especially -appreciated for support of platforms other than Linux. If proposing new +repo](https://github.com/htop-dev/htop) and send a [pull +request](https://github.com/htop-dev/htop/pulls). Help is especially +appreciated for support of platforms other than Linux. If proposing new features, please be mindful that htop is a system tool that needs to keep a -small footprint and perform well on systems under stress -- so unfortunately I -can't accept every new feature proposed, as I need to keep the tool slim and -maintainable. Great ideas backed by a PR are always carefully considered for -inclusion, though! Also, PRs containing bug fixes and portability tweaks are a -no-brainer, please send those in! +small footprint and perform well on systems under stress -- so unfortunately +we can't accept every new feature proposed, as we need to keep the tool slim +and maintainable. Great ideas backed by a PR are always carefully considered +for inclusion though! Also, PRs containing bug fixes and portability tweaks +are always included, please send those in! Feature Requests ---------------- -Back when htop was hosted in SourceForge, there used to be separate Bug -Tracker and Feature Request pages. These go all lumped together under "Issues" -in Github, which is a bit confusing. For this reason, I close Feature Requests -and file them with the [`feature -request`](https://github.com/hishamhm/htop/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22feature+request%22+) -label, where they remain accessible, but not mixed with actual bug reports. -This doesn't mean I'm dismissing or ignoring feature requests right away! It's -just an organizational issue (with Github, really!). - -Donations ---------- - -If you like htop, feel free to [buy the author a -beer](http://hisham.hm/htop/index.php?page=donate). :-) +Please label Github issues that are feature requests with the [`feature +request`](https://github.com/htop-dev/htop/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22feature+request%22+) +label. diff --git a/darwin/DarwinCRT.c b/darwin/DarwinCRT.c index 5a82f3122..2191f3076 100644 --- a/darwin/DarwinCRT.c +++ b/darwin/DarwinCRT.c @@ -15,7 +15,7 @@ void CRT_handleSIGSEGV(int sgn) { (void) sgn; CRT_done(); #ifdef __APPLE__ - fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n"); + fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); #ifdef HAVE_EXECINFO_H size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); fprintf(stderr, "\n Please include in your report the following backtrace: \n"); diff --git a/dragonflybsd/DragonFlyBSDCRT.c b/dragonflybsd/DragonFlyBSDCRT.c index 0ccfef598..a0920833e 100644 --- a/dragonflybsd/DragonFlyBSDCRT.c +++ b/dragonflybsd/DragonFlyBSDCRT.c @@ -17,7 +17,7 @@ in the source distribution for its full text. void CRT_handleSIGSEGV(int sgn) { (void) sgn; CRT_done(); - fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n"); + fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); #ifdef HAVE_EXECINFO_H size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); fprintf(stderr, "\n Please include in your report the following backtrace: \n"); diff --git a/linux/LinuxCRT.c b/linux/LinuxCRT.c index 5b2a21fda..c65b78221 100644 --- a/linux/LinuxCRT.c +++ b/linux/LinuxCRT.c @@ -17,7 +17,7 @@ void CRT_handleSIGSEGV(int sgn) { (void) sgn; CRT_done(); #ifdef __linux - fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n"); + fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); #ifdef HAVE_EXECINFO_H size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); fprintf(stderr, "\n Please include in your report the following backtrace: \n"); diff --git a/solaris/SolarisCRT.c b/solaris/SolarisCRT.c index d7f8f52e4..13e82d7c7 100644 --- a/solaris/SolarisCRT.c +++ b/solaris/SolarisCRT.c @@ -17,7 +17,7 @@ in the source distribution for its full text. void CRT_handleSIGSEGV(int sgn) { (void) sgn; CRT_done(); - fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n"); + fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); #ifdef HAVE_EXECINFO_H size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); fprintf(stderr, "\n Please include in your report the following backtrace: \n"); From b3aef4ea3a043c1988451bf237902fa77bccb0d5 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Sun, 23 Aug 2020 09:42:11 +1000 Subject: [PATCH 096/411] Revert "MakeHeader.py: use python3 shebang" This reverts commit 40ac7a88af5a2c7c0d03ca4ddb09cde01f7e80c5. as it causes build failure on non-python3 platforms. --- scripts/MakeHeader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/MakeHeader.py b/scripts/MakeHeader.py index 24533a621..3ef34b88c 100755 --- a/scripts/MakeHeader.py +++ b/scripts/MakeHeader.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python3 -import os, sys, io +#!/usr/bin/env python +import os, sys, string, io try: from StringIO import StringIO except ImportError: From 9e57b5c3f48c15aa8fb0ced408ec745eb6ad8874 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Sun, 23 Aug 2020 11:24:52 +1000 Subject: [PATCH 097/411] Generate an appropriate shebang line for MakeHeader script Use configure.ac to handle platform differences where some build hosts have only a python3, or only python, binary. Related to https://github.com/htop-dev/htop/pull/6 --- .gitignore | 1 + configure.ac | 5 ++++- scripts/{MakeHeader.py => MakeHeader.py.in} | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) rename scripts/{MakeHeader.py => MakeHeader.py.in} (99%) diff --git a/.gitignore b/.gitignore index f94f3f52e..b642d7cbd 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,5 @@ libtool ltmain.sh m4/ missing +scripts/MakeHeader.py stamp-h1 diff --git a/configure.ac b/configure.ac index 323a94e9a..a2eb53ecb 100644 --- a/configure.ac +++ b/configure.ac @@ -299,6 +299,9 @@ AC_ARG_ENABLE([werror], [AS_HELP_STRING([--enable-werror], [Treat warnings as er AS_IF([test "x$enable_werror" = "xyes"], [AM_CFLAGS="$AM_CFLAGS -Werror"]) AC_SUBST([AM_CFLAGS]) +AC_CHECK_PROGS(PYTHON, [python python3 python2]) +AC_SUBST(PYTHON) + # Bail out on errors. # ---------------------------------------------------------------------- if test ! -z "$missing_libraries"; then @@ -320,7 +323,7 @@ AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin]) AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris]) AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported]) AC_SUBST(my_htop_platform) -AC_CONFIG_FILES([Makefile htop.1]) +AC_CONFIG_FILES([Makefile htop.1 scripts/MakeHeader.py], [chmod +x scripts/MakeHeader.py]) AC_OUTPUT if test "$my_htop_platform" = "unsupported" diff --git a/scripts/MakeHeader.py b/scripts/MakeHeader.py.in similarity index 99% rename from scripts/MakeHeader.py rename to scripts/MakeHeader.py.in index 3ef34b88c..9da6685ab 100755 --- a/scripts/MakeHeader.py +++ b/scripts/MakeHeader.py.in @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env @PYTHON@ import os, sys, string, io try: from StringIO import StringIO From 9eb9064fbda0995c286cddd7a0436822a3d6906f Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Mon, 24 Aug 2020 10:22:44 +1000 Subject: [PATCH 098/411] Cleanup unused CI build notes and whitespace --- .github/workflows/ci.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5cb69fe35..bb7fb0a8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,20 +18,8 @@ jobs: - name: Distcheck run: make distcheck -# build-macos-latest: -# runs-on: macos-latest -# steps: -# - uses: actions/checkout@v2 -# - name: make -# run: | -# ./autogen.sh -# ./configure -# make - whitespace_check: - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - name: check-whitespaces From dad62b6c9e8a9e962b31175d4a768b37e1f8f3ec Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 24 Aug 2020 21:01:50 +0200 Subject: [PATCH 099/411] Put Makeheader.py.in into AC_CONFIG_FILES --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a2eb53ecb..a434cfd3b 100644 --- a/configure.ac +++ b/configure.ac @@ -323,7 +323,7 @@ AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin]) AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris]) AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported]) AC_SUBST(my_htop_platform) -AC_CONFIG_FILES([Makefile htop.1 scripts/MakeHeader.py], [chmod +x scripts/MakeHeader.py]) +AC_CONFIG_FILES([Makefile htop.1 scripts/MakeHeader.py.in], [chmod +x scripts/MakeHeader.py]) AC_OUTPUT if test "$my_htop_platform" = "unsupported" From 0bac7c9d9468f99fa43190ed3d0034d0cc0753b6 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 24 Aug 2020 21:08:07 +0200 Subject: [PATCH 100/411] Nope, configure works but make breaks. This reverts commit dad62b6c9e8a9e962b31175d4a768b37e1f8f3ec. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a434cfd3b..a2eb53ecb 100644 --- a/configure.ac +++ b/configure.ac @@ -323,7 +323,7 @@ AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin]) AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris]) AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported]) AC_SUBST(my_htop_platform) -AC_CONFIG_FILES([Makefile htop.1 scripts/MakeHeader.py.in], [chmod +x scripts/MakeHeader.py]) +AC_CONFIG_FILES([Makefile htop.1 scripts/MakeHeader.py], [chmod +x scripts/MakeHeader.py]) AC_OUTPUT if test "$my_htop_platform" = "unsupported" From e172282002b52e278636e6594a8d20ad5e140a25 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 24 Aug 2020 21:37:28 +0200 Subject: [PATCH 101/411] Fix in AC_CONFIG_FILES, try #2 --- configure.ac | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a2eb53ecb..18291b952 100644 --- a/configure.ac +++ b/configure.ac @@ -323,7 +323,8 @@ AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin]) AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris]) AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported]) AC_SUBST(my_htop_platform) -AC_CONFIG_FILES([Makefile htop.1 scripts/MakeHeader.py], [chmod +x scripts/MakeHeader.py]) +AC_CONFIG_FILES([Makefile htop.1]) +AC_CONFIG_FILES([scripts/MakeHeader.py], [chmod +x scripts/MakeHeader.py]) AC_OUTPUT if test "$my_htop_platform" = "unsupported" From 054b7f28013d4e392dbd34f2fa777ccc7c17b499 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Tue, 25 Aug 2020 10:09:35 +0200 Subject: [PATCH 102/411] Fix out-of-tree builds --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 0cc47b695..4dc638fd8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -225,7 +225,7 @@ coverage: $(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" LDFLAGS="-lgcov" .c.h: - @srcdir@/scripts/MakeHeader.py $< + ./scripts/MakeHeader.py $< cppcheck: cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS From 345d415537af1006fb32ff02743d788e64a32ae8 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Tue, 25 Aug 2020 11:38:14 +0200 Subject: [PATCH 103/411] Do not include the generated `config.h` header into the package --- Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 0cc47b695..c76306b87 100644 --- a/Makefile.am +++ b/Makefile.am @@ -203,7 +203,8 @@ endif SUFFIXES = .h BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders) -htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h +htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) +nodist_htop_SOURCES = config.h .PHONY: htop-headers clean-htop-headers From d64a6a245361b1cce92c77ec677ca8dc1f0fec49 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Tue, 25 Aug 2020 10:52:29 +0200 Subject: [PATCH 104/411] CI: Add a HWLOC enabled job --- .github/workflows/ci.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb7fb0a8e..a60d48a66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,21 @@ jobs: - name: Distcheck run: make distcheck + build-ubuntu-latest-hwloc: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Dependencies + run: sudo apt-get install libncursesw5-dev libhwloc-dev + - name: Bootstrap + run: ./autogen.sh + - name: Configure + run: ./configure --enable-werror --enable-hwloc + - name: Build + run: make + - name: Distcheck + run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-hwloc' + whitespace_check: runs-on: ubuntu-latest steps: From 6b117694489f523cfd7dce926b5b3ab5472095ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Aug 2020 21:26:10 +0200 Subject: [PATCH 105/411] Avoid conversion warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit linux/Platform.c:47:90: error: implicit conversion from ‘enum LinuxProcessFields’ to ‘enum ProcessFields’ [-Werror=enum-conversion] 47 | ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; | --- linux/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/Platform.c b/linux/Platform.c index 1725eea95..10311a2d0 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -44,7 +44,7 @@ in the source distribution for its full text. #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #endif -ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; +ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, (int)M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; //static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 }; From 21fb56e1e297c5ea85d685eb3809f1052d6f9a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Aug 2020 21:31:50 +0200 Subject: [PATCH 106/411] Avoid string overflow warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enough memory is allocated. Header.c: In function ‘Header_readMeterName’: Header.c:157:4: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 157 | strncpy(name, Meter_name(meter), nameLen); | ^ Header.c:154:18: note: length computed here 154 | int nameLen = strlen(Meter_name(meter)); | ^ --- Header.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Header.c b/Header.c index a4075d221..c8cfaabcd 100644 --- a/Header.c +++ b/Header.c @@ -154,7 +154,7 @@ char* Header_readMeterName(Header* this, int i, int column) { int nameLen = strlen(Meter_name(meter)); int len = nameLen + 100; char* name = xMalloc(len); - strncpy(name, Meter_name(meter), nameLen); + memcpy(name, Meter_name(meter), nameLen); name[nameLen] = '\0'; if (meter->param) xSnprintf(name + nameLen, len - nameLen, "(%d)", meter->param); From 7457bfe9f319d939f9840a79703991d4b7beaaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Aug 2020 21:34:28 +0200 Subject: [PATCH 107/411] Avoid string overflow warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use xStrdup instead of xMallow and strncpy StringUtils.c: In function ‘String_split’: StringUtils.c:86:7: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 86 | strncpy(token, s, size + 1); | ^ StringUtils.c:84:18: note: length computed here 84 | int size = strlen(s); | ^ --- StringUtils.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/StringUtils.c b/StringUtils.c index 0ac54b120..d7058a283 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -81,10 +81,7 @@ char** String_split(const char* s, char sep, int* n) { s += size + 1; } if (s[0] != '\0') { - int size = strlen(s); - char* token = xMalloc(size + 1); - strncpy(token, s, size + 1); - out[ctr] = token; + out[ctr] = xStrdup(s); ctr++; } out = xRealloc(out, sizeof(char*) * (ctr + 1)); From 11f558f93421a42aa29e0de7e50e670facfb5bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Aug 2020 21:58:14 +0200 Subject: [PATCH 108/411] Avoid discarding const qualifiers --- InfoScreen.c | 4 ++-- InfoScreen.h | 4 ++-- Process.c | 2 +- Process.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/InfoScreen.c b/InfoScreen.c index 0b9199329..93120006d 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -56,7 +56,7 @@ static const char* const InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"}; static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27}; -InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader) { +InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, const char* panelHeader) { this->process = process; if (!bar) { bar = FunctionBar_new(InfoScreenFunctions, InfoScreenKeys, InfoScreenEvents); @@ -75,7 +75,7 @@ InfoScreen* InfoScreen_done(InfoScreen* this) { return this; } -void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...) { +void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) { va_list ap; va_start(ap, fmt); attrset(CRT_colors[METER_TEXT]); diff --git a/InfoScreen.h b/InfoScreen.h index b9387cda3..e5d6bb67d 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -38,11 +38,11 @@ struct InfoScreen_ { Vector* lines; }; -extern InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader); +extern InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, const char* panelHeader); extern InfoScreen* InfoScreen_done(InfoScreen* this); -extern void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...); +extern void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...); extern void InfoScreen_addLine(InfoScreen* this, const char* line); diff --git a/Process.c b/Process.c index 7bcaf19ae..6a0d56b9a 100644 --- a/Process.c +++ b/Process.c @@ -85,7 +85,7 @@ typedef enum ProcessFields { typedef struct ProcessPidColumn_ { int id; - char* label; + const char* label; } ProcessPidColumn; typedef struct Process_ { diff --git a/Process.h b/Process.h index 56a4dba19..3085f1648 100644 --- a/Process.h +++ b/Process.h @@ -61,7 +61,7 @@ typedef enum ProcessFields { typedef struct ProcessPidColumn_ { int id; - char* label; + const char* label; } ProcessPidColumn; typedef struct Process_ { From 1130ad8b739be8f10bcf49a3928264cdf5566258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 23 Aug 2020 12:48:08 +0200 Subject: [PATCH 109/411] MakeHeader.py.in: remove executable bit --- scripts/MakeHeader.py.in | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 scripts/MakeHeader.py.in diff --git a/scripts/MakeHeader.py.in b/scripts/MakeHeader.py.in old mode 100755 new mode 100644 From b4ceb83d760e7f58eed7d6785c81bece01c29662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 23 Aug 2020 12:54:39 +0200 Subject: [PATCH 110/411] MakeHeader.py.in: remove unused import --- scripts/MakeHeader.py.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/MakeHeader.py.in b/scripts/MakeHeader.py.in index 9da6685ab..8a6887787 100644 --- a/scripts/MakeHeader.py.in +++ b/scripts/MakeHeader.py.in @@ -1,5 +1,5 @@ #!/usr/bin/env @PYTHON@ -import os, sys, string, io +import os, sys, io try: from StringIO import StringIO except ImportError: From 4e2b9f09654ff31602eaa294e0ac77b2f82ea3a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 25 Aug 2020 12:01:54 +0200 Subject: [PATCH 111/411] Avoid shadowing warnings --- Action.c | 14 +++++++------- linux/Battery.c | 26 +++++++++++++------------- linux/LinuxProcessList.c | 6 +++--- linux/Platform.c | 8 ++++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Action.c b/Action.c index 645739389..a7747f52c 100644 --- a/Action.c +++ b/Action.c @@ -316,17 +316,17 @@ static Htop_Reaction actionSetAffinity(State* st) { Process* p = (Process*) Panel_getSelected(panel); if (!p) return HTOP_OK; - Affinity* affinity = Affinity_get(p, st->pl); - if (!affinity) return HTOP_OK; - Panel* affinityPanel = AffinityPanel_new(st->pl, affinity); - Affinity_delete(affinity); + Affinity* affinity1 = Affinity_get(p, st->pl); + if (!affinity1) return HTOP_OK; + Panel* affinityPanel = AffinityPanel_new(st->pl, affinity1); + Affinity_delete(affinity1); void* set = Action_pickFromVector(st, affinityPanel, 15, true); if (set) { - Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL); + Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity2 }, NULL); if (!ok) beep(); - Affinity_delete(affinity); + Affinity_delete(affinity2); } Panel_delete((Object*)affinityPanel); #endif diff --git a/linux/Battery.c b/linux/Battery.c index 7a1c81636..4014a5000 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -64,7 +64,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short } char* line = NULL; - for (unsigned short int i = 0; i < lineNum; i++) { + for (unsigned short int j = 0; j < lineNum; j++) { free(line); line = String_readLine(file); if (!line) break; @@ -194,26 +194,26 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { const char filePath[50]; xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); - int fd = open(filePath, O_RDONLY); - if (fd == -1) + int fd1 = open(filePath, O_RDONLY); + if (fd1 == -1) continue; char type[8]; - ssize_t typelen = xread(fd, type, 7); - close(fd); + ssize_t typelen = xread(fd1, type, 7); + close(fd1); if (typelen < 1) continue; if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') { xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); - int fd = open(filePath, O_RDONLY); - if (fd == -1) { + int fd2 = open(filePath, O_RDONLY); + if (fd2 == -1) { closedir(dir); return; } char buffer[1024]; - ssize_t buflen = xread(fd, buffer, 1023); - close(fd); + ssize_t buflen = xread(fd2, buffer, 1023); + close(fd2); if (buflen < 1) { closedir(dir); return; @@ -259,18 +259,18 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { } xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); - int fd = open(filePath, O_RDONLY); - if (fd == -1) { + int fd3 = open(filePath, O_RDONLY); + if (fd3 == -1) { closedir(dir); return; } char buffer[2] = ""; for(;;) { - ssize_t res = read(fd, buffer, 1); + ssize_t res = read(fd3, buffer, 1); if (res == -1 && errno == EINTR) continue; break; } - close(fd); + close(fd3); if (buffer[0] == '0') { *isOnAC = AC_ABSENT; } else if (buffer[0] == '1') { diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 0d25e365a..6d3d03486 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1227,9 +1227,9 @@ static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { (sscanf(buffer, "processor: %d", &cpuid) == 1) ) { if (cpuid < 0 || cpuid > (cpus - 1)) { - char buffer[64]; - xSnprintf(buffer, sizeof(buffer), PROCCPUINFOFILE " contains out-of-range CPU number %d", cpuid); - CRT_fatalError(buffer); + char tmpbuffer[64]; + xSnprintf(tmpbuffer, sizeof(tmpbuffer), PROCCPUINFOFILE " contains out-of-range CPU number %d", cpuid); + CRT_fatalError(tmpbuffer); } } else if ( (sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) || diff --git a/linux/Platform.c b/linux/Platform.c index 10311a2d0..0f59fed65 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -94,12 +94,12 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) { LinuxProcess* p = (LinuxProcess*) Panel_getSelected(panel); if (!p) return HTOP_OK; - IOPriority ioprio = p->ioPriority; - Panel* ioprioPanel = IOPriorityPanel_new(ioprio); + IOPriority ioprio1 = p->ioPriority; + Panel* ioprioPanel = IOPriorityPanel_new(ioprio1); void* set = Action_pickFromVector(st, ioprioPanel, 21, true); if (set) { - IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio }, NULL); + IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio2 }, NULL); if (!ok) beep(); } From fc4f74aa47b0c15de3fb7d08e8aed7a2a5e086fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 25 Aug 2020 11:56:26 +0200 Subject: [PATCH 112/411] ci: add clang build --- .github/workflows/ci.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb7fb0a8e..5482d1eb1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,29 @@ jobs: - name: Build run: make - name: Distcheck - run: make distcheck + run: make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror + + build-ubuntu-clang-latest: + runs-on: ubuntu-latest + env: + CC: clang-10 + steps: + - uses: actions/checkout@v2 + - name: install clang repo + run: | + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key 2>/dev/null | sudo apt-key add - + sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main' -y + sudo apt-get update -q + - name: Install Dependencies + run: sudo apt-get install clang-10 libncursesw5-dev + - name: Bootstrap + run: ./autogen.sh + - name: Configure + run: ./configure --enable-werror + - name: Build + run: make + - name: Distcheck + run: make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror whitespace_check: runs-on: ubuntu-latest From 728b04bbb5667291f1e56058240fcd7e03cbfe74 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Wed, 26 Aug 2020 10:15:00 +1000 Subject: [PATCH 113/411] Merge branch 'ci-hwloc-job' of https://github.com/bertwesarg/htop into bertwesarg-ci-hwloc-job --- Action.c | 5 +- AffinityPanel.c | 399 +++++++++++++++++++++++++++++++++++++++--- AffinityPanel.h | 23 ++- CRT.c | 68 ++++--- CRT.h | 28 ++- CheckItem.c | 7 +- DisplayOptionsPanel.c | 3 + Panel.c | 8 + Panel.h | 2 + ProcessList.c | 19 +- Settings.c | 13 ++ Settings.h | 3 + Vector.c | 12 ++ Vector.h | 2 + 14 files changed, 529 insertions(+), 63 deletions(-) diff --git a/Action.c b/Action.c index a7747f52c..363c2b984 100644 --- a/Action.c +++ b/Action.c @@ -318,10 +318,11 @@ static Htop_Reaction actionSetAffinity(State* st) { if (!p) return HTOP_OK; Affinity* affinity1 = Affinity_get(p, st->pl); if (!affinity1) return HTOP_OK; - Panel* affinityPanel = AffinityPanel_new(st->pl, affinity1); + int width; + Panel* affinityPanel = AffinityPanel_new(st->pl, affinity1, &width); Affinity_delete(affinity1); - void* set = Action_pickFromVector(st, affinityPanel, 15, true); + void* set = Action_pickFromVector(st, affinityPanel, width, true); if (set) { Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl); bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity2 }, NULL); diff --git a/AffinityPanel.c b/AffinityPanel.c index d9f1612bd..7accb2ab1 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -8,69 +8,416 @@ in the source distribution for its full text. #include "AffinityPanel.h" #include "CRT.h" -#include "CheckItem.h" +#include "Vector.h" #include #include +#ifdef HAVE_LIBHWLOC +#include +#endif + /*{ #include "Panel.h" #include "Affinity.h" #include "ProcessList.h" -#include "ListItem.h" + }*/ -static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) { - CheckItem* selected = (CheckItem*) Panel_getSelected(this); +typedef struct MaskItem_ { + Object super; + const char* text; + const char* indent; + int value; /* tri-state: 0 - off, 1 - some set, 2 - all set */ + int sub_tree; /* tri-state: 0 - no sub-tree, 1 - open sub-tree, 2 - closed sub-tree */ + Vector *children; + #ifdef HAVE_LIBHWLOC + bool ownCpuset; + hwloc_bitmap_t cpuset; + #else + int cpu; + #endif +} MaskItem; + +static void MaskItem_delete(Object* cast) { + MaskItem* this = (MaskItem*) cast; + free((void*)this->text); + if (this->indent) + free((void*)this->indent); + Vector_delete(this->children); + #ifdef HAVE_LIBHWLOC + if (this->ownCpuset) + hwloc_bitmap_free(this->cpuset); + #endif + free(this); +} + +static void MaskItem_display(Object* cast, RichString* out) { + MaskItem* this = (MaskItem*)cast; + assert (this != NULL); + if (this->value == 2) + RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_FULL]); + else if (this->value == 1) + RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_PARTIAL]); + else + RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_NONE]); + RichString_append(out, CRT_colors[CHECK_TEXT], " "); + if (this->indent) + RichString_append(out, CRT_colors[PROCESS_TREE], this->indent); + if (this->sub_tree) { + RichString_append(out, CRT_colors[PROCESS_TREE], + this->sub_tree == 1 + ? CRT_collapStr[COLLAP_STR_OPEN] + : CRT_collapStr[COLLAP_STR_CLOSED]); + RichString_append(out, CRT_colors[CHECK_TEXT], " "); + } + RichString_append(out, CRT_colors[CHECK_TEXT], this->text); +} + +static ObjectClass MaskItem_class = { + .display = MaskItem_display, + .delete = MaskItem_delete +}; + +#ifdef HAVE_LIBHWLOC + +static MaskItem* MaskItem_newMask(const char* text, const char* indent, hwloc_bitmap_t cpuset, bool owner) { + MaskItem* this = AllocThis(MaskItem); + this->text = xStrdup(text); + this->indent = xStrdup(indent); + this->value = 0; + this->ownCpuset = owner; + this->cpuset = cpuset; + this->sub_tree = hwloc_bitmap_weight(cpuset) > 1 ? 1 : 0; + this->children = Vector_new(Class(MaskItem), true, DEFAULT_SIZE); + return this; +} + +#endif + +static MaskItem* MaskItem_newSingleton(const char* text, int cpu, bool isSet) { + MaskItem* this = AllocThis(MaskItem); + this->text = xStrdup(text); + this->indent = NULL; + this->sub_tree = 0; + this->children = Vector_new(Class(MaskItem), true, DEFAULT_SIZE); + + #ifdef HAVE_LIBHWLOC + this->ownCpuset = true; + this->cpuset = hwloc_bitmap_alloc(); + hwloc_bitmap_set(this->cpuset, cpu); + (void)isSet; + #else + this->cpu = cpu; + #endif + this->value = 2 * isSet; + + return this; +} + +typedef struct AffinityPanel_ { + Panel super; + ProcessList* pl; + bool topoView; + Vector *cpuids; + unsigned width; + + #ifdef HAVE_LIBHWLOC + MaskItem *topoRoot; + hwloc_const_cpuset_t allCpuset; + hwloc_bitmap_t workCpuset; + #endif +} AffinityPanel; + +static void AffinityPanel_delete(Object* cast) { + AffinityPanel* this = (AffinityPanel*) cast; + Panel* super = (Panel*) this; + Panel_done(super); + Vector_delete(this->cpuids); + #ifdef HAVE_LIBHWLOC + hwloc_bitmap_free(this->workCpuset); + MaskItem_delete((Object*) this->topoRoot); + #endif + free(this); +} + +#ifdef HAVE_LIBHWLOC + +static void AffinityPanel_updateItem(AffinityPanel* this, MaskItem* item) { + Panel* super = (Panel*) this; + + item->value = hwloc_bitmap_isincluded(item->cpuset, this->workCpuset) ? 2 : + hwloc_bitmap_intersects(item->cpuset, this->workCpuset) ? 1 : 0; + + Panel_add(super, (Object*) item); +} + +static void AffinityPanel_updateTopo(AffinityPanel* this, MaskItem* item) { + AffinityPanel_updateItem(this, item); + + if (item->sub_tree == 2) + return; + + for (int i = 0; i < Vector_size(item->children); i++) + AffinityPanel_updateTopo(this, (MaskItem*) Vector_get(item->children, i)); +} + +#endif + +static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) { + Panel* super = (Panel*) this; + + FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : ""); + FunctionBar_draw(super->currentBar, NULL); + + int oldSelected = Panel_getSelectedIndex(super); + Panel_prune(super); + + #ifdef HAVE_LIBHWLOC + if (this->topoView) + AffinityPanel_updateTopo(this, this->topoRoot); + else { + for (int i = 0; i < Vector_size(this->cpuids); i++) + AffinityPanel_updateItem(this, (MaskItem*) Vector_get(this->cpuids, i)); + } + #else + Panel_splice(super, this->cpuids); + #endif + + if (keepSelected) + Panel_setSelected(super, oldSelected); + + super->needsRedraw = true; +} + +static HandlerResult AffinityPanel_eventHandler(Panel* super, int ch) { + AffinityPanel* this = (AffinityPanel*) super; + HandlerResult result = IGNORED; + MaskItem* selected = (MaskItem*) Panel_getSelected(super); + bool keepSelected = true; + switch(ch) { case KEY_MOUSE: case KEY_RECLICK: case ' ': - CheckItem_set(selected, ! (CheckItem_get(selected)) ); - return HANDLED; + #ifdef HAVE_LIBHWLOC + if (selected->value == 2) { + /* Item was selected, so remove this mask from the top cpuset. */ + hwloc_bitmap_andnot(this->workCpuset, this->workCpuset, selected->cpuset); + selected->value = 0; + } else { + /* Item was not or only partial selected, so set all bits from this object + in the top cpuset. */ + hwloc_bitmap_or(this->workCpuset, this->workCpuset, selected->cpuset); + selected->value = 2; + } + #else + selected->value = 2 * !selected->value; /* toggle between 0 and 2 */ + #endif + + result = HANDLED; + break; + + #ifdef HAVE_LIBHWLOC + + case KEY_F(1): + hwloc_bitmap_copy(this->workCpuset, this->allCpuset); + result = HANDLED; + break; + + case KEY_F(2): + this->topoView = !this->topoView; + keepSelected = false; + + result = HANDLED; + break; + + case KEY_F(3): + case '-': + case '+': + if (selected->sub_tree) + selected->sub_tree = 1 + !(selected->sub_tree - 1); /* toggle between 1 and 2 */ + + result = HANDLED; + break; + + #endif + case 0x0a: case 0x0d: case KEY_ENTER: - return BREAK_LOOP; + result = BREAK_LOOP; + break; + } + + if (HANDLED == result) + AffinityPanel_update(this, keepSelected); + + return result; +} + +#ifdef HAVE_LIBHWLOC + +static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem *parent) { + const char* type_name = hwloc_obj_type_string(obj->type); + const char* index_prefix = " #"; + unsigned depth = obj->depth; + unsigned index = obj->logical_index; + size_t off = 0, left = 10 * depth; + char buf[64], indent_buf[left + 1]; + + if (obj->type == HWLOC_OBJ_PU) { + index = Settings_cpuId(this->pl->settings, obj->os_index); + type_name = "CPU"; + index_prefix = ""; + } + + indent_buf[0] = '\0'; + if (depth > 0) { + for (unsigned i = 1; i < depth; i++) { + xSnprintf(&indent_buf[off], left, "%s ", (indent & (1u << i)) ? CRT_treeStr[TREE_STR_VERT] : " "); + size_t len = strlen(&indent_buf[off]); + off += len, left -= len; + } + xSnprintf(&indent_buf[off], left, "%s%s ", + obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND], + CRT_treeStr[TREE_STR_HORZ]); + size_t len = strlen(&indent_buf[off]); + off += len, left -= len; + } + + xSnprintf(buf, 64, "%s%s%u", type_name, index_prefix, index); + + MaskItem *item = MaskItem_newMask(buf, indent_buf, obj->complete_cpuset, false); + if (parent) + Vector_add(parent->children, item); + + if (item->sub_tree && parent && parent->sub_tree == 1) { + /* if obj is fully included or fully excluded, collapse the item */ + hwloc_bitmap_t result = hwloc_bitmap_alloc(); + hwloc_bitmap_and(result, obj->complete_cpuset, this->workCpuset); + int weight = hwloc_bitmap_weight(result); + hwloc_bitmap_free(result); + if (weight == 0 || weight == (hwloc_bitmap_weight(this->workCpuset) + hwloc_bitmap_weight(obj->complete_cpuset))) + item->sub_tree = 2; + } + + /* "[x] " + "|- " * depth + ("[+] ")? + name */ + unsigned width = (CRT_utf8 ? 2 : 4) + 3 * depth + (item->sub_tree ? (CRT_utf8 ? 2 : 4) : 0) + strlen(buf); + if (width > this->width) + this->width = width; + + return item; +} + +static MaskItem *AffinityPanel_buildTopology(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem *parent) { + MaskItem *item = AffinityPanel_addObject(this, obj, indent, parent); + if (obj->next_sibling) { + indent |= (1u << obj->depth); + } else { + indent &= ~(1u << obj->depth); } - return IGNORED; + for (unsigned i = 0; i < obj->arity; i++) + AffinityPanel_buildTopology(this, obj->children[i], indent, item); + + return parent == NULL ? item : NULL; } +#endif + PanelClass AffinityPanel_class = { .super = { .extends = Class(Panel), - .delete = Panel_delete + .delete = AffinityPanel_delete }, .eventHandler = AffinityPanel_eventHandler }; -Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) { - Panel* this = Panel_new(1, 1, 1, 1, true, Class(CheckItem), FunctionBar_newEnterEsc("Set ", "Cancel ")); - Object_setClass(this, Class(AffinityPanel)); +static const char* const AffinityPanelFunctions[] = { + "Set ", + "Cancel ", + #ifdef HAVE_LIBHWLOC + "All", + "Topology", + " ", + #endif + NULL +}; +static const char* const AffinityPanelKeys[] = {"Enter", "Esc", "F1", "F2", "F3"}; +static const int AffinityPanelEvents[] = {13, 27, KEY_F(1), KEY_F(2), KEY_F(3)}; + +Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) { + AffinityPanel* this = AllocThis(AffinityPanel); + Panel* super = (Panel*) this; + Panel_init(super, 1, 1, 1, 1, Class(MaskItem), false, FunctionBar_new(AffinityPanelFunctions, AffinityPanelKeys, AffinityPanelEvents)); + + this->pl = pl; + this->width = 15; + + this->cpuids = Vector_new(Class(MaskItem), true, DEFAULT_SIZE); + + #ifdef HAVE_LIBHWLOC + this->topoView = pl->settings->topologyAffinity; + #else + this->topoView = false; + #endif + + #ifdef HAVE_LIBHWLOC + this->allCpuset = hwloc_topology_get_complete_cpuset(pl->topology); + this->workCpuset = hwloc_bitmap_alloc(); + #endif + + Panel_setHeader(super, "Use CPUs:"); - Panel_setHeader(this, "Use CPUs:"); int curCpu = 0; for (int i = 0; i < pl->cpuCount; i++) { - char number[10]; - xSnprintf(number, 9, "%d", Settings_cpuId(pl->settings, i)); - bool mode; + char number[16]; + xSnprintf(number, 9, "CPU %d", Settings_cpuId(pl->settings, i)); + unsigned width = 4 + strlen(number); + if (width > this->width) + this->width = width; + + bool isSet = false; if (curCpu < affinity->used && affinity->cpus[curCpu] == i) { - mode = true; + #ifdef HAVE_LIBHWLOC + hwloc_bitmap_set(this->workCpuset, i); + #endif + isSet = true; curCpu++; - } else { - mode = false; } - Panel_add(this, (Object*) CheckItem_newByVal(xStrdup(number), mode)); + + MaskItem* cpuItem = MaskItem_newSingleton(number, i, isSet); + Vector_add(this->cpuids, (Object*) cpuItem); } - return this; + + #ifdef HAVE_LIBHWLOC + this->topoRoot = AffinityPanel_buildTopology(this, hwloc_get_root_obj(pl->topology), 0, NULL); + #endif + + if (width) + *width = this->width; + + AffinityPanel_update(this, false); + + return super; } -Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl) { +Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) { + AffinityPanel* this = (AffinityPanel*) super; Affinity* affinity = Affinity_new(pl); - int size = Panel_size(this); - for (int i = 0; i < size; i++) { - if (CheckItem_get((CheckItem*)Panel_get(this, i))) - Affinity_add(affinity, i); + + #ifdef HAVE_LIBHWLOC + int i; + hwloc_bitmap_foreach_begin(i, this->workCpuset) + Affinity_add(affinity, i); + hwloc_bitmap_foreach_end(); + #else + for (int i = 0; i < this->pl->cpuCount; i++) { + MaskItem* item = (MaskItem*)Vector_get(this->cpuids, i); + if (item->value) + Affinity_add(affinity, item->cpu); } + #endif + return affinity; } diff --git a/AffinityPanel.h b/AffinityPanel.h index 3a9c78078..54d4f24cf 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -9,15 +9,32 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#ifdef HAVE_LIBHWLOC +#endif + #include "Panel.h" #include "Affinity.h" #include "ProcessList.h" -#include "ListItem.h" + + + +#ifdef HAVE_LIBHWLOC + +#endif + + +#ifdef HAVE_LIBHWLOC + +#endif + +#ifdef HAVE_LIBHWLOC + +#endif extern PanelClass AffinityPanel_class; -extern Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity); +extern Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width); -extern Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl); +extern Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl); #endif diff --git a/CRT.c b/CRT.c index 35b285f79..869573e51 100644 --- a/CRT.c +++ b/CRT.c @@ -59,6 +59,19 @@ typedef enum TreeStr_ { TREE_STR_COUNT } TreeStr; +typedef enum CheckStr_ { + CHECK_STR_NONE, + CHECK_STR_PARTIAL, + CHECK_STR_FULL, + CHECK_STR_COUNT +} CheckStr; + +typedef enum CollapStr_ { + COLLAP_STR_OPEN, + COLLAP_STR_CLOSED, + COLLAP_STR_COUNT +} CollapStr; + typedef enum ColorSchemes_ { COLORSCHEME_DEFAULT = 0, COLORSCHEME_MONOCHROME = 1, @@ -113,7 +126,6 @@ typedef enum ColorElements_ { LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE, - CHECK_BOX, CHECK_MARK, CHECK_TEXT, CLOCK, @@ -159,6 +171,17 @@ const char *CRT_treeStrAscii[TREE_STR_COUNT] = { "-", // TREE_STR_SHUT }; +const char *CRT_checkStrAscii[CHECK_STR_COUNT] = { + "[ ]", // CHECK_STR_NONE + "[o]", // CHECK_STR_PARTIAL + "[x]", // CHECK_STR_FULL +}; + +const char *CRT_collapStrAscii[COLLAP_STR_COUNT] = { + "[-]", // COLLAP_STR_OPEN + "[+]", // COLLAP_STR_CLOSED +}; + #ifdef HAVE_LIBNCURSESW const char *CRT_treeStrUtf8[TREE_STR_COUNT] = { @@ -171,12 +194,27 @@ const char *CRT_treeStrUtf8[TREE_STR_COUNT] = { "\xe2\x94\x80", // TREE_STR_SHUT ─ }; -bool CRT_utf8 = false; +const char *CRT_checkStrUtf8[CHECK_STR_COUNT] = { + "\xe2\x98\x90", // CHECK_STR_NONE ☐ + "\xe2\x98\x92", // CHECK_STR_PARTIAL ☒ + "\xe2\x98\x91", // CHECK_STR_FULL ☑ +}; + +const char *CRT_collapStrUtf8[COLLAP_STR_COUNT] = { + "\xe2\x8a\x9f", // COLLAP_STR_OPEN ⊟ + "\xe2\x8a\x9e", // COLLAP_STR_CLOSED ⊞ +}; #endif +bool CRT_utf8 = false; + const char **CRT_treeStr = CRT_treeStrAscii; +const char **CRT_checkStr = CRT_checkStrAscii; + +const char **CRT_collapStr = CRT_collapStrAscii; + static bool CRT_hasColors; int CRT_delay = 0; @@ -229,8 +267,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Black), [CLOCK] = A_BOLD, - [CHECK_BOX] = ColorPair(Cyan,Black), - [CHECK_MARK] = A_BOLD, + [CHECK_MARK] = A_BOLD | ColorPair(Cyan,Black), [CHECK_TEXT] = A_NORMAL, [HOSTNAME] = A_BOLD, [CPU_NICE] = ColorPair(Blue,Black), @@ -298,8 +335,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD, [CLOCK] = A_BOLD, - [CHECK_BOX] = A_BOLD, - [CHECK_MARK] = A_NORMAL, + [CHECK_MARK] = A_BOLD, [CHECK_TEXT] = A_NORMAL, [HOSTNAME] = A_BOLD, [CPU_NICE] = A_NORMAL, @@ -367,7 +403,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = ColorPair(Black,White), [HELP_BOLD] = ColorPair(Blue,White), [CLOCK] = ColorPair(Black,White), - [CHECK_BOX] = ColorPair(Blue,White), [CHECK_MARK] = ColorPair(Black,White), [CHECK_TEXT] = ColorPair(Black,White), [HOSTNAME] = ColorPair(Black,White), @@ -436,7 +471,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = ColorPair(White,Black), [HELP_BOLD] = ColorPair(Blue,Black), [CLOCK] = ColorPair(White,Black), - [CHECK_BOX] = ColorPair(Blue,Black), [CHECK_MARK] = ColorPair(Black,Black), [CHECK_TEXT] = ColorPair(Black,Black), [HOSTNAME] = ColorPair(White,Black), @@ -505,8 +539,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD | ColorPair(White,Blue), [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Blue), [CLOCK] = ColorPair(White,Blue), - [CHECK_BOX] = ColorPair(Cyan,Blue), - [CHECK_MARK] = A_BOLD | ColorPair(White,Blue), + [CHECK_MARK] = A_BOLD | ColorPair(Cyan,Blue), [CHECK_TEXT] = A_NORMAL | ColorPair(White,Blue), [HOSTNAME] = ColorPair(White,Blue), [CPU_NICE] = A_BOLD | ColorPair(Cyan,Blue), @@ -574,7 +607,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Black), [CLOCK] = ColorPair(Green,Black), - [CHECK_BOX] = ColorPair(Green,Black), [CHECK_MARK] = A_BOLD | ColorPair(Green,Black), [CHECK_TEXT] = ColorPair(Cyan,Black), [HOSTNAME] = ColorPair(Green,Black), @@ -731,17 +763,13 @@ void CRT_init(int delay, int colorScheme) { setlocale(LC_CTYPE, ""); #ifdef HAVE_LIBNCURSESW - if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) + if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) { CRT_utf8 = true; - else - CRT_utf8 = false; -#endif - - CRT_treeStr = -#ifdef HAVE_LIBNCURSESW - CRT_utf8 ? CRT_treeStrUtf8 : + CRT_treeStr = CRT_treeStrUtf8; + CRT_checkStr = CRT_checkStrUtf8; + CRT_collapStr = CRT_collapStrUtf8; + } #endif - CRT_treeStrAscii; #if NCURSES_MOUSE_VERSION > 1 mousemask(BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL); diff --git a/CRT.h b/CRT.h index 80022f705..5fb2f09cd 100644 --- a/CRT.h +++ b/CRT.h @@ -47,6 +47,19 @@ typedef enum TreeStr_ { TREE_STR_COUNT } TreeStr; +typedef enum CheckStr_ { + CHECK_STR_NONE, + CHECK_STR_PARTIAL, + CHECK_STR_FULL, + CHECK_STR_COUNT +} CheckStr; + +typedef enum CollapStr_ { + COLLAP_STR_OPEN, + COLLAP_STR_CLOSED, + COLLAP_STR_COUNT +} CollapStr; + typedef enum ColorSchemes_ { COLORSCHEME_DEFAULT = 0, COLORSCHEME_MONOCHROME = 1, @@ -101,7 +114,6 @@ typedef enum ColorElements_ { LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE, - CHECK_BOX, CHECK_MARK, CHECK_TEXT, CLOCK, @@ -138,16 +150,28 @@ extern void CRT_handleSIGSEGV(int sgn); extern const char *CRT_treeStrAscii[TREE_STR_COUNT]; +extern const char *CRT_checkStrAscii[CHECK_STR_COUNT]; + +extern const char *CRT_collapStrAscii[COLLAP_STR_COUNT]; + #ifdef HAVE_LIBNCURSESW extern const char *CRT_treeStrUtf8[TREE_STR_COUNT]; -extern bool CRT_utf8; +extern const char *CRT_checkStrUtf8[CHECK_STR_COUNT]; + +extern const char *CRT_collapStrUtf8[COLLAP_STR_COUNT]; #endif +extern bool CRT_utf8; + extern const char **CRT_treeStr; +extern const char **CRT_checkStr; + +extern const char **CRT_collapStr; + extern int CRT_delay; extern int* CRT_colors; diff --git a/CheckItem.c b/CheckItem.c index 910981e86..a045d2ffd 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -35,12 +35,11 @@ static void CheckItem_delete(Object* cast) { static void CheckItem_display(Object* cast, RichString* out) { CheckItem* this = (CheckItem*)cast; assert (this != NULL); - RichString_write(out, CRT_colors[CHECK_BOX], "["); if (CheckItem_get(this)) - RichString_append(out, CRT_colors[CHECK_MARK], "x"); + RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_FULL]); else - RichString_append(out, CRT_colors[CHECK_MARK], " "); - RichString_append(out, CRT_colors[CHECK_BOX], "] "); + RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_NONE]); + RichString_append(out, CRT_colors[CHECK_TEXT], " "); RichString_append(out, CRT_colors[CHECK_TEXT], this->text); } diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 0f44acc22..1222d8235 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -100,5 +100,8 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU percentage numerically"), &(settings->showCPUUsage))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU frequency"), &(settings->showCPUFrequency))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Enable the mouse"), &(settings->enableMouse))); + #ifdef HAVE_LIBHWLOC + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show topology when selecting affinity by default"), &(settings->topologyAffinity))); + #endif return this; } diff --git a/Panel.c b/Panel.c index fc4fa3c2d..348fd2381 100644 --- a/Panel.c +++ b/Panel.c @@ -264,6 +264,14 @@ void Panel_setSelected(Panel* this, int selected) { } } +void Panel_splice(Panel *this, Vector* from) { + assert (this != NULL); + assert (from != NULL); + + Vector_splice(this->items, from); + this->needsRedraw = true; +} + void Panel_draw(Panel* this, bool focus) { assert (this != NULL); diff --git a/Panel.h b/Panel.h index b7480c6ba..4b517f311 100644 --- a/Panel.h +++ b/Panel.h @@ -119,6 +119,8 @@ extern void Panel_setSelected(Panel* this, int selected); extern void Panel_draw(Panel* this, bool focus); +extern void Panel_splice(Panel *this, Vector* from); + extern bool Panel_onKey(Panel* this, int key); extern HandlerResult Panel_selectByTyping(Panel* this, int ch); diff --git a/ProcessList.c b/ProcessList.c index edbc114cb..36b494e29 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -93,12 +93,19 @@ ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* #ifdef HAVE_LIBHWLOC this->topologyOk = false; - int topoErr = hwloc_topology_init(&this->topology); - if (topoErr == 0) { - topoErr = hwloc_topology_load(this->topology); - } - if (topoErr == 0) { - this->topologyOk = true; + if (hwloc_topology_init(&this->topology) == 0) { + this->topologyOk = + #if HWLOC_API_VERSION < 0x00020000 + /* try to ignore the top-level machine object type */ + 0 == hwloc_topology_ignore_type_keep_structure(this->topology, HWLOC_OBJ_MACHINE) && + /* ignore caches, which don't add structure */ + 0 == hwloc_topology_ignore_type_keep_structure(this->topology, HWLOC_OBJ_CORE) && + 0 == hwloc_topology_ignore_type_keep_structure(this->topology, HWLOC_OBJ_CACHE) && + 0 == hwloc_topology_set_flags(this->topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM) && + #else + 0 == hwloc_topology_set_all_types_filter(this->topology, HWLOC_TYPE_FILTER_KEEP_STRUCTURE) && + #endif + 0 == hwloc_topology_load(this->topology); } #endif diff --git a/Settings.c b/Settings.c index 6197241f9..81d547bed 100644 --- a/Settings.c +++ b/Settings.c @@ -62,6 +62,9 @@ typedef struct Settings_ { bool headerMargin; bool enableMouse; bool vimMode; + #ifdef HAVE_LIBHWLOC + bool topologyAffinity; + #endif bool changed; } Settings; @@ -256,6 +259,10 @@ static bool Settings_read(Settings* this, const char* fileName) { didReadMeters = true; } else if (String_eq(option[0], "vim_mode")) { this->vimMode = atoi(option[1]); + #ifdef HAVE_LIBHWLOC + } else if (String_eq(option[0], "topology_affinity")) { + this->topologyAffinity = !!atoi(option[1]); + #endif } String_freeArray(option); } @@ -336,6 +343,9 @@ bool Settings_write(Settings* this) { fprintf(fd, "right_meters="); writeMeters(this, fd, 1); fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1); fprintf(fd, "vim_mode=%d\n", (int) this->vimMode); + #ifdef HAVE_LIBHWLOC + fprintf(fd, "topology_affinity=%d\n", (int) this->topologyAffinity); + #endif fclose(fd); return true; } @@ -362,6 +372,9 @@ Settings* Settings_new(int cpuCount) { this->cpuCount = cpuCount; this->showProgramPath = true; this->highlightThreads = true; + #ifdef HAVE_LIBHWLOC + this->topologyAffinity = false; + #endif this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); // TODO: turn 'fields' into a Vector, diff --git a/Settings.h b/Settings.h index 89300951e..f38b8ecd4 100644 --- a/Settings.h +++ b/Settings.h @@ -53,6 +53,9 @@ typedef struct Settings_ { bool headerMargin; bool enableMouse; bool vimMode; + #ifdef HAVE_LIBHWLOC + bool topologyAffinity; + #endif bool changed; } Settings; diff --git a/Vector.c b/Vector.c index 819d9863d..b5e774466 100644 --- a/Vector.c +++ b/Vector.c @@ -335,3 +335,15 @@ inline int Vector_indexOf(Vector* this, void* search_, Object_Compare compare) { } return -1; } + +void Vector_splice(Vector* this, Vector* from) { + assert(Vector_isConsistent(this)); + assert(Vector_isConsistent(from)); + assert(!(this->owner && from->owner)); + + int olditmes = this->items; + this->items += from->items; + Vector_checkArraySize(this); + for (int j = 0; j < from->items; j++) + this->array[olditmes + j] = from->array[j]; +} diff --git a/Vector.h b/Vector.h index b48c83636..0d9f1c2c8 100644 --- a/Vector.h +++ b/Vector.h @@ -88,4 +88,6 @@ extern void Vector_add(Vector* this, void* data_); extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare); +void Vector_splice(Vector* this, Vector* from); + #endif From df7e4fcdc0f36d2d1fc3941c0e68a72620c68a0f Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Wed, 26 Aug 2020 10:44:22 +1000 Subject: [PATCH 114/411] Update changelog with Berts latest addition --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index da91c074c..e76249110 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,8 @@ What's new in version 3.0.0 (thanks to Arnav Singh) * Update Linux sysfs battery discovery for recent kernels (thanks to @smattie) +* Add hardware topology information in the affinity panel + (thanks to Bert Wesarg) * Add timestamp reporting to the strace screen (thanks to Mario Harjac) * Add simple, optional vim key mapping mode From 94b8c2e714e740639f0c345e9df5b6de7cbe966a Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Wed, 26 Aug 2020 22:03:04 +0200 Subject: [PATCH 115/411] fix width of `AffinitPanel` The panel size of 15 includes the gap to the next panel, thus use 14 as the minimum size and let the caller of `AffinityPanel_new` handle the gap. --- Action.c | 1 + AffinityPanel.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Action.c b/Action.c index 363c2b984..d9cc5abfb 100644 --- a/Action.c +++ b/Action.c @@ -320,6 +320,7 @@ static Htop_Reaction actionSetAffinity(State* st) { if (!affinity1) return HTOP_OK; int width; Panel* affinityPanel = AffinityPanel_new(st->pl, affinity1, &width); + width += 1; /* we add a gap between the panels */ Affinity_delete(affinity1); void* set = Action_pickFromVector(st, affinityPanel, width, true); diff --git a/AffinityPanel.c b/AffinityPanel.c index 7accb2ab1..e95b381ed 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -352,7 +352,9 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) { Panel_init(super, 1, 1, 1, 1, Class(MaskItem), false, FunctionBar_new(AffinityPanelFunctions, AffinityPanelKeys, AffinityPanelEvents)); this->pl = pl; - this->width = 15; + /* defaults to 15, this also includes the gap between the panels, + * but this will be added by the caller */ + this->width = 14; this->cpuids = Vector_new(Class(MaskItem), true, DEFAULT_SIZE); From b5e6952cc6edaf4d54478f5fb23712c85e148912 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 27 Aug 2020 10:42:40 +1000 Subject: [PATCH 116/411] Update link to Coverity project, still pending. --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 5e6575465..52c0bedb7 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ ![htop](https://htop.dev) [![CI](https://github.com/htop-dev/htop/workflows/CI/badge.svg)](https://github.com/htop-dev/htop/actions) -[![Coverity Scan Build Status](https://scan.coverity.com/projects/21617/badge.svg)](https://scan.coverity.com/projects/21617) +[![Coverity Scan Build Status](https://scan.coverity.com/projects/21665/badge.svg)](https://scan.coverity.com/projects/21665) [![Mailing List](https://img.shields.io/badge/Mailing%20List-htop-blue.svg)](https://groups.io/g/htop) [![IRC #htop](https://img.shields.io/badge/IRC-htop-blue.svg)](https://webchat.freenode.net/#htop) [![Github Release](https://img.shields.io/github/release/htop-dev/htop.svg)](https://github.com/htop-dev/htop/releases/latest) From f97fbd668a7606453d29dba9410f98bdd6f85edd Mon Sep 17 00:00:00 2001 From: Zach Dykstra Date: Fri, 28 Aug 2020 00:02:35 -0500 Subject: [PATCH 117/411] Normalize ZFS ARC caption Other captions take the form of LABEL:. This moves the uncompressed ZFS ARC caption into the same style. --- zfs/ZfsArcMeter.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index 8042555c1..8bd0f5d2d 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -60,7 +60,6 @@ static void ZfsArcMeter_display(Object* cast, RichString* out) { Meter* this = (Meter*)cast; if (this->values[5] > 0) { - RichString_write(out, CRT_colors[METER_TEXT], ":"); Meter_humanUnit(buffer, this->total, 50); RichString_append(out, CRT_colors[METER_VALUE], buffer); Meter_humanUnit(buffer, this->values[5], 50); @@ -100,5 +99,5 @@ MeterClass ZfsArcMeter_class = { .attributes = ZfsArcMeter_attributes, .name = "ZFSARC", .uiName = "ZFS ARC", - .caption = "ARC" + .caption = "ARC: " }; From b992d52bcf8ff8c51c847cd4bbf33a7db441dbe9 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Fri, 28 Aug 2020 16:57:21 +1000 Subject: [PATCH 118/411] Increae the size of sysfs power supply path buffers Resolves https://github.com/htop-dev/htop/issues/15 --- linux/Battery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/Battery.c b/linux/Battery.c index 4014a5000..a8784da06 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -107,7 +107,7 @@ static ACPresence procAcpiCheck() { if (entryName[0] != 'A') continue; - char statePath[50]; + char statePath[256]; xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName); FILE* file = fopen(statePath, "r"); if (!file) { @@ -191,7 +191,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { if (!dirEntry) break; char* entryName = (char *) dirEntry->d_name; - const char filePath[50]; + const char filePath[256]; xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); int fd1 = open(filePath, O_RDONLY); From 3ef5df25bc7178d49a4e18eb6b62f48811187def Mon Sep 17 00:00:00 2001 From: Redha Gouicem Date: Fri, 28 Aug 2020 12:15:32 +0200 Subject: [PATCH 119/411] always display frequency in MHz --- CPUMeter.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 6131a09d4..e09769cc3 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -65,18 +65,13 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT); double percent = Platform_setCPUValues(this, cpu); if (this->pl->settings->showCPUFrequency) { - /* Initial frequency is in MHz. Emit it as GHz if it's larger than 1000MHz */ double cpuFrequency = this->values[CPU_METER_FREQUENCY]; char unit = 'M'; char cpuFrequencyBuffer[16]; if (cpuFrequency < 0) { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); } else { - if (cpuFrequency > 1000) { - cpuFrequency /= 1000; - unit = 'G'; - } - xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.3f%cHz", cpuFrequency, unit); + xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.0f%cHz", cpuFrequency, unit); } if (this->pl->settings->showCPUUsage) { xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer); From 5bee9026651e4f2f07e524dce7c9d8da75eafa19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 11:54:50 +0200 Subject: [PATCH 120/411] Drop configure option --enable-proc Move to HTOP_LINUX, as --enable-proc implies my_htop_platform=linux, and the Linux features do not work without a proc fs. --- configure.ac | 7 ------- htop.c | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 18291b952..e46b6eba3 100644 --- a/configure.ac +++ b/configure.ac @@ -111,13 +111,6 @@ AC_SUBST(wextra_flag) # ---------------------------------------------------------------------- PROCDIR=/proc -AC_ARG_ENABLE(proc, [AS_HELP_STRING([--enable-proc], [use Linux-compatible proc filesystem])], enable_proc="yes", enable_proc="no") -if test "x$enable_proc" = xyes; then - # An enabled proc assumes we're emulating Linux. - my_htop_platform=linux - AC_DEFINE(HAVE_PROC, 1, [Define if using a Linux-compatible proc filesystem.]) -fi - AC_ARG_WITH(proc, [AS_HELP_STRING([--with-proc=DIR], [Location of a Linux-compatible proc filesystem (default=/proc).])], if test -n "$withval"; then diff --git a/htop.c b/htop.c index 7cdf4e42b..c7689c66b 100644 --- a/htop.c +++ b/htop.c @@ -200,7 +200,7 @@ int main(int argc, char** argv) { CommandLineSettings flags = parseArguments(argc, argv); // may exit() -#ifdef HAVE_PROC +#ifdef HTOP_LINUX if (access(PROCDIR, R_OK) != 0) { fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR); exit(1); From 979d00421454582173aa7caefcb86bd1684fd02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 11:56:07 +0200 Subject: [PATCH 121/411] Improve indent --- configure.ac | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index e46b6eba3..2e73f59ad 100644 --- a/configure.ac +++ b/configure.ac @@ -112,12 +112,11 @@ AC_SUBST(wextra_flag) PROCDIR=/proc AC_ARG_WITH(proc, [AS_HELP_STRING([--with-proc=DIR], [Location of a Linux-compatible proc filesystem (default=/proc).])], - -if test -n "$withval"; then - AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem]) - PROCDIR="$withval" -fi, -AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem])) + if test -n "$withval"; then + AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem]) + PROCDIR="$withval" + fi, + AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem])) if test "x$cross_compiling" = xno; then if test "x$enable_proc" = xyes; then From 3b084db1c46149e069e8c42053136505c59abb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 12:10:31 +0200 Subject: [PATCH 122/411] Print configured state --- configure.ac | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/configure.ac b/configure.ac index 2e73f59ad..b98dacc03 100644 --- a/configure.ac +++ b/configure.ac @@ -332,3 +332,20 @@ then echo "****************************************************************" echo "" fi + +AC_MSG_RESULT([ + ${PACKAGE_NAME} ${VERSION} + + platform: $my_htop_platform + proc directory: $PROCDIR + openvz: $enable_openvz + cgroup: $enable_cgroup + vserver: $enable_vserver + ancient vserver: $enable_ancient_vserver + taskstats: $enable_taskstats + unicode: $enable_unicode + linux affinity: $enable_linux_affinity + hwlock: $enable_hwloc + setuid: $enable_setuid + linux delay accounting: $enable_delayacct +]) From 3f5784a3f0639e8a8bd01e35619aa2eec462ee8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 12:19:58 +0200 Subject: [PATCH 123/411] Convert hwlock CI run to a full featured one --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b269bd92..d95d0af91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,20 +40,20 @@ jobs: - name: Distcheck run: make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror - build-ubuntu-latest-hwloc: + build-ubuntu-latest-full-featured: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install Dependencies - run: sudo apt-get install libncursesw5-dev libhwloc-dev + run: sudo apt-get install libncursesw5-dev libhwloc-dev libnl-3-dev libnl-genl-3-dev - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror --enable-hwloc + run: ./configure --enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-linux-affinity --enable-hwloc --enable-setuid --enable-delayacct - name: Build run: make - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-hwloc' + run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-linux-affinity --enable-hwloc --enable-setuid --enable-delayacct' whitespace_check: runs-on: ubuntu-latest From a48ce9d10383a34598d7b0c40bfdb56f775dfc38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 12:29:24 +0200 Subject: [PATCH 124/411] Really tell gcc to ignore return value of fscanf --- linux/LinuxProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6d3d03486..609b347c0 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -577,7 +577,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d FILE* file = fopen(filename, "r"); if (!file) return; - (void) fscanf(file, + (void)! fscanf(file, "%*32u %*32s %*1c %*32u %*32u %*32u %*32u %*32u %*32u %*32u " "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " From d9a5dd4b916636b5e7ba8631885427372f0cfcad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 14:24:40 +0200 Subject: [PATCH 125/411] Improve OOM output * Fix sort by adding cast * Shrink column size to 4 * Drop unnecessary maximum field width specifier in sscanf --- linux/LinuxProcess.c | 7 +++---- linux/LinuxProcessList.c | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 3a1504956..6bae98867 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -241,7 +241,7 @@ ProcessFieldData Process_fields[] = { #ifdef HAVE_CGROUP [CGROUP] = { .name = "CGROUP", .title = " CGROUP ", .description = "Which cgroup the process is in", .flags = PROCESS_FLAG_LINUX_CGROUP, }, #endif - [OOM] = { .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = PROCESS_FLAG_LINUX_OOM, }, + [OOM] = { .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = PROCESS_FLAG_LINUX_OOM, }, [IO_PRIORITY] = { .name = "IO_PRIORITY", .title = "IO ", .description = "I/O priority", .flags = PROCESS_FLAG_LINUX_IOPRIO, }, #ifdef HAVE_DELAYACCT [PERCENT_CPU_DELAY] = { .name = "PERCENT_CPU_DELAY", .title = "CPUD% ", .description = "CPU delay %", .flags = 0, }, @@ -264,7 +264,6 @@ ProcessPidColumn Process_pidColumns[] = { { .id = TGID, .label = "TGID" }, { .id = PGRP, .label = "PGRP" }, { .id = SESSION, .label = "SID" }, - { .id = OOM, .label = "OOM" }, { .id = 0, .label = NULL }, }; @@ -397,7 +396,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) #ifdef HAVE_CGROUP case CGROUP: xSnprintf(buffer, n, "%-10s ", lp->cgroup); break; #endif - case OOM: xSnprintf(buffer, n, Process_pidFormat, lp->oom); break; + case OOM: xSnprintf(buffer, n, "%4u ", lp->oom); break; case IO_PRIORITY: { int klass = IOPriority_class(lp->ioPriority); if (klass == IOPRIO_CLASS_NONE) { @@ -493,7 +492,7 @@ long LinuxProcess_compare(const void* v1, const void* v2) { return strcmp(p1->cgroup ? p1->cgroup : "", p2->cgroup ? p2->cgroup : ""); #endif case OOM: - return (p2->oom - p1->oom); + return ((long)p2->oom - (long)p1->oom); #ifdef HAVE_DELAYACCT case PERCENT_CPU_DELAY: return (p2->cpu_delay_percent > p1->cpu_delay_percent ? 1 : -1); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6d3d03486..01efe1b66 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -670,7 +670,7 @@ static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirn char buffer[PROC_LINE_LENGTH + 1]; if (fgets(buffer, PROC_LINE_LENGTH, file)) { unsigned int oom; - int ok = sscanf(buffer, "%32u", &oom); + int ok = sscanf(buffer, "%u", &oom); if (ok >= 1) { process->oom = oom; } From df41979afc58f372348a4f54244d30d771403dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 15:20:18 +0200 Subject: [PATCH 126/411] Ignore wmove return value Found by Coverity --- InfoScreen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InfoScreen.c b/InfoScreen.c index 93120006d..5c586bdd4 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -80,7 +80,7 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) { va_start(ap, fmt); attrset(CRT_colors[METER_TEXT]); mvhline(0, 0, ' ', COLS); - wmove(stdscr, 0, 0); + (void) wmove(stdscr, 0, 0); vw_printw(stdscr, fmt, ap); attrset(CRT_colors[DEFAULT_COLOR]); this->display->needsRedraw = true; From af84d3dfa9d217096c709bad2860689b89cc1c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 15:26:28 +0200 Subject: [PATCH 127/411] Fail on out-of-range CPU number Found by Coverity --- linux/LinuxProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6d3d03486..d09797fba 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1235,7 +1235,7 @@ static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { (sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) || (sscanf(buffer, "cpu MHz: %lf", &frequency) == 1) ) { - if (cpuid < 0) { + if (cpuid < 0 || cpuid > (cpus - 1)) { CRT_fatalError(PROCCPUINFOFILE " is malformed: cpu MHz line without corresponding processor line"); } From 05a5fdc47faac329a80f9259b12731899ede6644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 15:28:50 +0200 Subject: [PATCH 128/411] Ignore sscanf return value of /proc/stat Found by Coverity --- linux/LinuxProcessList.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index d09797fba..27ddf79de 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1142,10 +1142,10 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { char* ok = fgets(buffer, PROC_LINE_LENGTH, file); if (!ok) buffer[0] = '\0'; if (i == 0) - sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice); + (void) sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice); else { int cpuid; - sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice); + (void) sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice); assert(cpuid == i - 1); } // Guest time is already accounted in usertime From a850d81bf507b7a3281c89f503ee8e7963f6772f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 15:31:16 +0200 Subject: [PATCH 129/411] Avoid use of uninitialized variables Found by Coverity --- linux/LinuxProcessList.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 27ddf79de..afdbc5fda 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1062,9 +1062,9 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { } static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { - unsigned long long int dbufSize; - unsigned long long int dnodeSize; - unsigned long long int bonusSize; + unsigned long long int dbufSize = 0; + unsigned long long int dnodeSize = 0; + unsigned long long int bonusSize = 0; FILE* file = fopen(PROCARCSTATSFILE, "r"); if (file == NULL) { From 5c99c6e942d5346bdac77d11eece9e2d60db4191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 28 Aug 2020 15:34:24 +0200 Subject: [PATCH 130/411] Check btime sscanf parse from /proc/stat Found by Coverity --- linux/LinuxProcessList.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index afdbc5fda..e426785ff 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -275,7 +275,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui } else if (String_startsWith(buffer, "cpu")) { cpus++; } else if (String_startsWith(buffer, "btime ")) { - sscanf(buffer, "btime %lld\n", &btime); + if (sscanf(buffer, "btime %lld\n", &btime) != 1) + CRT_fatalError("Failed to parse btime from " PROCSTATFILE); break; } } while(true); From 338bd829b05576e5050916cbbb876cac7fa5fc3b Mon Sep 17 00:00:00 2001 From: ckath Date: Sat, 29 Aug 2020 15:15:52 +0200 Subject: [PATCH 131/411] add toggle for vim mode in options --- DisplayOptionsPanel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 1222d8235..42375e6ac 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -100,6 +100,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU percentage numerically"), &(settings->showCPUUsage))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU frequency"), &(settings->showCPUFrequency))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Enable the mouse"), &(settings->enableMouse))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Enable vim mode"), &(settings->vimMode))); #ifdef HAVE_LIBHWLOC Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show topology when selecting affinity by default"), &(settings->topologyAffinity))); #endif From 4bd0859b80e6ff6441083784684b65b6d7d64d54 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Mon, 31 Aug 2020 16:12:44 +1000 Subject: [PATCH 132/411] Add a badge/link to the released source tarballs --- README | 1 + 1 file changed, 1 insertion(+) diff --git a/README b/README index 52c0bedb7..7ed93480b 100644 --- a/README +++ b/README @@ -5,6 +5,7 @@ [![Mailing List](https://img.shields.io/badge/Mailing%20List-htop-blue.svg)](https://groups.io/g/htop) [![IRC #htop](https://img.shields.io/badge/IRC-htop-blue.svg)](https://webchat.freenode.net/#htop) [![Github Release](https://img.shields.io/github/release/htop-dev/htop.svg)](https://github.com/htop-dev/htop/releases/latest) +[![Download](https://api.bintray.com/packages/htop/source/htop/images/download.svg)](https://bintray.com/htop/source/htop/_latestVersion) Introduction ------------ From 0a835e13bfab831426fafb751c1413041f5324ca Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Mon, 31 Aug 2020 16:14:23 +1000 Subject: [PATCH 133/411] Simplify the --version output, old dates are confusing people Drop the copyright notice from the version output as a number of people seem to be confused by what this means, and we can do without all the (well intentioned) bug reports. --- htop.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/htop.c b/htop.c index 7cdf4e42b..bdaeb8446 100644 --- a/htop.c +++ b/htop.c @@ -29,14 +29,12 @@ in the source distribution for its full text. //#link m static void printVersionFlag() { - fputs("htop " VERSION " - " COPYRIGHT "\n" - "Released under the GNU GPL.\n\n", - stdout); + fputs("htop " VERSION "\n", stdout); exit(0); } static void printHelpFlag() { - fputs("htop " VERSION " - " COPYRIGHT "\n" + fputs("htop " VERSION "\n" "Released under the GNU GPL.\n\n" "-C --no-color Use a monochrome color scheme\n" "-m --no-mouse Disable the mouse\n" From e7f6d1ce5fa5b10c856f4e4b2e0c062d3b6f7b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 31 Aug 2020 11:55:53 +0200 Subject: [PATCH 134/411] Reduce oom cast from long to int Oom values should never be greater then INT_MAX, they should be in the range 0 - 1000. Improves: d9a5dd4b916636b5e7ba8631885427372f0cfcad --- linux/LinuxProcess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 6bae98867..5970c9389 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -492,7 +492,7 @@ long LinuxProcess_compare(const void* v1, const void* v2) { return strcmp(p1->cgroup ? p1->cgroup : "", p2->cgroup ? p2->cgroup : ""); #endif case OOM: - return ((long)p2->oom - (long)p1->oom); + return ((int)p2->oom - (int)p1->oom); #ifdef HAVE_DELAYACCT case PERCENT_CPU_DELAY: return (p2->cpu_delay_percent > p1->cpu_delay_percent ? 1 : -1); From 293e3a2931c267441170289e9d717fe43d51b390 Mon Sep 17 00:00:00 2001 From: Redha Gouicem Date: Mon, 31 Aug 2020 13:29:24 +0200 Subject: [PATCH 135/411] remove unused variable --- CPUMeter.c | 1 - 1 file changed, 1 deletion(-) diff --git a/CPUMeter.c b/CPUMeter.c index e09769cc3..8328150d3 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -66,7 +66,6 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { double percent = Platform_setCPUValues(this, cpu); if (this->pl->settings->showCPUFrequency) { double cpuFrequency = this->values[CPU_METER_FREQUENCY]; - char unit = 'M'; char cpuFrequencyBuffer[16]; if (cpuFrequency < 0) { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); From 0f5d2cd1e456b251706ebd337cacc8593186819f Mon Sep 17 00:00:00 2001 From: Redha Gouicem Date: Mon, 31 Aug 2020 13:32:29 +0200 Subject: [PATCH 136/411] fixed compilation error --- CPUMeter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CPUMeter.c b/CPUMeter.c index 8328150d3..e082207cc 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -70,7 +70,7 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { if (cpuFrequency < 0) { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); } else { - xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.0f%cHz", cpuFrequency, unit); + xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.0fGHz", cpuFrequency); } if (this->pl->settings->showCPUUsage) { xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer); From d0e8ff9319cb9c0c283234bdaa16d4753672e1e7 Mon Sep 17 00:00:00 2001 From: Redha Gouicem Date: Mon, 31 Aug 2020 14:09:22 +0200 Subject: [PATCH 137/411] fix unit (GHz -> MHz) --- CPUMeter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CPUMeter.c b/CPUMeter.c index e082207cc..82f9892e9 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -70,7 +70,7 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { if (cpuFrequency < 0) { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); } else { - xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.0fGHz", cpuFrequency); + xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.0fMHz", cpuFrequency); } if (this->pl->settings->showCPUUsage) { xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer); From f861a2c61692eda9d24fc5e32608b3a56bb721bc Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Mon, 31 Aug 2020 22:08:35 +0200 Subject: [PATCH 138/411] Revert "Use UTF-8 for check buttons and tree open/closed" This reverts commit 5d5913d355b3a9f03da589b3542b8f55467b4ed6. --- AffinityPanel.c | 16 ++++++------ CRT.c | 68 +++++++++++++++---------------------------------- CRT.h | 28 ++------------------ CheckItem.c | 7 ++--- 4 files changed, 34 insertions(+), 85 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index e95b381ed..23f0ca800 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -55,20 +55,20 @@ static void MaskItem_delete(Object* cast) { static void MaskItem_display(Object* cast, RichString* out) { MaskItem* this = (MaskItem*)cast; assert (this != NULL); + RichString_append(out, CRT_colors[CHECK_BOX], "["); if (this->value == 2) - RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_FULL]); + RichString_append(out, CRT_colors[CHECK_MARK], "x"); else if (this->value == 1) - RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_PARTIAL]); + RichString_append(out, CRT_colors[CHECK_MARK], "o"); else - RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_NONE]); + RichString_append(out, CRT_colors[CHECK_MARK], " "); + RichString_append(out, CRT_colors[CHECK_BOX], "]"); RichString_append(out, CRT_colors[CHECK_TEXT], " "); if (this->indent) RichString_append(out, CRT_colors[PROCESS_TREE], this->indent); if (this->sub_tree) { - RichString_append(out, CRT_colors[PROCESS_TREE], - this->sub_tree == 1 - ? CRT_collapStr[COLLAP_STR_OPEN] - : CRT_collapStr[COLLAP_STR_CLOSED]); + RichString_append(out, CRT_colors[ PROCESS_TREE], + this->sub_tree == 1 ? "[-]" : "[+]"); RichString_append(out, CRT_colors[CHECK_TEXT], " "); } RichString_append(out, CRT_colors[CHECK_TEXT], this->text); @@ -303,7 +303,7 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u } /* "[x] " + "|- " * depth + ("[+] ")? + name */ - unsigned width = (CRT_utf8 ? 2 : 4) + 3 * depth + (item->sub_tree ? (CRT_utf8 ? 2 : 4) : 0) + strlen(buf); + unsigned width = 4 + 3 * depth + (item->sub_tree ? 4 : 0) + strlen(buf); if (width > this->width) this->width = width; diff --git a/CRT.c b/CRT.c index 869573e51..35b285f79 100644 --- a/CRT.c +++ b/CRT.c @@ -59,19 +59,6 @@ typedef enum TreeStr_ { TREE_STR_COUNT } TreeStr; -typedef enum CheckStr_ { - CHECK_STR_NONE, - CHECK_STR_PARTIAL, - CHECK_STR_FULL, - CHECK_STR_COUNT -} CheckStr; - -typedef enum CollapStr_ { - COLLAP_STR_OPEN, - COLLAP_STR_CLOSED, - COLLAP_STR_COUNT -} CollapStr; - typedef enum ColorSchemes_ { COLORSCHEME_DEFAULT = 0, COLORSCHEME_MONOCHROME = 1, @@ -126,6 +113,7 @@ typedef enum ColorElements_ { LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE, + CHECK_BOX, CHECK_MARK, CHECK_TEXT, CLOCK, @@ -171,17 +159,6 @@ const char *CRT_treeStrAscii[TREE_STR_COUNT] = { "-", // TREE_STR_SHUT }; -const char *CRT_checkStrAscii[CHECK_STR_COUNT] = { - "[ ]", // CHECK_STR_NONE - "[o]", // CHECK_STR_PARTIAL - "[x]", // CHECK_STR_FULL -}; - -const char *CRT_collapStrAscii[COLLAP_STR_COUNT] = { - "[-]", // COLLAP_STR_OPEN - "[+]", // COLLAP_STR_CLOSED -}; - #ifdef HAVE_LIBNCURSESW const char *CRT_treeStrUtf8[TREE_STR_COUNT] = { @@ -194,27 +171,12 @@ const char *CRT_treeStrUtf8[TREE_STR_COUNT] = { "\xe2\x94\x80", // TREE_STR_SHUT ─ }; -const char *CRT_checkStrUtf8[CHECK_STR_COUNT] = { - "\xe2\x98\x90", // CHECK_STR_NONE ☐ - "\xe2\x98\x92", // CHECK_STR_PARTIAL ☒ - "\xe2\x98\x91", // CHECK_STR_FULL ☑ -}; - -const char *CRT_collapStrUtf8[COLLAP_STR_COUNT] = { - "\xe2\x8a\x9f", // COLLAP_STR_OPEN ⊟ - "\xe2\x8a\x9e", // COLLAP_STR_CLOSED ⊞ -}; +bool CRT_utf8 = false; #endif -bool CRT_utf8 = false; - const char **CRT_treeStr = CRT_treeStrAscii; -const char **CRT_checkStr = CRT_checkStrAscii; - -const char **CRT_collapStr = CRT_collapStrAscii; - static bool CRT_hasColors; int CRT_delay = 0; @@ -267,7 +229,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Black), [CLOCK] = A_BOLD, - [CHECK_MARK] = A_BOLD | ColorPair(Cyan,Black), + [CHECK_BOX] = ColorPair(Cyan,Black), + [CHECK_MARK] = A_BOLD, [CHECK_TEXT] = A_NORMAL, [HOSTNAME] = A_BOLD, [CPU_NICE] = ColorPair(Blue,Black), @@ -335,7 +298,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD, [CLOCK] = A_BOLD, - [CHECK_MARK] = A_BOLD, + [CHECK_BOX] = A_BOLD, + [CHECK_MARK] = A_NORMAL, [CHECK_TEXT] = A_NORMAL, [HOSTNAME] = A_BOLD, [CPU_NICE] = A_NORMAL, @@ -403,6 +367,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = ColorPair(Black,White), [HELP_BOLD] = ColorPair(Blue,White), [CLOCK] = ColorPair(Black,White), + [CHECK_BOX] = ColorPair(Blue,White), [CHECK_MARK] = ColorPair(Black,White), [CHECK_TEXT] = ColorPair(Black,White), [HOSTNAME] = ColorPair(Black,White), @@ -471,6 +436,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = ColorPair(White,Black), [HELP_BOLD] = ColorPair(Blue,Black), [CLOCK] = ColorPair(White,Black), + [CHECK_BOX] = ColorPair(Blue,Black), [CHECK_MARK] = ColorPair(Black,Black), [CHECK_TEXT] = ColorPair(Black,Black), [HOSTNAME] = ColorPair(White,Black), @@ -539,7 +505,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD | ColorPair(White,Blue), [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Blue), [CLOCK] = ColorPair(White,Blue), - [CHECK_MARK] = A_BOLD | ColorPair(Cyan,Blue), + [CHECK_BOX] = ColorPair(Cyan,Blue), + [CHECK_MARK] = A_BOLD | ColorPair(White,Blue), [CHECK_TEXT] = A_NORMAL | ColorPair(White,Blue), [HOSTNAME] = ColorPair(White,Blue), [CPU_NICE] = A_BOLD | ColorPair(Cyan,Blue), @@ -607,6 +574,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Black), [CLOCK] = ColorPair(Green,Black), + [CHECK_BOX] = ColorPair(Green,Black), [CHECK_MARK] = A_BOLD | ColorPair(Green,Black), [CHECK_TEXT] = ColorPair(Cyan,Black), [HOSTNAME] = ColorPair(Green,Black), @@ -763,13 +731,17 @@ void CRT_init(int delay, int colorScheme) { setlocale(LC_CTYPE, ""); #ifdef HAVE_LIBNCURSESW - if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) { + if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) CRT_utf8 = true; - CRT_treeStr = CRT_treeStrUtf8; - CRT_checkStr = CRT_checkStrUtf8; - CRT_collapStr = CRT_collapStrUtf8; - } + else + CRT_utf8 = false; +#endif + + CRT_treeStr = +#ifdef HAVE_LIBNCURSESW + CRT_utf8 ? CRT_treeStrUtf8 : #endif + CRT_treeStrAscii; #if NCURSES_MOUSE_VERSION > 1 mousemask(BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL); diff --git a/CRT.h b/CRT.h index 5fb2f09cd..80022f705 100644 --- a/CRT.h +++ b/CRT.h @@ -47,19 +47,6 @@ typedef enum TreeStr_ { TREE_STR_COUNT } TreeStr; -typedef enum CheckStr_ { - CHECK_STR_NONE, - CHECK_STR_PARTIAL, - CHECK_STR_FULL, - CHECK_STR_COUNT -} CheckStr; - -typedef enum CollapStr_ { - COLLAP_STR_OPEN, - COLLAP_STR_CLOSED, - COLLAP_STR_COUNT -} CollapStr; - typedef enum ColorSchemes_ { COLORSCHEME_DEFAULT = 0, COLORSCHEME_MONOCHROME = 1, @@ -114,6 +101,7 @@ typedef enum ColorElements_ { LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE, + CHECK_BOX, CHECK_MARK, CHECK_TEXT, CLOCK, @@ -150,28 +138,16 @@ extern void CRT_handleSIGSEGV(int sgn); extern const char *CRT_treeStrAscii[TREE_STR_COUNT]; -extern const char *CRT_checkStrAscii[CHECK_STR_COUNT]; - -extern const char *CRT_collapStrAscii[COLLAP_STR_COUNT]; - #ifdef HAVE_LIBNCURSESW extern const char *CRT_treeStrUtf8[TREE_STR_COUNT]; -extern const char *CRT_checkStrUtf8[CHECK_STR_COUNT]; - -extern const char *CRT_collapStrUtf8[COLLAP_STR_COUNT]; +extern bool CRT_utf8; #endif -extern bool CRT_utf8; - extern const char **CRT_treeStr; -extern const char **CRT_checkStr; - -extern const char **CRT_collapStr; - extern int CRT_delay; extern int* CRT_colors; diff --git a/CheckItem.c b/CheckItem.c index a045d2ffd..910981e86 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -35,11 +35,12 @@ static void CheckItem_delete(Object* cast) { static void CheckItem_display(Object* cast, RichString* out) { CheckItem* this = (CheckItem*)cast; assert (this != NULL); + RichString_write(out, CRT_colors[CHECK_BOX], "["); if (CheckItem_get(this)) - RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_FULL]); + RichString_append(out, CRT_colors[CHECK_MARK], "x"); else - RichString_append(out, CRT_colors[CHECK_MARK], CRT_checkStr[CHECK_STR_NONE]); - RichString_append(out, CRT_colors[CHECK_TEXT], " "); + RichString_append(out, CRT_colors[CHECK_MARK], " "); + RichString_append(out, CRT_colors[CHECK_BOX], "] "); RichString_append(out, CRT_colors[CHECK_TEXT], this->text); } From b0f1336f79e5f07f591e05ceec13637b7452a15c Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Mon, 31 Aug 2020 22:05:01 +0200 Subject: [PATCH 139/411] affinity panel: show CPUs in the topology tree as `CPU x` As it is in the non-topology list. --- AffinityPanel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index 23f0ca800..91a9d456e 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -260,7 +260,7 @@ static HandlerResult AffinityPanel_eventHandler(Panel* super, int ch) { static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem *parent) { const char* type_name = hwloc_obj_type_string(obj->type); - const char* index_prefix = " #"; + const char* index_prefix = "#"; unsigned depth = obj->depth; unsigned index = obj->logical_index; size_t off = 0, left = 10 * depth; @@ -286,7 +286,7 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u off += len, left -= len; } - xSnprintf(buf, 64, "%s%s%u", type_name, index_prefix, index); + xSnprintf(buf, 64, "%s %s%u", type_name, index_prefix, index); MaskItem *item = MaskItem_newMask(buf, indent_buf, obj->complete_cpuset, false); if (parent) From 19359cec5a282350380a32981b09da0b4883fcda Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Mon, 31 Aug 2020 22:22:22 +0200 Subject: [PATCH 140/411] affinity panel: use the tree collapsing as in the process list With one exception, the root node does also have a `-`/`+` as a prefix. --- AffinityPanel.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index 91a9d456e..1ffa90089 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -27,7 +27,7 @@ in the source distribution for its full text. typedef struct MaskItem_ { Object super; const char* text; - const char* indent; + const char* indent; /* used also as an condition whether this is a tree node */ int value; /* tri-state: 0 - off, 1 - some set, 2 - all set */ int sub_tree; /* tri-state: 0 - no sub-tree, 1 - open sub-tree, 2 - closed sub-tree */ Vector *children; @@ -64,11 +64,12 @@ static void MaskItem_display(Object* cast, RichString* out) { RichString_append(out, CRT_colors[CHECK_MARK], " "); RichString_append(out, CRT_colors[CHECK_BOX], "]"); RichString_append(out, CRT_colors[CHECK_TEXT], " "); - if (this->indent) + if (this->indent) { RichString_append(out, CRT_colors[PROCESS_TREE], this->indent); - if (this->sub_tree) { - RichString_append(out, CRT_colors[ PROCESS_TREE], - this->sub_tree == 1 ? "[-]" : "[+]"); + RichString_append(out, CRT_colors[PROCESS_TREE], + this->sub_tree == 2 + ? CRT_treeStr[TREE_STR_OPEN] + : CRT_treeStr[TREE_STR_SHUT]); RichString_append(out, CRT_colors[CHECK_TEXT], " "); } RichString_append(out, CRT_colors[CHECK_TEXT], this->text); @@ -84,7 +85,7 @@ static ObjectClass MaskItem_class = { static MaskItem* MaskItem_newMask(const char* text, const char* indent, hwloc_bitmap_t cpuset, bool owner) { MaskItem* this = AllocThis(MaskItem); this->text = xStrdup(text); - this->indent = xStrdup(indent); + this->indent = xStrdup(indent); /* nonnull for tree node */ this->value = 0; this->ownCpuset = owner; this->cpuset = cpuset; @@ -98,7 +99,7 @@ static MaskItem* MaskItem_newMask(const char* text, const char* indent, hwloc_bi static MaskItem* MaskItem_newSingleton(const char* text, int cpu, bool isSet) { MaskItem* this = AllocThis(MaskItem); this->text = xStrdup(text); - this->indent = NULL; + this->indent = NULL; /* not a tree node */ this->sub_tree = 0; this->children = Vector_new(Class(MaskItem), true, DEFAULT_SIZE); @@ -279,9 +280,8 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u size_t len = strlen(&indent_buf[off]); off += len, left -= len; } - xSnprintf(&indent_buf[off], left, "%s%s ", - obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND], - CRT_treeStr[TREE_STR_HORZ]); + xSnprintf(&indent_buf[off], left, "%s", + obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]); size_t len = strlen(&indent_buf[off]); off += len, left -= len; } @@ -302,8 +302,8 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u item->sub_tree = 2; } - /* "[x] " + "|- " * depth + ("[+] ")? + name */ - unsigned width = 4 + 3 * depth + (item->sub_tree ? 4 : 0) + strlen(buf); + /* "[x] " + "|- " * depth + ("- ")?(if root node) + name */ + unsigned width = 4 + 3 * depth + (2 * !depth) + strlen(buf); if (width > this->width) this->width = width; From e1e60f38dc871a99d3fa71f3fabd6a3ddeb32ca9 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Mon, 31 Aug 2020 22:35:09 +0200 Subject: [PATCH 141/411] CRT: note about possible use of replacement for `+` glyph in tree --- CRT.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CRT.c b/CRT.c index 35b285f79..33ee96232 100644 --- a/CRT.c +++ b/CRT.c @@ -167,7 +167,9 @@ const char *CRT_treeStrUtf8[TREE_STR_COUNT] = { "\xe2\x94\x9c", // TREE_STR_RTEE ├ "\xe2\x94\x94", // TREE_STR_BEND └ "\xe2\x94\x8c", // TREE_STR_TEND ┌ - "+", // TREE_STR_OPEN + + "+", // TREE_STR_OPEN +, TODO use 🮯 'BOX DRAWINGS LIGHT HORIZONTAL + // WITH VERTICAL STROKE' (U+1FBAF, "\xf0\x9f\xae\xaf") when + // Unicode 13 is common "\xe2\x94\x80", // TREE_STR_SHUT ─ }; From db5adbeae09b8b80587294e4de125af109b8ecdc Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 1 Sep 2020 10:09:00 +0200 Subject: [PATCH 142/411] add option (-U, --no-unicode) to disable unicode at runtime --- CRT.c | 6 ++++-- CRT.h | 2 +- htop.1.in | 3 +++ htop.c | 31 +++++++++++++++++++------------ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/CRT.c b/CRT.c index 33ee96232..0d83bf426 100644 --- a/CRT.c +++ b/CRT.c @@ -667,7 +667,7 @@ void CRT_restorePrivileges() { // TODO: pass an instance of Settings instead. -void CRT_init(int delay, int colorScheme) { +void CRT_init(int delay, int colorScheme, bool allowUnicode) { initscr(); noecho(); CRT_delay = delay; @@ -733,10 +733,12 @@ void CRT_init(int delay, int colorScheme) { setlocale(LC_CTYPE, ""); #ifdef HAVE_LIBNCURSESW - if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) + if (allowUnicode && strcmp(nl_langinfo(CODESET), "UTF-8") == 0) CRT_utf8 = true; else CRT_utf8 = false; +#else + (void) allowUnicode; #endif CRT_treeStr = diff --git a/CRT.h b/CRT.h index 80022f705..7d5c8adfb 100644 --- a/CRT.h +++ b/CRT.h @@ -189,7 +189,7 @@ extern void CRT_restorePrivileges(); // TODO: pass an instance of Settings instead. -extern void CRT_init(int delay, int colorScheme); +extern void CRT_init(int delay, int colorScheme, bool allowUnicode); extern void CRT_done(); diff --git a/htop.1.in b/htop.1.in index 9ef0761bd..c5b131bb5 100644 --- a/htop.1.in +++ b/htop.1.in @@ -48,6 +48,9 @@ Sort by this column (use \-\-sort\-key help for a column list) \fB\-u \-\-user=USERNAME\fR Show only the processes of a given user .TP +\fB\-U \-\-no-unicode\fR +Do not use unicode but ASCII characters for graph meters +.TP \fB\-v \-\-version Output version information and exit .TP diff --git a/htop.c b/htop.c index d9302a0c1..bbf3a9115 100644 --- a/htop.c +++ b/htop.c @@ -43,6 +43,7 @@ static void printHelpFlag() { "-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n" "-t --tree Show the tree view by default\n" "-u --user[=USERNAME] Show only processes for a given user (or $USER)\n" + "-U --no-unicode Do not use unicode but plain ASCII\n" "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n" "-v --version Print version info\n" "\n" @@ -63,6 +64,7 @@ typedef struct CommandLineSettings_ { bool useColors; bool enableMouse; bool treeView; + bool allowUnicode; } CommandLineSettings; static CommandLineSettings parseArguments(int argc, char** argv) { @@ -75,26 +77,28 @@ static CommandLineSettings parseArguments(int argc, char** argv) { .useColors = true, .enableMouse = true, .treeView = false, + .allowUnicode = true, }; static struct option long_opts[] = { - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'v'}, - {"delay", required_argument, 0, 'd'}, - {"sort-key", required_argument, 0, 's'}, - {"user", optional_argument, 0, 'u'}, - {"no-color", no_argument, 0, 'C'}, - {"no-colour",no_argument, 0, 'C'}, - {"no-mouse", no_argument, 0, 'm'}, - {"tree", no_argument, 0, 't'}, - {"pid", required_argument, 0, 'p'}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'v'}, + {"delay", required_argument, 0, 'd'}, + {"sort-key", required_argument, 0, 's'}, + {"user", optional_argument, 0, 'u'}, + {"no-color", no_argument, 0, 'C'}, + {"no-colour", no_argument, 0, 'C'}, + {"no-mouse", no_argument, 0, 'm'}, + {"no-unicode", no_argument, 0, 'U'}, + {"tree", no_argument, 0, 't'}, + {"pid", required_argument, 0, 'p'}, {0,0,0,0} }; int opt, opti=0; /* Parse arguments */ - while ((opt = getopt_long(argc, argv, "hvmCs:td:u::p:", long_opts, &opti))) { + while ((opt = getopt_long(argc, argv, "hvmCs:td:u:Up:", long_opts, &opti))) { if (opt == EOF) break; switch (opt) { case 'h': @@ -148,6 +152,9 @@ static CommandLineSettings parseArguments(int argc, char** argv) { case 'm': flags.enableMouse = false; break; + case 'U': + flags.allowUnicode = false; + break; case 't': flags.treeView = true; break; @@ -226,7 +233,7 @@ int main(int argc, char** argv) { if (flags.treeView) settings->treeView = true; - CRT_init(settings->delay, settings->colorScheme); + CRT_init(settings->delay, settings->colorScheme, flags.allowUnicode); MainPanel* panel = MainPanel_new(); ProcessList_setPanel(pl, (Panel*) panel); From 8ee7d58cb069e30627fd97712c5a1ce1ca383cc6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Sep 2020 14:47:00 +0200 Subject: [PATCH 143/411] Do not link INSTALL file, because link target does not exist --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 7ed93480b..bb522c39a 100644 --- a/README +++ b/README @@ -20,7 +20,7 @@ Build instructions ------------------ This program is distributed as a standard autotools-based package. -For detailed instructions see the [INSTALL](/INSTALL) file, which +For detailed instructions see the `INSTALL` file, which is created after `./autogen.sh` is run. When compiling from a [release tarball](https://github.com/htop-dev/htop/releases/), run: From 746a5f279a5bd74e928d186fc48853b7f138cb7c Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 2 Sep 2020 11:54:17 +1200 Subject: [PATCH 144/411] Fix image logo and titles. --- README | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README b/README index 7ed93480b..b1e7828d0 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -![htop](https://htop.dev) +# [![htop](htop.png)](https://htop.dev) [![CI](https://github.com/htop-dev/htop/workflows/CI/badge.svg)](https://github.com/htop-dev/htop/actions) [![Coverity Scan Build Status](https://scan.coverity.com/projects/21665/badge.svg)](https://scan.coverity.com/projects/21665) @@ -7,8 +7,7 @@ [![Github Release](https://img.shields.io/github/release/htop-dev/htop.svg)](https://github.com/htop-dev/htop/releases/latest) [![Download](https://api.bintray.com/packages/htop/source/htop/images/download.svg)](https://bintray.com/htop/source/htop/_latestVersion) -Introduction ------------- +## Introduction `htop` is a cross-platform interactive process viewer. It requires `ncurses`. @@ -16,8 +15,7 @@ It requires `ncurses`. For more information and details on how to contribute to `htop` visit [htop.dev](https://htop.dev). -Build instructions ------------------- +## Build instructions This program is distributed as a standard autotools-based package. For detailed instructions see the [INSTALL](/INSTALL) file, which @@ -25,11 +23,15 @@ is created after `./autogen.sh` is run. When compiling from a [release tarball](https://github.com/htop-dev/htop/releases/), run: - ./configure && make +~~~ shell +./configure && make +~~~ For compiling sources downloaded from the Git repository, run: - ./autogen.sh && ./configure && make +~~~ shell +./autogen.sh && ./configure && make +~~~ By default `make install` will install into `/usr/local`, for changing the path use `./configure --prefix=/some/path`. From dace850fa6e27b5626115b366059258cfe4d60c9 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 3 Sep 2020 13:23:34 +1000 Subject: [PATCH 145/411] Bump version, changelog for minor htop-3.0.1 release --- ChangeLog | 13 +++++++++++++ configure.ac | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e76249110..a45b973e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +What's new in version 3.0.1 + +* Coverity fixes, CI improvements, documentation updates +* BUGFIX: Fix early exit with longer sysfs battery paths +* BUGFIX: Improve OOM output, fix sorting +(thanks to Christian Göttsche) +* Rework check buttons and tree open/closed +(thanks to Bert Wesarg) +* Add -U/--no-unicode option to disable unicode +(thanks to Christian Hesse) +* Improvements to the affinity panel +(thanks to Bert Wesarg) + What's new in version 3.0.0 * New maintainers - after a prolonged period of inactivity diff --git a/configure.ac b/configure.ac index b98dacc03..f6498b7e3 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.65) -AC_INIT([htop],[3.0.0],[htop@groups.io]) +AC_INIT([htop],[3.0.1],[htop@groups.io]) AC_CONFIG_SRCDIR([htop.c]) AC_CONFIG_AUX_DIR([.]) From 11ecc65ebb1527e9a83f67bb5ac0dec455cb03e6 Mon Sep 17 00:00:00 2001 From: Tobias Kortkamp Date: Thu, 3 Sep 2020 08:42:18 +0200 Subject: [PATCH 146/411] Unbreak with -fno-common on FreeBSD GCC10 and Clang11 now default to -fno-common. ld: error: duplicate symbol: jail_errmsg >>> defined at Platform.c >>> freebsd/Platform.o:(jail_errmsg) >>> defined at FreeBSDProcessList.c >>> freebsd/FreeBSDProcessList.o:(.bss+0x90) Signed-off-by: Tobias Kortkamp --- freebsd/FreeBSDProcessList.c | 3 ++- freebsd/FreeBSDProcessList.h | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 8c892a021..fd88a5636 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -33,7 +33,7 @@ in the source distribution for its full text. #include #define JAIL_ERRMSGLEN 1024 -char jail_errmsg[JAIL_ERRMSGLEN]; +extern char jail_errmsg[JAIL_ERRMSGLEN]; typedef struct CPUData_ { @@ -69,6 +69,7 @@ typedef struct FreeBSDProcessList_ { }*/ +char jail_errmsg[JAIL_ERRMSGLEN]; static int MIB_hw_physmem[2]; static int MIB_vm_stats_vm_v_page_count[4]; diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 7c1b7ad40..7bfcf427a 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -19,7 +19,7 @@ in the source distribution for its full text. #include #define JAIL_ERRMSGLEN 1024 -char jail_errmsg[JAIL_ERRMSGLEN]; +extern char jail_errmsg[JAIL_ERRMSGLEN]; typedef struct CPUData_ { @@ -54,15 +54,17 @@ typedef struct FreeBSDProcessList_ { } FreeBSDProcessList; +extern char jail_errmsg[JAIL_ERRMSGLEN]; -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); -void ProcessList_delete(ProcessList* this); +extern ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); -char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); +extern void ProcessList_delete(ProcessList* this); -char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc); +extern char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); -void ProcessList_goThroughEntries(ProcessList* this); +extern char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc); + +extern void ProcessList_goThroughEntries(ProcessList* this); #endif From 35d7e42b8831768351c738df3de9f7c9e0f23b15 Mon Sep 17 00:00:00 2001 From: Tobias Kortkamp Date: Thu, 3 Sep 2020 09:00:17 +0200 Subject: [PATCH 147/411] Add FreeBSD to Travis Signed-off-by: Tobias Kortkamp --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 22a5e07c0..b3e358de6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ compiler: - gcc os: + - freebsd - linux - osx From a1a027b9bd833db5384d7dc65046194018eb8bfa Mon Sep 17 00:00:00 2001 From: Zev Weiss Date: Sat, 21 Dec 2019 01:09:25 -0800 Subject: [PATCH 148/411] Axe automated header generation. Reasoning: - implementation was unsound -- broke down when I added a fairly basic macro definition expanding to a struct initializer in a *.c file. - made it way too easy (e.g. via otherwise totally innocuous git commands) to end up with timestamps such that it always ran MakeHeader.py but never used its output, leading to overbuild noise when running what should be a null 'make'. - but mostly: it's just an awkward way of dealing with C code. --- .gitignore | 1 - Action.c | 32 ------ Action.h | 2 - Affinity.c | 12 --- Affinity.h | 2 - AffinityPanel.c | 7 -- AffinityPanel.h | 2 - AvailableColumnsPanel.c | 9 -- AvailableColumnsPanel.h | 2 - AvailableMetersPanel.c | 17 --- AvailableMetersPanel.h | 2 - BatteryMeter.c | 9 -- BatteryMeter.h | 2 - CPUMeter.c | 18 ---- CPUMeter.h | 2 - CRT.c | 104 ------------------ CRT.h | 2 - CategoriesPanel.c | 16 --- CategoriesPanel.h | 2 - CheckItem.c | 11 -- CheckItem.h | 2 - ClockMeter.c | 3 - ClockMeter.h | 2 - ColorsPanel.c | 13 --- ColorsPanel.h | 2 - ColumnsPanel.c | 12 --- ColumnsPanel.h | 2 - DisplayOptionsPanel.c | 13 --- DisplayOptionsPanel.h | 2 - EnvScreen.c | 7 -- EnvScreen.h | 2 - FunctionBar.c | 13 --- FunctionBar.h | 2 - Hashtable.c | 20 ---- Hashtable.h | 2 - Header.c | 15 --- Header.h | 2 - HostnameMeter.c | 3 - HostnameMeter.h | 2 - IncSet.c | 33 ------ IncSet.h | 2 - InfoScreen.c | 36 ------- InfoScreen.h | 2 - ListItem.c | 11 -- ListItem.h | 2 - LoadAverageMeter.c | 3 - LoadAverageMeter.h | 2 - MainPanel.c | 19 ---- MainPanel.h | 2 - Makefile.am | 33 +----- MemoryMeter.c | 3 - MemoryMeter.h | 2 - Meter.c | 83 -------------- Meter.h | 2 - MetersPanel.c | 19 ---- MetersPanel.h | 2 - Object.c | 40 ------- Object.h | 2 - OpenFilesScreen.c | 24 ----- OpenFilesScreen.h | 2 - Panel.c | 54 ---------- Panel.h | 2 - Process.c | 139 ------------------------ Process.h | 2 - ProcessList.c | 63 ----------- ProcessList.h | 2 - RichString.c | 49 --------- RichString.h | 2 - ScreenManager.c | 27 ----- ScreenManager.h | 2 - Settings.c | 56 ---------- Settings.h | 2 - SignalsPanel.c | 8 -- SignalsPanel.h | 2 - StringUtils.c | 6 -- StringUtils.h | 2 - SwapMeter.c | 3 - SwapMeter.h | 2 - TasksMeter.c | 3 - TasksMeter.h | 2 - TraceScreen.c | 15 --- TraceScreen.h | 2 - UptimeMeter.c | 3 - UptimeMeter.h | 2 - UsersTable.c | 7 -- UsersTable.h | 2 - Vector.c | 19 ---- Vector.h | 2 - XAlloc.c | 5 - XAlloc.h | 2 - configure.ac | 1 - darwin/Battery.h | 2 - darwin/DarwinCRT.h | 2 - darwin/DarwinProcess.c | 15 --- darwin/DarwinProcess.h | 2 - darwin/DarwinProcessList.c | 22 ---- darwin/DarwinProcessList.h | 2 - darwin/Platform.c | 7 -- darwin/Platform.h | 2 - dragonflybsd/Battery.h | 2 - dragonflybsd/DragonFlyBSDCRT.h | 2 - dragonflybsd/DragonFlyBSDProcess.c | 28 ----- dragonflybsd/DragonFlyBSDProcess.h | 2 - dragonflybsd/DragonFlyBSDProcessList.c | 48 --------- dragonflybsd/DragonFlyBSDProcessList.h | 2 - dragonflybsd/Platform.c | 8 -- dragonflybsd/Platform.h | 2 - freebsd/Battery.h | 2 - freebsd/FreeBSDCRT.h | 2 - freebsd/FreeBSDProcess.c | 27 ----- freebsd/FreeBSDProcess.h | 2 - freebsd/FreeBSDProcessList.c | 47 -------- freebsd/FreeBSDProcessList.h | 2 - freebsd/Platform.c | 8 -- freebsd/Platform.h | 2 - htop.h | 2 - linux/Battery.h | 2 - linux/IOPriority.c | 40 ------- linux/IOPriority.h | 2 - linux/IOPriorityPanel.c | 5 - linux/IOPriorityPanel.h | 2 - linux/LinuxCRT.h | 2 - linux/LinuxProcess.c | 144 ------------------------- linux/LinuxProcess.h | 2 - linux/LinuxProcessList.c | 89 --------------- linux/LinuxProcessList.h | 2 - linux/Platform.c | 7 -- linux/Platform.h | 2 - openbsd/Battery.h | 2 - openbsd/OpenBSDCRT.h | 2 - openbsd/OpenBSDProcess.c | 20 ---- openbsd/OpenBSDProcess.h | 2 - openbsd/OpenBSDProcessList.c | 34 ------ openbsd/OpenBSDProcessList.h | 2 - openbsd/Platform.c | 8 -- openbsd/Platform.h | 2 - scripts/MakeHeader.py.in | 104 ------------------ solaris/Battery.h | 2 - solaris/Platform.c | 22 ---- solaris/Platform.h | 2 - solaris/SolarisCRT.h | 2 - solaris/SolarisProcess.c | 44 -------- solaris/SolarisProcess.h | 2 - solaris/SolarisProcessList.c | 39 ------- solaris/SolarisProcessList.h | 2 - unsupported/Battery.h | 2 - unsupported/Platform.c | 6 -- unsupported/Platform.h | 2 - unsupported/UnsupportedCRT.h | 2 - unsupported/UnsupportedProcess.c | 6 -- unsupported/UnsupportedProcess.h | 2 - unsupported/UnsupportedProcessList.c | 3 - unsupported/UnsupportedProcessList.h | 2 - 153 files changed, 2 insertions(+), 2040 deletions(-) delete mode 100644 linux/IOPriority.c delete mode 100644 scripts/MakeHeader.py.in diff --git a/.gitignore b/.gitignore index b642d7cbd..f94f3f52e 100644 --- a/.gitignore +++ b/.gitignore @@ -39,5 +39,4 @@ libtool ltmain.sh m4/ missing -scripts/MakeHeader.py stamp-h1 diff --git a/Action.c b/Action.c index d9cc5abfb..90d6bfe1f 100644 --- a/Action.c +++ b/Action.c @@ -30,38 +30,6 @@ in the source distribution for its full text. #include #include -/*{ - -#include "IncSet.h" -#include "Settings.h" -#include "Header.h" -#include "UsersTable.h" -#include "ProcessList.h" -#include "Panel.h" - -typedef enum { - HTOP_OK = 0x00, - HTOP_REFRESH = 0x01, - HTOP_RECALCULATE = 0x03, // implies HTOP_REFRESH - HTOP_SAVE_SETTINGS = 0x04, - HTOP_KEEP_FOLLOWING = 0x08, - HTOP_QUIT = 0x10, - HTOP_REDRAW_BAR = 0x20, - HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH -} Htop_Reaction; - -typedef Htop_Reaction (*Htop_Action)(); - -typedef struct State_ { - Settings* settings; - UsersTable* ut; - ProcessList* pl; - Panel* panel; - Header* header; -} State; - -}*/ - Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) { Panel* panel = st->panel; Header* header = st->header; diff --git a/Action.h b/Action.h index 4c5971b63..625bff6cd 100644 --- a/Action.h +++ b/Action.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Action #define HEADER_Action /* diff --git a/Affinity.c b/Affinity.c index b6eafceed..3ea45a9b8 100644 --- a/Affinity.c +++ b/Affinity.c @@ -21,18 +21,6 @@ in the source distribution for its full text. #include #endif -/*{ -#include "Process.h" -#include "ProcessList.h" - -typedef struct Affinity_ { - ProcessList* pl; - int size; - int used; - int* cpus; -} Affinity; - -}*/ Affinity* Affinity_new(ProcessList* pl) { Affinity* this = xCalloc(1, sizeof(Affinity)); diff --git a/Affinity.h b/Affinity.h index 3c716034c..322ca549a 100644 --- a/Affinity.h +++ b/Affinity.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Affinity #define HEADER_Affinity /* diff --git a/AffinityPanel.c b/AffinityPanel.c index 1ffa90089..d69ce0034 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -17,13 +17,6 @@ in the source distribution for its full text. #include #endif -/*{ -#include "Panel.h" -#include "Affinity.h" -#include "ProcessList.h" - -}*/ - typedef struct MaskItem_ { Object super; const char* text; diff --git a/AffinityPanel.h b/AffinityPanel.h index 54d4f24cf..64ee32ad4 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_AffinityPanel #define HEADER_AffinityPanel /* diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index 1e548dce9..8aedde241 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -16,15 +16,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Panel.h" - -typedef struct AvailableColumnsPanel_ { - Panel super; - Panel* columns; -} AvailableColumnsPanel; - -}*/ static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/AvailableColumnsPanel.h b/AvailableColumnsPanel.h index 2d6daf4ba..fc3cb219c 100644 --- a/AvailableColumnsPanel.h +++ b/AvailableColumnsPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_AvailableColumnsPanel #define HEADER_AvailableColumnsPanel /* diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index 5dac10b9f..0533cfbfe 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -16,23 +16,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Settings.h" -#include "Panel.h" -#include "ScreenManager.h" -#include "ProcessList.h" - -typedef struct AvailableMetersPanel_ { - Panel super; - ScreenManager* scr; - - Settings* settings; - Header* header; - Panel* leftPanel; - Panel* rightPanel; -} AvailableMetersPanel; - -}*/ static void AvailableMetersPanel_delete(Object* object) { Panel* super = (Panel*) object; diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index 00e0f5962..b2de67192 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_AvailableMetersPanel #define HEADER_AvailableMetersPanel /* diff --git a/BatteryMeter.c b/BatteryMeter.c index 716b77506..859df9d76 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -18,15 +18,6 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). #include #include -/*{ -#include "Meter.h" - -typedef enum ACPresence_ { - AC_ABSENT, - AC_PRESENT, - AC_ERROR -} ACPresence; -}*/ int BatteryMeter_attributes[] = { BATTERY diff --git a/BatteryMeter.h b/BatteryMeter.h index bf8d2e82a..658cd3f90 100644 --- a/BatteryMeter.h +++ b/BatteryMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_BatteryMeter #define HEADER_BatteryMeter /* diff --git a/CPUMeter.c b/CPUMeter.c index 6131a09d4..b6e4deab1 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -16,24 +16,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Meter.h" - -typedef enum { - CPU_METER_NICE = 0, - CPU_METER_NORMAL = 1, - CPU_METER_KERNEL = 2, - CPU_METER_IRQ = 3, - CPU_METER_SOFTIRQ = 4, - CPU_METER_STEAL = 5, - CPU_METER_GUEST = 6, - CPU_METER_IOWAIT = 7, - CPU_METER_FREQUENCY = 8, - CPU_METER_ITEMCOUNT = 9, // number of entries in this enum -} CPUMeterValues; - -}*/ - int CPUMeter_attributes[] = { CPU_NICE, CPU_NORMAL, CPU_SYSTEM, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT }; diff --git a/CPUMeter.h b/CPUMeter.h index 890e5dba1..56353c691 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_CPUMeter #define HEADER_CPUMeter /* diff --git a/CRT.c b/CRT.c index 0d83bf426..a9147f9af 100644 --- a/CRT.c +++ b/CRT.c @@ -45,110 +45,6 @@ in the source distribution for its full text. //#link curses -/*{ -#include - -typedef enum TreeStr_ { - TREE_STR_HORZ, - TREE_STR_VERT, - TREE_STR_RTEE, - TREE_STR_BEND, - TREE_STR_TEND, - TREE_STR_OPEN, - TREE_STR_SHUT, - TREE_STR_COUNT -} TreeStr; - -typedef enum ColorSchemes_ { - COLORSCHEME_DEFAULT = 0, - COLORSCHEME_MONOCHROME = 1, - COLORSCHEME_BLACKONWHITE = 2, - COLORSCHEME_LIGHTTERMINAL = 3, - COLORSCHEME_MIDNIGHT = 4, - COLORSCHEME_BLACKNIGHT = 5, - COLORSCHEME_BROKENGRAY = 6, - LAST_COLORSCHEME = 7, -} ColorSchemes; - -typedef enum ColorElements_ { - RESET_COLOR, - DEFAULT_COLOR, - FUNCTION_BAR, - FUNCTION_KEY, - FAILED_SEARCH, - PANEL_HEADER_FOCUS, - PANEL_HEADER_UNFOCUS, - PANEL_SELECTION_FOCUS, - PANEL_SELECTION_FOLLOW, - PANEL_SELECTION_UNFOCUS, - LARGE_NUMBER, - METER_TEXT, - METER_VALUE, - LED_COLOR, - UPTIME, - BATTERY, - TASKS_RUNNING, - SWAP, - PROCESS, - PROCESS_SHADOW, - PROCESS_TAG, - PROCESS_MEGABYTES, - PROCESS_TREE, - PROCESS_R_STATE, - PROCESS_D_STATE, - PROCESS_BASENAME, - PROCESS_HIGH_PRIORITY, - PROCESS_LOW_PRIORITY, - PROCESS_THREAD, - PROCESS_THREAD_BASENAME, - BAR_BORDER, - BAR_SHADOW, - GRAPH_1, - GRAPH_2, - MEMORY_USED, - MEMORY_BUFFERS, - MEMORY_BUFFERS_TEXT, - MEMORY_CACHE, - LOAD, - LOAD_AVERAGE_FIFTEEN, - LOAD_AVERAGE_FIVE, - LOAD_AVERAGE_ONE, - CHECK_BOX, - CHECK_MARK, - CHECK_TEXT, - CLOCK, - HELP_BOLD, - HOSTNAME, - CPU_NICE, - CPU_NICE_TEXT, - CPU_NORMAL, - CPU_SYSTEM, - CPU_IOWAIT, - CPU_IRQ, - CPU_SOFTIRQ, - CPU_STEAL, - CPU_GUEST, - PRESSURE_STALL_TEN, - PRESSURE_STALL_SIXTY, - PRESSURE_STALL_THREEHUNDRED, - ZFS_MFU, - ZFS_MRU, - ZFS_ANON, - ZFS_HEADER, - ZFS_OTHER, - ZFS_COMPRESSED, - ZFS_RATIO, - LAST_COLORELEMENT -} ColorElements; - -extern void CRT_fatalError(const char* note) __attribute__ ((noreturn)); - -extern void CRT_handleSIGSEGV(int sgn); - -#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) - -}*/ - const char *CRT_treeStrAscii[TREE_STR_COUNT] = { "-", // TREE_STR_HORZ "|", // TREE_STR_VERT diff --git a/CRT.h b/CRT.h index 7d5c8adfb..351f6397e 100644 --- a/CRT.h +++ b/CRT.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_CRT #define HEADER_CRT /* diff --git a/CategoriesPanel.c b/CategoriesPanel.c index 437f1a7be..8a1e16df4 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -17,22 +17,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Panel.h" -#include "Settings.h" -#include "ScreenManager.h" -#include "ProcessList.h" - -typedef struct CategoriesPanel_ { - Panel super; - ScreenManager* scr; - - Settings* settings; - Header* header; - ProcessList* pl; -} CategoriesPanel; - -}*/ static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/CategoriesPanel.h b/CategoriesPanel.h index 44c6842a0..dd637e7a1 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_CategoriesPanel #define HEADER_CategoriesPanel /* diff --git a/CheckItem.c b/CheckItem.c index 910981e86..d14149ee6 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -12,17 +12,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Object.h" - -typedef struct CheckItem_ { - Object super; - char* text; - bool* ref; - bool value; -} CheckItem; - -}*/ static void CheckItem_delete(Object* cast) { CheckItem* this = (CheckItem*)cast; diff --git a/CheckItem.h b/CheckItem.h index dbd1a039e..f59cc78e8 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_CheckItem #define HEADER_CheckItem /* diff --git a/ClockMeter.c b/ClockMeter.c index 0af886269..3168b3e9a 100644 --- a/ClockMeter.c +++ b/ClockMeter.c @@ -11,9 +11,6 @@ in the source distribution for its full text. #include -/*{ -#include "Meter.h" -}*/ int ClockMeter_attributes[] = { CLOCK diff --git a/ClockMeter.h b/ClockMeter.h index 3e0aef538..e888d585d 100644 --- a/ClockMeter.h +++ b/ClockMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_ClockMeter #define HEADER_ClockMeter /* diff --git a/ColorsPanel.c b/ColorsPanel.c index b2d3500cc..cfd975da4 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -20,19 +20,6 @@ in the source distribution for its full text. // * Add a define in CRT.h that matches the order of the array // * Add the colors in CRT_setColors -/*{ -#include "Panel.h" -#include "Settings.h" -#include "ScreenManager.h" - -typedef struct ColorsPanel_ { - Panel super; - - Settings* settings; - ScreenManager* scr; -} ColorsPanel; - -}*/ static const char* const ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/ColorsPanel.h b/ColorsPanel.h index 82b782b82..337a7f435 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_ColorsPanel #define HEADER_ColorsPanel /* diff --git a/ColumnsPanel.c b/ColumnsPanel.c index de89fa249..587175c81 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -16,18 +16,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Panel.h" -#include "Settings.h" - -typedef struct ColumnsPanel_ { - Panel super; - - Settings* settings; - bool moving; -} ColumnsPanel; - -}*/ static const char* const ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; diff --git a/ColumnsPanel.h b/ColumnsPanel.h index 669dc0272..e3d4bcb91 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_ColumnsPanel #define HEADER_ColumnsPanel /* diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 42375e6ac..cfbaba90a 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -14,19 +14,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Panel.h" -#include "Settings.h" -#include "ScreenManager.h" - -typedef struct DisplayOptionsPanel_ { - Panel super; - - Settings* settings; - ScreenManager* scr; -} DisplayOptionsPanel; - -}*/ static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index d9de40054..b38305415 100644 --- a/DisplayOptionsPanel.h +++ b/DisplayOptionsPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_DisplayOptionsPanel #define HEADER_DisplayOptionsPanel /* diff --git a/EnvScreen.c b/EnvScreen.c index 855023a47..fa6ffdcf7 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -11,13 +11,6 @@ #include #include -/*{ -#include "InfoScreen.h" - -typedef struct EnvScreen_ { - InfoScreen super; -} EnvScreen; -}*/ InfoScreenClass EnvScreen_class = { .super = { diff --git a/EnvScreen.h b/EnvScreen.h index 025cb8d3b..15f7acaae 100644 --- a/EnvScreen.h +++ b/EnvScreen.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_EnvScreen #define HEADER_EnvScreen diff --git a/FunctionBar.c b/FunctionBar.c index 8661bf0c1..e05f72e65 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -14,19 +14,6 @@ in the source distribution for its full text. #include #include -/*{ - -#include - -typedef struct FunctionBar_ { - int size; - char** functions; - char** keys; - int* events; - bool staticData; -} FunctionBar; - -}*/ static const char* const FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL}; diff --git a/FunctionBar.h b/FunctionBar.h index ee5b9347c..09652e8b5 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_FunctionBar #define HEADER_FunctionBar /* diff --git a/Hashtable.c b/Hashtable.c index 3436dad62..bb9517ad2 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -11,26 +11,6 @@ in the source distribution for its full text. #include #include -/*{ -#include - -typedef struct Hashtable_ Hashtable; - -typedef void(*Hashtable_PairFunction)(int, void*, void*); - -typedef struct HashtableItem { - unsigned int key; - void* value; - struct HashtableItem* next; -} HashtableItem; - -struct Hashtable_ { - int size; - HashtableItem** buckets; - int items; - bool owner; -}; -}*/ #ifdef DEBUG diff --git a/Hashtable.h b/Hashtable.h index 32b02188b..651f1648f 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Hashtable #define HEADER_Hashtable /* diff --git a/Header.c b/Header.c index c8cfaabcd..ffd31a244 100644 --- a/Header.c +++ b/Header.c @@ -16,21 +16,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Meter.h" -#include "Settings.h" -#include "Vector.h" - -typedef struct Header_ { - Vector** columns; - Settings* settings; - struct ProcessList_* pl; - int nrColumns; - int pad; - int height; -} Header; - -}*/ #ifndef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) diff --git a/Header.h b/Header.h index f51824540..844d04c94 100644 --- a/Header.h +++ b/Header.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Header #define HEADER_Header /* diff --git a/HostnameMeter.c b/HostnameMeter.c index 4c3b051e4..60bd81250 100644 --- a/HostnameMeter.c +++ b/HostnameMeter.c @@ -11,9 +11,6 @@ in the source distribution for its full text. #include -/*{ -#include "Meter.h" -}*/ int HostnameMeter_attributes[] = { HOSTNAME diff --git a/HostnameMeter.h b/HostnameMeter.h index 3697dff85..ecfab1aae 100644 --- a/HostnameMeter.h +++ b/HostnameMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_HostnameMeter #define HEADER_HostnameMeter /* diff --git a/IncSet.c b/IncSet.c index eaab549c4..90ce8b9fe 100644 --- a/IncSet.c +++ b/IncSet.c @@ -13,39 +13,6 @@ in the source distribution for its full text. #include #include -/*{ - -#include "FunctionBar.h" -#include "Panel.h" -#include - -#define INCMODE_MAX 40 - -typedef enum { - INC_SEARCH = 0, - INC_FILTER = 1 -} IncType; - -#define IncSet_filter(inc_) (inc_->filtering ? inc_->modes[INC_FILTER].buffer : NULL) - -typedef struct IncMode_ { - char buffer[INCMODE_MAX+1]; - int index; - FunctionBar* bar; - bool isFilter; -} IncMode; - -typedef struct IncSet_ { - IncMode modes[2]; - IncMode* active; - FunctionBar* defaultBar; - bool filtering; - bool found; -} IncSet; - -typedef const char* (*IncMode_GetPanelValue)(Panel*, int); - -}*/ static void IncMode_reset(IncMode* mode) { mode->index = 0; diff --git a/IncSet.h b/IncSet.h index 136436e2d..b75b234b0 100644 --- a/IncSet.h +++ b/IncSet.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_IncSet #define HEADER_IncSet /* diff --git a/InfoScreen.c b/InfoScreen.c index 5c586bdd4..8a6a3beeb 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -13,42 +13,6 @@ #include #include -/*{ -#include "Process.h" -#include "Panel.h" -#include "FunctionBar.h" -#include "IncSet.h" - -typedef struct InfoScreen_ InfoScreen; - -typedef void(*InfoScreen_Scan)(InfoScreen*); -typedef void(*InfoScreen_Draw)(InfoScreen*); -typedef void(*InfoScreen_OnErr)(InfoScreen*); -typedef bool(*InfoScreen_OnKey)(InfoScreen*, int); - -typedef struct InfoScreenClass_ { - ObjectClass super; - const InfoScreen_Scan scan; - const InfoScreen_Draw draw; - const InfoScreen_OnErr onErr; - const InfoScreen_OnKey onKey; -} InfoScreenClass; - -#define As_InfoScreen(this_) ((InfoScreenClass*)(((InfoScreen*)(this_))->super.klass)) -#define InfoScreen_scan(this_) As_InfoScreen(this_)->scan((InfoScreen*)(this_)) -#define InfoScreen_draw(this_) As_InfoScreen(this_)->draw((InfoScreen*)(this_)) -#define InfoScreen_onErr(this_) As_InfoScreen(this_)->onErr((InfoScreen*)(this_)) -#define InfoScreen_onKey(this_, ch_) As_InfoScreen(this_)->onKey((InfoScreen*)(this_), ch_) - -struct InfoScreen_ { - Object super; - Process* process; - Panel* display; - FunctionBar* bar; - IncSet* inc; - Vector* lines; -}; -}*/ static const char* const InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL}; diff --git a/InfoScreen.h b/InfoScreen.h index e5d6bb67d..b59527f35 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_InfoScreen #define HEADER_InfoScreen diff --git a/ListItem.c b/ListItem.c index abaf5d0ab..73129fa93 100644 --- a/ListItem.c +++ b/ListItem.c @@ -15,17 +15,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Object.h" - -typedef struct ListItem_ { - Object super; - char* value; - int key; - bool moving; -} ListItem; - -}*/ static void ListItem_delete(Object* cast) { ListItem* this = (ListItem*)cast; diff --git a/ListItem.h b/ListItem.h index 402c5c4ff..3174df098 100644 --- a/ListItem.h +++ b/ListItem.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_ListItem #define HEADER_ListItem /* diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index e29433f14..db397b6ca 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -10,9 +10,6 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -/*{ -#include "Meter.h" -}*/ int LoadAverageMeter_attributes[] = { LOAD_AVERAGE_ONE, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_FIFTEEN diff --git a/LoadAverageMeter.h b/LoadAverageMeter.h index bd18f4d01..83d3c8f58 100644 --- a/LoadAverageMeter.h +++ b/LoadAverageMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_LoadAverageMeter #define HEADER_LoadAverageMeter /* diff --git a/MainPanel.c b/MainPanel.c index 55be17bfd..eb7e663db 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -13,25 +13,6 @@ in the source distribution for its full text. #include -/*{ -#include "Panel.h" -#include "Action.h" -#include "Settings.h" - -typedef struct MainPanel_ { - Panel super; - State* state; - IncSet* inc; - Htop_Action *keys; - pid_t pidSearch; -} MainPanel; - -typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg); - -#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar) - -}*/ - static const char* const MainFunctions[] = {"Help ", "Setup ", "Search ", "Filter ", "Tree ", "SortBy ", "Nice - ", "Nice + ", "Kill ", "Quit ", NULL}; void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) { diff --git a/MainPanel.h b/MainPanel.h index 6162d8e93..cf46a4ee6 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_MainPanel #define HEADER_MainPanel /* diff --git a/Makefile.am b/Makefile.am index d455b4d45..5bf172b0e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = htop dist_man_MANS = htop.1 -EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png scripts/MakeHeader.py \ +EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png \ install-sh autogen.sh missing applicationsdir = $(datadir)/applications applications_DATA = htop.desktop @@ -36,8 +36,6 @@ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \ EnvScreen.h InfoScreen.h XAlloc.h -all_platform_headers = - # Linux # ----- @@ -54,11 +52,9 @@ linux_platform_headers = \ zfs/ZfsCompressedArcMeter.h \ zfs/ZfsArcStats.h -all_platform_headers += $(linux_platform_headers) - if HTOP_LINUX AM_LDFLAGS += -rdynamic -myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ +myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c \ linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \ linux/PressureStallMeter.c \ zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c @@ -80,8 +76,6 @@ freebsd_platform_headers = \ zfs/ZfsArcStats.h \ zfs/openzfs_sysctl.h -all_platform_headers += $(freebsd_platform_headers) - if HTOP_FREEBSD myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c \ @@ -100,8 +94,6 @@ dragonflybsd_platform_headers = \ dragonflybsd/DragonFlyBSDCRT.h \ dragonflybsd/Battery.h -all_platform_headers += $(dragonflybsd_platform_headers) - if HTOP_DRAGONFLYBSD AM_LDFLAGS += -lkvm -lkinfo -lexecinfo myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \ @@ -120,8 +112,6 @@ openbsd_platform_headers = \ openbsd/OpenBSDCRT.h \ openbsd/Battery.h -all_platform_headers += $(openbsd_platform_headers) - if HTOP_OPENBSD myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \ openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c @@ -143,8 +133,6 @@ darwin_platform_headers = \ zfs/ZfsArcStats.h \ zfs/openzfs_sysctl.h -all_platform_headers += $(darwin_platform_headers) - if HTOP_DARWIN AM_LDFLAGS += -framework IOKit -framework CoreFoundation myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \ @@ -167,8 +155,6 @@ solaris_platform_headers = \ zfs/ZfsCompressedArcMeter.h \ zfs/ZfsArcStats.h -all_platform_headers += $(solaris_platform_headers) - if HTOP_SOLARIS myhtopplatsources = solaris/Platform.c \ solaris/SolarisProcess.c solaris/SolarisProcessList.c \ @@ -188,8 +174,6 @@ unsupported_platform_headers = \ unsupported/UnsupportedCRT.h \ unsupported/Battery.h -all_platform_headers += $(unsupported_platform_headers) - if HTOP_UNSUPPORTED myhtopplatsources = unsupported/Platform.c \ unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \ @@ -200,19 +184,9 @@ endif # ---- -SUFFIXES = .h - -BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders) htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) nodist_htop_SOURCES = config.h -.PHONY: htop-headers clean-htop-headers - -htop-headers: $(myhtopheaders) $(all_platform_headers) - -clean-htop-headers: - -rm -f $(myhtopheaders) $(all_platform_headers) - target: echo $(htop_SOURCES) @@ -225,9 +199,6 @@ debug: coverage: $(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" LDFLAGS="-lgcov" -.c.h: - ./scripts/MakeHeader.py $< - cppcheck: cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS diff --git a/MemoryMeter.c b/MemoryMeter.c index 8d5d809e0..91f75b9c2 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -16,9 +16,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Meter.h" -}*/ int MemoryMeter_attributes[] = { MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE diff --git a/MemoryMeter.h b/MemoryMeter.h index 6ddae9233..771aa7359 100644 --- a/MemoryMeter.h +++ b/MemoryMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_MemoryMeter #define HEADER_MemoryMeter /* diff --git a/Meter.c b/Meter.c index 699a78816..ffdfc3e08 100644 --- a/Meter.c +++ b/Meter.c @@ -27,89 +27,6 @@ in the source distribution for its full text. #define GRAPH_HEIGHT 4 /* Unit: rows (lines) */ -/*{ -#include "ListItem.h" - -#include - -typedef struct Meter_ Meter; - -typedef void(*Meter_Init)(Meter*); -typedef void(*Meter_Done)(Meter*); -typedef void(*Meter_UpdateMode)(Meter*, int); -typedef void(*Meter_UpdateValues)(Meter*, char*, int); -typedef void(*Meter_Draw)(Meter*, int, int, int); - -typedef struct MeterClass_ { - ObjectClass super; - const Meter_Init init; - const Meter_Done done; - const Meter_UpdateMode updateMode; - const Meter_Draw draw; - const Meter_UpdateValues updateValues; - const int defaultMode; - const double total; - const int* attributes; - const char* name; - const char* uiName; - const char* caption; - const char* description; - const char maxItems; - char curItems; -} MeterClass; - -#define As_Meter(this_) ((MeterClass*)((this_)->super.klass)) -#define Meter_initFn(this_) As_Meter(this_)->init -#define Meter_init(this_) As_Meter(this_)->init((Meter*)(this_)) -#define Meter_done(this_) As_Meter(this_)->done((Meter*)(this_)) -#define Meter_updateModeFn(this_) As_Meter(this_)->updateMode -#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_) -#define Meter_drawFn(this_) As_Meter(this_)->draw -#define Meter_doneFn(this_) As_Meter(this_)->done -#define Meter_updateValues(this_, buf_, sz_) \ - As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_) -#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode -#define Meter_getItems(this_) As_Meter(this_)->curItems -#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_) -#define Meter_attributes(this_) As_Meter(this_)->attributes -#define Meter_name(this_) As_Meter(this_)->name -#define Meter_uiName(this_) As_Meter(this_)->uiName - -struct Meter_ { - Object super; - Meter_Draw draw; - - char* caption; - int mode; - int param; - void* drawData; - int h; - struct ProcessList_* pl; - double* values; - double total; -}; - -typedef struct MeterMode_ { - Meter_Draw draw; - const char* uiName; - int h; -} MeterMode; - -typedef enum { - CUSTOM_METERMODE = 0, - BAR_METERMODE, - TEXT_METERMODE, - GRAPH_METERMODE, - LED_METERMODE, - LAST_METERMODE -} MeterModeId; - -typedef struct GraphData_ { - struct timeval time; - double values[METER_BUFFER_LEN]; -} GraphData; - -}*/ #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) diff --git a/Meter.h b/Meter.h index 56d46f237..5596f3cc9 100644 --- a/Meter.h +++ b/Meter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Meter #define HEADER_Meter /* diff --git a/MetersPanel.c b/MetersPanel.c index 397a6c7d5..417834a30 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -11,25 +11,6 @@ in the source distribution for its full text. #include #include "CRT.h" -/*{ -#include "Panel.h" -#include "Settings.h" -#include "ScreenManager.h" - -typedef struct MetersPanel_ MetersPanel; - -struct MetersPanel_ { - Panel super; - - Settings* settings; - Vector* meters; - ScreenManager* scr; - MetersPanel* leftNeighbor; - MetersPanel* rightNeighbor; - bool moving; -}; - -}*/ // Note: In code the meters are known to have bar/text/graph "Modes", but in UI // we call them "Styles". diff --git a/MetersPanel.h b/MetersPanel.h index 12eabbe60..111d6ef33 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_MetersPanel #define HEADER_MetersPanel /* diff --git a/Object.c b/Object.c index 5edcc603f..4d8045ddf 100644 --- a/Object.c +++ b/Object.c @@ -8,46 +8,6 @@ in the source distribution for its full text. #include "Object.h" -/*{ -#include "RichString.h" -#include "XAlloc.h" - -typedef struct Object_ Object; - -typedef void(*Object_Display)(Object*, RichString*); -typedef long(*Object_Compare)(const void*, const void*); -typedef void(*Object_Delete)(Object*); - -#define Object_getClass(obj_) ((Object*)(obj_))->klass -#define Object_setClass(obj_, class_) Object_getClass(obj_) = (ObjectClass*) class_ - -#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_)) -#define Object_displayFn(obj_) Object_getClass(obj_)->display -#define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_) -#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_) - -#define Class(class_) ((ObjectClass*)(&(class_ ## _class))) - -#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); - -typedef struct ObjectClass_ { - const void* extends; - const Object_Display display; - const Object_Delete delete; - const Object_Compare compare; -} ObjectClass; - -struct Object_ { - ObjectClass* klass; -}; - -typedef union { - int i; - void* v; -} Arg; - -}*/ - ObjectClass Object_class = { .extends = NULL }; diff --git a/Object.h b/Object.h index 9be948f83..046447a77 100644 --- a/Object.h +++ b/Object.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Object #define HEADER_Object /* diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 658b1866d..3e45bf85a 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -23,30 +23,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "InfoScreen.h" - -typedef struct OpenFiles_Data_ { - char* data[256]; -} OpenFiles_Data; - -typedef struct OpenFiles_ProcessData_ { - OpenFiles_Data data; - int error; - struct OpenFiles_FileData_* files; -} OpenFiles_ProcessData; - -typedef struct OpenFiles_FileData_ { - OpenFiles_Data data; - struct OpenFiles_FileData_* next; -} OpenFiles_FileData; - -typedef struct OpenFilesScreen_ { - InfoScreen super; - pid_t pid; -} OpenFilesScreen; - -}*/ InfoScreenClass OpenFilesScreen_class = { .super = { diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index 39c71d5b4..5f4d35749 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_OpenFilesScreen #define HEADER_OpenFilesScreen /* diff --git a/Panel.c b/Panel.c index 348fd2381..297dc89c7 100644 --- a/Panel.c +++ b/Panel.c @@ -21,60 +21,6 @@ in the source distribution for its full text. //#link curses -/*{ -#include "Object.h" -#include "Vector.h" -#include "FunctionBar.h" - -typedef struct Panel_ Panel; - -typedef enum HandlerResult_ { - HANDLED = 0x01, - IGNORED = 0x02, - BREAK_LOOP = 0x04, - REDRAW = 0x08, - RESCAN = 0x10, - SYNTH_KEY = 0x20, -} HandlerResult; - -#define EVENT_SET_SELECTED -1 - -#define EVENT_HEADER_CLICK(x_) (-10000 + x_) -#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ <= -9000) -#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000) - -typedef HandlerResult(*Panel_EventHandler)(Panel*, int); - -typedef struct PanelClass_ { - const ObjectClass super; - const Panel_EventHandler eventHandler; -} PanelClass; - -#define As_Panel(this_) ((PanelClass*)((this_)->super.klass)) -#define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler -#define Panel_eventHandler(this_, ev_) As_Panel(this_)->eventHandler((Panel*)(this_), ev_) - -struct Panel_ { - Object super; - int x, y, w, h; - WINDOW* window; - Vector* items; - int selected; - int oldSelected; - int selectedLen; - void* eventHandlerState; - int scrollV; - short scrollH; - bool needsRedraw; - FunctionBar* currentBar; - FunctionBar* defaultBar; - RichString header; - int selectionColor; -}; - -#define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0) - -}*/ #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) diff --git a/Panel.h b/Panel.h index 4b517f311..aedc98b53 100644 --- a/Panel.h +++ b/Panel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Panel #define HEADER_Panel /* diff --git a/Process.c b/Process.c index 6a0d56b9a..e7ab4929b 100644 --- a/Process.c +++ b/Process.c @@ -49,145 +49,6 @@ in the source distribution for its full text. #endif #define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K ) -/*{ -#include "Object.h" - -#include - -#define PROCESS_FLAG_IO 0x0001 - -typedef enum ProcessFields { - NULL_PROCESSFIELD = 0, - PID = 1, - COMM = 2, - STATE = 3, - PPID = 4, - PGRP = 5, - SESSION = 6, - TTY_NR = 7, - TPGID = 8, - MINFLT = 10, - MAJFLT = 12, - PRIORITY = 18, - NICE = 19, - STARTTIME = 21, - PROCESSOR = 38, - M_SIZE = 39, - M_RESIDENT = 40, - ST_UID = 46, - PERCENT_CPU = 47, - PERCENT_MEM = 48, - USER = 49, - TIME = 50, - NLWP = 51, - TGID = 52, -} ProcessField; - -typedef struct ProcessPidColumn_ { - int id; - const char* label; -} ProcessPidColumn; - -typedef struct Process_ { - Object super; - - struct Settings_* settings; - - unsigned long long int time; - pid_t pid; - pid_t ppid; - pid_t tgid; - char* comm; - int commLen; - int indent; - - int basenameOffset; - bool updated; - - char state; - bool tag; - bool showChildren; - bool show; - unsigned int pgrp; - unsigned int session; - unsigned int tty_nr; - int tpgid; - uid_t st_uid; - unsigned long int flags; - int processor; - - float percent_cpu; - float percent_mem; - char* user; - - long int priority; - long int nice; - long int nlwp; - char starttime_show[8]; - time_t starttime_ctime; - - long m_size; - long m_resident; - - int exit_signal; - - unsigned long int minflt; - unsigned long int majflt; - #ifdef DEBUG - long int itrealvalue; - unsigned long int vsize; - long int rss; - unsigned long int rlim; - unsigned long int startcode; - unsigned long int endcode; - unsigned long int startstack; - unsigned long int kstkesp; - unsigned long int kstkeip; - unsigned long int signal; - unsigned long int blocked; - unsigned long int sigignore; - unsigned long int sigcatch; - unsigned long int wchan; - unsigned long int nswap; - unsigned long int cnswap; - #endif - -} Process; - -typedef struct ProcessFieldData_ { - const char* name; - const char* title; - const char* description; - int flags; -} ProcessFieldData; - -// Implemented in platform-specific code: -void Process_writeField(Process* this, RichString* str, ProcessField field); -long Process_compare(const void* v1, const void* v2); -void Process_delete(Object* cast); -bool Process_isThread(Process* this); -extern ProcessFieldData Process_fields[]; -extern ProcessPidColumn Process_pidColumns[]; -extern char Process_pidFormat[20]; - -typedef Process*(*Process_New)(struct Settings_*); -typedef void (*Process_WriteField)(Process*, RichString*, ProcessField); - -typedef struct ProcessClass_ { - const ObjectClass super; - const Process_WriteField writeField; -} ProcessClass; - -#define As_Process(this_) ((ProcessClass*)((this_)->super.klass)) - -#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid) - -#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_)) - -#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state)) - -}*/ - static int Process_getuid = -1; #define ONE_K 1024L diff --git a/Process.h b/Process.h index 3085f1648..d82724dd8 100644 --- a/Process.h +++ b/Process.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Process #define HEADER_Process /* diff --git a/ProcessList.c b/ProcessList.c index 36b494e29..025c87afc 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -14,69 +14,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Vector.h" -#include "Hashtable.h" -#include "UsersTable.h" -#include "Panel.h" -#include "Process.h" -#include "Settings.h" - -#ifdef HAVE_LIBHWLOC -#include -#endif - -#ifndef MAX_NAME -#define MAX_NAME 128 -#endif - -#ifndef MAX_READ -#define MAX_READ 2048 -#endif - -typedef struct ProcessList_ { - Settings* settings; - - Vector* processes; - Vector* processes2; - Hashtable* processTable; - UsersTable* usersTable; - - Panel* panel; - int following; - uid_t userId; - const char* incFilter; - Hashtable* pidWhiteList; - - #ifdef HAVE_LIBHWLOC - hwloc_topology_t topology; - bool topologyOk; - #endif - - int totalTasks; - int runningTasks; - int userlandThreads; - int kernelThreads; - - unsigned long long int totalMem; - unsigned long long int usedMem; - unsigned long long int freeMem; - unsigned long long int sharedMem; - unsigned long long int buffersMem; - unsigned long long int cachedMem; - unsigned long long int totalSwap; - unsigned long long int usedSwap; - unsigned long long int freeSwap; - - int cpuCount; - -} ProcessList; - -ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId); -void ProcessList_delete(ProcessList* pl); -void ProcessList_goThroughEntries(ProcessList* pl); - -}*/ ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { this->processes = Vector_new(klass, true, DEFAULT_SIZE); diff --git a/ProcessList.h b/ProcessList.h index ddc6f3fa8..1a4170c0c 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_ProcessList #define HEADER_ProcessList /* diff --git a/RichString.c b/RichString.c index d246f1e1b..702ab329f 100644 --- a/RichString.c +++ b/RichString.c @@ -13,55 +13,6 @@ in the source distribution for its full text. #define RICHSTRING_MAXLEN 350 -/*{ -#include "config.h" -#include - -#include -#ifdef HAVE_NCURSESW_CURSES_H -#include -#elif HAVE_NCURSES_NCURSES_H -#include -#elif HAVE_NCURSES_CURSES_H -#include -#elif HAVE_NCURSES_H -#include -#elif HAVE_CURSES_H -#include -#endif - -#ifdef HAVE_LIBNCURSESW -#include -#endif - -#define RichString_size(this) ((this)->chlen) -#define RichString_sizeVal(this) ((this).chlen) - -#define RichString_begin(this) RichString (this); memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr; -#define RichString_beginAllocated(this) memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr; -#define RichString_end(this) RichString_prune(&(this)); - -#ifdef HAVE_LIBNCURSESW -#define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) -#define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + off, n) -#define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255) -#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) -#define CharType cchar_t -#else -#define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr) -#define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + off, n) -#define RichString_getCharVal(this, i) ((this).chptr[i]) -#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = ch; } while(0) -#define CharType chtype -#endif - -typedef struct RichString_ { - int chlen; - CharType* chptr; - CharType chstr[RICHSTRING_MAXLEN+1]; -} RichString; - -}*/ #ifndef CLAMP #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) diff --git a/RichString.h b/RichString.h index d6fa63540..824c0e2aa 100644 --- a/RichString.h +++ b/RichString.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_RichString #define HEADER_RichString /* diff --git a/ScreenManager.c b/ScreenManager.c index 8e5f697f6..24d292dd0 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -16,33 +16,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "FunctionBar.h" -#include "Vector.h" -#include "Header.h" -#include "Settings.h" -#include "Panel.h" - -typedef enum Orientation_ { - VERTICAL, - HORIZONTAL -} Orientation; - -typedef struct ScreenManager_ { - int x1; - int y1; - int x2; - int y2; - Orientation orientation; - Vector* panels; - int panelCount; - const Header* header; - const Settings* settings; - bool owner; - bool allowFocusChange; -} ScreenManager; - -}*/ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner) { ScreenManager* this; diff --git a/ScreenManager.h b/ScreenManager.h index b7b5617b1..eaa908534 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_ScreenManager #define HEADER_ScreenManager /* diff --git a/Settings.c b/Settings.c index 81d547bed..104d9bb99 100644 --- a/Settings.c +++ b/Settings.c @@ -19,62 +19,6 @@ in the source distribution for its full text. #define DEFAULT_DELAY 15 -/*{ -#include "Process.h" -#include - -typedef struct { - int len; - char** names; - int* modes; -} MeterColumnSettings; - -typedef struct Settings_ { - char* filename; - - MeterColumnSettings columns[2]; - - ProcessField* fields; - int flags; - int colorScheme; - int delay; - - int cpuCount; - int direction; - ProcessField sortKey; - - bool countCPUsFromZero; - bool detailedCPUTime; - bool showCPUUsage; - bool showCPUFrequency; - bool treeView; - bool showProgramPath; - bool hideThreads; - bool shadowOtherUsers; - bool showThreadNames; - bool hideKernelThreads; - bool hideUserlandThreads; - bool highlightBaseName; - bool highlightMegabytes; - bool highlightThreads; - bool updateProcessNames; - bool accountGuestInCPUMeter; - bool headerMargin; - bool enableMouse; - bool vimMode; - #ifdef HAVE_LIBHWLOC - bool topologyAffinity; - #endif - - bool changed; -} Settings; - -#ifndef Settings_cpuId -#define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromZero ? (cpu) : (cpu)+1) -#endif - -}*/ - void Settings_delete(Settings* this) { free(this->filename); free(this->fields); diff --git a/Settings.h b/Settings.h index f38b8ecd4..23f5e7c1b 100644 --- a/Settings.h +++ b/Settings.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Settings #define HEADER_Settings /* diff --git a/SignalsPanel.c b/SignalsPanel.c index 2bfbcbf2b..8036142f8 100644 --- a/SignalsPanel.c +++ b/SignalsPanel.c @@ -18,14 +18,6 @@ in the source distribution for its full text. #include -/*{ - -typedef struct SignalItem_ { - const char* name; - int number; -} SignalItem; - -}*/ Panel* SignalsPanel_new() { Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Send ", "Cancel ")); diff --git a/SignalsPanel.h b/SignalsPanel.h index 8720376a7..a3991fd91 100644 --- a/SignalsPanel.h +++ b/SignalsPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_SignalsPanel #define HEADER_SignalsPanel /* diff --git a/StringUtils.c b/StringUtils.c index d7058a283..6bae8227a 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -14,12 +14,6 @@ in the source distribution for its full text. #include #include -/*{ -#include - -#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) -#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL) -}*/ /* * String_startsWith gives better performance if strlen(match) can be computed diff --git a/StringUtils.h b/StringUtils.h index c1070d4fe..0450f0df9 100644 --- a/StringUtils.h +++ b/StringUtils.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_StringUtils #define HEADER_StringUtils /* diff --git a/SwapMeter.c b/SwapMeter.c index 1406d6fb0..fcf450eed 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -16,9 +16,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Meter.h" -}*/ int SwapMeter_attributes[] = { SWAP diff --git a/SwapMeter.h b/SwapMeter.h index 2b57fe548..69a5855f5 100644 --- a/SwapMeter.h +++ b/SwapMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_SwapMeter #define HEADER_SwapMeter /* diff --git a/TasksMeter.c b/TasksMeter.c index 8a913ec06..49816bdb2 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -10,9 +10,6 @@ in the source distribution for its full text. #include "Platform.h" #include "CRT.h" -/*{ -#include "Meter.h" -}*/ int TasksMeter_attributes[] = { CPU_SYSTEM, PROCESS_THREAD, PROCESS, TASKS_RUNNING diff --git a/TasksMeter.h b/TasksMeter.h index a7a0db701..bdb62a739 100644 --- a/TasksMeter.h +++ b/TasksMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_TasksMeter #define HEADER_TasksMeter /* diff --git a/TraceScreen.c b/TraceScreen.c index b4b8436b1..99b56a05c 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -27,21 +27,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "InfoScreen.h" - -typedef struct TraceScreen_ { - InfoScreen super; - bool tracing; - int fdpair[2]; - int child; - FILE* strace; - int fd_strace; - bool contLine; - bool follow; -} TraceScreen; - -}*/ static const char* const TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL}; diff --git a/TraceScreen.h b/TraceScreen.h index d43281d91..18920405f 100644 --- a/TraceScreen.h +++ b/TraceScreen.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_TraceScreen #define HEADER_TraceScreen /* diff --git a/UptimeMeter.c b/UptimeMeter.c index 61f60905b..da1c9fd01 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -9,9 +9,6 @@ in the source distribution for its full text. #include "Platform.h" #include "CRT.h" -/*{ -#include "Meter.h" -}*/ int UptimeMeter_attributes[] = { UPTIME diff --git a/UptimeMeter.h b/UptimeMeter.h index fe0bbba94..5fa1e9310 100644 --- a/UptimeMeter.h +++ b/UptimeMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_UptimeMeter #define HEADER_UptimeMeter /* diff --git a/UsersTable.c b/UsersTable.c index f383256a9..86ed75c88 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -18,13 +18,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Hashtable.h" - -typedef struct UsersTable_ { - Hashtable* users; -} UsersTable; -}*/ UsersTable* UsersTable_new() { UsersTable* this; diff --git a/UsersTable.h b/UsersTable.h index 9eba59ad0..6113277ff 100644 --- a/UsersTable.h +++ b/UsersTable.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_UsersTable #define HEADER_UsersTable /* diff --git a/Vector.c b/Vector.c index b5e774466..e7776ea3c 100644 --- a/Vector.c +++ b/Vector.c @@ -12,25 +12,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Object.h" - -#define swap(a_,x_,y_) do{ void* tmp_ = a_[x_]; a_[x_] = a_[y_]; a_[y_] = tmp_; }while(0) - -#ifndef DEFAULT_SIZE -#define DEFAULT_SIZE -1 -#endif - -typedef struct Vector_ { - Object **array; - ObjectClass* type; - int arraySize; - int growthRate; - int items; - bool owner; -} Vector; - -}*/ Vector* Vector_new(ObjectClass* type, bool owner, int size) { Vector* this; diff --git a/Vector.h b/Vector.h index 0d9f1c2c8..7286bf658 100644 --- a/Vector.h +++ b/Vector.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Vector #define HEADER_Vector /* diff --git a/XAlloc.c b/XAlloc.c index 4aa8e217d..38616dfc3 100644 --- a/XAlloc.c +++ b/XAlloc.c @@ -8,11 +8,6 @@ #include #include -/*{ -#include -#include -#include -}*/ void fail() { curs_set(1); diff --git a/XAlloc.h b/XAlloc.h index 2d4640516..f67bf0dcb 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_XAlloc #define HEADER_XAlloc diff --git a/configure.ac b/configure.ac index f6498b7e3..5331d9024 100644 --- a/configure.ac +++ b/configure.ac @@ -316,7 +316,6 @@ AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris]) AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported]) AC_SUBST(my_htop_platform) AC_CONFIG_FILES([Makefile htop.1]) -AC_CONFIG_FILES([scripts/MakeHeader.py], [chmod +x scripts/MakeHeader.py]) AC_OUTPUT if test "$my_htop_platform" = "unsupported" diff --git a/darwin/Battery.h b/darwin/Battery.h index 8dc0cef6d..24d8f5c2d 100644 --- a/darwin/Battery.h +++ b/darwin/Battery.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Battery #define HEADER_Battery diff --git a/darwin/DarwinCRT.h b/darwin/DarwinCRT.h index e1c22bbdc..d79e34c84 100644 --- a/darwin/DarwinCRT.h +++ b/darwin/DarwinCRT.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_DarwinCRT #define HEADER_DarwinCRT /* diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index bf5fd5771..430b2b494 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -15,21 +15,6 @@ in the source distribution for its full text. #include -/*{ -#include "Settings.h" -#include "DarwinProcessList.h" - -#include - -typedef struct DarwinProcess_ { - Process super; - - uint64_t utime; - uint64_t stime; - bool taskAccess; -} DarwinProcess; - -}*/ ProcessClass DarwinProcess_class = { .super = { diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index c2058e21c..f885ccc58 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_DarwinProcess #define HEADER_DarwinProcess /* diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 9b4ba119d..cedabc9d6 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -54,28 +54,6 @@ int CompareKernelVersion(short int major, short int minor, short int component) return 0; } -/*{ -#include "ProcessList.h" -#include "zfs/ZfsArcStats.h" -#include -#include - -typedef struct DarwinProcessList_ { - ProcessList super; - - host_basic_info_data_t host_info; - vm_statistics_data_t vm_stats; - processor_cpu_load_info_t prev_load; - processor_cpu_load_info_t curr_load; - uint64_t kernel_threads; - uint64_t user_threads; - uint64_t global_diff; - - ZfsArcStats zfs; -} DarwinProcessList; - -}*/ - void ProcessList_getHostInfo(host_basic_info_data_t *p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index 73fbd34fe..d6c332768 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_DarwinProcessList #define HEADER_DarwinProcessList /* diff --git a/darwin/Platform.c b/darwin/Platform.c index 26e84112e..f8007d826 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -21,13 +21,6 @@ in the source distribution for its full text. #include -/*{ -#include "Action.h" -#include "SignalsPanel.h" -#include "CPUMeter.h" -#include "BatteryMeter.h" -#include "DarwinProcess.h" -}*/ #ifndef CLAMP #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) diff --git a/darwin/Platform.h b/darwin/Platform.h index e17661d61..5ce23684f 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Platform #define HEADER_Platform /* diff --git a/dragonflybsd/Battery.h b/dragonflybsd/Battery.h index efb44a8eb..f764a2dc8 100644 --- a/dragonflybsd/Battery.h +++ b/dragonflybsd/Battery.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Battery #define HEADER_Battery /* diff --git a/dragonflybsd/DragonFlyBSDCRT.h b/dragonflybsd/DragonFlyBSDCRT.h index b934ac328..2b98effbf 100644 --- a/dragonflybsd/DragonFlyBSDCRT.h +++ b/dragonflybsd/DragonFlyBSDCRT.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_DragonFlyBSDCRT #define HEADER_DragonFlyBSDCRT /* diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index ffaf5eb67..770143b0e 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -17,34 +17,6 @@ in the source distribution for its full text. #include #include -/*{ - -typedef enum DragonFlyBSDProcessFields { - // Add platform-specific fields here, with ids >= 100 - JID = 100, - JAIL = 101, - LAST_PROCESSFIELD = 102, -} DragonFlyBSDProcessField; - - -typedef struct DragonFlyBSDProcess_ { - Process super; - int kernel; - int jid; - char* jname; -} DragonFlyBSDProcess; - - -#ifndef Process_isKernelThread -#define Process_isKernelThread(_process) (_process->kernel == 1) -#endif - -#ifndef Process_isUserlandThread -//#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -#define Process_isUserlandThread(_process) (_process->nlwp > 1) -#endif - -}*/ ProcessClass DragonFlyBSDProcess_class = { .super = { diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h index 4a0f9a5a3..a0381c675 100644 --- a/dragonflybsd/DragonFlyBSDProcess.h +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_DragonFlyBSDProcess #define HEADER_DragonFlyBSDProcess /* diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 5bc4b3841..d77f12eb4 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -21,54 +21,6 @@ in the source distribution for its full text. #include #include -/*{ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "Hashtable.h" -#include "DragonFlyBSDProcess.h" - -#define JAIL_ERRMSGLEN 1024 -char jail_errmsg[JAIL_ERRMSGLEN]; - -typedef struct CPUData_ { - - double userPercent; - double nicePercent; - double systemPercent; - double irqPercent; - double idlePercent; - double systemAllPercent; - -} CPUData; - -typedef struct DragonFlyBSDProcessList_ { - ProcessList super; - kvm_t* kd; - - unsigned long long int memWire; - unsigned long long int memActive; - unsigned long long int memInactive; - unsigned long long int memFree; - - CPUData* cpus; - - unsigned long *cp_time_o; - unsigned long *cp_time_n; - - unsigned long *cp_times_o; - unsigned long *cp_times_n; - - Hashtable *jails; -} DragonFlyBSDProcessList; - -}*/ #define _UNUSED_ __attribute__((unused)) diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index 816e66d6e..f677c3e4a 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_DragonFlyBSDProcessList #define HEADER_DragonFlyBSDProcessList /* diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 250e50e76..84f137078 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -27,14 +27,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Action.h" -#include "BatteryMeter.h" -#include "SignalsPanel.h" - -extern ProcessFieldData Process_fields[]; - -}*/ #ifndef CLAMP #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index c2684f340..aa00d6564 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Platform #define HEADER_Platform /* diff --git a/freebsd/Battery.h b/freebsd/Battery.h index cc5b1fed8..6987d78bc 100644 --- a/freebsd/Battery.h +++ b/freebsd/Battery.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Battery #define HEADER_Battery /* diff --git a/freebsd/FreeBSDCRT.h b/freebsd/FreeBSDCRT.h index eb1091a9b..d0c216598 100644 --- a/freebsd/FreeBSDCRT.h +++ b/freebsd/FreeBSDCRT.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_FreeBSDCRT #define HEADER_FreeBSDCRT /* diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index c8d30f693..33dc75160 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -16,33 +16,6 @@ in the source distribution for its full text. #include #include -/*{ - -typedef enum FreeBSDProcessFields { - // Add platform-specific fields here, with ids >= 100 - JID = 100, - JAIL = 101, - LAST_PROCESSFIELD = 102, -} FreeBSDProcessField; - - -typedef struct FreeBSDProcess_ { - Process super; - int kernel; - int jid; - char* jname; -} FreeBSDProcess; - - -#ifndef Process_isKernelThread -#define Process_isKernelThread(_process) (_process->kernel == 1) -#endif - -#ifndef Process_isUserlandThread -#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -#endif - -}*/ ProcessClass FreeBSDProcess_class = { .super = { diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index 23d298a31..b269b7798 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_FreeBSDProcess #define HEADER_FreeBSDProcess /* diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index fd88a5636..344c33141 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -22,53 +22,6 @@ in the source distribution for its full text. #include #include -/*{ - -#include "zfs/ZfsArcStats.h" - -#include -#include -#include -#include -#include - -#define JAIL_ERRMSGLEN 1024 -extern char jail_errmsg[JAIL_ERRMSGLEN]; - -typedef struct CPUData_ { - - double userPercent; - double nicePercent; - double systemPercent; - double irqPercent; - double idlePercent; - double systemAllPercent; - -} CPUData; - -typedef struct FreeBSDProcessList_ { - ProcessList super; - kvm_t* kd; - - unsigned long long int memWire; - unsigned long long int memActive; - unsigned long long int memInactive; - unsigned long long int memFree; - - ZfsArcStats zfs; - - CPUData* cpus; - - unsigned long *cp_time_o; - unsigned long *cp_time_n; - - unsigned long *cp_times_o; - unsigned long *cp_times_n; - -} FreeBSDProcessList; - -}*/ - char jail_errmsg[JAIL_ERRMSGLEN]; static int MIB_hw_physmem[2]; diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 7bfcf427a..d01659dac 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_FreeBSDProcessList #define HEADER_FreeBSDProcessList /* diff --git a/freebsd/Platform.c b/freebsd/Platform.c index e6acebdb7..58a9bf1b1 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -28,14 +28,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Action.h" -#include "BatteryMeter.h" -#include "SignalsPanel.h" - -extern ProcessFieldData Process_fields[]; - -}*/ #ifndef CLAMP #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 0268f2c64..f453e68ef 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Platform #define HEADER_Platform /* diff --git a/htop.h b/htop.h index 26c191806..ced66de23 100644 --- a/htop.h +++ b/htop.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_htop #define HEADER_htop /* diff --git a/linux/Battery.h b/linux/Battery.h index 261cff056..d52b08c96 100644 --- a/linux/Battery.h +++ b/linux/Battery.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Battery #define HEADER_Battery /* diff --git a/linux/IOPriority.c b/linux/IOPriority.c deleted file mode 100644 index 087f7f980..000000000 --- a/linux/IOPriority.c +++ /dev/null @@ -1,40 +0,0 @@ -/* -htop - IOPriority.c -(C) 2004-2012 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file -in the source distribution for its full text. - -Based on ionice, -Copyright (C) 2005 Jens Axboe -Released under the terms of the GNU General Public License version 2 -*/ - -#include "IOPriority.h" - -/*{ - -enum { - IOPRIO_CLASS_NONE, - IOPRIO_CLASS_RT, - IOPRIO_CLASS_BE, - IOPRIO_CLASS_IDLE, -}; - -#define IOPRIO_WHO_PROCESS 1 - -#define IOPRIO_CLASS_SHIFT (13) -#define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1) - -#define IOPriority_class(ioprio_) ((int) ((ioprio_) >> IOPRIO_CLASS_SHIFT) ) -#define IOPriority_data(ioprio_) ((int) ((ioprio_) & IOPRIO_PRIO_MASK) ) - -typedef int IOPriority; - -#define IOPriority_tuple(class_, data_) (((class_) << IOPRIO_CLASS_SHIFT) | data_) - -#define IOPriority_error 0xffffffff - -#define IOPriority_None IOPriority_tuple(IOPRIO_CLASS_NONE, 0) -#define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 7) - -}*/ diff --git a/linux/IOPriority.h b/linux/IOPriority.h index a4733e890..4e2c379e8 100644 --- a/linux/IOPriority.h +++ b/linux/IOPriority.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_IOPriority #define HEADER_IOPriority /* diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index 22735bba2..ebb77bf78 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -7,11 +7,6 @@ in the source distribution for its full text. #include "IOPriorityPanel.h" -/*{ -#include "Panel.h" -#include "IOPriority.h" -#include "ListItem.h" -}*/ Panel* IOPriorityPanel_new(IOPriority currPrio) { Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Set ", "Cancel ")); diff --git a/linux/IOPriorityPanel.h b/linux/IOPriorityPanel.h index 906296ed0..5019d59ac 100644 --- a/linux/IOPriorityPanel.h +++ b/linux/IOPriorityPanel.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_IOPriorityPanel #define HEADER_IOPriorityPanel /* diff --git a/linux/LinuxCRT.h b/linux/LinuxCRT.h index 966dfecf4..f4f8cf069 100644 --- a/linux/LinuxCRT.h +++ b/linux/LinuxCRT.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_LinuxCRT #define HEADER_LinuxCRT /* diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 5970c9389..377aa5bb8 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -18,150 +18,6 @@ in the source distribution for its full text. #include #include -/*{ - -#define PROCESS_FLAG_LINUX_IOPRIO 0x0100 -#define PROCESS_FLAG_LINUX_OPENVZ 0x0200 -#define PROCESS_FLAG_LINUX_VSERVER 0x0400 -#define PROCESS_FLAG_LINUX_CGROUP 0x0800 -#define PROCESS_FLAG_LINUX_OOM 0x1000 -#define PROCESS_FLAG_LINUX_SMAPS 0x2000 - -typedef enum UnsupportedProcessFields { - FLAGS = 9, - ITREALVALUE = 20, - VSIZE = 22, - RSS = 23, - RLIM = 24, - STARTCODE = 25, - ENDCODE = 26, - STARTSTACK = 27, - KSTKESP = 28, - KSTKEIP = 29, - SIGNAL = 30, - BLOCKED = 31, - SSIGIGNORE = 32, - SIGCATCH = 33, - WCHAN = 34, - NSWAP = 35, - CNSWAP = 36, - EXIT_SIGNAL = 37, -} UnsupportedProcessField; - -typedef enum LinuxProcessFields { - CMINFLT = 11, - CMAJFLT = 13, - UTIME = 14, - STIME = 15, - CUTIME = 16, - CSTIME = 17, - M_SHARE = 41, - M_TRS = 42, - M_DRS = 43, - M_LRS = 44, - M_DT = 45, - #ifdef HAVE_OPENVZ - CTID = 100, - VPID = 101, - #endif - #ifdef HAVE_VSERVER - VXID = 102, - #endif - #ifdef HAVE_TASKSTATS - RCHAR = 103, - WCHAR = 104, - SYSCR = 105, - SYSCW = 106, - RBYTES = 107, - WBYTES = 108, - CNCLWB = 109, - IO_READ_RATE = 110, - IO_WRITE_RATE = 111, - IO_RATE = 112, - #endif - #ifdef HAVE_CGROUP - CGROUP = 113, - #endif - OOM = 114, - IO_PRIORITY = 115, - #ifdef HAVE_DELAYACCT - PERCENT_CPU_DELAY = 116, - PERCENT_IO_DELAY = 117, - PERCENT_SWAP_DELAY = 118, - #endif - M_PSS = 119, - M_SWAP = 120, - M_PSSWP = 121, - LAST_PROCESSFIELD = 122, -} LinuxProcessField; - -#include "IOPriority.h" - -typedef struct LinuxProcess_ { - Process super; - bool isKernelThread; - IOPriority ioPriority; - unsigned long int cminflt; - unsigned long int cmajflt; - unsigned long long int utime; - unsigned long long int stime; - unsigned long long int cutime; - unsigned long long int cstime; - long m_share; - long m_pss; - long m_swap; - long m_psswp; - long m_trs; - long m_drs; - long m_lrs; - long m_dt; - unsigned long long starttime; - #ifdef HAVE_TASKSTATS - unsigned long long io_rchar; - unsigned long long io_wchar; - unsigned long long io_syscr; - unsigned long long io_syscw; - unsigned long long io_read_bytes; - unsigned long long io_write_bytes; - unsigned long long io_cancelled_write_bytes; - unsigned long long io_rate_read_time; - unsigned long long io_rate_write_time; - double io_rate_read_bps; - double io_rate_write_bps; - #endif - #ifdef HAVE_OPENVZ - unsigned int ctid; - unsigned int vpid; - #endif - #ifdef HAVE_VSERVER - unsigned int vxid; - #endif - #ifdef HAVE_CGROUP - char* cgroup; - #endif - unsigned int oom; - char* ttyDevice; - #ifdef HAVE_DELAYACCT - unsigned long long int delay_read_time; - unsigned long long cpu_delay_total; - unsigned long long blkio_delay_total; - unsigned long long swapin_delay_total; - float cpu_delay_percent; - float blkio_delay_percent; - float swapin_delay_percent; - #endif -} LinuxProcess; - -#ifndef Process_isKernelThread -#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread) -#endif - -#ifndef Process_isUserlandThread -#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -#endif - -}*/ - /* semi-global */ long long btime; diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 7c0a11f86..462ae6bc1 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_LinuxProcess #define HEADER_LinuxProcess /* diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 732a86b70..a6fdada87 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -42,95 +42,6 @@ in the source distribution for its full text. #include #endif -/*{ - -#include "ProcessList.h" -#include "zfs/ZfsArcStats.h" - -extern long long btime; - -typedef struct CPUData_ { - unsigned long long int totalTime; - unsigned long long int userTime; - unsigned long long int systemTime; - unsigned long long int systemAllTime; - unsigned long long int idleAllTime; - unsigned long long int idleTime; - unsigned long long int niceTime; - unsigned long long int ioWaitTime; - unsigned long long int irqTime; - unsigned long long int softIrqTime; - unsigned long long int stealTime; - unsigned long long int guestTime; - - unsigned long long int totalPeriod; - unsigned long long int userPeriod; - unsigned long long int systemPeriod; - unsigned long long int systemAllPeriod; - unsigned long long int idleAllPeriod; - unsigned long long int idlePeriod; - unsigned long long int nicePeriod; - unsigned long long int ioWaitPeriod; - unsigned long long int irqPeriod; - unsigned long long int softIrqPeriod; - unsigned long long int stealPeriod; - unsigned long long int guestPeriod; - - double frequency; -} CPUData; - -typedef struct TtyDriver_ { - char* path; - unsigned int major; - unsigned int minorFrom; - unsigned int minorTo; -} TtyDriver; - -typedef struct LinuxProcessList_ { - ProcessList super; - - CPUData* cpus; - TtyDriver* ttyDrivers; - bool haveSmapsRollup; - - #ifdef HAVE_DELAYACCT - struct nl_sock *netlink_socket; - int netlink_family; - #endif - - ZfsArcStats zfs; -} LinuxProcessList; - -#ifndef PROCDIR -#define PROCDIR "/proc" -#endif - -#ifndef PROCCPUINFOFILE -#define PROCCPUINFOFILE PROCDIR "/cpuinfo" -#endif - -#ifndef PROCSTATFILE -#define PROCSTATFILE PROCDIR "/stat" -#endif - -#ifndef PROCMEMINFOFILE -#define PROCMEMINFOFILE PROCDIR "/meminfo" -#endif - -#ifndef PROCARCSTATSFILE -#define PROCARCSTATSFILE PROCDIR "/spl/kstat/zfs/arcstats" -#endif - -#ifndef PROCTTYDRIVERSFILE -#define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers" -#endif - -#ifndef PROC_LINE_LENGTH -#define PROC_LINE_LENGTH 4096 -#endif - -}*/ - #ifndef CLAMP #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #endif diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 86e9d3fd9..4a0e02064 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_LinuxProcessList #define HEADER_LinuxProcessList /* diff --git a/linux/Platform.c b/linux/Platform.c index 0f59fed65..d48dc7642 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -32,13 +32,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Action.h" -#include "MainPanel.h" -#include "BatteryMeter.h" -#include "LinuxProcess.h" -#include "SignalsPanel.h" -}*/ #ifndef CLAMP #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) diff --git a/linux/Platform.h b/linux/Platform.h index bf163a548..ec6852703 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Platform #define HEADER_Platform /* diff --git a/openbsd/Battery.h b/openbsd/Battery.h index 0f05af3a4..e858b15d2 100644 --- a/openbsd/Battery.h +++ b/openbsd/Battery.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Battery #define HEADER_Battery /* diff --git a/openbsd/OpenBSDCRT.h b/openbsd/OpenBSDCRT.h index c48309a72..66684c53a 100644 --- a/openbsd/OpenBSDCRT.h +++ b/openbsd/OpenBSDCRT.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_OpenBSDCRT #define HEADER_OpenBSDCRT /* diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index f54c9111d..1a8078489 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -16,26 +16,6 @@ in the source distribution for its full text. #include #include -/*{ - -typedef enum OpenBSDProcessFields { - // Add platform-specific fields here, with ids >= 100 - LAST_PROCESSFIELD = 100, -} OpenBSDProcessField; - -typedef struct OpenBSDProcess_ { - Process super; -} OpenBSDProcess; - -#ifndef Process_isKernelThread -#define Process_isKernelThread(_process) (_process->pgrp == 0) -#endif - -#ifndef Process_isUserlandThread -#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -#endif - -}*/ ProcessClass OpenBSDProcess_class = { .super = { diff --git a/openbsd/OpenBSDProcess.h b/openbsd/OpenBSDProcess.h index ba55e5ea0..b4fd82db7 100644 --- a/openbsd/OpenBSDProcess.h +++ b/openbsd/OpenBSDProcess.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_OpenBSDProcess #define HEADER_OpenBSDProcess /* diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index ea40fe17e..0d1a72266 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -27,40 +27,6 @@ in the source distribution for its full text. #include #include -/*{ - -#include - -typedef struct CPUData_ { - unsigned long long int totalTime; - unsigned long long int userTime; - unsigned long long int niceTime; - unsigned long long int sysTime; - unsigned long long int sysAllTime; - unsigned long long int spinTime; - unsigned long long int intrTime; - unsigned long long int idleTime; - - unsigned long long int totalPeriod; - unsigned long long int userPeriod; - unsigned long long int nicePeriod; - unsigned long long int sysPeriod; - unsigned long long int sysAllPeriod; - unsigned long long int spinPeriod; - unsigned long long int intrPeriod; - unsigned long long int idlePeriod; -} CPUData; - -typedef struct OpenBSDProcessList_ { - ProcessList super; - kvm_t* kd; - - CPUData* cpus; - -} OpenBSDProcessList; - -}*/ - /* * avoid relying on or conflicting with MIN() and MAX() in sys/param.h */ diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index ec9fab275..4b5203c70 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_OpenBSDProcessList #define HEADER_OpenBSDProcessList /* diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 0f5279e82..cb162078e 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -37,14 +37,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Action.h" -#include "BatteryMeter.h" -#include "SignalsPanel.h" - -extern ProcessFieldData Process_fields[]; - -}*/ ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; diff --git a/openbsd/Platform.h b/openbsd/Platform.h index 56e4c4000..da1a17402 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Platform #define HEADER_Platform /* diff --git a/scripts/MakeHeader.py.in b/scripts/MakeHeader.py.in deleted file mode 100644 index 8a6887787..000000000 --- a/scripts/MakeHeader.py.in +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env @PYTHON@ -import os, sys, io -try: - from StringIO import StringIO -except ImportError: - StringIO = io.StringIO - -ANY=1 -COPY=2 -SKIP=3 -SKIPONE=4 - -state = ANY -static = 0 - -file = io.open(sys.argv[1], "r", encoding="utf-8") -name = sys.argv[1][:-2] - -out = StringIO() - -selfheader = '#include "' + name + '.h"' - -out.write( "/* Do not edit this file. It was automatically generated. */\n" ) -out.write( "\n" ) - -out.write( "#ifndef HEADER_" + os.path.basename(name) + "\n") -out.write( "#define HEADER_" + os.path.basename(name) + "\n") -is_blank = False -for line in file.readlines(): - line = line[:-1] - if state == ANY: - if line == '/*{': - state = COPY - elif line == selfheader: - pass - elif line.find("#include") == 0: - pass - elif line.find("htop - ") == 0 and line[-2:] == ".c": - out.write(line[:-2] + ".h\n") - elif line.find("static ") != -1: - if line[-1] == "{": - state = SKIP - static = 1 - else: - state = SKIPONE - elif len(line) > 1: - static = 0 - equals = line.find(" = ") - if line[-3:] == "= {": - out.write( "extern " + line[:-4] + ";\n" ) - state = SKIP - elif equals != -1: - out.write("extern " + line[:equals] + ";\n" ) - elif line.startswith("typedef struct"): - state = SKIP - elif line[-1] == "{": - out.write("extern " + line[:-2].replace("inline ", "") + ";\n") - state = SKIP - elif line[-1] == ";": - out.write("extern " + line + "\n") - else: - out.write( line + "\n") - is_blank = False - elif line == "": - if not is_blank: - out.write( line + "\n") - is_blank = True - else: - out.write( line + "\n") - is_blank = False - elif state == COPY: - is_blank = False - if line == "}*/": - state = ANY - else: - out.write( line + "\n") - elif state == SKIP: - is_blank = False - if len(line) >= 1 and line[0] == "}": - if static == 1: - state = SKIPONE - else: - state = ANY - static = 0 - elif state == SKIPONE: - is_blank = False - state = ANY - -out.write( "\n" ) -out.write( "#endif\n" ) - -# only write a new .h file if something changed. -# This prevents a lot of recompilation during development -out.seek(0) -try: - with io.open(name + ".h", "r", encoding="utf-8") as orig: - origcontents = orig.readlines() -except: - origcontents = "" -if origcontents != out.readlines(): - with io.open(name + ".h", "w", encoding="utf-8") as new: - print("Writing "+name+".h") - new.write(out.getvalue()) -out.close() diff --git a/solaris/Battery.h b/solaris/Battery.h index 8dc0cef6d..24d8f5c2d 100644 --- a/solaris/Battery.h +++ b/solaris/Battery.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Battery #define HEADER_Battery diff --git a/solaris/Platform.c b/solaris/Platform.c index 092f4507b..436c9ce92 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -33,28 +33,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Action.h" -#include "BatteryMeter.h" -#include "SignalsPanel.h" -#include -#include -#include -#include - -#define kill(pid, signal) kill(pid / 1024, signal) - -extern ProcessFieldData Process_fields[]; -typedef struct var kvar_t; - -typedef struct envAccum_ { - size_t capacity; - size_t size; - size_t bytes; - char *env; -} envAccum; - -}*/ double plat_loadavg[3] = {0}; diff --git a/solaris/Platform.h b/solaris/Platform.h index dd1962dd2..041bf3fbb 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Platform #define HEADER_Platform /* diff --git a/solaris/SolarisCRT.h b/solaris/SolarisCRT.h index 6ab6dfcac..01b75696a 100644 --- a/solaris/SolarisCRT.h +++ b/solaris/SolarisCRT.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_SolarisCRT #define HEADER_SolarisCRT /* diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index 514453fd4..ab0bcab75 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -17,50 +17,6 @@ in the source distribution for its full text. #include #include -/*{ -#include "Settings.h" -#include -#include -#include - -typedef enum SolarisProcessFields { - // Add platform-specific fields here, with ids >= 100 - ZONEID = 100, - ZONE = 101, - PROJID = 102, - TASKID = 103, - POOLID = 104, - CONTID = 105, - LWPID = 106, - LAST_PROCESSFIELD = 107, -} SolarisProcessField; - - -typedef struct SolarisProcess_ { - Process super; - int kernel; - zoneid_t zoneid; - char* zname; - taskid_t taskid; - projid_t projid; - poolid_t poolid; - ctid_t contid; - bool is_lwp; - pid_t realpid; - pid_t realppid; - pid_t lwpid; -} SolarisProcess; - - -#ifndef Process_isKernelThread -#define Process_isKernelThread(_process) (_process->kernel == 1) -#endif - -#ifndef Process_isUserlandThread -#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -#endif - -}*/ ProcessClass SolarisProcess_class = { .super = { diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index 1b3492a77..a1064a30b 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_SolarisProcess #define HEADER_SolarisProcess /* diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index ab2cf68b4..b822237f5 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -25,45 +25,6 @@ in the source distribution for its full text. #define MAXCMDLINE 255 -#define GZONE "global " -#define UZONE "unknown " -/*{ - -#include "zfs/ZfsArcStats.h" - -#include -#include -#include -#include -#include -#include -#include - -#define ZONE_ERRMSGLEN 1024 -char zone_errmsg[ZONE_ERRMSGLEN]; - -typedef struct CPUData_ { - double userPercent; - double nicePercent; - double systemPercent; - double irqPercent; - double idlePercent; - double systemAllPercent; - uint64_t luser; - uint64_t lkrnl; - uint64_t lintr; - uint64_t lidle; -} CPUData; - -typedef struct SolarisProcessList_ { - ProcessList super; - kstat_ctl_t* kd; - CPUData* cpus; - ZfsArcStats zfs; -} SolarisProcessList; - -}*/ - char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { char* zname; if ( sproc->zoneid == 0 ) { diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index 06c1330ea..0e85f576d 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_SolarisProcessList #define HEADER_SolarisProcessList /* diff --git a/unsupported/Battery.h b/unsupported/Battery.h index 8dc0cef6d..24d8f5c2d 100644 --- a/unsupported/Battery.h +++ b/unsupported/Battery.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Battery #define HEADER_Battery diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 0e46a348e..420dfb78f 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -16,12 +16,6 @@ in the source distribution for its full text. #include "HostnameMeter.h" #include "UptimeMeter.h" -/*{ -#include "Action.h" -#include "BatteryMeter.h" -#include "SignalsPanel.h" -#include "UnsupportedProcess.h" -}*/ const SignalItem Platform_signals[] = { { .name = " 0 Cancel", .number = 0 }, diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 14f3d1a6d..2a3d768cc 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_Platform #define HEADER_Platform /* diff --git a/unsupported/UnsupportedCRT.h b/unsupported/UnsupportedCRT.h index 3c808ca6f..c8eff180f 100644 --- a/unsupported/UnsupportedCRT.h +++ b/unsupported/UnsupportedCRT.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_UnsupportedCRT #define HEADER_UnsupportedCRT /* diff --git a/unsupported/UnsupportedProcess.c b/unsupported/UnsupportedProcess.c index e3b4689a5..63e26add1 100644 --- a/unsupported/UnsupportedProcess.c +++ b/unsupported/UnsupportedProcess.c @@ -9,12 +9,6 @@ in the source distribution for its full text. #include "UnsupportedProcess.h" #include -/*{ -#include "Settings.h" - -#define Process_delete UnsupportedProcess_delete - -}*/ Process* UnsupportedProcess_new(Settings* settings) { Process* this = xCalloc(1, sizeof(Process)); diff --git a/unsupported/UnsupportedProcess.h b/unsupported/UnsupportedProcess.h index 4ca30436d..467297b5d 100644 --- a/unsupported/UnsupportedProcess.h +++ b/unsupported/UnsupportedProcess.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_UnsupportedProcess #define HEADER_UnsupportedProcess /* diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index 65749b18c..cad579c23 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -11,9 +11,6 @@ in the source distribution for its full text. #include #include -/*{ - -}*/ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { ProcessList* this = xCalloc(1, sizeof(ProcessList)); diff --git a/unsupported/UnsupportedProcessList.h b/unsupported/UnsupportedProcessList.h index 6eb13086c..093a8c438 100644 --- a/unsupported/UnsupportedProcessList.h +++ b/unsupported/UnsupportedProcessList.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_UnsupportedProcessList #define HEADER_UnsupportedProcessList /* From 7b7822b896af7673b9e13f0f1807e187ef2d4370 Mon Sep 17 00:00:00 2001 From: Zev Weiss Date: Wed, 2 Sep 2020 02:38:44 -0500 Subject: [PATCH 149/411] Remove superfluous 'extern's from function declarations. Applied via: $ find * -name '*.h' -exec sed -i -r 's/^extern (.+\()/\1/;' {} + Suggested-by: Bert Wesarg --- Action.h | 10 ++++---- Affinity.h | 14 +++++----- AffinityPanel.h | 4 +-- AvailableColumnsPanel.h | 2 +- AvailableMetersPanel.h | 2 +- CRT.h | 22 ++++++++-------- CategoriesPanel.h | 4 +-- CheckItem.h | 8 +++--- ColorsPanel.h | 2 +- ColumnsPanel.h | 6 ++--- DisplayOptionsPanel.h | 2 +- EnvScreen.h | 8 +++--- FunctionBar.h | 14 +++++----- Hashtable.h | 14 +++++----- Header.h | 26 +++++++++---------- IncSet.h | 20 +++++++-------- InfoScreen.h | 12 ++++----- ListItem.h | 8 +++--- MainPanel.h | 16 ++++++------ Meter.h | 12 ++++----- MetersPanel.h | 4 +-- Object.h | 2 +- OpenFilesScreen.h | 8 +++--- Panel.h | 50 ++++++++++++++++++------------------ Process.h | 30 +++++++++++----------- ProcessList.h | 28 ++++++++++---------- RichString.h | 18 ++++++------- ScreenManager.h | 14 +++++----- Settings.h | 8 +++--- SignalsPanel.h | 2 +- StringUtils.h | 14 +++++----- TraceScreen.h | 12 ++++----- UsersTable.h | 8 +++--- Vector.h | 32 +++++++++++------------ XAlloc.h | 12 ++++----- freebsd/FreeBSDProcessList.h | 10 ++++---- htop.h | 2 +- linux/Battery.h | 2 +- linux/IOPriorityPanel.h | 4 +-- linux/LinuxCRT.h | 2 +- linux/LinuxProcess.h | 16 ++++++------ linux/LinuxProcessList.h | 6 ++--- linux/Platform.h | 22 ++++++++-------- zfs/ZfsArcMeter.h | 2 +- 44 files changed, 257 insertions(+), 257 deletions(-) diff --git a/Action.h b/Action.h index 625bff6cd..ed13612c0 100644 --- a/Action.h +++ b/Action.h @@ -37,19 +37,19 @@ typedef struct State_ { } State; -extern Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess); +Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess); // ---------------------------------------- -extern bool Action_setUserOnly(const char* userName, uid_t* userId); +bool Action_setUserOnly(const char* userName, uid_t* userId); -extern Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey); +Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey); // ---------------------------------------- -extern Htop_Reaction Action_follow(State* st); +Htop_Reaction Action_follow(State* st); -extern void Action_setBindings(Htop_Action* keys); +void Action_setBindings(Htop_Action* keys); #endif diff --git a/Affinity.h b/Affinity.h index 322ca549a..8ee158d6c 100644 --- a/Affinity.h +++ b/Affinity.h @@ -28,23 +28,23 @@ typedef struct Affinity_ { } Affinity; -extern Affinity* Affinity_new(ProcessList* pl); +Affinity* Affinity_new(ProcessList* pl); -extern void Affinity_delete(Affinity* this); +void Affinity_delete(Affinity* this); -extern void Affinity_add(Affinity* this, int id); +void Affinity_add(Affinity* this, int id); #ifdef HAVE_LIBHWLOC -extern Affinity* Affinity_get(Process* proc, ProcessList* pl); +Affinity* Affinity_get(Process* proc, ProcessList* pl); -extern bool Affinity_set(Process* proc, Arg arg); +bool Affinity_set(Process* proc, Arg arg); #elif HAVE_LINUX_AFFINITY -extern Affinity* Affinity_get(Process* proc, ProcessList* pl); +Affinity* Affinity_get(Process* proc, ProcessList* pl); -extern bool Affinity_set(Process* proc, Arg arg); +bool Affinity_set(Process* proc, Arg arg); #endif diff --git a/AffinityPanel.h b/AffinityPanel.h index 64ee32ad4..f6ed350d7 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -31,8 +31,8 @@ in the source distribution for its full text. extern PanelClass AffinityPanel_class; -extern Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width); +Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width); -extern Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl); +Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl); #endif diff --git a/AvailableColumnsPanel.h b/AvailableColumnsPanel.h index fc3cb219c..ad70fbbb8 100644 --- a/AvailableColumnsPanel.h +++ b/AvailableColumnsPanel.h @@ -17,6 +17,6 @@ typedef struct AvailableColumnsPanel_ { extern PanelClass AvailableColumnsPanel_class; -extern AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns); +AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns); #endif diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index b2de67192..93db0dac4 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -25,6 +25,6 @@ typedef struct AvailableMetersPanel_ { extern PanelClass AvailableMetersPanel_class; -extern AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl); +AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl); #endif diff --git a/CRT.h b/CRT.h index 351f6397e..398fed319 100644 --- a/CRT.h +++ b/CRT.h @@ -127,9 +127,9 @@ typedef enum ColorElements_ { LAST_COLORELEMENT } ColorElements; -extern void CRT_fatalError(const char* note) __attribute__ ((noreturn)); +void CRT_fatalError(const char* note) __attribute__ ((noreturn)); -extern void CRT_handleSIGSEGV(int sgn); +void CRT_handleSIGSEGV(int sgn); #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) @@ -170,9 +170,9 @@ extern void *backtraceArray[128]; #define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0) -extern void CRT_dropPrivileges(); +void CRT_dropPrivileges(); -extern void CRT_restorePrivileges(); +void CRT_restorePrivileges(); #else @@ -187,18 +187,18 @@ extern void CRT_restorePrivileges(); // TODO: pass an instance of Settings instead. -extern void CRT_init(int delay, int colorScheme, bool allowUnicode); +void CRT_init(int delay, int colorScheme, bool allowUnicode); -extern void CRT_done(); +void CRT_done(); -extern void CRT_fatalError(const char* note); +void CRT_fatalError(const char* note); -extern int CRT_readKey(); +int CRT_readKey(); -extern void CRT_disableDelay(); +void CRT_disableDelay(); -extern void CRT_enableDelay(); +void CRT_enableDelay(); -extern void CRT_setColors(int colorScheme); +void CRT_setColors(int colorScheme); #endif diff --git a/CategoriesPanel.h b/CategoriesPanel.h index dd637e7a1..e6c7026d1 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -22,10 +22,10 @@ typedef struct CategoriesPanel_ { } CategoriesPanel; -extern void CategoriesPanel_makeMetersPage(CategoriesPanel* this); +void CategoriesPanel_makeMetersPage(CategoriesPanel* this); extern PanelClass CategoriesPanel_class; -extern CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl); +CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl); #endif diff --git a/CheckItem.h b/CheckItem.h index f59cc78e8..654c21f42 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -19,12 +19,12 @@ typedef struct CheckItem_ { extern ObjectClass CheckItem_class; -extern CheckItem* CheckItem_newByRef(char* text, bool* ref); +CheckItem* CheckItem_newByRef(char* text, bool* ref); -extern CheckItem* CheckItem_newByVal(char* text, bool value); +CheckItem* CheckItem_newByVal(char* text, bool value); -extern void CheckItem_set(CheckItem* this, bool value); +void CheckItem_set(CheckItem* this, bool value); -extern bool CheckItem_get(CheckItem* this); +bool CheckItem_get(CheckItem* this); #endif diff --git a/ColorsPanel.h b/ColorsPanel.h index 337a7f435..96a82a422 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -27,6 +27,6 @@ typedef struct ColorsPanel_ { extern PanelClass ColorsPanel_class; -extern ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); +ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); #endif diff --git a/ColumnsPanel.h b/ColumnsPanel.h index e3d4bcb91..89f500ab1 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -20,10 +20,10 @@ typedef struct ColumnsPanel_ { extern PanelClass ColumnsPanel_class; -extern ColumnsPanel* ColumnsPanel_new(Settings* settings); +ColumnsPanel* ColumnsPanel_new(Settings* settings); -extern int ColumnsPanel_fieldNameToIndex(const char* name); +int ColumnsPanel_fieldNameToIndex(const char* name); -extern void ColumnsPanel_update(Panel* super); +void ColumnsPanel_update(Panel* super); #endif diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index b38305415..69b8a3d52 100644 --- a/DisplayOptionsPanel.h +++ b/DisplayOptionsPanel.h @@ -21,6 +21,6 @@ typedef struct DisplayOptionsPanel_ { extern PanelClass DisplayOptionsPanel_class; -extern DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr); +DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr); #endif diff --git a/EnvScreen.h b/EnvScreen.h index 15f7acaae..54dfa41ab 100644 --- a/EnvScreen.h +++ b/EnvScreen.h @@ -9,12 +9,12 @@ typedef struct EnvScreen_ { extern InfoScreenClass EnvScreen_class; -extern EnvScreen* EnvScreen_new(Process* process); +EnvScreen* EnvScreen_new(Process* process); -extern void EnvScreen_delete(Object* this); +void EnvScreen_delete(Object* this); -extern void EnvScreen_draw(InfoScreen* this); +void EnvScreen_draw(InfoScreen* this); -extern void EnvScreen_scan(InfoScreen* this); +void EnvScreen_scan(InfoScreen* this); #endif diff --git a/FunctionBar.h b/FunctionBar.h index 09652e8b5..8971d1a50 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -20,18 +20,18 @@ typedef struct FunctionBar_ { -extern FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc); +FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc); -extern FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events); +FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events); -extern void FunctionBar_delete(FunctionBar* this); +void FunctionBar_delete(FunctionBar* this); -extern void FunctionBar_setLabel(FunctionBar* this, int event, const char* text); +void FunctionBar_setLabel(FunctionBar* this, int event, const char* text); -extern void FunctionBar_draw(const FunctionBar* this, char* buffer); +void FunctionBar_draw(const FunctionBar* this, char* buffer); -extern void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr); +void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr); -extern int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos); +int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos); #endif diff --git a/Hashtable.h b/Hashtable.h index 651f1648f..144f01cf3 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -28,20 +28,20 @@ struct Hashtable_ { #ifdef DEBUG -extern int Hashtable_count(Hashtable* this); +int Hashtable_count(Hashtable* this); #endif -extern Hashtable* Hashtable_new(int size, bool owner); +Hashtable* Hashtable_new(int size, bool owner); -extern void Hashtable_delete(Hashtable* this); +void Hashtable_delete(Hashtable* this); -extern void Hashtable_put(Hashtable* this, unsigned int key, void* value); +void Hashtable_put(Hashtable* this, unsigned int key, void* value); -extern void* Hashtable_remove(Hashtable* this, unsigned int key); +void* Hashtable_remove(Hashtable* this, unsigned int key); -extern void* Hashtable_get(Hashtable* this, unsigned int key); +void* Hashtable_get(Hashtable* this, unsigned int key); -extern void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData); +void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData); #endif diff --git a/Header.h b/Header.h index 844d04c94..73f264dcd 100644 --- a/Header.h +++ b/Header.h @@ -29,30 +29,30 @@ typedef struct Header_ { #define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_)) #endif -extern Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns); +Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns); -extern void Header_delete(Header* this); +void Header_delete(Header* this); -extern void Header_populateFromSettings(Header* this); +void Header_populateFromSettings(Header* this); -extern void Header_writeBackToSettings(const Header* this); +void Header_writeBackToSettings(const Header* this); -extern MeterModeId Header_addMeterByName(Header* this, char* name, int column); +MeterModeId Header_addMeterByName(Header* this, char* name, int column); -extern void Header_setMode(Header* this, int i, MeterModeId mode, int column); +void Header_setMode(Header* this, int i, MeterModeId mode, int column); -extern Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column); +Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column); -extern int Header_size(Header* this, int column); +int Header_size(Header* this, int column); -extern char* Header_readMeterName(Header* this, int i, int column); +char* Header_readMeterName(Header* this, int i, int column); -extern MeterModeId Header_readMeterMode(Header* this, int i, int column); +MeterModeId Header_readMeterMode(Header* this, int i, int column); -extern void Header_reinit(Header* this); +void Header_reinit(Header* this); -extern void Header_draw(const Header* this); +void Header_draw(const Header* this); -extern int Header_calculateHeight(Header* this); +int Header_calculateHeight(Header* this); #endif diff --git a/IncSet.h b/IncSet.h index b75b234b0..75949b0aa 100644 --- a/IncSet.h +++ b/IncSet.h @@ -39,24 +39,24 @@ typedef struct IncSet_ { typedef const char* (*IncMode_GetPanelValue)(Panel*, int); -extern void IncSet_reset(IncSet* this, IncType type); +void IncSet_reset(IncSet* this, IncType type); -extern IncSet* IncSet_new(FunctionBar* bar); +IncSet* IncSet_new(FunctionBar* bar); -extern void IncSet_delete(IncSet* this); +void IncSet_delete(IncSet* this); -extern bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue); +bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue); -extern bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue); +bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue); -extern bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines); +bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines); -extern const char* IncSet_getListItemValue(Panel* panel, int i); +const char* IncSet_getListItemValue(Panel* panel, int i); -extern void IncSet_activate(IncSet* this, IncType type, Panel* panel); +void IncSet_activate(IncSet* this, IncType type, Panel* panel); -extern void IncSet_drawBar(IncSet* this); +void IncSet_drawBar(IncSet* this); -extern int IncSet_synthesizeEvent(IncSet* this, int x); +int IncSet_synthesizeEvent(IncSet* this, int x); #endif diff --git a/InfoScreen.h b/InfoScreen.h index b59527f35..93665c1de 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -36,16 +36,16 @@ struct InfoScreen_ { Vector* lines; }; -extern InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, const char* panelHeader); +InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, const char* panelHeader); -extern InfoScreen* InfoScreen_done(InfoScreen* this); +InfoScreen* InfoScreen_done(InfoScreen* this); -extern void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...); +void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...); -extern void InfoScreen_addLine(InfoScreen* this, const char* line); +void InfoScreen_addLine(InfoScreen* this, const char* line); -extern void InfoScreen_appendLine(InfoScreen* this, const char* line); +void InfoScreen_appendLine(InfoScreen* this, const char* line); -extern void InfoScreen_run(InfoScreen* this); +void InfoScreen_run(InfoScreen* this); #endif diff --git a/ListItem.h b/ListItem.h index 3174df098..253f991c8 100644 --- a/ListItem.h +++ b/ListItem.h @@ -19,12 +19,12 @@ typedef struct ListItem_ { extern ObjectClass ListItem_class; -extern ListItem* ListItem_new(const char* value, int key); +ListItem* ListItem_new(const char* value, int key); -extern void ListItem_append(ListItem* this, const char* text); +void ListItem_append(ListItem* this, const char* text); -extern const char* ListItem_getRef(ListItem* this); +const char* ListItem_getRef(ListItem* this); -extern long ListItem_compare(const void* cast1, const void* cast2); +long ListItem_compare(const void* cast1, const void* cast2); #endif diff --git a/MainPanel.h b/MainPanel.h index cf46a4ee6..321f130c6 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -25,22 +25,22 @@ typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg); #define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar) -extern void MainPanel_updateTreeFunctions(MainPanel* this, bool mode); +void MainPanel_updateTreeFunctions(MainPanel* this, bool mode); -extern void MainPanel_pidSearch(MainPanel* this, int ch); +void MainPanel_pidSearch(MainPanel* this, int ch); -extern int MainPanel_selectedPid(MainPanel* this); +int MainPanel_selectedPid(MainPanel* this); -extern const char* MainPanel_getValue(MainPanel* this, int i); +const char* MainPanel_getValue(MainPanel* this, int i); -extern bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged); +bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged); extern PanelClass MainPanel_class; -extern MainPanel* MainPanel_new(); +MainPanel* MainPanel_new(); -extern void MainPanel_setState(MainPanel* this, State* state); +void MainPanel_setState(MainPanel* this, State* state); -extern void MainPanel_delete(Object* object); +void MainPanel_delete(Object* object); #endif diff --git a/Meter.h b/Meter.h index 5596f3cc9..1708a8ab8 100644 --- a/Meter.h +++ b/Meter.h @@ -107,17 +107,17 @@ typedef struct GraphData_ { extern MeterClass Meter_class; -extern Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type); +Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type); -extern int Meter_humanUnit(char* buffer, unsigned long int value, int size); +int Meter_humanUnit(char* buffer, unsigned long int value, int size); -extern void Meter_delete(Object* cast); +void Meter_delete(Object* cast); -extern void Meter_setCaption(Meter* this, const char* caption); +void Meter_setCaption(Meter* this, const char* caption); -extern void Meter_setMode(Meter* this, int modeIndex); +void Meter_setMode(Meter* this, int modeIndex); -extern ListItem* Meter_toListItem(Meter* this, bool moving); +ListItem* Meter_toListItem(Meter* this, bool moving); /* ---------- TextMeterMode ---------- */ diff --git a/MetersPanel.h b/MetersPanel.h index 111d6ef33..bea9238dc 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -32,10 +32,10 @@ struct MetersPanel_ { // In , arrows (U+2019..U+2199) are // considered "Ambiguous characters". -extern void MetersPanel_setMoving(MetersPanel* this, bool moving); +void MetersPanel_setMoving(MetersPanel* this, bool moving); extern PanelClass MetersPanel_class; -extern MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr); +MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr); #endif diff --git a/Object.h b/Object.h index 046447a77..f68742957 100644 --- a/Object.h +++ b/Object.h @@ -50,7 +50,7 @@ extern ObjectClass Object_class; #ifdef DEBUG -extern bool Object_isA(Object* o, const ObjectClass* klass); +bool Object_isA(Object* o, const ObjectClass* klass); #endif diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index 5f4d35749..9fc1216ba 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -32,12 +32,12 @@ typedef struct OpenFilesScreen_ { extern InfoScreenClass OpenFilesScreen_class; -extern OpenFilesScreen* OpenFilesScreen_new(Process* process); +OpenFilesScreen* OpenFilesScreen_new(Process* process); -extern void OpenFilesScreen_delete(Object* this); +void OpenFilesScreen_delete(Object* this); -extern void OpenFilesScreen_draw(InfoScreen* this); +void OpenFilesScreen_draw(InfoScreen* this); -extern void OpenFilesScreen_scan(InfoScreen* this); +void OpenFilesScreen_scan(InfoScreen* this); #endif diff --git a/Panel.h b/Panel.h index aedc98b53..be8646ab6 100644 --- a/Panel.h +++ b/Panel.h @@ -73,54 +73,54 @@ struct Panel_ { extern PanelClass Panel_class; -extern Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar); +Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar); -extern void Panel_delete(Object* cast); +void Panel_delete(Object* cast); -extern void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar); +void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar); -extern void Panel_done(Panel* this); +void Panel_done(Panel* this); -extern void Panel_setSelectionColor(Panel* this, int color); +void Panel_setSelectionColor(Panel* this, int color); -extern RichString* Panel_getHeader(Panel* this); +RichString* Panel_getHeader(Panel* this); -extern void Panel_setHeader(Panel* this, const char* header); +void Panel_setHeader(Panel* this, const char* header); -extern void Panel_move(Panel* this, int x, int y); +void Panel_move(Panel* this, int x, int y); -extern void Panel_resize(Panel* this, int w, int h); +void Panel_resize(Panel* this, int w, int h); -extern void Panel_prune(Panel* this); +void Panel_prune(Panel* this); -extern void Panel_add(Panel* this, Object* o); +void Panel_add(Panel* this, Object* o); -extern void Panel_insert(Panel* this, int i, Object* o); +void Panel_insert(Panel* this, int i, Object* o); -extern void Panel_set(Panel* this, int i, Object* o); +void Panel_set(Panel* this, int i, Object* o); -extern Object* Panel_get(Panel* this, int i); +Object* Panel_get(Panel* this, int i); -extern Object* Panel_remove(Panel* this, int i); +Object* Panel_remove(Panel* this, int i); -extern Object* Panel_getSelected(Panel* this); +Object* Panel_getSelected(Panel* this); -extern void Panel_moveSelectedUp(Panel* this); +void Panel_moveSelectedUp(Panel* this); -extern void Panel_moveSelectedDown(Panel* this); +void Panel_moveSelectedDown(Panel* this); -extern int Panel_getSelectedIndex(Panel* this); +int Panel_getSelectedIndex(Panel* this); -extern int Panel_size(Panel* this); +int Panel_size(Panel* this); -extern void Panel_setSelected(Panel* this, int selected); +void Panel_setSelected(Panel* this, int selected); -extern void Panel_draw(Panel* this, bool focus); +void Panel_draw(Panel* this, bool focus); -extern void Panel_splice(Panel *this, Vector* from); +void Panel_splice(Panel *this, Vector* from); -extern bool Panel_onKey(Panel* this, int key); +bool Panel_onKey(Panel* this, int key); -extern HandlerResult Panel_selectByTyping(Panel* this, int ch); +HandlerResult Panel_selectByTyping(Panel* this, int ch); #endif diff --git a/Process.h b/Process.h index d82724dd8..9aca41c96 100644 --- a/Process.h +++ b/Process.h @@ -173,36 +173,36 @@ typedef struct ProcessClass_ { extern char Process_pidFormat[20]; -extern void Process_setupColumnWidths(); +void Process_setupColumnWidths(); -extern void Process_humanNumber(RichString* str, unsigned long number, bool coloring); +void Process_humanNumber(RichString* str, unsigned long number, bool coloring); -extern void Process_colorNumber(RichString* str, unsigned long long number, bool coloring); +void Process_colorNumber(RichString* str, unsigned long long number, bool coloring); -extern void Process_printTime(RichString* str, unsigned long long totalHundredths); +void Process_printTime(RichString* str, unsigned long long totalHundredths); -extern void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring); +void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring); -extern void Process_writeField(Process* this, RichString* str, ProcessField field); +void Process_writeField(Process* this, RichString* str, ProcessField field); -extern void Process_display(Object* cast, RichString* out); +void Process_display(Object* cast, RichString* out); -extern void Process_done(Process* this); +void Process_done(Process* this); extern ProcessClass Process_class; -extern void Process_init(Process* this, struct Settings_* settings); +void Process_init(Process* this, struct Settings_* settings); -extern void Process_toggleTag(Process* this); +void Process_toggleTag(Process* this); -extern bool Process_setPriority(Process* this, int priority); +bool Process_setPriority(Process* this, int priority); -extern bool Process_changePriorityBy(Process* this, Arg delta); +bool Process_changePriorityBy(Process* this, Arg delta); -extern bool Process_sendSignal(Process* this, Arg sgn); +bool Process_sendSignal(Process* this, Arg sgn); -extern long Process_pidCompare(const void* v1, const void* v2); +long Process_pidCompare(const void* v1, const void* v2); -extern long Process_compare(const void* v1, const void* v2); +long Process_compare(const void* v1, const void* v2); #endif diff --git a/ProcessList.h b/ProcessList.h index 1a4170c0c..73f6c687a 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -69,32 +69,32 @@ void ProcessList_delete(ProcessList* pl); void ProcessList_goThroughEntries(ProcessList* pl); -extern ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); -extern void ProcessList_done(ProcessList* this); +void ProcessList_done(ProcessList* this); -extern void ProcessList_setPanel(ProcessList* this, Panel* panel); +void ProcessList_setPanel(ProcessList* this, Panel* panel); -extern void ProcessList_printHeader(ProcessList* this, RichString* header); +void ProcessList_printHeader(ProcessList* this, RichString* header); -extern void ProcessList_add(ProcessList* this, Process* p); +void ProcessList_add(ProcessList* this, Process* p); -extern void ProcessList_remove(ProcessList* this, Process* p); +void ProcessList_remove(ProcessList* this, Process* p); -extern Process* ProcessList_get(ProcessList* this, int idx); +Process* ProcessList_get(ProcessList* this, int idx); -extern int ProcessList_size(ProcessList* this); +int ProcessList_size(ProcessList* this); -extern void ProcessList_sort(ProcessList* this); +void ProcessList_sort(ProcessList* this); -extern ProcessField ProcessList_keyAt(ProcessList* this, int at); +ProcessField ProcessList_keyAt(ProcessList* this, int at); -extern void ProcessList_expandTree(ProcessList* this); +void ProcessList_expandTree(ProcessList* this); -extern void ProcessList_rebuildPanel(ProcessList* this); +void ProcessList_rebuildPanel(ProcessList* this); -extern Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor); +Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor); -extern void ProcessList_scan(ProcessList* this); +void ProcessList_scan(ProcessList* this); #endif diff --git a/RichString.h b/RichString.h index 824c0e2aa..59b77496c 100644 --- a/RichString.h +++ b/RichString.h @@ -67,26 +67,26 @@ typedef struct RichString_ { #ifdef HAVE_LIBNCURSESW -extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish); +void RichString_setAttrn(RichString* this, int attrs, int start, int finish); -extern int RichString_findChar(RichString* this, char c, int start); +int RichString_findChar(RichString* this, char c, int start); #else -extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish); +void RichString_setAttrn(RichString* this, int attrs, int start, int finish); -extern int RichString_findChar(RichString* this, char c, int start); +int RichString_findChar(RichString* this, char c, int start); #endif -extern void RichString_prune(RichString* this); +void RichString_prune(RichString* this); -extern void RichString_setAttr(RichString* this, int attrs); +void RichString_setAttr(RichString* this, int attrs); -extern void RichString_append(RichString* this, int attrs, const char* data); +void RichString_append(RichString* this, int attrs, const char* data); -extern void RichString_appendn(RichString* this, int attrs, const char* data, int len); +void RichString_appendn(RichString* this, int attrs, const char* data, int len); -extern void RichString_write(RichString* this, int attrs, const char* data); +void RichString_write(RichString* this, int attrs, const char* data); #endif diff --git a/ScreenManager.h b/ScreenManager.h index eaa908534..5907ce555 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -33,18 +33,18 @@ typedef struct ScreenManager_ { } ScreenManager; -extern ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner); +ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner); -extern void ScreenManager_delete(ScreenManager* this); +void ScreenManager_delete(ScreenManager* this); -extern int ScreenManager_size(ScreenManager* this); +int ScreenManager_size(ScreenManager* this); -extern void ScreenManager_add(ScreenManager* this, Panel* item, int size); +void ScreenManager_add(ScreenManager* this, Panel* item, int size); -extern Panel* ScreenManager_remove(ScreenManager* this, int idx); +Panel* ScreenManager_remove(ScreenManager* this, int idx); -extern void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2); +void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2); -extern void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey); +void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey); #endif diff --git a/Settings.h b/Settings.h index 23f5e7c1b..63b6e8a33 100644 --- a/Settings.h +++ b/Settings.h @@ -63,12 +63,12 @@ typedef struct Settings_ { #endif -extern void Settings_delete(Settings* this); +void Settings_delete(Settings* this); -extern bool Settings_write(Settings* this); +bool Settings_write(Settings* this); -extern Settings* Settings_new(int cpuCount); +Settings* Settings_new(int cpuCount); -extern void Settings_invertSortOrder(Settings* this); +void Settings_invertSortOrder(Settings* this); #endif diff --git a/SignalsPanel.h b/SignalsPanel.h index a3991fd91..94077ed01 100644 --- a/SignalsPanel.h +++ b/SignalsPanel.h @@ -14,6 +14,6 @@ typedef struct SignalItem_ { } SignalItem; -extern Panel* SignalsPanel_new(); +Panel* SignalsPanel_new(); #endif diff --git a/StringUtils.h b/StringUtils.h index 0450f0df9..cc0abb002 100644 --- a/StringUtils.h +++ b/StringUtils.h @@ -17,18 +17,18 @@ in the source distribution for its full text. * at compile time (e.g. when they are immutable string literals). :) */ -extern char* String_cat(const char* s1, const char* s2); +char* String_cat(const char* s1, const char* s2); -extern char* String_trim(const char* in); +char* String_trim(const char* in); -extern int String_eq(const char* s1, const char* s2); +int String_eq(const char* s1, const char* s2); -extern char** String_split(const char* s, char sep, int* n); +char** String_split(const char* s, char sep, int* n); -extern void String_freeArray(char** s); +void String_freeArray(char** s); -extern char* String_getToken(const char* line, const unsigned short int numMatch); +char* String_getToken(const char* line, const unsigned short int numMatch); -extern char* String_readLine(FILE* fd); +char* String_readLine(FILE* fd); #endif diff --git a/TraceScreen.h b/TraceScreen.h index 18920405f..1e5218c9d 100644 --- a/TraceScreen.h +++ b/TraceScreen.h @@ -23,16 +23,16 @@ typedef struct TraceScreen_ { extern InfoScreenClass TraceScreen_class; -extern TraceScreen* TraceScreen_new(Process* process); +TraceScreen* TraceScreen_new(Process* process); -extern void TraceScreen_delete(Object* cast); +void TraceScreen_delete(Object* cast); -extern void TraceScreen_draw(InfoScreen* this); +void TraceScreen_draw(InfoScreen* this); -extern bool TraceScreen_forkTracer(TraceScreen* this); +bool TraceScreen_forkTracer(TraceScreen* this); -extern void TraceScreen_updateTrace(InfoScreen* super); +void TraceScreen_updateTrace(InfoScreen* super); -extern bool TraceScreen_onKey(InfoScreen* super, int ch); +bool TraceScreen_onKey(InfoScreen* super, int ch); #endif diff --git a/UsersTable.h b/UsersTable.h index 6113277ff..fb3eaeddd 100644 --- a/UsersTable.h +++ b/UsersTable.h @@ -13,12 +13,12 @@ typedef struct UsersTable_ { Hashtable* users; } UsersTable; -extern UsersTable* UsersTable_new(); +UsersTable* UsersTable_new(); -extern void UsersTable_delete(UsersTable* this); +void UsersTable_delete(UsersTable* this); -extern char* UsersTable_getRef(UsersTable* this, unsigned int uid); +char* UsersTable_getRef(UsersTable* this, unsigned int uid); -extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData); +void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData); #endif diff --git a/Vector.h b/Vector.h index 7286bf658..7d1436aab 100644 --- a/Vector.h +++ b/Vector.h @@ -25,42 +25,42 @@ typedef struct Vector_ { } Vector; -extern Vector* Vector_new(ObjectClass* type, bool owner, int size); +Vector* Vector_new(ObjectClass* type, bool owner, int size); -extern void Vector_delete(Vector* this); +void Vector_delete(Vector* this); #ifdef DEBUG -extern int Vector_count(Vector* this); +int Vector_count(Vector* this); #endif -extern void Vector_prune(Vector* this); +void Vector_prune(Vector* this); // If I were to use only one sorting algorithm for both cases, it would probably be this one: /* */ -extern void Vector_quickSort(Vector* this); +void Vector_quickSort(Vector* this); -extern void Vector_insertionSort(Vector* this); +void Vector_insertionSort(Vector* this); -extern void Vector_insert(Vector* this, int idx, void* data_); +void Vector_insert(Vector* this, int idx, void* data_); -extern Object* Vector_take(Vector* this, int idx); +Object* Vector_take(Vector* this, int idx); -extern Object* Vector_remove(Vector* this, int idx); +Object* Vector_remove(Vector* this, int idx); -extern void Vector_moveUp(Vector* this, int idx); +void Vector_moveUp(Vector* this, int idx); -extern void Vector_moveDown(Vector* this, int idx); +void Vector_moveDown(Vector* this, int idx); -extern void Vector_set(Vector* this, int idx, void* data_); +void Vector_set(Vector* this, int idx, void* data_); #ifdef DEBUG -extern Object* Vector_get(Vector* this, int idx); +Object* Vector_get(Vector* this, int idx); #else @@ -70,7 +70,7 @@ extern Object* Vector_get(Vector* this, int idx); #ifdef DEBUG -extern int Vector_size(Vector* this); +int Vector_size(Vector* this); #else @@ -82,9 +82,9 @@ extern int Vector_size(Vector* this); */ -extern void Vector_add(Vector* this, void* data_); +void Vector_add(Vector* this, void* data_); -extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare); +int Vector_indexOf(Vector* this, void* search_, Object_Compare compare); void Vector_splice(Vector* this, Vector* from); diff --git a/XAlloc.h b/XAlloc.h index f67bf0dcb..b93342380 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -9,13 +9,13 @@ #include #include -extern void fail(void); +void fail(void); -extern void* xMalloc(size_t size); +void* xMalloc(size_t size); -extern void* xCalloc(size_t nmemb, size_t size); +void* xCalloc(size_t nmemb, size_t size); -extern void* xRealloc(void* ptr, size_t size); +void* xRealloc(void* ptr, size_t size); #undef xAsprintf @@ -36,9 +36,9 @@ extern void* xRealloc(void* ptr, size_t size); #endif #if (__has_attribute(nonnull) || \ ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) -extern char* xStrdup_(const char* str) __attribute__((nonnull)); +char* xStrdup_(const char* str) __attribute__((nonnull)); #endif // __has_attribute(nonnull) || GNU C 3.3 or later -extern char* xStrdup_(const char* str); +char* xStrdup_(const char* str); #endif diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index d01659dac..e00f25e99 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -55,14 +55,14 @@ typedef struct FreeBSDProcessList_ { extern char jail_errmsg[JAIL_ERRMSGLEN]; -extern ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); -extern void ProcessList_delete(ProcessList* this); +void ProcessList_delete(ProcessList* this); -extern char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); +char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); -extern char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc); +char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc); -extern void ProcessList_goThroughEntries(ProcessList* this); +void ProcessList_goThroughEntries(ProcessList* this); #endif diff --git a/htop.h b/htop.h index ced66de23..c51f96503 100644 --- a/htop.h +++ b/htop.h @@ -12,6 +12,6 @@ in the source distribution for its full text. // ---------------------------------------- -extern int main(int argc, char** argv); +int main(int argc, char** argv); #endif diff --git a/linux/Battery.h b/linux/Battery.h index d52b08c96..065895c56 100644 --- a/linux/Battery.h +++ b/linux/Battery.h @@ -27,6 +27,6 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat // READ FROM /sys // ---------------------------------------- -extern void Battery_getData(double* level, ACPresence* isOnAC); +void Battery_getData(double* level, ACPresence* isOnAC); #endif diff --git a/linux/IOPriorityPanel.h b/linux/IOPriorityPanel.h index 5019d59ac..04c1d43e1 100644 --- a/linux/IOPriorityPanel.h +++ b/linux/IOPriorityPanel.h @@ -11,8 +11,8 @@ in the source distribution for its full text. #include "IOPriority.h" #include "ListItem.h" -extern Panel* IOPriorityPanel_new(IOPriority currPrio); +Panel* IOPriorityPanel_new(IOPriority currPrio); -extern IOPriority IOPriorityPanel_getIOPriority(Panel* this); +IOPriority IOPriorityPanel_getIOPriority(Panel* this); #endif diff --git a/linux/LinuxCRT.h b/linux/LinuxCRT.h index f4f8cf069..61304dacb 100644 --- a/linux/LinuxCRT.h +++ b/linux/LinuxCRT.h @@ -10,6 +10,6 @@ in the source distribution for its full text. #ifdef HAVE_EXECINFO_H #endif -extern void CRT_handleSIGSEGV(int sgn); +void CRT_handleSIGSEGV(int sgn); #endif diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 462ae6bc1..8ee49f468 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -159,9 +159,9 @@ extern ProcessPidColumn Process_pidColumns[]; extern ProcessClass LinuxProcess_class; -extern LinuxProcess* LinuxProcess_new(Settings* settings); +LinuxProcess* LinuxProcess_new(Settings* settings); -extern void Process_delete(Object* cast); +void Process_delete(Object* cast); /* [1] Note that before kernel 2.6.26 a process that has not asked for @@ -173,18 +173,18 @@ extern io_priority; */ #define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->super.nice + 20) / 5) : p_->ioPriority) -extern IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this); +IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this); -extern bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio); +bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio); #ifdef HAVE_DELAYACCT -extern void LinuxProcess_printDelay(float delay_percent, char* buffer, int n); +void LinuxProcess_printDelay(float delay_percent, char* buffer, int n); #endif -extern void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field); +void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field); -extern long LinuxProcess_compare(const void* v1, const void* v2); +long LinuxProcess_compare(const void* v1, const void* v2); -extern bool Process_isThread(Process* this); +bool Process_isThread(Process* this); #endif diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 4a0e02064..b63f19aa5 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -109,9 +109,9 @@ typedef struct LinuxProcessList_ { #endif -extern ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); -extern void ProcessList_delete(ProcessList* pl); +void ProcessList_delete(ProcessList* pl); #ifdef HAVE_TASKSTATS @@ -134,6 +134,6 @@ extern void ProcessList_delete(ProcessList* pl); #endif -extern void ProcessList_goThroughEntries(ProcessList* super); +void ProcessList_goThroughEntries(ProcessList* super); #endif diff --git a/linux/Platform.h b/linux/Platform.h index ec6852703..922a33924 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -25,27 +25,27 @@ extern const SignalItem Platform_signals[]; extern const unsigned int Platform_numberOfSignals; -extern void Platform_setBindings(Htop_Action* keys); +void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; -extern int Platform_getUptime(); +int Platform_getUptime(); -extern void Platform_getLoadAverage(double* one, double* five, double* fifteen); +void Platform_getLoadAverage(double* one, double* five, double* fifteen); -extern int Platform_getMaxPid(); +int Platform_getMaxPid(); -extern double Platform_setCPUValues(Meter* this, int cpu); +double Platform_setCPUValues(Meter* this, int cpu); -extern void Platform_setMemoryValues(Meter* this); +void Platform_setMemoryValues(Meter* this); -extern void Platform_setSwapValues(Meter* this); +void Platform_setSwapValues(Meter* this); -extern void Platform_setZfsArcValues(Meter* this); +void Platform_setZfsArcValues(Meter* this); -extern void Platform_setZfsCompressedArcValues(Meter* this); -extern char* Platform_getProcessEnv(pid_t pid); +void Platform_setZfsCompressedArcValues(Meter* this); +char* Platform_getProcessEnv(pid_t pid); -extern void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); +void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); #endif diff --git a/zfs/ZfsArcMeter.h b/zfs/ZfsArcMeter.h index f2e322f94..c52083df2 100644 --- a/zfs/ZfsArcMeter.h +++ b/zfs/ZfsArcMeter.h @@ -15,7 +15,7 @@ in the source distribution for its full text. extern int ZfsArcMeter_attributes[]; -extern void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats); +void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats); extern MeterClass ZfsArcMeter_class; From 7758ffcdeae26f47f4ad6ec847fb8292fd5ceee3 Mon Sep 17 00:00:00 2001 From: Zev Weiss Date: Thu, 3 Sep 2020 12:00:21 -0500 Subject: [PATCH 150/411] Remove duplicate jail_errmsg declaration. Fixes: 11ecc65ebb1527e9a83f67bb5ac0dec455cb03e6 --- freebsd/FreeBSDProcessList.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index e00f25e99..c97646301 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -52,9 +52,6 @@ typedef struct FreeBSDProcessList_ { } FreeBSDProcessList; -extern char jail_errmsg[JAIL_ERRMSGLEN]; - - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_delete(ProcessList* this); From 0750ff7e76d845a70749cc00fa25dbe98a7147a1 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Fri, 4 Sep 2020 09:49:30 +1000 Subject: [PATCH 151/411] Fix regression in -u optional-argument handling Resolves https://github.com/htop-dev/htop/issues/91 --- htop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htop.c b/htop.c index bbf3a9115..37727d00e 100644 --- a/htop.c +++ b/htop.c @@ -98,7 +98,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { int opt, opti=0; /* Parse arguments */ - while ((opt = getopt_long(argc, argv, "hvmCs:td:u:Up:", long_opts, &opti))) { + while ((opt = getopt_long(argc, argv, "hvmCs:td:u::Up:", long_opts, &opti))) { if (opt == EOF) break; switch (opt) { case 'h': From f884beda97ee5dd45727dfa756c64b4f0d8c5b5c Mon Sep 17 00:00:00 2001 From: Dominik Hassler Date: Sat, 5 Sep 2020 15:29:15 +1000 Subject: [PATCH 152/411] htop should report the nice level properly --- solaris/SolarisProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index ab2cf68b4..4453c63d9 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -323,7 +323,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * sproc->poolid = _psinfo->pr_poolid; sproc->contid = _psinfo->pr_contract; proc->priority = _lwpsinfo->pr_pri; - proc->nice = _lwpsinfo->pr_nice; + proc->nice = _lwpsinfo->pr_nice - NZERO; proc->processor = _lwpsinfo->pr_onpro; proc->state = _lwpsinfo->pr_sname; // NOTE: This 'percentage' is a 16-bit BINARY FRACTIONS where 1.0 = 0x8000 From 780557511438d15f11ebe1814f936fbaa5c05751 Mon Sep 17 00:00:00 2001 From: Dominik Hassler Date: Sat, 5 Sep 2020 15:34:27 +1000 Subject: [PATCH 153/411] fix for double symbol link error on solaris --- solaris/SolarisProcessList.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index 06c1330ea..97d5dc604 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -26,7 +26,7 @@ in the source distribution for its full text. #include #define ZONE_ERRMSGLEN 1024 -char zone_errmsg[ZONE_ERRMSGLEN]; +extern char zone_errmsg[ZONE_ERRMSGLEN]; typedef struct CPUData_ { double userPercent; From 13b1e96b123c89da5bada7b8d173f9e5e931b9db Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 7 Sep 2020 09:42:48 +0200 Subject: [PATCH 154/411] Avoid shadowing of variables --- AffinityPanel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index 1ffa90089..99c247730 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -375,9 +375,9 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) { for (int i = 0; i < pl->cpuCount; i++) { char number[16]; xSnprintf(number, 9, "CPU %d", Settings_cpuId(pl->settings, i)); - unsigned width = 4 + strlen(number); - if (width > this->width) - this->width = width; + unsigned cpu_width = 4 + strlen(number); + if (cpu_width > this->width) + this->width = cpu_width; bool isSet = false; if (curCpu < affinity->used && affinity->cpus[curCpu] == i) { From 8ec5d4a3a07fe9a3c556a4abeac6645a7bb2235e Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 8 Sep 2020 17:33:50 +1000 Subject: [PATCH 155/411] Further, minor cleanups to headers post-MakeHeaders Remove leftover empty ifdef/endif pairs, whitespace. The generated htop.h file was also unused - removed. --- Action.h | 3 --- Affinity.h | 2 -- AffinityPanel.h | 18 -------------- AvailableColumnsPanel.h | 1 - AvailableMetersPanel.h | 1 - CPUMeter.h | 1 - CRT.c | 2 -- CRT.h | 2 -- CategoriesPanel.h | 1 - CheckItem.h | 1 - ColorsPanel.h | 1 - ColumnsPanel.h | 1 - DisplayOptionsPanel.h | 1 - FunctionBar.h | 3 --- Header.h | 3 --- IncSet.h | 2 -- ListItem.h | 1 - MainPanel.h | 1 - Makefile.am | 2 +- Meter.h | 6 ----- Object.h | 1 - OpenFilesScreen.h | 1 - Panel.c | 3 --- Panel.h | 3 --- ScreenManager.h | 1 - Settings.h | 3 --- SignalsPanel.h | 2 -- Vector.h | 6 ----- darwin/Battery.h | 1 - darwin/DarwinCRT.h | 1 - darwin/DarwinProcess.h | 1 - darwin/DarwinProcessList.h | 1 - dragonflybsd/DragonFlyBSDCRT.h | 4 --- dragonflybsd/DragonFlyBSDProcess.h | 8 ------ dragonflybsd/DragonFlyBSDProcessList.h | 7 +----- dragonflybsd/Platform.h | 1 - freebsd/FreeBSDCRT.h | 1 - freebsd/FreeBSDProcess.h | 10 +------- freebsd/FreeBSDProcessList.h | 4 --- freebsd/Platform.h | 1 - htop.h | 17 ------------- linux/Battery.h | 18 -------------- linux/IOPriority.h | 2 -- linux/LinuxCRT.h | 3 --- linux/LinuxProcess.h | 7 ------ linux/LinuxProcessList.h | 34 -------------------------- openbsd/OpenBSDCRT.h | 1 - openbsd/OpenBSDProcess.h | 8 +----- openbsd/OpenBSDProcessList.h | 6 ----- openbsd/Platform.h | 12 +-------- solaris/Battery.h | 1 - solaris/Platform.h | 1 - solaris/SolarisCRT.h | 3 --- solaris/SolarisProcess.h | 9 +------ solaris/SolarisProcessList.h | 2 -- unsupported/Battery.h | 1 - unsupported/UnsupportedCRT.h | 1 - unsupported/UnsupportedProcess.h | 2 -- unsupported/UnsupportedProcessList.h | 2 -- zfs/ZfsArcMeter.h | 2 -- zfs/ZfsArcStats.h | 3 --- zfs/ZfsCompressedArcMeter.h | 2 -- zfs/openzfs_sysctl.h | 2 -- 63 files changed, 6 insertions(+), 246 deletions(-) delete mode 100644 htop.h diff --git a/Action.h b/Action.h index ed13612c0..cf0169c48 100644 --- a/Action.h +++ b/Action.h @@ -7,7 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - #include "IncSet.h" #include "Settings.h" #include "Header.h" @@ -36,7 +35,6 @@ typedef struct State_ { Header* header; } State; - Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess); // ---------------------------------------- @@ -49,7 +47,6 @@ Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey); Htop_Reaction Action_follow(State* st); - void Action_setBindings(Htop_Action* keys); #endif diff --git a/Affinity.h b/Affinity.h index 8ee158d6c..6bdd9750b 100644 --- a/Affinity.h +++ b/Affinity.h @@ -14,7 +14,6 @@ in the source distribution for its full text. #else #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS #endif -#elif HAVE_LINUX_AFFINITY #endif #include "Process.h" @@ -27,7 +26,6 @@ typedef struct Affinity_ { int* cpus; } Affinity; - Affinity* Affinity_new(ProcessList* pl); void Affinity_delete(Affinity* this); diff --git a/AffinityPanel.h b/AffinityPanel.h index f6ed350d7..61e4287a0 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -7,28 +7,10 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifdef HAVE_LIBHWLOC -#endif - #include "Panel.h" #include "Affinity.h" #include "ProcessList.h" - - -#ifdef HAVE_LIBHWLOC - -#endif - - -#ifdef HAVE_LIBHWLOC - -#endif - -#ifdef HAVE_LIBHWLOC - -#endif - extern PanelClass AffinityPanel_class; Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width); diff --git a/AvailableColumnsPanel.h b/AvailableColumnsPanel.h index ad70fbbb8..629280589 100644 --- a/AvailableColumnsPanel.h +++ b/AvailableColumnsPanel.h @@ -14,7 +14,6 @@ typedef struct AvailableColumnsPanel_ { Panel* columns; } AvailableColumnsPanel; - extern PanelClass AvailableColumnsPanel_class; AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns); diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index 93db0dac4..ecebb28de 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -22,7 +22,6 @@ typedef struct AvailableMetersPanel_ { Panel* rightPanel; } AvailableMetersPanel; - extern PanelClass AvailableMetersPanel_class; AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl); diff --git a/CPUMeter.h b/CPUMeter.h index 56353c691..2caa82918 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -22,7 +22,6 @@ typedef enum { CPU_METER_ITEMCOUNT = 9, // number of entries in this enum } CPUMeterValues; - extern int CPUMeter_attributes[]; #ifndef MIN diff --git a/CRT.c b/CRT.c index a9147f9af..2a7c7912b 100644 --- a/CRT.c +++ b/CRT.c @@ -43,8 +43,6 @@ in the source distribution for its full text. #define KEY_WHEELDOWN KEY_F(21) #define KEY_RECLICK KEY_F(22) -//#link curses - const char *CRT_treeStrAscii[TREE_STR_COUNT] = { "-", // TREE_STR_HORZ "|", // TREE_STR_VERT diff --git a/CRT.h b/CRT.h index 398fed319..2e21e91eb 100644 --- a/CRT.h +++ b/CRT.h @@ -30,8 +30,6 @@ in the source distribution for its full text. #define KEY_WHEELDOWN KEY_F(21) #define KEY_RECLICK KEY_F(22) -//#link curses - #include typedef enum TreeStr_ { diff --git a/CategoriesPanel.h b/CategoriesPanel.h index e6c7026d1..fefc3e931 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -21,7 +21,6 @@ typedef struct CategoriesPanel_ { ProcessList* pl; } CategoriesPanel; - void CategoriesPanel_makeMetersPage(CategoriesPanel* this); extern PanelClass CategoriesPanel_class; diff --git a/CheckItem.h b/CheckItem.h index 654c21f42..11ac35f56 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -16,7 +16,6 @@ typedef struct CheckItem_ { bool value; } CheckItem; - extern ObjectClass CheckItem_class; CheckItem* CheckItem_newByRef(char* text, bool* ref); diff --git a/ColorsPanel.h b/ColorsPanel.h index 96a82a422..9977dc0b5 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -24,7 +24,6 @@ typedef struct ColorsPanel_ { ScreenManager* scr; } ColorsPanel; - extern PanelClass ColorsPanel_class; ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); diff --git a/ColumnsPanel.h b/ColumnsPanel.h index 89f500ab1..be139a6e7 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -17,7 +17,6 @@ typedef struct ColumnsPanel_ { bool moving; } ColumnsPanel; - extern PanelClass ColumnsPanel_class; ColumnsPanel* ColumnsPanel_new(Settings* settings); diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index 69b8a3d52..499b2fc19 100644 --- a/DisplayOptionsPanel.h +++ b/DisplayOptionsPanel.h @@ -18,7 +18,6 @@ typedef struct DisplayOptionsPanel_ { ScreenManager* scr; } DisplayOptionsPanel; - extern PanelClass DisplayOptionsPanel_class; DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr); diff --git a/FunctionBar.h b/FunctionBar.h index 8971d1a50..486990fc3 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -7,7 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - #include typedef struct FunctionBar_ { @@ -18,8 +17,6 @@ typedef struct FunctionBar_ { bool staticData; } FunctionBar; - - FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc); FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events); diff --git a/Header.h b/Header.h index 73f264dcd..e281a0c2e 100644 --- a/Header.h +++ b/Header.h @@ -20,14 +20,11 @@ typedef struct Header_ { int height; } Header; - #ifndef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) #endif -#ifndef Header_forEachColumn #define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_)) -#endif Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns); diff --git a/IncSet.h b/IncSet.h index 75949b0aa..2fb22c498 100644 --- a/IncSet.h +++ b/IncSet.h @@ -7,7 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - #include "FunctionBar.h" #include "Panel.h" #include @@ -38,7 +37,6 @@ typedef struct IncSet_ { typedef const char* (*IncMode_GetPanelValue)(Panel*, int); - void IncSet_reset(IncSet* this, IncType type); IncSet* IncSet_new(FunctionBar* bar); diff --git a/ListItem.h b/ListItem.h index 253f991c8..3fea7257d 100644 --- a/ListItem.h +++ b/ListItem.h @@ -16,7 +16,6 @@ typedef struct ListItem_ { bool moving; } ListItem; - extern ObjectClass ListItem_class; ListItem* ListItem_new(const char* value, int key); diff --git a/MainPanel.h b/MainPanel.h index 321f130c6..582dd2ec1 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -24,7 +24,6 @@ typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg); #define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar) - void MainPanel_updateTreeFunctions(MainPanel* this, bool mode); void MainPanel_pidSearch(MainPanel* this, int ch); diff --git a/Makefile.am b/Makefile.am index 5bf172b0e..fbbf7bef6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,7 +29,7 @@ InfoScreen.c XAlloc.c myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ CPUMeter.h CRT.h MainPanel.h DisplayOptionsPanel.h FunctionBar.h \ -Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ +Hashtable.h Header.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.h \ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ diff --git a/Meter.h b/Meter.h index 1708a8ab8..7936fb782 100644 --- a/Meter.h +++ b/Meter.h @@ -94,7 +94,6 @@ typedef struct GraphData_ { double values[METER_BUFFER_LEN]; } GraphData; - #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif @@ -126,7 +125,6 @@ ListItem* Meter_toListItem(Meter* this, bool moving); /* ---------- GraphMeterMode ---------- */ #ifdef HAVE_LIBNCURSESW - #define PIXPERROW_UTF8 4 #endif @@ -134,10 +132,6 @@ ListItem* Meter_toListItem(Meter* this, bool moving); /* ---------- LEDMeterMode ---------- */ -#ifdef HAVE_LIBNCURSESW - -#endif - extern MeterMode* Meter_modes[]; /* Blank meter */ diff --git a/Object.h b/Object.h index f68742957..e73230c0d 100644 --- a/Object.h +++ b/Object.h @@ -45,7 +45,6 @@ typedef union { void* v; } Arg; - extern ObjectClass Object_class; #ifdef DEBUG diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index 9fc1216ba..2c83cf1d5 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -29,7 +29,6 @@ typedef struct OpenFilesScreen_ { pid_t pid; } OpenFilesScreen; - extern InfoScreenClass OpenFilesScreen_class; OpenFilesScreen* OpenFilesScreen_new(Process* process); diff --git a/Panel.c b/Panel.c index 297dc89c7..73fa7858e 100644 --- a/Panel.c +++ b/Panel.c @@ -19,9 +19,6 @@ in the source distribution for its full text. #include #include -//#link curses - - #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif diff --git a/Panel.h b/Panel.h index be8646ab6..17b65c950 100644 --- a/Panel.h +++ b/Panel.h @@ -7,8 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -//#link curses - #include "Object.h" #include "Vector.h" #include "FunctionBar.h" @@ -61,7 +59,6 @@ struct Panel_ { #define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0) - #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif diff --git a/ScreenManager.h b/ScreenManager.h index 5907ce555..69d983a0b 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -32,7 +32,6 @@ typedef struct ScreenManager_ { bool allowFocusChange; } ScreenManager; - ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner); void ScreenManager_delete(ScreenManager* this); diff --git a/Settings.h b/Settings.h index 63b6e8a33..0188b614e 100644 --- a/Settings.h +++ b/Settings.h @@ -58,10 +58,7 @@ typedef struct Settings_ { bool changed; } Settings; -#ifndef Settings_cpuId #define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromZero ? (cpu) : (cpu)+1) -#endif - void Settings_delete(Settings* this); diff --git a/SignalsPanel.h b/SignalsPanel.h index 94077ed01..3d910ceee 100644 --- a/SignalsPanel.h +++ b/SignalsPanel.h @@ -7,13 +7,11 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - typedef struct SignalItem_ { const char* name; int number; } SignalItem; - Panel* SignalsPanel_new(); #endif diff --git a/Vector.h b/Vector.h index 7d1436aab..32cd809e9 100644 --- a/Vector.h +++ b/Vector.h @@ -24,7 +24,6 @@ typedef struct Vector_ { bool owner; } Vector; - Vector* Vector_new(ObjectClass* type, bool owner, int size); void Vector_delete(Vector* this); @@ -37,11 +36,6 @@ int Vector_count(Vector* this); void Vector_prune(Vector* this); -// If I were to use only one sorting algorithm for both cases, it would probably be this one: -/* - -*/ - void Vector_quickSort(Vector* this); void Vector_insertionSort(Vector* this); diff --git a/darwin/Battery.h b/darwin/Battery.h index 24d8f5c2d..21a1579ac 100644 --- a/darwin/Battery.h +++ b/darwin/Battery.h @@ -3,5 +3,4 @@ void Battery_getData(double* level, ACPresence* isOnAC); - #endif diff --git a/darwin/DarwinCRT.h b/darwin/DarwinCRT.h index d79e34c84..5e08422b5 100644 --- a/darwin/DarwinCRT.h +++ b/darwin/DarwinCRT.h @@ -9,5 +9,4 @@ in the source distribution for its full text. void CRT_handleSIGSEGV(int sgn); - #endif diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index f885ccc58..cf76fa8db 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -20,7 +20,6 @@ typedef struct DarwinProcess_ { bool taskAccess; } DarwinProcess; - extern ProcessClass DarwinProcess_class; DarwinProcess* DarwinProcess_new(Settings* settings); diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index d6c332768..7d6f53435 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -37,7 +37,6 @@ typedef struct DarwinProcessList_ { ZfsArcStats zfs; } DarwinProcessList; - void ProcessList_getHostInfo(host_basic_info_data_t *p); void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p); diff --git a/dragonflybsd/DragonFlyBSDCRT.h b/dragonflybsd/DragonFlyBSDCRT.h index 2b98effbf..2bf85f71a 100644 --- a/dragonflybsd/DragonFlyBSDCRT.h +++ b/dragonflybsd/DragonFlyBSDCRT.h @@ -8,10 +8,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifdef HAVE_EXECINFO_H -#endif - void CRT_handleSIGSEGV(int sgn); - #endif diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h index a0381c675..d5e5a6ee9 100644 --- a/dragonflybsd/DragonFlyBSDProcess.h +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -8,7 +8,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - typedef enum DragonFlyBSDProcessFields { // Add platform-specific fields here, with ids >= 100 JID = 100, @@ -16,7 +15,6 @@ typedef enum DragonFlyBSDProcessFields { LAST_PROCESSFIELD = 102, } DragonFlyBSDProcessField; - typedef struct DragonFlyBSDProcess_ { Process super; int kernel; @@ -24,16 +22,10 @@ typedef struct DragonFlyBSDProcess_ { char* jname; } DragonFlyBSDProcess; - -#ifndef Process_isKernelThread #define Process_isKernelThread(_process) (_process->kernel == 1) -#endif -#ifndef Process_isUserlandThread //#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) #define Process_isUserlandThread(_process) (_process->nlwp > 1) -#endif - extern ProcessClass DragonFlyBSDProcess_class; diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index f677c3e4a..403aa0965 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -8,7 +8,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - #include #include #include @@ -21,17 +20,15 @@ in the source distribution for its full text. #include "DragonFlyBSDProcess.h" #define JAIL_ERRMSGLEN 1024 -char jail_errmsg[JAIL_ERRMSGLEN]; +extern char jail_errmsg[JAIL_ERRMSGLEN]; typedef struct CPUData_ { - double userPercent; double nicePercent; double systemPercent; double irqPercent; double idlePercent; double systemAllPercent; - } CPUData; typedef struct DragonFlyBSDProcessList_ { @@ -54,10 +51,8 @@ typedef struct DragonFlyBSDProcessList_ { Hashtable *jails; } DragonFlyBSDProcessList; - #define _UNUSED_ __attribute__((unused)) - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index aa00d6564..c6792a28b 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -14,7 +14,6 @@ in the source distribution for its full text. extern ProcessFieldData Process_fields[]; - #ifndef CLAMP #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #endif diff --git a/freebsd/FreeBSDCRT.h b/freebsd/FreeBSDCRT.h index d0c216598..eb88fcc1f 100644 --- a/freebsd/FreeBSDCRT.h +++ b/freebsd/FreeBSDCRT.h @@ -9,5 +9,4 @@ in the source distribution for its full text. void CRT_handleSIGSEGV(int sgn); - #endif diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index b269b7798..897c53291 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -7,15 +7,13 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - -typedef enum FreeBSDProcessFields { +typedef enum FreeBSDProcessFields_ { // Add platform-specific fields here, with ids >= 100 JID = 100, JAIL = 101, LAST_PROCESSFIELD = 102, } FreeBSDProcessField; - typedef struct FreeBSDProcess_ { Process super; int kernel; @@ -23,15 +21,9 @@ typedef struct FreeBSDProcess_ { char* jname; } FreeBSDProcess; - -#ifndef Process_isKernelThread #define Process_isKernelThread(_process) (_process->kernel == 1) -#endif -#ifndef Process_isUserlandThread #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -#endif - extern ProcessClass FreeBSDProcess_class; diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index c97646301..1805c5af3 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -7,7 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - #include "zfs/ZfsArcStats.h" #include @@ -20,14 +19,12 @@ in the source distribution for its full text. extern char jail_errmsg[JAIL_ERRMSGLEN]; typedef struct CPUData_ { - double userPercent; double nicePercent; double systemPercent; double irqPercent; double idlePercent; double systemAllPercent; - } CPUData; typedef struct FreeBSDProcessList_ { @@ -51,7 +48,6 @@ typedef struct FreeBSDProcessList_ { } FreeBSDProcessList; - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/freebsd/Platform.h b/freebsd/Platform.h index f453e68ef..fd7045392 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -13,7 +13,6 @@ in the source distribution for its full text. extern ProcessFieldData Process_fields[]; - #ifndef CLAMP #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #endif diff --git a/htop.h b/htop.h deleted file mode 100644 index c51f96503..000000000 --- a/htop.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef HEADER_htop -#define HEADER_htop -/* -htop - htop.h -(C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file -in the source distribution for its full text. -*/ - -//#link m - -// ---------------------------------------- - - -int main(int argc, char** argv); - -#endif diff --git a/linux/Battery.h b/linux/Battery.h index 065895c56..8ca0d7fbe 100644 --- a/linux/Battery.h +++ b/linux/Battery.h @@ -9,24 +9,6 @@ in the source distribution for its full text. Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#define SYS_POWERSUPPLY_DIR "/sys/class/power_supply" - -// ---------------------------------------- -// READ FROM /proc -// ---------------------------------------- - -// This implementation reading from from /proc/acpi is really inefficient, -// but I think this is on the way out so I did not rewrite it. -// The /sys implementation below does things the right way. - -// ---------------------------------------- -// READ FROM /sys -// ---------------------------------------- - void Battery_getData(double* level, ACPresence* isOnAC); #endif diff --git a/linux/IOPriority.h b/linux/IOPriority.h index 4e2c379e8..7c4f3b63d 100644 --- a/linux/IOPriority.h +++ b/linux/IOPriority.h @@ -11,7 +11,6 @@ Copyright (C) 2005 Jens Axboe Released under the terms of the GNU General Public License version 2 */ - enum { IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, @@ -36,5 +35,4 @@ typedef int IOPriority; #define IOPriority_None IOPriority_tuple(IOPRIO_CLASS_NONE, 0) #define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 7) - #endif diff --git a/linux/LinuxCRT.h b/linux/LinuxCRT.h index 61304dacb..c379a8f65 100644 --- a/linux/LinuxCRT.h +++ b/linux/LinuxCRT.h @@ -7,9 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifdef HAVE_EXECINFO_H -#endif - void CRT_handleSIGSEGV(int sgn); #endif diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 8ee49f468..021cae7c7 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -8,7 +8,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - #define PROCESS_FLAG_LINUX_IOPRIO 0x0100 #define PROCESS_FLAG_LINUX_OPENVZ 0x0200 #define PROCESS_FLAG_LINUX_VSERVER 0x0400 @@ -141,16 +140,10 @@ typedef struct LinuxProcess_ { #endif } LinuxProcess; -#ifndef Process_isKernelThread #define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread) -#endif -#ifndef Process_isUserlandThread #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -#endif - -/* semi-global */ extern long long btime; extern ProcessFieldData Process_fields[]; diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index b63f19aa5..d689d4ac1 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -7,14 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifdef MAJOR_IN_MKDEV -#elif defined(MAJOR_IN_SYSMACROS) -#endif - -#ifdef HAVE_DELAYACCT -#endif - - #include "ProcessList.h" #include "zfs/ZfsArcStats.h" @@ -100,40 +92,14 @@ typedef struct LinuxProcessList_ { #define PROC_LINE_LENGTH 4096 #endif - #ifndef CLAMP #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #endif -#ifdef HAVE_DELAYACCT - -#endif - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_delete(ProcessList* pl); - -#ifdef HAVE_TASKSTATS - -#endif - -#ifdef HAVE_OPENVZ - -#endif - -#ifdef HAVE_CGROUP - -#endif - -#ifdef HAVE_VSERVER - -#endif - -#ifdef HAVE_DELAYACCT - -#endif - void ProcessList_goThroughEntries(ProcessList* super); #endif diff --git a/openbsd/OpenBSDCRT.h b/openbsd/OpenBSDCRT.h index 66684c53a..85860a96c 100644 --- a/openbsd/OpenBSDCRT.h +++ b/openbsd/OpenBSDCRT.h @@ -10,5 +10,4 @@ in the source distribution for its full text. void CRT_handleSIGSEGV(int sgn); - #endif diff --git a/openbsd/OpenBSDProcess.h b/openbsd/OpenBSDProcess.h index b4fd82db7..fede6f87c 100644 --- a/openbsd/OpenBSDProcess.h +++ b/openbsd/OpenBSDProcess.h @@ -8,8 +8,7 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - -typedef enum OpenBSDProcessFields { +typedef enum OpenBSDProcessFields_ { // Add platform-specific fields here, with ids >= 100 LAST_PROCESSFIELD = 100, } OpenBSDProcessField; @@ -18,14 +17,9 @@ typedef struct OpenBSDProcess_ { Process super; } OpenBSDProcess; -#ifndef Process_isKernelThread #define Process_isKernelThread(_process) (_process->pgrp == 0) -#endif -#ifndef Process_isUserlandThread #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -#endif - extern ProcessClass OpenBSDProcess_class; diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index 4b5203c70..038a263df 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -8,7 +8,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - #include typedef struct CPUData_ { @@ -39,7 +38,6 @@ typedef struct OpenBSDProcessList_ { } OpenBSDProcessList; - /* * avoid relying on or conflicting with MIN() and MAX() in sys/param.h */ @@ -61,10 +59,6 @@ void ProcessList_delete(ProcessList* this); char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); -/* - * Taken from OpenBSD's ps(1). - */ void ProcessList_goThroughEntries(ProcessList* this); - #endif diff --git a/openbsd/Platform.h b/openbsd/Platform.h index da1a17402..f51d6bc66 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -14,14 +14,11 @@ in the source distribution for its full text. extern ProcessFieldData Process_fields[]; - extern ProcessField Platform_defaultFields[]; extern int Platform_numberOfFields; -/* - * See /usr/include/sys/signal.h - */ +/* see /usr/include/sys/signal.h */ extern const SignalItem Platform_signals[]; extern const unsigned int Platform_numberOfSignals; @@ -30,7 +27,6 @@ void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; -// preserved from FreeBSD port int Platform_getUptime(); void Platform_getLoadAverage(double* one, double* five, double* fifteen); @@ -41,12 +37,6 @@ double Platform_setCPUValues(Meter* this, int cpu); void Platform_setMemoryValues(Meter* this); -/* - * Copyright (c) 1994 Thorsten Lockert - * All rights reserved. - * - * Taken almost directly from OpenBSD's top(1) - */ void Platform_setSwapValues(Meter* this); void Platform_setTasksValues(Meter* this); diff --git a/solaris/Battery.h b/solaris/Battery.h index 24d8f5c2d..21a1579ac 100644 --- a/solaris/Battery.h +++ b/solaris/Battery.h @@ -3,5 +3,4 @@ void Battery_getData(double* level, ACPresence* isOnAC); - #endif diff --git a/solaris/Platform.h b/solaris/Platform.h index 041bf3fbb..dd8614dcf 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -29,7 +29,6 @@ typedef struct envAccum_ { char *env; } envAccum; - extern double plat_loadavg[3]; extern const SignalItem Platform_signals[]; diff --git a/solaris/SolarisCRT.h b/solaris/SolarisCRT.h index 01b75696a..4e37b7f65 100644 --- a/solaris/SolarisCRT.h +++ b/solaris/SolarisCRT.h @@ -8,9 +8,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifdef HAVE_EXECINFO_H -#endif - void CRT_handleSIGSEGV(int sgn); #endif diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index a1064a30b..d36dea3ee 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -13,7 +13,7 @@ in the source distribution for its full text. #include #include -typedef enum SolarisProcessFields { +typedef enum SolarisProcessField_ { // Add platform-specific fields here, with ids >= 100 ZONEID = 100, ZONE = 101, @@ -25,7 +25,6 @@ typedef enum SolarisProcessFields { LAST_PROCESSFIELD = 107, } SolarisProcessField; - typedef struct SolarisProcess_ { Process super; int kernel; @@ -41,15 +40,9 @@ typedef struct SolarisProcess_ { pid_t lwpid; } SolarisProcess; - -#ifndef Process_isKernelThread #define Process_isKernelThread(_process) (_process->kernel == 1) -#endif -#ifndef Process_isUserlandThread #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -#endif - extern ProcessClass SolarisProcess_class; diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index 89ec46b26..259626857 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -46,7 +46,6 @@ typedef struct SolarisProcessList_ { ZfsArcStats zfs; } SolarisProcessList; - char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc); ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); @@ -63,5 +62,4 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * void ProcessList_goThroughEntries(ProcessList* this); - #endif diff --git a/unsupported/Battery.h b/unsupported/Battery.h index 24d8f5c2d..21a1579ac 100644 --- a/unsupported/Battery.h +++ b/unsupported/Battery.h @@ -3,5 +3,4 @@ void Battery_getData(double* level, ACPresence* isOnAC); - #endif diff --git a/unsupported/UnsupportedCRT.h b/unsupported/UnsupportedCRT.h index c8eff180f..24d63e5ca 100644 --- a/unsupported/UnsupportedCRT.h +++ b/unsupported/UnsupportedCRT.h @@ -9,5 +9,4 @@ in the source distribution for its full text. void CRT_handleSIGSEGV(int sgn); - #endif diff --git a/unsupported/UnsupportedProcess.h b/unsupported/UnsupportedProcess.h index 467297b5d..dbe9bf5e4 100644 --- a/unsupported/UnsupportedProcess.h +++ b/unsupported/UnsupportedProcess.h @@ -11,10 +11,8 @@ in the source distribution for its full text. #define Process_delete UnsupportedProcess_delete - Process* UnsupportedProcess_new(Settings* settings); void UnsupportedProcess_delete(Object* cast); - #endif diff --git a/unsupported/UnsupportedProcessList.h b/unsupported/UnsupportedProcessList.h index 093a8c438..69a7c1c7c 100644 --- a/unsupported/UnsupportedProcessList.h +++ b/unsupported/UnsupportedProcessList.h @@ -7,8 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/zfs/ZfsArcMeter.h b/zfs/ZfsArcMeter.h index c52083df2..e6b59d5b3 100644 --- a/zfs/ZfsArcMeter.h +++ b/zfs/ZfsArcMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_ZfsArcMeter #define HEADER_ZfsArcMeter /* diff --git a/zfs/ZfsArcStats.h b/zfs/ZfsArcStats.h index 9368ba9d2..087f3fc08 100644 --- a/zfs/ZfsArcStats.h +++ b/zfs/ZfsArcStats.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_ZfsArcStats #define HEADER_ZfsArcStats /* @@ -23,5 +21,4 @@ typedef struct ZfsArcStats_ { unsigned long long int uncompressed; } ZfsArcStats; - #endif diff --git a/zfs/ZfsCompressedArcMeter.h b/zfs/ZfsCompressedArcMeter.h index 5afcc99e6..8e6449352 100644 --- a/zfs/ZfsCompressedArcMeter.h +++ b/zfs/ZfsCompressedArcMeter.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_ZfsCompressedArcMeter #define HEADER_ZfsCompressedArcMeter /* diff --git a/zfs/openzfs_sysctl.h b/zfs/openzfs_sysctl.h index 6e44ac3b1..adb4b24cc 100644 --- a/zfs/openzfs_sysctl.h +++ b/zfs/openzfs_sysctl.h @@ -1,5 +1,3 @@ -/* Do not edit this file. It was automatically generated. */ - #ifndef HEADER_openzfs_sysctl #define HEADER_openzfs_sysctl /* From c5808c56db166528ae7e74cedb51cc466f973b9f Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Wed, 9 Sep 2020 16:56:04 +1000 Subject: [PATCH 156/411] Consolidate repeated macro definitions into one header The MIN, MAX, CLAMP, MINIMUM, and MAXIMUM macros appear throughout the codebase with many re-definitions. Make a single copy of each in a common header file, and use the BSD variants of MINIMUM/MAXIMUM due to conflicts in the system headers. --- CPUMeter.c | 7 ------- CPUMeter.h | 7 ------- EnvScreen.c | 2 +- Header.c | 9 +-------- Header.h | 4 ---- Macros.h | 16 +++++++++++++++ Makefile.am | 2 +- Meter.c | 11 ----------- Meter.h | 10 ---------- Object.h | 1 + Panel.c | 27 ++++++++++---------------- Panel.h | 7 ------- RichString.c | 6 +----- RichString.h | 5 ----- TasksMeter.c | 2 +- darwin/Platform.c | 4 ---- darwin/Platform.h | 4 ---- dragonflybsd/DragonFlyBSDProcessList.c | 2 +- dragonflybsd/Platform.c | 4 ---- dragonflybsd/Platform.h | 4 ---- freebsd/FreeBSDProcessList.c | 2 +- freebsd/Platform.c | 4 ---- freebsd/Platform.h | 4 ---- linux/LinuxProcessList.c | 6 +----- linux/LinuxProcessList.h | 4 ---- linux/Platform.c | 4 ---- linux/Platform.h | 4 ---- openbsd/OpenBSDProcessList.c | 15 -------------- openbsd/OpenBSDProcessList.h | 14 ------------- 29 files changed, 35 insertions(+), 156 deletions(-) create mode 100644 Macros.h diff --git a/CPUMeter.c b/CPUMeter.c index b6e4deab1..df5585e9e 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -20,13 +20,6 @@ int CPUMeter_attributes[] = { CPU_NICE, CPU_NORMAL, CPU_SYSTEM, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT }; -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - static void CPUMeter_init(Meter* this) { int cpu = this->param; if (this->pl->cpuCount > 1) { diff --git a/CPUMeter.h b/CPUMeter.h index 2caa82918..d66eefbb8 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -24,13 +24,6 @@ typedef enum { extern int CPUMeter_attributes[]; -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - extern MeterClass CPUMeter_class; extern MeterClass AllCPUsMeter_class; diff --git a/EnvScreen.c b/EnvScreen.c index fa6ffdcf7..479a45d6c 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -37,7 +37,7 @@ void EnvScreen_draw(InfoScreen* this) { void EnvScreen_scan(InfoScreen* this) { Panel* panel = this->display; - int idx = MAX(Panel_getSelectedIndex(panel), 0); + int idx = MAXIMUM(Panel_getSelectedIndex(panel), 0); Panel_prune(panel); diff --git a/Header.c b/Header.c index ffd31a244..574165a6e 100644 --- a/Header.c +++ b/Header.c @@ -16,14 +16,7 @@ in the source distribution for its full text. #include #include - -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - -#ifndef Header_forEachColumn #define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_)) -#endif Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) { Header* this = xCalloc(1, sizeof(Header)); @@ -196,7 +189,7 @@ int Header_calculateHeight(Header* this) { Meter* meter = (Meter*) Vector_get(meters, i); height += meter->h; } - maxHeight = MAX(maxHeight, height); + maxHeight = MAXIMUM(maxHeight, height); } this->height = maxHeight; this->pad = pad; diff --git a/Header.h b/Header.h index e281a0c2e..b221becfa 100644 --- a/Header.h +++ b/Header.h @@ -20,10 +20,6 @@ typedef struct Header_ { int height; } Header; -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - #define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_)) Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns); diff --git a/Macros.h b/Macros.h new file mode 100644 index 000000000..cb84b2916 --- /dev/null +++ b/Macros.h @@ -0,0 +1,16 @@ +#ifndef HEADER_Macros +#define HEADER_Macros + +#ifndef MINIMUM +#define MINIMUM(a, b) ((a) < (b) ? (a) : (b)) +#endif + +#ifndef MAXIMUM +#define MAXIMUM(a, b) ((a) > (b) ? (a) : (b)) +#endif + +#ifndef CLAMP +#define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low)) +#endif + +#endif diff --git a/Makefile.am b/Makefile.am index fbbf7bef6..50fb586bb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,7 +34,7 @@ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.h \ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \ -EnvScreen.h InfoScreen.h XAlloc.h +EnvScreen.h InfoScreen.h XAlloc.h Macros.h # Linux # ----- diff --git a/Meter.c b/Meter.c index ffdfc3e08..34f428ffd 100644 --- a/Meter.c +++ b/Meter.c @@ -27,17 +27,6 @@ in the source distribution for its full text. #define GRAPH_HEIGHT 4 /* Unit: rows (lines) */ - -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - MeterClass Meter_class = { .super = { .extends = Class(Object) diff --git a/Meter.h b/Meter.h index 7936fb782..773d94ff6 100644 --- a/Meter.h +++ b/Meter.h @@ -94,16 +94,6 @@ typedef struct GraphData_ { double values[METER_BUFFER_LEN]; } GraphData; -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - extern MeterClass Meter_class; Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type); diff --git a/Object.h b/Object.h index e73230c0d..50a5f12db 100644 --- a/Object.h +++ b/Object.h @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "RichString.h" #include "XAlloc.h" +#include "Macros.h" typedef struct Object_ Object; diff --git a/Panel.c b/Panel.c index 73fa7858e..883b3e626 100644 --- a/Panel.c +++ b/Panel.c @@ -19,13 +19,6 @@ in the source distribution for its full text. #include #include -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - #define KEY_CTRL(l) ((l)-'A'+1) PanelClass Panel_class = { @@ -233,7 +226,7 @@ void Panel_draw(Panel* this, bool focus) { mvhline(y, x, ' ', this->w); if (scrollH < headerLen) { RichString_printoffnVal(this->header, y, x, scrollH, - MIN(headerLen - scrollH, this->w)); + MINIMUM(headerLen - scrollH, this->w)); } attrset(CRT_colors[RESET_COLOR]); y++; @@ -244,7 +237,7 @@ void Panel_draw(Panel* this, bool focus) { this->scrollV = 0; this->needsRedraw = true; } else if (this->scrollV >= size) { - this->scrollV = MAX(size - 1, 0); + this->scrollV = MAXIMUM(size - 1, 0); this->needsRedraw = true; } // ensure selection is on screen @@ -257,7 +250,7 @@ void Panel_draw(Panel* this, bool focus) { } int first = this->scrollV; - int upTo = MIN(first + h, size); + int upTo = MINIMUM(first + h, size); int selectionColor = focus ? this->selectionColor @@ -271,7 +264,7 @@ void Panel_draw(Panel* this, bool focus) { RichString_begin(item); Object_display(itemObj, &item); int itemLen = RichString_sizeVal(item); - int amt = MIN(itemLen - scrollH, this->w); + int amt = MINIMUM(itemLen - scrollH, this->w); bool selected = (i == this->selected); if (selected) { attrset(selectionColor); @@ -306,13 +299,13 @@ void Panel_draw(Panel* this, bool focus) { mvhline(y+ this->oldSelected - first, x+0, ' ', this->w); if (scrollH < oldLen) RichString_printoffnVal(old, y+this->oldSelected - first, x, - scrollH, MIN(oldLen - scrollH, this->w)); + scrollH, MINIMUM(oldLen - scrollH, this->w)); attrset(selectionColor); mvhline(y+this->selected - first, x+0, ' ', this->w); RichString_setAttr(&new, selectionColor); if (scrollH < newLen) RichString_printoffnVal(new, y+this->selected - first, x, - scrollH, MIN(newLen - scrollH, this->w)); + scrollH, MINIMUM(newLen - scrollH, this->w)); attrset(CRT_colors[RESET_COLOR]); RichString_end(new); RichString_end(old); @@ -347,7 +340,7 @@ bool Panel_onKey(Panel* this, int key) { case KEY_LEFT: case KEY_CTRL('B'): if (this->scrollH > 0) { - this->scrollH -= MAX(CRT_scrollHAmount, 0); + this->scrollH -= MAXIMUM(CRT_scrollHAmount, 0); this->needsRedraw = true; } break; @@ -358,12 +351,12 @@ bool Panel_onKey(Panel* this, int key) { break; case KEY_PPAGE: this->selected -= (this->h - 1); - this->scrollV = MAX(0, this->scrollV - this->h + 1); + this->scrollV = MAXIMUM(0, this->scrollV - this->h + 1); this->needsRedraw = true; break; case KEY_NPAGE: this->selected += (this->h - 1); - this->scrollV = MAX(0, MIN(Vector_size(this->items) - this->h, + this->scrollV = MAXIMUM(0, MINIMUM(Vector_size(this->items) - this->h, this->scrollV + this->h - 1)); this->needsRedraw = true; break; @@ -395,7 +388,7 @@ bool Panel_onKey(Panel* this, int key) { break; case KEY_CTRL('E'): case '$': - this->scrollH = MAX(this->selectedLen - this->w, 0); + this->scrollH = MAXIMUM(this->selectedLen - this->w, 0); this->needsRedraw = true; break; default: diff --git a/Panel.h b/Panel.h index 17b65c950..480e2c0fe 100644 --- a/Panel.h +++ b/Panel.h @@ -59,13 +59,6 @@ struct Panel_ { #define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0) -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - #define KEY_CTRL(l) ((l)-'A'+1) extern PanelClass Panel_class; diff --git a/RichString.c b/RichString.c index 702ab329f..95ddf2976 100644 --- a/RichString.c +++ b/RichString.c @@ -7,17 +7,13 @@ in the source distribution for its full text. #include "RichString.h" #include "XAlloc.h" +#include "Macros.h" #include #include #define RICHSTRING_MAXLEN 350 - -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - #define charBytes(n) (sizeof(CharType) * (n)) static void RichString_extendLen(RichString* this, int len) { diff --git a/RichString.h b/RichString.h index 59b77496c..5431e92a0 100644 --- a/RichString.h +++ b/RichString.h @@ -56,11 +56,6 @@ typedef struct RichString_ { CharType chstr[RICHSTRING_MAXLEN+1]; } RichString; - -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - #define charBytes(n) (sizeof(CharType) * (n)) #define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0) diff --git a/TasksMeter.c b/TasksMeter.c index 49816bdb2..0b37ab274 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -20,7 +20,7 @@ static void TasksMeter_updateValues(Meter* this, char* buffer, int len) { this->values[0] = pl->kernelThreads; this->values[1] = pl->userlandThreads; this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads; - this->values[3] = MIN(pl->runningTasks, pl->cpuCount); + this->values[3] = MINIMUM(pl->runningTasks, pl->cpuCount); if (pl->totalTasks > this->total) { this->total = pl->totalTasks; } diff --git a/darwin/Platform.c b/darwin/Platform.c index f8007d826..a8ca45b24 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -22,10 +22,6 @@ in the source distribution for its full text. #include -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; const SignalItem Platform_signals[] = { diff --git a/darwin/Platform.h b/darwin/Platform.h index 5ce23684f..7dd4ae608 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -14,10 +14,6 @@ in the source distribution for its full text. #include "BatteryMeter.h" #include "DarwinProcess.h" -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - extern ProcessField Platform_defaultFields[]; extern const SignalItem Platform_signals[]; diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index d77f12eb4..08303ba6e 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -97,7 +97,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_o, &len, NULL, 0); } - pl->cpuCount = MAX(cpus, 1); + pl->cpuCount = MAXIMUM(cpus, 1); if (cpus == 1 ) { dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData)); diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 84f137078..3b8e1a0d9 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -28,10 +28,6 @@ in the source distribution for its full text. #include -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; int Platform_numberOfFields = LAST_PROCESSFIELD; diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index c6792a28b..83c14f518 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -14,10 +14,6 @@ in the source distribution for its full text. extern ProcessFieldData Process_fields[]; -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - extern ProcessField Platform_defaultFields[]; extern int Platform_numberOfFields; diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 344c33141..a4deaad9a 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -111,7 +111,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui sysctl(MIB_kern_cp_times, 2, fpl->cp_times_o, &len, NULL, 0); } - pl->cpuCount = MAX(cpus, 1); + pl->cpuCount = MAXIMUM(cpus, 1); if (cpus == 1 ) { fpl->cpus = xRealloc(fpl->cpus, sizeof(CPUData)); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 58a9bf1b1..c51b37cb7 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -29,10 +29,6 @@ in the source distribution for its full text. #include -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; int Platform_numberOfFields = LAST_PROCESSFIELD; diff --git a/freebsd/Platform.h b/freebsd/Platform.h index fd7045392..1a180551c 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -13,10 +13,6 @@ in the source distribution for its full text. extern ProcessFieldData Process_fields[]; -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - extern ProcessField Platform_defaultFields[]; extern int Platform_numberOfFields; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index a6fdada87..c9303a048 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -42,10 +42,6 @@ in the source distribution for its full text. #include #endif -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - static ssize_t xread(int fd, void *buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; @@ -194,7 +190,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui fclose(file); - pl->cpuCount = MAX(cpus - 1, 1); + pl->cpuCount = MAXIMUM(cpus - 1, 1); this->cpus = xCalloc(cpus, sizeof(CPUData)); for (int i = 0; i < cpus; i++) { diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index d689d4ac1..aa7317ab2 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -92,10 +92,6 @@ typedef struct LinuxProcessList_ { #define PROC_LINE_LENGTH 4096 #endif -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_delete(ProcessList* pl); diff --git a/linux/Platform.c b/linux/Platform.c index d48dc7642..ffe5c5c29 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -33,10 +33,6 @@ in the source distribution for its full text. #include -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, (int)M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; //static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 }; diff --git a/linux/Platform.h b/linux/Platform.h index 922a33924..9f0ee7fda 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -13,10 +13,6 @@ in the source distribution for its full text. #include "LinuxProcess.h" #include "SignalsPanel.h" -#ifndef CLAMP -#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) -#endif - extern ProcessField Platform_defaultFields[]; extern int Platform_numberOfFields; diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 0d1a72266..71cd56273 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -27,21 +27,6 @@ in the source distribution for its full text. #include #include -/* - * avoid relying on or conflicting with MIN() and MAX() in sys/param.h - */ -#ifndef MINIMUM -#define MINIMUM(x, y) ((x) > (y) ? (y) : (x)) -#endif - -#ifndef MAXIMUM -#define MAXIMUM(x, y) ((x) > (y) ? (x) : (y)) -#endif - -#ifndef CLAMP -#define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low)) -#endif - static long fscale; ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index 038a263df..d22243f7e 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -38,20 +38,6 @@ typedef struct OpenBSDProcessList_ { } OpenBSDProcessList; -/* - * avoid relying on or conflicting with MIN() and MAX() in sys/param.h - */ -#ifndef MINIMUM -#define MINIMUM(x, y) ((x) > (y) ? (y) : (x)) -#endif - -#ifndef MAXIMUM -#define MAXIMUM(x, y) ((x) > (y) ? (x) : (y)) -#endif - -#ifndef CLAMP -#define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low)) -#endif ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); From 459733295954ec0d5958f9a8d955d0c164876c84 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Wed, 9 Sep 2020 19:38:15 +1000 Subject: [PATCH 157/411] Switch variable/field naming from WhiteList to MatchList --- ProcessList.c | 6 +++--- ProcessList.h | 6 +++--- darwin/DarwinProcessList.c | 4 ++-- darwin/DarwinProcessList.h | 2 +- dragonflybsd/DragonFlyBSDProcessList.c | 4 ++-- dragonflybsd/DragonFlyBSDProcessList.h | 2 +- freebsd/FreeBSDProcessList.c | 4 ++-- freebsd/FreeBSDProcessList.h | 2 +- htop.c | 16 ++++++++-------- linux/LinuxProcessList.c | 4 ++-- linux/LinuxProcessList.h | 2 +- openbsd/OpenBSDProcessList.c | 2 +- openbsd/OpenBSDProcessList.h | 2 +- solaris/SolarisProcessList.c | 4 ++-- solaris/SolarisProcessList.h | 2 +- unsupported/UnsupportedProcessList.c | 4 ++-- unsupported/UnsupportedProcessList.h | 2 +- 17 files changed, 34 insertions(+), 34 deletions(-) diff --git a/ProcessList.c b/ProcessList.c index 025c87afc..aa529d5b1 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -15,11 +15,11 @@ in the source distribution for its full text. #include -ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { +ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { this->processes = Vector_new(klass, true, DEFAULT_SIZE); this->processTable = Hashtable_new(140, false); this->usersTable = usersTable; - this->pidWhiteList = pidWhiteList; + this->pidMatchList = pidMatchList; this->userId = userId; // tree-view auxiliary buffer @@ -254,7 +254,7 @@ void ProcessList_rebuildPanel(ProcessList* this) { if ( (!p->show) || (this->userId != (uid_t) -1 && (p->st_uid != this->userId)) || (incFilter && !(String_contains_i(p->comm, incFilter))) - || (this->pidWhiteList && !Hashtable_get(this->pidWhiteList, p->tgid)) ) + || (this->pidMatchList && !Hashtable_get(this->pidMatchList, p->tgid)) ) hidden = true; if (!hidden) { diff --git a/ProcessList.h b/ProcessList.h index 73f6c687a..7b572d8f1 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -38,7 +38,7 @@ typedef struct ProcessList_ { int following; uid_t userId; const char* incFilter; - Hashtable* pidWhiteList; + Hashtable* pidMatchList; #ifdef HAVE_LIBHWLOC hwloc_topology_t topology; @@ -64,12 +64,12 @@ typedef struct ProcessList_ { } ProcessList; -ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* pl); void ProcessList_goThroughEntries(ProcessList* pl); -ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_done(ProcessList* this); diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index cedabc9d6..39d99c159 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -114,11 +114,11 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { return processes; } -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { size_t len; DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList)); - ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId); + ProcessList_init(&this->super, Class(Process), usersTable, pidMatchList, userId); /* Initialize the CPU information */ this->super.cpuCount = ProcessList_allocateCPULoadInfo(&this->prev_load); diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index 7d6f53435..c6b29665e 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -47,7 +47,7 @@ void ProcessList_getVMStats(vm_statistics_t p); struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count); -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 08303ba6e..cd5526a70 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -41,12 +41,12 @@ static int MIB_kern_cp_time[2]; static int MIB_kern_cp_times[2]; static int kernelFScale; -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { size_t len; char errbuf[_POSIX2_LINE_MAX]; DragonFlyBSDProcessList* dfpl = xCalloc(1, sizeof(DragonFlyBSDProcessList)); ProcessList* pl = (ProcessList*) dfpl; - ProcessList_init(pl, Class(DragonFlyBSDProcess), usersTable, pidWhiteList, userId); + ProcessList_init(pl, Class(DragonFlyBSDProcess), usersTable, pidMatchList, userId); // physical memory in system: hw.physmem // physical page size: hw.pagesize diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index 403aa0965..84ab1c5a9 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -53,7 +53,7 @@ typedef struct DragonFlyBSDProcessList_ { #define _UNUSED_ __attribute__((unused)) -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index a4deaad9a..6318d4240 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -41,12 +41,12 @@ static int MIB_kern_cp_time[2]; static int MIB_kern_cp_times[2]; static int kernelFScale; -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { size_t len; char errbuf[_POSIX2_LINE_MAX]; FreeBSDProcessList* fpl = xCalloc(1, sizeof(FreeBSDProcessList)); ProcessList* pl = (ProcessList*) fpl; - ProcessList_init(pl, Class(FreeBSDProcess), usersTable, pidWhiteList, userId); + ProcessList_init(pl, Class(FreeBSDProcess), usersTable, pidMatchList, userId); // physical memory in system: hw.physmem // physical page size: hw.pagesize diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 1805c5af3..281bf3e2c 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -48,7 +48,7 @@ typedef struct FreeBSDProcessList_ { } FreeBSDProcessList; -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/htop.c b/htop.c index 37727d00e..2cf2602e4 100644 --- a/htop.c +++ b/htop.c @@ -57,7 +57,7 @@ static void printHelpFlag() { // ---------------------------------------- typedef struct CommandLineSettings_ { - Hashtable* pidWhiteList; + Hashtable* pidMatchList; uid_t userId; int sortKey; int delay; @@ -70,7 +70,7 @@ typedef struct CommandLineSettings_ { static CommandLineSettings parseArguments(int argc, char** argv) { CommandLineSettings flags = { - .pidWhiteList = NULL, + .pidMatchList = NULL, .userId = -1, // -1 is guaranteed to be an invalid uid_t (see setreuid(2)) .sortKey = 0, .delay = -1, @@ -163,13 +163,13 @@ static CommandLineSettings parseArguments(int argc, char** argv) { char* saveptr; char* pid = strtok_r(argCopy, ",", &saveptr); - if(!flags.pidWhiteList) { - flags.pidWhiteList = Hashtable_new(8, false); + if(!flags.pidMatchList) { + flags.pidMatchList = Hashtable_new(8, false); } while(pid) { unsigned int num_pid = atoi(pid); - Hashtable_put(flags.pidWhiteList, num_pid, (void *) 1); + Hashtable_put(flags.pidMatchList, num_pid, (void *) 1); pid = strtok_r(NULL, ",", &saveptr); } free(argCopy); @@ -215,7 +215,7 @@ int main(int argc, char** argv) { Process_setupColumnWidths(); UsersTable* ut = UsersTable_new(); - ProcessList* pl = ProcessList_new(ut, flags.pidWhiteList, flags.userId); + ProcessList* pl = ProcessList_new(ut, flags.pidMatchList, flags.userId); Settings* settings = Settings_new(pl->cpuCount); pl->settings = settings; @@ -281,8 +281,8 @@ int main(int argc, char** argv) { UsersTable_delete(ut); Settings_delete(settings); - if(flags.pidWhiteList) { - Hashtable_delete(flags.pidWhiteList); + if(flags.pidMatchList) { + Hashtable_delete(flags.pidMatchList); } return 0; } diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index c9303a048..8dae13c5e 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -149,11 +149,11 @@ static void LinuxProcessList_initNetlinkSocket(LinuxProcessList* this) { #endif -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { LinuxProcessList* this = xCalloc(1, sizeof(LinuxProcessList)); ProcessList* pl = &(this->super); - ProcessList_init(pl, Class(LinuxProcess), usersTable, pidWhiteList, userId); + ProcessList_init(pl, Class(LinuxProcess), usersTable, pidMatchList, userId); LinuxProcessList_initTtyDrivers(this); #ifdef HAVE_DELAYACCT diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index aa7317ab2..c484e75c8 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -92,7 +92,7 @@ typedef struct LinuxProcessList_ { #define PROC_LINE_LENGTH 4096 #endif -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* pl); diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 71cd56273..0fe43ba74 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -29,7 +29,7 @@ in the source distribution for its full text. static long fscale; -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { int mib[] = { CTL_HW, HW_NCPU }; int fmib[] = { CTL_KERN, KERN_FSCALE }; int i, e; diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index d22243f7e..0d9defbc8 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -39,7 +39,7 @@ typedef struct OpenBSDProcessList_ { } OpenBSDProcessList; -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index e4074a7e0..4e4d28281 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -38,10 +38,10 @@ char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { return zname; } -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { SolarisProcessList* spl = xCalloc(1, sizeof(SolarisProcessList)); ProcessList* pl = (ProcessList*) spl; - ProcessList_init(pl, Class(SolarisProcess), usersTable, pidWhiteList, userId); + ProcessList_init(pl, Class(SolarisProcess), usersTable, pidMatchList, userId); spl->kd = kstat_open(); diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index 259626857..9da39b4a0 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -48,7 +48,7 @@ typedef struct SolarisProcessList_ { char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc); -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* pl); diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index cad579c23..fc8a54dc8 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -12,9 +12,9 @@ in the source distribution for its full text. #include -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { ProcessList* this = xCalloc(1, sizeof(ProcessList)); - ProcessList_init(this, Class(Process), usersTable, pidWhiteList, userId); + ProcessList_init(this, Class(Process), usersTable, pidMatchList, userId); return this; } diff --git a/unsupported/UnsupportedProcessList.h b/unsupported/UnsupportedProcessList.h index 69a7c1c7c..c4b51acf9 100644 --- a/unsupported/UnsupportedProcessList.h +++ b/unsupported/UnsupportedProcessList.h @@ -7,7 +7,7 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* this); From d5eb72e64d2fbacb2b7045a07468b6bb1b8435a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 12 Sep 2020 18:14:39 +0200 Subject: [PATCH 158/411] Drop always true condition `env` is allocated by checked allocation functions and can not be NULL. This checks confuses clang analyzer and causes a null-dereference warning on `env[size-1]`. --- linux/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/Platform.c b/linux/Platform.c index ffe5c5c29..e82d8f88f 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -237,7 +237,7 @@ char* Platform_getProcessEnv(pid_t pid) { if (fd) { size_t capacity = 4096, size = 0, bytes; env = xMalloc(capacity); - while (env && (bytes = fread(env+size, 1, capacity-size, fd)) > 0) { + while ((bytes = fread(env+size, 1, capacity-size, fd)) > 0) { size += bytes; capacity *= 2; env = xRealloc(env, capacity); From 9207401f9711ba026a70d7dd47347d7eab168b3f Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Sat, 12 Sep 2020 18:25:25 -0300 Subject: [PATCH 159/411] Clean up some code duplication in the header files PR htop-dev/htop#70 got rid of the infrastructure for generating header files, but it left behind some code duplication. Some of cases are things that belong in the header file and don't need to be repeated in the C file. Other cases are things that belong in the C file and don't need to be in the header file. In this commit I tried to fix all of these that I could find. When given a choice I preferred keeping things out of the header file, unless they were being used by someone else. --- Action.h | 4 ---- Affinity.h | 8 -------- CRT.c | 11 +---------- CRT.h | 27 +-------------------------- ColorsPanel.h | 6 ------ Header.c | 2 -- IncSet.c | 1 - Meter.c | 4 ---- Meter.h | 25 ++----------------------- MetersPanel.h | 8 -------- Panel.c | 2 -- Process.c | 23 ----------------------- Process.h | 4 ---- RichString.c | 2 -- RichString.h | 7 ++----- Settings.c | 2 -- StringUtils.c | 6 ------ TraceScreen.c | 1 - Vector.c | 4 ++-- Vector.h | 4 ---- 20 files changed, 8 insertions(+), 143 deletions(-) diff --git a/Action.h b/Action.h index cf0169c48..8e5cc9b62 100644 --- a/Action.h +++ b/Action.h @@ -37,14 +37,10 @@ typedef struct State_ { Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess); -// ---------------------------------------- - bool Action_setUserOnly(const char* userName, uid_t* userId); Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey); -// ---------------------------------------- - Htop_Reaction Action_follow(State* st); void Action_setBindings(Htop_Action* keys); diff --git a/Affinity.h b/Affinity.h index 6bdd9750b..526194579 100644 --- a/Affinity.h +++ b/Affinity.h @@ -8,14 +8,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifdef HAVE_LIBHWLOC -#if __linux__ -#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_THREAD -#else -#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS -#endif -#endif - #include "Process.h" #include "ProcessList.h" diff --git a/CRT.c b/CRT.c index 2a7c7912b..7776c4e74 100644 --- a/CRT.c +++ b/CRT.c @@ -39,10 +39,6 @@ in the source distribution for its full text. #define ColorPairGrayBlack ColorPair(Magenta,Magenta) #define ColorIndexGrayBlack ColorIndex(Magenta,Magenta) -#define KEY_WHEELUP KEY_F(20) -#define KEY_WHEELDOWN KEY_F(21) -#define KEY_RECLICK KEY_F(22) - const char *CRT_treeStrAscii[TREE_STR_COUNT] = { "-", // TREE_STR_HORZ "|", // TREE_STR_VERT @@ -550,12 +546,7 @@ void CRT_restorePrivileges() { #else -/* Turn setuid operations into NOPs */ - -#ifndef CRT_dropPrivileges -#define CRT_dropPrivileges() -#define CRT_restorePrivileges() -#endif +// In this case, the setuid operations are defined as macros in CRT.h #endif diff --git a/CRT.h b/CRT.h index 2e21e91eb..80d1eb71e 100644 --- a/CRT.h +++ b/CRT.h @@ -7,31 +7,12 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#if HAVE_SETUID_ENABLED -#endif - -#define ColorIndex(i,j) ((7-i)*8+j) - -#define ColorPair(i,j) COLOR_PAIR(ColorIndex(i,j)) - -#define Black COLOR_BLACK -#define Red COLOR_RED -#define Green COLOR_GREEN -#define Yellow COLOR_YELLOW -#define Blue COLOR_BLUE -#define Magenta COLOR_MAGENTA -#define Cyan COLOR_CYAN -#define White COLOR_WHITE - -#define ColorPairGrayBlack ColorPair(Magenta,Magenta) -#define ColorIndexGrayBlack ColorIndex(Magenta,Magenta) +#include #define KEY_WHEELUP KEY_F(20) #define KEY_WHEELDOWN KEY_F(21) #define KEY_RECLICK KEY_F(22) -#include - typedef enum TreeStr_ { TREE_STR_HORZ, TREE_STR_VERT, @@ -158,16 +139,12 @@ extern int CRT_scrollWheelVAmount; extern char* CRT_termType; -// TODO move color scheme to Settings, perhaps? - extern int CRT_colorScheme; extern void *backtraceArray[128]; #if HAVE_SETUID_ENABLED -#define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0) - void CRT_dropPrivileges(); void CRT_restorePrivileges(); @@ -183,8 +160,6 @@ void CRT_restorePrivileges(); #endif -// TODO: pass an instance of Settings instead. - void CRT_init(int delay, int colorScheme, bool allowUnicode); void CRT_done(); diff --git a/ColorsPanel.h b/ColorsPanel.h index 9977dc0b5..479fad084 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -7,12 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -// TO ADD A NEW SCHEME: -// * Increment the size of bool check in ColorsPanel.h -// * Add the entry in the ColorSchemeNames array below in the file -// * Add a define in CRT.h that matches the order of the array -// * Add the colors in CRT_setColors - #include "Panel.h" #include "Settings.h" #include "ScreenManager.h" diff --git a/Header.c b/Header.c index 574165a6e..d2f3b8846 100644 --- a/Header.c +++ b/Header.c @@ -16,8 +16,6 @@ in the source distribution for its full text. #include #include -#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_)) - Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) { Header* this = xCalloc(1, sizeof(Header)); this->columns = xCalloc(nrColumns, sizeof(Vector*)); diff --git a/IncSet.c b/IncSet.c index 90ce8b9fe..e9e289346 100644 --- a/IncSet.c +++ b/IncSet.c @@ -7,7 +7,6 @@ in the source distribution for its full text. #include "IncSet.h" #include "StringUtils.h" -#include "Panel.h" #include "ListItem.h" #include "CRT.h" #include diff --git a/Meter.c b/Meter.c index 34f428ffd..00c49ceea 100644 --- a/Meter.c +++ b/Meter.c @@ -11,7 +11,6 @@ in the source distribution for its full text. #include "Object.h" #include "CRT.h" #include "StringUtils.h" -#include "ListItem.h" #include "Settings.h" #include @@ -19,9 +18,6 @@ in the source distribution for its full text. #include #include #include -#include - -#define METER_BUFFER_LEN 256 #define GRAPH_DELAY (DEFAULT_DELAY/2) diff --git a/Meter.h b/Meter.h index 773d94ff6..c4d00396e 100644 --- a/Meter.h +++ b/Meter.h @@ -7,16 +7,11 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define METER_BUFFER_LEN 256 - -#define GRAPH_DELAY (DEFAULT_DELAY/2) - -#define GRAPH_HEIGHT 4 /* Unit: rows (lines) */ - #include "ListItem.h" - #include +#define METER_BUFFER_LEN 256 + typedef struct Meter_ Meter; typedef void(*Meter_Init)(Meter*); @@ -108,24 +103,8 @@ void Meter_setMode(Meter* this, int modeIndex); ListItem* Meter_toListItem(Meter* this, bool moving); -/* ---------- TextMeterMode ---------- */ - -/* ---------- BarMeterMode ---------- */ - -/* ---------- GraphMeterMode ---------- */ - -#ifdef HAVE_LIBNCURSESW -#define PIXPERROW_UTF8 4 -#endif - -#define PIXPERROW_ASCII 2 - -/* ---------- LEDMeterMode ---------- */ - extern MeterMode* Meter_modes[]; -/* Blank meter */ - extern int BlankMeter_attributes[]; extern MeterClass BlankMeter_class; diff --git a/MetersPanel.h b/MetersPanel.h index bea9238dc..c02ce1cd9 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -24,14 +24,6 @@ struct MetersPanel_ { bool moving; }; - -// Note: In code the meters are known to have bar/text/graph "Modes", but in UI -// we call them "Styles". -// We avoid UTF-8 arrows ← → here as they might display full-width on Chinese -// terminals, breaking our aligning. -// In , arrows (U+2019..U+2199) are -// considered "Ambiguous characters". - void MetersPanel_setMoving(MetersPanel* this, bool moving); extern PanelClass MetersPanel_class; diff --git a/Panel.c b/Panel.c index 883b3e626..b77483d94 100644 --- a/Panel.c +++ b/Panel.c @@ -19,8 +19,6 @@ in the source distribution for its full text. #include #include -#define KEY_CTRL(l) ((l)-'A'+1) - PanelClass Panel_class = { .super = { .extends = Class(Object), diff --git a/Process.c b/Process.c index e7ab4929b..7a04c0f93 100644 --- a/Process.c +++ b/Process.c @@ -21,7 +21,6 @@ in the source distribution for its full text. #include #include #include -#include #include #include #include @@ -37,30 +36,8 @@ in the source distribution for its full text. #include #endif -#ifdef __ANDROID__ -#define SYS_ioprio_get __NR_ioprio_get -#define SYS_ioprio_set __NR_ioprio_set -#endif - -// On Linux, this works only with glibc 2.1+. On earlier versions -// the behavior is similar to have a hardcoded page size. -#ifndef PAGE_SIZE -#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) ) -#endif -#define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K ) - static int Process_getuid = -1; -#define ONE_K 1024L -#define ONE_M (ONE_K * ONE_K) -#define ONE_G (ONE_M * ONE_K) -#define ONE_T ((long long)ONE_G * ONE_K) - -#define ONE_DECIMAL_K 1000L -#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K) -#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K) -#define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K) - char Process_pidFormat[20] = "%7d "; static char Process_titleBuffer[20][20]; diff --git a/Process.h b/Process.h index 9aca41c96..ebf5cdf47 100644 --- a/Process.h +++ b/Process.h @@ -8,10 +8,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifdef MAJOR_IN_MKDEV -#elif defined(MAJOR_IN_SYSMACROS) -#endif - #ifdef __ANDROID__ #define SYS_ioprio_get __NR_ioprio_get #define SYS_ioprio_set __NR_ioprio_set diff --git a/RichString.c b/RichString.c index 95ddf2976..b97e34e55 100644 --- a/RichString.c +++ b/RichString.c @@ -12,8 +12,6 @@ in the source distribution for its full text. #include #include -#define RICHSTRING_MAXLEN 350 - #define charBytes(n) (sizeof(CharType) * (n)) static void RichString_extendLen(RichString* this, int len) { diff --git a/RichString.h b/RichString.h index 5431e92a0..e6fb4c320 100644 --- a/RichString.h +++ b/RichString.h @@ -7,7 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define RICHSTRING_MAXLEN 350 #include "config.h" #include @@ -50,16 +49,14 @@ in the source distribution for its full text. #define CharType chtype #endif +#define RICHSTRING_MAXLEN 350 + typedef struct RichString_ { int chlen; CharType* chptr; CharType chstr[RICHSTRING_MAXLEN+1]; } RichString; -#define charBytes(n) (sizeof(CharType) * (n)) - -#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0) - #ifdef HAVE_LIBNCURSESW void RichString_setAttrn(RichString* this, int attrs, int start, int finish); diff --git a/Settings.c b/Settings.c index 104d9bb99..c9c75d4a5 100644 --- a/Settings.c +++ b/Settings.c @@ -17,8 +17,6 @@ in the source distribution for its full text. #include #include -#define DEFAULT_DELAY 15 - void Settings_delete(Settings* this) { free(this->filename); free(this->fields); diff --git a/StringUtils.c b/StringUtils.c index 6bae8227a..e2386e3cd 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -14,12 +14,6 @@ in the source distribution for its full text. #include #include - -/* - * String_startsWith gives better performance if strlen(match) can be computed - * at compile time (e.g. when they are immutable string literals). :) - */ - char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); diff --git a/TraceScreen.c b/TraceScreen.c index 99b56a05c..0a3485ecc 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -8,7 +8,6 @@ in the source distribution for its full text. #include "TraceScreen.h" #include "CRT.h" -#include "InfoScreen.h" #include "ProcessList.h" #include "ListItem.h" #include "IncSet.h" diff --git a/Vector.c b/Vector.c index e7776ea3c..e51fd7b15 100644 --- a/Vector.c +++ b/Vector.c @@ -261,7 +261,7 @@ inline Object* Vector_get(Vector* this, int idx) { #else -#define Vector_get(v_, idx_) ((v_)->array[idx_]) +// In this case, Vector_get is defined as a macro in vector.h #endif @@ -274,7 +274,7 @@ inline int Vector_size(Vector* this) { #else -#define Vector_size(v_) ((v_)->items) +// In this case, Vector_size is defined as a macro in vector.h #endif diff --git a/Vector.h b/Vector.h index 32cd809e9..209e27cff 100644 --- a/Vector.h +++ b/Vector.h @@ -72,10 +72,6 @@ int Vector_size(Vector* this); #endif -/* - -*/ - void Vector_add(Vector* this, void* data_); int Vector_indexOf(Vector* this, void* search_, Object_Compare compare); From 5ad3c11eaad3f75b09569758e0b67d18933a6278 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Sat, 12 Sep 2020 19:16:07 -0300 Subject: [PATCH 160/411] Alignment tweak --- CRT.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRT.h b/CRT.h index 80d1eb71e..8a5d6ac6e 100644 --- a/CRT.h +++ b/CRT.h @@ -9,9 +9,9 @@ in the source distribution for its full text. #include -#define KEY_WHEELUP KEY_F(20) +#define KEY_WHEELUP KEY_F(20) #define KEY_WHEELDOWN KEY_F(21) -#define KEY_RECLICK KEY_F(22) +#define KEY_RECLICK KEY_F(22) typedef enum TreeStr_ { TREE_STR_HORZ, From a2ef400e4354125183015700fc859300ec63c477 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Sat, 12 Sep 2020 19:18:23 -0300 Subject: [PATCH 161/411] Merge identical ifdefs in Affinity.h --- Affinity.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Affinity.h b/Affinity.h index 526194579..20d004709 100644 --- a/Affinity.h +++ b/Affinity.h @@ -24,13 +24,7 @@ void Affinity_delete(Affinity* this); void Affinity_add(Affinity* this, int id); -#ifdef HAVE_LIBHWLOC - -Affinity* Affinity_get(Process* proc, ProcessList* pl); - -bool Affinity_set(Process* proc, Arg arg); - -#elif HAVE_LINUX_AFFINITY +#if defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY) Affinity* Affinity_get(Process* proc, ProcessList* pl); From b6828d7b8676a8a0e51f8fa2be0dc51977a451e4 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Sat, 12 Sep 2020 23:32:31 -0300 Subject: [PATCH 162/411] Remove some unused #includes As suggested by cppclean. --- Action.h | 7 +++---- MainPanel.h | 4 ++-- ScreenManager.h | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Action.h b/Action.h index 8e5cc9b62..0ec0537f8 100644 --- a/Action.h +++ b/Action.h @@ -7,12 +7,11 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "IncSet.h" -#include "Settings.h" #include "Header.h" -#include "UsersTable.h" -#include "ProcessList.h" #include "Panel.h" +#include "ProcessList.h" +#include "Settings.h" +#include "UsersTable.h" typedef enum { HTOP_OK = 0x00, diff --git a/MainPanel.h b/MainPanel.h index 582dd2ec1..ca064722a 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -8,9 +8,9 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "Panel.h" #include "Action.h" -#include "Settings.h" +#include "IncSet.h" +#include "Panel.h" typedef struct MainPanel_ { Panel super; diff --git a/ScreenManager.h b/ScreenManager.h index 69d983a0b..3c19a05d1 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -7,7 +7,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "FunctionBar.h" #include "Vector.h" #include "Header.h" #include "Settings.h" From fd4ada416d324b5195bb9ee34b48edb491015fa9 Mon Sep 17 00:00:00 2001 From: Stephen Gregoratto Date: Mon, 14 Sep 2020 13:18:40 +1000 Subject: [PATCH 163/411] fix building on openbsd due to remaining WhiteList --- openbsd/OpenBSDProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 0fe43ba74..c5d79f524 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -41,7 +41,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui opl = xCalloc(1, sizeof(OpenBSDProcessList)); pl = (ProcessList*) opl; size = sizeof(pl->cpuCount); - ProcessList_init(pl, Class(OpenBSDProcess), usersTable, pidWhiteList, userId); + ProcessList_init(pl, Class(OpenBSDProcess), usersTable, pidMatchList, userId); e = sysctl(mib, 2, &pl->cpuCount, &size, NULL, 0); if (e == -1 || pl->cpuCount < 1) { From c9ecd0fa74a11278afcab063c905325873462dd2 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 15 Sep 2020 09:33:58 +1000 Subject: [PATCH 164/411] Revert the vim_mode setting for now, needs a rethink There have been too many bugs reported in vim_mode, and the proposed fixes are increasingly fragile - hence we have decided to back it out for now. For reference: https://github.com/htop-dev/htop/issues/69 https://github.com/htop-dev/htop/pull/37 https://github.com/htop-dev/htop/pull/106 The whitespace changes also arrived in commit 12805f61d not sure what that was about, but backed out as well. --- DisplayOptionsPanel.c | 1 - ScreenManager.c | 16 ---------------- Settings.c | 10 ---------- Settings.h | 2 -- 4 files changed, 29 deletions(-) diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index cfbaba90a..6978e2386 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -87,7 +87,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU percentage numerically"), &(settings->showCPUUsage))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU frequency"), &(settings->showCPUFrequency))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Enable the mouse"), &(settings->enableMouse))); - Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Enable vim mode"), &(settings->vimMode))); #ifdef HAVE_LIBHWLOC Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show topology when selecting affinity by default"), &(settings->topologyAffinity))); #endif diff --git a/ScreenManager.c b/ScreenManager.c index 24d292dd0..92e792b46 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -163,22 +163,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { set_escdelay(25); ch = getch(); - if (this->settings->vimMode) { - switch (ch) { - case 'h': ch = KEY_LEFT; break; - case 'j': ch = KEY_DOWN; break; - case 'k': ch = KEY_UP; break; - case 'l': ch = KEY_RIGHT; break; - case KEY_LEFT: ch = 'h'; break; - case KEY_DOWN: ch = 'j'; break; - case KEY_UP: ch = 'k'; break; - case KEY_RIGHT: ch = 'l'; break; - case 'K': ch = 'k'; break; - case 'J': ch = 'K'; break; - case 'L': ch = 'l'; break; - } - } - HandlerResult result = IGNORED; if (ch == KEY_MOUSE && this->settings->enableMouse) { ch = ERR; diff --git a/Settings.c b/Settings.c index c9c75d4a5..d6ef53b98 100644 --- a/Settings.c +++ b/Settings.c @@ -63,7 +63,6 @@ static void Settings_defaultMeters(Settings* this) { this->columns[i].modes = xCalloc(sizes[i], sizeof(int)); this->columns[i].len = sizes[i]; } - int r = 0; if (this->cpuCount > 8) { this->columns[0].names[0] = xStrdup("LeftCPUs2"); @@ -83,7 +82,6 @@ static void Settings_defaultMeters(Settings* this) { this->columns[0].modes[1] = BAR_METERMODE; this->columns[0].names[2] = xStrdup("Swap"); this->columns[0].modes[2] = BAR_METERMODE; - this->columns[1].names[r] = xStrdup("Tasks"); this->columns[1].modes[r++] = TEXT_METERMODE; this->columns[1].names[r] = xStrdup("LoadAverage"); @@ -114,13 +112,11 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { static bool Settings_read(Settings* this, const char* fileName) { FILE* fd; - CRT_dropPrivileges(); fd = fopen(fileName, "r"); CRT_restorePrivileges(); if (!fd) return false; - bool didReadMeters = false; bool didReadFields = false; for (;;) { @@ -199,8 +195,6 @@ static bool Settings_read(Settings* this, const char* fileName) { } else if (String_eq(option[0], "right_meter_modes")) { Settings_readMeterModes(this, option[1], 1); didReadMeters = true; - } else if (String_eq(option[0], "vim_mode")) { - this->vimMode = atoi(option[1]); #ifdef HAVE_LIBHWLOC } else if (String_eq(option[0], "topology_affinity")) { this->topologyAffinity = !!atoi(option[1]); @@ -284,7 +278,6 @@ bool Settings_write(Settings* this) { fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0); fprintf(fd, "right_meters="); writeMeters(this, fd, 1); fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1); - fprintf(fd, "vim_mode=%d\n", (int) this->vimMode); #ifdef HAVE_LIBHWLOC fprintf(fd, "topology_affinity=%d\n", (int) this->topologyAffinity); #endif @@ -293,7 +286,6 @@ bool Settings_write(Settings* this) { } Settings* Settings_new(int cpuCount) { - Settings* this = xCalloc(1, sizeof(Settings)); this->sortKey = PERCENT_CPU; @@ -317,7 +309,6 @@ Settings* Settings_new(int cpuCount) { #ifdef HAVE_LIBHWLOC this->topologyAffinity = false; #endif - this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); // TODO: turn 'fields' into a Vector, // (and ProcessFields into proper objects). @@ -348,7 +339,6 @@ Settings* Settings_new(int cpuCount) { htopDir = String_cat(home, "/.config/htop"); } legacyDotfile = String_cat(home, "/.htoprc"); - CRT_dropPrivileges(); (void) mkdir(configDir, 0700); (void) mkdir(htopDir, 0700); diff --git a/Settings.h b/Settings.h index 0188b614e..e1518ecaf 100644 --- a/Settings.h +++ b/Settings.h @@ -20,7 +20,6 @@ typedef struct { typedef struct Settings_ { char* filename; - MeterColumnSettings columns[2]; ProcessField* fields; @@ -50,7 +49,6 @@ typedef struct Settings_ { bool accountGuestInCPUMeter; bool headerMargin; bool enableMouse; - bool vimMode; #ifdef HAVE_LIBHWLOC bool topologyAffinity; #endif From da62b44b16834dc78af0816b4ac68eea4fda9eb7 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 15 Sep 2020 09:43:36 +1000 Subject: [PATCH 165/411] Bump version, changelog for minor htop-3.0.2 release --- ChangeLog | 20 +++++++++++++++----- configure.ac | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index a45b973e2..4df88d54c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,15 +1,26 @@ +What's new in version 3.0.2 + +* BUGFIX: Drop 'vim_mode' - several issues, needs rethink +* BUGFIX: fix regression in -u optional-argument handling +* Build system rework to remove python, header generation + (thanks to Zev Weiss and Hugo Musso Gualandi) +* BUGFIX: report nice level correctly on Solaris + (thanks to Dominik Hassler) +* CI, code quality improvements + (thanks to Tobias Kortkamp, Christian Hesse, Benny Baumann) + What's new in version 3.0.1 * Coverity fixes, CI improvements, documentation updates * BUGFIX: Fix early exit with longer sysfs battery paths * BUGFIX: Improve OOM output, fix sorting -(thanks to Christian Göttsche) + (thanks to Christian Göttsche) * Rework check buttons and tree open/closed -(thanks to Bert Wesarg) + (thanks to Bert Wesarg) * Add -U/--no-unicode option to disable unicode -(thanks to Christian Hesse) + (thanks to Christian Hesse) * Improvements to the affinity panel -(thanks to Bert Wesarg) + (thanks to Bert Wesarg) What's new in version 3.0.0 @@ -18,7 +29,6 @@ What's new in version 3.0.0 of community maintainers have volunteered to take over a fork at https://htop.dev and https://github.com/htop-dev to keep the project going. - * Support ZFS ARC statistics (thanks to Ross Williams) * Support more than 2 smaller CPU meter columns diff --git a/configure.ac b/configure.ac index 5331d9024..30834f22b 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.65) -AC_INIT([htop],[3.0.1],[htop@groups.io]) +AC_INIT([htop],[3.0.2],[htop@groups.io]) AC_CONFIG_SRCDIR([htop.c]) AC_CONFIG_AUX_DIR([.]) From a852fae8e02650d621abdd5aea29b7a56d9a3090 Mon Sep 17 00:00:00 2001 From: Stephen Gregoratto Date: Tue, 15 Sep 2020 15:19:55 +1000 Subject: [PATCH 166/411] configure.ac: axe python check Now that the automated header script is gone, there's no need for python now. --- configure.ac | 3 --- 1 file changed, 3 deletions(-) diff --git a/configure.ac b/configure.ac index 30834f22b..18617c127 100644 --- a/configure.ac +++ b/configure.ac @@ -291,9 +291,6 @@ AC_ARG_ENABLE([werror], [AS_HELP_STRING([--enable-werror], [Treat warnings as er AS_IF([test "x$enable_werror" = "xyes"], [AM_CFLAGS="$AM_CFLAGS -Werror"]) AC_SUBST([AM_CFLAGS]) -AC_CHECK_PROGS(PYTHON, [python python3 python2]) -AC_SUBST(PYTHON) - # Bail out on errors. # ---------------------------------------------------------------------- if test ! -z "$missing_libraries"; then From 2899ed4cb00f4d887ee92c91e274ef098fd14f2b Mon Sep 17 00:00:00 2001 From: Zev Weiss Date: Thu, 19 Dec 2019 16:30:45 -0600 Subject: [PATCH 167/411] Number CPUs from zero by default. Numbering from one is idiosyncratic and inconsistent with basically everything else in the world; it doesn't make much sense as default behavior. All naming is updated to reflect that numbering from one is a non-default, opt-in option. The old label of the flag saved in htoprc ("cpu_count_from_zero") is still supported for backwards compatibility with existing configs, however. --- DisplayOptionsPanel.c | 2 +- Settings.c | 9 ++++++--- Settings.h | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 6978e2386..9d00b52d5 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -81,7 +81,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Leave a margin around header"), &(settings->headerMargin))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime))); - Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 1 instead of 0"), &(settings->countCPUsFromOne))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU percentage numerically"), &(settings->showCPUUsage))); diff --git a/Settings.c b/Settings.c index d6ef53b98..3330d0625 100644 --- a/Settings.c +++ b/Settings.c @@ -166,8 +166,11 @@ static bool Settings_read(Settings* this, const char* fileName) { this->detailedCPUTime = atoi(option[1]); } else if (String_eq(option[0], "detailed_cpu_time")) { this->detailedCPUTime = atoi(option[1]); + } else if (String_eq(option[0], "cpu_count_from_one")) { + this->countCPUsFromOne = atoi(option[1]); } else if (String_eq(option[0], "cpu_count_from_zero")) { - this->countCPUsFromZero = atoi(option[1]); + // old (inverted) naming also supported for backwards compatibility + this->countCPUsFromOne = !atoi(option[1]); } else if (String_eq(option[0], "show_cpu_usage")) { this->showCPUUsage = atoi(option[1]); } else if (String_eq(option[0], "show_cpu_frequency")) { @@ -266,7 +269,7 @@ bool Settings_write(Settings* this) { fprintf(fd, "tree_view=%d\n", (int) this->treeView); fprintf(fd, "header_margin=%d\n", (int) this->headerMargin); fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime); - fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->countCPUsFromZero); + fprintf(fd, "cpu_count_from_one=%d\n", (int) this->countCPUsFromOne); fprintf(fd, "show_cpu_usage=%d\n", (int) this->showCPUUsage); fprintf(fd, "show_cpu_frequency=%d\n", (int) this->showCPUFrequency); fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames); @@ -299,7 +302,7 @@ Settings* Settings_new(int cpuCount) { this->highlightBaseName = false; this->highlightMegabytes = false; this->detailedCPUTime = false; - this->countCPUsFromZero = false; + this->countCPUsFromOne = false; this->showCPUUsage = true; this->showCPUFrequency = false; this->updateProcessNames = false; diff --git a/Settings.h b/Settings.h index e1518ecaf..e40682a3b 100644 --- a/Settings.h +++ b/Settings.h @@ -31,7 +31,7 @@ typedef struct Settings_ { int direction; ProcessField sortKey; - bool countCPUsFromZero; + bool countCPUsFromOne; bool detailedCPUTime; bool showCPUUsage; bool showCPUFrequency; @@ -56,7 +56,7 @@ typedef struct Settings_ { bool changed; } Settings; -#define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromZero ? (cpu) : (cpu)+1) +#define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromOne ? (cpu)+1 : (cpu)) void Settings_delete(Settings* this); From 3a1c6985789426a2bfc9c7d39eb66c143c6a1c7e Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Wed, 16 Sep 2020 17:54:25 +0200 Subject: [PATCH 168/411] Update README with correct tarball locations, ncurses hints and support / bug reporting pointers. Closes #63 (Release URL tarballs) Closes #61, Closes #82 (Support requests on ncurses) Closes #89 (ncurses docs) Closes #28 (htop-dev vs. -legacy) --- README | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/README b/README index 92bd285ad..32ad7afa7 100644 --- a/README +++ b/README @@ -10,34 +10,58 @@ ## Introduction `htop` is a cross-platform interactive process viewer. -It requires `ncurses`. -For more information and details on how to contribute to `htop` -visit [htop.dev](https://htop.dev). +`htop` allows scrolling the list of processes vertically and horizontally to see their full command lines and related information like memory and CPU consumption. + +The information displayed is configurable through a graphical setup and can be sorted and filtered interactively. + +Tasks related to processes (e.g. killing and renicing) can be done without entering their PIDs. + +Running `htop` requires `ncurses` libraries (typically named libncursesw*). + +For more information and details on how to contribute to `htop` visit [htop.dev](https://htop.dev). ## Build instructions -This program is distributed as a standard autotools-based package. -For detailed instructions see the `INSTALL` file, which -is created after `./autogen.sh` is run. +This program is distributed as a standard GNU autotools-based package. -When compiling from a [release tarball](https://github.com/htop-dev/htop/releases/), run: +Compiling `htop` requires the header files for `ncurses` (libncursesw*-dev). Install these and other required packages for C development from your package manager. + +Then, when compiling from a [release tarball](https://bintray.com/htop/source/htop), run: ~~~ shell ./configure && make ~~~ -For compiling sources downloaded from the Git repository, run: +Alternatively, for compiling sources downloaded from the Git repository (`git clone` or downloads from [Github releases](https://github.com/htop-dev/htop/releases/)), +install the header files for `ncurses` (libncursesw*-dev) and other required development packages from your distribution's package manager. Then run: ~~~ shell ./autogen.sh && ./configure && make ~~~ -By default `make install` will install into `/usr/local`, for changing -the path use `./configure --prefix=/some/path`. +By default `make install` will install into `/usr/local`, for changing the path use `./configure --prefix=/some/path`. + +See the manual page (`man htop`) or the on-line help ('F1' or 'h' inside `htop`) for a list of supported key commands. + +## Support + +If you have trouble running `htop` please consult your Operating System / Linux distribution documentation for getting support and filing bugs. + +## Bugs, development feedback + +We have a [development mailing list](https://htop.dev/mailinglist.html). Feel free to subscribe for release announcements or asking questions on the development of htop. + +You can also join our IRC channel #htop on freenode and talk to the developers there. + +If you have found an issue with the source of htop, please check whether this has already been reported in our [Github issue tracker](https://github.com/htop-dev/htop/issues). +If not, please file a new issue describing the problem you have found, the location in the source code you are referring to and a possible fix. + +## History + +`htop` was invented, developed and maintained by Hisham Muhammad from 2006 to 2019. His [legacy repository](https://github.com/hishamhm/htop/) has been archived to preserve the history. -See the manual page (`man htop`) or the on-line help ('F1' or 'h' -inside `htop`) for a list of supported key commands. +In 2020 a [team](https://github.com/orgs/htop-dev/people) took over the development amicably and continues to maintain `htop` collaboratively. ## License From 6646030116c325157097cf8f66ec83b118d3c54f Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Thu, 17 Sep 2020 09:45:53 +0200 Subject: [PATCH 169/411] Update creation date to 2004 (thanks rubyFeedback) Closes #140 (doc update) --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 32ad7afa7..67f80eff6 100644 --- a/README +++ b/README @@ -59,7 +59,7 @@ If not, please file a new issue describing the problem you have found, the locat ## History -`htop` was invented, developed and maintained by Hisham Muhammad from 2006 to 2019. His [legacy repository](https://github.com/hishamhm/htop/) has been archived to preserve the history. +`htop` was invented, developed and maintained by Hisham Muhammad from 2004 to 2019. His [legacy repository](https://github.com/hishamhm/htop/) has been archived to preserve the history. In 2020 a [team](https://github.com/orgs/htop-dev/people) took over the development amicably and continues to maintain `htop` collaboratively. From 6921000481d3f8e3e0fecf89df436312efaa691a Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Tue, 15 Sep 2020 22:02:57 +0200 Subject: [PATCH 170/411] =?UTF-8?q?Barely=20ever=20seen=20any=201000=20dig?= =?UTF-8?q?it=20PIDs=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenFilesScreen.c | 4 ++-- TraceScreen.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 3e45bf85a..ae32590fa 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -52,8 +52,6 @@ void OpenFilesScreen_draw(InfoScreen* this) { } static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { - char buffer[1025]; - xSnprintf(buffer, 1024, "%d", pid); OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData)); OpenFiles_FileData* fdata = NULL; OpenFiles_Data* item = &(pdata->data); @@ -76,6 +74,8 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { exit(1); dup2(fdnull, STDERR_FILENO); close(fdnull); + char buffer[32] = {0}; + xSnprintf(buffer, sizeof(buffer), "%d", pid); execlp("lsof", "lsof", "-P", "-p", buffer, "-F", NULL); exit(127); } diff --git a/TraceScreen.c b/TraceScreen.c index 0a3485ecc..a04f9a0d0 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -74,7 +74,6 @@ void TraceScreen_draw(InfoScreen* this) { } bool TraceScreen_forkTracer(TraceScreen* this) { - char buffer[1001]; int error = pipe(this->fdpair); if (error == -1) return false; this->child = fork(); @@ -84,6 +83,7 @@ bool TraceScreen_forkTracer(TraceScreen* this) { dup2(this->fdpair[1], STDERR_FILENO); int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK); if (ok != -1) { + char buffer[32] = {0}; xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid); execlp("strace", "strace", "-T", "-tt", "-s", "512", "-p", buffer, NULL); } From 443a9437984c36b13986875c33818767cdadd17d Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Tue, 15 Sep 2020 22:07:52 +0200 Subject: [PATCH 171/411] Properly close pipe handles when work is done --- OpenFilesScreen.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index ae32590fa..323913dd1 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -53,18 +53,21 @@ void OpenFilesScreen_draw(InfoScreen* this) { static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData)); - OpenFiles_FileData* fdata = NULL; - OpenFiles_Data* item = &(pdata->data); - int fdpair[2]; + + int fdpair[2] = {0, 0}; if (pipe(fdpair) == -1) { pdata->error = 1; return pdata; } + pid_t child = fork(); if (child == -1) { + close(fdpair[1]); + close(fdpair[0]); pdata->error = 1; return pdata; } + if (child == 0) { close(fdpair[0]); dup2(fdpair[1], STDOUT_FILENO); @@ -80,12 +83,17 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { exit(127); } close(fdpair[1]); + + OpenFiles_Data* item = &(pdata->data); + OpenFiles_FileData* fdata = NULL; + FILE* fd = fdopen(fdpair[0], "r"); for (;;) { char* line = String_readLine(fd); if (!line) { break; } + unsigned char cmd = line[0]; if (cmd == 'f') { OpenFiles_FileData* nextFile = xCalloc(1, sizeof(OpenFiles_FileData)); @@ -101,15 +109,18 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { free(line); } fclose(fd); + int wstatus; if (waitpid(child, &wstatus, 0) == -1) { pdata->error = 1; return pdata; } + if (!WIFEXITED(wstatus)) pdata->error = 1; else pdata->error = WEXITSTATUS(wstatus); + return pdata; } From 95012d62593912c563312ac6bbb9dc53023e9d46 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Tue, 15 Sep 2020 22:08:43 +0200 Subject: [PATCH 172/411] Avoid hardcoding of buffer size --- TraceScreen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TraceScreen.c b/TraceScreen.c index a04f9a0d0..5c03f355a 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -101,7 +101,7 @@ bool TraceScreen_forkTracer(TraceScreen* this) { void TraceScreen_updateTrace(InfoScreen* super) { TraceScreen* this = (TraceScreen*) super; - char buffer[1001]; + char buffer[1025]; fd_set fds; FD_ZERO(&fds); // FD_SET(STDIN_FILENO, &fds); @@ -111,7 +111,7 @@ void TraceScreen_updateTrace(InfoScreen* super) { int ready = select(this->fd_strace+1, &fds, NULL, NULL, &tv); int nread = 0; if (ready > 0 && FD_ISSET(this->fd_strace, &fds)) - nread = fread(buffer, 1, 1000, this->strace); + nread = fread(buffer, 1, sizeof(buffer) - 1, this->strace); if (nread && this->tracing) { char* line = buffer; buffer[nread] = '\0'; From b096fdbfc093d06ba6d34dcad8a9f0efd47235f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 15 Sep 2020 19:55:21 +0200 Subject: [PATCH 173/411] Avoid potential buffer overflow in LinuxProcessList_readStatFile Pass size of allocated command buffer and limit write. --- linux/LinuxProcessList.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 8dae13c5e..2f17974ad 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -229,6 +229,8 @@ static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, const char* name, char* command, int* commLen) { LinuxProcess* lp = (LinuxProcess*) process; + const int commLenIn = *commLen; + *commLen = 0; char filename[MAX_NAME+1]; xSnprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name); int fd = open(filename, O_RDONLY); @@ -250,7 +252,7 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, char *end = strrchr(location, ')'); if (!end) return false; - int commsize = end - location; + int commsize = MINIMUM(end - location, commLenIn - 1); memcpy(command, location, commsize); command[commsize] = '\0'; *commLen = commsize; @@ -824,7 +826,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* char command[MAX_NAME+1]; unsigned long long int lasttimes = (lp->utime + lp->stime); - int commLen = 0; + int commLen = sizeof(command); unsigned int tty_nr = proc->tty_nr; if (! LinuxProcessList_readStatFile(proc, dirname, name, command, &commLen)) goto errorReadingProcess; From 1efddaf1e5a8da0406f336c85491f2fd720d6860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 15 Sep 2020 19:56:52 +0200 Subject: [PATCH 174/411] Check for fdopen failure in OpenFilesScreen_getProcessData --- OpenFilesScreen.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 323913dd1..915aba225 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -88,6 +88,10 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { OpenFiles_FileData* fdata = NULL; FILE* fd = fdopen(fdpair[0], "r"); + if (!fd) { + pdata->error = 1; + return pdata; + } for (;;) { char* line = String_readLine(fd); if (!line) { From 37921382f49c34738207146d84d1258e2fe0b88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 15 Sep 2020 12:29:46 +0200 Subject: [PATCH 175/411] Use PROCDIR throughout instead of /proc on Linux --- linux/LinuxProcessList.c | 2 +- linux/Platform.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 2f17974ad..cf91900bb 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -477,7 +477,7 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di #ifdef HAVE_OPENVZ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* dirname, const char* name) { - if ( (access("/proc/vz", R_OK) != 0)) { + if ( (access(PROCDIR "/vz", R_OK) != 0)) { process->vpid = process->super.pid; process->ctid = 0; return; diff --git a/linux/Platform.c b/linux/Platform.c index e82d8f88f..0545fc461 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -230,8 +230,8 @@ void Platform_setZfsCompressedArcValues(Meter* this) { ZfsCompressedArcMeter_readStats(this, &(lpl->zfs)); } char* Platform_getProcessEnv(pid_t pid) { - char procname[32+1]; - xSnprintf(procname, 32, "/proc/%d/environ", pid); + char procname[128]; + xSnprintf(procname, sizeof(procname), PROCDIR "/%d/environ", pid); FILE* fd = fopen(procname, "r"); char *env = NULL; if (fd) { From 84d39f95c68ce06b321010054955f6ce7213b2d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 15 Sep 2020 12:10:11 +0200 Subject: [PATCH 176/411] autotools: enable warnings and cleanup - enable warnings in autogen script - drop unused m4/ directory usage - drop AC_TYPE_SIGNAL: C99 guarantees the signal return type to be void - drop AC_CHECK_FILE of procdir: most of the time compilation is done on a different system than htop is run and there is a runtime check in place - improve linux_affinity corss compile logic: use fourth argument instead of pre-test --- Makefile.am | 2 -- autogen.sh | 3 +-- configure.ac | 14 +++----------- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/Makefile.am b/Makefile.am index 50fb586bb..dbf42d14e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,3 @@ - -ACLOCAL_AMFLAGS = -I m4 AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = htop diff --git a/autogen.sh b/autogen.sh index c07e08544..fb38e5e27 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,3 +1,2 @@ #!/bin/sh -mkdir -p m4 -autoreconf --install --force +autoreconf --force --install --verbose -Wall diff --git a/configure.ac b/configure.ac index 18617c127..12676fa31 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,6 @@ AC_INIT([htop],[3.0.2],[htop@groups.io]) AC_CONFIG_SRCDIR([htop.c]) AC_CONFIG_AUX_DIR([.]) AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_MACRO_DIR([m4]) # Required by hwloc scripts AC_CANONICAL_TARGET @@ -81,7 +80,6 @@ AC_TYPE_UID_T # Checks for library functions and compiler features. # ---------------------------------------------------------------------- AC_FUNC_CLOSEDIR_VOID -AC_TYPE_SIGNAL AC_FUNC_STAT AC_CHECK_FUNCS([memmove strncasecmp strstr strdup]) @@ -118,13 +116,6 @@ AC_ARG_WITH(proc, [AS_HELP_STRING([--with-proc=DIR], [Location of a Linux-compat fi, AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem])) -if test "x$cross_compiling" = xno; then - if test "x$enable_proc" = xyes; then - AC_CHECK_FILE($PROCDIR/stat,,AC_MSG_ERROR(Cannot find $PROCDIR/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.)) - AC_CHECK_FILE($PROCDIR/meminfo,,AC_MSG_ERROR(Cannot find $PROCDIR/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.)) - fi -fi - AC_ARG_ENABLE(openvz, [AS_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no") if test "x$enable_openvz" = xyes; then AC_DEFINE(HAVE_OPENVZ, 1, [Define if openvz support enabled.]) @@ -237,7 +228,7 @@ if test "$my_htop_platform" = "solaris"; then fi AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes") -if test "x$enable_linux_affinity" = xyes -a "x$cross_compiling" = xno; then +if test "x$enable_linux_affinity" = xyes; then AC_MSG_CHECKING([for usable sched_setaffinity]) AC_RUN_IFELSE([ AC_LANG_PROGRAM([[ @@ -251,7 +242,8 @@ if test "x$enable_linux_affinity" = xyes -a "x$cross_compiling" = xno; then ]])], [AC_MSG_RESULT([yes])], [enable_linux_affinity=no - AC_MSG_RESULT([no])]) + AC_MSG_RESULT([no])], + [AC_MSG_RESULT([yes (assumed while cross compiling)])]) fi if test "x$enable_linux_affinity" = xyes; then AC_DEFINE(HAVE_LINUX_AFFINITY, 1, [Define if Linux sched_setaffinity and sched_getaffinity are to be used.]) From ffc65b382753a1d61b8f43e4d86f5415b7bfb415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 12 Sep 2020 19:05:56 +0200 Subject: [PATCH 177/411] Reorder check to avoid crash on invalid process field setting If using a setting from a different development version with an unsupported process field, first dereferencing Process_fields[id] yields to a crash: ================================================================= ==19530==ERROR: AddressSanitizer: global-buffer-overflow on address 0x000000612800 at pc 0x000000521d1a bp 0x7ffec47a5ff0 sp 0x7ffec47a5fe8 READ of size 8 at 0x000000612800 thread T0 #0 0x521d19 in readFields .htop/Settings.c:107:40 #1 0x51d117 in Settings_read .htop/Settings.c:141:10 #2 0x51c0c4 in Settings_new .htop/Settings.c:382:12 #3 0x4eafe2 in main .htop/htop.c:220:25 #4 0x7fa450570cc9 in __libc_start_main csu/../csu/libc-start.c:308:16 #5 0x427a59 in _start (.htop/htop+0x427a59) 0x000000612800 is located 0 bytes to the right of global variable 'Process_fields' defined in 'linux/LinuxProcess.c:24:18' (0x6118a0) of size 3936 SUMMARY: AddressSanitizer: global-buffer-overflow .htop/Settings.c:107:40 in readFields Shadow bytes around the buggy address: 0x0000800ba4b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0000800ba4c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0000800ba4d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0000800ba4e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0000800ba4f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0000800ba500:[f9]f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 0x0000800ba510: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 0x0000800ba520: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 0x0000800ba530: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 0x0000800ba540: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 0x0000800ba550: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==19530==ABORTING --- Settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Settings.c b/Settings.c index d6ef53b98..0aac47968 100644 --- a/Settings.c +++ b/Settings.c @@ -100,7 +100,7 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { for (j = 0, i = 0; i < Platform_numberOfFields && ids[i]; i++) { // This "+1" is for compatibility with the older enum format. int id = atoi(ids[i]) + 1; - if (id > 0 && Process_fields[id].name && id < Platform_numberOfFields) { + if (id > 0 && id < Platform_numberOfFields && Process_fields[id].name) { fields[j] = id; *flags |= Process_fields[id].flags; j++; From 98ee833932ad90532246c95daf5859bdcf65dec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 11 Sep 2020 15:02:00 +0200 Subject: [PATCH 178/411] Add Linux process column for context switches Displays the incremental sum of voluntary_ctxt_switches and nonvoluntary_ctxt_switches. --- htop.1.in | 3 +++ linux/LinuxProcess.c | 8 ++++++++ linux/LinuxProcess.h | 6 +++++- linux/LinuxProcessList.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/htop.1.in b/htop.1.in index c5b131bb5..1ae1208f7 100644 --- a/htop.1.in +++ b/htop.1.in @@ -386,6 +386,9 @@ Which cgroup the process is in. .B OOM OOM killer score. .TP +.B CTXT +Incremental sum of voluntary and nonvoluntary context switches. +.TP .B IO_PRIORITY (IO) The I/O scheduling class followed by the priority if the class supports it: \fBR\fR for Realtime diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 377aa5bb8..bef648a9a 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -107,6 +107,7 @@ ProcessFieldData Process_fields[] = { [M_PSS] = { .name = "M_PSS", .title = " PSS ", .description = "proportional set size, same as M_RESIDENT but each page is divided by the number of processes sharing it.", .flags = PROCESS_FLAG_LINUX_SMAPS, }, [M_SWAP] = { .name = "M_SWAP", .title = " SWAP ", .description = "Size of the process's swapped pages", .flags = PROCESS_FLAG_LINUX_SMAPS, }, [M_PSSWP] = { .name = "M_PSSWP", .title = " PSSWP ", .description = "shows proportional swap share of this mapping, Unlike \"Swap\", this does not take into account swapped out page of underlying shmem objects.", .flags = PROCESS_FLAG_LINUX_SMAPS, }, + [CTXT] = { .name = "CTXT", .title = " CTXT ", .description = "Context switches (incremental sum of voluntary_ctxt_switches and nonvoluntary_ctxt_switches)", .flags = PROCESS_FLAG_LINUX_CTXT, }, [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, }; @@ -276,6 +277,11 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) case PERCENT_IO_DELAY: LinuxProcess_printDelay(lp->blkio_delay_percent, buffer, n); break; case PERCENT_SWAP_DELAY: LinuxProcess_printDelay(lp->swapin_delay_percent, buffer, n); break; #endif + case CTXT: + if (lp->ctxt_diff > 1000) + attr |= A_BOLD; + xSnprintf(buffer, n, "%5lu ", lp->ctxt_diff); + break; default: Process_writeField((Process*)this, str, field); return; @@ -359,6 +365,8 @@ long LinuxProcess_compare(const void* v1, const void* v2) { #endif case IO_PRIORITY: return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2); + case CTXT: + return ((long)p2->ctxt_diff - (long)p1->ctxt_diff); default: return Process_compare(v1, v2); } diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 021cae7c7..9972ee84a 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -14,6 +14,7 @@ in the source distribution for its full text. #define PROCESS_FLAG_LINUX_CGROUP 0x0800 #define PROCESS_FLAG_LINUX_OOM 0x1000 #define PROCESS_FLAG_LINUX_SMAPS 0x2000 +#define PROCESS_FLAG_LINUX_CTXT 0x4000 typedef enum UnsupportedProcessFields { FLAGS = 9, @@ -80,7 +81,8 @@ typedef enum LinuxProcessFields { M_PSS = 119, M_SWAP = 120, M_PSSWP = 121, - LAST_PROCESSFIELD = 122, + CTXT = 122, + LAST_PROCESSFIELD = 123, } LinuxProcessField; #include "IOPriority.h" @@ -138,6 +140,8 @@ typedef struct LinuxProcess_ { float blkio_delay_percent; float swapin_delay_percent; #endif + unsigned long ctxt_total; + unsigned long ctxt_diff; } LinuxProcess; #define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index cf91900bb..89746e176 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -588,6 +588,32 @@ static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirn fclose(file); } +static void LinuxProcessList_readCtxtData(LinuxProcess* process, const char* dirname, const char* name) { + char filename[MAX_NAME+1]; + xSnprintf(filename, MAX_NAME, "%s/%s/status", dirname, name); + FILE* file = fopen(filename, "r"); + if (!file) + return; + char buffer[PROC_LINE_LENGTH + 1]; + unsigned long ctxt = 0; + while (fgets(buffer, PROC_LINE_LENGTH, file)) { + if (String_startsWith(buffer, "voluntary_ctxt_switches:")) { + unsigned long vctxt; + int ok = sscanf(buffer, "voluntary_ctxt_switches:\t%lu", &vctxt); + if (ok >= 1) + ctxt += vctxt; + } else if (String_startsWith(buffer, "nonvoluntary_ctxt_switches:")) { + unsigned long nvctxt; + int ok = sscanf(buffer, "nonvoluntary_ctxt_switches:\t%lu", &nvctxt); + if (ok >= 1) + ctxt += nvctxt; + } + } + fclose(file); + process->ctxt_diff = (ctxt > process->ctxt_total) ? (ctxt - process->ctxt_total) : 0; + process->ctxt_total = ctxt; +} + #ifdef HAVE_DELAYACCT static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { @@ -885,6 +911,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* if (settings->flags & PROCESS_FLAG_LINUX_OOM) LinuxProcessList_readOomData(lp, dirname, name); + if (settings->flags & PROCESS_FLAG_LINUX_CTXT) + LinuxProcessList_readCtxtData(lp, dirname, name); + if (proc->state == 'Z' && (proc->basenameOffset == 0)) { proc->basenameOffset = -1; setCommand(proc, command, commLen); From 00665e2a2b9c6efca6cd1f1dbaca0a91ccb31534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 10 Sep 2020 00:09:01 +0200 Subject: [PATCH 179/411] Avoid unsigned integer overflow unsigned overflow is well defined, but creates noise when using sanitizers. unsigned overflow can be a symptom of logic issues of counter, so its reasonable to use. linux/LinuxProcessList.c:64:50: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'unsigned int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/LinuxProcessList.c:64:50 in linux/LinuxProcessList.c:64:11: runtime error: implicit conversion from type 'unsigned int' of value 4294967295 (32-bit, unsigned) to type 'int' changed the value to -1 (32-bit, signed) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/LinuxProcessList.c:64:11 in linux/LinuxProcessList.c:64:78: runtime error: unsigned integer overflow: 4 - 136 cannot be represented in type 'unsigned int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/LinuxProcessList.c:64:78 in --- linux/LinuxProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 89746e176..a02509fcb 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -61,7 +61,7 @@ static ssize_t xread(int fd, void *buf, size_t count) { static int sortTtyDrivers(const void* va, const void* vb) { TtyDriver* a = (TtyDriver*) va; TtyDriver* b = (TtyDriver*) vb; - return (a->major == b->major) ? (a->minorFrom - b->minorFrom) : (a->major - b->major); + return (a->major == b->major) ? ((int)a->minorFrom - (int)b->minorFrom) : ((int)a->major - (int)b->major); } static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { From 5d4061732f25863d78cca06968cd938ae468b8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 10 Sep 2020 00:17:59 +0200 Subject: [PATCH 180/411] Allow third party sigsegv handler For example from sanitizers. --- CRT.c | 8 +++++++- CRT.h | 1 + linux/LinuxCRT.c | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CRT.c b/CRT.c index 7776c4e74..3aea895eb 100644 --- a/CRT.c +++ b/CRT.c @@ -552,6 +552,8 @@ void CRT_restorePrivileges() { // TODO: pass an instance of Settings instead. +struct sigaction old_sigsegv_handler; + void CRT_init(int delay, int colorScheme, bool allowUnicode) { initscr(); noecho(); @@ -605,7 +607,11 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { } } #ifndef DEBUG - signal(11, CRT_handleSIGSEGV); + struct sigaction act; + sigemptyset (&act.sa_mask); + act.sa_flags = (int)SA_RESETHAND; + act.sa_handler = CRT_handleSIGSEGV; + sigaction (SIGSEGV, &act, &old_sigsegv_handler); #endif signal(SIGTERM, CRT_handleSIGTERM); signal(SIGQUIT, CRT_handleSIGTERM); diff --git a/CRT.h b/CRT.h index 8a5d6ac6e..32992e41b 100644 --- a/CRT.h +++ b/CRT.h @@ -108,6 +108,7 @@ typedef enum ColorElements_ { void CRT_fatalError(const char* note) __attribute__ ((noreturn)); +extern struct sigaction old_sigsegv_handler; void CRT_handleSIGSEGV(int sgn); #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) diff --git a/linux/LinuxCRT.c b/linux/LinuxCRT.c index c65b78221..dbfad27fb 100644 --- a/linux/LinuxCRT.c +++ b/linux/LinuxCRT.c @@ -7,6 +7,8 @@ in the source distribution for its full text. #include "config.h" #include "CRT.h" + +#include #include #include #ifdef HAVE_EXECINFO_H @@ -32,5 +34,7 @@ void CRT_handleSIGSEGV(int sgn) { fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); #endif - abort(); + + /* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */ + sigaction (SIGSEGV, &old_sigsegv_handler, NULL); } From 1f5bd5c4c84c53915bcdd68398e77269fe26328c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 12 Sep 2020 18:11:58 +0200 Subject: [PATCH 181/411] Avoid modifying optarg It might be working, but lets rather not modify getopt's global variable `optarg`. Also there is no need to call `getenv("USER")`, just use `geteuid()`. --- htop.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htop.c b/htop.c index 2cf2602e4..79526b882 100644 --- a/htop.c +++ b/htop.c @@ -131,21 +131,21 @@ static CommandLineSettings parseArguments(int argc, char** argv) { } break; case 'u': - if (!optarg && optind < argc && argv[optind] != NULL && + { + const char *username = optarg; + if (!username && optind < argc && argv[optind] != NULL && (argv[optind][0] != '\0' && argv[optind][0] != '-')) { - optarg = argv[optind++]; + username = argv[optind++]; } - if (!optarg) { - optarg = getenv("USER"); + if (!username) { flags.userId = geteuid(); - } - - if (!Action_setUserOnly(optarg, &(flags.userId))) { - fprintf(stderr, "Error: invalid user \"%s\".\n", optarg); + } else if (!Action_setUserOnly(username, &(flags.userId))) { + fprintf(stderr, "Error: invalid user \"%s\".\n", username); exit(1); } break; + } case 'C': flags.useColors = false; break; From 8a849bc85a1d59ffc77e6bff1aa3da2d4bcd746c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 11 Sep 2020 19:27:56 +0200 Subject: [PATCH 182/411] Call character checking function with unsigned char See https://wiki.sei.cmu.edu/confluence/display/c/STR37-C.+Arguments+to+character-handling+functions+must+be+representable+as+an+unsigned+char --- AvailableColumnsPanel.c | 2 +- CategoriesPanel.c | 2 +- ColumnsPanel.c | 2 +- IncSet.c | 2 +- MainPanel.c | 2 +- Panel.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index 8aedde241..0d9749e78 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -45,7 +45,7 @@ static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) { } default: { - if (ch < 255 && isalpha(ch)) + if (0 < ch && ch < 255 && isalpha((unsigned char)ch)) result = Panel_selectByTyping(super, ch); break; } diff --git a/CategoriesPanel.c b/CategoriesPanel.c index 8a1e16df4..c12b3905e 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -81,7 +81,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) { break; } default: - if (ch < 255 && isalpha(ch)) + if (0 < ch && ch < 255 && isalpha((unsigned char)ch)) result = Panel_selectByTyping(super, ch); if (result == BREAK_LOOP) result = IGNORED; diff --git a/ColumnsPanel.c b/ColumnsPanel.c index 587175c81..318c7af8c 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -91,7 +91,7 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { } default: { - if (ch < 255 && isalpha(ch)) + if (0 < ch && ch < 255 && isalpha((unsigned char)ch)) result = Panel_selectByTyping(super, ch); if (result == BREAK_LOOP) result = IGNORED; diff --git a/IncSet.c b/IncSet.c index e9e289346..b9a1d92d7 100644 --- a/IncSet.c +++ b/IncSet.c @@ -137,7 +137,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue if (size == 0) return true; IncMode_find(mode, panel, getPanelValue, 1); doSearch = false; - } else if (ch < 255 && isprint((char)ch)) { + } else if (0 < ch && ch < 255 && isprint((unsigned char)ch)) { if (mode->index < INCMODE_MAX) { mode->buffer[mode->index] = ch; mode->index++; diff --git a/MainPanel.c b/MainPanel.c index eb7e663db..4390dad63 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -79,7 +79,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { } else if (ch != ERR && ch > 0 && ch < KEY_MAX && this->keys[ch]) { reaction |= (this->keys[ch])(this->state); result = HANDLED; - } else if (isdigit(ch)) { + } else if (0 < ch && ch < 255 && isdigit((unsigned char)ch)) { MainPanel_pidSearch(this, ch); } else { if (ch != ERR) { diff --git a/Panel.c b/Panel.c index b77483d94..315f3887a 100644 --- a/Panel.c +++ b/Panel.c @@ -411,7 +411,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) { this->eventHandlerState = xCalloc(100, sizeof(char)); char* buffer = this->eventHandlerState; - if (ch > 0 && ch < 255 && isalnum(ch)) { + if (0 < ch && ch < 255 && isalnum((unsigned char)ch)) { int len = strlen(buffer); if (len < 99) { buffer[len] = ch; From 71c068ad286f1493fc1c3cc106e14d5ed104eb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 11 Sep 2020 20:14:56 +0200 Subject: [PATCH 183/411] Free movingBar memory on exit --- MetersPanel.c | 7 +++++++ MetersPanel.h | 2 ++ htop.c | 2 ++ 3 files changed, 11 insertions(+) diff --git a/MetersPanel.c b/MetersPanel.c index 417834a30..1e0afcdc0 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -27,6 +27,13 @@ static const char* const MetersMovingKeys[] = {"Space", "Enter", "Up", "Dn", "<- static int MetersMovingEvents[] = {' ', 13, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, ERR, KEY_DC, KEY_F(10)}; static FunctionBar* Meters_movingBar = NULL; +void MetersPanel_cleanup() { + if (Meters_movingBar) { + FunctionBar_delete(Meters_movingBar); + Meters_movingBar = NULL; + } +} + static void MetersPanel_delete(Object* object) { Panel* super = (Panel*) object; MetersPanel* this = (MetersPanel*) object; diff --git a/MetersPanel.h b/MetersPanel.h index c02ce1cd9..dbc31ee4b 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -24,6 +24,8 @@ struct MetersPanel_ { bool moving; }; +void MetersPanel_cleanup(void); + void MetersPanel_setMoving(MetersPanel* this, bool moving); extern PanelClass MetersPanel_class; diff --git a/htop.c b/htop.c index 79526b882..8399d73e4 100644 --- a/htop.c +++ b/htop.c @@ -12,6 +12,7 @@ in the source distribution for its full text. #include "ColumnsPanel.h" #include "CRT.h" #include "MainPanel.h" +#include "MetersPanel.h" #include "ProcessList.h" #include "ScreenManager.h" #include "Settings.h" @@ -277,6 +278,7 @@ int main(int argc, char** argv) { ProcessList_delete(pl); ScreenManager_delete(scr); + MetersPanel_cleanup(); UsersTable_delete(ut); Settings_delete(settings); From c7568bc0540d7d33233fc55fa9d5b11cffd56e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 11 Sep 2020 20:36:02 +0200 Subject: [PATCH 184/411] Fix memory leak in actionSetAffinity() Call correct delete method for AffinityPanel --- Action.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Action.c b/Action.c index 90d6bfe1f..5de0804d8 100644 --- a/Action.c +++ b/Action.c @@ -298,7 +298,7 @@ static Htop_Reaction actionSetAffinity(State* st) { if (!ok) beep(); Affinity_delete(affinity2); } - Panel_delete((Object*)affinityPanel); + Object_delete(affinityPanel); #endif return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; } From 3142077c7603fbac6adc12f881eb8c23280c9e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 11 Sep 2020 20:15:33 +0200 Subject: [PATCH 185/411] Add script to run htop under valgrind Includes suppressions for ncurses leaks. --- scripts/htop_suppressions.valgrind | 63 ++++++++++++++++++++++++++++++ scripts/run_valgrind.sh | 6 +++ 2 files changed, 69 insertions(+) create mode 100644 scripts/htop_suppressions.valgrind create mode 100755 scripts/run_valgrind.sh diff --git a/scripts/htop_suppressions.valgrind b/scripts/htop_suppressions.valgrind new file mode 100644 index 000000000..a7afb0fd4 --- /dev/null +++ b/scripts/htop_suppressions.valgrind @@ -0,0 +1,63 @@ +{ + + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:CRT_init + fun:main +} + +{ + + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:CRT_init +} + +{ + + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:wgetch + fun:ScreenManager_run + fun:Action_runSetup + fun:actionSetup + fun:MainPanel_eventHandler + fun:ScreenManager_run + fun:main +} + +{ + + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:wgetch + fun:ScreenManager_run + fun:main +} + +{ + + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:wrefresh + fun:main +} + +{ + + Memcheck:Leak + match-leak-kinds: reachable + fun:realloc + fun:_nc_doalloc + fun:_nc_tparm_analyze + fun:tparm + ... + fun:doupdate_sp + fun:wrefresh + obj:* +} diff --git a/scripts/run_valgrind.sh b/scripts/run_valgrind.sh new file mode 100755 index 000000000..f635b93b8 --- /dev/null +++ b/scripts/run_valgrind.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +SCRIPT=$(readlink -f "$0") +SCRIPTDIR=$(dirname "$SCRIPT") + +valgrind --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all --suppressions="${SCRIPTDIR}/htop_suppressions.valgrind" "${SCRIPTDIR}/../htop" From 40441dca8e22f30297b45f78a58013e9face3935 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 13 Sep 2020 23:50:24 +0200 Subject: [PATCH 186/411] Enhance highlighting of semi-large and large numbers --- CRT.c | 6 +++++ CRT.h | 1 + Process.c | 74 ++++++++++++++++++++++++++++++++++--------------------- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/CRT.c b/CRT.c index 3aea895eb..16f0e957e 100644 --- a/CRT.c +++ b/CRT.c @@ -98,6 +98,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black), [PROCESS_MEGABYTES] = ColorPair(Cyan,Black), + [PROCESS_GIGABYTES] = ColorPair(Green,Black), [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Black), [PROCESS_TREE] = ColorPair(Cyan,Black), [PROCESS_R_STATE] = ColorPair(Green,Black), @@ -167,6 +168,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_SHADOW] = A_DIM, [PROCESS_TAG] = A_BOLD, [PROCESS_MEGABYTES] = A_BOLD, + [PROCESS_GIGABYTES] = A_BOLD, [PROCESS_BASENAME] = A_BOLD, [PROCESS_TREE] = A_BOLD, [PROCESS_R_STATE] = A_BOLD, @@ -236,6 +238,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,White), [PROCESS_TAG] = ColorPair(White,Blue), [PROCESS_MEGABYTES] = ColorPair(Blue,White), + [PROCESS_GIGABYTES] = ColorPair(Green,White), [PROCESS_BASENAME] = ColorPair(Blue,White), [PROCESS_TREE] = ColorPair(Green,White), [PROCESS_R_STATE] = ColorPair(Green,White), @@ -305,6 +308,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, [PROCESS_TAG] = ColorPair(White,Blue), [PROCESS_MEGABYTES] = ColorPair(Blue,Black), + [PROCESS_GIGABYTES] = ColorPair(Green,Black), [PROCESS_BASENAME] = ColorPair(Green,Black), [PROCESS_TREE] = ColorPair(Blue,Black), [PROCESS_R_STATE] = ColorPair(Green,Black), @@ -374,6 +378,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Blue), [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Blue), [PROCESS_MEGABYTES] = ColorPair(Cyan,Blue), + [PROCESS_GIGABYTES] = ColorPair(Green,Blue), [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Blue), [PROCESS_TREE] = ColorPair(Cyan,Blue), [PROCESS_R_STATE] = ColorPair(Green,Blue), @@ -443,6 +448,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black), [PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black), + [PROCESS_GIGABYTES] = A_BOLD | ColorPair(Yellow,Black), [PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black), [PROCESS_TREE] = ColorPair(Cyan,Black), [PROCESS_THREAD] = ColorPair(Green,Black), diff --git a/CRT.h b/CRT.h index 32992e41b..4199837ee 100644 --- a/CRT.h +++ b/CRT.h @@ -58,6 +58,7 @@ typedef enum ColorElements_ { PROCESS_SHADOW, PROCESS_TAG, PROCESS_MEGABYTES, + PROCESS_GIGABYTES, PROCESS_TREE, PROCESS_R_STATE, PROCESS_D_STATE, diff --git a/Process.c b/Process.c index 7a04c0f93..343a736d3 100644 --- a/Process.c +++ b/Process.c @@ -61,46 +61,64 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { int largeNumberColor = CRT_colors[LARGE_NUMBER]; int processMegabytesColor = CRT_colors[PROCESS_MEGABYTES]; + int processGigabytesColor = CRT_colors[PROCESS_GIGABYTES]; int processColor = CRT_colors[PROCESS]; if (!coloring) { largeNumberColor = CRT_colors[PROCESS]; processMegabytesColor = CRT_colors[PROCESS]; + processGigabytesColor = CRT_colors[PROCESS]; } - if(number >= (10 * ONE_DECIMAL_M)) { - #ifdef __LP64__ - if(number >= (100 * ONE_DECIMAL_G)) { - len = snprintf(buffer, 10, "%4luT ", number / ONE_G); - RichString_appendn(str, largeNumberColor, buffer, len); - return; - } else if (number >= (1000 * ONE_DECIMAL_M)) { - len = snprintf(buffer, 10, "%4.1lfT ", (double)number / ONE_G); - RichString_appendn(str, largeNumberColor, buffer, len); - return; - } - #endif - if(number >= (100 * ONE_DECIMAL_M)) { - len = snprintf(buffer, 10, "%4luG ", number / ONE_M); - RichString_appendn(str, largeNumberColor, buffer, len); - return; - } - len = snprintf(buffer, 10, "%4.1lfG ", (double)number / ONE_M); - RichString_appendn(str, largeNumberColor, buffer, len); - return; - } else if (number >= 100000) { - len = snprintf(buffer, 10, "%4luM ", number / ONE_K); - RichString_appendn(str, processMegabytesColor, buffer, len); - return; - } else if (number >= 1000) { + if (number < 1000) { + //Plain number, no markings + len = snprintf(buffer, 10, "%5lu ", number); + RichString_appendn(str, processColor, buffer, len); + } else if (number < 100000) { + //2 digit MB, 3 digit KB len = snprintf(buffer, 10, "%2lu", number/1000); RichString_appendn(str, processMegabytesColor, buffer, len); number %= 1000; len = snprintf(buffer, 10, "%03lu ", number); RichString_appendn(str, processColor, buffer, len); - return; + } else if (number < 1000 * ONE_K) { + //3 digit MB + number /= ONE_K; + len = snprintf(buffer, 10, "%4luM ", number); + RichString_appendn(str, processMegabytesColor, buffer, len); + } else if (number < 10000 * ONE_K) { + //1 digit GB, 3 digit MB + number /= ONE_K; + len = snprintf(buffer, 10, "%1lu", number/1000); + RichString_appendn(str, processGigabytesColor, buffer, len); + number %= 1000; + len = snprintf(buffer, 10, "%03luM ", number); + RichString_appendn(str, processMegabytesColor, buffer, len); + } else if (number < 100 * ONE_M) { + //2 digit GB, 1 digit MB + number /= 100 * ONE_K; + len = snprintf(buffer, 10, "%2lu", number/10); + RichString_appendn(str, processGigabytesColor, buffer, len); + number %= 10; + len = snprintf(buffer, 10, ".%1luG ", number); + RichString_appendn(str, processMegabytesColor, buffer, len); + } else if (number < 1000 * ONE_M) { + //3 digit GB + number /= ONE_M; + len = snprintf(buffer, 10, "%4luG ", number); + RichString_appendn(str, processGigabytesColor, buffer, len); + } else if (number < 10000 * ONE_M) { + //1 digit TB, 3 digit GB + number /= ONE_M; + len = snprintf(buffer, 10, "%1lu", number/1000); + RichString_appendn(str, largeNumberColor, buffer, len); + number %= 1000; + len = snprintf(buffer, 10, "%03luG ", number); + RichString_appendn(str, processGigabytesColor, buffer, len); + } else { + //2 digit TB and above + len = snprintf(buffer, 10, "%4.1lfT ", (double)number/ONE_G); + RichString_appendn(str, largeNumberColor, buffer, len); } - len = snprintf(buffer, 10, "%5lu ", number); - RichString_appendn(str, processColor, buffer, len); } void Process_colorNumber(RichString* str, unsigned long long number, bool coloring) { From 1061bd719aa2e6762958c59bdf88aa3ee961999c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Wed, 16 Sep 2020 03:01:36 +0200 Subject: [PATCH 187/411] Change option '-m' to '-M' for consistency of cli `-m` was added as short option for `--no-mouse`, this is inconsistence to the rest of the cli since otherwise the short options to disable a feature are capital letters. Therefore this commit renames the option to `-M`. This commit also documents the option in the man page. --- htop.1.in | 3 +++ htop.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/htop.1.in b/htop.1.in index 1ae1208f7..bffe386b1 100644 --- a/htop.1.in +++ b/htop.1.in @@ -51,6 +51,9 @@ Show only the processes of a given user \fB\-U \-\-no-unicode\fR Do not use unicode but ASCII characters for graph meters .TP +\fB\-M \-\-no-mouse\fR +Disable support of mouse control +.TP \fB\-v \-\-version Output version information and exit .TP diff --git a/htop.c b/htop.c index 8399d73e4..070f581fe 100644 --- a/htop.c +++ b/htop.c @@ -38,7 +38,7 @@ static void printHelpFlag() { fputs("htop " VERSION "\n" "Released under the GNU GPL.\n\n" "-C --no-color Use a monochrome color scheme\n" - "-m --no-mouse Disable the mouse\n" + "-M --no-mouse Disable the mouse\n" "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" "-h --help Print this help screen\n" "-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n" @@ -90,7 +90,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { {"user", optional_argument, 0, 'u'}, {"no-color", no_argument, 0, 'C'}, {"no-colour", no_argument, 0, 'C'}, - {"no-mouse", no_argument, 0, 'm'}, + {"no-mouse", no_argument, 0, 'M'}, {"no-unicode", no_argument, 0, 'U'}, {"tree", no_argument, 0, 't'}, {"pid", required_argument, 0, 'p'}, @@ -99,7 +99,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { int opt, opti=0; /* Parse arguments */ - while ((opt = getopt_long(argc, argv, "hvmCs:td:u::Up:", long_opts, &opti))) { + while ((opt = getopt_long(argc, argv, "hvMCs:td:u::Up:", long_opts, &opti))) { if (opt == EOF) break; switch (opt) { case 'h': @@ -150,7 +150,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { case 'C': flags.useColors = false; break; - case 'm': + case 'M': flags.enableMouse = false; break; case 'U': From f3b4e248a360624ba429ec6c69e3ccfc9097ef2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 11 Sep 2020 16:34:27 +0200 Subject: [PATCH 188/411] Drop unused variable --- Panel.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Panel.h b/Panel.h index 480e2c0fe..1c7c171df 100644 --- a/Panel.h +++ b/Panel.h @@ -42,7 +42,6 @@ typedef struct PanelClass_ { struct Panel_ { Object super; int x, y, w, h; - WINDOW* window; Vector* items; int selected; int oldSelected; From f6b0efded5a65a15a6d5154dbe77e9727925f51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 17 Sep 2020 22:37:03 +0200 Subject: [PATCH 189/411] Convert short version option to capital V v is generally used for enabling verbose mode --- htop.1.in | 2 +- htop.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htop.1.in b/htop.1.in index bffe386b1..cbd5453c1 100644 --- a/htop.1.in +++ b/htop.1.in @@ -54,7 +54,7 @@ Do not use unicode but ASCII characters for graph meters \fB\-M \-\-no-mouse\fR Disable support of mouse control .TP -\fB\-v \-\-version +\fB\-V \-\-version Output version information and exit .TP \fB\-t \-\-tree diff --git a/htop.c b/htop.c index 070f581fe..916a10ddc 100644 --- a/htop.c +++ b/htop.c @@ -46,7 +46,7 @@ static void printHelpFlag() { "-u --user[=USERNAME] Show only processes for a given user (or $USER)\n" "-U --no-unicode Do not use unicode but plain ASCII\n" "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n" - "-v --version Print version info\n" + "-V --version Print version info\n" "\n" "Long options may be passed with a single dash.\n\n" "Press F1 inside htop for online help.\n" @@ -84,7 +84,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { static struct option long_opts[] = { {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, {"delay", required_argument, 0, 'd'}, {"sort-key", required_argument, 0, 's'}, {"user", optional_argument, 0, 'u'}, @@ -99,13 +99,13 @@ static CommandLineSettings parseArguments(int argc, char** argv) { int opt, opti=0; /* Parse arguments */ - while ((opt = getopt_long(argc, argv, "hvMCs:td:u::Up:", long_opts, &opti))) { + while ((opt = getopt_long(argc, argv, "hVMCs:td:u::Up:", long_opts, &opti))) { if (opt == EOF) break; switch (opt) { case 'h': printHelpFlag(); break; - case 'v': + case 'V': printVersionFlag(); break; case 's': From dd6500c7c7920f142474373a90bd7d07e037c141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 17 Sep 2020 22:39:06 +0200 Subject: [PATCH 190/411] Sort option in help message --- htop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htop.c b/htop.c index 916a10ddc..961ddc41b 100644 --- a/htop.c +++ b/htop.c @@ -38,14 +38,14 @@ static void printHelpFlag() { fputs("htop " VERSION "\n" "Released under the GNU GPL.\n\n" "-C --no-color Use a monochrome color scheme\n" - "-M --no-mouse Disable the mouse\n" "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" "-h --help Print this help screen\n" + "-M --no-mouse Disable the mouse\n" + "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n" "-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n" "-t --tree Show the tree view by default\n" "-u --user[=USERNAME] Show only processes for a given user (or $USER)\n" "-U --no-unicode Do not use unicode but plain ASCII\n" - "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n" "-V --version Print version info\n" "\n" "Long options may be passed with a single dash.\n\n" From f4602f7b4e7fdcf4b3a5d2c0c353b50fef98aa7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 8 Sep 2020 14:25:46 +0200 Subject: [PATCH 191/411] Add some default compiler warnings Compatible with gcc and clang. --- Makefile.am | 2 +- configure.ac | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Makefile.am b/Makefile.am index dbf42d14e..c97ae938c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ applications_DATA = htop.desktop pixmapdir = $(datadir)/pixmaps pixmap_DATA = htop.png -AM_CFLAGS += -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)" +AM_CFLAGS += -pedantic -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)" AM_LDFLAGS = AM_CPPFLAGS = -DNDEBUG diff --git a/configure.ac b/configure.ac index 12676fa31..f22490f5c 100644 --- a/configure.ac +++ b/configure.ac @@ -85,26 +85,13 @@ AC_CHECK_FUNCS([memmove strncasecmp strstr strdup]) save_cflags="${CFLAGS}" CFLAGS="${CFLAGS} -std=c99" -AC_MSG_CHECKING([whether gcc -std=c99 option works]) +AC_MSG_CHECKING([whether cc -std=c99 option works]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM( [AC_INCLUDES_DEFAULT], [[char *a; a = strdup("foo"); int i = 0; i++; // C99]])], [AC_MSG_RESULT([yes])], - [AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.])]) + [AC_MSG_ERROR([htop is written in C99. A newer compiler is required.])]) CFLAGS="$save_cflags" -save_cflags="${CFLAGS}" -CFLAGS="$CFLAGS -Wextra" -AC_MSG_CHECKING([if compiler supports -Wextra]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],[ - wextra_flag=-Wextra - AC_MSG_RESULT([yes]) -],[ - wextra_flag= - AC_MSG_RESULT([no]) -]) -CFLAGS="$save_cflags" -AC_SUBST(wextra_flag) - # Checks for features and flags. # ---------------------------------------------------------------------- PROCDIR=/proc @@ -279,6 +266,19 @@ then ]) fi +AM_CFLAGS="\ + -Wall\ + -Wcast-align\ + -Wextra\ + -Wmissing-format-attribute\ + -Wmissing-noreturn\ + -Wpointer-arith\ + -Wshadow\ + -Wstrict-prototypes\ + -Wundef\ + -Wunused\ + -Wwrite-strings" + AC_ARG_ENABLE([werror], [AS_HELP_STRING([--enable-werror], [Treat warnings as errors (default: warnings are not errors)])], [enable_werror="$enableval"], [enable_werror=no]) AS_IF([test "x$enable_werror" = "xyes"], [AM_CFLAGS="$AM_CFLAGS -Werror"]) AC_SUBST([AM_CFLAGS]) From 7107d1db0b3361a3e880d903a45920b64a05e9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 9 Sep 2020 21:35:15 +0200 Subject: [PATCH 192/411] Refactor __attribute__ usage Use internal macros for compatibility with non GNUC compilers. --- CRT.h | 4 +++- Macros.h | 16 ++++++++++++++++ XAlloc.c | 8 -------- XAlloc.h | 10 +--------- dragonflybsd/DragonFlyBSDProcessList.c | 4 +--- dragonflybsd/DragonFlyBSDProcessList.h | 2 -- zfs/ZfsArcStats.c | 4 +++- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/CRT.h b/CRT.h index 4199837ee..d7d01e2cf 100644 --- a/CRT.h +++ b/CRT.h @@ -7,6 +7,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "Macros.h" + #include #define KEY_WHEELUP KEY_F(20) @@ -107,7 +109,7 @@ typedef enum ColorElements_ { LAST_COLORELEMENT } ColorElements; -void CRT_fatalError(const char* note) __attribute__ ((noreturn)); +void CRT_fatalError(const char* note) ATTR_NORETURN; extern struct sigaction old_sigsegv_handler; void CRT_handleSIGSEGV(int sgn); diff --git a/Macros.h b/Macros.h index cb84b2916..ef4e8908b 100644 --- a/Macros.h +++ b/Macros.h @@ -13,4 +13,20 @@ #define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low)) #endif +#ifdef __GNUC__ // defined by GCC and Clang + +#define ATTR_FORMAT(type, index, check) __attribute__((format (type, index, check))) +#define ATTR_NONNULL __attribute__((nonnull)) +#define ATTR_NORETURN __attribute__((noreturn)) +#define ATTR_UNUSED __attribute__((unused)) + +#else /* __GNUC__ */ + +#define ATTR_FORMAT(type, index, check) +#define ATTR_NONNULL +#define ATTR_NORETURN +#define ATTR_UNUSED + +#endif /* __GNUC__ */ + #endif diff --git a/XAlloc.c b/XAlloc.c index 38616dfc3..c0fa75471 100644 --- a/XAlloc.c +++ b/XAlloc.c @@ -53,14 +53,6 @@ void* xRealloc(void* ptr, size_t size) { # define xStrdup(str_) (assert(str_), xStrdup_(str_)) #endif -#ifndef __has_attribute // Clang's macro -# define __has_attribute(x) 0 -#endif -#if (__has_attribute(nonnull) || \ - ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) -char* xStrdup_(const char* str) __attribute__((nonnull)); -#endif // __has_attribute(nonnull) || GNU C 3.3 or later - char* xStrdup_(const char* str) { char* data = strdup(str); if (!data) { diff --git a/XAlloc.h b/XAlloc.h index b93342380..3a2c658c4 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -31,14 +31,6 @@ void* xRealloc(void* ptr, size_t size); # define xStrdup(str_) (assert(str_), xStrdup_(str_)) #endif -#ifndef __has_attribute // Clang's macro -# define __has_attribute(x) 0 -#endif -#if (__has_attribute(nonnull) || \ - ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) -char* xStrdup_(const char* str) __attribute__((nonnull)); -#endif // __has_attribute(nonnull) || GNU C 3.3 or later - -char* xStrdup_(const char* str); +char* xStrdup_(const char* str) ATTR_NONNULL; #endif diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index cd5526a70..8901bc451 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -22,8 +22,6 @@ in the source distribution for its full text. #include -#define _UNUSED_ __attribute__((unused)) - static int MIB_hw_physmem[2]; static int MIB_vm_stats_vm_v_page_count[4]; static int pageSize; @@ -377,7 +375,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { for (int i = 0; i < count; i++) { struct kinfo_proc* kproc = &kprocs[i]; bool preExisting = false; - bool _UNUSED_ isIdleProcess = false; + bool ATTR_UNUSED isIdleProcess = false; // note: dragonflybsd kernel processes all have the same pid, so we misuse the kernel thread address to give them a unique identifier Process* proc = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, (Process_New) DragonFlyBSDProcess_new); diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index 84ab1c5a9..9665a60f1 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -51,8 +51,6 @@ typedef struct DragonFlyBSDProcessList_ { Hashtable *jails; } DragonFlyBSDProcessList; -#define _UNUSED_ __attribute__((unused)) - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/zfs/ZfsArcStats.c b/zfs/ZfsArcStats.c index bfed07d3c..6c02c2c11 100644 --- a/zfs/ZfsArcStats.c +++ b/zfs/ZfsArcStats.c @@ -21,4 +21,6 @@ typedef struct ZfsArcStats_ { } ZfsArcStats; }*/ -static int make_iso_compilers_happy __attribute__((unused)); +#include "Macros.h" + +static int make_iso_compilers_happy ATTR_UNUSED; From c3952e7c20a3108c2f16aa579f8062dfc2163bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 8 Sep 2020 14:28:34 +0200 Subject: [PATCH 193/411] Use strict function prototypes int foo(); declares a function taking any number of arguments. --- Action.c | 4 ++-- Action.h | 4 ++-- CRT.h | 12 ++++++------ MainPanel.h | 2 +- Process.h | 2 +- SignalsPanel.h | 2 +- UsersTable.h | 2 +- darwin/Platform.h | 4 ++-- dragonflybsd/Platform.h | 4 ++-- freebsd/Platform.h | 4 ++-- htop.c | 4 ++-- linux/Battery.c | 4 ++-- linux/Platform.h | 4 ++-- openbsd/Platform.h | 4 ++-- solaris/Platform.h | 4 ++-- unsupported/Platform.h | 4 ++-- 16 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Action.c b/Action.c index 5de0804d8..33320caf1 100644 --- a/Action.c +++ b/Action.c @@ -272,7 +272,7 @@ static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) { return st->settings->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st); } -static Htop_Reaction actionQuit() { +static Htop_Reaction actionQuit(ATTR_UNUSED State* st) { return HTOP_QUIT; } @@ -386,7 +386,7 @@ static Htop_Reaction actionTag(State* st) { return HTOP_OK; } -static Htop_Reaction actionRedraw() { +static Htop_Reaction actionRedraw(ATTR_UNUSED State *st) { clear(); return HTOP_REFRESH | HTOP_REDRAW_BAR; } diff --git a/Action.h b/Action.h index 0ec0537f8..0623e37d8 100644 --- a/Action.h +++ b/Action.h @@ -24,8 +24,6 @@ typedef enum { HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH } Htop_Reaction; -typedef Htop_Reaction (*Htop_Action)(); - typedef struct State_ { Settings* settings; UsersTable* ut; @@ -34,6 +32,8 @@ typedef struct State_ { Header* header; } State; +typedef Htop_Reaction (*Htop_Action)(State* st); + Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess); bool Action_setUserOnly(const char* userName, uid_t* userId); diff --git a/CRT.h b/CRT.h index d7d01e2cf..20ef283e3 100644 --- a/CRT.h +++ b/CRT.h @@ -149,9 +149,9 @@ extern void *backtraceArray[128]; #if HAVE_SETUID_ENABLED -void CRT_dropPrivileges(); +void CRT_dropPrivileges(void); -void CRT_restorePrivileges(); +void CRT_restorePrivileges(void); #else @@ -166,15 +166,15 @@ void CRT_restorePrivileges(); void CRT_init(int delay, int colorScheme, bool allowUnicode); -void CRT_done(); +void CRT_done(void); void CRT_fatalError(const char* note); -int CRT_readKey(); +int CRT_readKey(void); -void CRT_disableDelay(); +void CRT_disableDelay(void); -void CRT_enableDelay(); +void CRT_enableDelay(void); void CRT_setColors(int colorScheme); diff --git a/MainPanel.h b/MainPanel.h index ca064722a..01fb4977c 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -36,7 +36,7 @@ bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Ar extern PanelClass MainPanel_class; -MainPanel* MainPanel_new(); +MainPanel* MainPanel_new(void); void MainPanel_setState(MainPanel* this, State* state); diff --git a/Process.h b/Process.h index ebf5cdf47..82f6d6c82 100644 --- a/Process.h +++ b/Process.h @@ -169,7 +169,7 @@ typedef struct ProcessClass_ { extern char Process_pidFormat[20]; -void Process_setupColumnWidths(); +void Process_setupColumnWidths(void); void Process_humanNumber(RichString* str, unsigned long number, bool coloring); diff --git a/SignalsPanel.h b/SignalsPanel.h index 3d910ceee..460c81e73 100644 --- a/SignalsPanel.h +++ b/SignalsPanel.h @@ -12,6 +12,6 @@ typedef struct SignalItem_ { int number; } SignalItem; -Panel* SignalsPanel_new(); +Panel* SignalsPanel_new(void); #endif diff --git a/UsersTable.h b/UsersTable.h index fb3eaeddd..327bc087a 100644 --- a/UsersTable.h +++ b/UsersTable.h @@ -13,7 +13,7 @@ typedef struct UsersTable_ { Hashtable* users; } UsersTable; -UsersTable* UsersTable_new(); +UsersTable* UsersTable_new(void); void UsersTable_delete(UsersTable* this); diff --git a/darwin/Platform.h b/darwin/Platform.h index 7dd4ae608..6c0385874 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -28,11 +28,11 @@ void Platform_setBindings(Htop_Action* keys); extern int Platform_numberOfFields; -int Platform_getUptime(); +int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(); +int Platform_getMaxPid(void); extern ProcessPidColumn Process_pidColumns[]; diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 83c14f518..14a249e13 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -26,11 +26,11 @@ void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; -int Platform_getUptime(); +int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(); +int Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, int cpu); diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 1a180551c..e58e99d02 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -25,11 +25,11 @@ void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; -int Platform_getUptime(); +int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(); +int Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, int cpu); diff --git a/htop.c b/htop.c index 961ddc41b..941c6b83b 100644 --- a/htop.c +++ b/htop.c @@ -29,12 +29,12 @@ in the source distribution for its full text. //#link m -static void printVersionFlag() { +static void printVersionFlag(void) { fputs("htop " VERSION "\n", stdout); exit(0); } -static void printHelpFlag() { +static void printHelpFlag(void) { fputs("htop " VERSION "\n" "Released under the GNU GPL.\n\n" "-C --no-color Use a monochrome color scheme\n" diff --git a/linux/Battery.c b/linux/Battery.c index a8784da06..1930880da 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -89,7 +89,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short return total; } -static ACPresence procAcpiCheck() { +static ACPresence procAcpiCheck(void) { ACPresence isOn = AC_ERROR; const char *power_supplyPath = PROCDIR "/acpi/ac_adapter"; DIR *dir = opendir(power_supplyPath); @@ -137,7 +137,7 @@ static ACPresence procAcpiCheck() { return isOn; } -static double Battery_getProcBatData() { +static double Battery_getProcBatData(void) { const unsigned long int totalFull = parseBatInfo("info", 3, 4); if (totalFull == 0) return 0; diff --git a/linux/Platform.h b/linux/Platform.h index 9f0ee7fda..5060ea240 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -25,11 +25,11 @@ void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; -int Platform_getUptime(); +int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(); +int Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, int cpu); diff --git a/openbsd/Platform.h b/openbsd/Platform.h index f51d6bc66..9e742bf3c 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -27,11 +27,11 @@ void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; -int Platform_getUptime(); +int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(); +int Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, int cpu); diff --git a/solaris/Platform.h b/solaris/Platform.h index dd8614dcf..29cc79648 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -45,11 +45,11 @@ extern int Platform_numberOfFields; extern char Process_pidFormat[20]; -int Platform_getUptime(); +int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(); +int Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, int cpu); diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 2a3d768cc..fca7fc476 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -31,11 +31,11 @@ extern char Process_pidFormat[20]; extern ProcessPidColumn Process_pidColumns[]; -int Platform_getUptime(); +int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(); +int Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, int cpu); From b85a31415e8d68d0d46a105b1033a92669224682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 8 Sep 2020 13:59:30 +0200 Subject: [PATCH 194/411] Avoid checking of undefined macros These feature macros are either define or not defined at all at the configure step. --- Action.c | 4 ++-- Affinity.c | 6 +++--- CRT.c | 8 ++++---- CRT.h | 6 +++--- RichString.c | 4 ++-- RichString.h | 12 ++++++------ 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Action.c b/Action.c index 33320caf1..79a4225dc 100644 --- a/Action.c +++ b/Action.c @@ -279,7 +279,7 @@ static Htop_Reaction actionQuit(ATTR_UNUSED State* st) { static Htop_Reaction actionSetAffinity(State* st) { if (st->pl->cpuCount == 1) return HTOP_OK; -#if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY) +#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) Panel* panel = st->panel; Process* p = (Process*) Panel_getSelected(panel); @@ -416,7 +416,7 @@ static const struct { const char* key; const char* info; } helpRight[] = { { .key = " F9 k: ", .info = "kill process/tagged processes" }, { .key = " F7 ]: ", .info = "higher priority (root only)" }, { .key = " F8 [: ", .info = "lower priority (+ nice)" }, -#if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY) +#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) { .key = " a: ", .info = "set CPU affinity" }, #endif { .key = " e: ", .info = "show process environment" }, diff --git a/Affinity.c b/Affinity.c index 3ea45a9b8..098e5c169 100644 --- a/Affinity.c +++ b/Affinity.c @@ -12,12 +12,12 @@ in the source distribution for its full text. #ifdef HAVE_LIBHWLOC #include -#if __linux__ +#ifdef __linux__ #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_THREAD #else #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS #endif -#elif HAVE_LINUX_AFFINITY +#elif defined(HAVE_LINUX_AFFINITY) #include #endif @@ -79,7 +79,7 @@ bool Affinity_set(Process* proc, Arg arg) { return ok; } -#elif HAVE_LINUX_AFFINITY +#elif defined(HAVE_LINUX_AFFINITY) Affinity* Affinity_get(Process* proc, ProcessList* pl) { cpu_set_t cpuset; diff --git a/CRT.c b/CRT.c index 16f0e957e..d6390ab69 100644 --- a/CRT.c +++ b/CRT.c @@ -18,7 +18,7 @@ in the source distribution for its full text. #include #include #include -#if HAVE_SETUID_ENABLED +#ifdef HAVE_SETUID_ENABLED #include #include #endif @@ -519,7 +519,7 @@ static void CRT_handleSIGTERM(int sgn) { exit(0); } -#if HAVE_SETUID_ENABLED +#ifdef HAVE_SETUID_ENABLED static int CRT_euid = -1; @@ -550,11 +550,11 @@ void CRT_restorePrivileges() { } } -#else +#else /* HAVE_SETUID_ENABLED */ // In this case, the setuid operations are defined as macros in CRT.h -#endif +#endif /* HAVE_SETUID_ENABLED */ // TODO: pass an instance of Settings instead. diff --git a/CRT.h b/CRT.h index 20ef283e3..a2cfd8a9f 100644 --- a/CRT.h +++ b/CRT.h @@ -147,13 +147,13 @@ extern int CRT_colorScheme; extern void *backtraceArray[128]; -#if HAVE_SETUID_ENABLED +#ifdef HAVE_SETUID_ENABLED void CRT_dropPrivileges(void); void CRT_restorePrivileges(void); -#else +#else /* HAVE_SETUID_ENABLED */ /* Turn setuid operations into NOPs */ @@ -162,7 +162,7 @@ void CRT_restorePrivileges(void); #define CRT_restorePrivileges() #endif -#endif +#endif /* HAVE_SETUID_ENABLED */ void CRT_init(int delay, int colorScheme, bool allowUnicode); diff --git a/RichString.c b/RichString.c index b97e34e55..661b765d3 100644 --- a/RichString.c +++ b/RichString.c @@ -70,7 +70,7 @@ int RichString_findChar(RichString* this, char c, int start) { return -1; } -#else +#else /* HAVE_LIBNCURSESW */ static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { int newLen = from + len; @@ -99,7 +99,7 @@ int RichString_findChar(RichString* this, char c, int start) { return -1; } -#endif +#endif /* HAVE_LIBNCURSESW */ void RichString_prune(RichString* this) { if (this->chlen > RICHSTRING_MAXLEN) diff --git a/RichString.h b/RichString.h index e6fb4c320..6b626d40b 100644 --- a/RichString.h +++ b/RichString.h @@ -14,13 +14,13 @@ in the source distribution for its full text. #include #ifdef HAVE_NCURSESW_CURSES_H #include -#elif HAVE_NCURSES_NCURSES_H +#elif defined(HAVE_NCURSES_NCURSES_H) #include -#elif HAVE_NCURSES_CURSES_H +#elif defined(HAVE_NCURSES_CURSES_H) #include -#elif HAVE_NCURSES_H +#elif defined(HAVE_NCURSES_H) #include -#elif HAVE_CURSES_H +#elif defined(HAVE_CURSES_H) #include #endif @@ -63,13 +63,13 @@ void RichString_setAttrn(RichString* this, int attrs, int start, int finish); int RichString_findChar(RichString* this, char c, int start); -#else +#else /* HAVE_LIBNCURSESW */ void RichString_setAttrn(RichString* this, int attrs, int start, int finish); int RichString_findChar(RichString* this, char c, int start); -#endif +#endif /* HAVE_LIBNCURSESW */ void RichString_prune(RichString* this); From e719a85994e0ba13ac107c49fd85d49495dfc6a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 8 Sep 2020 14:28:15 +0200 Subject: [PATCH 195/411] Mark noreturn functions --- CRT.c | 1 + XAlloc.h | 4 +++- darwin/DarwinCRT.c | 1 + darwin/DarwinCRT.h | 4 +++- dragonflybsd/DragonFlyBSDCRT.c | 1 + dragonflybsd/DragonFlyBSDCRT.h | 4 +++- freebsd/FreeBSDCRT.c | 3 ++- freebsd/FreeBSDCRT.h | 6 ++++-- htop.c | 2 ++ linux/LinuxCRT.c | 1 + linux/LinuxCRT.h | 2 ++ openbsd/OpenBSDCRT.c | 3 ++- openbsd/OpenBSDCRT.h | 6 ++++-- solaris/SolarisCRT.c | 1 + solaris/SolarisCRT.h | 4 +++- unsupported/UnsupportedCRT.c | 1 + unsupported/UnsupportedCRT.h | 4 +++- 17 files changed, 37 insertions(+), 11 deletions(-) diff --git a/CRT.c b/CRT.c index d6390ab69..14d9ae627 100644 --- a/CRT.c +++ b/CRT.c @@ -513,6 +513,7 @@ int CRT_colorScheme = 0; void *backtraceArray[128]; +ATTR_NORETURN static void CRT_handleSIGTERM(int sgn) { (void) sgn; CRT_done(); diff --git a/XAlloc.h b/XAlloc.h index 3a2c658c4..cebe095c2 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -5,11 +5,13 @@ #define _GNU_SOURCE #endif +#include "Macros.h" + #include #include #include -void fail(void); +void fail(void) ATTR_NORETURN; void* xMalloc(size_t size); diff --git a/darwin/DarwinCRT.c b/darwin/DarwinCRT.c index 2191f3076..da16913db 100644 --- a/darwin/DarwinCRT.c +++ b/darwin/DarwinCRT.c @@ -6,6 +6,7 @@ in the source distribution for its full text. */ #include "config.h" +#include "DarwinCRT.h" #include "CRT.h" #include #include diff --git a/darwin/DarwinCRT.h b/darwin/DarwinCRT.h index 5e08422b5..663bd8b03 100644 --- a/darwin/DarwinCRT.h +++ b/darwin/DarwinCRT.h @@ -7,6 +7,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -void CRT_handleSIGSEGV(int sgn); +#include "Macros.h" + +void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; #endif diff --git a/dragonflybsd/DragonFlyBSDCRT.c b/dragonflybsd/DragonFlyBSDCRT.c index a0920833e..4d355ae9e 100644 --- a/dragonflybsd/DragonFlyBSDCRT.c +++ b/dragonflybsd/DragonFlyBSDCRT.c @@ -7,6 +7,7 @@ in the source distribution for its full text. */ #include "config.h" +#include "DragonFlyBSDCRT.h" #include "CRT.h" #include #include diff --git a/dragonflybsd/DragonFlyBSDCRT.h b/dragonflybsd/DragonFlyBSDCRT.h index 2bf85f71a..bf5384dbe 100644 --- a/dragonflybsd/DragonFlyBSDCRT.h +++ b/dragonflybsd/DragonFlyBSDCRT.h @@ -8,6 +8,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -void CRT_handleSIGSEGV(int sgn); +#include "Macros.h" + +void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; #endif diff --git a/freebsd/FreeBSDCRT.c b/freebsd/FreeBSDCRT.c index 49cc5d0d6..b0a0f6078 100644 --- a/freebsd/FreeBSDCRT.c +++ b/freebsd/FreeBSDCRT.c @@ -1,11 +1,12 @@ /* -htop - UnsupportedCRT.c +htop - FreeBSDCRT.c (C) 2014 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "config.h" +#include "FreeBSDCRT.h" #include "CRT.h" #include #include diff --git a/freebsd/FreeBSDCRT.h b/freebsd/FreeBSDCRT.h index eb88fcc1f..3ab802d99 100644 --- a/freebsd/FreeBSDCRT.h +++ b/freebsd/FreeBSDCRT.h @@ -1,12 +1,14 @@ #ifndef HEADER_FreeBSDCRT #define HEADER_FreeBSDCRT /* -htop - UnsupportedCRT.h +htop - FreeBSDCRT.h (C) 2014 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -void CRT_handleSIGSEGV(int sgn); +#include "Macros.h" + +void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; #endif diff --git a/htop.c b/htop.c index 941c6b83b..a7b37acb0 100644 --- a/htop.c +++ b/htop.c @@ -29,11 +29,13 @@ in the source distribution for its full text. //#link m +ATTR_NORETURN static void printVersionFlag(void) { fputs("htop " VERSION "\n", stdout); exit(0); } +ATTR_NORETURN static void printHelpFlag(void) { fputs("htop " VERSION "\n" "Released under the GNU GPL.\n\n" diff --git a/linux/LinuxCRT.c b/linux/LinuxCRT.c index dbfad27fb..2679d4f61 100644 --- a/linux/LinuxCRT.c +++ b/linux/LinuxCRT.c @@ -6,6 +6,7 @@ in the source distribution for its full text. */ #include "config.h" +#include "LinuxCRT.h" #include "CRT.h" #include diff --git a/linux/LinuxCRT.h b/linux/LinuxCRT.h index c379a8f65..2adb9f3fc 100644 --- a/linux/LinuxCRT.h +++ b/linux/LinuxCRT.h @@ -7,6 +7,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "Macros.h" + void CRT_handleSIGSEGV(int sgn); #endif diff --git a/openbsd/OpenBSDCRT.c b/openbsd/OpenBSDCRT.c index 233d30c99..8f026e3e7 100644 --- a/openbsd/OpenBSDCRT.c +++ b/openbsd/OpenBSDCRT.c @@ -1,5 +1,5 @@ /* -htop - UnsupportedCRT.c +htop - OpenBSDCRT.c (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville Released under the GNU GPL, see the COPYING file @@ -7,6 +7,7 @@ in the source distribution for its full text. */ #include "config.h" +#include "OpenBSDCRT.h" #include "CRT.h" #include #include diff --git a/openbsd/OpenBSDCRT.h b/openbsd/OpenBSDCRT.h index 85860a96c..74535beef 100644 --- a/openbsd/OpenBSDCRT.h +++ b/openbsd/OpenBSDCRT.h @@ -1,13 +1,15 @@ #ifndef HEADER_OpenBSDCRT #define HEADER_OpenBSDCRT /* -htop - UnsupportedCRT.h +htop - OpenBSDCRT.h (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -void CRT_handleSIGSEGV(int sgn); +#include "Macros.h" + +void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; #endif diff --git a/solaris/SolarisCRT.c b/solaris/SolarisCRT.c index 13e82d7c7..bea7d3775 100644 --- a/solaris/SolarisCRT.c +++ b/solaris/SolarisCRT.c @@ -7,6 +7,7 @@ in the source distribution for its full text. */ #include "config.h" +#include "SolarisCRT.h" #include "CRT.h" #include #include diff --git a/solaris/SolarisCRT.h b/solaris/SolarisCRT.h index 4e37b7f65..d9ab72089 100644 --- a/solaris/SolarisCRT.h +++ b/solaris/SolarisCRT.h @@ -8,6 +8,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -void CRT_handleSIGSEGV(int sgn); +#include "Macros.h" + +void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; #endif diff --git a/unsupported/UnsupportedCRT.c b/unsupported/UnsupportedCRT.c index 49cc5d0d6..f5c8fef1d 100644 --- a/unsupported/UnsupportedCRT.c +++ b/unsupported/UnsupportedCRT.c @@ -6,6 +6,7 @@ in the source distribution for its full text. */ #include "config.h" +#include "UnsupportedCRT.h" #include "CRT.h" #include #include diff --git a/unsupported/UnsupportedCRT.h b/unsupported/UnsupportedCRT.h index 24d63e5ca..cb248f805 100644 --- a/unsupported/UnsupportedCRT.h +++ b/unsupported/UnsupportedCRT.h @@ -7,6 +7,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -void CRT_handleSIGSEGV(int sgn); +#include "Macros.h" + +void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; #endif From 475f729a364ce92999f67adba4d754babe12a266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 8 Sep 2020 14:58:29 +0200 Subject: [PATCH 196/411] Resolve unused variable on FreeBSD --- freebsd/FreeBSDProcessList.c | 2 -- freebsd/Platform.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 6318d4240..06e729c8b 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -247,7 +247,6 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { u_long totalMem; u_int memActive, memWire, cachedMem; long buffersMem; - uint64_t memZfsArc; size_t len; //disabled for now, as it is always smaller than phycal amount of memory... @@ -383,7 +382,6 @@ void ProcessList_goThroughEntries(ProcessList* this) { FreeBSDProcessList_scanMemoryInfo(this); FreeBSDProcessList_scanCPUTime(this); - int cpus = this->cpuCount; int count = 0; struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index c51b37cb7..df664ae58 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -205,10 +205,12 @@ void Platform_setZfsCompressedArcValues(Meter* this) { } void Platform_setTasksValues(Meter* this) { + (void) this; // TODO } char* Platform_getProcessEnv(pid_t pid) { + (void) pid; // TODO return NULL; } From efb971f9df0a8f2ed908a19147ca7b0036b4515d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 8 Sep 2020 16:17:31 +0200 Subject: [PATCH 197/411] Fail travis CI on compiler warnings --- .travis.yml | 7 ++++++- darwin/DarwinProcessList.c | 1 - darwin/Platform.c | 4 ++-- freebsd/FreeBSDProcessList.c | 17 ++++++++++------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index b3e358de6..b86e51035 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,9 @@ os: - linux - osx -script: ./autogen.sh && ./configure && make +script: + - ./autogen.sh + # clang might warn about C11 generic selections in isnan() + - CFLAGS=-Wno-c11-extensions ./configure --enable-werror + - make + - CFLAGS=-Wno-c11-extensions make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 39d99c159..dea82379b 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -115,7 +115,6 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { } ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { - size_t len; DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList)); ProcessList_init(&this->super, Class(Process), usersTable, pidMatchList, userId); diff --git a/darwin/Platform.c b/darwin/Platform.c index a8ca45b24..1186fe04f 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -263,11 +263,11 @@ char* Platform_getProcessEnv(pid_t pid) { mib[0] = CTL_KERN; mib[1] = KERN_PROCARGS2; mib[2] = pid; - size_t bufsz = argmax; + bufsz = argmax; if (sysctl(mib, 3, buf, &bufsz, 0, 0) == 0) { if (bufsz > sizeof(int)) { char *p = buf, *endp = buf + bufsz; - int argc = *(int*)p; + int argc = *(int*)(void*)p; p += sizeof(int); // skip exe diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 06e729c8b..11cfe7e1f 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -391,7 +391,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { for (int i = 0; i < count; i++) { struct kinfo_proc* kproc = &kprocs[i]; bool preExisting = false; - bool isIdleProcess = false; + // TODO: bool isIdleProcess = false; struct tm date; Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, (Process_New) FreeBSDProcess_new); FreeBSDProcess* fp = (FreeBSDProcess*) proc; @@ -449,12 +449,15 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->percent_cpu = 100.0 * ((double)kproc->ki_pctcpu / (double)kernelFScale); proc->percent_mem = 100.0 * (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem); - if (proc->percent_cpu > 0.1) { - // system idle process should own all CPU time left regardless of CPU count - if ( strcmp("idle", kproc->ki_comm) == 0 ) { - isIdleProcess = true; - } - } + /* + * TODO + * if (proc->percent_cpu > 0.1) { + * // system idle process should own all CPU time left regardless of CPU count + * if ( strcmp("idle", kproc->ki_comm) == 0 ) { + * isIdleProcess = true; + * } + * } + */ proc->priority = kproc->ki_pri.pri_level - PZERO; From 5ea13e7ea9ca19130d5114a745d337b052cf2199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 8 Sep 2020 16:29:25 +0200 Subject: [PATCH 198/411] Add format attribute --- InfoScreen.h | 1 + 1 file changed, 1 insertion(+) diff --git a/InfoScreen.h b/InfoScreen.h index 93665c1de..a5a5abf60 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -40,6 +40,7 @@ InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar InfoScreen* InfoScreen_done(InfoScreen* this); +ATTR_FORMAT(printf, 2, 3) void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...); void InfoScreen_addLine(InfoScreen* this, const char* line); From 543286256ef35eb2a41531bc894c7ded53ae9de4 Mon Sep 17 00:00:00 2001 From: senjan Date: Fri, 18 Sep 2020 21:13:51 +0200 Subject: [PATCH 199/411] htop crashes on Solaris 11.4 due to missing ZFS ARC kstats --- solaris/SolarisProcessList.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 4e4d28281..45b7d902a 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -202,8 +202,8 @@ static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { int ksrphyserr = -1; kstat_named_t *cur_kstat = NULL; - if (spl->kd != NULL) { arcstats = kstat_lookup(spl->kd,"zfs",0,"arcstats"); } - if (arcstats != NULL) { ksrphyserr = kstat_read(spl->kd,arcstats,NULL); } + if (spl->kd != NULL) { arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats"); } + if (arcstats != NULL) { ksrphyserr = kstat_read(spl->kd, arcstats, NULL); } if (ksrphyserr != -1) { cur_kstat = kstat_data_lookup( arcstats, "size" ); spl->zfs.size = cur_kstat->value.ui64 / 1024; @@ -213,19 +213,19 @@ static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { spl->zfs.max = cur_kstat->value.ui64 / 1024; cur_kstat = kstat_data_lookup( arcstats, "mfu_size" ); - spl->zfs.MFU = cur_kstat->value.ui64 / 1024; + spl->zfs.MFU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; cur_kstat = kstat_data_lookup( arcstats, "mru_size" ); - spl->zfs.MRU = cur_kstat->value.ui64 / 1024; + spl->zfs.MRU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; cur_kstat = kstat_data_lookup( arcstats, "anon_size" ); - spl->zfs.anon = cur_kstat->value.ui64 / 1024; + spl->zfs.anon = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; cur_kstat = kstat_data_lookup( arcstats, "hdr_size" ); - spl->zfs.header = cur_kstat->value.ui64 / 1024; + spl->zfs.header = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; cur_kstat = kstat_data_lookup( arcstats, "other_size" ); - spl->zfs.other = cur_kstat->value.ui64 / 1024; + spl->zfs.other = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; if ((cur_kstat = kstat_data_lookup( arcstats, "compressed_size" )) != NULL) { spl->zfs.compressed = cur_kstat->value.ui64 / 1024; From 2c933f210b8ce50a9d5b18915a8ea7699b948afe Mon Sep 17 00:00:00 2001 From: senjan Date: Fri, 18 Sep 2020 21:37:00 +0200 Subject: [PATCH 200/411] htop shows no used memory in Solaris zone --- solaris/SolarisProcessList.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 45b7d902a..d09fc0bb1 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -133,10 +133,10 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { SolarisProcessList* spl = (SolarisProcessList*) pl; - kstat_t *meminfo = NULL; + static kstat_t *meminfo = NULL; int ksrphyserr = -1; kstat_named_t *totalmem_pgs = NULL; - kstat_named_t *lockedmem_pgs = NULL; + kstat_named_t *freemem_pgs = NULL; kstat_named_t *pages = NULL; struct swaptable *sl = NULL; struct swapent *swapdev = NULL; @@ -147,15 +147,21 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { char *spathbase = NULL; // Part 1 - physical memory - if (spl->kd != NULL) { meminfo = kstat_lookup(spl->kd,"unix",0,"system_pages"); } + if (spl->kd != NULL && meminfo == NULL) { + // Look up the kstat chain just one, it never changes + meminfo = kstat_lookup(spl->kd,"unix",0,"system_pages"); + } if (meminfo != NULL) { ksrphyserr = kstat_read(spl->kd,meminfo,NULL); } if (ksrphyserr != -1) { - totalmem_pgs = kstat_data_lookup( meminfo, "physmem" ); - lockedmem_pgs = kstat_data_lookup( meminfo, "pageslocked" ); - pages = kstat_data_lookup( meminfo, "pagestotal" ); + totalmem_pgs = kstat_data_lookup(meminfo, "physmem"); + freemem_pgs = kstat_data_lookup(meminfo, "freemem"); + pages = kstat_data_lookup(meminfo, "pagestotal"); pl->totalMem = totalmem_pgs->value.ui64 * PAGE_SIZE_KB; - pl->usedMem = lockedmem_pgs->value.ui64 * PAGE_SIZE_KB; + if (pl->totalMem > freemem_pgs->value.ui64 * PAGE_SIZE_KB) + pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * PAGE_SIZE_KB; + else + pl->usedMem = 0; // This can happen in non-global zone (in theory) // Not sure how to implement this on Solaris - suggestions welcome! pl->cachedMem = 0; // Not really "buffers" but the best Solaris analogue that I can find to From eb260af6bf0a63e076240398aa6568d5530bdee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 21 Sep 2020 13:47:39 +0200 Subject: [PATCH 201/411] Fix memory leak on cgroup read failure --- linux/LinuxProcess.c | 2 +- linux/LinuxProcessList.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index bef648a9a..9dd3b93de 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -251,7 +251,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) case VXID: xSnprintf(buffer, n, "%5u ", lp->vxid); break; #endif #ifdef HAVE_CGROUP - case CGROUP: xSnprintf(buffer, n, "%-10s ", lp->cgroup); break; + case CGROUP: xSnprintf(buffer, n, "%-10s ", lp->cgroup ? lp->cgroup : ""); break; #endif case OOM: xSnprintf(buffer, n, "%4u ", lp->oom); break; case IO_PRIORITY: { diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index a02509fcb..558792366 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -509,7 +509,10 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d xSnprintf(filename, MAX_NAME, "%s/%s/cgroup", dirname, name); FILE* file = fopen(filename, "r"); if (!file) { - process->cgroup = xStrdup(""); + if (process->cgroup) { + free(process->cgroup); + process->cgroup = NULL; + } return; } char output[PROC_LINE_LENGTH + 1]; From e0e5997c53ca9b61171d01b5a30c40d915622de2 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 20 Sep 2020 19:54:53 +0200 Subject: [PATCH 202/411] Fix minor regression in number highlighting Fixes #163 --- Process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Process.c b/Process.c index 343a736d3..428e121f8 100644 --- a/Process.c +++ b/Process.c @@ -93,7 +93,7 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { number %= 1000; len = snprintf(buffer, 10, "%03luM ", number); RichString_appendn(str, processMegabytesColor, buffer, len); - } else if (number < 100 * ONE_M) { + } else if (number < 100000 * ONE_K) { //2 digit GB, 1 digit MB number /= 100 * ONE_K; len = snprintf(buffer, 10, "%2lu", number/10); From f9966b5be3add7eae8e94cf6a55f53414fdf3cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 21 Sep 2020 14:27:32 +0200 Subject: [PATCH 203/411] Use checked allocation wrappers --- linux/LinuxProcessList.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 558792366..8333da504 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -73,7 +73,7 @@ static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { int bufSize = MAX_READ; int bufLen = 0; for(;;) { - buf = realloc(buf, bufSize); + buf = xRealloc(buf, bufSize); int size = xread(fd, buf + bufLen, MAX_READ); if (size <= 0) { buf[bufLen] = '\0'; @@ -89,7 +89,7 @@ static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { } int numDrivers = 0; int allocd = 10; - ttyDrivers = malloc(sizeof(TtyDriver) * allocd); + ttyDrivers = xMalloc(sizeof(TtyDriver) * allocd); char* at = buf; while (*at != '\0') { at = strchr(at, ' '); // skip first token @@ -97,7 +97,7 @@ static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { char* token = at; // mark beginning of path at = strchr(at, ' '); // find end of path *at = '\0'; at++; // clear and skip - ttyDrivers[numDrivers].path = strdup(token); // save + ttyDrivers[numDrivers].path = xStrdup(token); // save while (*at == ' ') at++; // skip spaces token = at; // mark beginning of major at = strchr(at, ' '); // find end of major @@ -123,12 +123,12 @@ static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { numDrivers++; if (numDrivers == allocd) { allocd += 10; - ttyDrivers = realloc(ttyDrivers, sizeof(TtyDriver) * allocd); + ttyDrivers = xRealloc(ttyDrivers, sizeof(TtyDriver) * allocd); } } free(buf); numDrivers++; - ttyDrivers = realloc(ttyDrivers, sizeof(TtyDriver) * numDrivers); + ttyDrivers = xRealloc(ttyDrivers, sizeof(TtyDriver) * numDrivers); ttyDrivers[numDrivers - 1].path = NULL; qsort(ttyDrivers, numDrivers - 1, sizeof(TtyDriver), sortTtyDrivers); this->ttyDrivers = ttyDrivers; @@ -773,7 +773,7 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in idx = min; } int err = stat(ttyDrivers[i].path, &sstat); - if (err == 0 && tty_nr == sstat.st_rdev) return strdup(ttyDrivers[i].path); + if (err == 0 && tty_nr == sstat.st_rdev) return xStrdup(ttyDrivers[i].path); } char* out; xAsprintf(&out, "/dev/%u:%u", maj, min); From 6b11738744d03889fc7654c17d6c605d54f847dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 23 Sep 2020 17:58:11 +0200 Subject: [PATCH 204/411] Avoid arithmetic on booleans --- AffinityPanel.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index d0a9e6dc7..aea0c98ab 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -100,11 +100,10 @@ static MaskItem* MaskItem_newSingleton(const char* text, int cpu, bool isSet) { this->ownCpuset = true; this->cpuset = hwloc_bitmap_alloc(); hwloc_bitmap_set(this->cpuset, cpu); - (void)isSet; #else this->cpu = cpu; #endif - this->value = 2 * isSet; + this->value = isSet ? 2 : 0; return this; } @@ -206,7 +205,7 @@ static HandlerResult AffinityPanel_eventHandler(Panel* super, int ch) { selected->value = 2; } #else - selected->value = 2 * !selected->value; /* toggle between 0 and 2 */ + selected->value = selected->value ? 0 : 2; /* toggle between 0 and 2 */ #endif result = HANDLED; From 2565dd3c58f87e611f1e50e12dc9f09fcd60c001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 17 Sep 2020 23:08:42 +0200 Subject: [PATCH 205/411] Drop dead code after break --- solaris/SolarisProcess.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index ab0bcab75..645bab80c 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -105,14 +105,7 @@ void SolarisProcess_writeField(Process* this, RichString* str, ProcessField fiel case TASKID: xSnprintf(buffer, n, Process_pidFormat, sp->taskid); break; case POOLID: xSnprintf(buffer, n, Process_pidFormat, sp->poolid); break; case CONTID: xSnprintf(buffer, n, Process_pidFormat, sp->contid); break; - case ZONE:{ - xSnprintf(buffer, n, "%-*s ", ZONENAME_MAX/4, sp->zname); break; - if (buffer[ZONENAME_MAX/4] != '\0') { - buffer[ZONENAME_MAX/4] = ' '; - buffer[(ZONENAME_MAX/4)+1] = '\0'; - } - break; - } + case ZONE: xSnprintf(buffer, n, "%-*s ", ZONENAME_MAX/4, sp->zname); break; case PID: xSnprintf(buffer, n, Process_pidFormat, sp->realpid); break; case PPID: xSnprintf(buffer, n, Process_pidFormat, sp->realppid); break; case LWPID: xSnprintf(buffer, n, Process_pidFormat, sp->lwpid); break; From 7844e06eb0ccdafa82fe4e774d13850cbdd127f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Fri, 18 Sep 2020 00:42:11 +0200 Subject: [PATCH 206/411] Document field M_SWAP in man page --- htop.1.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htop.1.in b/htop.1.in index cbd5453c1..26effeb0c 100644 --- a/htop.1.in +++ b/htop.1.in @@ -320,6 +320,9 @@ The library size of the process. .B M_DT (DIRTY) The size of the dirty pages of the process. .TP +.B M_SWAP (SWAP) +Size of the process's swapped pages. +.TP .B ST_UID (UID) The user ID of the process owner. .TP From 83257744cc37372ad2fca89d3d8b44cbdfb630b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Fri, 18 Sep 2020 00:48:59 +0200 Subject: [PATCH 207/411] Document M_PSS and M_PSSWP in man page --- htop.1.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htop.1.in b/htop.1.in index 26effeb0c..a68338852 100644 --- a/htop.1.in +++ b/htop.1.in @@ -323,6 +323,14 @@ The size of the dirty pages of the process. .B M_SWAP (SWAP) Size of the process's swapped pages. .TP +.B M_PSS (PSS) +proportional set size, same as M_RESIDENT but each page is divided by the +number of processes sharing it. +.TP +.B M_M_PSSWP (PSSWP) +Shows proportional swap share of this mapping, unlike \fBM_SWAP\fR this does not take +into account swapped out page of underlying shmem objects. +.TP .B ST_UID (UID) The user ID of the process owner. .TP From c1b52014440bf35ef27040a27bf458bb229a4823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Fri, 18 Sep 2020 13:32:59 +0200 Subject: [PATCH 208/411] Consistent wording/formatting of field descriptions --- htop.1.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htop.1.in b/htop.1.in index a68338852..424cc1570 100644 --- a/htop.1.in +++ b/htop.1.in @@ -321,14 +321,14 @@ The library size of the process. The size of the dirty pages of the process. .TP .B M_SWAP (SWAP) -Size of the process's swapped pages. +The size of the process's swapped pages. .TP .B M_PSS (PSS) -proportional set size, same as M_RESIDENT but each page is divided by the +The proportional set size, same as M_RESIDENT but each page is divided by the number of processes sharing it. .TP .B M_M_PSSWP (PSSWP) -Shows proportional swap share of this mapping, unlike \fBM_SWAP\fR this does not take +The proportional swap share of this mapping, unlike M_SWAP this does not take into account swapped out page of underlying shmem objects. .TP .B ST_UID (UID) From d2b3a7a3750c0ed7057cb6574dfa8563771421ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 18 Sep 2020 12:43:28 +0200 Subject: [PATCH 209/411] Drop dead process fields They are nowhere used. --- Process.h | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Process.h b/Process.h index 82f6d6c82..aff4374a0 100644 --- a/Process.h +++ b/Process.h @@ -103,25 +103,6 @@ typedef struct Process_ { unsigned long int minflt; unsigned long int majflt; - #ifdef DEBUG - long int itrealvalue; - unsigned long int vsize; - long int rss; - unsigned long int rlim; - unsigned long int startcode; - unsigned long int endcode; - unsigned long int startstack; - unsigned long int kstkesp; - unsigned long int kstkeip; - unsigned long int signal; - unsigned long int blocked; - unsigned long int sigignore; - unsigned long int sigcatch; - unsigned long int wchan; - unsigned long int nswap; - unsigned long int cnswap; - #endif - } Process; typedef struct ProcessFieldData_ { From f80509358954a39234b136466c4c6a77187744e9 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 1 Sep 2020 13:50:25 +0200 Subject: [PATCH 210/411] align cpu id to right --- CPUMeter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CPUMeter.c b/CPUMeter.c index cb77e712e..995867844 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -24,7 +24,7 @@ static void CPUMeter_init(Meter* this) { int cpu = this->param; if (this->pl->cpuCount > 1) { char caption[10]; - xSnprintf(caption, sizeof(caption), "%-3d", Settings_cpuId(this->pl->settings, cpu - 1)); + xSnprintf(caption, sizeof(caption), "%3d", Settings_cpuId(this->pl->settings, cpu - 1)); Meter_setCaption(this, caption); } if (this->param == 0) From 47e2cefe02dffe00369e5630eb1e3f54174f20af Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 7 Sep 2020 11:52:42 +0200 Subject: [PATCH 211/411] Update battery API to use NAN on error --- BatteryMeter.c | 5 +++-- darwin/Battery.c | 4 +++- dragonflybsd/Battery.c | 3 ++- freebsd/Battery.c | 3 ++- linux/Battery.c | 25 +++++++++++++------------ openbsd/Battery.c | 3 ++- solaris/Battery.c | 3 ++- unsupported/Battery.c | 3 ++- 8 files changed, 29 insertions(+), 20 deletions(-) diff --git a/BatteryMeter.c b/BatteryMeter.c index 859df9d76..0ae2834c8 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -15,6 +15,7 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). #include "StringUtils.h" #include "Platform.h" +#include #include #include @@ -29,8 +30,8 @@ static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) { Battery_getData(&percent, &isOnAC); - if (percent == -1) { - this->values[0] = 0; + if (isnan(percent)) { + this->values[0] = NAN; xSnprintf(buffer, len, "n/a"); return; } diff --git a/darwin/Battery.c b/darwin/Battery.c index d52a5954a..51d49c6d2 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -1,6 +1,8 @@ #include "BatteryMeter.h" +#include + #include #include #include @@ -9,7 +11,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFTypeRef power_sources = IOPSCopyPowerSourcesInfo(); - *level = -1; + *level = NAN; *isOnAC = AC_ERROR; if(NULL == power_sources) { diff --git a/dragonflybsd/Battery.c b/dragonflybsd/Battery.c index f17efb5da..589604290 100644 --- a/dragonflybsd/Battery.c +++ b/dragonflybsd/Battery.c @@ -7,13 +7,14 @@ in the source distribution for its full text. */ #include "BatteryMeter.h" +#include #include void Battery_getData(double* level, ACPresence* isOnAC) { int life; size_t life_len = sizeof(life); if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) - *level = -1; + *level = NAN; else *level = life; diff --git a/freebsd/Battery.c b/freebsd/Battery.c index b8c5e3124..009f7abe0 100644 --- a/freebsd/Battery.c +++ b/freebsd/Battery.c @@ -6,13 +6,14 @@ in the source distribution for its full text. */ #include "BatteryMeter.h" +#include #include void Battery_getData(double* level, ACPresence* isOnAC) { int life; size_t life_len = sizeof(life); if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) - *level = -1; + *level = NAN; else *level = life; diff --git a/linux/Battery.c b/linux/Battery.c index 1930880da..f92a3176f 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -17,6 +17,7 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat #include #include #include +#include #include "BatteryMeter.h" #include "StringUtils.h" @@ -140,18 +141,18 @@ static ACPresence procAcpiCheck(void) { static double Battery_getProcBatData(void) { const unsigned long int totalFull = parseBatInfo("info", 3, 4); if (totalFull == 0) - return 0; + return NAN; const unsigned long int totalRemain = parseBatInfo("state", 5, 3); if (totalRemain == 0) - return 0; + return NAN; return totalRemain * 100.0 / (double) totalFull; } static void Battery_getProcData(double* level, ACPresence* isOnAC) { - *level = Battery_getProcBatData(); *isOnAC = procAcpiCheck(); + *level = AC_ERROR != *isOnAC ? Battery_getProcBatData() : NAN; } // ---------------------------------------- @@ -176,7 +177,7 @@ static inline ssize_t xread(int fd, void *buf, size_t count) { static void Battery_getSysData(double* level, ACPresence* isOnAC) { - *level = 0; + *level = NAN; *isOnAC = AC_ERROR; DIR *dir = opendir(SYS_POWERSUPPLY_DIR); @@ -279,13 +280,14 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { } } closedir(dir); - *level = totalFull > 0 ? ((double) totalRemain * 100) / (double) totalFull : 0; + + *level = totalFull > 0 ? ((double) totalRemain * 100.0) / (double) totalFull : NAN; } static enum { BAT_PROC, BAT_SYS, BAT_ERR } Battery_method = BAT_PROC; static time_t Battery_cacheTime = 0; -static double Battery_cacheLevel = 0; +static double Battery_cacheLevel = NAN; static ACPresence Battery_cacheIsOnAC = 0; void Battery_getData(double* level, ACPresence* isOnAC) { @@ -299,22 +301,21 @@ void Battery_getData(double* level, ACPresence* isOnAC) { if (Battery_method == BAT_PROC) { Battery_getProcData(level, isOnAC); - if (*level == 0) { + if (isnan(*level)) { Battery_method = BAT_SYS; } } if (Battery_method == BAT_SYS) { Battery_getSysData(level, isOnAC); - if (*level == 0) { + if (isnan(*level)) { Battery_method = BAT_ERR; } } if (Battery_method == BAT_ERR) { - *level = -1; + *level = NAN; *isOnAC = AC_ERROR; - } - if (*level > 100.0) { - *level = 100.0; + } else { + CLAMP(*level, 0.0, 100.0); } Battery_cacheLevel = *level; Battery_cacheIsOnAC = *isOnAC; diff --git a/openbsd/Battery.c b/openbsd/Battery.c index c215e4181..66e4b631b 100644 --- a/openbsd/Battery.c +++ b/openbsd/Battery.c @@ -10,6 +10,7 @@ in the source distribution for its full text. #include #include #include +#include #include static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) { @@ -36,7 +37,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen); - *level = -1; + *level = NAN; if (found) { /* last full capacity */ mib[3] = 7; diff --git a/solaris/Battery.c b/solaris/Battery.c index 080cf5400..121d2e490 100644 --- a/solaris/Battery.c +++ b/solaris/Battery.c @@ -1,7 +1,8 @@ +#include #include "BatteryMeter.h" void Battery_getData(double* level, ACPresence* isOnAC) { - *level = -1; + *level = NAN; *isOnAC = AC_ERROR; } diff --git a/unsupported/Battery.c b/unsupported/Battery.c index 080cf5400..121d2e490 100644 --- a/unsupported/Battery.c +++ b/unsupported/Battery.c @@ -1,7 +1,8 @@ +#include #include "BatteryMeter.h" void Battery_getData(double* level, ACPresence* isOnAC) { - *level = -1; + *level = NAN; *isOnAC = AC_ERROR; } From 29ec1151436bd539dc659a394622cdd2d672f975 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 7 Sep 2020 11:53:58 +0200 Subject: [PATCH 212/411] Update IO rate display to use NAN on error --- Process.c | 2 +- linux/LinuxProcess.c | 13 ++++++++++--- linux/LinuxProcessList.c | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Process.c b/Process.c index 428e121f8..839db8d77 100644 --- a/Process.c +++ b/Process.c @@ -219,7 +219,7 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c largeNumberColor = CRT_colors[PROCESS]; processMegabytesColor = CRT_colors[PROCESS]; } - if (rate == -1) { + if (isnan(rate)) { int len = snprintf(buffer, n, " no perm "); RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len); } else if (rate < ONE_K) { diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 9dd3b93de..ccdb9da87 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -17,6 +17,7 @@ in the source distribution for its full text. #include #include #include +#include /* semi-global */ long long btime; @@ -237,9 +238,15 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) case IO_READ_RATE: Process_outputRate(str, buffer, n, lp->io_rate_read_bps, coloring); return; case IO_WRITE_RATE: Process_outputRate(str, buffer, n, lp->io_rate_write_bps, coloring); return; case IO_RATE: { - double totalRate = (lp->io_rate_read_bps != -1) - ? (lp->io_rate_read_bps + lp->io_rate_write_bps) - : -1; + double totalRate = NAN; + if(!isnan(lp->io_rate_read_bps) && !isnan(lp->io_rate_write_bps)) + totalRate = lp->io_rate_read_bps + lp->io_rate_write_bps; + else if(!isnan(lp->io_rate_read_bps)) + totalRate = lp->io_rate_read_bps; + else if(!isnan(lp->io_rate_write_bps)) + totalRate = lp->io_rate_write_bps; + else + totalRate = NAN; Process_outputRate(str, buffer, n, totalRate, coloring); return; } #endif diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 8333da504..33248b50b 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -331,8 +331,8 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna xSnprintf(filename, MAX_NAME, "%s/%s/io", dirname, name); int fd = open(filename, O_RDONLY); if (fd == -1) { - process->io_rate_read_bps = -1; - process->io_rate_write_bps = -1; + process->io_rate_read_bps = NAN; + process->io_rate_write_bps = NAN; process->io_rchar = -1LL; process->io_wchar = -1LL; process->io_syscr = -1LL; From d0d3deb73c9f185985e62b6b6bda76a4d324e9e8 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 7 Sep 2020 11:56:12 +0200 Subject: [PATCH 213/411] Properly query sysconf settting and use NAN if unavailable This also fixes an issue with time returned negative if sysconf(_SC_CLK_TCK) returned an error. --- linux/LinuxProcessList.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 33248b50b..18dda3edd 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -219,10 +219,18 @@ void ProcessList_delete(ProcessList* pl) { free(this); } -static double jiffy = 0.0; +static double jiffy = NAN; static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { - if(jiffy == 0.0) jiffy = sysconf(_SC_CLK_TCK); + if(isnan(jiffy)) { + errno = 0; + long sc_jiffy = sysconf(_SC_CLK_TCK); + if(errno || -1 == sc_jiffy) { + jiffy = NAN; + return t; // Assume 100Hz clock + } + jiffy = sc_jiffy; + } double jiffytime = 1.0 / jiffy; return (unsigned long long) t * jiffytime * 100; } From ebcf92464353d44c1d01b5afd286314415a66c96 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 7 Sep 2020 12:07:08 +0200 Subject: [PATCH 214/411] Use threshold for display of guest/steal/irq meters --- CPUMeter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 995867844..62c9971bc 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -83,12 +83,12 @@ static void CPUMeter_display(Object* cast, RichString* out) { xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_SOFTIRQ]); RichString_append(out, CRT_colors[METER_TEXT], "si:"); RichString_append(out, CRT_colors[CPU_SOFTIRQ], buffer); - if (this->values[CPU_METER_STEAL]) { + if (!isnan(this->values[CPU_METER_STEAL])) { xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_STEAL]); RichString_append(out, CRT_colors[METER_TEXT], "st:"); RichString_append(out, CRT_colors[CPU_STEAL], buffer); } - if (this->values[CPU_METER_GUEST]) { + if (!isnan(this->values[CPU_METER_GUEST])) { xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_GUEST]); RichString_append(out, CRT_colors[METER_TEXT], "gu:"); RichString_append(out, CRT_colors[CPU_GUEST], buffer); @@ -103,7 +103,7 @@ static void CPUMeter_display(Object* cast, RichString* out) { xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]); RichString_append(out, CRT_colors[METER_TEXT], "low:"); RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer); - if (this->values[CPU_METER_IRQ]) { + if (!isnan(this->values[CPU_METER_IRQ])) { xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_IRQ]); RichString_append(out, CRT_colors[METER_TEXT], "vir:"); RichString_append(out, CRT_colors[CPU_GUEST], buffer); From 3c65d78d77e43de12284417012fad2d8c195770e Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 7 Sep 2020 12:24:32 +0200 Subject: [PATCH 215/411] Update CPU freq display to use NAN on error --- CPUMeter.c | 2 +- darwin/Platform.c | 3 ++- dragonflybsd/Platform.c | 2 +- freebsd/Platform.c | 2 +- linux/LinuxProcessList.c | 2 +- openbsd/Platform.c | 2 +- solaris/Platform.c | 2 +- unsupported/Platform.c | 4 +++- 8 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 62c9971bc..badca9408 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -42,7 +42,7 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { if (this->pl->settings->showCPUFrequency) { double cpuFrequency = this->values[CPU_METER_FREQUENCY]; char cpuFrequencyBuffer[16]; - if (cpuFrequency < 0) { + if (isnan(cpuFrequency)) { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); } else { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.0fMHz", cpuFrequency); diff --git a/darwin/Platform.c b/darwin/Platform.c index 1186fe04f..129b1cb9d 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -19,6 +19,7 @@ in the source distribution for its full text. #include "zfs/ZfsCompressedArcMeter.h" #include "DarwinProcessList.h" +#include #include @@ -210,7 +211,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { /* Convert to percent and return */ total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL]; - mtr->values[CPU_METER_FREQUENCY] = -1; + mtr->values[CPU_METER_FREQUENCY] = NAN; return CLAMP(total, 0.0, 100.0); } diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 3b8e1a0d9..e4e78e384 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -168,7 +168,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; return percent; } diff --git a/freebsd/Platform.c b/freebsd/Platform.c index df664ae58..3fc5de31d 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -171,7 +171,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; return percent; } diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 18dda3edd..9f754f190 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1153,7 +1153,7 @@ static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { for (int i = 0; i <= cpus; i++) { CPUData* cpuData = &(this->cpus[i]); - cpuData->frequency = -1; + cpuData->frequency = NAN; } int numCPUsWithFrequency = 0; diff --git a/openbsd/Platform.c b/openbsd/Platform.c index cb162078e..bd5ef7efb 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -162,7 +162,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_STEAL] = 0.0; v[CPU_METER_GUEST] = 0.0; v[CPU_METER_IOWAIT] = 0.0; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; Meter_setItems(this, 8); totalPercent = v[0]+v[1]+v[2]+v[3]; } else { diff --git a/solaris/Platform.c b/solaris/Platform.c index 436c9ce92..d3ad1f932 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -186,7 +186,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; return percent; } diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 420dfb78f..20df33769 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -6,6 +6,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include + #include "Platform.h" #include "CPUMeter.h" #include "MemoryMeter.h" @@ -105,7 +107,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { (void) cpu; double* v = this->values; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; return 0.0; } From 321960bd96069ffefe209cf5da7eb7fca6489d53 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Fri, 18 Sep 2020 17:04:01 +0200 Subject: [PATCH 216/411] Update delay accounting to use NAN on error --- linux/LinuxProcess.c | 2 +- linux/LinuxProcessList.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index ccdb9da87..a589d62ea 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -182,7 +182,7 @@ bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio) { #ifdef HAVE_DELAYACCT void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) { - if (delay_percent == -1LL) { + if (isnan(delay_percent)) { xSnprintf(buffer, n, " N/A "); } else { xSnprintf(buffer, n, "%4.1f ", delay_percent); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 9f754f190..ac69ca213 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -681,9 +681,9 @@ static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProc } if (nl_send_sync(this->netlink_socket, msg) < 0) { - process->swapin_delay_percent = -1LL; - process->blkio_delay_percent = -1LL; - process->cpu_delay_percent = -1LL; + process->swapin_delay_percent = NAN; + process->blkio_delay_percent = NAN; + process->cpu_delay_percent = NAN; return; } From ba0fca18006c6797300da09ce46bcd8c08eec33e Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Fri, 18 Sep 2020 16:58:03 +0200 Subject: [PATCH 217/411] Add -Wfloat-equal to default build flags --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index f22490f5c..be1075f93 100644 --- a/configure.ac +++ b/configure.ac @@ -270,6 +270,7 @@ AM_CFLAGS="\ -Wall\ -Wcast-align\ -Wextra\ + -Wfloat-equal\ -Wmissing-format-attribute\ -Wmissing-noreturn\ -Wpointer-arith\ From 7ecea3d485a8e39ede377b4e74e5fee5bbfb4edd Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 21 Sep 2020 18:50:15 +0200 Subject: [PATCH 218/411] Use return value of CLAMP function --- linux/Battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/Battery.c b/linux/Battery.c index f92a3176f..e45afa4e7 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -315,7 +315,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { *level = NAN; *isOnAC = AC_ERROR; } else { - CLAMP(*level, 0.0, 100.0); + *level = CLAMP(*level, 0.0, 100.0); } Battery_cacheLevel = *level; Battery_cacheIsOnAC = *isOnAC; From 52338171220af1ff009ea30114a290c80847b2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 24 Sep 2020 12:01:59 +0200 Subject: [PATCH 219/411] Avoid unsigned integer overflow unsigned integer overflows are well-defined, but they might point to a counting issue. Having the code free of unsigned overflows makes it easier to spot potential bugs. Action.c:332:27: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uid_t' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Action.c:332:27 in --- Action.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Action.c b/Action.c index 79a4225dc..eac7f1f61 100644 --- a/Action.c +++ b/Action.c @@ -329,7 +329,7 @@ static Htop_Reaction actionFilterByUser(State* st) { ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, false); if (picked) { if (picked == allUsers) { - st->pl->userId = -1; + st->pl->userId = (uid_t)-1; } else { Action_setUserOnly(ListItem_getRef(picked), &(st->pl->userId)); } From f4bb50294a31c0d46dbcd742c4002f4fbb20d2a8 Mon Sep 17 00:00:00 2001 From: ryenus Date: Thu, 3 Aug 2017 17:43:28 +0800 Subject: [PATCH 220/411] show selected command wrapped in a separate window For a process with a very long command, especially with many long command line arguments, inspecting the command and its arguments could become inconvenient. Meanwhile htop supports the concept of "screen", or window, which is extended here to create a dedicated "CommandScreen", making it possible to display the command of the selected process in a separate window meanwhile being wrapped into multiple lines. Another benefit of using a command screen is, the user can navigate through the wrapped lines of the command and perform actions like searching and filtering. --- Action.c | 14 +++++++++- CommandScreen.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ CommandScreen.h | 16 +++++++++++ Makefile.am | 4 +-- htop.1.in | 3 ++ 5 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 CommandScreen.c create mode 100644 CommandScreen.h diff --git a/Action.c b/Action.c index eac7f1f61..f36e0bd2d 100644 --- a/Action.c +++ b/Action.c @@ -13,6 +13,7 @@ in the source distribution for its full text. #include "CategoriesPanel.h" #include "CRT.h" #include "EnvScreen.h" +#include "CommandScreen.h" #include "MainPanel.h" #include "OpenFilesScreen.h" #include "Process.h" @@ -422,8 +423,8 @@ static const struct { const char* key; const char* info; } helpRight[] = { { .key = " e: ", .info = "show process environment" }, { .key = " i: ", .info = "set IO priority" }, { .key = " l: ", .info = "list open files with lsof" }, + { .key = " M: ", .info = "show process command in multiple lines" }, { .key = " s: ", .info = "trace syscalls with strace" }, - { .key = " ", .info = "" }, { .key = " F2 C S: ", .info = "setup" }, { .key = " F1 h: ", .info = "show this help screen" }, { .key = " F10 q: ", .info = "quit" }, @@ -530,6 +531,16 @@ static Htop_Reaction actionShowEnvScreen(State* st) { return HTOP_REFRESH | HTOP_REDRAW_BAR; } +static Htop_Reaction actionShowCommandScreen(State* st) { + Process* p = (Process*) Panel_getSelected(st->panel); + if (!p) return HTOP_OK; + CommandScreen* cmdScr = CommandScreen_new(p); + InfoScreen_run((InfoScreen*)cmdScr); + CommandScreen_delete((Object*)cmdScr); + clear(); + CRT_enableDelay(); + return HTOP_REFRESH | HTOP_REDRAW_BAR; +} void Action_setBindings(Htop_Action* keys) { keys[KEY_RESIZE] = actionResize; @@ -584,4 +595,5 @@ void Action_setBindings(Htop_Action* keys) { keys['U'] = actionUntagAll; keys['c'] = actionTagAllChildren; keys['e'] = actionShowEnvScreen; + keys['M'] = actionShowCommandScreen; } diff --git a/CommandScreen.c b/CommandScreen.c new file mode 100644 index 000000000..0e261175a --- /dev/null +++ b/CommandScreen.c @@ -0,0 +1,74 @@ +#include "CommandScreen.h" + +#include "config.h" +#include "CRT.h" +#include "IncSet.h" +#include "ListItem.h" +#include "Platform.h" +#include "StringUtils.h" + +#include +#include +#include + + +static void CommandScreen_addLine(InfoScreen* this, char* line, const char* p, int line_offset, int len) { + memcpy(line, p - line_offset, len); + line[len] = '\0'; + InfoScreen_addLine(this, line); +} + +static void CommandScreen_scan(InfoScreen* this) { + Panel* panel = this->display; + int idx = MAXIMUM(Panel_getSelectedIndex(panel), 0); + + Panel_prune(panel); + + const char* p = this->process->comm; + char* line = xMalloc(COLS + 1); + int line_offset = 0, last_spc = -1, len; + for (; *p != '\0'; p++, line_offset++) { + if (*p == ' ') last_spc = line_offset; + + if (line_offset == COLS) { + len = (last_spc == -1) ? line_offset : last_spc; + CommandScreen_addLine(this, line, p, line_offset, len); + line_offset -= len; + last_spc = -1; + } + } + + if (line_offset > 0) CommandScreen_addLine(this, line, p, line_offset, line_offset); + + free(line); + Panel_setSelected(panel, idx); +} + +static void CommandScreen_draw(InfoScreen* this) { + char* title = xMalloc(COLS + 1); + int len = snprintf(title, COLS + 1, "Command of process %d - %s", this->process->pid, this->process->comm); + if (len > COLS) { + memset(&title[COLS - 3], '.', 3); + } + + InfoScreen_drawTitled(this, "%s", title); + free(title); +} + +InfoScreenClass CommandScreen_class = { + .super = { + .extends = Class(Object), + .delete = CommandScreen_delete + }, + .scan = CommandScreen_scan, + .draw = CommandScreen_draw +}; + +CommandScreen* CommandScreen_new(Process* process) { + CommandScreen* this = AllocThis(CommandScreen); + return (CommandScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 3, " "); +} + +void CommandScreen_delete(Object* this) { + free(InfoScreen_done((InfoScreen*)this)); +} diff --git a/CommandScreen.h b/CommandScreen.h new file mode 100644 index 000000000..a1604a3ed --- /dev/null +++ b/CommandScreen.h @@ -0,0 +1,16 @@ +#ifndef HEADER_CommandScreen +#define HEADER_CommandScreen + +#include "InfoScreen.h" + +typedef struct CommandScreen_ { + InfoScreen super; +} CommandScreen; + +extern InfoScreenClass CommandScreen_class; + +CommandScreen* CommandScreen_new(Process* process); + +void CommandScreen_delete(Object* this); + +#endif diff --git a/Makefile.am b/Makefile.am index c97ae938c..441ea80e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,7 @@ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.c \ TraceScreen.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c EnvScreen.c \ -InfoScreen.c XAlloc.c +InfoScreen.c CommandScreen.c XAlloc.c myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ @@ -32,7 +32,7 @@ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.h \ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \ -EnvScreen.h InfoScreen.h XAlloc.h Macros.h +EnvScreen.h InfoScreen.h CommandScreen.h XAlloc.h Macros.h # Linux # ----- diff --git a/htop.1.in b/htop.1.in index 424cc1570..215d92c5d 100644 --- a/htop.1.in +++ b/htop.1.in @@ -116,6 +116,9 @@ update of system calls issued by the process. Display open files for a process: if lsof(1) is installed, pressing this key will display the list of file descriptors opened by the process. .TP +.B M +Display the command line of the highlighted process in multiple lines. +.TP .B F1, h, ? Go to the help screen .TP From 005c4d1f2321b45f484fab0127db315927c2207b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 8 Sep 2020 16:25:22 +0200 Subject: [PATCH 221/411] Make --enable-hwloc and --enable-linux-affinity mutual exclusive They can not be supported both at the same time. Fail configure step instead of silently only use hwloc. --- .github/workflows/ci.yml | 12 +++++----- Affinity.h | 4 ++++ configure.ac | 52 ++++++++++++++++++++++++---------------- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d95d0af91..0d6de8fe9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,11 +12,11 @@ jobs: - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror + run: ./configure --enable-werror --enable-linux-affinity - name: Build run: make - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror + run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity" build-ubuntu-clang-latest: runs-on: ubuntu-latest @@ -34,11 +34,11 @@ jobs: - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror + run: ./configure --enable-werror --enable-linux-affinity - name: Build run: make - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror + run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity" build-ubuntu-latest-full-featured: runs-on: ubuntu-latest @@ -49,11 +49,11 @@ jobs: - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-linux-affinity --enable-hwloc --enable-setuid --enable-delayacct + run: ./configure --enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct - name: Build run: make - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-linux-affinity --enable-hwloc --enable-setuid --enable-delayacct' + run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct' whitespace_check: runs-on: ubuntu-latest diff --git a/Affinity.h b/Affinity.h index 20d004709..ced161b44 100644 --- a/Affinity.h +++ b/Affinity.h @@ -11,6 +11,10 @@ in the source distribution for its full text. #include "Process.h" #include "ProcessList.h" +#if defined(HAVE_LIBHWLOC) && defined(HAVE_LINUX_AFFINITY) +#error hwlock and linux affinity are mutual exclusive. +#endif + typedef struct Affinity_ { ProcessList* pl; int size; diff --git a/configure.ac b/configure.ac index be1075f93..0adbff04e 100644 --- a/configure.ac +++ b/configure.ac @@ -214,33 +214,43 @@ if test "$my_htop_platform" = "solaris"; then AC_CHECK_LIB([malloc], [free], [], [missing_libraries="$missing_libraries libmalloc"]) fi -AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes") -if test "x$enable_linux_affinity" = xyes; then - AC_MSG_CHECKING([for usable sched_setaffinity]) - AC_RUN_IFELSE([ - AC_LANG_PROGRAM([[ - #include - #include - static cpu_set_t cpuset; - ]], [[ - CPU_ZERO(&cpuset); - sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); - if (errno == ENOSYS) return 1; - ]])], - [AC_MSG_RESULT([yes])], - [enable_linux_affinity=no - AC_MSG_RESULT([no])], - [AC_MSG_RESULT([yes (assumed while cross compiling)])]) +AC_ARG_ENABLE(hwloc, [AS_HELP_STRING([--enable-hwloc], [enable hwloc support for CPU affinity, disables Linux affinity])],, enable_hwloc="no") +if test "x$enable_hwloc" = xyes +then + AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [missing_libraries="$missing_libraries libhwloc"]) + AC_CHECK_HEADERS([hwloc.h],[:], [missing_headers="$missing_headers $ac_header"]) +fi + +AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc])], ,enable_linux_affinity="check") +if test "x$enable_linux_affinity" = xcheck; then + if test "x$enable_hwloc" = xyes; then + enable_linux_affinity=no + else + AC_MSG_CHECKING([for usable sched_setaffinity]) + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([[ + #include + #include + static cpu_set_t cpuset; + ]], [[ + CPU_ZERO(&cpuset); + sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); + if (errno == ENOSYS) return 1; + ]])], + [enable_linux_affinity=yes + AC_MSG_RESULT([yes])], + [enable_linux_affinity=no + AC_MSG_RESULT([no])], + [AC_MSG_RESULT([yes (assumed while cross compiling)])]) + fi fi if test "x$enable_linux_affinity" = xyes; then AC_DEFINE(HAVE_LINUX_AFFINITY, 1, [Define if Linux sched_setaffinity and sched_getaffinity are to be used.]) fi -AC_ARG_ENABLE(hwloc, [AS_HELP_STRING([--enable-hwloc], [enable hwloc support for CPU affinity])],, enable_hwloc="no") -if test "x$enable_hwloc" = xyes +if test "x$enable_linux_affinity" = xyes -a "x$enable_hwloc" = xyes then - AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [missing_libraries="$missing_libraries libhwloc"]) - AC_CHECK_HEADERS([hwloc.h],[:], [missing_headers="$missing_headers $ac_header"]) + AC_MSG_ERROR([--enable-hwloc and --enable-linux-affinity are mutual exclusive. Specify at most one of them.]) fi AC_ARG_ENABLE(setuid, [AS_HELP_STRING([--enable-setuid], [enable setuid support for platforms that need it])],, enable_setuid="no") From 594409f2990e8068d2993ee89e714eddfab5f06d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 24 Sep 2020 19:52:08 +0200 Subject: [PATCH 222/411] Add DeepCode inline suppression commsize is bounded by the allocated length passed in by commLen, saved into commLenIn --- linux/LinuxProcessList.c | 1 + 1 file changed, 1 insertion(+) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index ac69ca213..318a94b9d 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -261,6 +261,7 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, if (!end) return false; int commsize = MINIMUM(end - location, commLenIn - 1); + // deepcode ignore BufferOverflow: commsize is bounded by the allocated length passed in by commLen, saved into commLenIn memcpy(command, location, commsize); command[commsize] = '\0'; *commLen = commsize; From f4e1f4619f3761382d5e97ddf92237085a7bd443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 24 Sep 2020 20:03:33 +0200 Subject: [PATCH 223/411] Add DeepCode inline suppression We just want a non-NUll pointer in the matching pid hashtable. The pointer is not dereferenced anyways. --- htop.c | 1 + 1 file changed, 1 insertion(+) diff --git a/htop.c b/htop.c index a7b37acb0..7bd15291f 100644 --- a/htop.c +++ b/htop.c @@ -172,6 +172,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { while(pid) { unsigned int num_pid = atoi(pid); + // deepcode ignore CastIntegerToAddress: we just want a non-NUll pointer here Hashtable_put(flags.pidMatchList, num_pid, (void *) 1); pid = strtok_r(NULL, ",", &saveptr); } From edf1b10d2c3fa94c23a23cfc947490cf1ebf66d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 22 Sep 2020 14:50:50 +0200 Subject: [PATCH 224/411] Read CPU frequency from sysfs by default Use the more portable sysfs node /sys/devices/system/cpu/cpuX/cpufreq/scaling_cur_freq to get the CPU frequency. In case of an error fall back to /proc/cpuinfo . Also use a fixed width of 4 for the frequency to avoid position jumps in case the frequency moves in the range 900-1100 MHz. --- CPUMeter.c | 2 +- linux/LinuxProcessList.c | 128 +++++++++++++++++++++++---------------- 2 files changed, 78 insertions(+), 52 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index badca9408..482565ee1 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -45,7 +45,7 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { if (isnan(cpuFrequency)) { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); } else { - xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.0fMHz", cpuFrequency); + xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%4uMHz", (unsigned)cpuFrequency); } if (this->pl->settings->showCPUUsage) { xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 318a94b9d..807cc8a66 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1145,79 +1145,105 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { return period; } -static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { - ProcessList* pl = (ProcessList*) this; - Settings* settings = pl->settings; - +static int scanCPUFreqencyFromSysCPUFreq(LinuxProcessList* this) { int cpus = this->super.cpuCount; - assert(cpus > 0); + int numCPUsWithFrequency = 0; + unsigned long totalFrequency = 0; + + for (int i = 0; i < cpus; ++i) { + char pathBuffer[64]; + xSnprintf(pathBuffer, sizeof(pathBuffer), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i); + + FILE* file = fopen(pathBuffer, "r"); + if (!file) + return -errno; + + unsigned long frequency; + if (fscanf(file, "%lu", &frequency) == 1) { + /* convert kHz to MHz */ + frequency = frequency / 1000; + this->cpus[i + 1].frequency = frequency; + numCPUsWithFrequency++; + totalFrequency += frequency; + } - for (int i = 0; i <= cpus; i++) { - CPUData* cpuData = &(this->cpus[i]); - cpuData->frequency = NAN; + fclose(file); } + if (numCPUsWithFrequency > 0) + this->cpus[0].frequency = (double)totalFrequency / numCPUsWithFrequency; + + return 0; +} + +static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) { + FILE* file = fopen(PROCCPUINFOFILE, "r"); + if (file == NULL) + return; + + int cpus = this->super.cpuCount; int numCPUsWithFrequency = 0; double totalFrequency = 0; + int cpuid = -1; - if (settings->showCPUFrequency) { - FILE* file = fopen(PROCCPUINFOFILE, "r"); - if (file == NULL) { - CRT_fatalError("Cannot open " PROCCPUINFOFILE); - } - - int cpuid = -1; + while (!feof(file)) { double frequency; - while (!feof(file)) { - char buffer[PROC_LINE_LENGTH]; - char *ok = fgets(buffer, PROC_LINE_LENGTH, file); - if (!ok) break; - - if ( - (sscanf(buffer, "processor : %d", &cpuid) == 1) || - (sscanf(buffer, "processor: %d", &cpuid) == 1) - ) { - if (cpuid < 0 || cpuid > (cpus - 1)) { - char tmpbuffer[64]; - xSnprintf(tmpbuffer, sizeof(tmpbuffer), PROCCPUINFOFILE " contains out-of-range CPU number %d", cpuid); - CRT_fatalError(tmpbuffer); - } - } else if ( - (sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) || - (sscanf(buffer, "cpu MHz: %lf", &frequency) == 1) - ) { - if (cpuid < 0 || cpuid > (cpus - 1)) { - CRT_fatalError(PROCCPUINFOFILE " is malformed: cpu MHz line without corresponding processor line"); - } + char buffer[PROC_LINE_LENGTH]; - int cpu = cpuid + 1; - CPUData* cpuData = &(this->cpus[cpu]); - cpuData->frequency = frequency; - numCPUsWithFrequency++; - totalFrequency += frequency; - } else if (buffer[0] == '\n') { - cpuid = -1; - } - } - fclose(file); + if (fgets(buffer, PROC_LINE_LENGTH, file) == NULL) + break; - if (numCPUsWithFrequency > 0) { - this->cpus[0].frequency = totalFrequency / numCPUsWithFrequency; + if ( + (sscanf(buffer, "processor : %d", &cpuid) == 1) || + (sscanf(buffer, "processor: %d", &cpuid) == 1) + ) { + continue; + } else if ( + (sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) || + (sscanf(buffer, "cpu MHz: %lf", &frequency) == 1) + ) { + if (cpuid < 0 || cpuid > (cpus - 1)) + continue; + + CPUData* cpuData = &(this->cpus[cpuid + 1]); + /* do not override sysfs data */ + if (isnan(cpuData->frequency)) + cpuData->frequency = frequency; + numCPUsWithFrequency++; + totalFrequency += frequency; + } else if (buffer[0] == '\n') { + cpuid = -1; } } + fclose(file); - double period = (double)this->cpus[0].totalPeriod / cpus; - return period; + if (numCPUsWithFrequency > 0) + this->cpus[0].frequency = totalFrequency / numCPUsWithFrequency; +} + +static void LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { + int cpus = this->super.cpuCount; + assert(cpus > 0); + + for (int i = 0; i <= cpus; i++) + this->cpus[i].frequency = NAN; + + if (scanCPUFreqencyFromSysCPUFreq(this) == 0) + return; + + scanCPUFreqencyFromCPUinfo(this); } void ProcessList_goThroughEntries(ProcessList* super) { LinuxProcessList* this = (LinuxProcessList*) super; + const Settings* settings = super->settings; LinuxProcessList_scanMemoryInfo(super); LinuxProcessList_scanZfsArcstats(this); double period = LinuxProcessList_scanCPUTime(this); - LinuxProcessList_scanCPUFrequency(this); + if (settings->showCPUFrequency) + LinuxProcessList_scanCPUFrequency(this); struct timeval tv; gettimeofday(&tv, NULL); From ce0fd5f6d8769e5d482fc553bdbc22fbdb518501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 23 Sep 2020 12:39:45 +0200 Subject: [PATCH 225/411] Drop unused macros --- Meter.c | 2 -- XAlloc.c | 14 -------------- 2 files changed, 16 deletions(-) diff --git a/Meter.c b/Meter.c index 00c49ceea..5b4ae006c 100644 --- a/Meter.c +++ b/Meter.c @@ -19,8 +19,6 @@ in the source distribution for its full text. #include #include -#define GRAPH_DELAY (DEFAULT_DELAY/2) - #define GRAPH_HEIGHT 4 /* Unit: rows (lines) */ MeterClass Meter_class = { diff --git a/XAlloc.c b/XAlloc.c index c0fa75471..294eb36ab 100644 --- a/XAlloc.c +++ b/XAlloc.c @@ -39,20 +39,6 @@ void* xRealloc(void* ptr, size_t size) { return data; } -#undef xAsprintf - -#define xAsprintf(strp, fmt, ...) do { int _r=asprintf(strp, fmt, __VA_ARGS__); if (_r < 0) { fail(); } } while(0) - -#define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0) - -#undef xStrdup -#undef xStrdup_ -#ifdef NDEBUG -# define xStrdup_ xStrdup -#else -# define xStrdup(str_) (assert(str_), xStrdup_(str_)) -#endif - char* xStrdup_(const char* str) { char* data = strdup(str); if (!data) { From 4296e74ada03f59724d80a77e8e8fe7e5ecce9a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 23 Sep 2020 13:43:03 +0200 Subject: [PATCH 226/411] Include prototype in Battery implementation linux/Battery.c:291:6: warning: no previous prototype for function 'Battery_getData' [-Wmissing-prototypes] void Battery_getData(double* level, ACPresence* isOnAC) { ^ --- linux/Battery.c | 3 ++- linux/Battery.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/linux/Battery.c b/linux/Battery.c index e45afa4e7..6ea48c459 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -7,6 +7,8 @@ in the source distribution for its full text. Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). */ +#include "Battery.h" + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif @@ -18,7 +20,6 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat #include #include #include -#include "BatteryMeter.h" #include "StringUtils.h" #define SYS_POWERSUPPLY_DIR "/sys/class/power_supply" diff --git a/linux/Battery.h b/linux/Battery.h index 8ca0d7fbe..3b3d23825 100644 --- a/linux/Battery.h +++ b/linux/Battery.h @@ -9,6 +9,8 @@ in the source distribution for its full text. Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). */ +#include "BatteryMeter.h" + void Battery_getData(double* level, ACPresence* isOnAC); #endif From 4a1f3fca96c10d3d983570d1696c1c2ca940786f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 23 Sep 2020 13:47:20 +0200 Subject: [PATCH 227/411] Drop unnecessary usage of comma operator --- AffinityPanel.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index aea0c98ab..57e889aa5 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -270,12 +270,14 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u for (unsigned i = 1; i < depth; i++) { xSnprintf(&indent_buf[off], left, "%s ", (indent & (1u << i)) ? CRT_treeStr[TREE_STR_VERT] : " "); size_t len = strlen(&indent_buf[off]); - off += len, left -= len; + off += len; + left -= len; } xSnprintf(&indent_buf[off], left, "%s", obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]); size_t len = strlen(&indent_buf[off]); - off += len, left -= len; + off += len; + left -= len; } xSnprintf(buf, 64, "%s %s%u", type_name, index_prefix, index); From cd1ba1422b7e3d4b07002192b7961c2d9783acc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 23 Sep 2020 13:52:49 +0200 Subject: [PATCH 228/411] Avoid bad function cast warning linux/Platform.c:142:17: warning: cast from function call of type 'double' to non-matching type 'int' [-Wbad-function-cast] return (int) floor(uptime); ^~~~~~~~~~~~~ --- linux/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/Platform.c b/linux/Platform.c index 0545fc461..8972862e0 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -139,7 +139,7 @@ int Platform_getUptime() { fclose(fd); if (n <= 0) return 0; } - return (int) floor(uptime); + return floor(uptime); } void Platform_getLoadAverage(double* one, double* five, double* fifteen) { From 6a03cd237a2e85600275a358430ea544f53aba3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 23 Sep 2020 13:55:01 +0200 Subject: [PATCH 229/411] Avoid warning about unreachable break statement htop.c:112:13: warning: 'break' will never be executed [-Wunreachable-code-break] break; ^~~~~ htop.c:109:13: warning: 'break' will never be executed [-Wunreachable-code-break] break; ^~~~~ --- htop.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/htop.c b/htop.c index 7bd15291f..fbd6dee4b 100644 --- a/htop.c +++ b/htop.c @@ -29,13 +29,10 @@ in the source distribution for its full text. //#link m -ATTR_NORETURN static void printVersionFlag(void) { fputs("htop " VERSION "\n", stdout); - exit(0); } -ATTR_NORETURN static void printHelpFlag(void) { fputs("htop " VERSION "\n" "Released under the GNU GPL.\n\n" @@ -54,7 +51,6 @@ static void printHelpFlag(void) { "Press F1 inside htop for online help.\n" "See 'man htop' for more information.\n", stdout); - exit(0); } // ---------------------------------------- @@ -106,10 +102,10 @@ static CommandLineSettings parseArguments(int argc, char** argv) { switch (opt) { case 'h': printHelpFlag(); - break; + exit(0); case 'V': printVersionFlag(); - break; + exit(0); case 's': if (strcmp(optarg, "help") == 0) { for (int j = 1; j < Platform_numberOfFields; j++) { From 18b1e9fba95ce50d47c2199920f6727f26de4063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 23 Sep 2020 14:15:51 +0200 Subject: [PATCH 230/411] Do not drop qualifier in cast ListItem.c:73:33: warning: cast from 'const void *' to 'struct ListItem_ *' drops const qualifier [-Wcast-qual] ListItem* obj1 = (ListItem*) cast1; ^ ListItem.c:74:33: warning: cast from 'const void *' to 'struct ListItem_ *' drops const qualifier [-Wcast-qual] ListItem* obj2 = (ListItem*) cast2; ^ Process.c:434:28: warning: cast from 'const void *' to 'struct Process_ *' drops const qualifier [-Wcast-qual] Process* p1 = (Process*)v1; ^ Process.c:435:28: warning: cast from 'const void *' to 'struct Process_ *' drops const qualifier [-Wcast-qual] Process* p2 = (Process*)v2; ^ Process.c:441:36: warning: cast from 'const void *' to 'struct Process_ *' drops const qualifier [-Wcast-qual] Settings *settings = ((Process*)v1)->settings; ^ Process.c:443:22: warning: cast from 'const void *' to 'struct Process_ *' drops const qualifier [-Wcast-qual] p1 = (Process*)v1; ^ Process.c:444:22: warning: cast from 'const void *' to 'struct Process_ *' drops const qualifier [-Wcast-qual] p2 = (Process*)v2; ^ Process.c:446:22: warning: cast from 'const void *' to 'struct Process_ *' drops const qualifier [-Wcast-qual] p2 = (Process*)v1; ^ Process.c:447:22: warning: cast from 'const void *' to 'struct Process_ *' drops const qualifier [-Wcast-qual] p1 = (Process*)v2; ^ AffinityPanel.c:37:16: warning: cast from 'const char *' to 'void *' drops const qualifier [-Wcast-qual] free((void*)this->text); ^ AffinityPanel.c:39:19: warning: cast from 'const char *' to 'void *' drops const qualifier [-Wcast-qual] free((void*)this->indent); ^ linux/LinuxProcess.c:294:36: warning: cast from 'const void *' to 'struct Process_ *' drops const qualifier [-Wcast-qual] Settings *settings = ((Process*)v1)->settings; ^ linux/LinuxProcess.c:296:27: warning: cast from 'const void *' to 'struct LinuxProcess_ *' drops const qualifier [-Wcast-qual] p1 = (LinuxProcess*)v1; ^ linux/LinuxProcess.c:297:27: warning: cast from 'const void *' to 'struct LinuxProcess_ *' drops const qualifier [-Wcast-qual] p2 = (LinuxProcess*)v2; ^ linux/LinuxProcess.c:299:27: warning: cast from 'const void *' to 'struct LinuxProcess_ *' drops const qualifier [-Wcast-qual] p2 = (LinuxProcess*)v1; ^ linux/LinuxProcess.c:300:27: warning: cast from 'const void *' to 'struct LinuxProcess_ *' drops const qualifier [-Wcast-qual] p1 = (LinuxProcess*)v2; ^ linux/LinuxProcessList.c:62:32: warning: cast from 'const void *' to 'struct TtyDriver_ *' drops const qualifier [-Wcast-qual] TtyDriver* a = (TtyDriver*) va; ^ linux/LinuxProcessList.c:63:32: warning: cast from 'const void *' to 'struct TtyDriver_ *' drops const qualifier [-Wcast-qual] TtyDriver* b = (TtyDriver*) vb; ^ linux/Battery.c:130:21: warning: cast from 'const char *' to 'char *' drops const qualifier [-Wcast-qual] free((char *) isOnline); ^ linux/Battery.c:197:26: warning: cast from 'const char *' to 'char *' drops const qualifier [-Wcast-qual] xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); ^ linux/Battery.c:209:29: warning: cast from 'const char *' to 'char *' drops const qualifier [-Wcast-qual] xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); ^ linux/Battery.c:262:29: warning: cast from 'const char *' to 'char *' drops const qualifier [-Wcast-qual] xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); ^ --- Action.c | 4 ++-- AffinityPanel.c | 9 ++++----- DisplayOptionsPanel.c | 6 +++--- ListItem.c | 4 ++-- MetersPanel.c | 2 +- Process.c | 16 ++++++++-------- ScreenManager.c | 2 +- ScreenManager.h | 4 ++-- linux/Battery.c | 12 ++++++------ linux/LinuxProcess.c | 12 ++++++------ linux/LinuxProcessList.c | 4 ++-- 11 files changed, 37 insertions(+), 38 deletions(-) diff --git a/Action.c b/Action.c index f36e0bd2d..622660843 100644 --- a/Action.c +++ b/Action.c @@ -73,9 +73,9 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) // ---------------------------------------- -static void Action_runSetup(Settings* settings, const Header* header, ProcessList* pl) { +static void Action_runSetup(Settings* settings, Header* header, ProcessList* pl) { ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true); - CategoriesPanel* panelCategories = CategoriesPanel_new(scr, settings, (Header*) header, pl); + CategoriesPanel* panelCategories = CategoriesPanel_new(scr, settings, header, pl); ScreenManager_add(scr, (Panel*) panelCategories, 16); CategoriesPanel_makeMetersPage(panelCategories); Panel* panelFocus; diff --git a/AffinityPanel.c b/AffinityPanel.c index 57e889aa5..1cae4ee49 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -19,8 +19,8 @@ in the source distribution for its full text. typedef struct MaskItem_ { Object super; - const char* text; - const char* indent; /* used also as an condition whether this is a tree node */ + char* text; + char* indent; /* used also as an condition whether this is a tree node */ int value; /* tri-state: 0 - off, 1 - some set, 2 - all set */ int sub_tree; /* tri-state: 0 - no sub-tree, 1 - open sub-tree, 2 - closed sub-tree */ Vector *children; @@ -34,9 +34,8 @@ typedef struct MaskItem_ { static void MaskItem_delete(Object* cast) { MaskItem* this = (MaskItem*) cast; - free((void*)this->text); - if (this->indent) - free((void*)this->indent); + free(this->text); + free(this->indent); Vector_delete(this->children); #ifdef HAVE_LIBHWLOC if (this->ownCpuset) diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 6978e2386..37b5bcd09 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -43,9 +43,9 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { if (result == HANDLED) { this->settings->changed = true; - const Header* header = this->scr->header; - Header_calculateHeight((Header*) header); - Header_reinit((Header*) header); + Header* header = this->scr->header; + Header_calculateHeight(header); + Header_reinit(header); Header_draw(header); ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); } diff --git a/ListItem.c b/ListItem.c index 73129fa93..8d26d7f01 100644 --- a/ListItem.c +++ b/ListItem.c @@ -70,7 +70,7 @@ const char* ListItem_getRef(ListItem* this) { } long ListItem_compare(const void* cast1, const void* cast2) { - ListItem* obj1 = (ListItem*) cast1; - ListItem* obj2 = (ListItem*) cast2; + const ListItem* obj1 = (const ListItem*) cast1; + const ListItem* obj2 = (const ListItem*) cast2; return strcmp(obj1->value, obj2->value); } diff --git a/MetersPanel.c b/MetersPanel.c index 1e0afcdc0..c82ba48bc 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -177,7 +177,7 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { } } if (result == HANDLED || sideMove) { - Header* header = (Header*) this->scr->header; + Header* header = this->scr->header; this->settings->changed = true; Header_calculateHeight(header); Header_draw(header); diff --git a/Process.c b/Process.c index 839db8d77..3c404db32 100644 --- a/Process.c +++ b/Process.c @@ -431,20 +431,20 @@ bool Process_sendSignal(Process* this, Arg sgn) { } long Process_pidCompare(const void* v1, const void* v2) { - Process* p1 = (Process*)v1; - Process* p2 = (Process*)v2; + const Process* p1 = (const Process*)v1; + const Process* p2 = (const Process*)v2; return (p1->pid - p2->pid); } long Process_compare(const void* v1, const void* v2) { - Process *p1, *p2; - Settings *settings = ((Process*)v1)->settings; + const Process *p1, *p2; + const Settings *settings = ((const Process*)v1)->settings; if (settings->direction == 1) { - p1 = (Process*)v1; - p2 = (Process*)v2; + p1 = (const Process*)v1; + p2 = (const Process*)v2; } else { - p2 = (Process*)v1; - p1 = (Process*)v2; + p2 = (const Process*)v1; + p1 = (const Process*)v2; } switch (settings->sortKey) { case PERCENT_CPU: diff --git a/ScreenManager.c b/ScreenManager.c index 92e792b46..2a2cb1d09 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -17,7 +17,7 @@ in the source distribution for its full text. #include -ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner) { +ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, bool owner) { ScreenManager* this; this = xMalloc(sizeof(ScreenManager)); this->x1 = x1; diff --git a/ScreenManager.h b/ScreenManager.h index 3c19a05d1..6f19ab8fc 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -25,13 +25,13 @@ typedef struct ScreenManager_ { Orientation orientation; Vector* panels; int panelCount; - const Header* header; + Header* header; const Settings* settings; bool owner; bool allowFocusChange; } ScreenManager; -ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner); +ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, bool owner); void ScreenManager_delete(ScreenManager* this); diff --git a/linux/Battery.c b/linux/Battery.c index 6ea48c459..a0a0e58ef 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -120,7 +120,7 @@ static ACPresence procAcpiCheck(void) { fclose(file); if (!line) continue; - const char *isOnline = String_getToken(line, 2); + char *isOnline = String_getToken(line, 2); free(line); if (strcmp(isOnline, "on-line") == 0) { @@ -128,7 +128,7 @@ static ACPresence procAcpiCheck(void) { } else { isOn = AC_ABSENT; } - free((char *) isOnline); + free(isOnline); if (isOn == AC_PRESENT) { break; } @@ -193,9 +193,9 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { if (!dirEntry) break; char* entryName = (char *) dirEntry->d_name; - const char filePath[256]; + char filePath[256]; - xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); + xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); int fd1 = open(filePath, O_RDONLY); if (fd1 == -1) continue; @@ -207,7 +207,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { continue; if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') { - xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); + xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); int fd2 = open(filePath, O_RDONLY); if (fd2 == -1) { closedir(dir); @@ -260,7 +260,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { continue; } - xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); + xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); int fd3 = open(filePath, O_RDONLY); if (fd3 == -1) { closedir(dir); diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index a589d62ea..41404de18 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -297,14 +297,14 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) } long LinuxProcess_compare(const void* v1, const void* v2) { - LinuxProcess *p1, *p2; - Settings *settings = ((Process*)v1)->settings; + const LinuxProcess *p1, *p2; + const Settings *settings = ((const Process*)v1)->settings; if (settings->direction == 1) { - p1 = (LinuxProcess*)v1; - p2 = (LinuxProcess*)v2; + p1 = (const LinuxProcess*)v1; + p2 = (const LinuxProcess*)v2; } else { - p2 = (LinuxProcess*)v1; - p1 = (LinuxProcess*)v2; + p2 = (const LinuxProcess*)v1; + p1 = (const LinuxProcess*)v2; } long long diff; switch ((int)settings->sortKey) { diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 807cc8a66..76f2a423a 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -59,8 +59,8 @@ static ssize_t xread(int fd, void *buf, size_t count) { } static int sortTtyDrivers(const void* va, const void* vb) { - TtyDriver* a = (TtyDriver*) va; - TtyDriver* b = (TtyDriver*) vb; + const TtyDriver* a = (const TtyDriver*) va; + const TtyDriver* b = (const TtyDriver*) vb; return (a->major == b->major) ? ((int)a->minorFrom - (int)b->minorFrom) : ((int)a->major - (int)b->major); } From dfa40ad0ebdb40a859ea16a264e775ce766bb037 Mon Sep 17 00:00:00 2001 From: multi Date: Thu, 24 Sep 2020 19:13:25 +0100 Subject: [PATCH 231/411] Linux: consider the ZFS ARC to be cache. This commit is based on a patch originally by @edef1c. The ZFS ARC is a cache (it's in the name), which will be evicted by the kernel if memory pressure so requires. Hence, the ARC should not be counted towards a system's total used memory, and should instead be grouped with the other caches in the system. Signed-off-by: edef --- linux/Platform.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/linux/Platform.c b/linux/Platform.c index 0545fc461..4550097aa 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -202,6 +202,8 @@ double Platform_setCPUValues(Meter* this, int cpu) { void Platform_setMemoryValues(Meter* this) { ProcessList* pl = (ProcessList*) this->pl; + LinuxProcessList* lpl = (LinuxProcessList*) this->pl; + long int usedMem = pl->usedMem; long int buffersMem = pl->buffersMem; long int cachedMem = pl->cachedMem; @@ -210,6 +212,11 @@ void Platform_setMemoryValues(Meter* this) { this->values[0] = usedMem; this->values[1] = buffersMem; this->values[2] = cachedMem; + + if (lpl->zfs.enabled != 0) { + this->values[0] -= lpl->zfs.size; + this->values[2] += lpl->zfs.size; + } } void Platform_setSwapValues(Meter* this) { From 4e282eb845c68d70093dda2c078604d52e8fee87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 25 Sep 2020 14:03:55 +0200 Subject: [PATCH 232/411] Add -Wmissing-prototypes compiler warning --- configure.ac | 1 + darwin/Battery.c | 3 +-- darwin/Battery.h | 2 ++ dragonflybsd/Battery.c | 3 ++- dragonflybsd/Battery.h | 2 ++ freebsd/Battery.c | 3 ++- freebsd/Battery.h | 2 ++ openbsd/Battery.c | 3 ++- openbsd/Battery.h | 2 ++ solaris/Battery.c | 4 ++-- solaris/Battery.h | 2 ++ unsupported/Battery.c | 4 ++-- unsupported/Battery.h | 2 ++ 13 files changed, 24 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index be1075f93..a220155f9 100644 --- a/configure.ac +++ b/configure.ac @@ -273,6 +273,7 @@ AM_CFLAGS="\ -Wfloat-equal\ -Wmissing-format-attribute\ -Wmissing-noreturn\ + -Wmissing-prototypes\ -Wpointer-arith\ -Wshadow\ -Wstrict-prototypes\ diff --git a/darwin/Battery.c b/darwin/Battery.c index 51d49c6d2..772f38864 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -1,5 +1,4 @@ - -#include "BatteryMeter.h" +#include "Battery.h" #include diff --git a/darwin/Battery.h b/darwin/Battery.h index 21a1579ac..74a27fc58 100644 --- a/darwin/Battery.h +++ b/darwin/Battery.h @@ -1,6 +1,8 @@ #ifndef HEADER_Battery #define HEADER_Battery +#include "BatteryMeter.h" + void Battery_getData(double* level, ACPresence* isOnAC); #endif diff --git a/dragonflybsd/Battery.c b/dragonflybsd/Battery.c index 589604290..bb1a575ad 100644 --- a/dragonflybsd/Battery.c +++ b/dragonflybsd/Battery.c @@ -6,7 +6,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "BatteryMeter.h" +#include "Battery.h" + #include #include diff --git a/dragonflybsd/Battery.h b/dragonflybsd/Battery.h index f764a2dc8..2e42351b1 100644 --- a/dragonflybsd/Battery.h +++ b/dragonflybsd/Battery.h @@ -8,6 +8,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "BatteryMeter.h" + void Battery_getData(double* level, ACPresence* isOnAC); #endif diff --git a/freebsd/Battery.c b/freebsd/Battery.c index 009f7abe0..2dd4609f8 100644 --- a/freebsd/Battery.c +++ b/freebsd/Battery.c @@ -5,7 +5,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "BatteryMeter.h" +#include "Battery.h" + #include #include diff --git a/freebsd/Battery.h b/freebsd/Battery.h index 6987d78bc..d9294556f 100644 --- a/freebsd/Battery.h +++ b/freebsd/Battery.h @@ -7,6 +7,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "BatteryMeter.h" + void Battery_getData(double* level, ACPresence* isOnAC); #endif diff --git a/openbsd/Battery.c b/openbsd/Battery.c index 66e4b631b..612330304 100644 --- a/openbsd/Battery.c +++ b/openbsd/Battery.c @@ -6,7 +6,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "BatteryMeter.h" +#include "Battery.h" + #include #include #include diff --git a/openbsd/Battery.h b/openbsd/Battery.h index e858b15d2..bf80f3f68 100644 --- a/openbsd/Battery.h +++ b/openbsd/Battery.h @@ -8,6 +8,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "BatteryMeter.h" + void Battery_getData(double* level, ACPresence* isOnAC); #endif diff --git a/solaris/Battery.c b/solaris/Battery.c index 121d2e490..c824df249 100644 --- a/solaris/Battery.c +++ b/solaris/Battery.c @@ -1,6 +1,6 @@ -#include +#include "Battery.h" -#include "BatteryMeter.h" +#include void Battery_getData(double* level, ACPresence* isOnAC) { *level = NAN; diff --git a/solaris/Battery.h b/solaris/Battery.h index 21a1579ac..74a27fc58 100644 --- a/solaris/Battery.h +++ b/solaris/Battery.h @@ -1,6 +1,8 @@ #ifndef HEADER_Battery #define HEADER_Battery +#include "BatteryMeter.h" + void Battery_getData(double* level, ACPresence* isOnAC); #endif diff --git a/unsupported/Battery.c b/unsupported/Battery.c index 121d2e490..c824df249 100644 --- a/unsupported/Battery.c +++ b/unsupported/Battery.c @@ -1,6 +1,6 @@ -#include +#include "Battery.h" -#include "BatteryMeter.h" +#include void Battery_getData(double* level, ACPresence* isOnAC) { *level = NAN; diff --git a/unsupported/Battery.h b/unsupported/Battery.h index 21a1579ac..74a27fc58 100644 --- a/unsupported/Battery.h +++ b/unsupported/Battery.h @@ -1,6 +1,8 @@ #ifndef HEADER_Battery #define HEADER_Battery +#include "BatteryMeter.h" + void Battery_getData(double* level, ACPresence* isOnAC); #endif From d22f6573f3765bd8b47b8d544bbbe99007b66b9d Mon Sep 17 00:00:00 2001 From: multi Date: Thu, 24 Sep 2020 20:17:51 +0100 Subject: [PATCH 233/411] CPUMeter: refactor common CPU meter rendering code. Instead of scanning the meter name to determine the number of columns in a CPU meter, move the common code behind some wrapper functions, and specify the number of columns as an explicit parameter when called from the wrappers. While this does add a bit of code for all the necessary wrapper functions, this should be less brittle in case of future changes to the CPU meter code. --- CPUMeter.c | 134 +++++++++++++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 65 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 482565ee1..ccb924a3a 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -130,16 +130,7 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) { } } -static int MapClassnameToColumncount(Meter* this){ - if (strchr(Meter_name(this), '4')) - return 4; - else if (strchr(Meter_name(this), '2')) - return 2; - else - return 1; -} - -static void AllCPUsMeter_init(Meter* this) { +static void CPUMeterCommonInit(Meter *this, int ncol) { int cpus = this->pl->cpuCount; if (!this->drawData) this->drawData = xCalloc(cpus, sizeof(Meter*)); @@ -154,19 +145,10 @@ static void AllCPUsMeter_init(Meter* this) { if (this->mode == 0) this->mode = BAR_METERMODE; int h = Meter_modes[this->mode]->h; - int ncol = MapClassnameToColumncount(this); this->h = h * ((count + ncol - 1)/ ncol); } -static void AllCPUsMeter_done(Meter* this) { - Meter** meters = (Meter**) this->drawData; - int start, count; - AllCPUsMeter_getRange(this, &start, &count); - for (int i = 0; i < count; i++) - Meter_delete((Object*)meters[i]); -} - -static void AllCPUsMeter_updateMode(Meter* this, int mode) { +static void CPUMeterCommonUpdateMode(Meter* this, int mode, int ncol) { Meter** meters = (Meter**) this->drawData; this->mode = mode; int h = Meter_modes[mode]->h; @@ -175,43 +157,45 @@ static void AllCPUsMeter_updateMode(Meter* this, int mode) { for (int i = 0; i < count; i++) { Meter_setMode(meters[i], mode); } - int ncol = MapClassnameToColumncount(this); this->h = h * ((count + ncol - 1)/ ncol); } -static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) { +static void AllCPUsMeter_done(Meter* this) { Meter** meters = (Meter**) this->drawData; int start, count; - int pad = this->pl->settings->headerMargin ? 2 : 0; AllCPUsMeter_getRange(this, &start, &count); - int height = (count+1)/2; - int startY = y; - for (int i = 0; i < height; i++) { - meters[i]->draw(meters[i], x, y, (w-pad)/2); - y += meters[i]->h; - } - y = startY; - for (int i = height; i < count; i++) { - meters[i]->draw(meters[i], x+(w-1)/2+1+(pad/2), y, (w-pad)/2); - y += meters[i]->h; - } + for (int i = 0; i < count; i++) + Meter_delete((Object*)meters[i]); } -static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) { - Meter** meters = (Meter**) this->drawData; - int start, count; - AllCPUsMeter_getRange(this, &start, &count); - for (int i = 0; i < count; i++) { - meters[i]->draw(meters[i], x, y, w); - y += meters[i]->h; - } +static void SingleColCPUsMeter_init(Meter* this) { + CPUMeterCommonInit(this, 1); } -static void MultiColCPUsMeter_draw(Meter* this, int x, int y, int w){ +static void SingleColCPUsMeter_updateMode(Meter* this, int mode) { + CPUMeterCommonUpdateMode(this, mode, 1); +} + +static void DualColCPUsMeter_init(Meter* this) { + CPUMeterCommonInit(this, 2); +} + +static void DualColCPUsMeter_updateMode(Meter* this, int mode) { + CPUMeterCommonUpdateMode(this, mode, 2); +} + +static void QuadColCPUsMeter_init(Meter* this) { + CPUMeterCommonInit(this, 4); +} + +static void QuadColCPUsMeter_updateMode(Meter* this, int mode) { + CPUMeterCommonUpdateMode(this, mode, 4); +} + +static void CPUMeterCommonDraw(Meter* this, int x, int y, int w, int ncol) { Meter** meters = (Meter**) this->drawData; int start, count; AllCPUsMeter_getRange(this, &start, &count); - int ncol = MapClassnameToColumncount(this); int colwidth = (w-ncol)/ncol + 1; int diff = (w - (colwidth * ncol)); int nrows = (count + ncol - 1) / ncol; @@ -223,6 +207,26 @@ static void MultiColCPUsMeter_draw(Meter* this, int x, int y, int w){ } } +static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) { + CPUMeterCommonDraw(this, x, y, w, 2); +} + +static void QuadColCPUsMeter_draw(Meter* this, int x, int y, int w) { + CPUMeterCommonDraw(this, x, y, w, 4); +} + + +static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) { + Meter** meters = (Meter**) this->drawData; + int start, count; + AllCPUsMeter_getRange(this, &start, &count); + for (int i = 0; i < count; i++) { + meters[i]->draw(meters[i], x, y, w); + y += meters[i]->h; + } +} + + MeterClass CPUMeter_class = { .super = { .extends = Class(Meter), @@ -254,8 +258,8 @@ MeterClass AllCPUsMeter_class = { .description = "CPUs (1/1): all CPUs", .caption = "CPU", .draw = SingleColCPUsMeter_draw, - .init = AllCPUsMeter_init, - .updateMode = AllCPUsMeter_updateMode, + .init = SingleColCPUsMeter_init, + .updateMode = SingleColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; @@ -273,8 +277,8 @@ MeterClass AllCPUs2Meter_class = { .description = "CPUs (1&2/2): all CPUs in 2 shorter columns", .caption = "CPU", .draw = DualColCPUsMeter_draw, - .init = AllCPUsMeter_init, - .updateMode = AllCPUsMeter_updateMode, + .init = DualColCPUsMeter_init, + .updateMode = DualColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; @@ -292,8 +296,8 @@ MeterClass LeftCPUsMeter_class = { .description = "CPUs (1/2): first half of list", .caption = "CPU", .draw = SingleColCPUsMeter_draw, - .init = AllCPUsMeter_init, - .updateMode = AllCPUsMeter_updateMode, + .init = SingleColCPUsMeter_init, + .updateMode = SingleColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; @@ -311,8 +315,8 @@ MeterClass RightCPUsMeter_class = { .description = "CPUs (2/2): second half of list", .caption = "CPU", .draw = SingleColCPUsMeter_draw, - .init = AllCPUsMeter_init, - .updateMode = AllCPUsMeter_updateMode, + .init = SingleColCPUsMeter_init, + .updateMode = SingleColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; @@ -330,8 +334,8 @@ MeterClass LeftCPUs2Meter_class = { .description = "CPUs (1&2/4): first half in 2 shorter columns", .caption = "CPU", .draw = DualColCPUsMeter_draw, - .init = AllCPUsMeter_init, - .updateMode = AllCPUsMeter_updateMode, + .init = DualColCPUsMeter_init, + .updateMode = DualColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; @@ -349,8 +353,8 @@ MeterClass RightCPUs2Meter_class = { .description = "CPUs (3&4/4): second half in 2 shorter columns", .caption = "CPU", .draw = DualColCPUsMeter_draw, - .init = AllCPUsMeter_init, - .updateMode = AllCPUsMeter_updateMode, + .init = DualColCPUsMeter_init, + .updateMode = DualColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; @@ -367,9 +371,9 @@ MeterClass AllCPUs4Meter_class = { .uiName = "CPUs (1&2&3&4/4)", .description = "CPUs (1&2&3&4/4): all CPUs in 4 shorter columns", .caption = "CPU", - .draw = MultiColCPUsMeter_draw, - .init = AllCPUsMeter_init, - .updateMode = AllCPUsMeter_updateMode, + .draw = QuadColCPUsMeter_draw, + .init = QuadColCPUsMeter_init, + .updateMode = QuadColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; @@ -386,9 +390,9 @@ MeterClass LeftCPUs4Meter_class = { .uiName = "CPUs (1-4/8)", .description = "CPUs (1-4/8): first half in 4 shorter columns", .caption = "CPU", - .draw = MultiColCPUsMeter_draw, - .init = AllCPUsMeter_init, - .updateMode = AllCPUsMeter_updateMode, + .draw = QuadColCPUsMeter_draw, + .init = QuadColCPUsMeter_init, + .updateMode = QuadColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; @@ -405,8 +409,8 @@ MeterClass RightCPUs4Meter_class = { .uiName = "CPUs (5-8/8)", .description = "CPUs (5-8/8): second half in 4 shorter columns", .caption = "CPU", - .draw = MultiColCPUsMeter_draw, - .init = AllCPUsMeter_init, - .updateMode = AllCPUsMeter_updateMode, + .draw = QuadColCPUsMeter_draw, + .init = QuadColCPUsMeter_init, + .updateMode = QuadColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; From 491bf98b901d7f4fd96bf5d077c53b136a48af96 Mon Sep 17 00:00:00 2001 From: multi Date: Thu, 24 Sep 2020 20:50:29 +0100 Subject: [PATCH 234/411] Add missing 4-column CPU meters to non-Linux platforms. --- darwin/Platform.c | 3 +++ dragonflybsd/Platform.c | 3 +++ freebsd/Platform.c | 3 +++ openbsd/Platform.c | 3 +++ solaris/Platform.c | 3 +++ unsupported/Platform.c | 3 +++ 6 files changed, 18 insertions(+) diff --git a/darwin/Platform.c b/darwin/Platform.c index 129b1cb9d..d1401cb60 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -105,10 +105,13 @@ MeterClass* Platform_meterTypes[] = { &UptimeMeter_class, &AllCPUsMeter_class, &AllCPUs2Meter_class, + &AllCPUs4Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, &BlankMeter_class, diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index e4e78e384..da7464738 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -88,10 +88,13 @@ MeterClass* Platform_meterTypes[] = { &HostnameMeter_class, &AllCPUsMeter_class, &AllCPUs2Meter_class, + &AllCPUs4Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, &BlankMeter_class, NULL }; diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 3fc5de31d..e0bce04ea 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -89,10 +89,13 @@ MeterClass* Platform_meterTypes[] = { &HostnameMeter_class, &AllCPUsMeter_class, &AllCPUs2Meter_class, + &AllCPUs4Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, &BlankMeter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, diff --git a/openbsd/Platform.c b/openbsd/Platform.c index bd5ef7efb..4fda8e0e3 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -101,10 +101,13 @@ MeterClass* Platform_meterTypes[] = { &HostnameMeter_class, &AllCPUsMeter_class, &AllCPUs2Meter_class, + &AllCPUs4Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, &BlankMeter_class, NULL }; diff --git a/solaris/Platform.c b/solaris/Platform.c index d3ad1f932..dcdf0bbcf 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -98,10 +98,13 @@ MeterClass* Platform_meterTypes[] = { &UptimeMeter_class, &AllCPUsMeter_class, &AllCPUs2Meter_class, + &AllCPUs4Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, &BlankMeter_class, diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 20df33769..5c22b573a 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -69,10 +69,13 @@ MeterClass* Platform_meterTypes[] = { &UptimeMeter_class, &AllCPUsMeter_class, &AllCPUs2Meter_class, + &AllCPUs4Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, &BlankMeter_class, NULL }; From 9ee72568dc36e2c83add9c602387509909f3d292 Mon Sep 17 00:00:00 2001 From: multi Date: Thu, 24 Sep 2020 20:56:40 +0100 Subject: [PATCH 235/411] CPUMeter: add octuple-column CPU meters. This is a straightforward extension of the existing multi-column CPU meter code, which now allows for up CPU meters to be displayed in up to 16 columns. This also adds the meter declarations to all the platform-specific code. --- CPUMeter.c | 69 +++++++++++++++++++++++++++++++++++++++++ CPUMeter.h | 6 ++++ darwin/Platform.c | 3 ++ dragonflybsd/Platform.c | 3 ++ freebsd/Platform.c | 3 ++ linux/Platform.c | 3 ++ openbsd/Platform.c | 3 ++ solaris/Platform.c | 3 ++ unsupported/Platform.c | 3 ++ 9 files changed, 96 insertions(+) diff --git a/CPUMeter.c b/CPUMeter.c index ccb924a3a..c5e271243 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -192,6 +192,14 @@ static void QuadColCPUsMeter_updateMode(Meter* this, int mode) { CPUMeterCommonUpdateMode(this, mode, 4); } +static void OctoColCPUsMeter_init(Meter* this) { + CPUMeterCommonInit(this, 8); +} + +static void OctoColCPUsMeter_updateMode(Meter* this, int mode) { + CPUMeterCommonUpdateMode(this, mode, 8); +} + static void CPUMeterCommonDraw(Meter* this, int x, int y, int w, int ncol) { Meter** meters = (Meter**) this->drawData; int start, count; @@ -215,6 +223,10 @@ static void QuadColCPUsMeter_draw(Meter* this, int x, int y, int w) { CPUMeterCommonDraw(this, x, y, w, 4); } +static void OctoColCPUsMeter_draw(Meter* this, int x, int y, int w) { + CPUMeterCommonDraw(this, x, y, w, 8); +} + static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) { Meter** meters = (Meter**) this->drawData; @@ -414,3 +426,60 @@ MeterClass RightCPUs4Meter_class = { .updateMode = QuadColCPUsMeter_updateMode, .done = AllCPUsMeter_done }; + +MeterClass AllCPUs8Meter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = CPUMeter_display + }, + .defaultMode = CUSTOM_METERMODE, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "AllCPUs8", + .uiName = "CPUs (1-8/8)", + .description = "CPUs (1-8/8): all CPUs in 8 shorter columns", + .caption = "CPU", + .draw = OctoColCPUsMeter_draw, + .init = OctoColCPUsMeter_init, + .updateMode = OctoColCPUsMeter_updateMode, + .done = AllCPUsMeter_done +}; + +MeterClass LeftCPUs8Meter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = CPUMeter_display + }, + .defaultMode = CUSTOM_METERMODE, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "LeftCPUs8", + .uiName = "CPUs (1-8/16)", + .description = "CPUs (1-8/16): first half in 8 shorter columns", + .caption = "CPU", + .draw = OctoColCPUsMeter_draw, + .init = OctoColCPUsMeter_init, + .updateMode = OctoColCPUsMeter_updateMode, + .done = AllCPUsMeter_done +}; + +MeterClass RightCPUs8Meter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = CPUMeter_display + }, + .defaultMode = CUSTOM_METERMODE, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "RightCPUs8", + .uiName = "CPUs (9-16/16)", + .description = "CPUs (9-16/16): second half in 8 shorter columns", + .caption = "CPU", + .draw = OctoColCPUsMeter_draw, + .init = OctoColCPUsMeter_init, + .updateMode = OctoColCPUsMeter_updateMode, + .done = AllCPUsMeter_done +}; diff --git a/CPUMeter.h b/CPUMeter.h index d66eefbb8..62a1ddc39 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -44,4 +44,10 @@ extern MeterClass LeftCPUs4Meter_class; extern MeterClass RightCPUs4Meter_class; +extern MeterClass AllCPUs8Meter_class; + +extern MeterClass LeftCPUs8Meter_class; + +extern MeterClass RightCPUs8Meter_class; + #endif diff --git a/darwin/Platform.c b/darwin/Platform.c index d1401cb60..747ffefb7 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -106,12 +106,15 @@ MeterClass* Platform_meterTypes[] = { &AllCPUsMeter_class, &AllCPUs2Meter_class, &AllCPUs4Meter_class, + &AllCPUs8Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &LeftCPUs4Meter_class, &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, &BlankMeter_class, diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index da7464738..7d16eda15 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -89,12 +89,15 @@ MeterClass* Platform_meterTypes[] = { &AllCPUsMeter_class, &AllCPUs2Meter_class, &AllCPUs4Meter_class, + &AllCPUs8Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &LeftCPUs4Meter_class, &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, &BlankMeter_class, NULL }; diff --git a/freebsd/Platform.c b/freebsd/Platform.c index e0bce04ea..318b3e122 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -90,12 +90,15 @@ MeterClass* Platform_meterTypes[] = { &AllCPUsMeter_class, &AllCPUs2Meter_class, &AllCPUs4Meter_class, + &AllCPUs8Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &LeftCPUs4Meter_class, &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, &BlankMeter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, diff --git a/linux/Platform.c b/linux/Platform.c index c579adeb3..58bc3bea7 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -114,12 +114,15 @@ MeterClass* Platform_meterTypes[] = { &AllCPUsMeter_class, &AllCPUs2Meter_class, &AllCPUs4Meter_class, + &AllCPUs8Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &LeftCPUs4Meter_class, &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, &BlankMeter_class, &PressureStallCPUSomeMeter_class, &PressureStallIOSomeMeter_class, diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 4fda8e0e3..2c8bc7aeb 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -102,12 +102,15 @@ MeterClass* Platform_meterTypes[] = { &AllCPUsMeter_class, &AllCPUs2Meter_class, &AllCPUs4Meter_class, + &AllCPUs8Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &LeftCPUs4Meter_class, &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, &BlankMeter_class, NULL }; diff --git a/solaris/Platform.c b/solaris/Platform.c index dcdf0bbcf..05b444628 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -99,12 +99,15 @@ MeterClass* Platform_meterTypes[] = { &AllCPUsMeter_class, &AllCPUs2Meter_class, &AllCPUs4Meter_class, + &AllCPUs8Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &LeftCPUs4Meter_class, &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, &BlankMeter_class, diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 5c22b573a..b095e1264 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -70,12 +70,15 @@ MeterClass* Platform_meterTypes[] = { &AllCPUsMeter_class, &AllCPUs2Meter_class, &AllCPUs4Meter_class, + &AllCPUs8Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &LeftCPUs4Meter_class, &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, &BlankMeter_class, NULL }; From 214c742ae176078c3b081e1598b3fbf0cc122f77 Mon Sep 17 00:00:00 2001 From: ryenus Date: Sat, 26 Sep 2020 05:22:24 +0800 Subject: [PATCH 236/411] command screen: fill current line when scanning --- CommandScreen.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CommandScreen.c b/CommandScreen.c index 0e261175a..d8e709c49 100644 --- a/CommandScreen.c +++ b/CommandScreen.c @@ -12,33 +12,33 @@ #include -static void CommandScreen_addLine(InfoScreen* this, char* line, const char* p, int line_offset, int len) { - memcpy(line, p - line_offset, len); - line[len] = '\0'; - InfoScreen_addLine(this, line); -} - static void CommandScreen_scan(InfoScreen* this) { Panel* panel = this->display; int idx = MAXIMUM(Panel_getSelectedIndex(panel), 0); - Panel_prune(panel); const char* p = this->process->comm; char* line = xMalloc(COLS + 1); int line_offset = 0, last_spc = -1, len; for (; *p != '\0'; p++, line_offset++) { + line[line_offset] = *p; if (*p == ' ') last_spc = line_offset; if (line_offset == COLS) { len = (last_spc == -1) ? line_offset : last_spc; - CommandScreen_addLine(this, line, p, line_offset, len); + line[len] = '\0'; + InfoScreen_addLine(this, line); + line_offset -= len; last_spc = -1; + memcpy(line, p - line_offset, line_offset + 1); } } - if (line_offset > 0) CommandScreen_addLine(this, line, p, line_offset, line_offset); + if (line_offset > 0) { + line[line_offset] = '\0'; + InfoScreen_addLine(this, line); + } free(line); Panel_setSelected(panel, idx); From 843949131aa75312086bea6a50408e09d82f5209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 28 Sep 2020 12:17:52 +0200 Subject: [PATCH 237/411] Drop redundant casts to the same type --- Action.c | 2 +- AvailableMetersPanel.c | 2 +- InfoScreen.c | 2 +- Meter.c | 2 +- StringUtils.c | 2 +- Vector.c | 2 +- linux/Battery.c | 8 ++++---- linux/LinuxProcess.c | 2 +- linux/LinuxProcessList.c | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Action.c b/Action.c index 622660843..233f13247 100644 --- a/Action.c +++ b/Action.c @@ -305,7 +305,7 @@ static Htop_Reaction actionSetAffinity(State* st) { } static Htop_Reaction actionKill(State* st) { - Panel* signalsPanel = (Panel*) SignalsPanel_new(); + Panel* signalsPanel = SignalsPanel_new(); ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true); if (sgn) { if (sgn->key != 0) { diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index 0533cfbfe..3538cd13d 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -25,7 +25,7 @@ static void AvailableMetersPanel_delete(Object* object) { } static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, MeterClass* type, int param, int column) { - Meter* meter = (Meter*) Header_addMeterByClass(header, type, param, column); + Meter* meter = Header_addMeterByClass(header, type, param, column); Panel_add(panel, (Object*) Meter_toListItem(meter, false)); Panel_setSelected(panel, Panel_size(panel) - 1); MetersPanel_setMoving((MetersPanel*)panel, true); diff --git a/InfoScreen.c b/InfoScreen.c index 8a6a3beeb..b8859af0c 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -57,7 +57,7 @@ void InfoScreen_addLine(InfoScreen* this, const char* line) { Vector_add(this->lines, (Object*) ListItem_new(line, 0)); const char* incFilter = IncSet_filter(this->inc); if (!incFilter || String_contains_i(line, incFilter)) - Panel_add(this->display, (Object*)Vector_get(this->lines, Vector_size(this->lines)-1)); + Panel_add(this->display, Vector_get(this->lines, Vector_size(this->lines)-1)); } void InfoScreen_appendLine(InfoScreen* this, const char* line) { diff --git a/Meter.c b/Meter.c index 5b4ae006c..d144b5b80 100644 --- a/Meter.c +++ b/Meter.c @@ -282,7 +282,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { struct timeval now; gettimeofday(&now, NULL); if (!timercmp(&now, &(data->time), <)) { - struct timeval delay = { .tv_sec = (int)(CRT_delay/10), .tv_usec = (CRT_delay-((int)(CRT_delay/10)*10)) * 100000 }; + struct timeval delay = { .tv_sec = CRT_delay/10, .tv_usec = (CRT_delay-((CRT_delay/10)*10)) * 100000 }; timeradd(&now, &delay, &(data->time)); for (int i = 0; i < nValues - 1; i++) diff --git a/StringUtils.c b/StringUtils.c index e2386e3cd..1e4c03b33 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -112,7 +112,7 @@ char* String_getToken(const char* line, const unsigned short int numMatch) { } match[foundCount] = '\0'; - return((char*)xStrdup(match)); + return xStrdup(match); } char* String_readLine(FILE* fd) { diff --git a/Vector.c b/Vector.c index e51fd7b15..20578851a 100644 --- a/Vector.c +++ b/Vector.c @@ -309,7 +309,7 @@ inline int Vector_indexOf(Vector* this, void* search_, Object_Compare compare) { assert(compare); assert(Vector_isConsistent(this)); for (int i = 0; i < this->items; i++) { - Object* o = (Object*)this->array[i]; + Object* o = this->array[i]; assert(o); if (compare(search, o) == 0) return i; diff --git a/linux/Battery.c b/linux/Battery.c index a0a0e58ef..614126e8d 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -100,11 +100,11 @@ static ACPresence procAcpiCheck(void) { } for (;;) { - struct dirent* dirEntry = readdir((DIR *) dir); + struct dirent* dirEntry = readdir(dir); if (!dirEntry) break; - char* entryName = (char *) dirEntry->d_name; + const char* entryName = dirEntry->d_name; if (entryName[0] != 'A') continue; @@ -189,10 +189,10 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { unsigned long int totalRemain = 0; for (;;) { - struct dirent* dirEntry = readdir((DIR *) dir); + struct dirent* dirEntry = readdir(dir); if (!dirEntry) break; - char* entryName = (char *) dirEntry->d_name; + const char* entryName = dirEntry->d_name; char filePath[256]; xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 41404de18..890c8a0fa 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -290,7 +290,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) xSnprintf(buffer, n, "%5lu ", lp->ctxt_diff); break; default: - Process_writeField((Process*)this, str, field); + Process_writeField(this, str, field); return; } RichString_append(str, attr, buffer); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 76f2a423a..e984735b3 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -232,7 +232,7 @@ static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { jiffy = sc_jiffy; } double jiffytime = 1.0 / jiffy; - return (unsigned long long) t * jiffytime * 100; + return t * jiffytime * 100; } static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, const char* name, char* command, int* commLen) { From 6db2d52261d676a378625a24c307fa718025bc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 28 Sep 2020 12:23:07 +0200 Subject: [PATCH 238/411] Covert Meter attributes to file-local constant arrays --- BatteryMeter.c | 2 +- BatteryMeter.h | 2 -- CPUMeter.c | 11 +++++++++-- CPUMeter.h | 2 -- ClockMeter.c | 2 +- ClockMeter.h | 2 -- HostnameMeter.c | 2 +- HostnameMeter.h | 2 -- LoadAverageMeter.c | 10 +++++++--- LoadAverageMeter.h | 4 ---- MemoryMeter.c | 6 ++++-- MemoryMeter.h | 2 -- Meter.c | 2 +- Meter.h | 2 -- SwapMeter.c | 2 +- SwapMeter.h | 2 -- TasksMeter.c | 7 +++++-- TasksMeter.h | 2 -- UptimeMeter.c | 2 +- UptimeMeter.h | 2 -- 20 files changed, 31 insertions(+), 37 deletions(-) diff --git a/BatteryMeter.c b/BatteryMeter.c index 0ae2834c8..733298a19 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -20,7 +20,7 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). #include -int BatteryMeter_attributes[] = { +static const int BatteryMeter_attributes[] = { BATTERY }; diff --git a/BatteryMeter.h b/BatteryMeter.h index 658cd3f90..b67754d39 100644 --- a/BatteryMeter.h +++ b/BatteryMeter.h @@ -17,8 +17,6 @@ typedef enum ACPresence_ { AC_ERROR } ACPresence; -extern int BatteryMeter_attributes[]; - extern MeterClass BatteryMeter_class; #endif diff --git a/CPUMeter.c b/CPUMeter.c index c5e271243..44ef1adde 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -16,8 +16,15 @@ in the source distribution for its full text. #include #include -int CPUMeter_attributes[] = { - CPU_NICE, CPU_NORMAL, CPU_SYSTEM, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT +static const int CPUMeter_attributes[] = { + CPU_NICE, + CPU_NORMAL, + CPU_SYSTEM, + CPU_IRQ, + CPU_SOFTIRQ, + CPU_STEAL, + CPU_GUEST, + CPU_IOWAIT }; static void CPUMeter_init(Meter* this) { diff --git a/CPUMeter.h b/CPUMeter.h index 62a1ddc39..6244c42a4 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -22,8 +22,6 @@ typedef enum { CPU_METER_ITEMCOUNT = 9, // number of entries in this enum } CPUMeterValues; -extern int CPUMeter_attributes[]; - extern MeterClass CPUMeter_class; extern MeterClass AllCPUsMeter_class; diff --git a/ClockMeter.c b/ClockMeter.c index 3168b3e9a..6ad191a20 100644 --- a/ClockMeter.c +++ b/ClockMeter.c @@ -12,7 +12,7 @@ in the source distribution for its full text. #include -int ClockMeter_attributes[] = { +static const int ClockMeter_attributes[] = { CLOCK }; diff --git a/ClockMeter.h b/ClockMeter.h index e888d585d..bb6881aea 100644 --- a/ClockMeter.h +++ b/ClockMeter.h @@ -9,8 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern int ClockMeter_attributes[]; - extern MeterClass ClockMeter_class; #endif diff --git a/HostnameMeter.c b/HostnameMeter.c index 60bd81250..edb23358e 100644 --- a/HostnameMeter.c +++ b/HostnameMeter.c @@ -12,7 +12,7 @@ in the source distribution for its full text. #include -int HostnameMeter_attributes[] = { +static const int HostnameMeter_attributes[] = { HOSTNAME }; diff --git a/HostnameMeter.h b/HostnameMeter.h index ecfab1aae..152100d04 100644 --- a/HostnameMeter.h +++ b/HostnameMeter.h @@ -9,8 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern int HostnameMeter_attributes[]; - extern MeterClass HostnameMeter_class; #endif diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index db397b6ca..3f75aeca6 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -11,11 +11,15 @@ in the source distribution for its full text. #include "Platform.h" -int LoadAverageMeter_attributes[] = { - LOAD_AVERAGE_ONE, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_FIFTEEN +static const int LoadAverageMeter_attributes[] = { + LOAD_AVERAGE_ONE, + LOAD_AVERAGE_FIVE, + LOAD_AVERAGE_FIFTEEN }; -int LoadMeter_attributes[] = { LOAD }; +static const int LoadMeter_attributes[] = { + LOAD +}; static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) { Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]); diff --git a/LoadAverageMeter.h b/LoadAverageMeter.h index 83d3c8f58..5ac771a4a 100644 --- a/LoadAverageMeter.h +++ b/LoadAverageMeter.h @@ -9,10 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern int LoadAverageMeter_attributes[]; - -extern int LoadMeter_attributes[]; - extern MeterClass LoadAverageMeter_class; extern MeterClass LoadMeter_class; diff --git a/MemoryMeter.c b/MemoryMeter.c index 91f75b9c2..cac0da72b 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -17,8 +17,10 @@ in the source distribution for its full text. #include -int MemoryMeter_attributes[] = { - MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE +static const int MemoryMeter_attributes[] = { + MEMORY_USED, + MEMORY_BUFFERS, + MEMORY_CACHE }; static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) { diff --git a/MemoryMeter.h b/MemoryMeter.h index 771aa7359..f8df247d2 100644 --- a/MemoryMeter.h +++ b/MemoryMeter.h @@ -9,8 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern int MemoryMeter_attributes[]; - extern MeterClass MemoryMeter_class; #endif diff --git a/Meter.c b/Meter.c index d144b5b80..c453b4bc6 100644 --- a/Meter.c +++ b/Meter.c @@ -433,7 +433,7 @@ static void BlankMeter_display(Object* cast, RichString* out) { RichString_prune(out); } -int BlankMeter_attributes[] = { +static const int BlankMeter_attributes[] = { DEFAULT_COLOR }; diff --git a/Meter.h b/Meter.h index c4d00396e..03b49608d 100644 --- a/Meter.h +++ b/Meter.h @@ -105,8 +105,6 @@ ListItem* Meter_toListItem(Meter* this, bool moving); extern MeterMode* Meter_modes[]; -extern int BlankMeter_attributes[]; - extern MeterClass BlankMeter_class; #endif diff --git a/SwapMeter.c b/SwapMeter.c index fcf450eed..ae4d40972 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -17,7 +17,7 @@ in the source distribution for its full text. #include -int SwapMeter_attributes[] = { +static const int SwapMeter_attributes[] = { SWAP }; diff --git a/SwapMeter.h b/SwapMeter.h index 69a5855f5..2ba596cb6 100644 --- a/SwapMeter.h +++ b/SwapMeter.h @@ -9,8 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern int SwapMeter_attributes[]; - extern MeterClass SwapMeter_class; #endif diff --git a/TasksMeter.c b/TasksMeter.c index 0b37ab274..45d3ba152 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -11,8 +11,11 @@ in the source distribution for its full text. #include "CRT.h" -int TasksMeter_attributes[] = { - CPU_SYSTEM, PROCESS_THREAD, PROCESS, TASKS_RUNNING +static const int TasksMeter_attributes[] = { + CPU_SYSTEM, + PROCESS_THREAD, + PROCESS, + TASKS_RUNNING }; static void TasksMeter_updateValues(Meter* this, char* buffer, int len) { diff --git a/TasksMeter.h b/TasksMeter.h index bdb62a739..82ddc081e 100644 --- a/TasksMeter.h +++ b/TasksMeter.h @@ -9,8 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern int TasksMeter_attributes[]; - extern MeterClass TasksMeter_class; #endif diff --git a/UptimeMeter.c b/UptimeMeter.c index da1c9fd01..0a9589a03 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -10,7 +10,7 @@ in the source distribution for its full text. #include "CRT.h" -int UptimeMeter_attributes[] = { +static const int UptimeMeter_attributes[] = { UPTIME }; diff --git a/UptimeMeter.h b/UptimeMeter.h index 5fa1e9310..cac51aad7 100644 --- a/UptimeMeter.h +++ b/UptimeMeter.h @@ -9,8 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern int UptimeMeter_attributes[]; - extern MeterClass UptimeMeter_class; #endif From 7ae967a04b7a05ce1f3b77035ba06be904ff6b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 28 Sep 2020 12:28:17 +0200 Subject: [PATCH 239/411] Drop redundant return statements --- BatteryMeter.c | 2 -- linux/LinuxProcessList.c | 1 - 2 files changed, 3 deletions(-) diff --git a/BatteryMeter.c b/BatteryMeter.c index 733298a19..c43bbe5f0 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -56,8 +56,6 @@ static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) { } else { xSnprintf(buffer, len, unknownText, percent); } - - return; } MeterClass BatteryMeter_class = { diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index e984735b3..1e472affd 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -506,7 +506,6 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d "%*32u %*32u %32u %32u", &process->vpid, &process->ctid); fclose(file); - return; } #endif From 241e4b3dbf8ebee4a12a337dec725b3547c242e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 28 Sep 2020 12:32:55 +0200 Subject: [PATCH 240/411] Drop redundant declarations - `CRT_fatalError()` is declared twice in CRT.h - `Process_pidFormat`, `Process_writeField()` and `Process_compare` are declared twice in Process.h - `btime` is defined in LinuxProcess.c and also declared in LinuxProcess.h, so drop in LinuxProcessList.h --- CRT.h | 2 -- Process.h | 6 ------ linux/LinuxProcessList.h | 2 -- 3 files changed, 10 deletions(-) diff --git a/CRT.h b/CRT.h index a2cfd8a9f..c0b939526 100644 --- a/CRT.h +++ b/CRT.h @@ -168,8 +168,6 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode); void CRT_done(void); -void CRT_fatalError(const char* note); - int CRT_readKey(void); void CRT_disableDelay(void); diff --git a/Process.h b/Process.h index aff4374a0..404f73e6c 100644 --- a/Process.h +++ b/Process.h @@ -148,8 +148,6 @@ typedef struct ProcessClass_ { #define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K) #define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K) -extern char Process_pidFormat[20]; - void Process_setupColumnWidths(void); void Process_humanNumber(RichString* str, unsigned long number, bool coloring); @@ -160,8 +158,6 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths); void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring); -void Process_writeField(Process* this, RichString* str, ProcessField field); - void Process_display(Object* cast, RichString* out); void Process_done(Process* this); @@ -180,6 +176,4 @@ bool Process_sendSignal(Process* this, Arg sgn); long Process_pidCompare(const void* v1, const void* v2); -long Process_compare(const void* v1, const void* v2); - #endif diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index c484e75c8..266540208 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -10,8 +10,6 @@ in the source distribution for its full text. #include "ProcessList.h" #include "zfs/ZfsArcStats.h" -extern long long btime; - typedef struct CPUData_ { unsigned long long int totalTime; unsigned long long int userTime; From 8b55113ea8924d6e4ace14a3d54c9d9aca23eaa7 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Fri, 18 Sep 2020 20:38:25 +0200 Subject: [PATCH 241/411] Reimplement xAsnprintf and xSnprintf as type-safe functions --- XAlloc.c | 28 ++++++++++++++++++++++++++++ XAlloc.h | 8 ++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/XAlloc.c b/XAlloc.c index 294eb36ab..c43eca769 100644 --- a/XAlloc.c +++ b/XAlloc.c @@ -5,6 +5,8 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif + +#include #include #include @@ -39,6 +41,32 @@ void* xRealloc(void* ptr, size_t size) { return data; } +int xAsprintf(char** strp, const char* fmt, ...) { + va_list vl; + va_start(vl, fmt); + int _r = vasprintf(strp, fmt, vl); + va_end(vl); + + if (_r < 0) { + fail(); + } + + return _r; +} + +int xSnprintf(char* buf, int len, const char* fmt, ...) { + va_list vl; + va_start(vl, fmt); + int _n=vsnprintf(buf, len, fmt, vl); + va_end(vl); + + if (!(_n > -1 && _n < len)) { + fail(); + } + + return _n; +} + char* xStrdup_(const char* str) { char* data = strdup(str); if (!data) { diff --git a/XAlloc.h b/XAlloc.h index cebe095c2..70dfc59ff 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -19,11 +19,11 @@ void* xCalloc(size_t nmemb, size_t size); void* xRealloc(void* ptr, size_t size); -#undef xAsprintf +ATTR_FORMAT(printf, 2, 3) +int xAsprintf(char **strp, const char* fmt, ...); -#define xAsprintf(strp, fmt, ...) do { int _r=asprintf(strp, fmt, __VA_ARGS__); if (_r < 0) { fail(); } } while(0) - -#define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0) +ATTR_FORMAT(printf, 3, 4) +int xSnprintf(char *buf, int len, const char* fmt, ...); #undef xStrdup #undef xStrdup_ From 736c496dbf15c1a665ba7e0b03d7994117a0b215 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Fri, 18 Sep 2020 20:39:50 +0200 Subject: [PATCH 242/411] Cleanse xStrdup mess --- XAlloc.c | 2 +- XAlloc.h | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/XAlloc.c b/XAlloc.c index c43eca769..20ddafc8b 100644 --- a/XAlloc.c +++ b/XAlloc.c @@ -67,7 +67,7 @@ int xSnprintf(char* buf, int len, const char* fmt, ...) { return _n; } -char* xStrdup_(const char* str) { +char* xStrdup(const char* str) { char* data = strdup(str); if (!data) { fail(); diff --git a/XAlloc.h b/XAlloc.h index 70dfc59ff..32389e571 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -25,14 +25,6 @@ int xAsprintf(char **strp, const char* fmt, ...); ATTR_FORMAT(printf, 3, 4) int xSnprintf(char *buf, int len, const char* fmt, ...); -#undef xStrdup -#undef xStrdup_ -#ifdef NDEBUG -# define xStrdup_ xStrdup -#else -# define xStrdup(str_) (assert(str_), xStrdup_(str_)) -#endif - -char* xStrdup_(const char* str) ATTR_NONNULL; +char* xStrdup(const char* str) ATTR_NONNULL; #endif From dac1e05a2c7ac68993f6d046c43fbef209458206 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Fri, 18 Sep 2020 21:55:09 +0200 Subject: [PATCH 243/411] Fix FreeBSD compile issue This issue was previously hidden as xSnprintf expanded to only one large command that didn't trigger the GCC formatting check. --- freebsd/FreeBSDProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 11cfe7e1f..6e7f6ecb8 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -355,7 +355,7 @@ char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) { if (jid < 0) { if (!jail_errmsg[0]) xSnprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s", strerror(errno)); - return NULL; + return NULL; } else if (jid == kproc->ki_jid) { jname = xStrdup(jnamebuf); if (jname == NULL) From e1c96879f444150b01c7f556cacdca82c811efb1 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Fri, 18 Sep 2020 19:23:04 +0200 Subject: [PATCH 244/411] Sort headers/includes --- Affinity.c | 2 ++ AvailableMetersPanel.h | 4 ++-- CategoriesPanel.h | 4 ++-- ColorsPanel.h | 2 +- DisplayOptionsPanel.h | 2 +- IncSet.h | 3 ++- InfoScreen.h | 4 ++-- Meter.h | 3 ++- MetersPanel.h | 2 +- Panel.h | 2 +- Process.h | 4 ++-- ProcessList.h | 4 ++-- ScreenManager.h | 2 +- Settings.h | 3 ++- XAlloc.h | 2 +- 15 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Affinity.c b/Affinity.c index 098e5c169..d207e5a34 100644 --- a/Affinity.c +++ b/Affinity.c @@ -6,6 +6,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "config.h" + #include "Affinity.h" #include diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index ecebb28de..92d7c941d 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -7,10 +7,10 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "Settings.h" #include "Panel.h" -#include "ScreenManager.h" #include "ProcessList.h" +#include "ScreenManager.h" +#include "Settings.h" typedef struct AvailableMetersPanel_ { Panel super; diff --git a/CategoriesPanel.h b/CategoriesPanel.h index fefc3e931..5f8cb0f50 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -8,9 +8,9 @@ in the source distribution for its full text. */ #include "Panel.h" -#include "Settings.h" -#include "ScreenManager.h" #include "ProcessList.h" +#include "ScreenManager.h" +#include "Settings.h" typedef struct CategoriesPanel_ { Panel super; diff --git a/ColorsPanel.h b/ColorsPanel.h index 479fad084..8dd61711c 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -8,8 +8,8 @@ in the source distribution for its full text. */ #include "Panel.h" -#include "Settings.h" #include "ScreenManager.h" +#include "Settings.h" typedef struct ColorsPanel_ { Panel super; diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index 499b2fc19..b103503b6 100644 --- a/DisplayOptionsPanel.h +++ b/DisplayOptionsPanel.h @@ -8,8 +8,8 @@ in the source distribution for its full text. */ #include "Panel.h" -#include "Settings.h" #include "ScreenManager.h" +#include "Settings.h" typedef struct DisplayOptionsPanel_ { Panel super; diff --git a/IncSet.h b/IncSet.h index 2fb22c498..81f0f54cb 100644 --- a/IncSet.h +++ b/IncSet.h @@ -7,9 +7,10 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include + #include "FunctionBar.h" #include "Panel.h" -#include #define INCMODE_MAX 40 diff --git a/InfoScreen.h b/InfoScreen.h index a5a5abf60..196c56e1b 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -1,10 +1,10 @@ #ifndef HEADER_InfoScreen #define HEADER_InfoScreen -#include "Process.h" -#include "Panel.h" #include "FunctionBar.h" #include "IncSet.h" +#include "Panel.h" +#include "Process.h" typedef struct InfoScreen_ InfoScreen; diff --git a/Meter.h b/Meter.h index 03b49608d..da1dc5dfe 100644 --- a/Meter.h +++ b/Meter.h @@ -7,9 +7,10 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "ListItem.h" #include +#include "ListItem.h" + #define METER_BUFFER_LEN 256 typedef struct Meter_ Meter; diff --git a/MetersPanel.h b/MetersPanel.h index dbc31ee4b..919b117d7 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -8,8 +8,8 @@ in the source distribution for its full text. */ #include "Panel.h" -#include "Settings.h" #include "ScreenManager.h" +#include "Settings.h" typedef struct MetersPanel_ MetersPanel; diff --git a/Panel.h b/Panel.h index 1c7c171df..e5b28a41d 100644 --- a/Panel.h +++ b/Panel.h @@ -7,9 +7,9 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "FunctionBar.h" #include "Object.h" #include "Vector.h" -#include "FunctionBar.h" typedef struct Panel_ Panel; diff --git a/Process.h b/Process.h index 404f73e6c..a2f266f77 100644 --- a/Process.h +++ b/Process.h @@ -20,10 +20,10 @@ in the source distribution for its full text. #endif #define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K ) -#include "Object.h" - #include +#include "Object.h" + #define PROCESS_FLAG_IO 0x0001 typedef enum ProcessFields { diff --git a/ProcessList.h b/ProcessList.h index 7b572d8f1..34f92b1bb 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -7,12 +7,12 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "Vector.h" #include "Hashtable.h" -#include "UsersTable.h" #include "Panel.h" #include "Process.h" #include "Settings.h" +#include "UsersTable.h" +#include "Vector.h" #ifdef HAVE_LIBHWLOC #include diff --git a/ScreenManager.h b/ScreenManager.h index 6f19ab8fc..4c78efd30 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -7,10 +7,10 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "Vector.h" #include "Header.h" #include "Settings.h" #include "Panel.h" +#include "Vector.h" typedef enum Orientation_ { VERTICAL, diff --git a/Settings.h b/Settings.h index e1518ecaf..2f52681c9 100644 --- a/Settings.h +++ b/Settings.h @@ -9,9 +9,10 @@ in the source distribution for its full text. #define DEFAULT_DELAY 15 -#include "Process.h" #include +#include "Process.h" + typedef struct { int len; char** names; diff --git a/XAlloc.h b/XAlloc.h index 32389e571..97c155197 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -7,8 +7,8 @@ #include "Macros.h" -#include #include +#include #include void fail(void) ATTR_NORETURN; From ab3171d21d4034a6524046757a0dc3cef1ae57d1 Mon Sep 17 00:00:00 2001 From: Michael Witten Date: Tue, 29 Sep 2020 14:04:22 +0000 Subject: [PATCH 245/411] Process.{h,c}: Use integer types that are more portable When building on a 32-bit system, the compiler warned that the following line uses a constant whose value is the overflow result of a compile-time computation: Process.c (line 109): } else if (number < 10000 * ONE_M) { Namely, this constant expression: 10000 * ONE_M was intended to produce the following value: 10485760000 However, the result overflowed to produce: 1895825408 The reason for this overflow is as follows: o The macros are expanded: 10000 * (ONE_K * ONE_K) 10000 * (1024L * 1024L) o The untyped constant expression "10000" is typed: 10000U * (1024L * 1024L) o The parenthesized expression is evaluated: 10000U * (1048576L) o The left operand ("10000U") is converted: 10000L * (1048576L) Unbound by integer sizes, that last multiplication would produce the following value: 10485760000 However, on a 32-bit machine, where a long is 32 bits (really 31 bits when talking about positive numbers), the maximum value that can be computed is 2**31-1: 2147483647 Consequently, the computation overflows. o The compiler produces a long int value that is the the result of overflow (10485760000 % 2**31): 1895825408L Actually, I think this overflow is implementation-defined, so it's not even a portable description of what happens. The solution is to use a long long int (or, even better, an unsigned long long int) type for the constant expression; the C standard mandates a sufficiently large maximum value for such types. Hence, the following change is made to the bad line: - } else if (number < 10000 * ONE_M) { + } else if (number < 10000ULL * ONE_M) { However, the whole line is now patently silly, because the variable "number" is typed "unsigned long", and so it will always be less than the constant expression (the compiler will warn about this, too). Hence, "number" must be typed "unsigned long long"; however, this necessitates changing all of the string formats from something like "%lu" to something like "%llu". Et voila! This commit is born. Then, for the sake of completeness, the declared types of the constant-expression macros are updated: o ONE_K is made unsigned (a "UL" instead of "L") o ONE_T is computed by introducing "1ULL *" o Similar changes are made for ONE_DECIMAL_{K,T} Also, a non-portable overflow-conversion to a signed value has been replaced with a portable comparison: - if ((long long) number == -1LL) { + if (number == ULLONG_MAX) { It might be worth reviewing the rest of the code for other cases where overflows are not handled correctly; even at runtime, it's often necessary to check for overflow unless such behavior is expected (especially for signed integer values, for which overflow has implementation-defined behavior). --- Process.c | 28 ++++++++++++++-------------- Process.h | 10 +++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Process.c b/Process.c index 3c404db32..9fbe0dd71 100644 --- a/Process.c +++ b/Process.c @@ -55,7 +55,7 @@ void Process_setupColumnWidths() { xSnprintf(Process_pidFormat, sizeof(Process_pidFormat), "%%%dd ", digits); } -void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { +void Process_humanNumber(RichString* str, unsigned long long number, bool coloring) { char buffer[11]; int len; @@ -71,48 +71,48 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { if (number < 1000) { //Plain number, no markings - len = snprintf(buffer, 10, "%5lu ", number); + len = snprintf(buffer, 10, "%5llu ", number); RichString_appendn(str, processColor, buffer, len); } else if (number < 100000) { //2 digit MB, 3 digit KB - len = snprintf(buffer, 10, "%2lu", number/1000); + len = snprintf(buffer, 10, "%2llu", number/1000); RichString_appendn(str, processMegabytesColor, buffer, len); number %= 1000; - len = snprintf(buffer, 10, "%03lu ", number); + len = snprintf(buffer, 10, "%03llu ", number); RichString_appendn(str, processColor, buffer, len); } else if (number < 1000 * ONE_K) { //3 digit MB number /= ONE_K; - len = snprintf(buffer, 10, "%4luM ", number); + len = snprintf(buffer, 10, "%4lluM ", number); RichString_appendn(str, processMegabytesColor, buffer, len); } else if (number < 10000 * ONE_K) { //1 digit GB, 3 digit MB number /= ONE_K; - len = snprintf(buffer, 10, "%1lu", number/1000); + len = snprintf(buffer, 10, "%1llu", number/1000); RichString_appendn(str, processGigabytesColor, buffer, len); number %= 1000; - len = snprintf(buffer, 10, "%03luM ", number); + len = snprintf(buffer, 10, "%03lluM ", number); RichString_appendn(str, processMegabytesColor, buffer, len); } else if (number < 100000 * ONE_K) { //2 digit GB, 1 digit MB number /= 100 * ONE_K; - len = snprintf(buffer, 10, "%2lu", number/10); + len = snprintf(buffer, 10, "%2llu", number/10); RichString_appendn(str, processGigabytesColor, buffer, len); number %= 10; - len = snprintf(buffer, 10, ".%1luG ", number); + len = snprintf(buffer, 10, ".%1lluG ", number); RichString_appendn(str, processMegabytesColor, buffer, len); } else if (number < 1000 * ONE_M) { //3 digit GB number /= ONE_M; - len = snprintf(buffer, 10, "%4luG ", number); + len = snprintf(buffer, 10, "%4lluG ", number); RichString_appendn(str, processGigabytesColor, buffer, len); - } else if (number < 10000 * ONE_M) { + } else if (number < 10000ULL * ONE_M) { //1 digit TB, 3 digit GB number /= ONE_M; - len = snprintf(buffer, 10, "%1lu", number/1000); + len = snprintf(buffer, 10, "%1llu", number/1000); RichString_appendn(str, largeNumberColor, buffer, len); number %= 1000; - len = snprintf(buffer, 10, "%03luG ", number); + len = snprintf(buffer, 10, "%03lluG ", number); RichString_appendn(str, processGigabytesColor, buffer, len); } else { //2 digit TB and above @@ -134,7 +134,7 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori processShadowColor = CRT_colors[PROCESS]; } - if ((long long) number == -1LL) { + if (number == ULLONG_MAX) { int len = snprintf(buffer, 13, " no perm "); RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len); } else if (number >= 100000LL * ONE_DECIMAL_T) { diff --git a/Process.h b/Process.h index 404f73e6c..15ea97bf1 100644 --- a/Process.h +++ b/Process.h @@ -138,19 +138,19 @@ typedef struct ProcessClass_ { #define Process_sortState(state) ((state) == 'I' ? 0x100 : (state)) -#define ONE_K 1024L +#define ONE_K 1024UL #define ONE_M (ONE_K * ONE_K) #define ONE_G (ONE_M * ONE_K) -#define ONE_T ((long long)ONE_G * ONE_K) +#define ONE_T (1ULL * ONE_G * ONE_K) -#define ONE_DECIMAL_K 1000L +#define ONE_DECIMAL_K 1000UL #define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K) #define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K) -#define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K) +#define ONE_DECIMAL_T (1ULL * ONE_DECIMAL_G * ONE_DECIMAL_K) void Process_setupColumnWidths(void); -void Process_humanNumber(RichString* str, unsigned long number, bool coloring); +void Process_humanNumber(RichString* str, unsigned long long number, bool coloring); void Process_colorNumber(RichString* str, unsigned long long number, bool coloring); From 2cde4a7f8eef5f4b4701128b272d529c74f5cfc1 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Fri, 18 Sep 2020 19:32:41 +0200 Subject: [PATCH 246/411] Enable NULL pointer checks via compiler if supported --- configure.ac | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/configure.ac b/configure.ac index d06c598f4..5302f1e63 100644 --- a/configure.ac +++ b/configure.ac @@ -169,6 +169,23 @@ m4_define([HTOP_CHECK_LIB], ], [$4]) ]) +dnl https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS + AC_ARG_ENABLE(unicode, [AS_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes") if test "x$enable_unicode" = xyes; then HTOP_CHECK_SCRIPT([ncursesw6], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw6-config", @@ -291,6 +308,8 @@ AM_CFLAGS="\ -Wunused\ -Wwrite-strings" +AX_CHECK_COMPILE_FLAG([-Wnull-dereference], [AM_CFLAGS="$AM_CFLAGS -Wnull-dereference"], , [-Werror]) + AC_ARG_ENABLE([werror], [AS_HELP_STRING([--enable-werror], [Treat warnings as errors (default: warnings are not errors)])], [enable_werror="$enableval"], [enable_werror=no]) AS_IF([test "x$enable_werror" = "xyes"], [AM_CFLAGS="$AM_CFLAGS -Werror"]) AC_SUBST([AM_CFLAGS]) From 816734e2d4608e6ee2d4c0098c4f3bdb8c702b66 Mon Sep 17 00:00:00 2001 From: Bart Joy Date: Thu, 1 Oct 2020 20:08:49 +1300 Subject: [PATCH 247/411] Add screen shot of htop to readme Added a basic screenshot of htop in action to the readme so that visitors to the page can quickly get a rough idea about what htop does. --- README | 2 ++ docs/images/screenshot.png | Bin 0 -> 80937 bytes 2 files changed, 2 insertions(+) create mode 100644 docs/images/screenshot.png diff --git a/README b/README index 67f80eff6..880597d8a 100644 --- a/README +++ b/README @@ -7,6 +7,8 @@ [![Github Release](https://img.shields.io/github/release/htop-dev/htop.svg)](https://github.com/htop-dev/htop/releases/latest) [![Download](https://api.bintray.com/packages/htop/source/htop/images/download.svg)](https://bintray.com/htop/source/htop/_latestVersion) +![Screenshot of htop](docs/images/screenshot.png?raw=true) + ## Introduction `htop` is a cross-platform interactive process viewer. diff --git a/docs/images/screenshot.png b/docs/images/screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..0ff3cfeadfe66028ad42c3cf7fffed2a7fdd630f GIT binary patch literal 80937 zcmcG!V{~L)w=W)B6{BNxY}@GAwv&#{j_q`8+qTuQ?WALOtXus&?-_rLGwwL|!(BD% zL+zTi_TFpFALgtbt{^9Y2!{&?0s?|4B`K-|0s=k_0s;mO0|h+7y+qpz0z%&5siNVm zWavg@?`UUc`Q4Pr*~8wH$kg4^3iiluo*S6WhUomGbx^Bv` zjSj}txD_yc5$ZfBJ0>j{uAyNlL~#P;m_&S-qQOZbW4W?=j%d!kE$`ueFFV>BuPhbA zAK%KyRx+}oGLoE#eQ7z2EPkpuQWas+RQ+Mrk!4#}vTiER#7m~tuCp?mY>!UXvMpLP zt7_U3kL8O`C|b7dy5Abv$tLYkgvuf4G>*bCPxnaHESY3~{StYt>5-(GQq}x|%X8Uy zN8e$)Zu7_|#~GBs^ZZjeHp}$|Cq<*<&DDmahr8YmdI)wDM}m&8Tp!^ESc+Rss<$OkiM0iDwChWy0I zc)k~#S3Hj?kCSyvpSIh3`m0dX3 zH#po$W#Q=jV76N^*4ICp3JR9hZmTv@A6NdaeKg0x8A8}7*_Qq5?X(kLhBS2D%A7gd z!Fva7-cRd}Bp3)Nd^BqwExfj6XAtJg z;ah0vpN*r<#opEz_-0|DVP{3rm|*aBiCL0SwwsFO7(^wLp0J}B9A0pDe>O8ByQ@|n zsV{!_uD_N#E#gsVOS?PFC-qZ6FH^f5g86RE{7NNyzipeCeX`EHv^TtpbXez)CQr4A zvaSeSbe*W8R(q~OFitYFO->HpjKantU&E~c=*IkP>{?n%5G{V7BOHIR>qhgfN={D0 zmipPn<79iImb&Rm(HXl{3?p$?a|suiu$RHPU*eEzIn#WiC6Tb;yQ5U`O|nv0k) zY{W28#msec5rep&kF-Xu4X!MXk9QO^!KlkDj>=EqN3O;fLB8^{FRqUr%qLtcXXBUv zIR9r>3g}wTWaFIpHt%$&DAq_>_f+HtE%=u#nvJ&b^Rhf}LsO08U?wIy`-etU7jVpM ztTZ(&icF0-nJka#aBoi@S*zl+xnsU1#918$Gf}7+?)0dntCGSdZmW|m4`w{2Z=6Ku z2F6P38JWNTM>N_?g6pawG*W&b>GihMs2nYjkCii5g ziD&RyREAsO3&!6zjBTfv*ac=I6FY1q5wb0a^f-g^`rOVEh&v-a>idb)B0+2jyV=#& za%NU5c_l6qUu#6N?_ukRQ|}B9MHcL8IsLwTlQKb426x;La!lxHYH%ZC%Kt+)HV%(_ zIGn|z$nV+|`3omItyxE|^Ubu%WMamO400p8fyJ=YMUK*MEV!yyaww6_`l&0BxI&Tu z;*{$JfWyDW7C^qO;6paqL0UumScXv!OE-yYvK`0wV860fBFaVL{ia<$* zjw7}-yd*MsFx;)bPRkUTK`nsWA)Othzueu36Z#mnR6rW!r{5SkZ@T$wI)O`(45gMqX**mnONr<8j5I<$rzpv>! z1gy4^&}$?FfC#)*5AzU-4@%nBEwG2>J2Z}lAt5APz23eT6de%8vRx^q`I(;X+_y^g z4Q}OL$J1f!nSONY*P=6kzQ&6dtzXbG18#SyXE`4RLLx< ztn_&GL0;EC^HLN<8KHJ#62j|*_&m5slBA7J@^ETH{Z+%n4U3pit@*FP4B=?vM_}lm zpqHmh6)6rKd9dx=M`%-pziN=t%_~up@bDF8*u^Dx5Vhz$p-eVC?PMG^#Y7T z>YsQLRb-76tu(cR2eo@AR%8g-*GkoX$|vy%!+7(IbIXP&7tmcEh#gGHFx?SgL#>W} zP2mMtPVmi|*gG9MHRBhX1MGC*FRHbW(ZrgG$Oo^gAM`1DgmBK3Kp3^WG-|q#re(0atebaoT?8A6^j<` zClk||!Z(q}d^RCQ-YC0#Y}+7{enSezD;QQy(3Nl#1{m4>byv$eCisjnjPWehsv>VT zsQ_paXbBp@!0!W1(866W;M0pR@aPsn?}S>$ShGBLphP%`4(QGSLT@Sf(hln6gsydA ze`bsEN@6N^2q~raM9&&Tf5p(!AL7XE^+nnOXpi-T?D^c;bivQYc8Ivem&W^PZs{|Z z$-8#g{EN`EJU;_dz{X2d_#nWv2_W|8@3ouPM#WkK?1lN%XCR(qK1TK=&A|oJ$fT$W zwAyzc<%XMjx7;tF|5OPsUD@FfS6)HqjuH0BU5dmVoc#gU_C>d?#oJH}?!yUfzSg-P za3od$fblK7;m~8fK~?UuKQdg6jUT9BEsdkw+vtpq7+-|SxL*~ZJ*umhzE1`dI6r&% ztIQbTi~p%n2UFvv2pB6(=e&VvCErjTRSh7MPReB2n+Zia0GkW3O>8>hNwGOWDQdZr}J-EX6AwtUg2@z=~<*%Vl%LP{$i~PQ{hHT%J#wGT`DDz@%V6VTi zGMdajQeAcv>4<{44TTtP)Dl=1)UB(j1}P}u;HB#@(pe-S@}$Y3cc5R2icd|28Avv# z((IkuL`;Cty_`CtmBGR04XzBq<)QjxvbcpEi;>`MN?W0I2IrbcDGRi2 z=Is`Ep>R3o=hC0*9ip%ka@9bBH(_alxT07rPO=s?{ThK4A1#d#enK-?eM)&~_sZi| z_lvaUc!p7>y$;*Cr8t>)6oXPrSbK!cCy{CERluJ`4ma8)`>6`6Dl;P-Wiva{ifH~* z&?G>35zbwfKB-WHd)8kI4rMj1Sv+-}Gyag584|IhpdaY|y2?W&F!yHLqsm0ijWNS; zl778lDcwd!eUwRtc-EPOt{X}Ns~@Zt=f3GeG=ybg5;rLTm8U2~r#q}^J)tMru4%Pb z?<$H1Pd*O{NA9SJ|Be7F-f&MPg2leVi$Ps<(=J~SIT+e`Kb&bCpg*>d0c*V-i@hYW zJ{-ZB#UW5LOp+v_E3wLu8$g@y5$Iv@nrB6pFw9~C$q?0o8}J81ALSdZNjx{=j{e04 zP=P;t9~+26bj3+(nZ9S8LS*x42Gzh&qp854E*-OHMddlDNPF5*%;K)ksIIy~s8P_g zkL?uPp2nR~2=OXF%V#C%+vMyf*!#B*&o)E|+6d}1@~H~EyHLZUIKY;e3sFd~QS4zs zb+jK|&FnDIPH+b%=tz(O_GXMt@9Wp%1LUP^=eb0 zGBtxj@<;A7?~r7{(^SChR#vOK1lI`8?tD!~n&~(?mGqBoDYruJ6^4@^O*v;M<#Rqx z2r`z@bAkUtHdd{Ly7mW~-+Y^EY#|Zw016}Q*=y5f5bN-p#VB*u3!%+7n5plO%f9FH zC)JDBH(VndnPx~zFhBM;)Z7e8N7C~qKduC5O{<4H+GBPP;i3@h@5|}knGJ`r=$E-|N13n z(xBA)DQ+;nPy_@b$yVi>272=p>>OnXsl!NdrVcuSy6?Wwk-e&+TTYA%9q`!K+?w&&Qytk!te_A)(YfK`ZoetEkI2GkSLM!RRVdjw&5RZZEJ~9K zyWtrVCdQdVpt=pzwNRko0tWV28xk3FOvBkGMj5IhCW(s9;AN&>hC!p>f++NBx+(}r zm_4@!Gd|i51inMe5Wz$o*68=F0jjBIn^vq9yOXd?uUtKsfMDu(L#@5$aMBzo`y7~3 zCOt6FWCJ;#ZwH2?Vr{up^a>zgPx})6paZjnhfux=4!={L@o2&9rb4a)SZ*|iOo&5b zEE$`FczmsNcDY^A!N|AN)O5M~oc1Q}zy^u~UC7JCf1@3exJSsePqA=Jm8Oi1@~v78 zV8Xtrv_+_$NX!wdb^ggmGeC#DjT&@TPJ`Ex6y1giV@$G_3AU8MI!V6nhB=egGDw-n zD2N$&!3^yr*`bSz&wvO4uZ@d~;tWb#O67=vqBc{-n&U2^)S53NOSD>%sYHJ}Xb*tU zFosOSzq;fOLv0IuMe`E3>i3jxL`)?|?(b9T5mpA4&hQehDcf`Cpy0*kL{_UN$jv9C61E@-m?5mCY{&jqvsVbyXpkZ(mZkO5 zKcdi|_5C`e0Xhp?MYRjStj$O_ssXj5=%*@pYsBDS6rFLWC@YPT)Q*x(=xLWp-X7C5dh{5OIC>0MStRaLVv}m36&7(r8PGo<^G0e6UR_U z`#T^*X%675T3!B-FQ`+FhDwTwcqf7Rvs9TUE>WkqZHzf%TS+g~Giy*&!Pvh;s)`U1 z56VZDRFXwl#$_icPPcp#yaL)6)_Xg3YXi`vqigt_>*%0-g{V^`lgtssy39&A)mt4w?`gwPn8h88NggT z2mz|16!f|uuXT{T*{Bq#1p8QFeRHZb4xLPCt|O8>bpv-Th)GHn;oTA4LnI!*^}f_U5YzU#mBOO+(09OUL6rCsq z+z`huk`$s@6fRXefA`O%v#aEpcsbIAL=q=1@jF@&M^R5!9Q%bCro&_VLwtA#>63Fa z85rH##jmbKMl+-&Bk&K{vqnKVu<-Z09xzD?b#Oc3mGb-ZJ0-@3U~iDoriBFM;?T2I zl5=H-OwTxRUo8>$pe(B!QsxR7#;2ak*fN>=&f?})L|{=+kY(mtst1^yr6IQT=KB^6 zsi})|Rb1RR2k+{?dtYWvEXGVhecg$u+Rx~vv6>)Re{v^%WajpZ(@r2YvAq*^*q~++u*s4*~(M&SF>?ZB0zgJ3{;eM4sgw&I?`n@l0qs1=J+*>BDtd_c-S~%@@O=_5t6cz!tlrC+kBLVf^~ufhMM0B#QeE)R z{#yUV19t=TKoeC~6B7(-ZqcTi!gH8F+gprU$Xr1Khze?3@Y=IBU!6iLt2I5=%=CIhyn6)T-v?alG-LL=w>OXX68~>&nan5|91;gN<*O9Gwr3g*~My80k5L?jXVc8!W7g9)y%)Rx4u@Ro! z*oG#_<>d8|SN6eeFO98`sOwn%a|+8eu*J-Lk0b7~p@;^$@hplM7iub2GtYdkLV%w5 zo8I~4Hezvw3CK9GX^pIaYU8}H_V@|>MM&et8&m@Mq|{m_bu6Neb*mNgPOXF{aF#X2r*{KKM3c~X%NRj+FqsQbRRJ!`1O?QhdRGUnK z!_I%tgayk6ax4V7FZB5Jx8SxBq@-|bc8`x571x~1Z$n+(T>NB>%a&W5PEd4_ zP?AfMUP3W4HcgDajahSXKYs=rg!CTVxHzU^Su}Z6*w?fd`WDhb;?Y0}zNaWgwu2ac z>hQ9-Lgc0+cG_jg51p@j*mJXnu}I(aW)Cm{L32uzy^`{>fRI@gQOb@CT?~sw1Z`b zXxxE2qKo`Jr2f!SMI8&L1#%+_g9?>^(CrE(42exfV|NCY(8Sb=J1#c9`g|C^`>vgp z18X-mZL;>4mBH9JlGJO^WGsv>#GAl^z}{Ar80eYARuMsj-bE*jLd`)$KM^9)4O%=T zq%q$Aql+!oN^8Pn*Z6ET;B37&o2J8JO-) zpHy9>vkp^!R&$@@f&rLjU)8X*2j&2g=R}V`@dXvgI8NsYVM^&IkqCRgTV)0N4kI}# zz%34Du4vXw!GN8vEce8#p7tgLAC#}DqUNklcgxe0(KOr`N#WalS2w4Yb+IS1XV0Y2 zx+~Aie+c5`xc^C4a>=sSX8gEny*(!z8@x`s;pcaJYFmTA_YfssnnjK ze8$j3Wp(YM(k&OnV-Zy)U$PVz68n~g^fisd*5KC{RErT)C8aLS(-)x-vs8?JAxM#T zt7K50>l&-YC@X3AXxcy(lQqXai7r^;i(L>7PU;uzRK}CfDa{C4VfPCoM+7qVv{?0} z-IWul_{QgN+fBA?>4&Iauo=@>rF8YC)s&%_kGS1mwycvQ_Plt zq5`xyf0sEZ4})$06*{`g!r`K!S8G18X^(SEs0L-4>HsDf-J4TH`gm&Vdf%4^`s=EP zUhptEJ6CWCz+H|5Mk6_UA5$M)3Ql4yR7-m4(i-ed%r}FZ8pM>?8SgoSbA-Vl;SS1_ z2H%m3q^mdgOlsy*#zz00WAPMQ#X`j4u?)O6#+%50fxFTx?g<-B1^Kc6lZ=mIVZkz* zT8#~~NJ(Iwg{mvLyd^xK8;uv-E%v_k_ z+fxH7V?{5*OkUGIuYpyFHco6TYpsiWeZgSmcgyoNrRBUS6{%TCkR9m-KsdhE+?ffE zy?D^+!VfgF1MF9B=9{2?p$1SmvR2Zs(+QAZaR6{4p6ZDA2Vrp4m^4T$0}o-MJ|x}4 zj|ydnvF;)nUpk2D@Xty+GaY9?g!nSkA-y*Qy&ztH>vK%jqL<2E!{(^A?u^hJAUo30l64W^^don$K5#-{Y}l8gph9*~8nBnkA-S?UciAIY}T7#w|<*gjsd@iGG(`!PFls_MOoS@o| zG8r+;r`pu+mK`9{g+Jm4Mhr!584yJNUHS~Wu{2qo=-d{=SBTsXk!LY7hMaT*U_imC zP-H=t41&3%R@PlAH8)aPjeUPqimYU5Tbf=0kvM~!gZVSB-AY2>*Mp{p0sd6H53Mg6 zW<@M~spYAmSR3&d*lpswRGhtUB14XeB#wT54V^vIi^Yj2 z+#DStMG@Ef_I^|-RiUU@o`SK(yi`S~tX3r8_*Mi&hZ=bWOOf8Ds={Ay7hm96>h{js z^G7nB{i>ZPGDMj*P)gJR=xlJ6I9#Y5iztiuTj^cG5K62ts`YRbVC>FJ?8Ij?zR>qY zjD-E!STkbf9jeJncWOPFjpd=5G!1foWdw{F+$cn4x(wX9>gr_MzgNj7ye1A8k`@`R z7LDNxL9;@xu|1VQeL0#06UkeM-82bbjkoGlc3^ z`~GRZy(#e8_v7XL^D)>j3x6S>k%V8rt-nWtID8+K2&|6!NWVthdob|CgzCb%$T8DX zd6pTvFV=sifYr%(#O?YD1PTr08mw0g|Mi+v??RYa6jn21j0U|NXPKl(MBj%%c% z3va(NG=E{>q5QZg$iD))Q_wrRs-STvo-Nf@7`~rjkX0d;XxUg$JvL`_aj2`ve5kpm zpvsEaMJEtv`&5u3&B>`K1NRb83bMcjwFhzkkPt`CyKD=)UXxhN4s{^*kVj&dt=Z6~2lx4!xOT-j zl}gHsjbu?Pq?32F7yE|fbZ7_FGgR;m2yu+;Zz0kM{5(&*B}&%0!DowgOv^*PwGGe{A(#;CPNm6V>em@k0_+x`tcLs+sUv?v1ValTyk%K*B&my@>as2)jT}h&A7lKd+b= z!pG#aXAU>gP%jeSpGbxqxk+kDG*zRLn2A5508tllx>M`JZTD3L{S<{ImfFgZ>EC@- z3V|O2P+R&X!>j?~U0=soaM#<^hB4&M}nk+5Gad&c{=uMvZfZHVn?+% zj0nNF)sCy&nvVfb-cYtch~*)~28GZZoF?JV;HEOrqD54BrT%inF2zloM}Tr-$k9l# zT0yp$mWq2e;I$^nJYT-Xgnf?}NRy^G>Kzg&nhtKtwg5PR)JALlX*x@)Hc0G!To_`Z|A$d zx0Wwyhb2_8>$CpZDnn?16y{Ys&%svN^jcDblqHprtu1fRzFd+^V*6Z$xVZg!Y$V7_ z%)YrSta;8>(!g=|j?ALBzo81RM8AD_=QVYd)1?=n92g@0INw+CaQ4xp(tY%E1$2H4 zCu#sOpLSf~Aq_i_Red|if`XGyejYTqoj;vA+Hq!2k542Sp?DC<3pP3H+uJ+E<0&!z z)dyDYnV;#}Y?vts2xyR{h=_ueh{%6E#sz$ME7K>QPjWy3Jy>43Nr@WC6~$pxA&WNb zo5KP%dY*78hL#JX#|a@T6B!kKOn`M?U(Qf@U}QrzQgr~)6Zqc2ap5ru`Bnn1x(Sz+pUO<10K5I_(a)o+5uXGXeI;rRT5OuL(4Is!4MC3seH-odL}}XO1VAEu zNC}z-f8tlMIIq|jWwxx_;LH)~Bf2TAreUqe1BNK{KZoSi^SI)0@ESo70644CTsS<3 zH5VmXlVjeKeL}}~)HZZS)!tF2SVW6BU4bXUx9lp_%*^Wq5~l$^uYpvPuD>iNlS== zeExmqc9kRokHFeXYC3^{z@zl;H{E?fDnO5i3+K> zubpptxMM87kK8;?Y&s=^2nhlv3IT73~BlXa=?B8VHfXD4`%&J0^BazI~*|9VCEo>{5{J-g#!flCeB)q_LPM zJ9Rf?GJ)U${vE4dmBoli{u%i@nxg-XzJ{=WM}YZ%!XT&rjUj={7W+2_oj3B|7)p1{ ze}fdSY5xy`{zqr~9|ir7E(wvuU9Z6m(Zj>z;P8;i_wDK1y!)ESxT%5rBVQI$NS|X1 zd`&YvAbwyjlgsJbSz=~p=78<9vT9C5SlH=&h(=DkGC_39_wYxzo&lHJu~eHi6rWd{ zh^wBSVXVU1+PL%c@9cJ4l~t;uqUEOND|L-lixHuOzE5#SLvHIf?sjeDhM8G8@_j>C z75o?gz+wp^vHS4V$W~q8=-u=_K6Bv`CK+xtv)vZ2O&JM^l1(HQL$PLqnG1!$lH0bT z^HrBAsS(p+2?&S%EypG>(px0gn)a(I{42H zXv_(`p%^jkRj2_71PEvtHq4{G-`$t>XY0kEO2y8Xgw5z}$5NOqW7}TDSAwwMN(mSv-so z;K~2Vn6jw&wD8sXBHLA9YH*1v{aA0dG-|dvd%L}ZP zYiCSLOA{?njEIP6G!qjo{1wngbaHayLc$PYx%c{h#e~b&ztt4^l%kJ{%Y$jXKa88x za;gjfSW@0wW+7!?Y<8?}7D-nzNbV0uKc6>Dr*b(_41^*tW73e2sIvRKIImr{d7Yxr z;If^@O{m|O0oS$grBM!gI<&vnA6)u#dU|?!iJF9Dk=bYv2FxD>Bv0YER@?VKTjUQt zEuBKYhzSgUwi$}R2))1k&%VF@2D{{;UCIRwBFcncd6mNibG&$`03wLXn_Tm6wy_RU zE2!rDi>*=LW4`|ec@1WhxVN{rqvPYoZ%;Q##W#(i$>Y7(mtNfX2!V&TSg%qED!2eZ zSuC9LH>eSS(2n$mgU#T;;Tr9^x7I?GI8jU?WNW6K!bW6qONnR=wbKCIO z)hK;Y5fxR*S$f=A^|=`uOs4Hi=LGPe0t;BgLfKTo-TP(ZDqU@3c+_a|G!DD$W)N9@E+oD|B#?QFWT0$+y_|EnVdz%q11{Yc61L9?Ctynw>LCW7 z+6I_NWNlNNff}~-{v!mW?_G~Da%ll2>I@iBVPTRYh}k|Op+;4@($1GUNzK3`%p0~* z6tdSyUnJiuYG5{fd1i4~uD5+SF0=Vm`GFi4n(tXX7Vc%&h4H9q4rqTi3lmjY10Ek^ z%yL@4Vdx>dos$L;RjV0xS<-Z`ZVg!J`K)3FLaOZIw5^!p9FH5_u0}5?1flO`7dojC zc*1%Tz{Z^KY#vk$EU1pw4rlY1-bQtcn^dc+pLM+kjA29v6KuSRsGEf z+;2WwC4ol)kqrD~@N=yW#{946EM`-gW7oR_O+yi3l1Z{T{8`O5>q}{GqWV9wj?ZfT ziyWEU`O%?}zG%Gs@b&F(Rs$|wGJsSZ1qK2HCRjLh^S{7^$m_1x?p)Ta0ECYPjansV zWs3e^sFw0?a$wnS8`eP~5<%?h^lrJ;qr_QXaY!jy{=L)n7uMjvNRZSm2U9f%vf1Bp z9$H3%^8Zt^{2he-RVt$vVV?pr;NBgUeW|`tC)h^n#t6ayT+owlhNsQrkYKrFNSxbKV0Q7 zeuoGwvA30TPa+NV)u(^Ys^>{pg@wAYJaY{ZZP`ZAbYpfB|Ji4*TKZEL2xR zQpLXtxM~A1+2bs8bJu?^5krK$55N6`nI>u#aQPg5(QO|r5r>4S ze@mmQHL+QIH3^bKsLvXv`rlTk!@8e~;Y9xCdRhEda}^>UW#=WgaL+Sh-Sgee zwimZn=lh(=8R+*}}RwhbN+dcW6M zRqAAhu|$E!*^(lw6?z>qf9Xx|*u(@-&6QMC3fcb32_^!Rl)QWm%kzznClwH0g~>c{ z%057CKrG|0YUp#i@p;5gfVA9bWy()Hu z`~DXp@gZtCOOrd#C^($<1}C4-&(CXGz+f%$C~TqJ!q^xEO6L{2p1*3R=(E-vcvK{v zVg(QUSzxo#P{e@e^M728j}z!4KBn~yh%m|&7-$Wo3zH}qh77*{@IrcSI z=pU8qVFKbkv6agCffV+4tRnw+p7Ac7%^IjkqznwPH~S;%>BI8`TJ+!p9aksLj0njc zy6#Q7z?qZ(KawQlb80o~A9a4Xv*l(}#;qNmg9b ztxk_MCE%*9VKV5+02TFARL@%^bg%7{I^wE3!(ETyvRd~h7ALUF8f(^VTlMdDmCIXe zPHr?`IPMa1#9Tk!tN?w@8E`?$tW-Tu%LY^E$(!Ao9+K%qog8b~zxM)t;=d*amG{-Q z2mkE#D!l8n`Z1|ej z?W5WbWc)>R-%Bn=gaEs4*k;5!>>*@+$@BeKRZien_k8Z`>8yR9DLo26o45iANv#Xi zJF8n@s%6vE6dq@L)h<;JEw-_AcU%o`wI#0n_$c`6@5-k88dj_E#pjC)`EEqpxHua| zH9AxK^}1@=ZIsG@=KhNx15d_iMGY#=N$2>>gEo*9cJO&M{uT$4KFHbo`rbmjY|CU( zcdRKb3RPQinsl)t3**Rx~uhK3+jCH?PlC8~F>+d=7jOzeJ~rz_C!mt^4W0>`LtDmB4tEJm0G2OhoF%)!GG}R4n54FZXd?hj#WQg@x>}~wv!8|t*w>YS-~)D)cdcZa5^n;wvj5&A3VH9OO+H}Nkc=@)s;Pi!){3nBi?g=-ZUvz zzZK>3N#u6^#&h=}&;CYirV#e~2cWnImZ2vh_3{_ZPI5-B7`#RY62T`l?K>IMWSKzd z_7)sIk1#J3je7t5bZ>bL-p30zk1K7JR@2^YC?S90GYsz^l*>qlt)s`kQhB@KgxKOR zSB1BQXWM(e0wBdE`xwFsvh8l$bKUL{$o73_%wQYP>dC$if*t%lT@%j>`6_hH&6pwN z4St>tGDN6qr$x6FxH&Co;kl`gh0_x7nX+TGi!kyDo#&QkPmNfxoVjO|&&9RE<60_= z8o!2^orTL6bryv7w?^7($8c-0U5SSgM`ZX9gJ>0yDAoMw@U4OJM9KDo`rWPGbb|0s zr{h8%)ehbLiq!5J%v4}_BqQtKO-SUhgYxJ&hP zP5R`+j*cn(nwTpRIzZ~K*Xhm#^d3A1&oHrs^6s}LCHa>dINOAul8UbEOU1GvD+2Ee zxyym8b)?nv@*`{Q7^K*htkFlyJ;Nzkh_jTy3Nh7Y9o78+ARGu)^d{=F<2d>TzM>db z1wIWsb71&%A|A$m{ocQhfxscU?6(U#9Uk}WRZEKES@6M-10=m6Kr%Np_mYzGH`x%M=8@j_yq(;xw^72>6Vuj(tX011u_d8qXGiE1~?pZmzW(K=q zmEMInyRGwZm9{$f)YP=w>9|}L4DUPZ$yJa1Z~{3*i7ZXk4>Yjcvzo6@Q#^mK_oe4E z`m+!Eahua(Gkqrt=Sd<4VxaWaIm!T~z~jzJpaR9`j1JEC2EPAwtfWL=03?FY=V!m~ zdsz1kR4PSww~ul+f50-=54U%G-&1|Zp_QPWCRGc2Q_k3jMja?KQVZ7d@0=Iq5hwF@ z{+LdAL%gG{ReO(?%be=9T_pp6n*R96+-I3~7>X5g->vfkYy^Ay~J- zNBo~QC#fHwKHgrJu9d>Lz?y1obdv5}#dY14dA{$^vHSD5V2<7TI?HWA4@2=fvvXx4 z&7Hmjfs_vMZxQ43`92tUq^iD)$CWTD&7io_!2tx|u-E&&dkvjBd>RGNkA=%*N7)@K z7{Ozr_?|O$212JmtpYtvxS?PUKcg{}D2eLp#qFUS$Yyagi?^1!g-4-Nut#hR{%*tc zuaJEQjT`bzB~*hJ3#6~jfti|GSodZbmRp%m3FPRAc;Y}QLGjo}e0$uEtxzthZ+=fR z-|M)O>)#(ywm(b?x@-lvzF70&K#1W_Z^Y6gVz(n0`thoL(vexgj6dxMS~#5@{d(R| z(WK+*%kQc<+l}Vl)wL zwd-A(ReM)sI*`}$sMV?5_Z{rHMW~NVvIn*^i)Ji?kl7cWhcJkcAqfA`Pd9bVMd-`M zNIyV1_jw(qlc0Y*cW2Qmxnw&QxHJ)j-f;nU(OlvEZn=R#lQt{`NekO;Z$k%@FdmZTl9x`OL6}<-BM;4E2p_jU`~@mHt^{=^BgzZY2PzMjb?~!-?_H>w;PfpuNFLJW`lLt zCsp~UV{nUYf@Yh*%3`_n zfPNS5W7|=(>K_UGU|k&8YIpN<}6$R z%b8NelW^w-AFmR-q)OVOj)b1F40TQGF(*{k97wY<+KI|^P5z4BwqN+KOCHUf-EFsm zo7Y??`4zqN0i#$buia3;)~_-J?VF%Fu=mdT=u3YOdh_?k@`(d0k@I|#J$-Ngd!I#S zoA+z**^~Lc`Y;CVkS1TgYGt`H$8?p6@%0vl_%h}2$(-2xO*eFbKMMVuxFmD6t=3lk zv%ntLrYoMpiUoL}hqUTvPd5%Xi=0P(jk zdhp}P1CM7FAM4T#4&2}!ukvyd1|=>5UgCY#y0zB=rZ!wD;~p^{cV;kHfg{QeT3*$j z5(P6YJ$JPCHJ(=Q3u5AC6kB+9gNscxX7j~6j)o>?Mn3ndntpsg__u@tVY=^->g4(R zwAvDmH`6FdSu5GBsi96)Q{@iYj;xwR8XWt=yF6Hcp=EVQIln@MZYEJQ zq0|r`=`daiYJahXHwUI^GG*ZhAOCn1s8XqnJYJr{aJ+-DVC`=+-H74z_geglN&a!) z$46-kY{i8iDrg*MDwG+e2WF+jXU71=f9Z75bo=uU8nATwH#zs}ZZ2Ag(Mf%@ezx;Q996os6sbTBkk102*smP`VvN*P^T#pg#>!b}(o5cmA5hRqME2>Zhqd499%ACyg z(f6akt0=4L4uw%ow=wo-YA=;(xjoc~to(7>#k82UG7?0!Xg=QWM@MLB+>0Ki)o)KW z>$NT4`xcujzUhk=if;4Q`tVF_PgmG6Gv}&GU%#S_bZo{YtJOuD524Nb-Y3mxJP^=h zWqMM3H_hREI7H6JuRtDI`z*xbZVYZV(Zr|dkz{8?cA3IIRO_Zz(VUD?;gWYdQ|+4P zkUPKMW2dEIWCI|>CNm_SR?X{{YQ8es>J0IVCuGLN$M0rxZhINaCP@alk1aYZa~*NM z3dItD436u%Figq=$)S@=oJisRL1ys861R7`>!46w?(-v5w6UZ=W;FSsoG(F&|)@!>M{V>rvp-Lb)pSE5wY}kIvuTIsXiUKF**(@ICmkAnlJqXZg9?eJ_pi1e2jCQ%#UXX~lPd(GJ=-pDsJmNLg+^^d5t;_Szn_CiY`TEN1&p^aq>ky5E~`Plor= zx1Es9I$WPZ5XzREdEZ~rGMT`Eo^DZ#b-UIOqC{?p!|La}hUIe1&O+JWkCYxs8qTLG z=AUh6^d%`b*43cnB-}Py!6$7D9TO+4XZ7RdNjd$?nLTN%Gw1qKHscx!PoDQ`x^G@z zQ8+R<@e>wJtj`USH)TSLr+KEtxc7J`WspVT{ zi(l3oaN2Zf_4?BbY|xd2zP#g)iWTZP5k{nmZ+oLfMBX4_``L}6obMS`+I17(u31B~ zZT_b__j;D6ELs@T_6POoeQJKY{Dbwwn{b02{gMDu7Iz?4fV-wJowbd2awKwx0l9aQ zqc3i|x8245i163e4Z_q}wXYZ61~){uXMfx4^>~fJ!Di@4I}B7{VM)ny#vA6Q6Y@tq zsZ2N8h@?-8S&#>!)QF2 zOTD>*DeIIO*s1)!Tm+PMRdDw5f1l`v&G z_*PEft2z0!#*d3k8Om~hIS6AyZ^1@u^*KFnKu50MN~PxDIG=pxH~*6CexD`Hq5(^W zo^x6!J%Zq6ich5aQGw5JAj^F~6ZpAj{{7%FCpFc;OfpBbdjI~n-FJ$#`woYg)?OLJjN7LiF_i z;_R)%s{FdOQMwxhr4ghgrMp3qQba(yM7q1XL8PQhK)SoT7bV>-x#*5>@_YBY_rCUb z_I0jvxcoz4t@S+5oO6tEk9*u>@b9V;Y1}*bYlJlSafM_-^}!OwVJ}S<0fVuZ^Bzks zjOZR`Cf*c0m~H>cJWGE~D}q$sF#I{YuV{Z|W@fW?CH;Bqd_{K&@Oq04*~!q??|8=abwZOMXg>(*7j7TezjXaQ9|!cVW?2HE1;29vC<}{R1svDxXa%gq0>4v ziL?a13->f1l3e4ZB_(&s+@@KwteT}j)*URDCTG7T2dYB9e1c+42mU{>s@0#L$gBS% zhNg^g-M7h_c$R)ghy$*q$Je-&Xn8afVc8`pygTe&I#*cR@*h>UB3y?=o+*SpDqQfQ#WY8iq<_CZ{nG#crAzzPa%b_@O4J-?*L5$aw7o5yG2~>s|RQ8 zHscf;o%->7mGjp4Plx=W5kqo!mrL(&Quv;_4hGXD zTF6|f_={QJP+Xfq)GGf$RRw4316Rww`Ow$lCn`zskQXjW(6>+`h>=_E9%RZm zE)Ooi4Hu*ugW!7gcxRl&@l}b}n)0}`mG*$*v5iR;^1yCj?QkGFmi{2QT0M=YQ{i7l zm-hB8^~>|1)B(ktAc{Faj9=d07pd25Cz&zcLqu$UkvXrSZa*TEm%%HFSlm9I5DDD- zVef-9#{!xm7WZHYvSUX}%aYVxqcIr@kF&Auqgzh1si7wmwF5-FiEtA<^4tsLf_aS2 zizWM*RAICD)N=cLvJ~OPi@RM_R1?iq{#l>A^qPrfuVsi@MHiMr@>e&OdKw#k@~8s} zt^tL|ztnl;6oNBYEvJzO&Br~Ao7bYJZ<2UwIpSGswX_;&SoR#IXLnAwX6rO_)&&!^ zz9Q$zS8@=t*7#YqTDV!&wfAu1dv5P6&MQ2wz|VtZz|neuK)|3MPr&2Cd>-(F{j80H zMz;@Fz3`{jBCP+`0@b~k>(|==O&vjFnzJ;lE<;{IRD~(!W=j_c-z-g8mNOgQNlNWq7(;81?L5v z_>ECKT4Y6oCPN<1oYxxWg;%DHMsX5f8v50#GSV4;8OIr~2|G>-t8;esC& z|2^?ksI^>_r6=J3Yq4Hb33*8#WjDm$TLw%so>`-3`Qd`cw_R7f0h!zxrgVDn_lN9) z<%_|QUKU3Fzk(Wts&pXJNzTKjuyYN!B@Mp^{|xt&gU)i8Auly(ck` zW%%Hx{z{uq(U)p8@1~sar#3V10Mt#br*y8rd8FECJ}# zZgq(~lG=5lgrC_jY^O)v61BE1=7ibB&(wsJYN`_oLeDWmK~|c^qE$5om~fbEd6FWh zW%;7lU~L6=epPTLCO**us?#Mu<&%8}1Aw67d{Py1`QpWM`6L{j%G@)aizpF&=z{wB z9jUH1O!?(fr-&`hA;$>K#c?k%hAvQBUUNH%i3=FZLIhmVQyUQ5y=5WZJ1T_A`3&23gSNpuHIb2ONC91;6d_ z(ES+2V6PL@Xh8fPZNyxG0=PJ+(|g=9JL*vZk6@GTKnN_j!{K6fCYc)-uo5q$D-3?P zmG0MTPV(ckfFhyNY>igAn2u!%(3pfvN1%v2)Y*OHC#O5QS~oi1NvkSXTeH6)SLlG< zMx1GMN9CYdFOWQQca5z5poGFyICnj(qx32D?hj(7QgBw*OHf@e ze6N7vet$l#7B2-fBL&v+emhYc|&@= z2lcv~+nmz=bojZ62@Z-b$T**ikQXjgguK01I)%E_SnNlT=#6l2$4j|)qiGtag+#|m zo#{Mwc=WueyKr54(FS5Ro$eC8K&@F&vuE>EQgASeuGNh9UKc+89>nor;BeuM{DM{^ zp3Bawwfg!QjT&9(T)=FD!z?EnT3M}CulYnSlcSts>5WC%yP-nPt)E=zmoD3@yQ8qD z{`kT1=xGQ4q`rJts@F7)``6cX13LLua|GEo>!#bieSOwxM3=W_?)S^~6Y}BYLP>)x zjYSm$u0M z#UxEYSItw1+v>#%NYQA}sItB}zuv$n>yq3}1bPPrx2+fY6khv+Zl9FA0gwjKN9?Mb zXb_7t-76B{X;2DK=&rUPDFGhc71|tvT-XzFY-Eh@ali%8!|LIfUsfY@>I*&)js@1M zT4U%IYoSM@0L*n1MY)C6Rd(ZeWnLHANwnKRQ0XXXwYa@1-+vF?{!D6E8TvVi0NBZoeZ+p*JuVA3#XT!&Hgoey@O)m<=z>{NA@djW7hnid>O_+5WAPk+`EviXXQ=gRqXh=aoa`+Yy`3qI&S+4Z-GROY9$JM(jl zA8BdYwI`fLvH>;$)0%$OmSkg2OYOXCDDJ?lZMtyPMD9e7f3kzfK`*aiKOzKb3p5@O zQjoFhKR!6=L)%0R$7zO&n0zO4^`Hyy_U|vtxh;!qwPO+!I66^)e85_v|pHu_^+Rs)DWdimz5ydH8qkPV6ug~>LYIdU$G zNqk#xG=F>F`}Lg?HV(i7eM4Onts+2&0W@6iojd&fh3$UmA^4%*#=D%2)s2WyfMCtA zKUpYyu(Wmy?FCQ_uq*9fY9mKeo%G`xmB%A{k1q}*z>6V{bq;s!*U`n!`s75X5O zgs|`cbcTlQG}qH`P>ueB;sP+|B#-ZUiwc?^dG7`QQ4*H*AD5k4O}IV)DUJZ zv}hE-sg^k%ylk=0M*|uwV(p`*PtQ_v2m!$c zc65RcEhuK@tiu892~N#Z33GSib_E{bUL2sr@t|X5p-qbMYc`N+rl+=gd~m)w?=+vn zFuQjJub^p4o^|Ras{lc4uV}&9gK^o@XHm&47Dnno?S-mSdZ=BAin znzeWqqp6+te`rlN%2vEqV1c5p?DW(o-43fuUsBs64xD0C@91bT*ZSAx4?vpWb-AdJ z;_!Gcx$HTQIuj|928xS0JK|thkuqRF`aoqdPLoyn^~vV~QNo((GP!C33s4HszHzZt zS8|&*az@7NFrPr$>!kp$fi_xI8+K5(uMrnRob9jXW~5{Rx!~pAHdAkQ6rKmDGi6J! z?o1#nF1K{OSAg-itbesCYrYaKW36Ki3nKArgr{WqNtFRWX_xR7(;o(#}>=bY;f5teTl$z&18#Q=94MMCPn3sJonKLqW51@8n0KBLK z6(2{Z9p7d7N2BS?~qmI-aUHcQXdy-AEHA z3V;VdTkeaN)OHQ&SZYQUxno<}EA4eVsD1|D2Mhl;9l-5bV^t5p4{2J=!{Iz$8Nld+ zikFXPZ=}&+^(FI=b}5JF=~n1<{hckKRRAEqL|dM{z6NOfoe}fZ&E79o&9_fnhJr{l z$Rr52!EygbRgF;gKQaa9o3s3Amu^B9ni|89(??&#u6UMiz~~Y4AhrE(g((wZ0KH`4 z9sdQo+xrG=TV7vltkQG>miBOo%&ZehpTl_S?e!Dt*xb~E&iL&8QGN#kGstcSmOuCJgjn-p)Epob2~!vv=~aF6v6^86f$0^J zYnLEF7hWIsVqP80q)AO`u z?eC9kbY8lnLHOu$Dl47#={*AH{#9_OH+NQ4Qttrp58>fP733i(i|!m#JrP_V5l~O7 znE>Y9=B%2l%AW>@=wFf#hoojR)$XNuKe2sq)?S~iN7}({36umBB~@%xv|!ATLcwbuc{_uOtFc6uLxA2`;9JyM*s>+=UnNQUd`*z1qpcA9uaE>;*?hYIYVC`c>gGVB0kf zde>U_SeiU;cHBf0%Rq}=ciNEsl8~D~SuzwD>IdL0eAXS=7 zo>bN&BOr_Re6O&Xm+_6mme;WkJU}6k^Ud<|t418^S-Ivj#6ngbl#MSWh2|Sg%q}b@ z5_(5t9U4&HBORqLAMx}VPPx6=v}?1V4&Y9O4J1k$v7fq5yAC3fsN^x_5eZP%op$Cu z@nG{cTF=&LSL6|!LO4o|*7U^s1Q9s&$#S`cyuY!+yG)q-K2#GuB>Z!zMKc-eXZjBV ztt|@5nbL&{VVG6TZx5eMqnPuVDBK1KL3SW-4vO-=a6?nYPqm}%f4nYJ^OtRZ~PNLXD?d&M~u%*5<)w|VJrlQ~hr2ZaLqbxp@BV((YX z(fy9%&*CpCE<*lGfvMQOP`N(W0>fX3BHFuu5M}NtoaZQo;1fH9rX@?fTZb0vcxokvtwO%6u zpo~8~94+(X;%ovZ3SXx==_or&zgS0c&TixtS2_@sf&iS_c6BV7D^GoQ*^2LcHfCCk z-ibUW7;J^8%7Mb_ppd4*8%d^1A~0(2D6&%&Q$&|>bpGT1ELy@zQ^CyBX2+buLaGhMkZ*1Z5Px1RG~Wg*;BK)ZE*@U9^ZF6XJrqo?w|Fn zEHqNjAb2cau#e=cN>==M3xU08|8=?f<;TF?uQl)}AhC5tb?e3QRnFDrw1s?4qDxa_ z*L7%QkFt4VLGC380*ZfcRPRzXIyDDJ2>l{b=UdXHQ!5+xKoj5TWJ6f-l>{ZhUQ~jx zui`6s+p_L)k*ED~#uPpoTKjiPM^j7OKldNf{*=E`F;aWkGFzXNda+kwpjq%t4#^Ce zlhtXhS$xTy{)*0j$=g}DF3MKnHYlSnq7$nLQ zK7ytdcVi;oJ!6QI+ZG}umF`$xLFfx7Q5ofdDG-5a#%Gu9L6ta>F*uGPpbad)>ZU{{ zanY`a&(<2#3_3z}_ip#pnA5i}Pd7-JM_yoUfzkND5i&&)PqO1V<)+0zq2t8nrz8j+ zO-Oho!cqTH5-zUbH{`XnT1`eSmu9A~WBIl>9wdS_x=$$fJ^c2sZ3=omddVM!7@$Q1 zU!x(`SLfjeptY_lDyi_O-WZ{EQ_JXEEPlzkMrH{ZWinnyV}*T0oYZ)@m!~s$E-CCo z!5X-B4U~b#sm~Mw4xId|<6N1+a%ps+zmGh8$M-*h^w{Gs8C#9VdI>{NaFxi--topb6$ z8K$Ofu;2D+%4@viM?Tf8&cQZozL7{(6^{k1nEq3ri+01y&AA`uo{sm6*Rk9DjOTlt zDx09a#s7A}uJ8yReJ|N6ST4~QaO%%xXjET3Xa4e?ThEsRCjt+M%R4AM{6PupNcdPX zZaOGW2nVQ5c~uu8szObE@Ijzf{3TmPBM9>!=v{m3B`AxD4285Gv7z~lopX502rYIO z>9l7_cAHL$t++cp0((VAT;CST7y47|+Rsz%Wa1t*jqm5AAaMtV<3H7noILiUr;x>= z;#VRNVfDE_vjcOEl{2SR%XNg)CCDom&(7J$`&W&6*^PRGrIWmbxcLd~c6Z1#_FvU0 zH-!+1BNW>G<=YfIJe%_*PMuOYTBAoYzST^;9lnuKmqLsa={4e>Ed*WC_05bmxM*Nn zvBBis(F}czI@F=u9WFrtv;D;Q9Q$4NndJ7xz!BYd$2dEc-udbiV?=Cc@eFdyp#F{P ze|tu5k#^V+Ix936?eFwmQZ z5>A2r_1vljO>=D@s{Z)lscI01 z2vv$W7W?BeR&5}MHxTde<+hqt1$b^V@#{Ix5aYCD-Vxk}C?{g2`9ph4c#b~{)fUw9|g110(&(YN`ws|r(Ecl-)m((=J#z1!pq@nFmMsOPRNr8!wQO{>$4 z5`;z>Y>?^t^eX3UDmISuabGux6;;e@#<*)c=}d%pY}*fPLU$IDNYqh9 zFl}AkFVfKysZ$-4(#hmr+_;KXGQ2W6Z=N__#4Y6=Ie@GCxRB?+_jY^NE)L#2c|(A` zGDfj-T~UGVYoZhHplO}12DeeICzN%i_VNazmHs6VkS2Ah>UnnC3?>_7F&%9#$daEw zHQSL;Pwd1}XFf16?X{We#QiShQVT$Sfs(qd$;IS;%{I$eShuwI@%on*`f5~+x#6Vs z5$QF;8cAx@;{t(PC0HqjLA%h4%|BA(4*N47hwth}_=2voq-Gi&$taaBbwOO%V(6K(1&ADwwFTNP+z#ZEyfat@ z7hGhjX5UUE-(ipEo(h_6rH;A>PUxxqJx3aa;R}Al$uXb+ci_U=Zl^h0_sJ=DOQ6?9 zDy}+Re$s=W>oZ+sSV_JQgo=4P)b2)p<=~_3555V$Db;+8iPRXAW6VujEtn~8u1G1# zUE?Enm}6#z?y5Yyuo-@1XXwE298$Se=9SQlW23VAr)rsZ%d<+Hoi5ey&q%g+^_}ZE zJfkdX#a3TKEW*dEQhMaa!e!wSe#eZQq|eOV^T_$#XRO3^8D|+T|AS{tO9&y)qSpc@ z=RYfVyCo^JAjYI(om@0g-)5XBQ`B~PY+l3M>W<&qGUu1yeX>i7wRN-vVDFl+}SN#<;nn5|3RVVUx{|9{4NP@G`Y)z_OElKD4 zyN300#{69yPpHcJ{N6wXqVxMh-;>zp(#Dpl!Rilz`LV)%^_wp9O50cDTI*+@S{oNq z2~9jwvI@N%K83fe7l!?6QA5D|E@PL{L?lBnP--n^|rg!e%8S0rPdxNBUpO`izkXl*Qn2z*%*(LJ# zhZ;K#a})1Hvd|?vMmd39L8qh#lDDmTr9ItIM-%66Tn|ZNr|P$9UMnB-ez5%9IBQ_I zWlcA%jYz`Tho=0_htwnu^u$3m^WYPQ^d^^`h&vqB)YGu5uxT4vr{j}`6dk5a3QmAJ zBbwXgO>|ybmh-;az7k5MgIN>LCkye1<;OH@SAOt|j)9S0^GUQvEvMD`o85tls2A%) zR`c9XC7V2*-Q^MG)b+au&SQ!poPTQp$l(PZ*HSPp9GUC&HKO)5KgDO}kyUAat{gP_ z+KwBO!rcaG3_v(rmGP?wL7(6Z$A-epyOU-b3X7-iG;%f@1F$+ zE`!F#PY=TKK!%KW)hm+X^VT0IX7E#au-$GQhp3~vo=6-YczjQMk8QG-F|>O3SJYeO zfL}OO0E@1^t*QXDF)NJ++(2}1hRxh649N1o^Hv6+Bk!qwb`A9E0(Qf}wK?yl2kKtvvl2HEIhE{6v8wnNCp$bZ`m7 zDGK`FVocqzQyI-m|LBdMn@a;xw7OnrUwDrxSQ3T}6l0_KkbtnIj|i)t3x%uO4UYb5`ts&fazOV*a3Y!FZ&^jK>0x8br4uV6xRJMXZ&-UNhU z3BFIi*d`rL8~FBl1j%&79cj_~YuxT!Ve+8f`6hcX7wU6n|9N1=Srt?>+a(Lou zUBzpWCk?BXQejHPQ^n7e7%105GqQqj3$yeWO}a5(mrnYA!zChk&FCO8I#3|36f2)a zKQ%RiNmK*Fw@mSk6HgaOqV3|YWKWYQQE;e!#07FX#K#enXn<4Sko9ezn}9;(fkn;0 z;6t4&mp?c6C^{C>L_Yor&~U6hcqCR79!f#kk8tMg#!EU@BQCJ92lLY zrHvkDTF5$9JI$EszL}br^)t_rjuhRMY}P%!v$>4z?*r6Jx4}uKJxhwd*|mCW3d!ps zB)l=DZe4yRsfzn9LEq^%4nN;y$og9E?&=F- z@g~z}SD+&oRVdbrJoNUm-D=^vT%N+pi{~)>{7I$$-Q_>zmook+EL|DSVR}D*yZ3-E zxrvM=+G0j@Hj)Cnlu|s9{sys0IwGS{&u^S%1cDV_&)21`4dd;rUMad^`_}P*k%OMO zd(W!H=V;z4lf#Ln)~`L9n*L__G2?bUihiL2F;u{*tx$)efrQ6*XW<1U!ikU@rHK3U zjUDA9jVkYNyPqcE9iDM-OulY<*nM4n9@gAUMamT_y@&jLy7c&_ur!0iIPzp5gZ91z z)l^(@X{KCvXlMZZt%c88uUA|KVqEi;=R%Ejvp*J;&+S*agmS-z$Ajn5xa@R{G zuO~(`57*^gwCtr^T}q4ruo4mNCb-ZF5WLT zc?=VOmx;<~^k}rzc(^*&y}1a8%-e2Uc!uY@HmXGb0DWxZ;6wl-5Burjb?#-|?Co2q zSeh{6$jtLsd5Z824LA`mvhixs5;0sNBL_x)tmv|R{aUaW&1IHxwa3b4F_&?*uP&PD zJqp3%Cnrz2LGJFRU#LQTm8SsfE-VRw&WG{kR}P&o$i&@wn!Ep_pB?75LS>}=}TzVaPkND6GL^a z^`6YDF4VY&D$k*UE~xpoXHI`V{aiJAXgJ3ACcz_(YTv$Y#15;L)hY`4$VtZOO0%hq ztC@1!d6g2h%I73WNz~>2By;{M?&az_pSWsQ%36LiK9=>96zP9AN+Fby6m4;0CE(** z;W7E>NVjrz43j>>VC=c??CFMVnA&WiF}aS=9fU3M&8*Nilxn`=dE%hE@m9ZV-1P3#)#}!5^wHD}7Uum6hZj2%Y zJV~V*9mSf=U;MOORI)uJMN43YZB7pE>L5caM<^?5gGM1GpKX0}dytYB zvWAZ}^VY>#WcmZpDND5{hvE=mq#hntYArF_r*$MeH~K_akVLqKPdsiZm#fhmlDWl> z+6}{pJvnDf#v7fET~|a!DPau0BBjn&w)1cmj{&1TB<*{=rvN*=a865`^=lo8S845hU7 zzD9phwM6vle0o&G4k_m&!^z?z)!%7sxskM@bAp4Vh#wrrl-iX@cU!|BHnx$wJA+Jb z-`3ePbQONi@>FE4&rzy1CBjqSs4t68KLv}ZYC!;VZhST3XcU^t_*ergsMJ#asbE8O=AB* zYb$2i(@)#k`I>aZ*8JNLg~|qIaa0uJTG;SS7Gqsx#J~x5a#K4k((DWYg+O4Id~!ym zy~!+ZlM{A8;b+*FAL_$|;!LLgI3o#1BL~KH^-9=0de-};Le6$@=H^}k$5ncBCiYOI zj>D>fR3c{!Dgayv=L|XJfX~6au14r7rAGNNW4UB;rJ~ zz*VtE0;aD-5arz#2}*JCAOxwQ;mMhGBV#p@&@-9SlWrdhIC?MVV)|Rr!gH-%MiIAt z`O}%n5+E0-y0zteznSnI8BuI{1Y2&pWZ$6d7sAH1UEk#a{6r2q&BFuE+)T!3FLJjr zmh`D$$Po-Uhu`$cB(b(WC=&5PP7mCvd4^KtPfg~s)0eLKOK7tV} ze;%Im$~oNwDc3+II9Fj)a9Ou7$k-4e_4>5kYLQsnY_9@eDKm3{E{yq$=+&YVOgeVY z0_ol7Vx^=X9r<3N*c5@*L(freE|Hi25Ud#u!iWz{Pd2%zYYCG7R7hp~Q`9#g-jYlr z>FCIaZVdCCLJ(zjrX0up{26FmiC<*@mCIt$-VcqVe9ljhg^J(yGcoQwCY$<-j6dU7 z68OVn-@ZDChi=Y{BB*Rde90)dDu}CwPrg&0CH0rWs3>Oui}F%c6$KET;G{ks;H=~I z4|nrcDV%1uf?jy4X<^u8j3jatyv0|S%fNA9EuQbSTTLM4yn9D~atvFlEre23w8WQD zMIb07bQB)ZJ~0Lx8dk_EO^+~Q&RvtmI+U=vy);@zd(ER>iGEk{?h#+ znxXvFy}@WMIhMn*MvXrZd{DA#X8=$6WOV%_B8BpirUpux^a3~z2WZh@=rE#xGT~*{ z*Pm`L}oSg*{D|I z=Ywapib6;tD#QE}c@oAqXS)Y7eg}9M&olTL4#(huNfUPWMoDb!exc?opkYMYSnaIP zKq}H_?n2n{wq< zMD})knw;CeU<0E7XOrz)3*87d@Xmy0@OfSI`4|`o_IL zK{upai6AEjF4Ip3LB#!+2NGj$BKTwXJ9KeDW)-&^?5~e~@NfgP zb>dXcNJx|;X<{q;80`r<@qE-gM8Mn&a)Rihe=iv5EP1PXzByjy=H`wqAVLvv1ksBf zz!^9Y72;OLs+L92EOu8vCcORCBpBK}z#q^ipFP0v} z#=_9wE>k2K%S@dmEdM48^!)|5%+86uMSH>(j>D(NMrl{g0; za})p!W8db`%gc%%gQ?ue2%@ZmFPLdU4&^4hUk?1Ap+a zm;9>wRBQ?CIujhSfY++x&=s+W^d@C2GYyTnrqYtM0`t17<~L{wEQl`0aQvrRahpy) zFo>sHCL4?v4!w-Y5BcuafJmf3biesIkT^i zp67bK*@-YNV)!;J#ugb@b{5uk?=!&SSpBT6vB}R(=Aq`JxoM`;IZECH1Z7cTFn0>6 z142{@g6=3w#_1*^|6u2TExHg30z5Jt9_mKxL&2EmsuL9J2}P6fW-!Smu;{v8_=DVR zg~zgp|3bUjcWqUo+OwdL{mSZ3QGUa~Y>PW;w~m+3>L-=~x#O22K;11M89R3|s*-USv5P#H1zaYZX}2-s$Ph7OP}S z=L=E4Dl7B8TM>)BJ4PnBgl1n|*~F%Zl)lL)j3f&i-qDzbm=s4dKLqi|*)X312 zjEtlgc0lWK9T&$=WJ@92@(57L26pH-b!>!mu}ZaqCC z#YrZ5@0Zls`~5M{SDqF(sVYsTvQgrh=B%NiqS{ULw<)Q^Ei3_Wh+%}8SAQ5{m+E}R z2NOPA-Crv88RE2D&gC&0;CS~fk-xIB`A)$L)7|Vw|8T$)+tm{<)c1a#PfXds&&YCY z%lYg2<(CL_^3wgC-|g*_X&D8J#cD-wa95Il!sxR*H#8V|d9fjF++I?T^dRM+qH+=W z5l3EnWq$=Qzs#N?R54w8CxXOCQ8!J9L@@A!i)j(9U92D*&P#ztw9=1ksRG%Y%*E!% zGAQ69{F>bJ8`{FdncU_I<&aMP;)X_%BRV&kHv1Mc3W?4>y9fAraL)6DMi!D@8f}bU zHb!l4Eqc7#Y1GQBLQlC|uYAxHxUrRGJ(2rncy*QjdL28M(X|Y>Q?$ubh~UKw5b#e^ zms3-e?zn@N8-qG1y#CC^$yL)4@?JG})KjEmdk)6azmsE{|NPN6t5{<&f}Pv$twq!% z<06Hpc-Ri4}jvHTj5H80O`JZ*mM2eCVAV@iKgKL1b^nU5}NF3JA z$ol-xrqsuNXsh4GrplEP5Um8%hn!I^R2X?LrY{$tx{z zl{il1paf9*Y9)@h1KQ%}yz{a6HdQ6VBkHd(JS}SL3Fz<5ZsX(S|wy!m!vNQH)MmI*I ziZ5;Us<~!e{OX_FO@TuvrBUPEgPUaugQ8=xz$XHnkJRgM+ zJZ`+N@9ctU<$c$7lnGdLu-N2gx6kZF>5Ebky4s;}!}s>nr828gB5UVIt1BVhI2a^I zxvH$^_gej)ReYak+Z@fm=|^_aTK(awDD{qkfUiW|3S*@t7E0Q^MmU2p!j5N>m-WrC z(h;Tcb%$ynVPLkO9lS^84EQLcf216t+~A!1bkzXye3-P%%o|m^4?+$f6=#byebyv` zl+M06z9NORdR3E8NoFdU(j$qC@#fT8DF5@We{MP8BdisWSHV(N3H-MoiswHU zK7jkzjXhle3{qVCk7xYnW(ofD($}?m=H?iQa)BjUjZ-egV`F3A`whWAwR&5lY71U@ z+iUkCjasaa`2=qgF@%MMtLK8u&%j+bIF}HfZjY$aj@G_nXaCTh>vFm^)8OzrD=Ujp zPWf=YeA3uKJfLslEngwX`%j-bvd6li_xG zh=PSBEh~%m@#9D9qZP5gdwX`KF_57|w(qhkp%1f_jNIZH8gCt;fe!)bqpjAkKT-wS z&;GWnM{&>RFr<6_L|=~A@w^U*QIvX#+tk#AgOBg`=g+4U5ifE}OUsn=-M@cz!Az^* z$Vh2ZQ$~FQgX0NBkxcNU4*ZT)iTIo!62ijJ6;gP8NO&w)ZqE03?f>Ew6&3BeM~;88 zTdLNHxw+r(PSAl9L`z^2YcEo#7xo~g+_-Op=^qYopJo97t)Mta-o4stnf&$= z+6(r4b!R7}KZb4{4DX}#zqLbo=5$CoGOMnBVmzdDt<7dnFN=q#^mjAB7ZF_)4V~(G z`LWGvA~1&BqV_$$u!jit+{}zF80SjQ%-juaeT4MqfzJ%e&ZdrM(FzswLuy}MrU0W_ z1Dl(L=!U@nLT~UZZp($>582Xs$7|irCmX25+~#V=1~SPYFgo;a+V0O*B7^<1wzHE^ zP{4wNhaW39=v8b;pY5U~`U1ph0q8_8sj0IUoXqvNmAAl<%qytZV;C|v`Dninv7DUT z(dDw&I%xlNzCL+{hK_FbAM5Tw@sVio?)vndvoo*RZ48|v9tA}@;{gT+#@o-I32p4` z){FXQXA|G%eAL&|69dOU44me7nwq3LQ^h2(qRxWkiJ-wJBqW6D#fujk;3m7Kral`{ zsLVbmCdNyY%dH82!4ddJ#cT5GhwX`s3`#saysWz+HjH;~-%`GhXUcyTku;vYw=O{= z;8<2OEnw{(+}tekMN#Uw+G3s?kCgOo>^_^rjy8IKzIVq9z_G5CU6q%_A}w>SrVUzL ztI9BjCma2ejB$8mWMm4$n3$Na=4-7~XQ%7!w)=oAoOhBnPBtVgY>@7mz}yfjmr8;t zC1tJEGHnd4e1XdF4fw#B88xFj6aLyVW{l47Wo2w{+^?*`h2`Mj;COqnk^zllRRIp0 z?fI?>(C{mOz6UAkNYZ@$N-&z^=@%6?>(VddWZ#L4!zFTCe2E}k26s?;@~GA5$ZWj6 zzAoW;f38}g-;MU;=g+q#+Rd_{m_+j?i15q9yBq}_7j7=DfKQAd&q=_= z!SQwk<8jV}F)=XO){l?CXPe%)sxkF6xtx}n&%Qa^okUMdOLM-z;qtDS4>1PQa)y(6 z3}(voP_VIkL5Je#db7s+!U`8~s^sM5^-N7e7Zx;~-P~S_Q1IIar|s(POppt?uIx@0 z4vggFbfiEEQ|bYZ11`rm}!fGjxO=x z11?>9Pj7FwYN__O#Re{z3@~5v+f>mDU>|%s2fGt_*j@U^bol=qhz|*pFMWW60|&W8 zr&YT!NlQx$mxLtj;r@2oR0O`QBLLmz@=z;9*rP#qK2$#lQy$EW19K5q*4BKfBm#9G zAMR(WOqA=>G1S%7#TetVoS;jsMN^GKEdm4`Hk=ZJ^0QPfrh4 zQBiRyg%5vgYij_?%*?#Hxfy^-!o5;h+Txp>OadHX>~iJgP>okrKtci$c>C(!UKsF9 zuesb@TxDr#1|~VlWUTWAg1EvBuMwT zn3Xwjdbqpp8yEn+^pe#?BWBYj-JsR#dwM!{{wGibID~-#UGTw2N7hf?9t{3Hy1eWK zFJLnnr`de0EYEaLQAC7;#lXZoKHE{AnVF$vU_jMsux|%W2F&uIF5a8?N$vv!GEAx@ zHrN~=tdobt^m!yu9m!-{Qqi6xUFMJOgk@WQSec_R@ ztS|D@()Br)u%5b?hl|z@4)=c-G$#yH zH2B0O9IDNxvB3D~x9{FPg&|EXt>~1LyHeX&Dce0+Fh zWaO*cTUE34r{EeF_l%T`j4ENUusUjOO@E=uMft!9gi&7itFnO_@F4bw3yCq9o9pfa z>&GxK7@d@?tk~ePlHiv8#r2B6{rO4mIa^->XzM;dUl^E^a11s=LO|JOZ4A9A-d$}S zi;0c(Clhd_?>(8XT%%J=Gi)yXflX)y$`PZF_f9Al7F5_6OvbE9!ensh=o^ZOa81XJ zxo6)hfU}8{jb z*wfSV==8L3($jJ@1J>QcgWc=Fy~*`F^n7ijb4D*LIvN)YSdH|&zsa;&@6mmZbiO@lLv8 zT3jl+~4f=n)I=Z;{e5>K5s;bJQ-K4g8 z3j7bR$<`Zg#$*!ZC*<^A(CdNJ>)|@@#8IMTD47R4GBOg&nHu_UEx>agOVY#TRvim6 z(BBVmZOTK?utcEgnwaFHJ>!XqjSahYi+e~QCdrd2eE9GI#v94{9@4gUnV_(Bq*23knF@FnoJit; zJClhFXDj{R3_@J9B~j-lgYnGlx@|B+X+n)(gwHQ7q;+*OPFNy<+7-kdWO7gjBOI~X z3l9sE000BbcMe=^bn2X#P~NO*ZNPhS*GVPsSrUL`6CcL<`oswMC0)=ot5#vy-`bEa z;IQitoEh~|bBr0B*la8{FV# z+h7nK+Vj8 zU{-x>3@jQ?IxQVtVakE=b0qLkE)jR1zheUQ^j49zHe&-66A*jrMq|@rV`FU<*DXM^ z!o$NYG-{VMEtBdB^n$xv2Wl7}YNA+}gQB%*Jz^g1`JYdX!c%$pv~q0|d5V(?&IKp= zqLkiCZl$fRUbe-Bg|}ldjQ~OZ=__oi3s;elkN_Rr;udaCSwW8afmrfLkmSqj=`%Yi z2LN_3C4#U5s;jFjG+RB%5?FNttE(OA>&1=AJ99@shy!R9i-wkV4WMCZOG}n7)ut+t z8t^vV=h8;e>BY3FlR4{d;3Vqn>w~=_oB=LFyV=#$t57rgE6Y86tkz=Dt_!NU`7WGd znqYgjOcbZBe%!&`=-?naFuqREsmlIsl(Kqcy>EC}#f5ABRyDT%+gAbZf3i6EtLy9b zsVTyzq+_Ms?+NydkAL(J3@jjx9UdCe{rVNDTnz*GfuCT_n=1O|=Sd(Ch+4JjGa9^* z@g)Ee*OM*}=7XMm4g`V)9OBW@kti74@RWuqa9h>8U9y0&{n0IKj*MFQ^4svRAR6L#t8R36pGN&G{qSKc%J)mJl^aGsUg_!qbjaGW zkDs4E*I_KW{R)SrFprtMaJc|!22geDpPQ;r47Jb~6&0Cv6}ea3wn|8&K5T0BHS`$;#@`i@>&eCj4J!JFTXV&7S>@qCcYTc1dj+SW@k}UKo`Ir`2Y(BswpY z&KYa!5-f=d;fpcllEy}cbLY<8m%1uM5^%;OzN8zKcYphK3kU4B{rg#P2?K6l*jbmT z$>UG*08NVIoQP!Q?hA6j>!*UAqxuDl(DBXu?@=_jpzq@<+eo&J6^ zf-!JDTn`D+P8n>z%NpgmtbP?e5B1oX;z<8dPCGj-7GrAam$H1jbti7K_C5h@UBXTf zb5ZrD4|$hN%Dh&7Fl?D9r&nBjyZKCDpzK8LqwNr;*SUs^CZ$zMIO$lwc&QR<+YnQ8 z*}OWQay>YBL!Qf=s5zErR^@%1Y$pmG_xkz!Z%<52Wtx?N;Yl_<`udb{$0vZ5A&aZ%>3ME4?mp(4{p=Yh zawm?x8Yc({yIsQa+(>{x~^c~;7e+LT7Z+Cfp?)wV& zTU++tcqo4H8bH~)M6JW}^75~7<$%OMqJ?Ygv$HC99zIl!Q+*IU?uLwzZFrfA>goZS zU0SgZhFed+m&vRfSLZ7bbNhqtiqc4`!efexkN3sl|Nh-$uxD<(&h1oxP*s2MSalV` ze^6C_uvlzVh1TJJuylXWZG4Y)AMN=27u@`li2Hx$yApQ;H?C!1P~3OzH!GHR{uAKJ z2A(6`SpK=Lza-bNNG{*GbLTrz&LA4Z{ap9+lLPnjE>eab5en*M5@5nm|LpF%x`UvQ zS5OE-)Ar;E7k1v`-^~{w#ab2?e}q;%l)Ae9-o1NSN&5PZcIV!Cd1xga!;0&D>TCVY zEcqm-scHXk7yU1p1@{FuH`(=@XyR#` z9nU$>f?quF-aQ|n6qKO=))(Yy97t>;eN>#wVn&+aQ1AO(qzP5R;T6)TcYO6i`}3?Ke9Ftoul zS=Y~Oewx-A$E@m;V>>_=&m=rdY7u=BcxG3Q10&6Hu5H^qZ!NOl!|*aeVZ zy?tnzxX^%3%ZHok(-*5T_a8c>u=qiO*dlE#s!z~|w|esAw#zAG5GqLaw00rfr8dCGWvi}x9EEddgb{ZMfdM(-EAm= z(fQ2#+9w8NPCm!E16I1e*lp2b_>lhanN8H_4k{`t_&RRhxKWp)FZOP3=;I5qEqg7z zQ1J;o#!VPr=-lJUBVI~5{tv{AJpD8&1aBG#Dli{C9QfdY-`%?mxi4OnH#KdSYTLIY* zpnsqL^^5!kEPv&hMJqT??#sAIgVn)3F-s`8jYdF3{)NnDDwQF%XnW1t+;#A9v6v} z12i8!ew-#sfJ{`FGP};viKS#s1XDO}J{?ZM8?3r1;PvVnW6a8IvzI!yMkeRVI4iJx6-FZ0U!*lJK#o z=f_#V+Pt_jqO;RfhjE|5>wR=mm#H7^p?uj<@_a^iV6myDwLVULadp_Q`T5geM$sT% z> z*KPMQd+8HRuJ-Bf@4t?<*#m-;k4OAJ;C{W96CI9_OW^&Zf<*mrLTlr`tOowPt+2CF zG#rPwOsrw`GHc*sNIm5bLY$BwG<0;%q20^R?%@9ecLO{qhlqldFin|O0U<|o$X|XT z(_BN!;c;^uY7{{-=V~9F9R6c9290gy4GP&PAnTb@VtmM*p}DZN{_FABu$^52**{)^ zsOj$Rrl1n;-@jkVb$%0``l~Lt#hPC)O_Y_rd03?-)!hVEOplr@Ef?65e3SH0O?|<@4;b=g*DKor`-0^hXDt@3YB|d(qLHy)Pd{SKryL za@xiw0Dx6~>YU)DG|EB$T&Lx&O+KZ4k#463Mr17Sv^SQ+{R?kTU}eCGAtUB}S)H}c z(hfEg2LA|z_ksg|Ssf?Z9t%e`9O?w7YoXW}IpPEnMW zJQj<(Y+PAaw|2K)rbc*I)_`VG-uN%GBz}I>oX@Co1o1$GTg$|xYiyqQ%vh{LLKbzb zMBvu=CG5NElm0|?y)k7(dHVEH^d@RZ622O|UW%M@Krn(%Q&uR7B6%WseI}40pr{=E=iwjVH)`pmF7yJ$pt6n-uEv z?b&V4Yo{Kj?`W;pdok_Yzc9VcVd)Zw^(*1)R4{E9p(&bPdO&884u*bSAX+GI+Bf|D zS3~teKH4dC-a4Y~Q=#w5ya`8DWJY4 z*!o+#T-U}xo{){(x4W0xu`k{~mnMB_%o`-ID^~c2+=~h`yKb~!m;3WI`54{3@{my8 zGBRvvn7yN-I3CHkt)cXH7VaYumS*`z?Ob}@~u+O6$*xigx#&S zMjv|M$dMy?4o|eIb)sz0w#{R41U;F z@*i>6wcyp1GbSduT<(+_PE%#{p#+>EpO}-bTx(8SJ7i#Lbd((gC6};pFiyRs0^g97 znvRB86((EUfN&=)?69Hsq`SULKX}Uq$Qm(j@j)t z5V>E4?n#5~fdae48xeoUr?%Xot#W%$X;*CU5Rq7RM!b0HjOn|F66gwpI5yr|1+V|_ z7Z9C#;}pI9_YV@WYJKk_lob`1E32t(N5cskC2>F-ldErkwE9Xx zgT(FO;qkJiB@|~@Fah_V3FHDZf>lp%OIdk2c6IUp zHQa-Ry{@B}ZPsmm3Bh+<0&7*fijqYC!DPTED)d0rdZstjP<&2ae>ll6LlBo=zBYNb zCESY^jDK4p^DGm;>|z;}(&g{V-^Z*lHB7Jar4ULL-TAid+o^!s#T`c3CnhH)%$w`$ zOL34901A}#^3|(Ph+mdR`53bMW+u#|Q4=z9XoG#z*9>=~O%O>-%gbZ*77bCWKpK9U z`O&v!>|^EN@5k=+f5L%eb3<8Ho1Gd~(aSlnh9G36hK2^<<&}xa)^7U12Ny42PW>U7 zbrOBhYslZqfQ-sux|C&QDS7rojDmajYPZvE5^#TQBJ`=JM^5tcHzn8Uo)y?ndX}y& zaja2=``5L%u7$g&Y~q_Ty!q=qUn-W_v>Y*ij!Jmv?p?*%pCjtG{QdnRB3KAflaZ67 z+fI1OyV5SRfryzCa-1+bQdD>Dg~)zUI02NSV`5+dTRZ{*+rq@E|9saG%rdR>@TM}7 zUVMmVeVu2nco{J(z%o=mHQW&lS|kYkT2NZi><#CInLc3K2mJ#B7aIzY{R}^VI=LUN zJ;z2JC(diw2-E@8bci)UP>FPl@ZE)1UIUjM{N;*F9Kxi~mHcAa>J`*P>A;tsL1 zQ|qR#4GIpn)&JkoDc^@$#M}`y21f3oa};PYTPp!Ng|f0T!Uic{xRBn=9VO-Ba^}J$ z-#VAToZMOYlkYx&TU@zjP4jEN{Y*@u>U@_oH+wGH{bev1o;H3S8D3hk>|J_)Sb<>odp5C^%I)rcUd-5inlX`=v zYo7mI`F_{#W3*{>#+iYMDY=z#BQl?GyFmjd<4r+aExb!Vn+_4V*C1-2Dt1jN@J1|e z8#y7tcN1#Gs_hxo{>~Rv&-ubZ{1ZG0{s26@cTP^u_>U+B-+q_%76JkSlz_@|z@Cr} zqOhW`=93A%caKv-;zR{g`;+X6QLgpZA4WjdkIgy1Bd7A875t_V-@m~|&Oa8ugeZw9 zM^pF-y;M8PuGv{iz=}KJ`qqY8cZGNF+7)>J{`Cml^jICTQ~ctm<=~3NRh-8@Q2{?M z%Q!w?1>VJYG%~df;14GtM02;SDNW7chUSd!4%|Kh3JAZj=J$OnDk{);2w;Irj38{d zpYC>{reiUvOwg|vv=_EmElMx1U9!? z80ubYTU(C|?DJbh%ryRg2CQkK6Qgi`T8Eid}!ROSBRxw33T{WFYEBo=L3I9_-)T0x*R`vqC||GNz0-Noy?A{8e^T|4 z0-(KzPmxH?=&NC;G{7sUDI_LY`6pl5XXAC3Go z6yBwmNn@L5FjFD`73ra*JuR(wv|iYan>R21_^OuG_2B+}cAO_?^(`!tZm^1qGE8BG ztajLw)hxqSMpY%15Q^h&21K9yqdQ{NY0~ta_N=z};cS zcC^djEVcW8N$B3_kHHzILqewmMKHWTR8RPlJ`_5I2JgxI$gg(G|KBljrlgJ{hFDG; zd0fl8lJO=9TP_%K z>f_ZTB{%PDzg6nyc}_+~27DBeF&_T>WBZ+k(+JnbP{Hrkb{rmSX zr1qg<=8H5eb|n(N|B#@NP#NCBI*?qsx#DQyqDdX4Uk5x**p_u@7>IcZhA}gA?0Na$ zKjg&-~_?T)2C0n zgNA*f7X~3*d{4njjx8Bc3FIDj7?zCi@wsk`Mb#^BqaGr7-sk#_8^kFYh~MB(X&n%I zCvok?`~wl)s?_N^cO@&dTE zi||U{7k@r^;OvYB#PmIT)UU?Bos(#2ZOzsDEXmKm2Hpqqa?snrJTheRuT8XJxZ!I? z33d>)nT^uh=gN&|I;f=jHh5cn-8?uonc;|^5T1=yPYsJ%FJFe8FB^u^q;V5w3PJ1& z2zP~9GB7yU6Q??1J$h3+L+{>AZ%{=qW;gb9cZRbx*LvkFtMMN{#vs9qShq7^X`@+v zpIZcP3~70+goTC6K?aDo6~uy}0?T~+*j}9K%fZZV!u^jXLMQS@f`fzWe-^fELb7(P z%wj=V*V`76tW@9H73#W7vTZ51(79XiSmxVUb(%sf1IKBem#k{#5|wh<+`{TV^Gub$0p@aG83X3cAMo-!F*V} z`5fIb(v@o3o6j8=a2P$EiFT`@rJ2}?=*oFzu0S6CuyUu`Scc=Yv-GZi63b(!UMi`o z(ve53udm;T!}HZC6{X)#?(I4sqwbNB0PN;y81(vE(%9fwsfTN**XBWME9LBni2dcu z2Wubg7c{{YKq!zf>^u$fwLzJp-*)J>7aB_#M7w)>JW#xhMmh^0T6NmO^oB~XmUvU( zCaGRB+I1@@N9MeKg#r#BPWhfw0$gQf_rVffq+?uJQ9;GD=akl* ztL0yKGKt@sZ54D}*sn_ur|B^RM$L@(k`Fx?!0O+FJIvAX@3l3UIldpK2CQ)DnVHMM zJi$x>`yRZH@y`Nma4jXA7P8pT^)L*gN_ecjh6gCgftR>=`2Psr8}crhBI#2OEGX$s zu}PochL)y=$*KQ$*qtx!KV$bBtgHdobyK+bMITC1A+Jwx4dj`za4f+t{pr42jMscgLI@}at28Jtx(Ti2hzVf zVEyG!V9#&Ox(fA879i}kX{3uzR85DjLJEwVGZqOCgiY@`g@j7h;7CcGh^PXM!k5!B=cC}{fs;h5om9$gZJc6s4c;FRE9p7KeW)TMo%WQ^+ zp)*|OH!ux6?eZ#{$czU)bYSEgSno1s)De3HFjf#p=I(%3j!w-0rb?Cfp zFN4D;Lj=HUM;=M7R8e`O*OanyKbh${m9qv*s#KQGyS3v*0X{w=?^4v_+=#&S0N+lV zVmT34sXn6dwhx*vOVqNi|CpcE?#TCMH+DVd9D3WIxJ^C1;s1}MhDGd2Fq)eDoQ)w8 zm%cVuwboxg^7uDvJZRBbAd!9k&HuE``_&)!A{$NeZwPM~( z`XR|Dsf<2GO7JUfmUb2gSmuUU&evtrk?jwbM>jv9u1@2b%iQGT6QJ_m?3OgcNP^;VNE|#nm(%5{ z0@R>X?z4I&<pR3l~=zeQZt z(rlUiS*$Gk;3ns(r>E=ZAJ*w*T|01e@F|tzI)-)Y7}CrX4;0d-9KRU7JLP>-Z0Zg1 z9-31}Gfv4}yC+vibKOfWIw2(|JE8H!@<%@d?iIXRF79z(_Jxe)e#_p6KTJkUWt_yF zMlQYUeC}7o*5)%&2AkaRzh5pp@Bf6K8_O+|d8GihVR)GUHJ6J}owZwPV%d8&juipkc?U8|$ zY=Z8=2}N1|`Vy>u0W!L{q$H=f_$DyCo@fv$kCT#UVG%2-i&DVc1Qi7{AD$i_OUkre z;@(q;BN9SbH+XXN*gIZU#1=;#iF^qKYQ5ib@-I)HX20g?DQMBiJ2MIRxD7l)m-CO+ z(!VA&ms3+mXJ%@}ew+-+5SsymK=fr;MiWvt0Kmg*czU2A_CB&tiS6Px%Rat-^!~EE z49znqJR}zq_v~pjLW7v_^r;tgAz)j)Bsw@ZvdW0u4;HKrW=MkYvG&XHO z$ht!pHbTjxS-G+lfHULru- zQD7BJN6p0LI9rl+Qp&&w2)fMLQA%)lTmxuAiQlpR#1U0hMSJ^6vJyki?Q>uiGNHlj zLT?&Xk^iGdtnJy>H-R8woj>#H*5>O00hMUsy9WpPS~@`S5d#${7l?Fd2u_2C%)QVf zAG6~3I0!n)(fOH6Km$bYr*!xA`J$+9m2usA_Uu{WwgiLe0~zJ@V(kInC|0QH2hGiQ zz{S^lwj8=EJ*$*Erd=>4fd<0nZfIx>@U>o!ddE}&2})6atiD)x3ZLuG_FhwVAJiWHE3tFj!VveOxe@&wDji8k1^YilB4a}-bd|3 z9PZttb;PG0P*z?ET)7VKkt{v9+}h%jC7M{Q<09G&+{g+vkU)!vk)3O(<;y6*U<541 z$~D4*ezCufqp`7(9X=5JUbHOlaccJ%F3vKc|MDXf8So&Zl%r?JYZu)QtV^sBe^{9> z08L#H&C>|y=fwPd%NT|fOMd!Kib}$)4r<^N#*07{NRxp^`=Ms;w^8Hl>;2LJ|FyKV z5>h_nfnxo!OGs?S>=Y)hRs>W!nf5AZUWG~D15f`Gmc?|f+kz)7Xw@r>4ba!fLH;Ft z6Knv4iG(~>3g1Q3_p~^4d0+@A7Z&EP;;bou{hG$QJ@e?!Vv!!UR8cW4ojkH>z?cwE zFPT!%d3rob#3&v4QdS+=t6@zdMjkSk0+*`l1EB+{moU_Ni&<<905ydI>W&zF@z*Ru zXYPGf5Oru~#|}K8rNwX$v5z?P5=7@~mxclV19!qVa|VEPdaRPI_jwkDaG7X1$>zX} z<8|;g08N5WHxIT=%}!dv_;j*&FK{o$5WO$KoCq#gN5!`kpr%?g9_v;v)l71J9s9k% zp>|d??(yvS*~Wsg)!Ueyax-_gAJJ{{UX>u}#Mnedm2go;wE)9I!}ZBA6YAdwi!&Zr+4$a&q!fZEbHD$CglF3fZw}4IxLz z)x1o`V6Js_h<0~C4%^|whrbA6SIq1Mq5_4%=I_Q~;m`sJF)vMkJ9<&E85a5T5<4?1#@z*qY?;AK=TJk)u zUw{ECuN1R3{FaaId;Xa*A!Qv)G>?D?2%V!ni6iwJ`mdL%g3kjqj<5(@I_ke zvuEqUUQpaoVL>yVfdq|7aO-sg4QD^rpF43@w1o{XJwWp3EO+LG&F<}$>{iRnm_4x5)M;;Hf31mhsH$R^ffDapx zFH$l`k!?ZS{GR%wv{QvQpzXmIr_B#&3qITjhCECY(NkX6*6N1!g6DgM(}uHnW)m~> zPH#g^&1DJ-EnUos2hQ-?d3oa0@;WeY9FAIaWtbVG#U+ z2^xtq3)9B2Hi}u^&EM+ZFROh`_>uWG{n}7bP%vB*Y3R;QN6VV(_ zx!Jq(cgaWz3lr++*OdM*f3Zk<%s?{+^IJEvV2vKv*H5sJfm&}Vu_k4BBYoUWnX1JOEj@#<9xyot0?*))E%egY7Joq-~W z%LEX7CUlg8S;{g9WESr*%j~C$RWmc~4?@6ml(n^O#;@Mr5W5O&a}QJ_Q2jG>Z-Lry zKO-G%`b)F3vx$O*p`@V*DvMnhTXaWL0}kx8rRAz1B`;{tr*XDf3^dvfHSeZl7NtW0 zz_e|aJjbtn8(3M_u(7d$!Y;unL%87Q&pkszLJUAp?kD{%@u}ieGR9TB0wC?t8`+(C z{_0!LkJ6D&mig}=J(^QWokj{}Zd>vMB_(NuJn+-$?5snkDiVVpy2m5mZ@2Iqq41qM&iu^RvLm|2Zu3(^`d=8T>VLn&G18T`e7C-=wzk`o zvDzi27@xtBL+1C4Fk*`CSRT%!FE&&nm39Ns-zr!_&%*IN{gtqYj0MN8DvMt{Id6asiYK%vQ z7c*R=Fi;x<@AbDm@7tGbYB0;ZdVtJ}p{e@)Dhdh&V2gmEp*k%9$0{U?L-?`K=B~g% zwdeIOHjNi*u5<_RT)-+w{pn|~APF8Kxa+gzmG8H-lXViEZR3^Mnk&&4kbY{uYw;JG zgA^-l0GMxzd-5|bk_Vy=&X`Xn9?L9dz_+eLK`uqV)6?Hi!_3S~-aB|j|G_lT<)QNp zUXgk2A2d$%w)g#1I=Ho6mn5l!A9c)9#5W^flNeUHDL_T@7gI$y;@jU zj83)~Zj+HQ>@|69Sns?00b|Cl+$3vVN?=-AnsW#7yoO<*y38KOo*t%6VgY@%_+sI} z4Fd&R-P=`qF*zwe^@oGhdOyXx7>Gf!y$kFKueg?eypH3~?`rr}*b}v?vynvu+@-~z zRgAWost_}a!N+&S!OC}7RTaRAC!#%NrIQ2P?0iAIerP8b4J+T?qJxx=c~qgAw_Kk$ z@FZxTX7BMAs;wY3M)cRyksi6Y&^;S!s}CEyrY2k0>*UiF&)!g7m@^bAwDVI1H&H%P zw9U2e9j)~%3?V5%x!2OrkcEYs0SFqSP?GAQqS;BuD!-yVxueP*gHVUU=aR3jns3## z-$+g!K7rAKExnMew!!PYp|`IuSe1Jl_RIDNQ26))ps*atoB(;2j&*IVtr{qhH4h~; zVP8L)d%**&-{6NN3)~_-o|1&^+>(&5`9ix10AHCeqyZY=#_^b_ z1&d)FZHf{v1No)!AB*>KtE)_eo@Hl$eaIBXmuxWG3Tz{OUONlABl+amCr|3oL6Gln zo}2{4g#oPig!J@4uJtP`UcG8SISMJ8!!}dq4&Kr9tN0ncetLT8Ch+Ru@XNgXxSw2( zE{xiLWAX4abVu#zZgf7OYly*3MchLLyP+4M(;nPvC3N-5%%tw_&wXNEC^LGjDq?mIUb`TQOq4v<;64p*_5@(KzZ%ETNBx&#L|Irx!p)fIHA zHv2YRO&^ozOnPi7b?xs@6WF9?0$4sh@m@VBEbIns_X55J%lP>C(vhvgJw$Qa^%}3< z7badUZEX%11+jOO#k?3O@1taKYluaO-Vh%O#k{n7~Md|JzohZ~yqxsBM@G_>(YB(W}^6=KT7!Kx=p244~aoOyK|??KnBt9}|!cN)!H4 zY+N=}7#Mi{<{hmSeq}o^{`y%X{Sg2fwe0ELB5(LW(8}CE{rdvyxvAE{eHJ=9!^OvU?$xddqFb#*M7Xj7PWU#of`EKu{-YYgy3 zr>MwcE*&+D)J|B_Kr&%+A^@l~Vx~=t^XLwraM8W(k7nB$?d`(khpzs(+hAh*{o%DE za9P2B?2T*!4h*7$5%Ylh*DiXg=KU<0*oqiVQspj3Ee}Uyb~(JnDph8ybwyK#@gb}B z%$3-<@X(=qx6+croAT7)h3}F2#Y(aDUlpi5$8@7k*eF^X8!Md2xQ`dD09xT#E(jbk zK3?9(c%5~yogD^WDmXJe9SGZqK_z+}IY>(h7^Z}N-ug|f=bjSRm(QPnY$Qg7U&KNmEm&uLFvB#ceWi|QLggx^`-ecB6 zOR>`8^V-*Vj6!&Z4d#UxI37HSyYnb!+gN)JkBhFZP@(gK3Csb$@dY=3H#k@UbKE`lUV0?W1k@>eHohRj%|C$RnzbrcNB3GpP&u7Y)(pR(XvvDQE`=1A;DUYEn zAzwK7b!n*w20#bkfr&*Lz+iohub$|os`ox*N@{$nv9>k<>&k!2-ovi%8XBIRXlAj# zr%ie-GhzNH4JBkKJi#8;z?pF1;6c$Ub@0gXc*z+~fs=B$k-BIFd%(u798YWIMKSg=aX6V~scj1c$z$H;0OV}|mgn}1~ zEy>5vABX>0KP^VR%fJq^Pf8dULMldF`qE^1P_l`cnRnqN*huY**F}34y_yQcmMuxo zmlVeh3rgE5^>(+J{X8!;KWlm5BW4HLcd71XgLC^XVMQN9t5yWCH)nJ`zt^7c!SxC+ zos`Dx_^52}93Xnjpu6W*@x>@HL!Ist$L(q9@5r9Ot_dJa)-hzByw ze=6q=Uhum))GhW@VDT?6z|~JL{p_Z`o#5NG>j^o0_dAJ>fp+>)-Oz9c#|a@Yu@lKh z!vR<-aT4S}EQp|4;1XrdpgQmb=0G-BYcWD6QGsWil%BgTIY#%)1smjirnHtxBiK!!A}RWoS|y_ z;RpEaNiR*Ih>MGNqq-lmwSD&e*W1r>U2j%_lv>WWv+1wb-hJge-G+=!+{(%V9||@* zN2MP*iDM4^BfLf^Na|z_m|s%RJgXXhb~5e!4=ARAj~?Adzbnf3@LqqU4{;2E16~0@ zpT1G}{LJKF)s>ZY8 zB@ z1jacSr1;W?1_q+Q`Vc({Z42i3Jb*0lTT{c6W$$BdX?YV>X>U6}erya$GXh$b!=8_I zdI1I}iaQ)*z%dsfW}uBRg1(e{d3Xyxg=0~MiN(he=@*+wh>)u4-O$y*cX-1Tz*R({ z$N`HSJ$33f!i>y6N?UjQu;@EdfCTkdl>y}<`k2KaFer5eJv~+;-RV3D!MHF&S02uPrSwcuu|NYi;El`=Juc4#tD^_1!1*`16V)EikYin=+gszRY4}}C{i?R3C zcPtfhST_>n{>AvJ~MdB6m89B2ZE13TkQ`$5xRJ2W+1W`r!xcj>$# zBr!kYwgyu?EbY(ptG;{afmHv5Tet5;7Q<8xIvh^T+eCU05?cR0POUseKS#XdgT^CK zF%j)onJ07>*NED{_77_B{BOm=pz8JO68MYgV6DY=S%&kh1P55}vNSzcL>zm6MqMw% zYA`Rk46*?c3*=>?rdza~!6+EkDZ-+vYyYI@qF&AIHu!9T?q?Ml%xQaemJHOC?X~Aw zLuNe@RKh!>_c0TcV@y)g;f3r^$Saalq%1hxFZST)p7(esn zb?v3>VFsaGGPegEneHOaO}KP?w*MW)RF*BWQltra@7SbR8P?ILP6 z0e9q^s$L*P79U0?#Bq#M9;=0m^6uHwk{{8Y9Y1+zd%`XM1KP*dQy#}k%%WV}NM(z?#kle*`CSwg$(*M@8aeb`#Kb#Bx; z>Jhg1OMRi;WjB}t%6ZEPr$XUF^zqwg4@Ee+ zASwnvHNe_6BvudunA(HF34;m+zwYX&tJAZ&OswPExzh+eJBSYpyJ$t`UySyVQZ0ik zsHivwYUgw{e|$c|lh+cP#dEij=)2DPGJ81hr5L}q^k2f~3v$#4r7*eq8tp*oT zwTM*!Mokl;2Mv>08N_Jmx@#@XC`j;~F58lJXPygq#ERQQO7z9tl2WNhQcjG|Iw!=( zuK+BG?Y6YAIBjN@peZw?{)oS4O31|H2_Zd%(L|lMIR^Vme5f2MZ{{eBd%`;505Y7o>L#Vm@RZW zQio>Itr5HjqUm*W^F1sY;Kf0xU3!vP>zSEVfJsSHgw4tAAzPx8w~SXx>LFC7gAjmq zT7BMDS06TC6%2rN6s64^=v3?Y@q`~KNnuv>k$bw{y+$;$5Zt~px4UR6FTCd#Qa;RC z7^UFXmAGLbfK5Fvl>g|En9hpcPvykugBd|{IJ`|PEmiR9pvWj9V4@)cY}0G5y&-zF z;qihpmrf|polMQPPIuiu5Wu2x4WsrW@71f!YFUNy9D=4<_EqaUgH3s7hHC9>H_TzRimyD-8?>xa`A}ZE)&id7MaE`iN2?t;tHvvQc3uU}_XUl~ zrE?=%6h``4$1$H25J;80WP==){dWH=4DIy;TehoR4<|gku_arMEmD z!8Wwv-W#j(?yg3kaQMiPIIM;{XzM^t)WOn2~J37M8f5?@?(_YxeBK5x$K2I|vMVKP= z2H=K|Ah8_Bc61~SuCA)CK9(2K0`K<52{NRQ4j1GaFUBKa@w2nY;r`b1AnZ<}Vl)>{ z|3xz`y`k$l)E^w|jrBjZ72q zi&2vqa&ibn$o)$viBt}GHaOew(it1RZya3;R2fpKesAM8A z6CDPxPouB-y9t==fl>`)uqIZ%(t1BH4Eveme6k4jZ%;{ruUQpiaKPtkFn)e{$S>+} zuFOmMCaaV%=o4Ty)%zk>5+lrXv*@$=53sM*fa5a4v*z9wCi1V$G+S3>{l#q{H**u@ zCNi}REt}gg>Vz%^9*H#!9t>#UFTo>?&W#jrD|}?VN?+apUl*m)x@P3BuP5Ay_|$NiJK5Ma;ns}cn@mQw zW1P35V>mX6YaET&-ic~UY}=4D(cT@xhQ4+i&b%EMZ7yuT8kJ&qF@uMlodVcI#yg0y zAFr*Xsw(m5S=9~w0c`X!A72>V38M{e)Y>%sVWnJGkwu@k=#OM*$$(QH$9MT?@g0C6 zZvl555vOZSJ}{`-Y3Nh8xj%ifb?ZB}XN#vSJIN|k4`>bI(jEKc2;FOMH z+!qxj?=~_7P#3`DHpU#HpB+q2Q{oG`lai8h#Hu-N|LmhjPe#5TyoRZ{x-_=Uii&~e zI*em4E{6=EWjcmQ*VQbNcgfsYdATR46nN~mEQk=Mx_IHjW1J#k;uoX!u13}1NtuF8 z6@i)9_QC~rz$JoG6LWL#gHeeJw%dIEEY{5NWYfQp|VDuzT_cpK^&2qn44HVj+SNJER1%)6IVXtoo(45JGc@VWI z^vHL?{A?b8bvXQvvw34PxviL)C1{e%J1yXy3&mgRrrEE0vc{*6l+mk%GXxV0auy&cRoVS>g7pDQudzVuQ} zGl&8arv}mRfgxTkgabV-=$S0@$sJZ_&d9@z&-aEg^g`!>{M^p2yvCb8UbTJi0S_^t zae%fj2801Ow-2#;&CJZ)jfha=3{sMd$J3gs6F8FiSn z@ATUb^6)YA`UWhogoK3aWIEFJ$`#!k#wdJTj5iZ;egPYSl2YSaQ45L;MeM`l8p8NO z&35_ml=~magOK9&dBnQVn!W^iF>)9_A^FNhHU-z(0^cDoi-Um{{}3Mq%xW`ZfM>_4 z6G$wW6e~T9DS?qgh`C8M$m5hjABe=dRQXe88&0;B3k%6(H@jCV*vom$J7ZRa%(T!; zPg5vJC~(JgBpVz7N##9b#7%*-fXJRH1$F208?!1QhQacPU=_qvyuX@{099_xsU;<~2wButwg z8fZtr)zK3tRw9j%M3sOzL9;bJ1W*cLb9GVN!aq_8{vAI8+~$`-aovWuEC4gqRw;+I zh(n4f>)VPx`5;W1$&#?mnOY!{*Ln64FA6pREHDzF z>XFs8l7jq91w3^aV{gN_KrAE#?L!g!ve*}0t`PvSF$SOwtSE&7+6?Qx2YvLP`PPtl z{Kv;_!I2&rni?o$Ez+QQ|0dLE{BwZW#cqN}H7?&V@X10Q-~Q;aW7lxpE~lb0Lfjc96q`=ucRrc?ke85WzbdUZ z!t#$7G5@2sKF7w8FjgdJ0{lfC#FBIR?UdF zT!VPvbdu5yuev*kP+}9tCepq!1U~~AD1)GZ+*VJ3Nw4J5nr($XlxBsZ59dtzM6#s{?g zv151Id-|Wbe8qWn=Iwn!GFybHsOllGK?$j;_t=;=ZbZJL&alJ3VeijVL|(rb(b!?UU7z$2tX5};ocYm*Ori&7{n&yJgpI1^G8?VwhiP& z+=WZsOV^nz`bOcyXds*accTeTQJfzddU`j|06#7$FyPt1ua^`5Z2exL%}HseD&AbD zsT(PdX=1h!gBkNPR9G-siZF^HXo3Pui*2k9R9HyLpRuWNki%2i^azLsE<;4YFq4d8 zz#QTp#~r6`QWwwn_IUIy&huDw4vHrSGqqQzfp!7^xQskCsP)*1usRay;~YQ*&ivGN zQ~t?os}TAI{@XtF&abJ$g3HfjhyCO?{-V=1+S~L9^mAE#{W=6k`TF{<0PN)mIb7Pe zxcI%trudf+NvB6zDe-~9-%1kqc?)-FXlqwgogoAsk8!#@ZtVj&_O-9cUgTfQRCzDb#3~&bfP!QU z;hQ*hiJ=lMTBr}oy)TuZQIX>WJMuHYvXg1YPeF8|%u+*ZJ!C0pPcVO5T2ewm{4lXT zXz(^V82ryI6lJSNM^xc@A|ZYVjKUkex`0--%APQPV5g07T?6rWkU&w`UASF_ni(?B z(MQsk2{5)$HN9jEBj9$u0Owb7f!CesDM^%zP;E@1~LobT%ewih+blTf}of7K7RwESHb`B4tJys zi+T|6CB|EaenqH!?761Ig)3Bjhg{^r>E1>qe~h`_`{EZl@q^w(Q&|u^cUW^6(-Lwg zPHZLtDAJMiI5_?!EHr71F?C6%HPOnU4V5fGh^wL(TEu1!BY{nBDhmy7{93XmH3|00 zNlF@$45-`&AdJ&h>)0`Q9NLGSlx^!1LlDPCf~L`=K1)gJ420woay9=ynhQ2MIYCrr%dQG?E@Br9n|0~I=P^Kfwy9bV*o0A>Rb_j-$Tnt1Y=h@?Q2 zj<(qbK<$3yyN=Jg{^2Vy@tl(?wiYHZaekxM&pvum5Fl3j(1K|vK|utvww2?L+>Dn~ zbOgoz6ta1Z@vc!W*>SrE%t6Le`14m?o2I@z_?z&3i~4l3_5TIb`{N^+|3ZnG?4Tc@ zlQhoOCLE2yttF>TOd8Kv-Tng(h8eE7S6hk2gXu+bqsivYRkX2T3mMOzU4w?~%jTN! z>?!7m@DD~0Zb;nCIy!P|wi*trMP-O!85q969983qsAWr+UVubN21((UBZFgjR(B_e z*Y8_bF&lbgP$rdF=!m1|EdGvrMo`o_5e*MY=DNRs1@1D@Q~U}~H36FKi;M<88vhYg z27uu>Mki){XNZJ?yJ|iS0ZfuCx4U@J1Gu5h!{UhR`KF|eh^-*xJ|g=ev}_X)(2%P{ zgfHj>1ssT=eS!i5-7&P1_%YioIOj)_4w>`FYKTpoB8KGu3?lzzU|&_3oq}6#E3&&m zHBp1|Cx(XRG|l%idrlRUpgs~~f2`%d#wK5rO#pHXO(uo4tc#BjRc=PxLY!+w49onQ$S!XvXl;B`VEkdqlH{RvW8WPq~vp; z?ZpXB=!EM^QST!W_(`rq!7v{AA+Vv*>9kKRK+6++6TYSDQFuSn?FNn^B4bG8q`~n52SFlX zKm*tcb4VpTW$Df{wy=9v+ZW-&MiPVtI-QIqyUvdt!jR3**0-_N_1rdJgW-CQI}&kY zaL@v+&%qQs^Q8R-dA8fh$Kjl1BtIFlKp<$XS+(ls@4i!q^que5e?B83gSK`I`3dAM z9*6m965U?)Fgni774iA=LxziG>N39?pIWiOCP$q8&};>r7N|v9Y>%@&QIP;EL9}?V z%JGN9&VP7J-1)W074@DP=}OaaMs5dTYLSFw(J_e0Bf!9|EGz?rP6GXj8PLXfb+)Cl zQmg@A-$kf^>CrMUP{r&*4Bqrkulm5-i1J142@yJ5&Cp=)y7$o0ka%#m3~+|ZAQlt$ z$nCVNS2y|j=V!(@H71&HGH%ezx)Z67XStn=OJv#*x0pcc7rFfHI5|b&VNPy)q7s4| zCVq?X7x*zLieqn^%^`HbRV^*La(xgb!F4|4&f4A1@Hdo8maqnAkcO`hFa>`HdC z4_8xF#Zi9v)I#IxL*WbcS_Wu*F$W|EU6?CK>34Nzyt#vyS1I*5u@Aktvd3j^I0yd< z_B@pd`0O<~9-;>VF2|X?ZK*5<CjiaBc59u8iZvqjmSe z17%QzcML7zoC0Z34_`jR!jCr7$fIZ*PaHpff!6oth2fUf2pF3B{!s;UJW=qz&0>=9 zHKwzMi+Gt9ks7Af(~kOeJRbVgZv#ft)xxOpnAB0f%y%q*c>!jeVI$m%yg8-aY}k3B z#Oyt3g99rQ%1U)r)zKG^L`~>h<}G;n)uv|j&oEcSZpC;{1Avhkgi2yNBj0_y%01qJ zCSCQtCs*jd6s!IF0MMiPf`4=a6dFAU3%geNnZQ4PR|{6$q_qbLZunsjLHvFMcYJq% zE+-R&Zw#ZKM)!{fyacBwfoL;}%netu3B2TS{R9V;KO~&;%SfZ>hCljrKOT#}0<^-H z%BH3!k_-QOm36c*PV9cCt38ud!Lny#%eG@c%1@EZ${^lu6?iM{**U!Ji*U6*-0zfq zH8yz-*axJKx;ew3OQEb-v7%scVGbABP{W>}3nwo!v~;GsV4bTY6KGh5_+3g79*K2~ zOOiwM1{$=Sron^)*en56u{-WhAIPJJALbxCknMic>z_2|w zc>K696-O zP=>;7ib`R7x&dbvIIHS38OI44Y=2FMohvCwp78=jeKovQL)@UdJ#DU1X2FBZlY;Xg zHg;01M~dc-^v3UnpEPee9uf5jD5;7RxUgGha1@KWw7QxWlH}12UyO0!W6NQUScm0+ zlgk*TV6C5G_m3I>r1+$7M|p||Z>j{lEZl27cyYIHa?i_rCFOgN8H}l8jPT zL`r35B%`udW@aKqlC6QFLRKm(WJW?EBgq!Y$_U9QlFW?of4=+u&hMP-T<5y~*LC05 zeLt=q=XZu9zTfZXJzlTpdby6R0y?+^@EWY7q&|k@c0jKStMI{OcP`{%AQX>)ydx@! zv(3B!*q2h!le`17O|BMUVfuaMHIk^PNKLJ!)pEE5?74t~qGI5^dmp|O|4w`zZre`` zzmUPfn6aD!IX;f}C2%gvp&ljED)4KJ!Rm}H+SeN=mbW`4gSz`)s1)?uV*jo-cs)Zj zY%rtY!W+f-L<= znr1bWq`yA1EP5h+06iQgb}y_0#bcw|{%8;UO(Z^onBI*8I+XK-TDQ9+@C%9>eiC^C zHM$8tfYoLRxv)n4A?3OZYf>o;I>(j6A}=_7r+ z1@JXe+YsD^ggUHlL8JH-7dRSwg7$zF2K;3;z(fClY-qeL@)_bZJ zS2x1*&T$&wwJ;vF*o~9(_*T|}v;WdHrAZY5P~4~@fNkt~HAV*@Xhh|UlKm<9q(iXLEWI~Q1^ZTF*QkxL0gyTI>fb23*lO~(R!!kn?q!uq@H~K z1T+FR{mCWWcalY)JbCr6%uQHD5@xHD`3;Z0J$04_A9FQ*ui}XlN1=?wy~L3&g3tIL zOjtrMFE)|bO1yxlaOlDxNCXcgP6YALy@yFmCmy zPVEA)BBBrCQ{kh9J-9A#62*XRhKw1jsjG27m76zRh8 zdx^FNy<9G~g3O)=i1Z@fOvK1yL?`qK)WA)=aQthVuY3sn0CfqJp1jKn(u$0s`vNB68}Bx%>f1G z&V?Yvv!J*GvoA=`AYs(~nNP<;Jsqf?03uRF{!!j|g|u6rLyoI@%8 z3unt%O9W0?Bs3^`F?mBR@>cfm=Br$t8Ab|{A+Z?yVAs+(qbdr6hCT?HfUv!xUC`mp?KvFQO6CWZhv8nY5 zD)&*5rC$3(8+DS=BvlvCCeoY%0iozp>Cqq*yr|5>pnb!KaoInnVMS1-46ly@QKipb;+5j^;h z`j1wT%=CZ2$>=oc1|F$ZV-xl++d|z~)$pe{B<8|20&+GNhPUj>dn)HKX8JBxE^&4| zq|e*D9XXOWP|Yo)V4~o^_h+T(r5~Enf&2wt0d6LJ5cl!pkbIOA5RX73m6h_wB5TuN z+YSd{vR(ADvaMWv;l+ZKses?OSwYZ~{6;PlNJoIQYKC|HO~{sZp^1n=NZ|KOFZ+-3 z26~N@YMB2wV_1uO2Q*0WyTx9yq^~#!bv3a7XPpW9B|)OiVN`-@fukiGAnWD6tWY3n zUc24#lC-M(f%C%+8PyQi-TrkD&04I%rnEY9hl@EUp8k{3D&CgfpIO8kif=MM6Gsc4 z=ENiVE1+Pgzo4Fn5y2BTgQx-c zo7)LPfPl|CIufWAO�Do2VdJkm{(lCqkE`%>ZIAe*JnWIt5M6Zypvoyz8APnxeeD=q~9=DaCa0kw?9%?)&O;?aPX^_kn)Gfq?GUHrNfzF=ZZ0%FZwl8Sc# zi7K8-!jA)$Xgzv|wNWP$Ictc6!KMSY2%;q7Js3dI@*Csf;YpCx&)SQ}A0FI*H&luQ znEN&oB%$q}vBI4m4>Cd#La`YHJ__DrCr@fQ3zqHQme$ymp7I}{jt#l|_I7q8cM*f0 zilL4&W__Fe>->?O8$Tf{lvbRpQKsvjqS%wV?G9spXCJ(4yqJwkp?y+6$U%9ieNAJw z>1A*mt|AFY{_qAum>3=H3C#zWxOgO}gy7d>lanF*$1&3jS$ik7aw0=Q;sw({wjFT( zPaCAHWFlb(3@6GPu+G4ofHQq6M!%IF$l~Qf{)Gl#g!$J08WV4;T`r>->Et`Bn~50Kn@1Ic!UEfBlDUV zsXiZQDf1vE0$$#ouoPfn5x61#Nis&m@pmO7HpuDl2o1WaKy6-4r?-`rH!&-c-8L4V zqC6^1^(2wMR65OZ=W~v^%^$`QfdiQVT*6J{bDaT40>mSwQCzr@zON?=g-yuMt3U#{ zziwq@tcSRgQ$ivNZx+UpL=E?x8&F6PRTN5Wrr{FEbSMExm}<%VyNs%KGT2W{Z_H0o z@BZNUi#G>+6%V00{jK#{1a87InynHzl1!;4_JSYME}-!Ip-KV;W& zeg%Ylgm+6U!VUp0l%ZXBuzKB~qkK09{ZK}5Q&Ay9qVHWpLDZ$XhEu#Fk zvaZeglrH!Eigf5PcI@1_9A_FtMj$(;e-1)8K@n>NB|%@+)wLoex4;G6k-TD${YOR(cu?erwNEs z=z0i-NL&N;);7(=(!W?V^<9)NIeBr}w8fS!7gnk3ZC6oI4XSEXWqI**qy3Q!C2m(< z$!z$EaZ5Y*3+g$IS%h9!%xT!fea5$YDfh0ckFHj5nuos3Vcom;VHeAn-d7aI^Vf^T zM_Pso4ffg(bnfeNsSO`5I9pkrbZdyc!35+P%F)kg7%%_mUIHB^Bi*vk_E6ipj#cg^ zxrs{2-=J@mhJ~6WL4*#lyiy-BmY0z|0Sa>q?%DX-1Ppn``Y46|K06)s&`q4jTeHO7 zssj(-W)P5iQ(o?eh2RU!iwwWHF!4pD9$B_aBtdcD6j=_D!47B;SaC7$CQwx7t@r&& zDzV2FESh*$*v#ZuM0%}yuEPw?MivpQZ!#cp8I&_5qmBQ;4n8CP?6rHU}KcbUI-f zRcj=Ps*hA;XsrDp^b&wM2Gen~M^;c%`vwH8&p;22;b=QC7@ZAtEq5vl&B~SUM2>QI zba|j|BCm%0O`MT8L1E9|#tk$he#sr=lEvSv-b>2oHtG31VyER@fnY<{U)+63SJx@-T>ATFvl;;pvv09+jU|{QK-SJ^)Z#C> zH>IUFQQG^05TFZBkGo{`?SM8{niHn!T}63{%L<~=CvF9JCs5p!pz!5Oo?eB?009h}h6rW`HBfI`>g`ZsvWz6IM3- zl0-NKHy?`HlXHtWuX0@!{Bh$;Lz)Qyu&o8j`?vAZtQK1=h482wTetKjy{_63R9y3x zHdn-Psa1CEDH1-26p_11oT2kn(_GjrV!C4)v$satm&Bo*wa7WI{hdG6l)xay*qsIA!j(zszWl zmfu~6GfNu97;Ny}!^5=r@PX7Vr35Q*ST(1TgMu?< zMy(6pX)(G?+`czqbtN63V0caUFn4?n_C^^f05aSSKdA?e2Vn_dGj`~&hDizb=L^8< ze&L~%;IT&W9C5BE!_q)`5ZfPEK;rTH0rA0?noLY~z+@VYc1IYu9^ri+zIKMIS|Ajp zF7fMO_Gb=k`b7EyO#U-!dtpmn-N?9RmalVjX6O=&QO*Sf2C6(ZgJFyfoId4z_p2q? zTdx7_|=){6Sc>W5Ik;Z#8!oW8}1#EiD2MjNa5mE)jo@Zhfk zOWpy168D)UPWL0lQR+xH3?A`${jJ|c2hJvT{G+e&tm@E_m?CS1}7y+ zhk_oH1d#92=^sl?S-dWou9r*ZoP99-BEDMn&kM||G4Tq{QZfT!t_{6syyN+($Vh`; z54RRAWU0L>D?4ftE?FF|j-IcXaW{!s16aQ2*&3{_xW|vJ5};e!s@@NzHwF#pz5QoH zYv1m`xUqLnjinr~kxbc#%Dy|;>q#@_X=W2{|oYHiKTW0ao04^QK ziP)M#%YEGGX@X`7auQZk$bbfH*S+q)E|YY7tL&`+jb*2@^mFZ~A`Uy;&EF<%W^T?d zA<-3GcPzJ3*{o=TiYysdMZ(*Fbo8K0X_-+WcMB%rdEt`AQd~lU8_uJ_vg5aq4Uy}N zUJ@K}m`zbitO#aHe1_h*PnS_JJ!KW%Zv@Ml_-D~CLGc|0(s2R2Pmu2)+dN|kEN%w+Qtx{Di^N6oyj&H+>c|0;7Blv zz5^{pLS=|m7-ds-yTQsU(C3heUDLomN#rb)w#O}Q?KV49#*G1w)nvvXv^N_;&R#hh zTa3jvv0aR}T6;ov_+pT%N8A{o9ZSnEG`T}#nGTv(B72fVRbPZPI*6TYPr?Ren`oM} zXxW`jo|0zrfM|7}UBtj0$cs0(o;qz|p*2X&m%q(K{^UuY*x1_hEIF)1|A){edW+wmMPQ>Gc@*T80s4X%Q`uh71HZB*52n@y;~T{XRqsLdFi1p(7wm z?dgx7R*=PppV-8gRO4NBugd!VqSxH<|+`k+NsP8;tYm6QC2vT25m>ZJn=!DBYXe*Fs zfS^xxk1D2Enl7=7 zPHjTGDglv$-ryCkctYkt>#KDvyt+U%G<2`MgY5S@iDh0>GE1ov^rrx`lJGWcMiP!` zDYTWS$t8>T{ah`v;xG@7;@oUQ!2>LcvB6W^Jm?&ViWQnEP>3aG(+j+D(wM+^ckq0- zq*rJw68Nx@-p_S>$Fa<7Us)~C^M)$MzjX8+YH@umvC*F`VKPkV8vHKJ%4qSr*&G93Uo#Zm0wzYoJuJ zcW%k+-%&5UJp^7M5HSKMj-~m+q?6QN;~UcR#}vHE1;M7`>0L%)NSfiGV~S5CR3RiY z0(2I?olEH7ET7lo?&(z@gw2_Ff0nPIbFBUW^!6;vzyydl((hb=BLx&VCu!4g zX8H1-#jwA&Q$ZtLMTU6Ex&s-?s$t8PZP(D~m_wQye$x$Dp>U3K!y!bZY-=J1zD|@e z+1>!-rUP?Vq<^xrIa=?AQyv)Elen)dfK6HkQto5&^3W)3cm&DkX5H^&y#B4Pt~{Ex zEn1~h;OyMBZuRPos3kX{b%IOv1nFsBLni*lY|uqLB&jqve>SvAl+nb+$=TWW>C?T? zw6P+7g2#P+QtQ+3@VuV?Zh@oW2}f9kXNz;D(KB%{;>Cr1Vt*Jrk1RFR74rpB8 zKa1y|%UO)O~QxO-8Nj}G@V4m5TyF8M@tZZdN1+Ms_hl& zI37NQ3D<@OQ}r(U>O&!QL`w8&WW-i* zxKX>$NyTmHT%vEp6=wqi-~+TYvB?S_<#r5kkVAIlH4_&TzDsE2Gw%OHPFk174}wKu)tAaBT@ z%6;VZuEHR0Z_Kwk5{2*{Z-w})K;YuJ>=7^AjQD-$W!kyh;1-sGq(q&2GfXzxT(q}N z0=|e=P5ROQz;^Hn4|m9F{0nuog=DK-!CsCg>0Navg>d=tXr@X+ZkIvZhO-Keo7V`@ zJdZIY)*tgW17hY9>^fyz;DtjDPj(gFA(D=0Q2#%6EO48hxS|j*Sjn=)4M012;?EbP z2rc%f&;q_-1XY%bjO44CiX%=K3y)0K17dU(YmO(Yqm0u(-`!1{PxpGV#Nw^N(b1<5 zh0`lUx1fP@cFnIFQ_$xO73YnSkL z?Hd*hbBucRXWt{Z2L@kpq&$-JxkqT0aUl%k)V`WFH8cB!zUejWU%vU!(T|WJJ3vAA z{5*&Yiwy6>6tJCTWgHJ*1fx9SqUK@kSg( z5TFp{I9LUsM`A!Hvc_=%eo9F%d=0RSkZ+KMZGk~k49Q45aWzMI{Np)fj#4*vx%vD` z(ejJfv-qCF^bSKz#P*Z-qQ~7)D>ytx7b6{8-;EJhPR2Gr%!W^KZ!&rASF`8U9^vk^ zbKJZf4bP0SE472$AhbD$AHphMbFitW*Bz40A^5BTTUUBS-^4(FcS0N)QiL2_w zT-L@^olUrfjGPvhC}nRCl~M1_a`|}<7=rSkt3tdgIjn9mi)ha2Dk}$k$hlyW6oviC z&daMbfuUyB9XTp!?Vc-{F$~+aiVy6_ zxAqq&!G4~!V2ppO7JHNywcW%C03Dk*7ZfO6NH!?QJEo|(38CL@EjTq~kXvwq`Jnr+ zoO}B$PIv{6$_6J4_P>2?*O||rjyixd)%{m}v>80|DPhhnS=+`%}u<*l_#wU)r(TF~{ZD>LiI3S%~PN_%JM1)HM9t*B)L6uo% zL@bd#gbJDK8J|fAqbFt-dwzK7n2ye13!H?0Mr%@2}0GMXy;E)A4AV*@1M7M-&j3QlF{!g4FTTU(DDDVZ6L_g<#X0rU9 zJYN`5{oaHSX)9d`dIvvnW;SyVgwEV0J%X&1)YanQtgNwP9}VK4RNpgMKn)N>d_$1Ltt(eDbXB-}M| zTkqaI;FVPzmTjA4Z6G5S9KKBB;SwhY$=-YC!mBfB3%{97O-#t(*6DQn`B8AsA1jM+ z$3#j>=y4QhL@GkNRS2I<7@z)n%m8=nbXtM64$#vpGc&W(48$EBc#Trx8NzcpTW38w zHFXpgKXTp>%@hVCzkkVR66}P*PdE$9fp(%uT~`w&!9oH{Ak%!Z&k!eajAjavlmVwj zTGk_k>}-DT4+8-?C7}f+(SzA0I{^enjLpu>d_uo+6oH{Q2EBj~4bP!oE&(b`22Mqo zVHDs>C=c33WzJLwN)6_uL0~}42>`eVeT_re7{Oi6{E9qhc)2;mVfHwG{`}?diVOgE zq%m!h2~L(09I|Wf#7M=w!jFAw{&uUyfp2Ux*n2!XNl3D`w>1)&xJ#G>41 zSAq4?hC~|~e%EmSSV{1kZ5ONowi*a-3BZ=kM+j=E;ljR#cLk_?iEaMq?}Q{&BVjHx zRWC*F+Yba37%h2*rh5vb+nZ8XrF0urSldk2c4eQ{`q18P0+fzFj-66ZQ)6tQqM*YgBOeJghQoOSBI}wMZ%H^HcZN(B zmRd<}7&1B!ugkZl<&i868L$b}XBjXVdlU+4D1MUn8N%&BW@Mts{DkMh0=4*@-m3S0&1g)Kv-25fA<2A4OW{L? zkXS@QbVBgIM74yqlvmBoTY%p-F)AtQ+{r*aMAVrW|MMFCTn4mLB(woHeBlv5LOZh; zj&(Bf1mWghflCRt%cJ3;L`jUgjsoO(1*lCLs9z8k!O(F+k=wsI`%ql_kMG^pG0$yPJ4`zei!MjGj8tJsCs615Jkab0d7Lr$h+PMVy zPj`PmH6>9ea~CXVWYRgh`FEUVWZEMvxs!z!wzmGLxrXvDAqU?kJib=?J!YU#p{^>% z2N129k{$7}K`a25$u#oX10y03G?uxV%fu;c_sBc8-rKe^8QY zC{Zx(4@d@wVF|*kZg>7s6A4}ttLa$Vv2{tugC&VUo-Z4gyglB)Ywz^D*h4BD?`IWs zb?^gqb@v5ZxZcW610oxZx*AtYbKz8rp~qL|4tO-^XAHY0n{c;)jIY<(rF?#u20nU+ zvQ=b25EMXuyd~g`v02-a@UW;ua`E^RwbHlaC&k-;K8B+~$ohk_g+81b?<|Gd7U6!Y zy7=+3yx9TM$oHaR&gf!qLq%Eq@gwtduS={fP#gmdFTrzKLO~~3j+-UxW>{k%LrM(^ z`#>5QC>+8R0z)bVXwXyIoEO=z$)tXN%;@A3%^hGODCc|LtRf5T*YqfA zhP9wYpu+e2cIGAG57D_Sr&zW=<3Nky zWG;|1-LgmbI=l0-2x{f0M>#fl^-g0d- z2vQFL@%(|2+hpi1o;{r7w>x8f%ozO&6C=*44*IJ@j)rEyjm=Tt{dui|O#(-V+~CyR zytIKcA|V<6f|mI)32729#govi;r16B(BTUk5_RO|;!3LM+z7?XFts?MEWl#@2IVfI zK|$fO6dDBVBX5=Ju*k@@XjUUyu*Mv|&+?c>CP3JbRVn`UJ{~A(N=Q{4ue#Yu0tY-~ zL+`$B>vW&9i5SwYR+9~t(~PC=og9+x$kXU8z~%TEN7G%8=`}Xj_|JB!>J%h8-*a2P zUPrR2e)Fk*Y@Sz0q1H%NPkQ%fYp<_$ff&iqCOm>>y{#o#EBy{J>V&_5cM=2E+7=-< z(dj+5PWilZx9?^ilFLXaT8VLp8#@5-L3)~Z$$-GYYA2$qDk|O`>iLPWl-H_U=ca5> z`ANS&QT)0q1=(|EhmYsP2{H-#H!}0W>_oH!fbx8_44mRCvi%@{ki&sbMqH3B{~;q* zsX9=%zo*OrP!nXPWw`uF6$Q2*+S+AEQ%(NSbsKc`(6;P7ivNKA`3LR)H}K7WC;IoV z5Wh8&#r7quCCU#Fgw6Srm{8piT-w)>{{Odu1k=;eXbuR=eq>zK0dtH<4+l1T3ubp; z_kN5-oVZ(pykaVpC* zUzX<8>!r_tpH44^%hZik^BXs3?nd2or1c3?@^Y#py?tyy2cjIdXv8aQ2K_^_B4yjI zX8h4MX!57(uVl5~r))#V`XVhy(B<;wZd`EAQSJJXZcD56#_W_F^yB9X{V{3HVX*Ov z9$z_f$0inb5wZh?0Kir*j2b3^{H%~Oj0o=EN(;Z60;Z`*e#G7pXiNZUR^Y>)eqU9K#SPc9iN1vMY!hy*JJyb+_$O}>FFuh%Bw0Ra>k zgz_;Z9JcNz`MCII7A`QePjRZN`qOPSvF44B2vy%M{XDEu{F76W7MTC4mjz6jw4rk* z)V?pxrlEe%_P3u!s5Wc@!3Q0`KO}MrG-0IPlnvdFx_S6XCAv<2ykz~JyxXIR$vvH6 zm8P%D%jLlA`J%hnz{tpjv5ZDPL{BCNcV3nzjZ+U8I9K(ieQJ7o4?AZw;dO|Z0Y$@( z_b02M;0qvSJ@MYZvtx=CeKy!6J2^eguGSRg{=QbNFC|?j+t6ck6Equ5Q^T7yLisk2 z?K%$h5juV{Xt@W|cfvaJem(l*d52aqOe%N9CY$!Jcku8^6e#Ga5`_T~P3iT_%yF8z z@4T58s;qs7q`3UA%=Gy2zd>sxgEvd~GKi0i0?S{)HbjOX5&jUHaW{}Aa}5bL-zy@; z*r2hbq$lpj`Wd~;mvit@X@<8Y3AC}^yY(mF_wb-t7fG4RKqC;#uZ4LxC}cOkTy~{l z{P@Wr6}P%Q1M1=psOE@7r!q^;BxFE#a@Dt3?n^yX*#uPEMJ6L#wxls5F$sm202n_A z!C3%xueq~98+$I7$1J84} z^Y$d@9{&6W_{bOkfE0lO?y4iN7k~cvjrg8>qJREH0jFKRfx>@<6#l2a=|A(^{s+FK zzuw#b@u&3H2k^i8DF6DV|I9P_?|Vsq{kH!I2mUWFlmFed^zT1_|F)O(*AMzHF7JQ; zlK$E!|AdzRmp`Td3oq%ft@}T4GyV0F0+%b8@TEGt{!(O&^RX>@JH1!@*1FFnfBTPo zR{pbVZhq+-T<7#RIwFzouQ$ehcI@HTL0|m6+vJ~brGB~b6{cqV+McQMK}uE98Z;=E^Beq`#s>Lqj%=DU9!+ z3l%!o!GJ33T2xe5*S@ntmp>GW@tW6o&fM5=xYDb?S6-cVU6|g}gmLl6y~R71a&U+f z+8^xRyHuThlvjYki1P0t)PSw)Sa%;}aB}&{zSw`fBK1j(Wz*^{Y6(&XMTNzE&d5Z0 zdhg%{^J^;}fIATt-3!*1{A#I{h}Y;QK_|E^476R9yn?4iQ&6I;M5HzJEYQGZr4Ps+ zWj{Oh?GevjVYx|@@{5Kks#N9>MeCfB(3<1+KfH@W9JjZRzrTO&9NImisGv}E+}$e> zhw{PU9%ec4mic=m4b>5X1+2>>WMELpe8ytX$q2JaembS0I$ya>eA`S?64m0p@FNBZ zYlGqZ==tow#Orn9s0y^P5==ll&~q%gY$q0!dnkFhHP%M>kYXt7$QKp$`LDYxhf@Tb zS)i6D+CnfkM<9nAMaOSUq+TyCJ-M{tVdo0d*eHo^L%Ptl+qY?fk7ZmQJq^!V)|=6j zwPSr1wCm(TG*Y53&pX6U*7Y4aDp)oBV-+YJg03Oef{5P0Ist4+dD-DG6x~_K+*8Y3 zG5pPFbhKP~>Wj+r*NTZgj|K0rKT-%4mFPnZ2>>RmMFe`aEDX?Y<)!XWW`-O22sb%oLfyM|ZAFm-jg!wh z>5c*#^`2g31y?lk1iOMxO={(p7-=7pSO-x8=--+0@_{6vVy9tFCo?8TKVJ#qVSAB1 zKS$+MA9TzVE#CXC#dzP7cxSLsJf4?;rE=~?X>aAz^N#!bmG%av_`h#Ae3uOoIVd?Z;=x46GWvsUyTj0w5}#cbcoxPlw-B!w(E1^|>MloH z>~gH}-sMzm*lEaxVFeSgrL$AHa4xO(S>xFjsRA<^*5x(SYp=`3#Ky&!uAtDZroxoV zD-g+>AT7PLcDHRC-I&L`;)u%(_hvz#HT4U&*%x-uf$60c;%F8~vdN7*$h0vE%E^cP z{SzWi^RsQsl^0AscfWYy)6rRIIUo4+BZnLRjtP@8D?{{#uhD2+q)r?4`fk9J;tuP4iZ(?NI0dsmbv;vw17{olWPs_OJlam07+jh}6Rss7ToRu8)a_cLY(e8=)XOM^s(vv3=vKT9dDQ>_-H!p6q+#wt(l zcDz`_$@*s;V?905ozJK=B6rrQmK}&MZ4Kx;$o^aaPlW#Df88XIW#rGbZH;uMVou+u^ zIBlweBl@0Dl2Ld@Mn$CXy0O{Gn9FtwDN}No6LBa-t7I&*jup!Q2YdiHb+?hxoC}^_ zRLQ)$%XQ{wD~ir9nbArgEc-EWrh-Y>yXi$2`^cMBy}bGeO*o;Pb;d+l&;0MQbBeR|a6x8H2KK z<+ox$dk_|y2(Mu|?E$Jp=zB;W)|@pIabzEOIbt-^YN4EE<&{4_7dYQ)5zyXx1hVG4 zr?nr8E3CBS)01?!6RbgAyjgRz@}(i~jtCKly94<5n2UB-Q_bH#YqAYr19VCX;bbiRZ-ZMXuQ~Qa|vfOLe>gNWkl5v-!eJ|-Mda#uiGk~+h!f(_l z^#bGm%0p*ccr!mCp`7WfO+?VbA}T@iVRs^#7&*9b%CmMDPd#HqI0YbgXGaE!~G zKK-cvv)c45=S%>bvX9S>k%~a}%6)crMgk_@Q#WFJp1jDi?Hg|Q`6aO+*%al`y!~s4 zu(kGtpH>RBALBks?zaB)!qpCzoI>*QvUdmW_B4PsA_F;ITwkJL9;2rGR!q!T;KJ!# zM^@^lrj0$k9O8ef&yhcS6=*jBeTn*9{MQfZ2(?x5^o7%8iS&Iuq3DZUEQ11qm~g?v zlHS&`t5A%LiGhy77!=^$_Auum&3luBRQu@ZZ9Z0sTwIy^Kv+7%GO)Nkt1%*}Xu-E* z*$U5mQC0~S^ZB_Uy$9#SjVRks-d}!UXp8Cd=j$E6vyOZa0GIl#X5Jp`0Lk@(RBfm_ z)mYs1pq;SI`v=<;*nS^C%P89Ykwscev!4axw22Q7M~dVYf?}n6 zzU$w3ARIW}wa7kDwAeJvnxZZsI?6L~jmNfe<$b9H?yW(M(->;}n+HPCN_e1j9?-f? zmqxsIu`O|0wW?yik3O*_^+-qvPmE=I^Orvt3*PXn(o!n0BP1q~r0K#Ps#oaRnmD>) z-FC@>bId}!Pp~f5GPClp>-i*oLrSieLNPa2{*rr!o@&kOls8Q&0Y8TlP8FTXl3WN<VZZLHi{8I2x+GcHBrSNf@?*ivZp+Di+r>B0r&!#%iY*9?o+OQugms~%M5%rMEG0C!U>P2EaT$w+L+c{UJ@AyhctrA6bLQ?=)MFS2F*wzq>K&pV*@L zWwleoF_vB1w_v~tuc2YD>!MhyX8HkVSKl{^b+pO17)##w#6rD3+xtBab15ZdWR{ot zv-ra?%dlU(71!H^MRDH8$9WD89Z8abOUk(@tfngY1B*GEz*@nZj?{d7;*ic=fAVAx zH1vz-9-d6wt@MZXe6+jug3PKG(J;d)Yi<2KT(xFjJ%AGWfa@bivDr|9FAtvj6FGhs&e>H%wSOUma&G0 zK;&H|dwW}@JMraz&WW2w;vE%|K7sv9;glzVTfe{{Lh+PW>)IcC^hj&&KHh}m(o;R9 z%Fk^LA2aEPKN?_UK{7xO4iLgJKv{&*UsM!uqs5Q~(hP>&K3?3VC)YP(TpQ*L9 z%mjPzT$-rP6WxHOq-*(`cE_zdPop0+mHJCDZ1vrO1Sdl)ZqwUaHMAuMYQnGK$C_YN zcB%MQ*`G93tY_a*Dr$JuT#e2d2+g?Vec8I76_b*8Y0s<|K6g)jO`qK%sD^GaMg4N^ zjX1c(e%(6GPIsnfc@AtTD$8bC(iru`OV6gWE&59YEVdZ(3#~Q;VUUKB!Nm3Y_+h@f&*U#O(O&%^>D1MAQx7 zbHns*#YhLzZ&G{w+)%g3_}lD`6cuR~d(qs2f?~OJ=%A7{pCl*nyp;<%9jd|Dvm?cT z*=~i;)vuNDCT)w%+g1v* zyN-Z3OawQ!v7wcdD}R)*C*<|%j)T45KP+)LwvsF%k55Y*9|-S|t4j*=74DKTu;vxw z;=&C@HxmeBRE0qv-HcWmtFY)cG@T{+SI^Dvwe1uo@ew5886;B~q-o9`i$6}>qfD0F zez$Wc>tc^=@40r(^WzWF^sDJuoIaPmd-H}))avLH>d4l)Wc1gTcY|o|ny^K8X05`? zW3T4)XW;&i)bs=Q&&R%z@hME`47}cZw@3SD`^9ycG&@YQX)FIx#jD*7&SB@;y?l;$s05PUy7` z=l2Q$%W(bj?%8}ru(F3|k?qFdbX7L~!&?Vg+&z143tz0&zT4U+)tb#?rrkAAa2*Owj1Ynwg+MMpbwvLQP#ZHO^-BtSC zbb5E`3eL;kvtS}fm=@%ABvtAa)ZjOvFxfK4SY0QvqS4A!B9~^;?@LsCjoS9OTkCMr z_~5sl25Exf0#roy1Ib8)%es5(n7ljO=At|EHlskV(8*Xj!yQuV@Lje1K-nP1yk2xK zSreWMZQuuJccvB*Nf(VWDCgqWjj%kz4`SUd`Re_%?!!+;3a{0?-#BLec4BR9jrUrw z{vKJ=+e|A)rv-TDe_i~3Bk|jZ4HY#q{WmrQ=;&+~9qgI^$+MFf>=Sjflc(;NBp~bJ z7VH6Af?wEM^bU8e!)GgVjt`7=$?0F0@A)&TJ)YK9itv5NU-Twc+>Mg0JFtPK>Svcv z>&;D^ela!;lFf~_KifGYG z#A0s1xq1aT(dKoLw*iDKBa;|G!qc8LOiP15W`{)+_i$`7Y0x-bwTzQQ*cB2bC;^Vs z=Z`FXtS+Vb@<1@N$e@j(d0JWpYR)Pt;p%;aJSIwI`xRq%@A+@LnJ-lt`?nTj9B>!O zik=2RM_w3lzawstYs^Jc=kpHRdMOvjzGvT!h=$|7(3z{)EGT}uq05!(-)CV%_caqC zFgfyFHQ^N>pVOL4dovVxgbJQ?3J??*z4&E4-YprAs1zy62+=jBNH#c~cpmJ?r__r!6eCZHzxT)seeiM<-GBOKoS_ z)VpIXJRy#*RXpDO_O99<3@l~kLO7?cJk&^09&RyoIPt>l_m>;|PwJfJ+%9pnIZhsb z`{`^yQ-xJiPh!Lk?tF>fVVavaDok&ZHYlEL_s+O(OJ&A1HI7GBa^_}U++D8AGJkei zyxh$m6l1#b#*GSfv&8|43cs6Io+;Ab^JgmeTt8p3(ek+qxF_qKp)~Y%G=knT6B}LX z!}<^$zCqrs@$7Gg41ATr(fs~@BVhmkf#j7wEH2|Rc^g+!R3$~hA9>jmGHFsqSN}f? CJ2*Q4 literal 0 HcmV?d00001 From 3afa5dfbcc12c4752504504756fdf3042303440f Mon Sep 17 00:00:00 2001 From: ckath Date: Fri, 2 Oct 2020 14:33:07 +0200 Subject: [PATCH 248/411] minor typo in Vector.c --- Vector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vector.c b/Vector.c index 20578851a..713d68318 100644 --- a/Vector.c +++ b/Vector.c @@ -322,9 +322,9 @@ void Vector_splice(Vector* this, Vector* from) { assert(Vector_isConsistent(from)); assert(!(this->owner && from->owner)); - int olditmes = this->items; + int olditems = this->items; this->items += from->items; Vector_checkArraySize(this); for (int j = 0; j < from->items; j++) - this->array[olditmes + j] = from->array[j]; + this->array[olditems + j] = from->array[j]; } From 8efc88593ab29ce409d720c2add603795d73f12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 29 Sep 2020 10:25:20 +0200 Subject: [PATCH 249/411] InfoScreen: update content on resize --- InfoScreen.c | 1 + 1 file changed, 1 insertion(+) diff --git a/InfoScreen.c b/InfoScreen.c index b8859af0c..35c16473b 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -137,6 +137,7 @@ void InfoScreen_run(InfoScreen* this) { break; case KEY_RESIZE: Panel_resize(panel, COLS, LINES-2); + if (As_InfoScreen(this)->scan) InfoScreen_scan(this); InfoScreen_draw(this); break; default: From 4b14ab9789eee004daab8594ac00a113c18af060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 28 Sep 2020 14:55:38 +0200 Subject: [PATCH 250/411] Adjust colors - do not reverse CPU steal and guest in monochrome - black on black in Light Terminal is not visible, use blue on black - white on blue in Light Terminal is display as blue on black, use yellow on black - re-draw FunctionBar after color change --- CRT.c | 54 +++++++++++++++++++++++++-------------------------- CRT.h | 6 +----- ColorsPanel.c | 1 + 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/CRT.c b/CRT.c index 14d9ae627..c0faf8868 100644 --- a/CRT.c +++ b/CRT.c @@ -39,7 +39,7 @@ in the source distribution for its full text. #define ColorPairGrayBlack ColorPair(Magenta,Magenta) #define ColorIndexGrayBlack ColorIndex(Magenta,Magenta) -const char *CRT_treeStrAscii[TREE_STR_COUNT] = { +static const char *const CRT_treeStrAscii[TREE_STR_COUNT] = { "-", // TREE_STR_HORZ "|", // TREE_STR_VERT "`", // TREE_STR_RTEE @@ -51,7 +51,7 @@ const char *CRT_treeStrAscii[TREE_STR_COUNT] = { #ifdef HAVE_LIBNCURSESW -const char *CRT_treeStrUtf8[TREE_STR_COUNT] = { +static const char *const CRT_treeStrUtf8[TREE_STR_COUNT] = { "\xe2\x94\x80", // TREE_STR_HORZ ─ "\xe2\x94\x82", // TREE_STR_VERT │ "\xe2\x94\x9c", // TREE_STR_RTEE ├ @@ -67,7 +67,7 @@ bool CRT_utf8 = false; #endif -const char **CRT_treeStr = CRT_treeStrAscii; +const char *const *CRT_treeStr = CRT_treeStrAscii; static bool CRT_hasColors; @@ -203,8 +203,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_IOWAIT] = A_NORMAL, [CPU_IRQ] = A_BOLD, [CPU_SOFTIRQ] = A_BOLD, - [CPU_STEAL] = A_REVERSE, - [CPU_GUEST] = A_REVERSE, + [CPU_STEAL] = A_DIM, + [CPU_GUEST] = A_DIM, [PRESSURE_STALL_THREEHUNDRED] = A_DIM, [PRESSURE_STALL_SIXTY] = A_NORMAL, [PRESSURE_STALL_TEN] = A_BOLD, @@ -287,10 +287,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_RATIO] = ColorPair(Magenta,White), }, [COLORSCHEME_LIGHTTERMINAL] = { - [RESET_COLOR] = ColorPair(Black,Black), - [DEFAULT_COLOR] = ColorPair(Black,Black), + [RESET_COLOR] = ColorPair(Blue,Black), + [DEFAULT_COLOR] = ColorPair(Blue,Black), [FUNCTION_BAR] = ColorPair(Black,Cyan), - [FUNCTION_KEY] = ColorPair(Black,Black), + [FUNCTION_KEY] = ColorPair(Blue,Black), [PANEL_HEADER_FOCUS] = ColorPair(Black,Green), [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Green), [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), @@ -301,12 +301,12 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [BATTERY] = ColorPair(Yellow,Black), [LARGE_NUMBER] = ColorPair(Red,Black), [METER_TEXT] = ColorPair(Blue,Black), - [METER_VALUE] = ColorPair(Black,Black), + [METER_VALUE] = ColorPair(Blue,Black), [LED_COLOR] = ColorPair(Green,Black), [TASKS_RUNNING] = ColorPair(Green,Black), - [PROCESS] = ColorPair(Black,Black), + [PROCESS] = ColorPair(Blue,Black), [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = ColorPair(White,Blue), + [PROCESS_TAG] = ColorPair(Yellow,Blue), [PROCESS_MEGABYTES] = ColorPair(Blue,Black), [PROCESS_GIGABYTES] = ColorPair(Green,Black), [PROCESS_BASENAME] = ColorPair(Green,Black), @@ -326,32 +326,32 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [MEMORY_BUFFERS] = ColorPair(Cyan,Black), [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan,Black), [MEMORY_CACHE] = ColorPair(Yellow,Black), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Black,Black), - [LOAD_AVERAGE_FIVE] = ColorPair(Black,Black), - [LOAD_AVERAGE_ONE] = ColorPair(Black,Black), - [LOAD] = ColorPair(White,Black), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Blue,Black), + [LOAD_AVERAGE_FIVE] = ColorPair(Blue,Black), + [LOAD_AVERAGE_ONE] = ColorPair(Yellow,Black), + [LOAD] = ColorPair(Yellow,Black), [HELP_BOLD] = ColorPair(Blue,Black), - [CLOCK] = ColorPair(White,Black), + [CLOCK] = ColorPair(Yellow,Black), [CHECK_BOX] = ColorPair(Blue,Black), - [CHECK_MARK] = ColorPair(Black,Black), - [CHECK_TEXT] = ColorPair(Black,Black), - [HOSTNAME] = ColorPair(White,Black), + [CHECK_MARK] = ColorPair(Blue,Black), + [CHECK_TEXT] = ColorPair(Blue,Black), + [HOSTNAME] = ColorPair(Yellow,Black), [CPU_NICE] = ColorPair(Cyan,Black), [CPU_NICE_TEXT] = ColorPair(Cyan,Black), [CPU_NORMAL] = ColorPair(Green,Black), [CPU_SYSTEM] = ColorPair(Red,Black), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black,Black), + [CPU_IOWAIT] = A_BOLD | ColorPair(Blue,Black), [CPU_IRQ] = A_BOLD | ColorPair(Blue,Black), [CPU_SOFTIRQ] = ColorPair(Blue,Black), - [CPU_STEAL] = ColorPair(Black,Black), - [CPU_GUEST] = ColorPair(Black,Black), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,Black), - [PRESSURE_STALL_SIXTY] = ColorPair(Black,Black), - [PRESSURE_STALL_TEN] = ColorPair(Black,Black), + [CPU_STEAL] = ColorPair(Blue,Black), + [CPU_GUEST] = ColorPair(Blue,Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Blue,Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Blue,Black), + [PRESSURE_STALL_TEN] = ColorPair(Blue,Black), [ZFS_MFU] = ColorPair(Cyan,Black), [ZFS_MRU] = ColorPair(Yellow,Black), [ZFS_ANON] = A_BOLD | ColorPair(Magenta,Black), - [ZFS_HEADER] = ColorPair(Black,Black), + [ZFS_HEADER] = ColorPair(Blue,Black), [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Cyan,Black), [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Black), @@ -410,7 +410,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan,Blue), [CPU_NORMAL] = A_BOLD | ColorPair(Green,Blue), [CPU_SYSTEM] = A_BOLD | ColorPair(Red,Blue), - [CPU_IOWAIT] = A_BOLD | ColorPair(Blue,Blue), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black,Blue), [CPU_IRQ] = A_BOLD | ColorPair(Black,Blue), [CPU_SOFTIRQ] = ColorPair(Black,Blue), [CPU_STEAL] = ColorPair(White,Blue), diff --git a/CRT.h b/CRT.h index c0b939526..f21488fe8 100644 --- a/CRT.h +++ b/CRT.h @@ -117,17 +117,13 @@ void CRT_handleSIGSEGV(int sgn); #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) -extern const char *CRT_treeStrAscii[TREE_STR_COUNT]; - #ifdef HAVE_LIBNCURSESW -extern const char *CRT_treeStrUtf8[TREE_STR_COUNT]; - extern bool CRT_utf8; #endif -extern const char **CRT_treeStr; +extern const char *const *CRT_treeStr; extern int CRT_delay; diff --git a/ColorsPanel.c b/ColorsPanel.c index cfd975da4..972f60756 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -68,6 +68,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) { clear(); Panel* menu = (Panel*) Vector_get(this->scr->panels, 0); Header_draw(header); + FunctionBar_draw(super->currentBar, NULL); RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]); RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]); ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); From 6f387008cba414abdf695ae0eccdc0501bd36a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 28 Sep 2020 12:06:13 +0200 Subject: [PATCH 251/411] Add security attribute process column --- linux/LinuxProcess.c | 5 +++++ linux/LinuxProcess.h | 5 ++++- linux/LinuxProcessList.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 890c8a0fa..2775122c0 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -109,6 +109,7 @@ ProcessFieldData Process_fields[] = { [M_SWAP] = { .name = "M_SWAP", .title = " SWAP ", .description = "Size of the process's swapped pages", .flags = PROCESS_FLAG_LINUX_SMAPS, }, [M_PSSWP] = { .name = "M_PSSWP", .title = " PSSWP ", .description = "shows proportional swap share of this mapping, Unlike \"Swap\", this does not take into account swapped out page of underlying shmem objects.", .flags = PROCESS_FLAG_LINUX_SMAPS, }, [CTXT] = { .name = "CTXT", .title = " CTXT ", .description = "Context switches (incremental sum of voluntary_ctxt_switches and nonvoluntary_ctxt_switches)", .flags = PROCESS_FLAG_LINUX_CTXT, }, + [SECATTR] = { .name = "SECATTR", .title = " Security Attribute ", .description = "Security attribute of the process (e.g. SELinux or AppArmor)", .flags = PROCESS_FLAG_LINUX_SECATTR, }, [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, }; @@ -148,6 +149,7 @@ void Process_delete(Object* cast) { #ifdef HAVE_CGROUP free(this->cgroup); #endif + free(this->secattr); free(this->ttyDevice); free(this); } @@ -289,6 +291,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) attr |= A_BOLD; xSnprintf(buffer, n, "%5lu ", lp->ctxt_diff); break; + case SECATTR: snprintf(buffer, n, "%-30s ", lp->secattr ? lp->secattr : "?"); break; default: Process_writeField(this, str, field); return; @@ -374,6 +377,8 @@ long LinuxProcess_compare(const void* v1, const void* v2) { return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2); case CTXT: return ((long)p2->ctxt_diff - (long)p1->ctxt_diff); + case SECATTR: + return strcmp(p1->secattr ? p1->secattr : "", p2->secattr ? p2->secattr : ""); default: return Process_compare(v1, v2); } diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 9972ee84a..587748624 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -15,6 +15,7 @@ in the source distribution for its full text. #define PROCESS_FLAG_LINUX_OOM 0x1000 #define PROCESS_FLAG_LINUX_SMAPS 0x2000 #define PROCESS_FLAG_LINUX_CTXT 0x4000 +#define PROCESS_FLAG_LINUX_SECATTR 0x8000 typedef enum UnsupportedProcessFields { FLAGS = 9, @@ -82,7 +83,8 @@ typedef enum LinuxProcessFields { M_SWAP = 120, M_PSSWP = 121, CTXT = 122, - LAST_PROCESSFIELD = 123, + SECATTR = 123, + LAST_PROCESSFIELD = 124, } LinuxProcessField; #include "IOPriority.h" @@ -142,6 +144,7 @@ typedef struct LinuxProcess_ { #endif unsigned long ctxt_total; unsigned long ctxt_diff; + char *secattr; } LinuxProcess; #define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 1e472affd..1df7b32bd 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -625,6 +625,32 @@ static void LinuxProcessList_readCtxtData(LinuxProcess* process, const char* dir process->ctxt_total = ctxt; } +static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* dirname, const char* name) { + char filename[MAX_NAME+1]; + xSnprintf(filename, sizeof(filename), "%s/%s/attr/current", dirname, name); + FILE* file = fopen(filename, "r"); + if (!file) { + free(process->secattr); + process->secattr = NULL; + return; + } + char buffer[PROC_LINE_LENGTH + 1]; + char *res = fgets(buffer, sizeof(buffer), file); + fclose(file); + if (!res) { + free(process->secattr); + process->secattr = NULL; + return; + } + char *newline = strchr(buffer, '\n'); + if (newline) + *newline = '\0'; + if (process->secattr && 0 == strcmp(process->secattr, buffer)) + return; + free(process->secattr); + process->secattr = xStrdup(buffer); +} + #ifdef HAVE_DELAYACCT static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { @@ -925,6 +951,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* if (settings->flags & PROCESS_FLAG_LINUX_CTXT) LinuxProcessList_readCtxtData(lp, dirname, name); + if (settings->flags & PROCESS_FLAG_LINUX_SECATTR) + LinuxProcessList_readSecattrData(lp, dirname, name); + if (proc->state == 'Z' && (proc->basenameOffset == 0)) { proc->basenameOffset = -1; setCommand(proc, command, commLen); From e5184599814a3210497035e9942f154945f2b02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 13 Sep 2020 19:46:34 +0200 Subject: [PATCH 252/411] Add DiskIOMeter for IO read/write usage --- CRT.c | 18 ++++++++ CRT.h | 3 ++ DiskIOMeter.c | 92 +++++++++++++++++++++++++++++++++++++++++ DiskIOMeter.h | 14 +++++++ Makefile.am | 4 +- darwin/Platform.c | 5 +++ darwin/Platform.h | 2 + dragonflybsd/Platform.c | 5 +++ dragonflybsd/Platform.h | 2 + freebsd/Platform.c | 5 +++ freebsd/Platform.h | 2 + linux/Platform.c | 51 +++++++++++++++++++++++ linux/Platform.h | 2 + openbsd/Platform.c | 5 +++ openbsd/Platform.h | 2 + solaris/Platform.c | 5 +++ solaris/Platform.h | 2 + unsupported/Platform.c | 4 ++ unsupported/Platform.h | 2 + 19 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 DiskIOMeter.c create mode 100644 DiskIOMeter.h diff --git a/CRT.c b/CRT.c index c0faf8868..693722986 100644 --- a/CRT.c +++ b/CRT.c @@ -145,6 +145,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Blue,Black), [ZFS_RATIO] = ColorPair(Magenta,Black), + [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(White,Black), + [DISKIO_READ] = ColorPair(Green,Black), + [DISKIO_WRITE] = ColorPair(Blue,Black), }, [COLORSCHEME_MONOCHROME] = { [RESET_COLOR] = A_NORMAL, @@ -215,6 +218,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_DIM, [ZFS_COMPRESSED] = A_BOLD, [ZFS_RATIO] = A_BOLD, + [DISKIO_UTIL_HIGH] = A_BOLD, + [DISKIO_READ] = A_NORMAL, + [DISKIO_WRITE] = A_NORMAL, }, [COLORSCHEME_BLACKONWHITE] = { [RESET_COLOR] = ColorPair(Black,White), @@ -285,6 +291,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta,White), [ZFS_COMPRESSED] = ColorPair(Cyan,White), [ZFS_RATIO] = ColorPair(Magenta,White), + [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(Yellow,White), + [DISKIO_READ] = ColorPair(Green,White), + [DISKIO_WRITE] = ColorPair(Blue,White), }, [COLORSCHEME_LIGHTTERMINAL] = { [RESET_COLOR] = ColorPair(Blue,Black), @@ -355,6 +364,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Cyan,Black), [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Black), + [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(Yellow,Black), + [DISKIO_READ] = ColorPair(Green,Black), + [DISKIO_WRITE] = ColorPair(Blue,Black), }, [COLORSCHEME_MIDNIGHT] = { [RESET_COLOR] = ColorPair(White,Blue), @@ -425,6 +437,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Blue), [ZFS_COMPRESSED] = A_BOLD | ColorPair(White,Blue), [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Blue), + [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(White,Blue), + [DISKIO_READ] = ColorPair(Green,Blue), + [DISKIO_WRITE] = ColorPair(Black,Blue), }, [COLORSCHEME_BLACKNIGHT] = { [RESET_COLOR] = ColorPair(Cyan,Black), @@ -495,6 +510,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Blue,Black), [ZFS_RATIO] = ColorPair(Magenta,Black), + [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(Green,Black), + [DISKIO_READ] = ColorPair(Green,Black), + [DISKIO_WRITE] = ColorPair(Blue,Black), }, [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. }; diff --git a/CRT.h b/CRT.h index f21488fe8..4eeb9a461 100644 --- a/CRT.h +++ b/CRT.h @@ -106,6 +106,9 @@ typedef enum ColorElements_ { ZFS_OTHER, ZFS_COMPRESSED, ZFS_RATIO, + DISKIO_UTIL_HIGH, + DISKIO_READ, + DISKIO_WRITE, LAST_COLORELEMENT } ColorElements; diff --git a/DiskIOMeter.c b/DiskIOMeter.c new file mode 100644 index 000000000..8c3f1455f --- /dev/null +++ b/DiskIOMeter.c @@ -0,0 +1,92 @@ +/* +htop - DiskIOMeter.c +(C) 2020 Christian Göttsche +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "DiskIOMeter.h" + +#include + +#include "CRT.h" +#include "Platform.h" + + +static const int DiskIOMeter_attributes[] = { + DISKIO_UTIL_HIGH, + DISKIO_READ, + DISKIO_WRITE, +}; + +static unsigned long int cached_read_diff = 0; +static unsigned long int cached_write_diff = 0; +static double cached_utilisation_diff = 0.0; + +static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) { + static unsigned long int cached_read_total = 0; + static unsigned long int cached_write_total = 0; + static unsigned long int cached_msTimeSpend_total = 0; + static unsigned long long int cached_last_update = 0; + + struct timeval tv; + gettimeofday(&tv, NULL); + unsigned long long int timeInMilliSeconds = (unsigned long long int)tv.tv_sec * 1000 + (unsigned long long int)tv.tv_usec / 1000; + + /* update only every 500ms */ + if (timeInMilliSeconds - cached_last_update > 500) { + unsigned long int bytesRead, bytesWrite, msTimeSpend; + + Platform_getDiskIO(&bytesRead, &bytesWrite, &msTimeSpend); + + cached_read_diff = (bytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + cached_read_total = bytesRead; + + cached_write_diff = (bytesWrite - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + cached_write_total = bytesWrite; + + cached_utilisation_diff = 100 * (double)(msTimeSpend - cached_msTimeSpend_total) / (timeInMilliSeconds - cached_last_update); + cached_last_update = timeInMilliSeconds; + cached_msTimeSpend_total = msTimeSpend; + } + + this->values[0] = cached_utilisation_diff; + this->total = MAXIMUM(this->values[0], 100.0); /* fix total after (initial) spike */ + + char bufferRead[12], bufferWrite[12]; + Meter_humanUnit(bufferRead, cached_read_diff, sizeof(bufferRead)); + Meter_humanUnit(bufferWrite, cached_write_diff, sizeof(bufferWrite)); + snprintf(buffer, len, "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff); +} + +static void DIskIOMeter_display(ATTR_UNUSED Object* cast, RichString* out) { + char buffer[16]; + + int color = cached_utilisation_diff > 40.0 ? DISKIO_UTIL_HIGH : METER_VALUE; + xSnprintf(buffer, sizeof(buffer), "%.1f%%", cached_utilisation_diff); + RichString_write(out, CRT_colors[color], buffer); + + RichString_append(out, CRT_colors[METER_TEXT], " read: "); + Meter_humanUnit(buffer, cached_read_diff, sizeof(buffer)); + RichString_append(out, CRT_colors[DISKIO_READ], buffer); + + RichString_append(out, CRT_colors[METER_TEXT], " write: "); + Meter_humanUnit(buffer, cached_write_diff, sizeof(buffer)); + RichString_append(out, CRT_colors[DISKIO_WRITE], buffer); +} + +MeterClass DiskIOMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = DIskIOMeter_display + }, + .updateValues = DiskIOMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 1, + .total = 100.0, + .attributes = DiskIOMeter_attributes, + .name = "DiskIO", + .uiName = "Disk IO", + .caption = "Disk IO: " +}; diff --git a/DiskIOMeter.h b/DiskIOMeter.h new file mode 100644 index 000000000..6aca5c2d7 --- /dev/null +++ b/DiskIOMeter.h @@ -0,0 +1,14 @@ +#ifndef HEADER_DiskIOMeter +#define HEADER_DiskIOMeter +/* + h top - DiskIOMeter*.h +(C) 2020 Christian Göttsche +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern MeterClass DiskIOMeter_class; + +#endif /* HEADER_DiskIOMeter */ diff --git a/Makefile.am b/Makefile.am index 441ea80e6..ea9a2e429 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,8 +15,8 @@ AM_LDFLAGS = AM_CPPFLAGS = -DNDEBUG myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ -ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c MainPanel.c \ -DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ +ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DiskIOMeter.c DiskIOMeter.h \ +MainPanel.c DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.c \ diff --git a/darwin/Platform.c b/darwin/Platform.c index 747ffefb7..5aa50a65f 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -305,3 +305,8 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } + +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { + // TODO + *bytesRead = *bytesWrite = *msTimeSpend = 0; +} diff --git a/darwin/Platform.h b/darwin/Platform.h index 6c0385874..3a6f119f6 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -48,4 +48,6 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); + #endif diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 7d16eda15..36ab2c21a 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -205,3 +205,8 @@ char* Platform_getProcessEnv(pid_t pid) { (void)pid; // prevent unused warning return NULL; } + +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { + // TODO + *bytesRead = *bytesWrite = *msTimeSpend = 0; +} diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 14a249e13..c0a602336 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -42,4 +42,6 @@ void Platform_setTasksValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); + #endif diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 318b3e122..36256f9a1 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -220,3 +220,8 @@ char* Platform_getProcessEnv(pid_t pid) { // TODO return NULL; } + +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { + // TODO + *bytesRead = *bytesWrite = *msTimeSpend = 0; +} diff --git a/freebsd/Platform.h b/freebsd/Platform.h index e58e99d02..780d23e6a 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -45,4 +45,6 @@ void Platform_setTasksValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); + #endif diff --git a/linux/Platform.c b/linux/Platform.c index 58bc3bea7..78313b2d0 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -14,6 +14,7 @@ in the source distribution for its full text. #include "Meter.h" #include "CPUMeter.h" +#include "DiskIOMeter.h" #include "MemoryMeter.h" #include "SwapMeter.h" #include "TasksMeter.h" @@ -25,12 +26,14 @@ in the source distribution for its full text. #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" #include "LinuxProcess.h" +#include "StringUtils.h" #include #include #include #include #include +#include ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, (int)M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; @@ -131,6 +134,7 @@ MeterClass* Platform_meterTypes[] = { &PressureStallMemoryFullMeter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, + &DiskIOMeter_class, NULL }; @@ -281,3 +285,50 @@ void Platform_getPressureStall(const char *file, bool some, double* ten, double* assert(total == 3); fclose(fd); } + +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { + FILE *fd = fopen(PROCDIR "/diskstats", "r"); + if (!fd) { + *bytesRead = 0; + *bytesWrite = 0; + *msTimeSpend = 0; + return; + } + unsigned long int read_sum = 0, write_sum = 0, timeSpend_sum = 0; + char lineBuffer[256]; + while (fgets(lineBuffer, sizeof(lineBuffer), fd)) { + char diskname[32]; + unsigned long int read_tmp, write_tmp, timeSpend_tmp; + if (sscanf(lineBuffer, "%*d %*d %31s %*u %*u %lu %*u %*u %*u %lu %*u %*u %lu", diskname, &read_tmp, &write_tmp, &timeSpend_tmp) == 4) { + if (String_startsWith(diskname, "dm-")) + continue; + + /* only count root disks, e.g. do not count IO from sda and sda1 twice */ + if ((diskname[0] == 's' || diskname[0] == 'h') + && diskname[1] == 'd' + && isalpha((unsigned char)diskname[2]) + && isdigit((unsigned char)diskname[3])) + continue; + + /* only count root disks, e.g. do not count IO from mmcblk0 and mmcblk0p1 twice */ + if (diskname[0] == 'm' + && diskname[1] == 'm' + && diskname[2] == 'c' + && diskname[3] == 'b' + && diskname[4] == 'l' + && diskname[5] == 'k' + && isdigit((unsigned char)diskname[6]) + && diskname[7] == 'p') + continue; + + read_sum += read_tmp; + write_sum += write_tmp; + timeSpend_sum += timeSpend_tmp; + } + } + fclose(fd); + /* multiply with sector size */ + *bytesRead = 512 * read_sum; + *bytesWrite = 512 * write_sum; + *msTimeSpend = timeSpend_sum; +} diff --git a/linux/Platform.h b/linux/Platform.h index 5060ea240..68b18f285 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -44,4 +44,6 @@ char* Platform_getProcessEnv(pid_t pid); void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); + #endif diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 2c8bc7aeb..ce3709945 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -286,3 +286,8 @@ char* Platform_getProcessEnv(pid_t pid) { (void) kvm_close(kt); return env; } + +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { + // TODO + *bytesRead = *bytesWrite = *msTimeSpend = 0; +} diff --git a/openbsd/Platform.h b/openbsd/Platform.h index 9e742bf3c..e5e09ce0e 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -43,4 +43,6 @@ void Platform_setTasksValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); + #endif diff --git a/solaris/Platform.c b/solaris/Platform.c index 05b444628..2114215ef 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -258,3 +258,8 @@ char* Platform_getProcessEnv(pid_t pid) { strncpy( envBuilder.env + envBuilder.size, "\0", 1); return envBuilder.env; } + +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { + // TODO + *bytesRead = *bytesWrite = *msTimeSpend = 0; +} diff --git a/solaris/Platform.h b/solaris/Platform.h index 29cc79648..d3dddb722 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -63,4 +63,6 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); + #endif diff --git a/unsupported/Platform.c b/unsupported/Platform.c index b095e1264..6a6b01310 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -135,3 +135,7 @@ char* Platform_getProcessEnv(pid_t pid) { (void) pid; return NULL; } + +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { + *bytesRead = *bytesWrite = *msTimeSpend = 0; +} diff --git a/unsupported/Platform.h b/unsupported/Platform.h index fca7fc476..cdce6f38f 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -47,4 +47,6 @@ bool Process_isThread(Process* this); char* Platform_getProcessEnv(pid_t pid); +void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); + #endif From b7f63292e5394ca7eee2dc5d14d0d1244db61c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 17 Sep 2020 22:23:05 +0200 Subject: [PATCH 253/411] Add --enable-debug configure option to enable asserts asserts are still disabled by default. --- Makefile.am | 1 - configure.ac | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index ea9a2e429..1ef92364a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,6 @@ pixmap_DATA = htop.png AM_CFLAGS += -pedantic -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)" AM_LDFLAGS = -AM_CPPFLAGS = -DNDEBUG myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DiskIOMeter.c DiskIOMeter.h \ diff --git a/configure.ac b/configure.ac index d06c598f4..6104a1f3b 100644 --- a/configure.ac +++ b/configure.ac @@ -293,8 +293,14 @@ AM_CFLAGS="\ AC_ARG_ENABLE([werror], [AS_HELP_STRING([--enable-werror], [Treat warnings as errors (default: warnings are not errors)])], [enable_werror="$enableval"], [enable_werror=no]) AS_IF([test "x$enable_werror" = "xyes"], [AM_CFLAGS="$AM_CFLAGS -Werror"]) + AC_SUBST([AM_CFLAGS]) +AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], [Enable asserts (default: asserts are disabled)])], [enable_debug="$enableval"], [enable_debug=no]) +AS_IF([test "x$enable_debug" = "xyes"], , [AM_CPPFLAGS="$AM_CPPFLAGS -DNDEBUG"]) + +AC_SUBST([AM_CPPFLAGS]) + # Bail out on errors. # ---------------------------------------------------------------------- if test ! -z "$missing_libraries"; then From d69585b82abfdaede9e8c358982a4953c432e8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 17 Sep 2020 22:27:33 +0200 Subject: [PATCH 254/411] Resolve DEBUG compilation issues Use NDEBUG conditional instead of DEBUG. Do not call static functions in extern inline ones. Vector.c:67:11: error: static function 'Vector_isConsistent' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline] --- CRT.c | 4 ++-- Hashtable.c | 6 +++--- Hashtable.h | 4 ++-- Object.c | 4 ++-- Object.h | 4 ++-- Vector.c | 46 +++++++++++++--------------------------- Vector.h | 23 +++++--------------- linux/LinuxProcessList.c | 2 +- 8 files changed, 32 insertions(+), 61 deletions(-) diff --git a/CRT.c b/CRT.c index 693722986..374e1721e 100644 --- a/CRT.c +++ b/CRT.c @@ -631,13 +631,13 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { define_key(sequence, KEY_ALT('A' + (c - 'a'))); } } -#ifndef DEBUG + struct sigaction act; sigemptyset (&act.sa_mask); act.sa_flags = (int)SA_RESETHAND; act.sa_handler = CRT_handleSIGSEGV; sigaction (SIGSEGV, &act, &old_sigsegv_handler); -#endif + signal(SIGTERM, CRT_handleSIGTERM); signal(SIGQUIT, CRT_handleSIGTERM); use_default_colors(); diff --git a/Hashtable.c b/Hashtable.c index bb9517ad2..f8815f939 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -12,7 +12,7 @@ in the source distribution for its full text. #include -#ifdef DEBUG +#ifndef NDEBUG static bool Hashtable_isConsistent(Hashtable* this) { int items = 0; @@ -39,7 +39,7 @@ int Hashtable_count(Hashtable* this) { return items; } -#endif +#endif /* NDEBUG */ static HashtableItem* HashtableItem_new(unsigned int key, void* value) { HashtableItem* this; @@ -124,7 +124,7 @@ void* Hashtable_remove(Hashtable* this, unsigned int key) { return NULL; } -inline void* Hashtable_get(Hashtable* this, unsigned int key) { +void* Hashtable_get(Hashtable* this, unsigned int key) { unsigned int index = key % this->size; HashtableItem* bucketPtr = this->buckets[index]; while (true) { diff --git a/Hashtable.h b/Hashtable.h index 144f01cf3..aacbb3406 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -26,11 +26,11 @@ struct Hashtable_ { bool owner; }; -#ifdef DEBUG +#ifndef NDEBUG int Hashtable_count(Hashtable* this); -#endif +#endif /* NDEBUG */ Hashtable* Hashtable_new(int size, bool owner); diff --git a/Object.c b/Object.c index 4d8045ddf..9ac2be670 100644 --- a/Object.c +++ b/Object.c @@ -12,7 +12,7 @@ ObjectClass Object_class = { .extends = NULL }; -#ifdef DEBUG +#ifndef NDEBUG bool Object_isA(Object* o, const ObjectClass* klass) { if (!o) @@ -26,4 +26,4 @@ bool Object_isA(Object* o, const ObjectClass* klass) { return false; } -#endif +#endif /* NDEBUG */ diff --git a/Object.h b/Object.h index 50a5f12db..462797c29 100644 --- a/Object.h +++ b/Object.h @@ -48,10 +48,10 @@ typedef union { extern ObjectClass Object_class; -#ifdef DEBUG +#ifndef NDEBUG bool Object_isA(Object* o, const ObjectClass* klass); -#endif +#endif /* NDEBUG */ #endif diff --git a/Vector.c b/Vector.c index 713d68318..ebddc0d62 100644 --- a/Vector.c +++ b/Vector.c @@ -38,9 +38,9 @@ void Vector_delete(Vector* this) { free(this); } -#ifdef DEBUG +#ifndef NDEBUG -static inline bool Vector_isConsistent(Vector* this) { +static bool Vector_isConsistent(Vector* this) { assert(this->items <= this->arraySize); if (this->owner) { for (int i = 0; i < this->items; i++) @@ -62,7 +62,18 @@ int Vector_count(Vector* this) { return items; } -#endif +Object* Vector_get(Vector* this, int idx) { + assert(idx < this->items); + assert(Vector_isConsistent(this)); + return this->array[idx]; +} + +int Vector_size(Vector* this) { + assert(Vector_isConsistent(this)); + return this->items; +} + +#endif /* NDEBUG */ void Vector_prune(Vector* this) { assert(Vector_isConsistent(this)); @@ -251,33 +262,6 @@ void Vector_set(Vector* this, int idx, void* data_) { assert(Vector_isConsistent(this)); } -#ifdef DEBUG - -inline Object* Vector_get(Vector* this, int idx) { - assert(idx < this->items); - assert(Vector_isConsistent(this)); - return this->array[idx]; -} - -#else - -// In this case, Vector_get is defined as a macro in vector.h - -#endif - -#ifdef DEBUG - -inline int Vector_size(Vector* this) { - assert(Vector_isConsistent(this)); - return this->items; -} - -#else - -// In this case, Vector_size is defined as a macro in vector.h - -#endif - /* static void Vector_merge(Vector* this, Vector* v2) { @@ -303,7 +287,7 @@ void Vector_add(Vector* this, void* data_) { assert(Vector_isConsistent(this)); } -inline int Vector_indexOf(Vector* this, void* search_, Object_Compare compare) { +int Vector_indexOf(Vector* this, void* search_, Object_Compare compare) { Object* search = search_; assert(Object_isA((Object*)search, this->type)); assert(compare); diff --git a/Vector.h b/Vector.h index 209e27cff..9bf73b52a 100644 --- a/Vector.h +++ b/Vector.h @@ -28,12 +28,6 @@ Vector* Vector_new(ObjectClass* type, bool owner, int size); void Vector_delete(Vector* this); -#ifdef DEBUG - -int Vector_count(Vector* this); - -#endif - void Vector_prune(Vector* this); void Vector_quickSort(Vector* this); @@ -52,25 +46,18 @@ void Vector_moveDown(Vector* this, int idx); void Vector_set(Vector* this, int idx, void* data_); -#ifdef DEBUG +#ifndef NDEBUG Object* Vector_get(Vector* this, int idx); - -#else - -#define Vector_get(v_, idx_) ((v_)->array[idx_]) - -#endif - -#ifdef DEBUG - int Vector_size(Vector* this); +int Vector_count(Vector* this); -#else +#else /* NDEBUG */ +#define Vector_get(v_, idx_) ((v_)->array[idx_]) #define Vector_size(v_) ((v_)->items) -#endif +#endif /* NDEBUG */ void Vector_add(Vector* this, void* data_); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 1df7b32bd..dcef14cf4 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -670,7 +670,7 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { if ((nlattr = nlattrs[TASKSTATS_TYPE_AGGR_PID]) || (nlattr = nlattrs[TASKSTATS_TYPE_NULL])) { stats = nla_data(nla_next(nla_data(nlattr), &rem)); - assert(lp->super.pid == stats->ac_pid); + assert(lp->super.pid == (pid_t)stats->ac_pid); timeDelta = (stats->ac_etime*1000 - lp->delay_read_time); #define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x; #define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100); From b82a13c6ba48eb8711071342bec80798aca5de1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 21 Sep 2020 15:06:19 +0200 Subject: [PATCH 255/411] Add clang analyzer CI job --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ AffinityPanel.c | 7 ++++--- htop.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d6de8fe9..5eb002ccb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,26 @@ jobs: - name: Distcheck run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct' + build-ubuntu-latest-clang-analyzer: + runs-on: ubuntu-latest + env: + CC: clang-11 + steps: + - uses: actions/checkout@v2 + - name: install clang repo + run: | + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key 2>/dev/null | sudo apt-key add - + sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' -y + sudo apt-get update -q + - name: Install Dependencies + run: sudo apt-get install clang-11 clang-tools-11 libncursesw5-dev libhwloc-dev libnl-3-dev libnl-genl-3-dev + - name: Bootstrap + run: ./autogen.sh + - name: Configure + run: scan-build-11 -analyze-headers --status-bugs ./configure --enable-debug --enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct + - name: Build + run: scan-build-11 -analyze-headers --status-bugs make -j"$(nproc)" + whitespace_check: runs-on: ubuntu-latest steps: diff --git a/AffinityPanel.c b/AffinityPanel.c index 1cae4ee49..79fe7f36a 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -274,9 +274,10 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u } xSnprintf(&indent_buf[off], left, "%s", obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]); - size_t len = strlen(&indent_buf[off]); - off += len; - left -= len; + // Uncomment when further appending to indent_buf + //size_t len = strlen(&indent_buf[off]); + //off += len; + //left -= len; } xSnprintf(buf, 64, "%s %s%u", type_name, index_prefix, index); diff --git a/htop.c b/htop.c index fbd6dee4b..5054379d4 100644 --- a/htop.c +++ b/htop.c @@ -107,6 +107,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { printVersionFlag(); exit(0); case 's': + assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */ if (strcmp(optarg, "help") == 0) { for (int j = 1; j < Platform_numberOfFields; j++) { const char* name = Process_fields[j].name; @@ -158,6 +159,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { flags.treeView = true; break; case 'p': { + assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */ char* argCopy = xStrdup(optarg); char* saveptr; char* pid = strtok_r(argCopy, ",", &saveptr); From 42946ec113e8ae6d6bc114dbd90e9721f464abfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 28 Sep 2020 21:14:50 +0200 Subject: [PATCH 256/411] Introduce ARRAYSIZE --- Macros.h | 4 ++++ Settings.c | 2 +- linux/LinuxCRT.c | 2 +- linux/Platform.c | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Macros.h b/Macros.h index ef4e8908b..de674edaa 100644 --- a/Macros.h +++ b/Macros.h @@ -13,6 +13,10 @@ #define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low)) #endif +#ifndef ARRAYSIZE +#define ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + #ifdef __GNUC__ // defined by GCC and Clang #define ATTR_FORMAT(type, index, check) __attribute__((format (type, index, check))) diff --git a/Settings.c b/Settings.c index 0aac47968..1cfd00616 100644 --- a/Settings.c +++ b/Settings.c @@ -20,7 +20,7 @@ in the source distribution for its full text. void Settings_delete(Settings* this) { free(this->filename); free(this->fields); - for (unsigned int i = 0; i < (sizeof(this->columns)/sizeof(MeterColumnSettings)); i++) { + for (unsigned int i = 0; i < ARRAYSIZE(this->columns); i++) { String_freeArray(this->columns[i].names); free(this->columns[i].modes); } diff --git a/linux/LinuxCRT.c b/linux/LinuxCRT.c index 2679d4f61..7adb154da 100644 --- a/linux/LinuxCRT.c +++ b/linux/LinuxCRT.c @@ -22,7 +22,7 @@ void CRT_handleSIGSEGV(int sgn) { #ifdef __linux fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); #ifdef HAVE_EXECINFO_H - size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); + size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray)); fprintf(stderr, "\n Please include in your report the following backtrace: \n"); backtrace_symbols_fd(backtraceArray, size, 2); fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); diff --git a/linux/Platform.c b/linux/Platform.c index 78313b2d0..2d3258646 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -79,7 +79,7 @@ const SignalItem Platform_signals[] = { { .name = "31 SIGSYS", .number = 31 }, }; -const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); static Htop_Reaction Platform_actionSetIOPriority(State* st) { Panel* panel = st->panel; From 90d16b66305aecccbfb5600b3aa4e61bde175e9a Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 5 Oct 2020 09:47:49 +0200 Subject: [PATCH 257/411] Update copyright statement --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index fb6400fdd..da895c5e2 100644 --- a/configure.ac +++ b/configure.ac @@ -329,7 +329,7 @@ if test ! -z "$missing_headers"; then AC_MSG_ERROR([missing headers: $missing_headers]) fi -AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-2018 Hisham Muhammad", [Copyright message.]) +AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-2019 Hisham Muhammad, (C) 2020 htop dev team", [Copyright message.]) # We're done, let's go! # ---------------------------------------------------------------------- From 079c2abf8e571a865102957b2d0d3a55863aadcf Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 5 Oct 2020 09:51:32 +0200 Subject: [PATCH 258/411] Update License consistently to GPLv2 as per COPYING file --- Action.c | 4 ++-- Action.h | 2 +- Affinity.c | 2 +- Affinity.h | 2 +- AffinityPanel.c | 2 +- AffinityPanel.h | 2 +- AvailableColumnsPanel.c | 2 +- AvailableColumnsPanel.h | 2 +- AvailableMetersPanel.c | 2 +- AvailableMetersPanel.h | 2 +- BatteryMeter.c | 2 +- BatteryMeter.h | 2 +- CPUMeter.c | 2 +- CPUMeter.h | 2 +- CRT.c | 2 +- CRT.h | 2 +- CategoriesPanel.c | 2 +- CategoriesPanel.h | 2 +- CheckItem.c | 2 +- CheckItem.h | 2 +- ClockMeter.c | 2 +- ClockMeter.h | 2 +- ColorsPanel.c | 2 +- ColorsPanel.h | 2 +- ColumnsPanel.c | 2 +- ColumnsPanel.h | 2 +- DiskIOMeter.c | 2 +- DiskIOMeter.h | 2 +- DisplayOptionsPanel.c | 2 +- DisplayOptionsPanel.h | 2 +- FunctionBar.c | 2 +- FunctionBar.h | 2 +- Hashtable.c | 2 +- Hashtable.h | 2 +- Header.c | 2 +- Header.h | 2 +- HostnameMeter.c | 2 +- HostnameMeter.h | 2 +- IncSet.c | 2 +- IncSet.h | 2 +- ListItem.c | 2 +- ListItem.h | 2 +- LoadAverageMeter.c | 2 +- LoadAverageMeter.h | 2 +- MainPanel.c | 2 +- MainPanel.h | 2 +- MemoryMeter.c | 2 +- MemoryMeter.h | 2 +- Meter.c | 2 +- Meter.h | 2 +- MetersPanel.c | 2 +- MetersPanel.h | 2 +- Object.c | 2 +- Object.h | 2 +- OpenFilesScreen.c | 2 +- OpenFilesScreen.h | 2 +- Panel.c | 2 +- Panel.h | 2 +- Process.c | 2 +- Process.h | 2 +- ProcessList.c | 2 +- ProcessList.h | 2 +- RichString.c | 2 +- RichString.h | 2 +- ScreenManager.c | 2 +- ScreenManager.h | 2 +- Settings.c | 2 +- Settings.h | 2 +- SignalsPanel.c | 2 +- SignalsPanel.h | 2 +- StringUtils.c | 2 +- StringUtils.h | 2 +- SwapMeter.c | 2 +- SwapMeter.h | 2 +- TasksMeter.c | 2 +- TasksMeter.h | 2 +- TraceScreen.c | 2 +- TraceScreen.h | 2 +- UptimeMeter.c | 2 +- UptimeMeter.h | 2 +- UsersTable.c | 2 +- UsersTable.h | 2 +- Vector.c | 2 +- Vector.h | 2 +- configure.ac | 2 +- darwin/DarwinCRT.c | 2 +- darwin/DarwinCRT.h | 2 +- darwin/DarwinProcess.c | 2 +- darwin/DarwinProcess.h | 2 +- darwin/DarwinProcessList.c | 2 +- darwin/DarwinProcessList.h | 2 +- darwin/Platform.c | 2 +- darwin/Platform.h | 2 +- dragonflybsd/Battery.c | 2 +- dragonflybsd/Battery.h | 2 +- dragonflybsd/DragonFlyBSDCRT.c | 2 +- dragonflybsd/DragonFlyBSDCRT.h | 2 +- dragonflybsd/DragonFlyBSDProcess.c | 2 +- dragonflybsd/DragonFlyBSDProcess.h | 2 +- dragonflybsd/DragonFlyBSDProcessList.c | 2 +- dragonflybsd/DragonFlyBSDProcessList.h | 2 +- dragonflybsd/Platform.c | 2 +- dragonflybsd/Platform.h | 2 +- freebsd/Battery.c | 2 +- freebsd/Battery.h | 2 +- freebsd/FreeBSDCRT.c | 2 +- freebsd/FreeBSDCRT.h | 2 +- freebsd/FreeBSDProcess.c | 2 +- freebsd/FreeBSDProcess.h | 2 +- freebsd/FreeBSDProcessList.c | 2 +- freebsd/FreeBSDProcessList.h | 2 +- freebsd/Platform.c | 2 +- freebsd/Platform.h | 2 +- htop.c | 4 ++-- linux/Battery.c | 2 +- linux/Battery.h | 2 +- linux/IOPriority.h | 2 +- linux/IOPriorityPanel.c | 2 +- linux/IOPriorityPanel.h | 2 +- linux/LinuxCRT.c | 2 +- linux/LinuxCRT.h | 2 +- linux/LinuxProcess.c | 2 +- linux/LinuxProcess.h | 2 +- linux/LinuxProcessList.c | 2 +- linux/LinuxProcessList.h | 2 +- linux/Platform.c | 2 +- linux/Platform.h | 2 +- linux/PressureStallMeter.c | 2 +- linux/PressureStallMeter.h | 2 +- openbsd/Battery.c | 2 +- openbsd/Battery.h | 2 +- openbsd/OpenBSDCRT.c | 2 +- openbsd/OpenBSDCRT.h | 2 +- openbsd/OpenBSDProcess.c | 2 +- openbsd/OpenBSDProcess.h | 2 +- openbsd/OpenBSDProcessList.c | 2 +- openbsd/OpenBSDProcessList.h | 2 +- openbsd/Platform.c | 2 +- openbsd/Platform.h | 2 +- solaris/Platform.c | 2 +- solaris/Platform.h | 2 +- solaris/SolarisCRT.c | 2 +- solaris/SolarisCRT.h | 2 +- solaris/SolarisProcess.c | 2 +- solaris/SolarisProcess.h | 2 +- solaris/SolarisProcessList.c | 2 +- solaris/SolarisProcessList.h | 2 +- unsupported/Platform.c | 2 +- unsupported/Platform.h | 2 +- unsupported/UnsupportedCRT.c | 2 +- unsupported/UnsupportedCRT.h | 2 +- unsupported/UnsupportedProcess.c | 2 +- unsupported/UnsupportedProcess.h | 2 +- unsupported/UnsupportedProcessList.c | 2 +- unsupported/UnsupportedProcessList.h | 2 +- zfs/ZfsArcMeter.c | 2 +- zfs/ZfsArcMeter.h | 2 +- zfs/ZfsArcStats.c | 2 +- zfs/ZfsArcStats.h | 2 +- zfs/ZfsCompressedArcMeter.c | 2 +- zfs/ZfsCompressedArcMeter.h | 2 +- zfs/openzfs_sysctl.c | 2 +- zfs/openzfs_sysctl.h | 2 +- 163 files changed, 165 insertions(+), 165 deletions(-) diff --git a/Action.c b/Action.c index 233f13247..106fbb039 100644 --- a/Action.c +++ b/Action.c @@ -1,7 +1,7 @@ /* htop - Action.c (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ @@ -441,7 +441,7 @@ static Htop_Reaction actionHelp(State* st) { mvhline(i, 0, ' ', COLS); mvaddstr(0, 0, "htop " VERSION " - " COPYRIGHT); - mvaddstr(1, 0, "Released under the GNU GPL. See 'man' page for more info."); + mvaddstr(1, 0, "Released under the GNU GPLv2. See 'man' page for more info."); attrset(CRT_colors[DEFAULT_COLOR]); mvaddstr(3, 0, "CPU usage bar: "); diff --git a/Action.h b/Action.h index 0623e37d8..4f85b4817 100644 --- a/Action.h +++ b/Action.h @@ -3,7 +3,7 @@ /* htop - Action.h (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Affinity.c b/Affinity.c index d207e5a34..852d4d5f4 100644 --- a/Affinity.c +++ b/Affinity.c @@ -2,7 +2,7 @@ htop - Affinity.c (C) 2004-2011 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Affinity.h b/Affinity.h index ced161b44..6d744dded 100644 --- a/Affinity.h +++ b/Affinity.h @@ -4,7 +4,7 @@ htop - Affinity.h (C) 2004-2011 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/AffinityPanel.c b/AffinityPanel.c index 79fe7f36a..6c64b14b7 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -1,7 +1,7 @@ /* htop - AffinityPanel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/AffinityPanel.h b/AffinityPanel.h index 61e4287a0..37c7e5d9e 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -3,7 +3,7 @@ /* htop - AffinityPanel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index 0d9749e78..e605ae520 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -1,7 +1,7 @@ /* htop - AvailableColumnsPanel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/AvailableColumnsPanel.h b/AvailableColumnsPanel.h index 629280589..dd011755b 100644 --- a/AvailableColumnsPanel.h +++ b/AvailableColumnsPanel.h @@ -3,7 +3,7 @@ /* htop - AvailableColumnsPanel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index 3538cd13d..604a6891c 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -1,7 +1,7 @@ /* htop - AvailableMetersPanel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index 92d7c941d..f4f18dac2 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -3,7 +3,7 @@ /* htop - AvailableMetersPanel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/BatteryMeter.c b/BatteryMeter.c index c43bbe5f0..4f119e1f9 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -1,7 +1,7 @@ /* htop - BatteryMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). diff --git a/BatteryMeter.h b/BatteryMeter.h index b67754d39..8f9441ccd 100644 --- a/BatteryMeter.h +++ b/BatteryMeter.h @@ -3,7 +3,7 @@ /* htop - BatteryMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). diff --git a/CPUMeter.c b/CPUMeter.c index 44ef1adde..51c16c683 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -1,7 +1,7 @@ /* htop - CPUMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/CPUMeter.h b/CPUMeter.h index 6244c42a4..471f33fcb 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -3,7 +3,7 @@ /* htop - CPUMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/CRT.c b/CRT.c index 374e1721e..21c97a932 100644 --- a/CRT.c +++ b/CRT.c @@ -1,7 +1,7 @@ /* htop - CRT.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/CRT.h b/CRT.h index 4eeb9a461..217f19580 100644 --- a/CRT.h +++ b/CRT.h @@ -3,7 +3,7 @@ /* htop - CRT.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/CategoriesPanel.c b/CategoriesPanel.c index c12b3905e..b09a015f3 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -1,7 +1,7 @@ /* htop - CategoriesPanel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/CategoriesPanel.h b/CategoriesPanel.h index 5f8cb0f50..891d77113 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -3,7 +3,7 @@ /* htop - CategoriesPanel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/CheckItem.c b/CheckItem.c index d14149ee6..f6d5bb916 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -1,7 +1,7 @@ /* htop - CheckItem.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/CheckItem.h b/CheckItem.h index 11ac35f56..714835262 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -3,7 +3,7 @@ /* htop - CheckItem.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ClockMeter.c b/ClockMeter.c index 6ad191a20..d309852f5 100644 --- a/ClockMeter.c +++ b/ClockMeter.c @@ -1,7 +1,7 @@ /* htop - ClockMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ClockMeter.h b/ClockMeter.h index bb6881aea..e431e3677 100644 --- a/ClockMeter.h +++ b/ClockMeter.h @@ -3,7 +3,7 @@ /* htop - ClockMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ColorsPanel.c b/ColorsPanel.c index 972f60756..36cd85bd9 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -1,7 +1,7 @@ /* htop - ColorsPanel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ColorsPanel.h b/ColorsPanel.h index 8dd61711c..0f69e8f74 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -3,7 +3,7 @@ /* htop - ColorsPanel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ColumnsPanel.c b/ColumnsPanel.c index 318c7af8c..d7132e188 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -1,7 +1,7 @@ /* htop - ColumnsPanel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ColumnsPanel.h b/ColumnsPanel.h index be139a6e7..a35036f11 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -3,7 +3,7 @@ /* htop - ColumnsPanel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 8c3f1455f..1349bf40b 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -1,7 +1,7 @@ /* htop - DiskIOMeter.c (C) 2020 Christian Göttsche -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/DiskIOMeter.h b/DiskIOMeter.h index 6aca5c2d7..f75aaf814 100644 --- a/DiskIOMeter.h +++ b/DiskIOMeter.h @@ -3,7 +3,7 @@ /* h top - DiskIOMeter*.h (C) 2020 Christian Göttsche -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 37b5bcd09..54b389ba4 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -1,7 +1,7 @@ /* htop - DisplayOptionsPanel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index b103503b6..aad7bc758 100644 --- a/DisplayOptionsPanel.h +++ b/DisplayOptionsPanel.h @@ -3,7 +3,7 @@ /* htop - DisplayOptionsPanel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/FunctionBar.c b/FunctionBar.c index e05f72e65..55279c213 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -1,7 +1,7 @@ /* htop - FunctionBar.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/FunctionBar.h b/FunctionBar.h index 486990fc3..8fa744041 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -3,7 +3,7 @@ /* htop - FunctionBar.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Hashtable.c b/Hashtable.c index f8815f939..d032ba77b 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -1,7 +1,7 @@ /* htop - Hashtable.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Hashtable.h b/Hashtable.h index aacbb3406..f42620916 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -3,7 +3,7 @@ /* htop - Hashtable.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Header.c b/Header.c index d2f3b8846..7a58c4c21 100644 --- a/Header.c +++ b/Header.c @@ -1,7 +1,7 @@ /* htop - Header.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Header.h b/Header.h index b221becfa..2637dc99f 100644 --- a/Header.h +++ b/Header.h @@ -3,7 +3,7 @@ /* htop - Header.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/HostnameMeter.c b/HostnameMeter.c index edb23358e..4d39a39a8 100644 --- a/HostnameMeter.c +++ b/HostnameMeter.c @@ -1,7 +1,7 @@ /* htop - HostnameMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/HostnameMeter.h b/HostnameMeter.h index 152100d04..c868512b1 100644 --- a/HostnameMeter.h +++ b/HostnameMeter.h @@ -3,7 +3,7 @@ /* htop - HostnameMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/IncSet.c b/IncSet.c index b9a1d92d7..3e3a1b998 100644 --- a/IncSet.c +++ b/IncSet.c @@ -1,7 +1,7 @@ /* htop - IncSet.c (C) 2005-2012 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/IncSet.h b/IncSet.h index 81f0f54cb..30b63665e 100644 --- a/IncSet.h +++ b/IncSet.h @@ -3,7 +3,7 @@ /* htop - IncSet.h (C) 2005-2012 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ListItem.c b/ListItem.c index 8d26d7f01..206444670 100644 --- a/ListItem.c +++ b/ListItem.c @@ -1,7 +1,7 @@ /* htop - ListItem.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ListItem.h b/ListItem.h index 3fea7257d..8e76ff7ed 100644 --- a/ListItem.h +++ b/ListItem.h @@ -3,7 +3,7 @@ /* htop - ListItem.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index 3f75aeca6..b54907857 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -1,7 +1,7 @@ /* htop - LoadAverageMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/LoadAverageMeter.h b/LoadAverageMeter.h index 5ac771a4a..442306930 100644 --- a/LoadAverageMeter.h +++ b/LoadAverageMeter.h @@ -3,7 +3,7 @@ /* htop - LoadAverageMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/MainPanel.c b/MainPanel.c index 4390dad63..51bcf1ae8 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -2,7 +2,7 @@ htop - ColumnsPanel.c (C) 2004-2015 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/MainPanel.h b/MainPanel.h index 01fb4977c..72790d3c6 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -4,7 +4,7 @@ htop - ColumnsPanel.h (C) 2004-2015 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/MemoryMeter.c b/MemoryMeter.c index cac0da72b..5834e5076 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -1,7 +1,7 @@ /* htop - MemoryMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/MemoryMeter.h b/MemoryMeter.h index f8df247d2..c490b143e 100644 --- a/MemoryMeter.h +++ b/MemoryMeter.h @@ -3,7 +3,7 @@ /* htop - MemoryMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Meter.c b/Meter.c index c453b4bc6..c0b2af9e4 100644 --- a/Meter.c +++ b/Meter.c @@ -1,7 +1,7 @@ /* htop - Meter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Meter.h b/Meter.h index da1dc5dfe..07e66e0e8 100644 --- a/Meter.h +++ b/Meter.h @@ -3,7 +3,7 @@ /* htop - Meter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/MetersPanel.c b/MetersPanel.c index c82ba48bc..6f59f0134 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -1,7 +1,7 @@ /* htop - MetersPanel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/MetersPanel.h b/MetersPanel.h index 919b117d7..501489443 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -3,7 +3,7 @@ /* htop - MetersPanel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Object.c b/Object.c index 9ac2be670..3195ab405 100644 --- a/Object.c +++ b/Object.c @@ -2,7 +2,7 @@ htop - Object.c (C) 2004-2012 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Object.h b/Object.h index 462797c29..53b522ae1 100644 --- a/Object.h +++ b/Object.h @@ -4,7 +4,7 @@ htop - Object.h (C) 2004-2012 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 915aba225..652e07484 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -1,7 +1,7 @@ /* htop - OpenFilesScreen.c (C) 2005-2006 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index 2c83cf1d5..9d63fe7a3 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -3,7 +3,7 @@ /* htop - OpenFilesScreen.h (C) 2005-2006 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Panel.c b/Panel.c index 315f3887a..b97fbc9c9 100644 --- a/Panel.c +++ b/Panel.c @@ -1,7 +1,7 @@ /* htop - Panel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Panel.h b/Panel.h index e5b28a41d..239de0a5e 100644 --- a/Panel.h +++ b/Panel.h @@ -3,7 +3,7 @@ /* htop - Panel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Process.c b/Process.c index 9fbe0dd71..07ea13829 100644 --- a/Process.c +++ b/Process.c @@ -2,7 +2,7 @@ htop - Process.c (C) 2004-2015 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Process.h b/Process.h index 6ed3a1f69..dd9c052c2 100644 --- a/Process.h +++ b/Process.h @@ -4,7 +4,7 @@ htop - Process.h (C) 2004-2015 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ProcessList.c b/ProcessList.c index aa529d5b1..6ec7ce851 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -1,7 +1,7 @@ /* htop - ProcessList.c (C) 2004,2005 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ProcessList.h b/ProcessList.h index 34f92b1bb..c9d1f28f1 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -3,7 +3,7 @@ /* htop - ProcessList.h (C) 2004,2005 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/RichString.c b/RichString.c index 661b765d3..8019135e6 100644 --- a/RichString.c +++ b/RichString.c @@ -1,7 +1,7 @@ /* htop - RichString.c (C) 2004,2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/RichString.h b/RichString.h index 6b626d40b..f402d6971 100644 --- a/RichString.h +++ b/RichString.h @@ -3,7 +3,7 @@ /* htop - RichString.h (C) 2004,2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ScreenManager.c b/ScreenManager.c index 2a2cb1d09..91ad47f83 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -1,7 +1,7 @@ /* htop - ScreenManager.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/ScreenManager.h b/ScreenManager.h index 4c78efd30..722fb7f22 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -3,7 +3,7 @@ /* htop - ScreenManager.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Settings.c b/Settings.c index 1cfd00616..1a8fafa0d 100644 --- a/Settings.c +++ b/Settings.c @@ -1,7 +1,7 @@ /* htop - Settings.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Settings.h b/Settings.h index 2f52681c9..97c0cb570 100644 --- a/Settings.h +++ b/Settings.h @@ -3,7 +3,7 @@ /* htop - Settings.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/SignalsPanel.c b/SignalsPanel.c index 8036142f8..933a21ba9 100644 --- a/SignalsPanel.c +++ b/SignalsPanel.c @@ -1,7 +1,7 @@ /* htop - SignalsPanel.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/SignalsPanel.h b/SignalsPanel.h index 460c81e73..9ded22f1b 100644 --- a/SignalsPanel.h +++ b/SignalsPanel.h @@ -3,7 +3,7 @@ /* htop - SignalsPanel.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/StringUtils.c b/StringUtils.c index 1e4c03b33..f74566f88 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -1,7 +1,7 @@ /* htop - StringUtils.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/StringUtils.h b/StringUtils.h index cc0abb002..936617ffb 100644 --- a/StringUtils.h +++ b/StringUtils.h @@ -3,7 +3,7 @@ /* htop - StringUtils.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/SwapMeter.c b/SwapMeter.c index ae4d40972..93a34e8f3 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -1,7 +1,7 @@ /* htop - SwapMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/SwapMeter.h b/SwapMeter.h index 2ba596cb6..502e6ee66 100644 --- a/SwapMeter.h +++ b/SwapMeter.h @@ -3,7 +3,7 @@ /* htop - SwapMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/TasksMeter.c b/TasksMeter.c index 45d3ba152..eb727cc27 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -1,7 +1,7 @@ /* htop - TasksMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/TasksMeter.h b/TasksMeter.h index 82ddc081e..8be826be3 100644 --- a/TasksMeter.h +++ b/TasksMeter.h @@ -3,7 +3,7 @@ /* htop - TasksMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/TraceScreen.c b/TraceScreen.c index 5c03f355a..184064546 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -1,7 +1,7 @@ /* htop - TraceScreen.c (C) 2005-2006 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/TraceScreen.h b/TraceScreen.h index 1e5218c9d..04b0848fa 100644 --- a/TraceScreen.h +++ b/TraceScreen.h @@ -3,7 +3,7 @@ /* htop - TraceScreen.h (C) 2005-2006 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/UptimeMeter.c b/UptimeMeter.c index 0a9589a03..07c4169bf 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -1,7 +1,7 @@ /* htop - UptimeMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/UptimeMeter.h b/UptimeMeter.h index cac51aad7..aef3ac375 100644 --- a/UptimeMeter.h +++ b/UptimeMeter.h @@ -3,7 +3,7 @@ /* htop - UptimeMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/UsersTable.c b/UsersTable.c index 86ed75c88..722dd6e14 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -1,7 +1,7 @@ /* htop - UsersTable.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/UsersTable.h b/UsersTable.h index 327bc087a..0cac7dc4b 100644 --- a/UsersTable.h +++ b/UsersTable.h @@ -3,7 +3,7 @@ /* htop - UsersTable.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Vector.c b/Vector.c index ebddc0d62..af219dda5 100644 --- a/Vector.c +++ b/Vector.c @@ -1,7 +1,7 @@ /* htop - Vector.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/Vector.h b/Vector.h index 9bf73b52a..e2de5e826 100644 --- a/Vector.h +++ b/Vector.h @@ -3,7 +3,7 @@ /* htop - Vector.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/configure.ac b/configure.ac index da895c5e2..f98f146a6 100644 --- a/configure.ac +++ b/configure.ac @@ -329,7 +329,7 @@ if test ! -z "$missing_headers"; then AC_MSG_ERROR([missing headers: $missing_headers]) fi -AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-2019 Hisham Muhammad, (C) 2020 htop dev team", [Copyright message.]) +AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-2019 Hisham Muhammad. (C) 2020 htop dev team.", [Copyright message.]) # We're done, let's go! # ---------------------------------------------------------------------- diff --git a/darwin/DarwinCRT.c b/darwin/DarwinCRT.c index da16913db..a4f0eb3f9 100644 --- a/darwin/DarwinCRT.c +++ b/darwin/DarwinCRT.c @@ -1,7 +1,7 @@ /* htop - DarwinCRT.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/darwin/DarwinCRT.h b/darwin/DarwinCRT.h index 663bd8b03..258fb68ec 100644 --- a/darwin/DarwinCRT.h +++ b/darwin/DarwinCRT.h @@ -3,7 +3,7 @@ /* htop - DarwinCRT.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 430b2b494..d3af4788d 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -1,7 +1,7 @@ /* htop - DarwinProcess.c (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index cf76fa8db..276795822 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -3,7 +3,7 @@ /* htop - DarwinProcess.h (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index dea82379b..ad8488771 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -1,7 +1,7 @@ /* htop - DarwinProcessList.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index c6b29665e..58102d355 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -3,7 +3,7 @@ /* htop - DarwinProcessList.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/darwin/Platform.c b/darwin/Platform.c index 5aa50a65f..942db15ac 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -2,7 +2,7 @@ htop - darwin/Platform.c (C) 2014 Hisham H. Muhammad (C) 2015 David C. Hunt -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/darwin/Platform.h b/darwin/Platform.h index 3a6f119f6..ba7799761 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -4,7 +4,7 @@ htop - darwin/Platform.h (C) 2014 Hisham H. Muhammad (C) 2015 David C. Hunt -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/Battery.c b/dragonflybsd/Battery.c index bb1a575ad..4bae3aa5d 100644 --- a/dragonflybsd/Battery.c +++ b/dragonflybsd/Battery.c @@ -2,7 +2,7 @@ htop - dragonflybsd/Battery.c (C) 2015 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/Battery.h b/dragonflybsd/Battery.h index 2e42351b1..eed0f630f 100644 --- a/dragonflybsd/Battery.h +++ b/dragonflybsd/Battery.h @@ -4,7 +4,7 @@ htop - dragonflybsd/Battery.h (C) 2015 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/DragonFlyBSDCRT.c b/dragonflybsd/DragonFlyBSDCRT.c index 4d355ae9e..ae8e7fec9 100644 --- a/dragonflybsd/DragonFlyBSDCRT.c +++ b/dragonflybsd/DragonFlyBSDCRT.c @@ -2,7 +2,7 @@ htop - dragonflybsd/DragonFlyBSDCRT.c (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/DragonFlyBSDCRT.h b/dragonflybsd/DragonFlyBSDCRT.h index bf5384dbe..9a0fdbeb3 100644 --- a/dragonflybsd/DragonFlyBSDCRT.h +++ b/dragonflybsd/DragonFlyBSDCRT.h @@ -4,7 +4,7 @@ htop - dragonflybsd/DragonFlyBSDCRT.h (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 770143b0e..972c77c2b 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -2,7 +2,7 @@ htop - dragonflybsd/DragonFlyBSDProcess.c (C) 2015 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h index d5e5a6ee9..b33f32b27 100644 --- a/dragonflybsd/DragonFlyBSDProcess.h +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -4,7 +4,7 @@ htop - dragonflybsd/DragonFlyBSDProcess.h (C) 2015 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 8901bc451..1c10a4124 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -2,7 +2,7 @@ htop - DragonFlyBSDProcessList.c (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index 9665a60f1..f35e60ebf 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -4,7 +4,7 @@ htop - DragonFlyBSDProcessList.h (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 36ab2c21a..edaa1b236 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -2,7 +2,7 @@ htop - dragonflybsd/Platform.c (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index c0a602336..5dfd28c00 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -4,7 +4,7 @@ htop - dragonflybsd/Platform.h (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/Battery.c b/freebsd/Battery.c index 2dd4609f8..50691c8b4 100644 --- a/freebsd/Battery.c +++ b/freebsd/Battery.c @@ -1,7 +1,7 @@ /* htop - freebsd/Battery.c (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/Battery.h b/freebsd/Battery.h index d9294556f..98adb6eef 100644 --- a/freebsd/Battery.h +++ b/freebsd/Battery.h @@ -3,7 +3,7 @@ /* htop - freebsd/Battery.h (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/FreeBSDCRT.c b/freebsd/FreeBSDCRT.c index b0a0f6078..e1024d30b 100644 --- a/freebsd/FreeBSDCRT.c +++ b/freebsd/FreeBSDCRT.c @@ -1,7 +1,7 @@ /* htop - FreeBSDCRT.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/FreeBSDCRT.h b/freebsd/FreeBSDCRT.h index 3ab802d99..af64cf10b 100644 --- a/freebsd/FreeBSDCRT.h +++ b/freebsd/FreeBSDCRT.h @@ -3,7 +3,7 @@ /* htop - FreeBSDCRT.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 33dc75160..399c5f692 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -1,7 +1,7 @@ /* htop - FreeBSDProcess.c (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index 897c53291..80dcaf659 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -3,7 +3,7 @@ /* htop - FreeBSDProcess.h (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 6e7f6ecb8..cd9897fb8 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -1,7 +1,7 @@ /* htop - FreeBSDProcessList.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 281bf3e2c..064433b35 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -3,7 +3,7 @@ /* htop - FreeBSDProcessList.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 36256f9a1..5f6a12d50 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -1,7 +1,7 @@ /* htop - freebsd/Platform.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 780d23e6a..09783afc3 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -3,7 +3,7 @@ /* htop - freebsd/Platform.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/htop.c b/htop.c index 5054379d4..5eedcab37 100644 --- a/htop.c +++ b/htop.c @@ -1,7 +1,7 @@ /* htop - htop.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ @@ -35,7 +35,7 @@ static void printVersionFlag(void) { static void printHelpFlag(void) { fputs("htop " VERSION "\n" - "Released under the GNU GPL.\n\n" + "Released under the GNU GPLv2.\n\n" "-C --no-color Use a monochrome color scheme\n" "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" "-h --help Print this help screen\n" diff --git a/linux/Battery.c b/linux/Battery.c index 614126e8d..14fcc90b7 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -1,7 +1,7 @@ /* htop - linux/Battery.c (C) 2004-2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). diff --git a/linux/Battery.h b/linux/Battery.h index 3b3d23825..496ce1a62 100644 --- a/linux/Battery.h +++ b/linux/Battery.h @@ -3,7 +3,7 @@ /* htop - linux/Battery.h (C) 2004-2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). diff --git a/linux/IOPriority.h b/linux/IOPriority.h index 7c4f3b63d..e60eb9bae 100644 --- a/linux/IOPriority.h +++ b/linux/IOPriority.h @@ -3,7 +3,7 @@ /* htop - IOPriority.h (C) 2004-2012 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. Based on ionice, diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index ebb77bf78..b3b1a37b4 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -1,7 +1,7 @@ /* htop - IOPriorityPanel.c (C) 2004-2012 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/IOPriorityPanel.h b/linux/IOPriorityPanel.h index 04c1d43e1..d73582261 100644 --- a/linux/IOPriorityPanel.h +++ b/linux/IOPriorityPanel.h @@ -3,7 +3,7 @@ /* htop - IOPriorityPanel.h (C) 2004-2012 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/LinuxCRT.c b/linux/LinuxCRT.c index 7adb154da..7bbb80e09 100644 --- a/linux/LinuxCRT.c +++ b/linux/LinuxCRT.c @@ -1,7 +1,7 @@ /* htop - LinuxCRT.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/LinuxCRT.h b/linux/LinuxCRT.h index 2adb9f3fc..d9263d66b 100644 --- a/linux/LinuxCRT.h +++ b/linux/LinuxCRT.h @@ -3,7 +3,7 @@ /* htop - LinuxCRT.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 2775122c0..8fb26e01f 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -2,7 +2,7 @@ htop - LinuxProcess.c (C) 2014 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 587748624..4b2386e90 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -4,7 +4,7 @@ htop - LinuxProcess.h (C) 2014 Hisham H. Muhammad (C) 2020 Red Hat, Inc. All Rights Reserved. -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index dcef14cf4..c02bca888 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1,7 +1,7 @@ /* htop - LinuxProcessList.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 266540208..913f3cb4f 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -3,7 +3,7 @@ /* htop - LinuxProcessList.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/Platform.c b/linux/Platform.c index 2d3258646..f27c78762 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -1,7 +1,7 @@ /* htop - linux/Platform.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/Platform.h b/linux/Platform.h index 68b18f285..58f5acec5 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -3,7 +3,7 @@ /* htop - linux/Platform.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c index 56055bff3..577692e3e 100644 --- a/linux/PressureStallMeter.c +++ b/linux/PressureStallMeter.c @@ -2,7 +2,7 @@ htop - PressureStallMeter.c (C) 2004-2011 Hisham H. Muhammad (C) 2019 Ran Benita -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/linux/PressureStallMeter.h b/linux/PressureStallMeter.h index 22b8b9724..823659ff0 100644 --- a/linux/PressureStallMeter.h +++ b/linux/PressureStallMeter.h @@ -6,7 +6,7 @@ htop - PressureStallMeter.h (C) 2004-2011 Hisham H. Muhammad (C) 2019 Ran Benita -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/Battery.c b/openbsd/Battery.c index 612330304..232b12558 100644 --- a/openbsd/Battery.c +++ b/openbsd/Battery.c @@ -2,7 +2,7 @@ htop - openbsd/Battery.c (C) 2015 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/Battery.h b/openbsd/Battery.h index bf80f3f68..60b632d25 100644 --- a/openbsd/Battery.h +++ b/openbsd/Battery.h @@ -4,7 +4,7 @@ htop - openbsd/Battery.h (C) 2015 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/OpenBSDCRT.c b/openbsd/OpenBSDCRT.c index 8f026e3e7..88cb8e23d 100644 --- a/openbsd/OpenBSDCRT.c +++ b/openbsd/OpenBSDCRT.c @@ -2,7 +2,7 @@ htop - OpenBSDCRT.c (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/OpenBSDCRT.h b/openbsd/OpenBSDCRT.h index 74535beef..6259b78cc 100644 --- a/openbsd/OpenBSDCRT.h +++ b/openbsd/OpenBSDCRT.h @@ -4,7 +4,7 @@ htop - OpenBSDCRT.h (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 1a8078489..6f52adf0e 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -2,7 +2,7 @@ htop - OpenBSDProcess.c (C) 2015 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/OpenBSDProcess.h b/openbsd/OpenBSDProcess.h index fede6f87c..13f172744 100644 --- a/openbsd/OpenBSDProcess.h +++ b/openbsd/OpenBSDProcess.h @@ -4,7 +4,7 @@ htop - OpenBSDProcess.h (C) 2015 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index c5d79f524..9d1367e77 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -2,7 +2,7 @@ htop - OpenBSDProcessList.c (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index 0d9defbc8..ab4785716 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -4,7 +4,7 @@ htop - OpenBSDProcessList.h (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/Platform.c b/openbsd/Platform.c index ce3709945..f7a713c63 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -2,7 +2,7 @@ htop - openbsd/Platform.c (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/openbsd/Platform.h b/openbsd/Platform.h index e5e09ce0e..dc9b0fa37 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -4,7 +4,7 @@ htop - openbsd/Platform.h (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/solaris/Platform.c b/solaris/Platform.c index 2114215ef..e3bf0cdf0 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -3,7 +3,7 @@ htop - solaris/Platform.c (C) 2014 Hisham H. Muhammad (C) 2015 David C. Hunt (C) 2017,2018 Guy M. Broome -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/solaris/Platform.h b/solaris/Platform.h index d3dddb722..fa8be103a 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -5,7 +5,7 @@ htop - solaris/Platform.h (C) 2014 Hisham H. Muhammad (C) 2015 David C. Hunt (C) 2017,2018 Guy M. Broome -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/solaris/SolarisCRT.c b/solaris/SolarisCRT.c index bea7d3775..ef16aabc4 100644 --- a/solaris/SolarisCRT.c +++ b/solaris/SolarisCRT.c @@ -2,7 +2,7 @@ htop - SolarisCRT.c (C) 2014 Hisham H. Muhammad (C) 2018 Guy M. Broome -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/solaris/SolarisCRT.h b/solaris/SolarisCRT.h index d9ab72089..aa8c81bb2 100644 --- a/solaris/SolarisCRT.h +++ b/solaris/SolarisCRT.h @@ -4,7 +4,7 @@ htop - SolarisCRT.h (C) 2014 Hisham H. Muhammad (C) 2018 Guy M. Broome -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index 645bab80c..89b1690da 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -2,7 +2,7 @@ htop - SolarisProcess.c (C) 2015 Hisham H. Muhammad (C) 2017,2018 Guy M. Broome -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index d36dea3ee..6ae383311 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -4,7 +4,7 @@ htop - SolarisProcess.h (C) 2015 Hisham H. Muhammad (C) 2017,2018 Guy M. Broome -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index d09fc0bb1..dbbd54c26 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -2,7 +2,7 @@ htop - SolarisProcessList.c (C) 2014 Hisham H. Muhammad (C) 2017,2018 Guy M. Broome -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index 9da39b4a0..c8a2d8d08 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -4,7 +4,7 @@ htop - SolarisProcessList.h (C) 2014 Hisham H. Muhammad (C) 2017,2018 Guy M. Broome -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 6a6b01310..5075257e5 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -2,7 +2,7 @@ htop - unsupported/Platform.c (C) 2014 Hisham H. Muhammad (C) 2015 David C. Hunt -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/unsupported/Platform.h b/unsupported/Platform.h index cdce6f38f..8349d97a7 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -4,7 +4,7 @@ htop - unsupported/Platform.h (C) 2014 Hisham H. Muhammad (C) 2015 David C. Hunt -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/unsupported/UnsupportedCRT.c b/unsupported/UnsupportedCRT.c index f5c8fef1d..5ee076cda 100644 --- a/unsupported/UnsupportedCRT.c +++ b/unsupported/UnsupportedCRT.c @@ -1,7 +1,7 @@ /* htop - UnsupportedCRT.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/unsupported/UnsupportedCRT.h b/unsupported/UnsupportedCRT.h index cb248f805..f89d787cb 100644 --- a/unsupported/UnsupportedCRT.h +++ b/unsupported/UnsupportedCRT.h @@ -3,7 +3,7 @@ /* htop - UnsupportedCRT.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/unsupported/UnsupportedProcess.c b/unsupported/UnsupportedProcess.c index 63e26add1..0827c6088 100644 --- a/unsupported/UnsupportedProcess.c +++ b/unsupported/UnsupportedProcess.c @@ -1,7 +1,7 @@ /* htop - UnsupportedProcess.c (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/unsupported/UnsupportedProcess.h b/unsupported/UnsupportedProcess.h index dbe9bf5e4..11335cdb9 100644 --- a/unsupported/UnsupportedProcess.h +++ b/unsupported/UnsupportedProcess.h @@ -3,7 +3,7 @@ /* htop - UnsupportedProcess.h (C) 2015 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index fc8a54dc8..3531d0f92 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -1,7 +1,7 @@ /* htop - UnsupportedProcessList.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/unsupported/UnsupportedProcessList.h b/unsupported/UnsupportedProcessList.h index c4b51acf9..68c0ca7e1 100644 --- a/unsupported/UnsupportedProcessList.h +++ b/unsupported/UnsupportedProcessList.h @@ -3,7 +3,7 @@ /* htop - UnsupportedProcessList.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index 8bd0f5d2d..94bffdc7d 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -1,7 +1,7 @@ /* htop - ZfsArcMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/zfs/ZfsArcMeter.h b/zfs/ZfsArcMeter.h index e6b59d5b3..6b9a6e168 100644 --- a/zfs/ZfsArcMeter.h +++ b/zfs/ZfsArcMeter.h @@ -3,7 +3,7 @@ /* htop - ZfsArcMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/zfs/ZfsArcStats.c b/zfs/ZfsArcStats.c index 6c02c2c11..ae5656337 100644 --- a/zfs/ZfsArcStats.c +++ b/zfs/ZfsArcStats.c @@ -1,7 +1,7 @@ /* htop - ZfsArcStats.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/zfs/ZfsArcStats.h b/zfs/ZfsArcStats.h index 087f3fc08..d891dc2fa 100644 --- a/zfs/ZfsArcStats.h +++ b/zfs/ZfsArcStats.h @@ -3,7 +3,7 @@ /* htop - ZfsArcStats.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index ac3944d34..360877ad5 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -1,7 +1,7 @@ /* htop - ZfsCompressedArcMeter.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/zfs/ZfsCompressedArcMeter.h b/zfs/ZfsCompressedArcMeter.h index 8e6449352..8982eddbc 100644 --- a/zfs/ZfsCompressedArcMeter.h +++ b/zfs/ZfsCompressedArcMeter.h @@ -3,7 +3,7 @@ /* htop - ZfsCompressedArcMeter.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c index c1ab22394..876bf5c89 100644 --- a/zfs/openzfs_sysctl.c +++ b/zfs/openzfs_sysctl.c @@ -1,7 +1,7 @@ /* htop - zfs/openzfs_sysctl.c (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ diff --git a/zfs/openzfs_sysctl.h b/zfs/openzfs_sysctl.h index adb4b24cc..1bc5d3e07 100644 --- a/zfs/openzfs_sysctl.h +++ b/zfs/openzfs_sysctl.h @@ -3,7 +3,7 @@ /* htop - zfs/openzfs_sysctl.h (C) 2014 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ From ff455b0004080a260a63f12ca8bf7c148eab6ee7 Mon Sep 17 00:00:00 2001 From: ryenus Date: Sat, 3 Oct 2020 00:12:31 +0800 Subject: [PATCH 259/411] limit max screen title length to window width Applies screen title truncating to all InfoScreen classes. --- CommandScreen.c | 9 +-------- InfoScreen.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CommandScreen.c b/CommandScreen.c index d8e709c49..bc71e09fe 100644 --- a/CommandScreen.c +++ b/CommandScreen.c @@ -45,14 +45,7 @@ static void CommandScreen_scan(InfoScreen* this) { } static void CommandScreen_draw(InfoScreen* this) { - char* title = xMalloc(COLS + 1); - int len = snprintf(title, COLS + 1, "Command of process %d - %s", this->process->pid, this->process->comm); - if (len > COLS) { - memset(&title[COLS - 3], '.', 3); - } - - InfoScreen_drawTitled(this, "%s", title); - free(title); + InfoScreen_drawTitled(this, "Command of process %d - %s", this->process->pid, this->process->comm); } InfoScreenClass CommandScreen_class = { diff --git a/InfoScreen.c b/InfoScreen.c index 35c16473b..52117d0bf 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -42,14 +42,21 @@ InfoScreen* InfoScreen_done(InfoScreen* this) { void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) { va_list ap; va_start(ap, fmt); + + char* title = xMalloc(COLS + 1); + int len = vsnprintf(title, COLS + 1, fmt, ap); + if (len > COLS) { + memset(&title[COLS - 3], '.', 3); + } + attrset(CRT_colors[METER_TEXT]); mvhline(0, 0, ' ', COLS); - (void) wmove(stdscr, 0, 0); - vw_printw(stdscr, fmt, ap); + mvwprintw(stdscr, 0, 0, title); attrset(CRT_colors[DEFAULT_COLOR]); this->display->needsRedraw = true; Panel_draw(this->display, true); IncSet_drawBar(this->inc); + free(title); va_end(ap); } From 77587748905e2456adfacadeab4b3e4f08ffbc50 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 5 Oct 2020 10:16:13 +0200 Subject: [PATCH 260/411] Add Copyright statement to --help (needed as it has the license info) --- htop.c | 1 + 1 file changed, 1 insertion(+) diff --git a/htop.c b/htop.c index 5eedcab37..ec4e62425 100644 --- a/htop.c +++ b/htop.c @@ -35,6 +35,7 @@ static void printVersionFlag(void) { static void printHelpFlag(void) { fputs("htop " VERSION "\n" + COPYRIGHT "\n" "Released under the GNU GPLv2.\n\n" "-C --no-color Use a monochrome color scheme\n" "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" From 49bb1b57f82a7ef2de5ed9a7d39caafb6c8328c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 12:27:20 +0200 Subject: [PATCH 261/411] Assert that low value is lower than the high value in CLAMP --- Macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Macros.h b/Macros.h index de674edaa..33e727d8d 100644 --- a/Macros.h +++ b/Macros.h @@ -10,7 +10,7 @@ #endif #ifndef CLAMP -#define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low)) +#define CLAMP(x, low, high) (assert(low < high), ((x) > (high)) ? (high) : MAXIMUM(x, low)) #endif #ifndef ARRAYSIZE From cdd39136476a9a09341caaa8cf987ee61ccdcb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 12:27:27 +0200 Subject: [PATCH 262/411] Merge identical declarations --- RichString.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/RichString.h b/RichString.h index 6b626d40b..6b66ed87a 100644 --- a/RichString.h +++ b/RichString.h @@ -57,20 +57,10 @@ typedef struct RichString_ { CharType chstr[RICHSTRING_MAXLEN+1]; } RichString; -#ifdef HAVE_LIBNCURSESW - -void RichString_setAttrn(RichString* this, int attrs, int start, int finish); - -int RichString_findChar(RichString* this, char c, int start); - -#else /* HAVE_LIBNCURSESW */ - void RichString_setAttrn(RichString* this, int attrs, int start, int finish); int RichString_findChar(RichString* this, char c, int start); -#endif /* HAVE_LIBNCURSESW */ - void RichString_prune(RichString* this); void RichString_setAttr(RichString* this, int attrs); From 577984d875982ae5cd1d667e2c0131776e559c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 12:27:32 +0200 Subject: [PATCH 263/411] Mark argument in Object_isA const --- Object.c | 2 +- Object.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Object.c b/Object.c index 9ac2be670..982f7bda9 100644 --- a/Object.c +++ b/Object.c @@ -14,7 +14,7 @@ ObjectClass Object_class = { #ifndef NDEBUG -bool Object_isA(Object* o, const ObjectClass* klass) { +bool Object_isA(const Object* o, const ObjectClass* klass) { if (!o) return false; const ObjectClass* type = o->klass; diff --git a/Object.h b/Object.h index 462797c29..ba213c89d 100644 --- a/Object.h +++ b/Object.h @@ -50,7 +50,7 @@ extern ObjectClass Object_class; #ifndef NDEBUG -bool Object_isA(Object* o, const ObjectClass* klass); +bool Object_isA(const Object* o, const ObjectClass* klass); #endif /* NDEBUG */ From ffd90c28ab55a2cdbbd5c3b8130e0462a24af8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 12:29:31 +0200 Subject: [PATCH 264/411] Mention platform for platform specific configure options --- configure.ac | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index fb6400fdd..371e03d55 100644 --- a/configure.ac +++ b/configure.ac @@ -361,16 +361,16 @@ fi AC_MSG_RESULT([ ${PACKAGE_NAME} ${VERSION} - platform: $my_htop_platform - proc directory: $PROCDIR - openvz: $enable_openvz - cgroup: $enable_cgroup - vserver: $enable_vserver - ancient vserver: $enable_ancient_vserver - taskstats: $enable_taskstats - unicode: $enable_unicode - linux affinity: $enable_linux_affinity - hwlock: $enable_hwloc - setuid: $enable_setuid - linux delay accounting: $enable_delayacct + platform: $my_htop_platform + (Linux) proc directory: $PROCDIR + (Linux) openvz: $enable_openvz + (Linux) cgroup: $enable_cgroup + (Linux) vserver: $enable_vserver + (Linux) ancient vserver: $enable_ancient_vserver + (Linux) taskstats: $enable_taskstats + (Linux) affinity: $enable_linux_affinity + (Linux) delay accounting: $enable_delayacct + unicode: $enable_unicode + hwlock: $enable_hwloc + setuid: $enable_setuid ]) From d93cac12be1a7a580e338c6fa80286bfa703ffc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Mon, 5 Oct 2020 13:52:58 +0200 Subject: [PATCH 265/411] Add a date and datetime meter (#159) Add a date meter and sort header and source files in Makefile Change the lists of header and source files sorted alphabetical and one file per line. This way diffs become better readable and merges easier. --- CRT.c | 10 ++++ CRT.h | 2 + DateMeter.c | 47 ++++++++++++++++ DateMeter.h | 16 ++++++ DateTimeMeter.c | 47 ++++++++++++++++ DateTimeMeter.h | 16 ++++++ Makefile.am | 120 +++++++++++++++++++++++++++++++++------- darwin/Platform.c | 4 ++ dragonflybsd/Platform.c | 4 ++ freebsd/Platform.c | 4 ++ linux/Platform.c | 4 ++ openbsd/Platform.c | 4 ++ solaris/Platform.c | 4 ++ unsupported/Platform.c | 4 ++ 14 files changed, 267 insertions(+), 19 deletions(-) create mode 100644 DateMeter.c create mode 100644 DateMeter.h create mode 100644 DateTimeMeter.c create mode 100644 DateTimeMeter.h diff --git a/CRT.c b/CRT.c index 374e1721e..d38740437 100644 --- a/CRT.c +++ b/CRT.c @@ -122,6 +122,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Black), [CLOCK] = A_BOLD, + [DATE] = A_BOLD, + [DATETIME] = A_BOLD, [CHECK_BOX] = ColorPair(Cyan,Black), [CHECK_MARK] = A_BOLD, [CHECK_TEXT] = A_NORMAL, @@ -195,6 +197,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD, [CLOCK] = A_BOLD, + [DATE] = A_BOLD, + [DATETIME] = A_BOLD, [CHECK_BOX] = A_BOLD, [CHECK_MARK] = A_NORMAL, [CHECK_TEXT] = A_NORMAL, @@ -268,6 +272,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = ColorPair(Black,White), [HELP_BOLD] = ColorPair(Blue,White), [CLOCK] = ColorPair(Black,White), + [DATE] = ColorPair(Black,White), + [DATETIME] = ColorPair(Black,White), [CHECK_BOX] = ColorPair(Blue,White), [CHECK_MARK] = ColorPair(Black,White), [CHECK_TEXT] = ColorPair(Black,White), @@ -341,6 +347,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = ColorPair(Yellow,Black), [HELP_BOLD] = ColorPair(Blue,Black), [CLOCK] = ColorPair(Yellow,Black), + [DATE] = ColorPair(White,Black), + [DATETIME] = ColorPair(White,Black), [CHECK_BOX] = ColorPair(Blue,Black), [CHECK_MARK] = ColorPair(Blue,Black), [CHECK_TEXT] = ColorPair(Blue,Black), @@ -414,6 +422,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD | ColorPair(White,Blue), [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Blue), [CLOCK] = ColorPair(White,Blue), + [DATE] = ColorPair(White,Blue), + [DATETIME] = ColorPair(White,Blue), [CHECK_BOX] = ColorPair(Cyan,Blue), [CHECK_MARK] = A_BOLD | ColorPair(White,Blue), [CHECK_TEXT] = A_NORMAL | ColorPair(White,Blue), diff --git a/CRT.h b/CRT.h index 4eeb9a461..13fe66d77 100644 --- a/CRT.h +++ b/CRT.h @@ -85,6 +85,8 @@ typedef enum ColorElements_ { CHECK_MARK, CHECK_TEXT, CLOCK, + DATE, + DATETIME, HELP_BOLD, HOSTNAME, CPU_NICE, diff --git a/DateMeter.c b/DateMeter.c new file mode 100644 index 000000000..6fd933731 --- /dev/null +++ b/DateMeter.c @@ -0,0 +1,47 @@ +/* +htop - DateMeter.c +(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "DateMeter.h" + +#include "CRT.h" + +#include + + +int DateMeter_attributes[] = { + DATE +}; + +static void DateMeter_updateValues(Meter* this, char* buffer, int size) { + time_t t = time(NULL); + struct tm result; + struct tm *lt = localtime_r(&t, &result); + this->values[0] = lt->tm_yday; + int year = lt->tm_year + 1900; + if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) { + this->total = 366; + } + else { + this->total = 365; + } + strftime(buffer, size, "%F", lt); +} + +MeterClass DateMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete + }, + .updateValues = DateMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 1, + .total = 365, + .attributes = DateMeter_attributes, + .name = "Date", + .uiName = "Date", + .caption = "Date: ", +}; diff --git a/DateMeter.h b/DateMeter.h new file mode 100644 index 000000000..6cb899dd5 --- /dev/null +++ b/DateMeter.h @@ -0,0 +1,16 @@ +#ifndef HEADER_DateMeter +#define HEADER_DateMeter +/* +htop - DateMeter.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern int DateMeter_attributes[]; + +extern MeterClass DateMeter_class; + +#endif diff --git a/DateTimeMeter.c b/DateTimeMeter.c new file mode 100644 index 000000000..5c60884ae --- /dev/null +++ b/DateTimeMeter.c @@ -0,0 +1,47 @@ +/* +htop - DateTimeMeter.c +(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "DateTimeMeter.h" + +#include "CRT.h" + +#include + + +int DateTimeMeter_attributes[] = { + DATETIME +}; + +static void DateTimeMeter_updateValues(Meter* this, char* buffer, int size) { + time_t t = time(NULL); + struct tm result; + struct tm *lt = localtime_r(&t, &result); + int year = lt->tm_year + 1900; + if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) { + this->total = 366; + } + else { + this->total = 365; + } + this->values[0] = lt->tm_yday; + strftime(buffer, size, "%F %H:%M:%S", lt); +} + +MeterClass DateTimeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete + }, + .updateValues = DateTimeMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 1, + .total = 365, + .attributes = DateTimeMeter_attributes, + .name = "DateTime", + .uiName = "Date and Time", + .caption = "Date & Time: ", +}; diff --git a/DateTimeMeter.h b/DateTimeMeter.h new file mode 100644 index 000000000..6d1e3a68a --- /dev/null +++ b/DateTimeMeter.h @@ -0,0 +1,16 @@ +#ifndef HEADER_DateTimeMeter +#define HEADER_DateTimeMeter +/* +htop - DateTimeMeter.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern int DateTimeMeter_attributes[]; + +extern MeterClass DateTimeMeter_class; + +#endif diff --git a/Makefile.am b/Makefile.am index 1ef92364a..9bfe007a6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,25 +13,107 @@ pixmap_DATA = htop.png AM_CFLAGS += -pedantic -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)" AM_LDFLAGS = -myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ -ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DiskIOMeter.c DiskIOMeter.h \ -MainPanel.c DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ -LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ -BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ -SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.c \ -TraceScreen.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ -HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c EnvScreen.c \ -InfoScreen.c CommandScreen.c XAlloc.c - -myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ -CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ -CPUMeter.h CRT.h MainPanel.h DisplayOptionsPanel.h FunctionBar.h \ -Hashtable.h Header.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ -BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ -ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.h \ -TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ -AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \ -EnvScreen.h InfoScreen.h CommandScreen.h XAlloc.h Macros.h +myhtopsources = \ + Action.c \ + Affinity.c \ + AffinityPanel.c \ + AvailableColumnsPanel.c \ + AvailableMetersPanel.c \ + BatteryMeter.c \ + CategoriesPanel.c \ + CheckItem.c \ + ClockMeter.c \ + ColorsPanel.c \ + ColumnsPanel.c \ + CommandScreen.c \ + CPUMeter.c \ + CRT.c \ + DateMeter.c \ + DateTimeMeter.c \ + DiskIOMeter.c \ + DiskIOMeter.h \ + DisplayOptionsPanel.c \ + EnvScreen.c \ + FunctionBar.c \ + Hashtable.c \ + Header.c \ + HostnameMeter.c \ + htop.c \ + IncSet.c \ + InfoScreen.c \ + ListItem.c \ + LoadAverageMeter.c \ + MainPanel.c \ + MemoryMeter.c \ + Meter.c \ + MetersPanel.c \ + Object.c \ + OpenFilesScreen.c \ + Panel.c \ + Process.c \ + ProcessList.c \ + RichString.c \ + ScreenManager.c \ + Settings.c \ + SignalsPanel.c \ + StringUtils.c \ + SwapMeter.c \ + TasksMeter.c \ + TraceScreen.c \ + UptimeMeter.c \ + UsersTable.c \ + Vector.c \ + XAlloc.c + +myhtopheaders = \ + Action.h \ + Affinity.h \ + AffinityPanel.h \ + AvailableColumnsPanel.h \ + AvailableMetersPanel.h \ + BatteryMeter.h \ + CPUMeter.h \ + CRT.h \ + CategoriesPanel.h \ + CheckItem.h \ + ClockMeter.h \ + ColorsPanel.h \ + ColumnsPanel.h \ + CommandScreen.h \ + DateMeter.h \ + DateTimeMeter.h \ + DisplayOptionsPanel.h \ + EnvScreen.h \ + FunctionBar.h \ + Hashtable.h \ + Header.h \ + HostnameMeter.h \ + IncSet.h \ + InfoScreen.h \ + ListItem.h \ + LoadAverageMeter.h \ + Macros.h \ + MainPanel.h \ + MemoryMeter.h \ + Meter.h \ + MetersPanel.h \ + Object.h \ + OpenFilesScreen.h \ + Panel.h \ + Process.h \ + ProcessList.h \ + RichString.h \ + ScreenManager.h \ + Settings.h \ + SignalsPanel.h \ + StringUtils.h \ + SwapMeter.h \ + TasksMeter.h \ + TraceScreen.h \ + UptimeMeter.h \ + UsersTable.h \ + Vector.h \ + XAlloc.h # Linux # ----- diff --git a/darwin/Platform.c b/darwin/Platform.c index 5aa50a65f..8ca8d2c69 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -13,6 +13,8 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "LoadAverageMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "UptimeMeter.h" #include "zfs/ZfsArcMeter.h" @@ -95,6 +97,8 @@ ProcessFieldData Process_fields[] = { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 36ab2c21a..61fe25b68 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -15,6 +15,8 @@ in the source distribution for its full text. #include "LoadAverageMeter.h" #include "UptimeMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "DragonFlyBSDProcess.h" #include "DragonFlyBSDProcessList.h" @@ -78,6 +80,8 @@ void Platform_setBindings(Htop_Action* keys) { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 36256f9a1..2c1d72e6d 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -14,6 +14,8 @@ in the source distribution for its full text. #include "LoadAverageMeter.h" #include "UptimeMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" @@ -79,6 +81,8 @@ void Platform_setBindings(Htop_Action* keys) { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/linux/Platform.c b/linux/Platform.c index 2d3258646..ef5015d1d 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -22,6 +22,8 @@ in the source distribution for its full text. #include "UptimeMeter.h" #include "PressureStallMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" @@ -106,6 +108,8 @@ void Platform_setBindings(Htop_Action* keys) { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/openbsd/Platform.c b/openbsd/Platform.c index ce3709945..574b573ca 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -15,6 +15,8 @@ in the source distribution for its full text. #include "LoadAverageMeter.h" #include "UptimeMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "SignalsPanel.h" #include "OpenBSDProcess.h" @@ -91,6 +93,8 @@ void Platform_setBindings(Htop_Action* keys) { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/solaris/Platform.c b/solaris/Platform.c index 2114215ef..07f57517d 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -15,6 +15,8 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "LoadAverageMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "UptimeMeter.h" #include "zfs/ZfsArcMeter.h" @@ -88,6 +90,8 @@ ProcessField Platform_defaultFields[] = { PID, LWPID, USER, PRIORITY, NICE, M_SI MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 6a6b01310..fbcf6431f 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -15,6 +15,8 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "LoadAverageMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "UptimeMeter.h" @@ -59,6 +61,8 @@ ProcessFieldData Process_fields[] = { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, From dc6523bf60df8a1f7428b8cc3638eaddb46a3980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 13:54:33 +0200 Subject: [PATCH 266/411] DateMeter followup --- DateMeter.c | 2 +- DateMeter.h | 2 -- DateTimeMeter.c | 2 +- DateTimeMeter.h | 2 -- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/DateMeter.c b/DateMeter.c index 6fd933731..e130159ad 100644 --- a/DateMeter.c +++ b/DateMeter.c @@ -12,7 +12,7 @@ in the source distribution for its full text. #include -int DateMeter_attributes[] = { +static const int DateMeter_attributes[] = { DATE }; diff --git a/DateMeter.h b/DateMeter.h index 6cb899dd5..44ed24da3 100644 --- a/DateMeter.h +++ b/DateMeter.h @@ -9,8 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern int DateMeter_attributes[]; - extern MeterClass DateMeter_class; #endif diff --git a/DateTimeMeter.c b/DateTimeMeter.c index 5c60884ae..32dd5d1a4 100644 --- a/DateTimeMeter.c +++ b/DateTimeMeter.c @@ -12,7 +12,7 @@ in the source distribution for its full text. #include -int DateTimeMeter_attributes[] = { +static const int DateTimeMeter_attributes[] = { DATETIME }; diff --git a/DateTimeMeter.h b/DateTimeMeter.h index 6d1e3a68a..ef25264ce 100644 --- a/DateTimeMeter.h +++ b/DateTimeMeter.h @@ -9,8 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern int DateTimeMeter_attributes[]; - extern MeterClass DateTimeMeter_class; #endif From ad3acfc847e9d54f07a0684c19181d5f4c28fee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 18:27:55 +0200 Subject: [PATCH 267/411] Handle Panel_getSelected() returning NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by compiling with LTO: ColumnsPanel.c: In function ‘ColumnsPanel_eventHandler’: ColumnsPanel.c:46:59: error: potential null pointer dereference [-Werror=null-dereference] 46 | ((ListItem*)Panel_getSelected(super))->moving = this->moving; | ^ AvailableColumnsPanel.c: In function ‘AvailableColumnsPanel_eventHandler’: AvailableColumnsPanel.c:31:8: error: potential null pointer dereference [-Werror=null-dereference] 31 | int key = ((ListItem*) Panel_getSelected(super))->key; | ^ AvailableMetersPanel.c: In function ‘AvailableMetersPanel_eventHandler’: AvailableMetersPanel.c:40:24: error: potential null pointer dereference [-Werror=null-dereference] 40 | int param = selected->key & 0xff; | ^ linux/IOPriorityPanel.c: In function ‘IOPriorityPanel_getIOPriority’: linux/IOPriorityPanel.c:37:11: error: potential null pointer dereference [-Werror=null-dereference] 37 | return (IOPriority) ( ((ListItem*) Panel_getSelected(this))->key ); | ^ --- AvailableColumnsPanel.c | 6 +++++- AvailableMetersPanel.c | 5 ++++- ColumnsPanel.c | 4 +++- linux/IOPriorityPanel.c | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index e605ae520..fd247af01 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -28,7 +28,6 @@ static void AvailableColumnsPanel_delete(Object* object) { static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) { AvailableColumnsPanel* this = (AvailableColumnsPanel*) super; - int key = ((ListItem*) Panel_getSelected(super))->key; HandlerResult result = IGNORED; switch(ch) { @@ -36,6 +35,11 @@ static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) { case KEY_ENTER: case KEY_F(5): { + const ListItem* selected = (ListItem*) Panel_getSelected(super); + if (!selected) + break; + + int key = selected->key; int at = Panel_getSelectedIndex(this->columns); Panel_insert(this->columns, at, (Object*) ListItem_new(Process_fields[key].name, key)); Panel_setSelected(this->columns, at+1); diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index 604a6891c..f5e59218b 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -36,7 +36,10 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { AvailableMetersPanel* this = (AvailableMetersPanel*) super; Header* header = this->header; - ListItem* selected = (ListItem*) Panel_getSelected(super); + const ListItem* selected = (ListItem*) Panel_getSelected(super); + if (!selected) + return IGNORED; + int param = selected->key & 0xff; int type = selected->key >> 16; HandlerResult result = IGNORED; diff --git a/ColumnsPanel.c b/ColumnsPanel.c index d7132e188..8328d15e8 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -43,7 +43,9 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { if (selected < size - 1) { this->moving = !(this->moving); Panel_setSelectionColor(super, this->moving ? CRT_colors[PANEL_SELECTION_FOLLOW] : CRT_colors[PANEL_SELECTION_FOCUS]); - ((ListItem*)Panel_getSelected(super))->moving = this->moving; + ListItem* selectedItem = (ListItem*) Panel_getSelected(super); + if (selectedItem) + selectedItem->moving = this->moving; result = HANDLED; } break; diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index b3b1a37b4..a12b8065b 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -34,5 +34,6 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { } IOPriority IOPriorityPanel_getIOPriority(Panel* this) { - return (IOPriority) ( ((ListItem*) Panel_getSelected(this))->key ); + const ListItem* selected = (ListItem*) Panel_getSelected(this); + return selected ? selected->key : IOPriority_None; } From db472075a4fb82bf6a491848941a5b9c92526c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 4 Oct 2020 14:30:35 +0200 Subject: [PATCH 268/411] Enable -Wcast-qual compiler warning --- FunctionBar.c | 16 ++++++++-------- FunctionBar.h | 5 ++++- Macros.h | 16 ++++++++++++++++ configure.ac | 1 + dragonflybsd/DragonFlyBSDProcess.c | 12 ++++++------ freebsd/FreeBSDProcess.c | 12 ++++++------ freebsd/FreeBSDProcessList.c | 3 +++ openbsd/OpenBSDProcess.c | 12 ++++++------ solaris/SolarisProcess.c | 12 ++++++------ 9 files changed, 56 insertions(+), 33 deletions(-) diff --git a/FunctionBar.c b/FunctionBar.c index 55279c213..df1fab8f4 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -40,18 +40,18 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke } if (keys && events) { this->staticData = false; - this->keys = xCalloc(15, sizeof(char*)); + this->keys.keys = xCalloc(15, sizeof(char*)); this->events = xCalloc(15, sizeof(int)); int i = 0; while (i < 15 && functions[i]) { - this->keys[i] = xStrdup(keys[i]); + this->keys.keys[i] = xStrdup(keys[i]); this->events[i] = events[i]; i++; } this->size = i; } else { this->staticData = true; - this->keys = (char**) FunctionBar_FKeys; + this->keys.constKeys = FunctionBar_FKeys; this->events = FunctionBar_FEvents; this->size = 10; } @@ -65,9 +65,9 @@ void FunctionBar_delete(FunctionBar* this) { free(this->functions); if (!this->staticData) { for (int i = 0; i < this->size; i++) { - free(this->keys[i]); + free(this->keys.keys[i]); } - free(this->keys); + free(this->keys.keys); free(this->events); } free(this); @@ -93,8 +93,8 @@ void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) { int x = 0; for (int i = 0; i < this->size; i++) { attrset(CRT_colors[FUNCTION_KEY]); - mvaddstr(LINES-1, x, this->keys[i]); - x += strlen(this->keys[i]); + mvaddstr(LINES-1, x, this->keys.constKeys[i]); + x += strlen(this->keys.constKeys[i]); attrset(CRT_colors[FUNCTION_BAR]); mvaddstr(LINES-1, x, this->functions[i]); x += strlen(this->functions[i]); @@ -113,7 +113,7 @@ void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) { int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) { int x = 0; for (int i = 0; i < this->size; i++) { - x += strlen(this->keys[i]); + x += strlen(this->keys.constKeys[i]); x += strlen(this->functions[i]); if (pos < x) { return this->events[i]; diff --git a/FunctionBar.h b/FunctionBar.h index 8fa744041..c650c1a40 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -12,7 +12,10 @@ in the source distribution for its full text. typedef struct FunctionBar_ { int size; char** functions; - char** keys; + union { + char** keys; + const char* const* constKeys; + } keys; int* events; bool staticData; } FunctionBar; diff --git a/Macros.h b/Macros.h index 33e727d8d..bb3a90e06 100644 --- a/Macros.h +++ b/Macros.h @@ -33,4 +33,20 @@ #endif /* __GNUC__ */ +// ignore casts discarding const specifier, e.g. +// const char [] -> char * / void * +// const char *[2]' -> char *const * +#ifdef __clang__ +#define IGNORE_WCASTQUAL_BEGIN _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wcast-qual\"") +#define IGNORE_WCASTQUAL_END _Pragma("clang diagnostic pop") +#elif defined(__GNUC__) +#define IGNORE_WCASTQUAL_BEGIN _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") +#define IGNORE_WCASTQUAL_END _Pragma("GCC diagnostic pop") +#else +#define IGNORE_WCASTQUAL_BEGIN +#define IGNORE_WCASTQUAL_END +#endif + #endif diff --git a/configure.ac b/configure.ac index ce4e96b48..7982d6480 100644 --- a/configure.ac +++ b/configure.ac @@ -296,6 +296,7 @@ fi AM_CFLAGS="\ -Wall\ -Wcast-align\ + -Wcast-qual\ -Wextra\ -Wfloat-equal\ -Wmissing-format-attribute\ diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 972c77c2b..df320e082 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -108,14 +108,14 @@ void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField } long DragonFlyBSDProcess_compare(const void* v1, const void* v2) { - DragonFlyBSDProcess *p1, *p2; - Settings *settings = ((Process*)v1)->settings; + const DragonFlyBSDProcess *p1, *p2; + const Settings *settings = ((const Process*)v1)->settings; if (settings->direction == 1) { - p1 = (DragonFlyBSDProcess*)v1; - p2 = (DragonFlyBSDProcess*)v2; + p1 = (const DragonFlyBSDProcess*)v1; + p2 = (const DragonFlyBSDProcess*)v2; } else { - p2 = (DragonFlyBSDProcess*)v1; - p1 = (DragonFlyBSDProcess*)v2; + p2 = (const DragonFlyBSDProcess*)v1; + p1 = (const DragonFlyBSDProcess*)v2; } switch ((int) settings->sortKey) { // add Platform-specific fields here diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 399c5f692..767f485b4 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -107,14 +107,14 @@ void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel } long FreeBSDProcess_compare(const void* v1, const void* v2) { - FreeBSDProcess *p1, *p2; - Settings *settings = ((Process*)v1)->settings; + const FreeBSDProcess *p1, *p2; + const Settings *settings = ((const Process*)v1)->settings; if (settings->direction == 1) { - p1 = (FreeBSDProcess*)v1; - p2 = (FreeBSDProcess*)v2; + p1 = (const FreeBSDProcess*)v1; + p2 = (const FreeBSDProcess*)v2; } else { - p2 = (FreeBSDProcess*)v1; - p1 = (FreeBSDProcess*)v2; + p2 = (const FreeBSDProcess*)v1; + p1 = (const FreeBSDProcess*)v2; } switch ((int) settings->sortKey) { // add FreeBSD-specific fields here diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index cd9897fb8..f9377a2d8 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -5,6 +5,7 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "Macros.h" #include "ProcessList.h" #include "FreeBSDProcessList.h" #include "FreeBSDProcess.h" @@ -338,6 +339,7 @@ char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) { if (kproc->ki_jid != 0 ){ memset(jnamebuf, 0, sizeof(jnamebuf)); +IGNORE_WCASTQUAL_BEGIN *(const void **)&jiov[0].iov_base = "jid"; jiov[0].iov_len = sizeof("jid"); jiov[1].iov_base = &kproc->ki_jid; @@ -350,6 +352,7 @@ char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) { jiov[4].iov_len = sizeof("errmsg"); jiov[5].iov_base = jail_errmsg; jiov[5].iov_len = JAIL_ERRMSGLEN; +IGNORE_WCASTQUAL_END jail_errmsg[0] = 0; jid = jail_get(jiov, 6, 0); if (jid < 0) { diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 6f52adf0e..94ce48283 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -193,14 +193,14 @@ void OpenBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel } long OpenBSDProcess_compare(const void* v1, const void* v2) { - OpenBSDProcess *p1, *p2; - Settings *settings = ((Process*)v1)->settings; + const OpenBSDProcess *p1, *p2; + const Settings *settings = ((const Process*)v1)->settings; if (settings->direction == 1) { - p1 = (OpenBSDProcess*)v1; - p2 = (OpenBSDProcess*)v2; + p1 = (const OpenBSDProcess*)v1; + p2 = (const OpenBSDProcess*)v2; } else { - p2 = (OpenBSDProcess*)v1; - p1 = (OpenBSDProcess*)v2; + p2 = (const OpenBSDProcess*)v1; + p1 = (const OpenBSDProcess*)v2; } switch (settings->sortKey) { // add OpenBSD-specific fields here diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index 89b1690da..d0a75dfec 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -117,14 +117,14 @@ void SolarisProcess_writeField(Process* this, RichString* str, ProcessField fiel } long SolarisProcess_compare(const void* v1, const void* v2) { - SolarisProcess *p1, *p2; - Settings* settings = ((Process*)v1)->settings; + const SolarisProcess *p1, *p2; + const Settings* settings = ((const Process*)v1)->settings; if (settings->direction == 1) { - p1 = (SolarisProcess*)v1; - p2 = (SolarisProcess*)v2; + p1 = (const SolarisProcess*)v1; + p2 = (const SolarisProcess*)v2; } else { - p2 = (SolarisProcess*)v1; - p1 = (SolarisProcess*)v2; + p2 = (const SolarisProcess*)v1; + p1 = (const SolarisProcess*)v2; } switch ((int) settings->sortKey) { case ZONEID: From db159e758020a1a224eb6097ba697c70dacc1818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 6 Oct 2020 11:39:27 +0200 Subject: [PATCH 269/411] Enclose CLAMP macro arguments in parentheses --- Macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Macros.h b/Macros.h index bb3a90e06..00413f4ec 100644 --- a/Macros.h +++ b/Macros.h @@ -10,7 +10,7 @@ #endif #ifndef CLAMP -#define CLAMP(x, low, high) (assert(low < high), ((x) > (high)) ? (high) : MAXIMUM(x, low)) +#define CLAMP(x, low, high) (assert((low) < (high)), ((x) > (high)) ? (high) : MAXIMUM(x, low)) #endif #ifndef ARRAYSIZE From 3653ee35c572ccca09f8f080b78a1ad7d26cbb24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 6 Oct 2020 11:40:24 +0200 Subject: [PATCH 270/411] Drop redundant cast to same type --- LoadAverageMeter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index b54907857..d14d97ab2 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -49,7 +49,7 @@ static void LoadMeter_updateValues(Meter* this, char* buffer, int size) { static void LoadMeter_display(Object* cast, RichString* out) { Meter* this = (Meter*)cast; char buffer[20]; - xSnprintf(buffer, sizeof(buffer), "%.2f ", ((Meter*)this)->values[0]); + xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]); RichString_write(out, CRT_colors[LOAD], buffer); } From 954d6c12f58724773596b1bd669683ce59cae2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 28 Sep 2020 12:01:56 +0200 Subject: [PATCH 271/411] Simplify statm parsing and document unused fields --- linux/LinuxProcess.c | 4 ++-- linux/LinuxProcessList.c | 31 +++++++++++++------------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 8fb26e01f..373c9ad80 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -67,8 +67,8 @@ ProcessFieldData Process_fields[] = { [M_SHARE] = { .name = "M_SHARE", .title = " SHR ", .description = "Size of the process's shared pages", .flags = 0, }, [M_TRS] = { .name = "M_TRS", .title = " CODE ", .description = "Size of the text segment of the process", .flags = 0, }, [M_DRS] = { .name = "M_DRS", .title = " DATA ", .description = "Size of the data segment plus stack usage of the process", .flags = 0, }, - [M_LRS] = { .name = "M_LRS", .title = " LIB ", .description = "The library size of the process", .flags = 0, }, - [M_DT] = { .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process", .flags = 0, }, + [M_LRS] = { .name = "M_LRS", .title = " LIB ", .description = "The library size of the process (unused since Linux 2.6; always 0)", .flags = 0, }, + [M_DT] = { .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process (unused since Linux 2.6; always 0)", .flags = 0, }, [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index c02bca888..2317e1c86 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -406,25 +406,20 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* dirname, const char* name) { char filename[MAX_NAME+1]; - xSnprintf(filename, MAX_NAME, "%s/%s/statm", dirname, name); - int fd = open(filename, O_RDONLY); - if (fd == -1) + xSnprintf(filename, sizeof(filename), "%s/%s/statm", dirname, name); + FILE* statmfile = fopen(filename, "r"); + if (!statmfile) return false; - char buf[PROC_LINE_LENGTH + 1]; - ssize_t rres = xread(fd, buf, PROC_LINE_LENGTH); - close(fd); - if (rres < 1) return false; - - char *p = buf; - errno = 0; - process->super.m_size = strtol(p, &p, 10); if (*p == ' ') p++; - process->super.m_resident = strtol(p, &p, 10); if (*p == ' ') p++; - process->m_share = strtol(p, &p, 10); if (*p == ' ') p++; - process->m_trs = strtol(p, &p, 10); if (*p == ' ') p++; - process->m_lrs = strtol(p, &p, 10); if (*p == ' ') p++; - process->m_drs = strtol(p, &p, 10); if (*p == ' ') p++; - process->m_dt = strtol(p, &p, 10); - return (errno == 0); + int r = fscanf(statmfile, "%ld %ld %ld %ld %ld %ld %ld", + &process->super.m_size, + &process->super.m_resident, + &process->m_share, + &process->m_trs, + &process->m_lrs, + &process->m_drs, + &process->m_dt); + fclose(statmfile); + return r == 7; } static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* dirname, const char* name, bool haveSmapsRollup) { From fbf6424e645614121b9506352b9553aacef51420 Mon Sep 17 00:00:00 2001 From: laydervus <20249311+layderv@users.noreply.github.com> Date: Tue, 6 Oct 2020 16:22:58 -0400 Subject: [PATCH 272/411] Option to set initial filter Closes #219 --- htop.1.in | 5 ++++- htop.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/htop.1.in b/htop.1.in index 215d92c5d..48e5cee55 100644 --- a/htop.1.in +++ b/htop.1.in @@ -4,7 +4,7 @@ htop \- interactive process viewer .SH "SYNOPSIS" .LP .B htop -.RB [ \-dChpustv ] +.RB [ \-dCFhpustv ] .SH "DESCRIPTION" .LP .B htop @@ -36,6 +36,9 @@ Start .B htop in monochrome mode .TP +\fB\-F \-\-filter=FILTER +Filter processes by command +.TP \fB\-h \-\-help Display a help message and exit .TP diff --git a/htop.c b/htop.c index ec4e62425..8d17de9b2 100644 --- a/htop.c +++ b/htop.c @@ -39,6 +39,7 @@ static void printHelpFlag(void) { "Released under the GNU GPLv2.\n\n" "-C --no-color Use a monochrome color scheme\n" "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" + "-F --filter=FILTER Show only the commands matching the given filter\n" "-h --help Print this help screen\n" "-M --no-mouse Disable the mouse\n" "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n" @@ -58,6 +59,7 @@ static void printHelpFlag(void) { typedef struct CommandLineSettings_ { Hashtable* pidMatchList; + char* commFilter; uid_t userId; int sortKey; int delay; @@ -71,6 +73,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { CommandLineSettings flags = { .pidMatchList = NULL, + .commFilter = NULL, .userId = -1, // -1 is guaranteed to be an invalid uid_t (see setreuid(2)) .sortKey = 0, .delay = -1, @@ -93,12 +96,13 @@ static CommandLineSettings parseArguments(int argc, char** argv) { {"no-unicode", no_argument, 0, 'U'}, {"tree", no_argument, 0, 't'}, {"pid", required_argument, 0, 'p'}, + {"filter", required_argument, 0, 'F'}, {0,0,0,0} }; int opt, opti=0; /* Parse arguments */ - while ((opt = getopt_long(argc, argv, "hVMCs:td:u::Up:", long_opts, &opti))) { + while ((opt = getopt_long(argc, argv, "hVMCs:td:u::Up:F:", long_opts, &opti))) { if (opt == EOF) break; switch (opt) { case 'h': @@ -179,6 +183,12 @@ static CommandLineSettings parseArguments(int argc, char** argv) { break; } + case 'F': { + assert(optarg); + flags.commFilter = xStrdup(optarg); + + break; + } default: exit(1); } @@ -196,6 +206,23 @@ static void millisleep(unsigned long millisec) { } } +static void setCommFilter(State* state, char** commFilter) { + MainPanel* panel = (MainPanel*)state->panel; + ProcessList* pl = state->pl; + IncSet* inc = panel->inc; + size_t maxlen = sizeof(inc->modes[INC_FILTER].buffer) - 1; + char* buffer = inc->modes[INC_FILTER].buffer; + + strncpy(buffer, *commFilter, maxlen); + buffer[maxlen] = 0; + inc->modes[INC_FILTER].index = strlen(buffer); + inc->filtering = true; + pl->incFilter = IncSet_filter(inc); + + free(*commFilter); + *commFilter = NULL; +} + int main(int argc, char** argv) { char *lc_ctype = getenv("LC_CTYPE"); @@ -257,7 +284,11 @@ int main(int argc, char** argv) { .panel = (Panel*) panel, .header = header, }; + MainPanel_setState(panel, &state); + if (flags.commFilter) { + setCommFilter(&state, &(flags.commFilter)); + } ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true); ScreenManager_add(scr, (Panel*) panel, -1); From 769df604b20857e896189434f4134fec253744ac Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Wed, 7 Oct 2020 10:35:06 +0200 Subject: [PATCH 273/411] Set a -dev version to bug reports show a useful version and not the last release --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7982d6480..31d4a57c4 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.65) -AC_INIT([htop],[3.0.2],[htop@groups.io]) +AC_INIT([htop],[3.0.3-dev],[htop@groups.io]) AC_CONFIG_SRCDIR([htop.c]) AC_CONFIG_AUX_DIR([.]) From 1704c29b90535286afde9a42982c6cacc2e94ae2 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Tue, 6 Oct 2020 17:10:23 +0200 Subject: [PATCH 274/411] Use memmove for Vector_take Doing a quick check with callgrind this gives an average reduction from 1804 cycles/call down to 491 cycles/call on my test system. The average was taken over about 40k calls. --- Vector.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Vector.c b/Vector.c index af219dda5..a606894da 100644 --- a/Vector.c +++ b/Vector.c @@ -204,8 +204,9 @@ Object* Vector_take(Vector* this, int idx) { Object* removed = this->array[idx]; //assert (removed != NULL); this->items--; - for (int i = idx; i < this->items; i++) - this->array[i] = this->array[i+1]; + if(idx < this->items) { + memmove(&this->array[idx], &this->array[idx + 1], (this->items - idx) * sizeof(this->array[0])); + } //this->array[this->items] = NULL; assert(Vector_isConsistent(this)); return removed; From 164051354f11c0426e09e4fa09feeca7de92e619 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Tue, 6 Oct 2020 17:19:40 +0200 Subject: [PATCH 275/411] Replace copy loop by memmove in Vector_insert This is basically the same change like in Vector_take, just in the opposite direction. --- Vector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vector.c b/Vector.c index a606894da..3d4e64669 100644 --- a/Vector.c +++ b/Vector.c @@ -190,8 +190,8 @@ void Vector_insert(Vector* this, int idx, void* data_) { Vector_checkArraySize(this); //assert(this->array[this->items] == NULL); - for (int i = this->items; i > idx; i--) { - this->array[i] = this->array[i-1]; + if(idx < this->items) { + memmove(&this->array[idx + 1], &this->array[idx], (this->items - idx) * sizeof(this->array[0])); } this->array[idx] = data; this->items++; From 08d85e61435e43ade490ecef16437f93c0d88bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 4 Oct 2020 17:55:08 +0200 Subject: [PATCH 276/411] Mark Object classes and Object class fields const --- CPUMeter.c | 2 +- InfoScreen.h | 4 ++-- Meter.c | 8 ++++---- Meter.h | 20 +++++++++----------- Object.c | 2 +- Object.h | 10 +++++----- Panel.c | 4 ++-- Panel.h | 6 +++--- Process.h | 2 +- ProcessList.c | 2 +- ProcessList.h | 2 +- Vector.c | 2 +- Vector.h | 4 ++-- darwin/Platform.c | 2 +- dragonflybsd/Platform.c | 4 ++-- freebsd/Platform.c | 4 ++-- linux/Platform.c | 4 ++-- openbsd/Platform.c | 4 ++-- solaris/Platform.c | 4 ++-- zfs/ZfsArcMeter.c | 2 +- 20 files changed, 45 insertions(+), 47 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 51c16c683..72988472a 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -146,7 +146,7 @@ static void CPUMeterCommonInit(Meter *this, int ncol) { AllCPUsMeter_getRange(this, &start, &count); for (int i = 0; i < count; i++) { if (!meters[i]) - meters[i] = Meter_new(this->pl, start+i+1, (MeterClass*) Class(CPUMeter)); + meters[i] = Meter_new(this->pl, start+i+1, (const MeterClass*) Class(CPUMeter)); Meter_init(meters[i]); } if (this->mode == 0) diff --git a/InfoScreen.h b/InfoScreen.h index 196c56e1b..e5c58461b 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -14,14 +14,14 @@ typedef void(*InfoScreen_OnErr)(InfoScreen*); typedef bool(*InfoScreen_OnKey)(InfoScreen*, int); typedef struct InfoScreenClass_ { - ObjectClass super; + const ObjectClass super; const InfoScreen_Scan scan; const InfoScreen_Draw draw; const InfoScreen_OnErr onErr; const InfoScreen_OnKey onKey; } InfoScreenClass; -#define As_InfoScreen(this_) ((InfoScreenClass*)(((InfoScreen*)(this_))->super.klass)) +#define As_InfoScreen(this_) ((const InfoScreenClass*)(((InfoScreen*)(this_))->super.klass)) #define InfoScreen_scan(this_) As_InfoScreen(this_)->scan((InfoScreen*)(this_)) #define InfoScreen_draw(this_) As_InfoScreen(this_)->draw((InfoScreen*)(this_)) #define InfoScreen_onErr(this_) As_InfoScreen(this_)->onErr((InfoScreen*)(this_)) diff --git a/Meter.c b/Meter.c index c0b2af9e4..cd6d089f7 100644 --- a/Meter.c +++ b/Meter.c @@ -27,13 +27,13 @@ MeterClass Meter_class = { } }; -Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) { +Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type) { Meter* this = xCalloc(1, sizeof(Meter)); Object_setClass(this, type); this->h = 1; this->param = param; this->pl = pl; - type->curItems = type->maxItems; + this->curItems = type->maxItems; this->values = xCalloc(type->maxItems, sizeof(double)); this->total = type->total; this->caption = xStrdup(type->caption); @@ -191,7 +191,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { // First draw in the bar[] buffer... int offset = 0; - int items = Meter_getItems(this); + int items = this->curItems; for (int i = 0; i < items; i++) { double value = this->values[i]; value = CLAMP(value, 0.0, this->total); @@ -292,7 +292,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { Meter_updateValues(this, buffer, nValues - 1); double value = 0.0; - int items = Meter_getItems(this); + int items = this->curItems; for (int i = 0; i < items; i++) value += this->values[i]; value /= this->total; diff --git a/Meter.h b/Meter.h index 07e66e0e8..34f388f41 100644 --- a/Meter.h +++ b/Meter.h @@ -22,7 +22,7 @@ typedef void(*Meter_UpdateValues)(Meter*, char*, int); typedef void(*Meter_Draw)(Meter*, int, int, int); typedef struct MeterClass_ { - ObjectClass super; + const ObjectClass super; const Meter_Init init; const Meter_Done done; const Meter_UpdateMode updateMode; @@ -30,16 +30,15 @@ typedef struct MeterClass_ { const Meter_UpdateValues updateValues; const int defaultMode; const double total; - const int* attributes; - const char* name; - const char* uiName; - const char* caption; - const char* description; + const int* const attributes; + const char* const name; + const char* const uiName; + const char* const caption; + const char* const description; const char maxItems; - char curItems; } MeterClass; -#define As_Meter(this_) ((MeterClass*)((this_)->super.klass)) +#define As_Meter(this_) ((const MeterClass*)((this_)->super.klass)) #define Meter_initFn(this_) As_Meter(this_)->init #define Meter_init(this_) As_Meter(this_)->init((Meter*)(this_)) #define Meter_done(this_) As_Meter(this_)->done((Meter*)(this_)) @@ -50,8 +49,6 @@ typedef struct MeterClass_ { #define Meter_updateValues(this_, buf_, sz_) \ As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_) #define Meter_defaultMode(this_) As_Meter(this_)->defaultMode -#define Meter_getItems(this_) As_Meter(this_)->curItems -#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_) #define Meter_attributes(this_) As_Meter(this_)->attributes #define Meter_name(this_) As_Meter(this_)->name #define Meter_uiName(this_) As_Meter(this_)->uiName @@ -66,6 +63,7 @@ struct Meter_ { void* drawData; int h; struct ProcessList_* pl; + char curItems; double* values; double total; }; @@ -92,7 +90,7 @@ typedef struct GraphData_ { extern MeterClass Meter_class; -Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type); +Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type); int Meter_humanUnit(char* buffer, unsigned long int value, int size); diff --git a/Object.c b/Object.c index 6f16009aa..97e913e6c 100644 --- a/Object.c +++ b/Object.c @@ -8,7 +8,7 @@ in the source distribution for its full text. #include "Object.h" -ObjectClass Object_class = { +const ObjectClass Object_class = { .extends = NULL }; diff --git a/Object.h b/Object.h index 6fafd4e16..0d0e00362 100644 --- a/Object.h +++ b/Object.h @@ -19,26 +19,26 @@ typedef long(*Object_Compare)(const void*, const void*); typedef void(*Object_Delete)(Object*); #define Object_getClass(obj_) ((Object*)(obj_))->klass -#define Object_setClass(obj_, class_) Object_getClass(obj_) = (ObjectClass*) class_ +#define Object_setClass(obj_, class_) Object_getClass(obj_) = (const ObjectClass*) class_ #define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_)) #define Object_displayFn(obj_) Object_getClass(obj_)->display #define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_) #define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_) -#define Class(class_) ((ObjectClass*)(&(class_ ## _class))) +#define Class(class_) ((const ObjectClass*)(&(class_ ## _class))) #define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); typedef struct ObjectClass_ { - const void* extends; + const void* const extends; const Object_Display display; const Object_Delete delete; const Object_Compare compare; } ObjectClass; struct Object_ { - ObjectClass* klass; + const ObjectClass* klass; }; typedef union { @@ -46,7 +46,7 @@ typedef union { void* v; } Arg; -extern ObjectClass Object_class; +extern const ObjectClass Object_class; #ifndef NDEBUG diff --git a/Panel.c b/Panel.c index b97fbc9c9..5922d4c7f 100644 --- a/Panel.c +++ b/Panel.c @@ -27,7 +27,7 @@ PanelClass Panel_class = { .eventHandler = Panel_selectByTyping, }; -Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar) { +Panel* Panel_new(int x, int y, int w, int h, bool owner, const ObjectClass* type, FunctionBar* fuBar) { Panel* this; this = xMalloc(sizeof(Panel)); Object_setClass(this, Class(Panel)); @@ -41,7 +41,7 @@ void Panel_delete(Object* cast) { free(this); } -void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar) { +void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type, bool owner, FunctionBar* fuBar) { this->x = x; this->y = y; this->w = w; diff --git a/Panel.h b/Panel.h index 239de0a5e..7c4a6f2f8 100644 --- a/Panel.h +++ b/Panel.h @@ -35,7 +35,7 @@ typedef struct PanelClass_ { const Panel_EventHandler eventHandler; } PanelClass; -#define As_Panel(this_) ((PanelClass*)((this_)->super.klass)) +#define As_Panel(this_) ((const PanelClass*)((this_)->super.klass)) #define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler #define Panel_eventHandler(this_, ev_) As_Panel(this_)->eventHandler((Panel*)(this_), ev_) @@ -62,11 +62,11 @@ struct Panel_ { extern PanelClass Panel_class; -Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar); +Panel* Panel_new(int x, int y, int w, int h, bool owner, const ObjectClass* type, FunctionBar* fuBar); void Panel_delete(Object* cast); -void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar); +void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type, bool owner, FunctionBar* fuBar); void Panel_done(Panel* this); diff --git a/Process.h b/Process.h index dd9c052c2..2ff7f5e0c 100644 --- a/Process.h +++ b/Process.h @@ -129,7 +129,7 @@ typedef struct ProcessClass_ { const Process_WriteField writeField; } ProcessClass; -#define As_Process(this_) ((ProcessClass*)((this_)->super.klass)) +#define As_Process(this_) ((const ProcessClass*)((this_)->super.klass)) #define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid) diff --git a/ProcessList.c b/ProcessList.c index 6ec7ce851..e509b8976 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -15,7 +15,7 @@ in the source distribution for its full text. #include -ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { +ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { this->processes = Vector_new(klass, true, DEFAULT_SIZE); this->processTable = Hashtable_new(140, false); this->usersTable = usersTable; diff --git a/ProcessList.h b/ProcessList.h index c9d1f28f1..164ff7b05 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -69,7 +69,7 @@ void ProcessList_delete(ProcessList* pl); void ProcessList_goThroughEntries(ProcessList* pl); -ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); +ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_done(ProcessList* this); diff --git a/Vector.c b/Vector.c index 3d4e64669..a12d6bb5b 100644 --- a/Vector.c +++ b/Vector.c @@ -13,7 +13,7 @@ in the source distribution for its full text. #include -Vector* Vector_new(ObjectClass* type, bool owner, int size) { +Vector* Vector_new(const ObjectClass* type, bool owner, int size) { Vector* this; if (size == DEFAULT_SIZE) diff --git a/Vector.h b/Vector.h index e2de5e826..d0d42c6cf 100644 --- a/Vector.h +++ b/Vector.h @@ -17,14 +17,14 @@ in the source distribution for its full text. typedef struct Vector_ { Object **array; - ObjectClass* type; + const ObjectClass* type; int arraySize; int growthRate; int items; bool owner; } Vector; -Vector* Vector_new(ObjectClass* type, bool owner, int size); +Vector* Vector_new(const ObjectClass* type, bool owner, int size); void Vector_delete(Vector* this); diff --git a/darwin/Platform.c b/darwin/Platform.c index b7451e83a..fabf5520a 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -216,7 +216,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { mtr->values[CPU_METER_KERNEL] = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total; - Meter_setItems(mtr, 3); + mtr->curItems = 3; /* Convert to percent and return */ total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL]; diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 8fd929e65..332824053 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -167,11 +167,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { if (this->pl->settings->detailedCPUTime) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; - Meter_setItems(this, 4); + this->curItems = 4; percent = v[0]+v[1]+v[2]+v[3]; } else { v[2] = cpuData->systemAllPercent; - Meter_setItems(this, 3); + this->curItems = 3; percent = v[0]+v[1]+v[2]; } diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 59256858c..3e4b9b74f 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -170,11 +170,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { if (this->pl->settings->detailedCPUTime) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; - Meter_setItems(this, 4); + this->curItems = 4; percent = v[0]+v[1]+v[2]+v[3]; } else { v[2] = cpuData->systemAllPercent; - Meter_setItems(this, 3); + this->curItems = 3; percent = v[0]+v[1]+v[2]; } diff --git a/linux/Platform.c b/linux/Platform.c index b0053bc09..6ec0d0763 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -191,7 +191,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_STEAL] = cpuData->stealPeriod / total * 100.0; v[CPU_METER_GUEST] = cpuData->guestPeriod / total * 100.0; v[CPU_METER_IOWAIT] = cpuData->ioWaitPeriod / total * 100.0; - Meter_setItems(this, 8); + this->curItems = 8; if (this->pl->settings->accountGuestInCPUMeter) { percent = v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6]; } else { @@ -200,7 +200,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { } else { v[2] = cpuData->systemAllPeriod / total * 100.0; v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0; - Meter_setItems(this, 4); + this->curItems = 4; percent = v[0]+v[1]+v[2]+v[3]; } percent = CLAMP(percent, 0.0, 100.0); diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 6649064ff..0368d722a 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -173,13 +173,13 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_GUEST] = 0.0; v[CPU_METER_IOWAIT] = 0.0; v[CPU_METER_FREQUENCY] = NAN; - Meter_setItems(this, 8); + this->curItems = 8; totalPercent = v[0]+v[1]+v[2]+v[3]; } else { v[2] = cpuData->sysAllPeriod / total * 100.0; v[3] = 0.0; // No steal nor guest on OpenBSD totalPercent = v[0]+v[1]+v[2]; - Meter_setItems(this, 4); + this->curItems = 4; } totalPercent = CLAMP(totalPercent, 0.0, 100.0); diff --git a/solaris/Platform.c b/solaris/Platform.c index 4a5daee69..5f7373426 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -185,11 +185,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { if (this->pl->settings->detailedCPUTime) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; - Meter_setItems(this, 4); + this->curItems = 4; percent = v[0]+v[1]+v[2]+v[3]; } else { v[2] = cpuData->systemAllPercent; - Meter_setItems(this, 3); + this->curItems = 3; percent = v[0]+v[1]+v[2]; } diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index 94bffdc7d..d52605c6c 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -38,7 +38,7 @@ void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats) { // "Hide" the last value so it can // only be accessed by index and is not // displayed by the Bar or Graph style - Meter_setItems(this, 5); + this->curItems = 5; this->values[5] = stats->size; } From ba282cfe193719f4fe030ebdcd80519ae19ffca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 13:19:50 +0200 Subject: [PATCH 277/411] Mark Object instances const --- AffinityPanel.c | 2 +- AffinityPanel.h | 2 +- AvailableColumnsPanel.c | 2 +- AvailableColumnsPanel.h | 2 +- AvailableMetersPanel.c | 8 ++++---- AvailableMetersPanel.h | 2 +- BatteryMeter.c | 2 +- BatteryMeter.h | 2 +- CPUMeter.c | 26 +++++++++++++------------- CPUMeter.h | 26 +++++++++++++------------- CategoriesPanel.c | 2 +- CategoriesPanel.h | 2 +- CheckItem.c | 2 +- CheckItem.h | 2 +- ClockMeter.c | 2 +- ClockMeter.h | 2 +- ColorsPanel.c | 2 +- ColorsPanel.h | 2 +- ColumnsPanel.c | 2 +- ColumnsPanel.h | 2 +- CommandScreen.c | 2 +- CommandScreen.h | 2 +- DateMeter.c | 2 +- DateMeter.h | 2 +- DateTimeMeter.c | 2 +- DateTimeMeter.h | 2 +- DiskIOMeter.c | 2 +- DiskIOMeter.h | 2 +- DisplayOptionsPanel.c | 2 +- DisplayOptionsPanel.h | 2 +- EnvScreen.c | 2 +- EnvScreen.h | 2 +- Header.c | 4 ++-- Header.h | 2 +- HostnameMeter.c | 2 +- HostnameMeter.h | 2 +- ListItem.c | 2 +- ListItem.h | 2 +- LoadAverageMeter.c | 4 ++-- LoadAverageMeter.h | 4 ++-- MainPanel.c | 2 +- MainPanel.h | 2 +- MemoryMeter.c | 2 +- MemoryMeter.h | 2 +- Meter.c | 8 ++++---- Meter.h | 6 +++--- MetersPanel.c | 2 +- MetersPanel.h | 2 +- OpenFilesScreen.c | 2 +- OpenFilesScreen.h | 2 +- Panel.c | 2 +- Panel.h | 2 +- Process.c | 2 +- Process.h | 2 +- SwapMeter.c | 2 +- SwapMeter.h | 2 +- TasksMeter.c | 2 +- TasksMeter.h | 2 +- TraceScreen.c | 2 +- TraceScreen.h | 2 +- UptimeMeter.c | 2 +- UptimeMeter.h | 2 +- darwin/Platform.c | 2 +- darwin/Platform.h | 2 +- dragonflybsd/Platform.c | 2 +- dragonflybsd/Platform.h | 2 +- freebsd/Platform.c | 2 +- freebsd/Platform.h | 2 +- linux/Platform.c | 2 +- linux/Platform.h | 2 +- openbsd/Platform.c | 2 +- openbsd/Platform.h | 2 +- solaris/Platform.c | 2 +- solaris/Platform.h | 2 +- unsupported/Platform.c | 2 +- unsupported/Platform.h | 2 +- 76 files changed, 111 insertions(+), 111 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index 6c64b14b7..127623c69 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -319,7 +319,7 @@ static MaskItem *AffinityPanel_buildTopology(AffinityPanel* this, hwloc_obj_t ob #endif -PanelClass AffinityPanel_class = { +const PanelClass AffinityPanel_class = { .super = { .extends = Class(Panel), .delete = AffinityPanel_delete diff --git a/AffinityPanel.h b/AffinityPanel.h index 37c7e5d9e..fdefeae40 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -11,7 +11,7 @@ in the source distribution for its full text. #include "Affinity.h" #include "ProcessList.h" -extern PanelClass AffinityPanel_class; +extern const PanelClass AffinityPanel_class; Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width); diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index fd247af01..dcfbb3e27 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -57,7 +57,7 @@ static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) { return result; } -PanelClass AvailableColumnsPanel_class = { +const PanelClass AvailableColumnsPanel_class = { .super = { .extends = Class(Panel), .delete = AvailableColumnsPanel_delete diff --git a/AvailableColumnsPanel.h b/AvailableColumnsPanel.h index dd011755b..8672eb9e7 100644 --- a/AvailableColumnsPanel.h +++ b/AvailableColumnsPanel.h @@ -14,7 +14,7 @@ typedef struct AvailableColumnsPanel_ { Panel* columns; } AvailableColumnsPanel; -extern PanelClass AvailableColumnsPanel_class; +extern const PanelClass AvailableColumnsPanel_class; AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns); diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index f5e59218b..812d1f3d9 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -24,7 +24,7 @@ static void AvailableMetersPanel_delete(Object* object) { free(this); } -static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, MeterClass* type, int param, int column) { +static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, const MeterClass* type, int param, int column) { Meter* meter = Header_addMeterByClass(header, type, param, column); Panel_add(panel, (Object*) Meter_toListItem(meter, false)); Panel_setSelected(panel, Panel_size(panel) - 1); @@ -77,7 +77,7 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { return result; } -PanelClass AvailableMetersPanel_class = { +const PanelClass AvailableMetersPanel_class = { .super = { .extends = Class(Panel), .delete = AvailableMetersPanel_delete @@ -101,13 +101,13 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade // Platform_meterTypes[0] should be always (&CPUMeter_class), which we will // handle separately in the code below. for (int i = 1; Platform_meterTypes[i]; i++) { - MeterClass* type = Platform_meterTypes[i]; + const MeterClass* type = Platform_meterTypes[i]; assert(type != &CPUMeter_class); const char* label = type->description ? type->description : type->uiName; Panel_add(super, (Object*) ListItem_new(label, i << 16)); } // Handle (&CPUMeter_class) - MeterClass* type = &CPUMeter_class; + const MeterClass* type = &CPUMeter_class; int cpus = pl->cpuCount; if (cpus > 1) { Panel_add(super, (Object*) ListItem_new("CPU average", 0)); diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index f4f18dac2..f168869d6 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -22,7 +22,7 @@ typedef struct AvailableMetersPanel_ { Panel* rightPanel; } AvailableMetersPanel; -extern PanelClass AvailableMetersPanel_class; +extern const PanelClass AvailableMetersPanel_class; AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl); diff --git a/BatteryMeter.c b/BatteryMeter.c index 4f119e1f9..060b125cc 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -58,7 +58,7 @@ static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) { } } -MeterClass BatteryMeter_class = { +const MeterClass BatteryMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete diff --git a/BatteryMeter.h b/BatteryMeter.h index 8f9441ccd..b6e8c5201 100644 --- a/BatteryMeter.h +++ b/BatteryMeter.h @@ -17,6 +17,6 @@ typedef enum ACPresence_ { AC_ERROR } ACPresence; -extern MeterClass BatteryMeter_class; +extern const MeterClass BatteryMeter_class; #endif diff --git a/CPUMeter.c b/CPUMeter.c index 72988472a..7ce6caf81 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -246,7 +246,7 @@ static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) { } -MeterClass CPUMeter_class = { +const MeterClass CPUMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -263,7 +263,7 @@ MeterClass CPUMeter_class = { .init = CPUMeter_init }; -MeterClass AllCPUsMeter_class = { +const MeterClass AllCPUsMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -282,7 +282,7 @@ MeterClass AllCPUsMeter_class = { .done = AllCPUsMeter_done }; -MeterClass AllCPUs2Meter_class = { +const MeterClass AllCPUs2Meter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -301,7 +301,7 @@ MeterClass AllCPUs2Meter_class = { .done = AllCPUsMeter_done }; -MeterClass LeftCPUsMeter_class = { +const MeterClass LeftCPUsMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -320,7 +320,7 @@ MeterClass LeftCPUsMeter_class = { .done = AllCPUsMeter_done }; -MeterClass RightCPUsMeter_class = { +const MeterClass RightCPUsMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -339,7 +339,7 @@ MeterClass RightCPUsMeter_class = { .done = AllCPUsMeter_done }; -MeterClass LeftCPUs2Meter_class = { +const MeterClass LeftCPUs2Meter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -358,7 +358,7 @@ MeterClass LeftCPUs2Meter_class = { .done = AllCPUsMeter_done }; -MeterClass RightCPUs2Meter_class = { +const MeterClass RightCPUs2Meter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -377,7 +377,7 @@ MeterClass RightCPUs2Meter_class = { .done = AllCPUsMeter_done }; -MeterClass AllCPUs4Meter_class = { +const MeterClass AllCPUs4Meter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -396,7 +396,7 @@ MeterClass AllCPUs4Meter_class = { .done = AllCPUsMeter_done }; -MeterClass LeftCPUs4Meter_class = { +const MeterClass LeftCPUs4Meter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -415,7 +415,7 @@ MeterClass LeftCPUs4Meter_class = { .done = AllCPUsMeter_done }; -MeterClass RightCPUs4Meter_class = { +const MeterClass RightCPUs4Meter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -434,7 +434,7 @@ MeterClass RightCPUs4Meter_class = { .done = AllCPUsMeter_done }; -MeterClass AllCPUs8Meter_class = { +const MeterClass AllCPUs8Meter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -453,7 +453,7 @@ MeterClass AllCPUs8Meter_class = { .done = AllCPUsMeter_done }; -MeterClass LeftCPUs8Meter_class = { +const MeterClass LeftCPUs8Meter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -472,7 +472,7 @@ MeterClass LeftCPUs8Meter_class = { .done = AllCPUsMeter_done }; -MeterClass RightCPUs8Meter_class = { +const MeterClass RightCPUs8Meter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/CPUMeter.h b/CPUMeter.h index 471f33fcb..d60e82f73 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -22,30 +22,30 @@ typedef enum { CPU_METER_ITEMCOUNT = 9, // number of entries in this enum } CPUMeterValues; -extern MeterClass CPUMeter_class; +extern const MeterClass CPUMeter_class; -extern MeterClass AllCPUsMeter_class; +extern const MeterClass AllCPUsMeter_class; -extern MeterClass AllCPUs2Meter_class; +extern const MeterClass AllCPUs2Meter_class; -extern MeterClass LeftCPUsMeter_class; +extern const MeterClass LeftCPUsMeter_class; -extern MeterClass RightCPUsMeter_class; +extern const MeterClass RightCPUsMeter_class; -extern MeterClass LeftCPUs2Meter_class; +extern const MeterClass LeftCPUs2Meter_class; -extern MeterClass RightCPUs2Meter_class; +extern const MeterClass RightCPUs2Meter_class; -extern MeterClass AllCPUs4Meter_class; +extern const MeterClass AllCPUs4Meter_class; -extern MeterClass LeftCPUs4Meter_class; +extern const MeterClass LeftCPUs4Meter_class; -extern MeterClass RightCPUs4Meter_class; +extern const MeterClass RightCPUs4Meter_class; -extern MeterClass AllCPUs8Meter_class; +extern const MeterClass AllCPUs8Meter_class; -extern MeterClass LeftCPUs8Meter_class; +extern const MeterClass LeftCPUs8Meter_class; -extern MeterClass RightCPUs8Meter_class; +extern const MeterClass RightCPUs8Meter_class; #endif diff --git a/CategoriesPanel.c b/CategoriesPanel.c index b09a015f3..8adf14f63 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -109,7 +109,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) { return result; } -PanelClass CategoriesPanel_class = { +const PanelClass CategoriesPanel_class = { .super = { .extends = Class(Panel), .delete = CategoriesPanel_delete diff --git a/CategoriesPanel.h b/CategoriesPanel.h index 891d77113..1f17bd2e6 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -23,7 +23,7 @@ typedef struct CategoriesPanel_ { void CategoriesPanel_makeMetersPage(CategoriesPanel* this); -extern PanelClass CategoriesPanel_class; +extern const PanelClass CategoriesPanel_class; CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl); diff --git a/CheckItem.c b/CheckItem.c index f6d5bb916..09e42ee66 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -33,7 +33,7 @@ static void CheckItem_display(Object* cast, RichString* out) { RichString_append(out, CRT_colors[CHECK_TEXT], this->text); } -ObjectClass CheckItem_class = { +const ObjectClass CheckItem_class = { .display = CheckItem_display, .delete = CheckItem_delete }; diff --git a/CheckItem.h b/CheckItem.h index 714835262..168efdcc0 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -16,7 +16,7 @@ typedef struct CheckItem_ { bool value; } CheckItem; -extern ObjectClass CheckItem_class; +extern const ObjectClass CheckItem_class; CheckItem* CheckItem_newByRef(char* text, bool* ref); diff --git a/ClockMeter.c b/ClockMeter.c index d309852f5..51fbed630 100644 --- a/ClockMeter.c +++ b/ClockMeter.c @@ -24,7 +24,7 @@ static void ClockMeter_updateValues(Meter* this, char* buffer, int size) { strftime(buffer, size, "%H:%M:%S", lt); } -MeterClass ClockMeter_class = { +const MeterClass ClockMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete diff --git a/ClockMeter.h b/ClockMeter.h index e431e3677..ecd4b6a93 100644 --- a/ClockMeter.h +++ b/ClockMeter.h @@ -9,6 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass ClockMeter_class; +extern const MeterClass ClockMeter_class; #endif diff --git a/ColorsPanel.c b/ColorsPanel.c index 36cd85bd9..75d3e6548 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -76,7 +76,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) { return result; } -PanelClass ColorsPanel_class = { +const PanelClass ColorsPanel_class = { .super = { .extends = Class(Panel), .delete = ColorsPanel_delete diff --git a/ColorsPanel.h b/ColorsPanel.h index 0f69e8f74..f63ca3563 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -18,7 +18,7 @@ typedef struct ColorsPanel_ { ScreenManager* scr; } ColorsPanel; -extern PanelClass ColorsPanel_class; +extern const PanelClass ColorsPanel_class; ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); diff --git a/ColumnsPanel.c b/ColumnsPanel.c index 8328d15e8..e4fe4fc1f 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -105,7 +105,7 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { return result; } -PanelClass ColumnsPanel_class = { +const PanelClass ColumnsPanel_class = { .super = { .extends = Class(Panel), .delete = ColumnsPanel_delete diff --git a/ColumnsPanel.h b/ColumnsPanel.h index a35036f11..e8acbb233 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -17,7 +17,7 @@ typedef struct ColumnsPanel_ { bool moving; } ColumnsPanel; -extern PanelClass ColumnsPanel_class; +extern const PanelClass ColumnsPanel_class; ColumnsPanel* ColumnsPanel_new(Settings* settings); diff --git a/CommandScreen.c b/CommandScreen.c index bc71e09fe..58ed88404 100644 --- a/CommandScreen.c +++ b/CommandScreen.c @@ -48,7 +48,7 @@ static void CommandScreen_draw(InfoScreen* this) { InfoScreen_drawTitled(this, "Command of process %d - %s", this->process->pid, this->process->comm); } -InfoScreenClass CommandScreen_class = { +const InfoScreenClass CommandScreen_class = { .super = { .extends = Class(Object), .delete = CommandScreen_delete diff --git a/CommandScreen.h b/CommandScreen.h index a1604a3ed..4f3ce9479 100644 --- a/CommandScreen.h +++ b/CommandScreen.h @@ -7,7 +7,7 @@ typedef struct CommandScreen_ { InfoScreen super; } CommandScreen; -extern InfoScreenClass CommandScreen_class; +extern const InfoScreenClass CommandScreen_class; CommandScreen* CommandScreen_new(Process* process); diff --git a/DateMeter.c b/DateMeter.c index e130159ad..6ea108e14 100644 --- a/DateMeter.c +++ b/DateMeter.c @@ -31,7 +31,7 @@ static void DateMeter_updateValues(Meter* this, char* buffer, int size) { strftime(buffer, size, "%F", lt); } -MeterClass DateMeter_class = { +const MeterClass DateMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete diff --git a/DateMeter.h b/DateMeter.h index 44ed24da3..634557674 100644 --- a/DateMeter.h +++ b/DateMeter.h @@ -9,6 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass DateMeter_class; +extern const MeterClass DateMeter_class; #endif diff --git a/DateTimeMeter.c b/DateTimeMeter.c index 32dd5d1a4..f3c877b38 100644 --- a/DateTimeMeter.c +++ b/DateTimeMeter.c @@ -31,7 +31,7 @@ static void DateTimeMeter_updateValues(Meter* this, char* buffer, int size) { strftime(buffer, size, "%F %H:%M:%S", lt); } -MeterClass DateTimeMeter_class = { +const MeterClass DateTimeMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete diff --git a/DateTimeMeter.h b/DateTimeMeter.h index ef25264ce..6cb73c24f 100644 --- a/DateTimeMeter.h +++ b/DateTimeMeter.h @@ -9,6 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass DateTimeMeter_class; +extern const MeterClass DateTimeMeter_class; #endif diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 1349bf40b..781d9bb6a 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -75,7 +75,7 @@ static void DIskIOMeter_display(ATTR_UNUSED Object* cast, RichString* out) { RichString_append(out, CRT_colors[DISKIO_WRITE], buffer); } -MeterClass DiskIOMeter_class = { +const MeterClass DiskIOMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/DiskIOMeter.h b/DiskIOMeter.h index f75aaf814..c7e4542ae 100644 --- a/DiskIOMeter.h +++ b/DiskIOMeter.h @@ -9,6 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass DiskIOMeter_class; +extern const MeterClass DiskIOMeter_class; #endif /* HEADER_DiskIOMeter */ diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 54b389ba4..1aede655f 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -52,7 +52,7 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { return result; } -PanelClass DisplayOptionsPanel_class = { +const PanelClass DisplayOptionsPanel_class = { .super = { .extends = Class(Panel), .delete = DisplayOptionsPanel_delete diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index aad7bc758..02b67a087 100644 --- a/DisplayOptionsPanel.h +++ b/DisplayOptionsPanel.h @@ -18,7 +18,7 @@ typedef struct DisplayOptionsPanel_ { ScreenManager* scr; } DisplayOptionsPanel; -extern PanelClass DisplayOptionsPanel_class; +extern const PanelClass DisplayOptionsPanel_class; DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr); diff --git a/EnvScreen.c b/EnvScreen.c index 479a45d6c..1f107457e 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -12,7 +12,7 @@ #include -InfoScreenClass EnvScreen_class = { +const InfoScreenClass EnvScreen_class = { .super = { .extends = Class(Object), .delete = EnvScreen_delete diff --git a/EnvScreen.h b/EnvScreen.h index 54dfa41ab..428a121f8 100644 --- a/EnvScreen.h +++ b/EnvScreen.h @@ -7,7 +7,7 @@ typedef struct EnvScreen_ { InfoScreen super; } EnvScreen; -extern InfoScreenClass EnvScreen_class; +extern const InfoScreenClass EnvScreen_class; EnvScreen* EnvScreen_new(Process* process); diff --git a/Header.c b/Header.c index 7a58c4c21..e5a64db19 100644 --- a/Header.c +++ b/Header.c @@ -88,7 +88,7 @@ MeterModeId Header_addMeterByName(Header* this, char* name, int column) { *paren = '\0'; } MeterModeId mode = TEXT_METERMODE; - for (MeterClass** type = Platform_meterTypes; *type; type++) { + for (const MeterClass* const* type = Platform_meterTypes; *type; type++) { if (String_eq(name, (*type)->name)) { Meter* meter = Meter_new(this->pl, param, *type); Vector_add(meters, meter); @@ -110,7 +110,7 @@ void Header_setMode(Header* this, int i, MeterModeId mode, int column) { Meter_setMode(meter, mode); } -Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column) { +Meter* Header_addMeterByClass(Header* this, const MeterClass* type, int param, int column) { Vector* meters = this->columns[column]; Meter* meter = Meter_new(this->pl, param, type); diff --git a/Header.h b/Header.h index 2637dc99f..9059a9f46 100644 --- a/Header.h +++ b/Header.h @@ -34,7 +34,7 @@ MeterModeId Header_addMeterByName(Header* this, char* name, int column); void Header_setMode(Header* this, int i, MeterModeId mode, int column); -Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column); +Meter* Header_addMeterByClass(Header* this, const MeterClass* type, int param, int column); int Header_size(Header* this, int column); diff --git a/HostnameMeter.c b/HostnameMeter.c index 4d39a39a8..24424d015 100644 --- a/HostnameMeter.c +++ b/HostnameMeter.c @@ -21,7 +21,7 @@ static void HostnameMeter_updateValues(Meter* this, char* buffer, int size) { gethostname(buffer, size-1); } -MeterClass HostnameMeter_class = { +const MeterClass HostnameMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete diff --git a/HostnameMeter.h b/HostnameMeter.h index c868512b1..77fe3da92 100644 --- a/HostnameMeter.h +++ b/HostnameMeter.h @@ -9,6 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass HostnameMeter_class; +extern const MeterClass HostnameMeter_class; #endif diff --git a/ListItem.c b/ListItem.c index 206444670..e1dcd52d7 100644 --- a/ListItem.c +++ b/ListItem.c @@ -42,7 +42,7 @@ static void ListItem_display(Object* cast, RichString* out) { RichString_append(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/); } -ObjectClass ListItem_class = { +const ObjectClass ListItem_class = { .display = ListItem_display, .delete = ListItem_delete, .compare = ListItem_compare diff --git a/ListItem.h b/ListItem.h index 8e76ff7ed..387e8e214 100644 --- a/ListItem.h +++ b/ListItem.h @@ -16,7 +16,7 @@ typedef struct ListItem_ { bool moving; } ListItem; -extern ObjectClass ListItem_class; +extern const ObjectClass ListItem_class; ListItem* ListItem_new(const char* value, int key); diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index d14d97ab2..d2fa582a6 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -53,7 +53,7 @@ static void LoadMeter_display(Object* cast, RichString* out) { RichString_write(out, CRT_colors[LOAD], buffer); } -MeterClass LoadAverageMeter_class = { +const MeterClass LoadAverageMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -70,7 +70,7 @@ MeterClass LoadAverageMeter_class = { .caption = "Load average: " }; -MeterClass LoadMeter_class = { +const MeterClass LoadMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/LoadAverageMeter.h b/LoadAverageMeter.h index 442306930..776c8bf63 100644 --- a/LoadAverageMeter.h +++ b/LoadAverageMeter.h @@ -9,8 +9,8 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass LoadAverageMeter_class; +extern const MeterClass LoadAverageMeter_class; -extern MeterClass LoadMeter_class; +extern const MeterClass LoadMeter_class; #endif diff --git a/MainPanel.c b/MainPanel.c index 51bcf1ae8..604749a90 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -150,7 +150,7 @@ bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Ar return ok; } -PanelClass MainPanel_class = { +const PanelClass MainPanel_class = { .super = { .extends = Class(Panel), .delete = MainPanel_delete diff --git a/MainPanel.h b/MainPanel.h index 72790d3c6..9e2da305a 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -34,7 +34,7 @@ const char* MainPanel_getValue(MainPanel* this, int i); bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged); -extern PanelClass MainPanel_class; +extern const PanelClass MainPanel_class; MainPanel* MainPanel_new(void); diff --git a/MemoryMeter.c b/MemoryMeter.c index 5834e5076..fa0e09abb 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -53,7 +53,7 @@ static void MemoryMeter_display(Object* cast, RichString* out) { RichString_append(out, CRT_colors[MEMORY_CACHE], buffer); } -MeterClass MemoryMeter_class = { +const MeterClass MemoryMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/MemoryMeter.h b/MemoryMeter.h index c490b143e..d299483ae 100644 --- a/MemoryMeter.h +++ b/MemoryMeter.h @@ -9,6 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass MemoryMeter_class; +extern const MeterClass MemoryMeter_class; #endif diff --git a/Meter.c b/Meter.c index cd6d089f7..15be309f9 100644 --- a/Meter.c +++ b/Meter.c @@ -21,7 +21,7 @@ in the source distribution for its full text. #define GRAPH_HEIGHT 4 /* Unit: rows (lines) */ -MeterClass Meter_class = { +const MeterClass Meter_class = { .super = { .extends = Class(Object) } @@ -115,7 +115,7 @@ void Meter_setMode(Meter* this, int modeIndex) { free(this->drawData); this->drawData = NULL; - MeterMode* mode = Meter_modes[modeIndex]; + const MeterMode* mode = Meter_modes[modeIndex]; this->draw = mode->draw; this->h = mode->h; } @@ -410,7 +410,7 @@ static MeterMode LEDMeterMode = { .draw = LEDMeterMode_draw, }; -MeterMode* Meter_modes[] = { +const MeterMode* const Meter_modes[] = { NULL, &BarMeterMode, &TextMeterMode, @@ -437,7 +437,7 @@ static const int BlankMeter_attributes[] = { DEFAULT_COLOR }; -MeterClass BlankMeter_class = { +const MeterClass BlankMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/Meter.h b/Meter.h index 34f388f41..0647c764d 100644 --- a/Meter.h +++ b/Meter.h @@ -88,7 +88,7 @@ typedef struct GraphData_ { double values[METER_BUFFER_LEN]; } GraphData; -extern MeterClass Meter_class; +extern const MeterClass Meter_class; Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type); @@ -102,8 +102,8 @@ void Meter_setMode(Meter* this, int modeIndex); ListItem* Meter_toListItem(Meter* this, bool moving); -extern MeterMode* Meter_modes[]; +extern const MeterMode* const Meter_modes[]; -extern MeterClass BlankMeter_class; +extern const MeterClass BlankMeter_class; #endif diff --git a/MetersPanel.c b/MetersPanel.c index 6f59f0134..36cc8f451 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -186,7 +186,7 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { return result; } -PanelClass MetersPanel_class = { +const PanelClass MetersPanel_class = { .super = { .extends = Class(Panel), .delete = MetersPanel_delete diff --git a/MetersPanel.h b/MetersPanel.h index 501489443..760388d85 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -28,7 +28,7 @@ void MetersPanel_cleanup(void); void MetersPanel_setMoving(MetersPanel* this, bool moving); -extern PanelClass MetersPanel_class; +extern const PanelClass MetersPanel_class; MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr); diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 652e07484..7c0acebe7 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -24,7 +24,7 @@ in the source distribution for its full text. #include -InfoScreenClass OpenFilesScreen_class = { +const InfoScreenClass OpenFilesScreen_class = { .super = { .extends = Class(Object), .delete = OpenFilesScreen_delete diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index 9d63fe7a3..9a12dcd0d 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -29,7 +29,7 @@ typedef struct OpenFilesScreen_ { pid_t pid; } OpenFilesScreen; -extern InfoScreenClass OpenFilesScreen_class; +extern const InfoScreenClass OpenFilesScreen_class; OpenFilesScreen* OpenFilesScreen_new(Process* process); diff --git a/Panel.c b/Panel.c index 5922d4c7f..06a15c6b1 100644 --- a/Panel.c +++ b/Panel.c @@ -19,7 +19,7 @@ in the source distribution for its full text. #include #include -PanelClass Panel_class = { +const PanelClass Panel_class = { .super = { .extends = Class(Object), .delete = Panel_delete diff --git a/Panel.h b/Panel.h index 7c4a6f2f8..4b28c42d5 100644 --- a/Panel.h +++ b/Panel.h @@ -60,7 +60,7 @@ struct Panel_ { #define KEY_CTRL(l) ((l)-'A'+1) -extern PanelClass Panel_class; +extern const PanelClass Panel_class; Panel* Panel_new(int x, int y, int w, int h, bool owner, const ObjectClass* type, FunctionBar* fuBar); diff --git a/Process.c b/Process.c index 07ea13829..ea703e4b2 100644 --- a/Process.c +++ b/Process.c @@ -384,7 +384,7 @@ void Process_done(Process* this) { free(this->comm); } -ProcessClass Process_class = { +const ProcessClass Process_class = { .super = { .extends = Class(Object), .display = Process_display, diff --git a/Process.h b/Process.h index 2ff7f5e0c..beca4f25c 100644 --- a/Process.h +++ b/Process.h @@ -162,7 +162,7 @@ void Process_display(Object* cast, RichString* out); void Process_done(Process* this); -extern ProcessClass Process_class; +extern const ProcessClass Process_class; void Process_init(Process* this, struct Settings_* settings); diff --git a/SwapMeter.c b/SwapMeter.c index 93a34e8f3..e754bbe63 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -45,7 +45,7 @@ static void SwapMeter_display(Object* cast, RichString* out) { RichString_append(out, CRT_colors[METER_VALUE], buffer); } -MeterClass SwapMeter_class = { +const MeterClass SwapMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/SwapMeter.h b/SwapMeter.h index 502e6ee66..623a0364a 100644 --- a/SwapMeter.h +++ b/SwapMeter.h @@ -9,6 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass SwapMeter_class; +extern const MeterClass SwapMeter_class; #endif diff --git a/TasksMeter.c b/TasksMeter.c index eb727cc27..bf289e99e 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -66,7 +66,7 @@ static void TasksMeter_display(Object* cast, RichString* out) { RichString_append(out, CRT_colors[METER_TEXT], " running"); } -MeterClass TasksMeter_class = { +const MeterClass TasksMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/TasksMeter.h b/TasksMeter.h index 8be826be3..cecb40136 100644 --- a/TasksMeter.h +++ b/TasksMeter.h @@ -9,6 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass TasksMeter_class; +extern const MeterClass TasksMeter_class; #endif diff --git a/TraceScreen.c b/TraceScreen.c index 184064546..8e5f61e70 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -33,7 +33,7 @@ static const char* const TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"}; static int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27}; -InfoScreenClass TraceScreen_class = { +const InfoScreenClass TraceScreen_class = { .super = { .extends = Class(Object), .delete = TraceScreen_delete diff --git a/TraceScreen.h b/TraceScreen.h index 04b0848fa..513ea4612 100644 --- a/TraceScreen.h +++ b/TraceScreen.h @@ -21,7 +21,7 @@ typedef struct TraceScreen_ { } TraceScreen; -extern InfoScreenClass TraceScreen_class; +extern const InfoScreenClass TraceScreen_class; TraceScreen* TraceScreen_new(Process* process); diff --git a/UptimeMeter.c b/UptimeMeter.c index 07c4169bf..a11951869 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -41,7 +41,7 @@ static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) { xSnprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds); } -MeterClass UptimeMeter_class = { +const MeterClass UptimeMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete diff --git a/UptimeMeter.h b/UptimeMeter.h index aef3ac375..49300bbb1 100644 --- a/UptimeMeter.h +++ b/UptimeMeter.h @@ -9,6 +9,6 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass UptimeMeter_class; +extern const MeterClass UptimeMeter_class; #endif diff --git a/darwin/Platform.c b/darwin/Platform.c index fabf5520a..4d8ede322 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -94,7 +94,7 @@ ProcessFieldData Process_fields[] = { [100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, }; -MeterClass* Platform_meterTypes[] = { +const MeterClass* const Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, &DateMeter_class, diff --git a/darwin/Platform.h b/darwin/Platform.h index ba7799761..9b7a324b9 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -22,7 +22,7 @@ extern const unsigned int Platform_numberOfSignals; extern ProcessFieldData Process_fields[]; -extern MeterClass* Platform_meterTypes[]; +extern const MeterClass* const Platform_meterTypes[]; void Platform_setBindings(Htop_Action* keys); diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 332824053..21ebc40a8 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -77,7 +77,7 @@ void Platform_setBindings(Htop_Action* keys) { (void) keys; } -MeterClass* Platform_meterTypes[] = { +const MeterClass* const Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, &DateMeter_class, diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 5dfd28c00..3dc1eb1e8 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -24,7 +24,7 @@ extern const unsigned int Platform_numberOfSignals; void Platform_setBindings(Htop_Action* keys); -extern MeterClass* Platform_meterTypes[]; +extern const MeterClass* const Platform_meterTypes[]; int Platform_getUptime(void); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 3e4b9b74f..9c91de152 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -78,7 +78,7 @@ void Platform_setBindings(Htop_Action* keys) { (void) keys; } -MeterClass* Platform_meterTypes[] = { +const MeterClass* const Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, &DateMeter_class, diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 09783afc3..feda7416a 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -23,7 +23,7 @@ extern const unsigned int Platform_numberOfSignals; void Platform_setBindings(Htop_Action* keys); -extern MeterClass* Platform_meterTypes[]; +extern const MeterClass* const Platform_meterTypes[]; int Platform_getUptime(void); diff --git a/linux/Platform.c b/linux/Platform.c index 6ec0d0763..e0a035483 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -105,7 +105,7 @@ void Platform_setBindings(Htop_Action* keys) { keys['i'] = Platform_actionSetIOPriority; } -MeterClass* Platform_meterTypes[] = { +const MeterClass* const Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, &DateMeter_class, diff --git a/linux/Platform.h b/linux/Platform.h index 58f5acec5..66a60d8b6 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -23,7 +23,7 @@ extern const unsigned int Platform_numberOfSignals; void Platform_setBindings(Htop_Action* keys); -extern MeterClass* Platform_meterTypes[]; +extern const MeterClass* const Platform_meterTypes[]; int Platform_getUptime(void); diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 0368d722a..02a821e7d 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -90,7 +90,7 @@ void Platform_setBindings(Htop_Action* keys) { (void) keys; } -MeterClass* Platform_meterTypes[] = { +const MeterClass* const Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, &DateMeter_class, diff --git a/openbsd/Platform.h b/openbsd/Platform.h index dc9b0fa37..c71d490e9 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -25,7 +25,7 @@ extern const unsigned int Platform_numberOfSignals; void Platform_setBindings(Htop_Action* keys); -extern MeterClass* Platform_meterTypes[]; +extern const MeterClass* const Platform_meterTypes[]; int Platform_getUptime(void); diff --git a/solaris/Platform.c b/solaris/Platform.c index 5f7373426..e1243bfa0 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -87,7 +87,7 @@ const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(Si ProcessField Platform_defaultFields[] = { PID, LWPID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; -MeterClass* Platform_meterTypes[] = { +const MeterClass* const Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, &DateMeter_class, diff --git a/solaris/Platform.h b/solaris/Platform.h index fa8be103a..a9b7712dc 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -37,7 +37,7 @@ extern const unsigned int Platform_numberOfSignals; extern ProcessField Platform_defaultFields[]; -extern MeterClass* Platform_meterTypes[]; +extern const MeterClass* const Platform_meterTypes[]; void Platform_setBindings(Htop_Action* keys); diff --git a/unsupported/Platform.c b/unsupported/Platform.c index da360a319..304989eef 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -58,7 +58,7 @@ ProcessFieldData Process_fields[] = { [100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, }; -MeterClass* Platform_meterTypes[] = { +const MeterClass* const Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, &DateMeter_class, diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 8349d97a7..ce188afad 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -21,7 +21,7 @@ extern ProcessField Platform_defaultFields[]; extern ProcessFieldData Process_fields[]; -extern MeterClass* Platform_meterTypes[]; +extern const MeterClass* const Platform_meterTypes[]; void Platform_setBindings(Htop_Action* keys); From 2970cae5436c1e38a98661da3d59c3371051d606 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Wed, 30 Sep 2020 23:46:52 +0200 Subject: [PATCH 278/411] Handle parsing envID & VPid from process status file Fixes #55 Fixes #192 --- linux/LinuxProcess.c | 11 +++-- linux/LinuxProcess.h | 4 +- linux/LinuxProcessList.c | 93 ++++++++++++++++++++++++++++++++++------ 3 files changed, 90 insertions(+), 18 deletions(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 373c9ad80..5e661e03c 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -77,8 +77,8 @@ ProcessFieldData Process_fields[] = { [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, }, [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, }, #ifdef HAVE_OPENVZ - [CTID] = { .name = "CTID", .title = " CTID ", .description = "OpenVZ container ID (a.k.a. virtual environment ID)", .flags = PROCESS_FLAG_LINUX_OPENVZ, }, - [VPID] = { .name = "VPID", .title = " VPID ", .description = "OpenVZ process ID", .flags = PROCESS_FLAG_LINUX_OPENVZ, }, + [CTID] = { .name = "CTID", .title = " CTID ", .description = "OpenVZ container ID (a.k.a. virtual environment ID)", .flags = PROCESS_FLAG_LINUX_OPENVZ, }, + [VPID] = { .name = "VPID", .title = " VPID ", .description = "OpenVZ process ID", .flags = PROCESS_FLAG_LINUX_OPENVZ, }, #endif #ifdef HAVE_VSERVER [VXID] = { .name = "VXID", .title = " VXID ", .description = "VServer process ID", .flags = PROCESS_FLAG_LINUX_VSERVER, }, @@ -148,6 +148,9 @@ void Process_delete(Object* cast) { Process_done((Process*)cast); #ifdef HAVE_CGROUP free(this->cgroup); +#endif +#ifdef HAVE_OPENVZ + free(this->ctid); #endif free(this->secattr); free(this->ttyDevice); @@ -253,7 +256,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) } #endif #ifdef HAVE_OPENVZ - case CTID: xSnprintf(buffer, n, "%7u ", lp->ctid); break; + case CTID: xSnprintf(buffer, n, "%-8s ", lp->ctid ? lp->ctid : ""); break; case VPID: xSnprintf(buffer, n, Process_pidFormat, lp->vpid); break; #endif #ifdef HAVE_VSERVER @@ -351,7 +354,7 @@ long LinuxProcess_compare(const void* v1, const void* v2) { #endif #ifdef HAVE_OPENVZ case CTID: - return (p2->ctid - p1->ctid); + return strcmp(p1->ctid ? p1->ctid : "", p2->ctid ? p2->ctid : ""); case VPID: return (p2->vpid - p1->vpid); #endif diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 4b2386e90..c1eb0ed53 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -122,8 +122,8 @@ typedef struct LinuxProcess_ { double io_rate_write_bps; #endif #ifdef HAVE_OPENVZ - unsigned int ctid; - unsigned int vpid; + char* ctid; + pid_t vpid; #endif #ifdef HAVE_VSERVER unsigned int vxid; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 2317e1c86..5a32f3dde 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -482,25 +482,94 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* dirname, const char* name) { if ( (access(PROCDIR "/vz", R_OK) != 0)) { + free(process->ctid); + process->ctid = NULL; process->vpid = process->super.pid; - process->ctid = 0; return; } + char filename[MAX_NAME+1]; - xSnprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name); + xSnprintf(filename, sizeof(filename), "%s/%s/status", dirname, name); FILE* file = fopen(filename, "r"); - if (!file) + if (!file) { + free(process->ctid); + process->ctid = NULL; + process->vpid = process->super.pid; return; - (void)! fscanf(file, - "%*32u %*32s %*1c %*32u %*32u %*32u %*32u %*32u %*32u %*32u " - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u " - "%*32u %*32u %32u %32u", - &process->vpid, &process->ctid); + } + + bool foundEnvID = false; + bool foundVPid = false; + char linebuf[256]; + while(fgets(linebuf, sizeof(linebuf), file) != NULL) { + if(strchr(linebuf, '\n') == NULL) { + // Partial line, skip to end of this line + while(fgets(linebuf, sizeof(linebuf), file) != NULL) { + if(strchr(linebuf, '\n') != NULL) { + break; + } + } + continue; + } + + char* name_value_sep = strchr(linebuf, ':'); + if(name_value_sep == NULL) { + continue; + } + + int field; + if(0 == strncasecmp(linebuf, "envID", name_value_sep - linebuf)) { + field = 1; + } else if(0 == strncasecmp(linebuf, "VPid", name_value_sep - linebuf)) { + field = 2; + } else { + continue; + } + + do { + name_value_sep++; + } while(*name_value_sep != '\0' && *name_value_sep <= 32); + + char* value_end = name_value_sep; + + while(*value_end != '\0' && *value_end > 32) { + value_end++; + } + + if(name_value_sep == value_end) { + continue; + } + + *value_end = '\0'; + + switch(field) { + case 1: + foundEnvID = true; + if(0 != strcmp(name_value_sep, process->ctid ? process->ctid : "")) { + free(process->ctid); + process->ctid = xStrdup(name_value_sep); + } + break; + case 2: + foundVPid = true; + process->vpid = strtoul(name_value_sep, NULL, 0); + break; + default: + //Sanity Check: Should never reach here, or the implementation is missing something! + assert(false && "OpenVZ handling: Unimplemented case for field handling reached."); + } + } + fclose(file); + + if(!foundEnvID) { + free(process->ctid); + process->ctid = NULL; + } + + if(!foundVPid) { + process->vpid = process->super.pid; + } } #endif From 4a78f4bb928a4fd6b7b0c003ebdea279cf0d319f Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 3 Oct 2020 22:00:27 +0200 Subject: [PATCH 279/411] Some more locations for ARRAYSIZE --- darwin/Platform.c | 3 ++- dragonflybsd/DragonFlyBSDProcessList.c | 3 ++- dragonflybsd/Platform.c | 3 ++- freebsd/FreeBSDProcessList.c | 3 ++- freebsd/Platform.c | 3 ++- openbsd/OpenBSDProcessList.c | 3 ++- openbsd/Platform.c | 3 ++- solaris/Platform.c | 3 ++- unsupported/Platform.c | 3 ++- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/darwin/Platform.c b/darwin/Platform.c index 4d8ede322..99787a277 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -7,6 +7,7 @@ in the source distribution for its full text. */ #include "Platform.h" +#include "Macros.h" #include "CPUMeter.h" #include "MemoryMeter.h" #include "SwapMeter.h" @@ -63,7 +64,7 @@ const SignalItem Platform_signals[] = { { .name = "31 SIGUSR2", .number = 31 }, }; -const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); ProcessFieldData Process_fields[] = { [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 1c10a4124..87f16069a 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -9,6 +9,7 @@ in the source distribution for its full text. #include "ProcessList.h" #include "DragonFlyBSDProcessList.h" #include "DragonFlyBSDProcess.h" +#include "Macros.h" #include #include @@ -253,7 +254,7 @@ static inline void DragonFlyBSDProcessList_scanMemoryInfo(ProcessList* pl) { //pl->freeMem *= pageSizeKb; struct kvm_swap swap[16]; - int nswap = kvm_getswapinfo(dfpl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0); + int nswap = kvm_getswapinfo(dfpl->kd, swap, ARRAYSIZE(swap), 0); pl->totalSwap = 0; pl->usedSwap = 0; for (int i = 0; i < nswap; i++) { diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 21ebc40a8..6eb1e99c5 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -7,6 +7,7 @@ in the source distribution for its full text. */ #include "Platform.h" +#include "Macros.h" #include "Meter.h" #include "CPUMeter.h" #include "MemoryMeter.h" @@ -71,7 +72,7 @@ const SignalItem Platform_signals[] = { { .name = "33 SIGLIBRT", .number = 33 }, }; -const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); void Platform_setBindings(Htop_Action* keys) { (void) keys; diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index f9377a2d8..71f87e16e 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -11,6 +11,7 @@ in the source distribution for its full text. #include "FreeBSDProcess.h" #include "zfs/ZfsArcStats.h" #include "zfs/openzfs_sysctl.h" +#include "Macros.h" #include #include @@ -293,7 +294,7 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { //pl->freeMem *= pageSizeKb; struct kvm_swap swap[16]; - int nswap = kvm_getswapinfo(fpl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0); + int nswap = kvm_getswapinfo(fpl->kd, swap, ARRAYSIZE(swap), 0); pl->totalSwap = 0; pl->usedSwap = 0; for (int i = 0; i < nswap; i++) { diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 9c91de152..2288d2f21 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -6,6 +6,7 @@ in the source distribution for its full text. */ #include "Platform.h" +#include "Macros.h" #include "Meter.h" #include "CPUMeter.h" #include "MemoryMeter.h" @@ -72,7 +73,7 @@ const SignalItem Platform_signals[] = { { .name = "33 SIGLIBRT", .number = 33 }, }; -const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); void Platform_setBindings(Htop_Action* keys) { (void) keys; diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 9d1367e77..c3ba763af 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "ProcessList.h" #include "OpenBSDProcessList.h" #include "OpenBSDProcess.h" +#include "Macros.h" #include #include @@ -118,7 +119,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { pl->cachedMem *= PAGE_SIZE_KB; struct kvm_swap swap[16]; - int nswap = kvm_getswapinfo(opl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0); + int nswap = kvm_getswapinfo(opl->kd, swap, ARRAYSIZE(swap), 0); pl->totalSwap = 0; pl->usedSwap = 0; for (int i = 0; i < nswap; i++) { diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 02a821e7d..4c2ebdfb8 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -7,6 +7,7 @@ in the source distribution for its full text. */ #include "Platform.h" +#include "Macros.h" #include "Meter.h" #include "CPUMeter.h" #include "MemoryMeter.h" @@ -84,7 +85,7 @@ const SignalItem Platform_signals[] = { { .name = "32 SIGTHR", .number = 32 }, }; -const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); void Platform_setBindings(Htop_Action* keys) { (void) keys; diff --git a/solaris/Platform.c b/solaris/Platform.c index e1243bfa0..ef0d41237 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -8,6 +8,7 @@ in the source distribution for its full text. */ #include "Platform.h" +#include "Macros.h" #include "Meter.h" #include "CPUMeter.h" #include "MemoryMeter.h" @@ -83,7 +84,7 @@ const SignalItem Platform_signals[] = { { .name = "41 SIGINFO", .number = 41 }, }; -const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); ProcessField Platform_defaultFields[] = { PID, LWPID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 304989eef..b7fdf17db 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -9,6 +9,7 @@ in the source distribution for its full text. #include #include "Platform.h" +#include "Macros.h" #include "CPUMeter.h" #include "MemoryMeter.h" #include "SwapMeter.h" @@ -25,7 +26,7 @@ const SignalItem Platform_signals[] = { { .name = " 0 Cancel", .number = 0 }, }; -const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; From 32a2caa692ee2e2b26d77d00b60166fba87667fb Mon Sep 17 00:00:00 2001 From: ryenus Date: Thu, 8 Oct 2020 00:36:20 +0800 Subject: [PATCH 280/411] use 'w' for command wrapping as 'M' is already used since 'M' is already used for sort-by-memory, as with: keys['M'] = actionSortByMemory; reorder help info about shortcut keys --- Action.c | 4 ++-- htop.1.in | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Action.c b/Action.c index 106fbb039..4ea6fdfbc 100644 --- a/Action.c +++ b/Action.c @@ -423,8 +423,8 @@ static const struct { const char* key; const char* info; } helpRight[] = { { .key = " e: ", .info = "show process environment" }, { .key = " i: ", .info = "set IO priority" }, { .key = " l: ", .info = "list open files with lsof" }, - { .key = " M: ", .info = "show process command in multiple lines" }, { .key = " s: ", .info = "trace syscalls with strace" }, + { .key = " w: ", .info = "wrap process command in multiple lines" }, { .key = " F2 C S: ", .info = "setup" }, { .key = " F1 h: ", .info = "show this help screen" }, { .key = " F10 q: ", .info = "quit" }, @@ -595,5 +595,5 @@ void Action_setBindings(Htop_Action* keys) { keys['U'] = actionUntagAll; keys['c'] = actionTagAllChildren; keys['e'] = actionShowEnvScreen; - keys['M'] = actionShowCommandScreen; + keys['w'] = actionShowCommandScreen; } diff --git a/htop.1.in b/htop.1.in index 48e5cee55..cd5562b66 100644 --- a/htop.1.in +++ b/htop.1.in @@ -119,8 +119,9 @@ update of system calls issued by the process. Display open files for a process: if lsof(1) is installed, pressing this key will display the list of file descriptors opened by the process. .TP -.B M -Display the command line of the highlighted process in multiple lines. +.B w +Display the command line of the selected process in a separate screen, wrapped +onto multiple lines as needed. .TP .B F1, h, ? Go to the help screen From 41eea8a355d9f8935c2bcb25b4da83cf628f357b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 7 Oct 2020 19:02:15 +0200 Subject: [PATCH 281/411] Mark process argument of Process_isThread const --- InfoScreen.c | 2 +- InfoScreen.h | 4 ++-- Process.h | 2 +- darwin/DarwinProcess.c | 2 +- darwin/DarwinProcess.h | 2 +- dragonflybsd/DragonFlyBSDProcess.c | 4 ++-- dragonflybsd/DragonFlyBSDProcess.h | 2 +- freebsd/FreeBSDProcess.c | 4 ++-- freebsd/FreeBSDProcess.h | 2 +- linux/LinuxProcess.c | 2 +- linux/LinuxProcess.h | 4 ++-- openbsd/OpenBSDProcess.c | 2 +- openbsd/OpenBSDProcess.h | 2 +- solaris/SolarisProcess.c | 4 ++-- solaris/SolarisProcess.h | 2 +- unsupported/Platform.c | 2 +- unsupported/Platform.h | 2 +- 17 files changed, 22 insertions(+), 22 deletions(-) diff --git a/InfoScreen.c b/InfoScreen.c index 52117d0bf..ecde6d91e 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -20,7 +20,7 @@ static const char* const InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"}; static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27}; -InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, const char* panelHeader) { +InfoScreen* InfoScreen_init(InfoScreen* this, const Process* process, FunctionBar* bar, int height, const char* panelHeader) { this->process = process; if (!bar) { bar = FunctionBar_new(InfoScreenFunctions, InfoScreenKeys, InfoScreenEvents); diff --git a/InfoScreen.h b/InfoScreen.h index e5c58461b..79927c474 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -29,14 +29,14 @@ typedef struct InfoScreenClass_ { struct InfoScreen_ { Object super; - Process* process; + const Process* process; Panel* display; FunctionBar* bar; IncSet* inc; Vector* lines; }; -InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, const char* panelHeader); +InfoScreen* InfoScreen_init(InfoScreen* this, const Process* process, FunctionBar* bar, int height, const char* panelHeader); InfoScreen* InfoScreen_done(InfoScreen* this); diff --git a/Process.h b/Process.h index beca4f25c..664aecc72 100644 --- a/Process.h +++ b/Process.h @@ -116,7 +116,7 @@ typedef struct ProcessFieldData_ { void Process_writeField(Process* this, RichString* str, ProcessField field); long Process_compare(const void* v1, const void* v2); void Process_delete(Object* cast); -bool Process_isThread(Process* this); +bool Process_isThread(const Process* this); extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; extern char Process_pidFormat[20]; diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index d3af4788d..59853770a 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -45,7 +45,7 @@ void Process_delete(Object* cast) { free(this); } -bool Process_isThread(Process* this) { +bool Process_isThread(const Process* this) { (void) this; return false; } diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index 276795822..11dc2c3cb 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -26,7 +26,7 @@ DarwinProcess* DarwinProcess_new(Settings* settings); void Process_delete(Object* cast); -bool Process_isThread(Process* this); +bool Process_isThread(const Process* this); void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now); diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index df320e082..9c5e426e5 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -128,8 +128,8 @@ long DragonFlyBSDProcess_compare(const void* v1, const void* v2) { } } -bool Process_isThread(Process* this) { - DragonFlyBSDProcess* fp = (DragonFlyBSDProcess*) this; +bool Process_isThread(const Process* this) { + const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) this; if (fp->kernel == 1 ) return 1; diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h index b33f32b27..637dddb0f 100644 --- a/dragonflybsd/DragonFlyBSDProcess.h +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -41,6 +41,6 @@ void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField long DragonFlyBSDProcess_compare(const void* v1, const void* v2); -bool Process_isThread(Process* this); +bool Process_isThread(const Process* this); #endif diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 767f485b4..6548ff681 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -127,8 +127,8 @@ long FreeBSDProcess_compare(const void* v1, const void* v2) { } } -bool Process_isThread(Process* this) { - FreeBSDProcess* fp = (FreeBSDProcess*) this; +bool Process_isThread(const Process* this) { + const FreeBSDProcess* fp = (const FreeBSDProcess*) this; if (fp->kernel == 1 ) return 1; diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index 80dcaf659..f6fa8b3e2 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -39,6 +39,6 @@ void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel long FreeBSDProcess_compare(const void* v1, const void* v2); -bool Process_isThread(Process* this); +bool Process_isThread(const Process* this); #endif diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 5e661e03c..e6f78f9fb 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -389,6 +389,6 @@ long LinuxProcess_compare(const void* v1, const void* v2) { return (diff > 0) ? 1 : (diff < 0 ? -1 : 0); } -bool Process_isThread(Process* this) { +bool Process_isThread(const Process* this) { return (Process_isUserlandThread(this) || Process_isKernelThread(this)); } diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index c1eb0ed53..9227dd7f2 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -147,7 +147,7 @@ typedef struct LinuxProcess_ { char *secattr; } LinuxProcess; -#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread) +#define Process_isKernelThread(_process) (((const LinuxProcess*)(_process))->isKernelThread) #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) @@ -185,6 +185,6 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) long LinuxProcess_compare(const void* v1, const void* v2); -bool Process_isThread(Process* this); +bool Process_isThread(const Process* this); #endif diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 94ce48283..6b87f372e 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -209,6 +209,6 @@ long OpenBSDProcess_compare(const void* v1, const void* v2) { } } -bool Process_isThread(Process* this) { +bool Process_isThread(const Process* this) { return (Process_isKernelThread(this)); } diff --git a/openbsd/OpenBSDProcess.h b/openbsd/OpenBSDProcess.h index 13f172744..bd3659425 100644 --- a/openbsd/OpenBSDProcess.h +++ b/openbsd/OpenBSDProcess.h @@ -35,6 +35,6 @@ void OpenBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel long OpenBSDProcess_compare(const void* v1, const void* v2); -bool Process_isThread(Process* this); +bool Process_isThread(const Process* this); #endif diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index d0a75dfec..b796c96e1 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -150,8 +150,8 @@ long SolarisProcess_compare(const void* v1, const void* v2) { } } -bool Process_isThread(Process* this) { - SolarisProcess* fp = (SolarisProcess*) this; +bool Process_isThread(const Process* this) { + const SolarisProcess* fp = (const SolarisProcess*) this; if (fp->kernel == 1 ) { return 1; diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index 6ae383311..2a32f8c72 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -58,6 +58,6 @@ void SolarisProcess_writeField(Process* this, RichString* str, ProcessField fiel long SolarisProcess_compare(const void* v1, const void* v2); -bool Process_isThread(Process* this); +bool Process_isThread(const Process* this); #endif diff --git a/unsupported/Platform.c b/unsupported/Platform.c index b7fdf17db..6e8968f11 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -131,7 +131,7 @@ void Platform_setSwapValues(Meter* this) { (void) this; } -bool Process_isThread(Process* this) { +bool Process_isThread(const Process* this) { (void) this; return false; } diff --git a/unsupported/Platform.h b/unsupported/Platform.h index ce188afad..f24dcf4cd 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -43,7 +43,7 @@ void Platform_setMemoryValues(Meter* this); void Platform_setSwapValues(Meter* this); -bool Process_isThread(Process* this); +bool Process_isThread(const Process* this); char* Platform_getProcessEnv(pid_t pid); From f4439b1b60be6e0cb0bfeb9fbbcd9952f0d66120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 8 Oct 2020 16:20:34 +0200 Subject: [PATCH 282/411] Makefile sort correction --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 9bfe007a6..f4618eb67 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,7 +31,6 @@ myhtopsources = \ DateMeter.c \ DateTimeMeter.c \ DiskIOMeter.c \ - DiskIOMeter.h \ DisplayOptionsPanel.c \ EnvScreen.c \ FunctionBar.c \ @@ -82,6 +81,7 @@ myhtopheaders = \ CommandScreen.h \ DateMeter.h \ DateTimeMeter.h \ + DiskIOMeter.h \ DisplayOptionsPanel.h \ EnvScreen.h \ FunctionBar.h \ From e5fdb80c7d13d836ec244390976741dd99bc6535 Mon Sep 17 00:00:00 2001 From: Fynn Wulf Date: Thu, 8 Oct 2020 22:48:35 +0200 Subject: [PATCH 283/411] Fix Hashtable_put to allow storing the same pointer --- Hashtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hashtable.c b/Hashtable.c index d032ba77b..383b34a88 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -88,7 +88,7 @@ void Hashtable_put(Hashtable* this, unsigned int key, void* value) { this->items++; break; } else if ((*bucketPtr)->key == key) { - if (this->owner) + if (this->owner && (*bucketPtr)->value != value) free((*bucketPtr)->value); (*bucketPtr)->value = value; break; From 79ad39c718bfb2973d610c2d039a5024354e602f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 6 Oct 2020 12:28:11 +0200 Subject: [PATCH 284/411] Mark Object pointer to _display function const --- AffinityPanel.c | 4 ++-- CPUMeter.c | 4 ++-- CheckItem.c | 6 +++--- CheckItem.h | 2 +- DiskIOMeter.c | 2 +- ListItem.c | 4 ++-- LoadAverageMeter.c | 8 ++++---- MemoryMeter.c | 4 ++-- Meter.c | 5 ++--- Object.h | 8 ++++---- Process.c | 12 ++++++------ Process.h | 6 +++--- SwapMeter.c | 4 ++-- TasksMeter.c | 6 +++--- linux/PressureStallMeter.c | 4 ++-- zfs/ZfsArcMeter.c | 4 ++-- zfs/ZfsCompressedArcMeter.c | 6 +++--- 17 files changed, 44 insertions(+), 45 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index 127623c69..0cddd0792 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -44,8 +44,8 @@ static void MaskItem_delete(Object* cast) { free(this); } -static void MaskItem_display(Object* cast, RichString* out) { - MaskItem* this = (MaskItem*)cast; +static void MaskItem_display(const Object* cast, RichString* out) { + const MaskItem* this = (const MaskItem*)cast; assert (this != NULL); RichString_append(out, CRT_colors[CHECK_BOX], "["); if (this->value == 2) diff --git a/CPUMeter.c b/CPUMeter.c index 7ce6caf81..c1ccb12c4 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -66,9 +66,9 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { } } -static void CPUMeter_display(Object* cast, RichString* out) { +static void CPUMeter_display(const Object* cast, RichString* out) { char buffer[50]; - Meter* this = (Meter*)cast; + const Meter* this = (const Meter*)cast; RichString_prune(out); if (this->param > this->pl->cpuCount) { RichString_append(out, CRT_colors[METER_TEXT], "absent"); diff --git a/CheckItem.c b/CheckItem.c index 09e42ee66..d1f119633 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -21,8 +21,8 @@ static void CheckItem_delete(Object* cast) { free(this); } -static void CheckItem_display(Object* cast, RichString* out) { - CheckItem* this = (CheckItem*)cast; +static void CheckItem_display(const Object* cast, RichString* out) { + const CheckItem* this = (const CheckItem*)cast; assert (this != NULL); RichString_write(out, CRT_colors[CHECK_BOX], "["); if (CheckItem_get(this)) @@ -61,7 +61,7 @@ void CheckItem_set(CheckItem* this, bool value) { this->value = value; } -bool CheckItem_get(CheckItem* this) { +bool CheckItem_get(const CheckItem* this) { if (this->ref) return *(this->ref); else diff --git a/CheckItem.h b/CheckItem.h index 168efdcc0..b4300db40 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -24,6 +24,6 @@ CheckItem* CheckItem_newByVal(char* text, bool value); void CheckItem_set(CheckItem* this, bool value); -bool CheckItem_get(CheckItem* this); +bool CheckItem_get(const CheckItem* this); #endif diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 781d9bb6a..6baca32c5 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -59,7 +59,7 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) { snprintf(buffer, len, "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff); } -static void DIskIOMeter_display(ATTR_UNUSED Object* cast, RichString* out) { +static void DIskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { char buffer[16]; int color = cached_utilisation_diff > 40.0 ? DISKIO_UTIL_HIGH : METER_VALUE; diff --git a/ListItem.c b/ListItem.c index e1dcd52d7..d9d36f89c 100644 --- a/ListItem.c +++ b/ListItem.c @@ -22,8 +22,8 @@ static void ListItem_delete(Object* cast) { free(this); } -static void ListItem_display(Object* cast, RichString* out) { - ListItem* const this = (ListItem*)cast; +static void ListItem_display(const Object* cast, RichString* out) { + const ListItem* const this = (const ListItem*)cast; assert (this != NULL); /* int len = strlen(this->value)+1; diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index d2fa582a6..208b7e95b 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -26,8 +26,8 @@ static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) { xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]); } -static void LoadAverageMeter_display(Object* cast, RichString* out) { - Meter* this = (Meter*)cast; +static void LoadAverageMeter_display(const Object* cast, RichString* out) { + const Meter* this = (const Meter*)cast; char buffer[20]; xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]); RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer); @@ -46,8 +46,8 @@ static void LoadMeter_updateValues(Meter* this, char* buffer, int size) { xSnprintf(buffer, size, "%.2f", this->values[0]); } -static void LoadMeter_display(Object* cast, RichString* out) { - Meter* this = (Meter*)cast; +static void LoadMeter_display(const Object* cast, RichString* out) { + const Meter* this = (const Meter*)cast; char buffer[20]; xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]); RichString_write(out, CRT_colors[LOAD], buffer); diff --git a/MemoryMeter.c b/MemoryMeter.c index fa0e09abb..311f17910 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -36,9 +36,9 @@ static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) { } } -static void MemoryMeter_display(Object* cast, RichString* out) { +static void MemoryMeter_display(const Object* cast, RichString* out) { char buffer[50]; - Meter* this = (Meter*)cast; + const Meter* this = (const Meter*)cast; RichString_write(out, CRT_colors[METER_TEXT], ":"); Meter_humanUnit(buffer, this->total, 50); RichString_append(out, CRT_colors[METER_VALUE], buffer); diff --git a/Meter.c b/Meter.c index 15be309f9..c8cd19eba 100644 --- a/Meter.c +++ b/Meter.c @@ -92,7 +92,7 @@ void Meter_setCaption(Meter* this, const char* caption) { this->caption = xStrdup(caption); } -static inline void Meter_displayBuffer(Meter* this, char* buffer, RichString* out) { +static inline void Meter_displayBuffer(const Meter* this, const char* buffer, RichString* out) { if (Object_displayFn(this)) { Object_display(this, out); } else { @@ -428,8 +428,7 @@ static void BlankMeter_updateValues(Meter* this, char* buffer, int size) { } } -static void BlankMeter_display(Object* cast, RichString* out) { - (void) cast; +static void BlankMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { RichString_prune(out); } diff --git a/Object.h b/Object.h index 0d0e00362..36ab2544e 100644 --- a/Object.h +++ b/Object.h @@ -14,16 +14,16 @@ in the source distribution for its full text. typedef struct Object_ Object; -typedef void(*Object_Display)(Object*, RichString*); +typedef void(*Object_Display)(const Object*, RichString*); typedef long(*Object_Compare)(const void*, const void*); typedef void(*Object_Delete)(Object*); -#define Object_getClass(obj_) ((Object*)(obj_))->klass -#define Object_setClass(obj_, class_) Object_getClass(obj_) = (const ObjectClass*) class_ +#define Object_getClass(obj_) ((const Object*)(obj_))->klass +#define Object_setClass(obj_, class_) (((Object*)(obj_))->klass = (const ObjectClass*) class_) #define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_)) #define Object_displayFn(obj_) Object_getClass(obj_)->display -#define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_) +#define Object_display(obj_, str_) Object_getClass(obj_)->display((const Object*)(obj_), str_) #define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_) #define Class(class_) ((const ObjectClass*)(&(class_ ## _class))) diff --git a/Process.c b/Process.c index ea703e4b2..2d5ffb4fe 100644 --- a/Process.c +++ b/Process.c @@ -181,9 +181,9 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths) { } } -static inline void Process_writeCommand(Process* this, int attr, int baseattr, RichString* str) { +static inline void Process_writeCommand(const Process* this, int attr, int baseattr, RichString* str) { int start = RichString_size(str), finish = 0; - char* comm = this->comm; + const char* comm = this->comm; if (this->settings->highlightBaseName || !this->settings->showProgramPath) { int i, basename = 0; @@ -240,7 +240,7 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c } } -void Process_writeField(Process* this, RichString* str, ProcessField field) { +void Process_writeField(const Process* this, RichString* str, ProcessField field) { char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; int baseattr = CRT_colors[PROCESS_BASENAME]; @@ -366,9 +366,9 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) { RichString_append(str, attr, buffer); } -void Process_display(Object* cast, RichString* out) { - Process* this = (Process*) cast; - ProcessField* fields = this->settings->fields; +void Process_display(const Object* cast, RichString* out) { + const Process* this = (const Process*) cast; + const ProcessField* fields = this->settings->fields; RichString_prune(out); for (int i = 0; fields[i]; i++) As_Process(this)->writeField(this, out, fields[i]); diff --git a/Process.h b/Process.h index 664aecc72..7e1bda681 100644 --- a/Process.h +++ b/Process.h @@ -113,7 +113,7 @@ typedef struct ProcessFieldData_ { } ProcessFieldData; // Implemented in platform-specific code: -void Process_writeField(Process* this, RichString* str, ProcessField field); +void Process_writeField(const Process* this, RichString* str, ProcessField field); long Process_compare(const void* v1, const void* v2); void Process_delete(Object* cast); bool Process_isThread(const Process* this); @@ -122,7 +122,7 @@ extern ProcessPidColumn Process_pidColumns[]; extern char Process_pidFormat[20]; typedef Process*(*Process_New)(struct Settings_*); -typedef void (*Process_WriteField)(Process*, RichString*, ProcessField); +typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField); typedef struct ProcessClass_ { const ObjectClass super; @@ -158,7 +158,7 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths); void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring); -void Process_display(Object* cast, RichString* out); +void Process_display(const Object* cast, RichString* out); void Process_done(Process* this); diff --git a/SwapMeter.c b/SwapMeter.c index e754bbe63..fc4e6b289 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -34,9 +34,9 @@ static void SwapMeter_updateValues(Meter* this, char* buffer, int size) { } } -static void SwapMeter_display(Object* cast, RichString* out) { +static void SwapMeter_display(const Object* cast, RichString* out) { char buffer[50]; - Meter* this = (Meter*)cast; + const Meter* this = (const Meter*)cast; RichString_write(out, CRT_colors[METER_TEXT], ":"); Meter_humanUnit(buffer, this->total, 50); RichString_append(out, CRT_colors[METER_VALUE], buffer); diff --git a/TasksMeter.c b/TasksMeter.c index bf289e99e..fb3767c55 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -33,9 +33,9 @@ static void TasksMeter_updateValues(Meter* this, char* buffer, int len) { xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total); } -static void TasksMeter_display(Object* cast, RichString* out) { - Meter* this = (Meter*)cast; - Settings* settings = this->pl->settings; +static void TasksMeter_display(const Object* cast, RichString* out) { + const Meter* this = (const Meter*)cast; + const Settings* settings = this->pl->settings; char buffer[20]; int processes = (int) this->values[2]; diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c index 577692e3e..a54b4375b 100644 --- a/linux/PressureStallMeter.c +++ b/linux/PressureStallMeter.c @@ -41,8 +41,8 @@ static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]); } -static void PressureStallMeter_display(Object* cast, RichString* out) { - Meter* this = (Meter*)cast; +static void PressureStallMeter_display(const Object* cast, RichString* out) { + const Meter* this = (const Meter*)cast; char buffer[20]; xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]); RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer); diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index d52605c6c..6301a9c43 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -55,9 +55,9 @@ static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) { } } -static void ZfsArcMeter_display(Object* cast, RichString* out) { +static void ZfsArcMeter_display(const Object* cast, RichString* out) { char buffer[50]; - Meter* this = (Meter*)cast; + const Meter* this = (const Meter*)cast; if (this->values[5] > 0) { Meter_humanUnit(buffer, this->total, 50); diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index 360877ad5..ccf57203a 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -38,7 +38,7 @@ void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats) { } } -static void ZfsCompressedArcMeter_printRatioString(Meter* this, char* buffer, int size) { +static void ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buffer, int size) { xSnprintf(buffer, size, "%.2f:1", this->total/this->values[0]); } @@ -48,9 +48,9 @@ static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int si ZfsCompressedArcMeter_printRatioString(this, buffer, size); } -static void ZfsCompressedArcMeter_display(Object* cast, RichString* out) { +static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) { char buffer[50]; - Meter* this = (Meter*)cast; + const Meter* this = (const Meter*)cast; if (this->values[0] > 0) { Meter_humanUnit(buffer, this->total, 50); From f8b9ced93f258f1b4b6071f08a54c6f0f9233b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 7 Oct 2020 19:02:23 +0200 Subject: [PATCH 285/411] OpenFilesScreen update - Remove local types and function from header file - Reduce OpenFiles_Data to neccessary size - Print file access mode (r/w/u) - Fix memory leak on consecutive items without an intermediate file item: ==15257==ERROR: LeakSanitizer: detected memory leaks Direct leak of 120 byte(s) in 12 object(s) allocated from: #0 0x48c864 in strdup (htop/htop+0x48c864) #1 0x542f68 in xStrdup htop/XAlloc.c:71:17 #2 0x50e225 in OpenFilesScreen_getProcessData htop/OpenFilesScreen.c:112:25 #3 0x50cd17 in OpenFilesScreen_scan htop/OpenFilesScreen.c:141:35 #4 0x4fd3eb in InfoScreen_run htop/InfoScreen.c:81:35 #5 0x4d58bb in actionLsof htop/Action.c:361:4 #6 0x501766 in MainPanel_eventHandler htop/MainPanel.c:80:19 #7 0x5289fa in ScreenManager_run htop/ScreenManager.c:227:19 #8 0x4f748e in main htop/htop.c:300:4 #9 0x7ff73e0d8cc9 in __libc_start_main csu/../csu/libc-start.c:308:16 SUMMARY: AddressSanitizer: 120 byte(s) leaked in 12 allocation(s). --- OpenFilesScreen.c | 129 +++++++++++++++++++++++++++++++++++----------- OpenFilesScreen.h | 21 +------- 2 files changed, 101 insertions(+), 49 deletions(-) diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 7c0acebe7..1973cc45c 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -24,30 +24,63 @@ in the source distribution for its full text. #include -const InfoScreenClass OpenFilesScreen_class = { - .super = { - .extends = Class(Object), - .delete = OpenFilesScreen_delete - }, - .scan = OpenFilesScreen_scan, - .draw = OpenFilesScreen_draw -}; +typedef struct OpenFiles_Data_ { + char* data[7]; +} OpenFiles_Data; + +typedef struct OpenFiles_ProcessData_ { + OpenFiles_Data data; + int error; + struct OpenFiles_FileData_* files; +} OpenFiles_ProcessData; + +typedef struct OpenFiles_FileData_ { + OpenFiles_Data data; + struct OpenFiles_FileData_* next; +} OpenFiles_FileData; + +static size_t getIndexForType(char type) { + switch (type) { + case 'f': + return 0; + case 'a': + return 1; + case 'D': + return 2; + case 'i': + return 3; + case 'n': + return 4; + case 's': + return 5; + case 't': + return 6; + } + + /* should never reach here */ + abort(); +} + +static const char* getDataForType(const OpenFiles_Data* data, char type) { + size_t index = getIndexForType(type); + return data->data[index] ? data->data[index] : ""; +} -OpenFilesScreen* OpenFilesScreen_new(Process* process) { +OpenFilesScreen* OpenFilesScreen_new(const Process* process) { OpenFilesScreen* this = xMalloc(sizeof(OpenFilesScreen)); Object_setClass(this, Class(OpenFilesScreen)); if (Process_isThread(process)) this->pid = process->tgid; else this->pid = process->pid; - return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " FD TYPE DEVICE SIZE NODE NAME"); + return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " FD TYPE MODE DEVICE SIZE NODE NAME"); } void OpenFilesScreen_delete(Object* this) { free(InfoScreen_done((InfoScreen*)this)); } -void OpenFilesScreen_draw(InfoScreen* this) { +static void OpenFilesScreen_draw(InfoScreen* this) { InfoScreen_drawTitled(this, "Snapshot of files open in process %d - %s", ((OpenFilesScreen*)this)->pid, this->process->comm); } @@ -99,7 +132,9 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { } unsigned char cmd = line[0]; - if (cmd == 'f') { + switch (cmd) { + case 'f': /* file descriptor */ + { OpenFiles_FileData* nextFile = xCalloc(1, sizeof(OpenFiles_FileData)); if (fdata == NULL) { pdata->files = nextFile; @@ -108,8 +143,35 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { } fdata = nextFile; item = &(fdata->data); + } /* FALLTHRU */ + case 'a': /* file access mode */ + case 'D': /* file's major/minor device number */ + case 'i': /* file's inode number */ + case 'n': /* file name, comment, Internet address */ + case 's': /* file's size */ + case 't': /* file's type */ + { + size_t index = getIndexForType(cmd); + free(item->data[index]); + item->data[index] = xStrdup(line + 1); + break; + } + case 'c': /* process command name */ + case 'd': /* file's device character code */ + case 'g': /* process group ID */ + case 'G': /* file flags */ + case 'k': /* link count */ + case 'l': /* file's lock status */ + case 'L': /* process login name */ + case 'o': /* file's offset */ + case 'p': /* process ID */ + case 'P': /* protocol name */ + case 'R': /* parent process ID */ + case 'T': /* TCP/TPI information, identified by prefixes */ + case 'u': /* process user ID */ + /* ignore */ + break; } - item->data[cmd] = xStrdup(line + 1); free(line); } fclose(fd); @@ -128,13 +190,12 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { return pdata; } -static inline void OpenFiles_Data_clear(OpenFiles_Data* data) { - for (int i = 0; i < 255; i++) - if (data->data[i]) - free(data->data[i]); +static void OpenFiles_Data_clear(OpenFiles_Data* data) { + for (size_t i = 0; i < ARRAYSIZE(data->data); i++) + free(data->data[i]); } -void OpenFilesScreen_scan(InfoScreen* this) { +static void OpenFilesScreen_scan(InfoScreen* this) { Panel* panel = this->display; int idx = Panel_getSelectedIndex(panel); Panel_prune(panel); @@ -146,19 +207,20 @@ void OpenFilesScreen_scan(InfoScreen* this) { } else { OpenFiles_FileData* fdata = pdata->files; while (fdata) { - char** data = fdata->data.data; - int lenN = data['n'] ? strlen(data['n']) : 0; - int sizeEntry = 5 + 7 + 10 + 10 + 10 + lenN + 5 /*spaces*/ + 1 /*null*/; + OpenFiles_Data* data = &fdata->data; + size_t lenN = strlen(getDataForType(data, 'n')); + size_t sizeEntry = 5 + 7 + 4 + 10 + 10 + 10 + lenN + 7 /*spaces*/ + 1 /*null*/; char entry[sizeEntry]; - xSnprintf(entry, sizeEntry, "%5.5s %7.7s %10.10s %10.10s %10.10s %s", - data['f'] ? data['f'] : "", - data['t'] ? data['t'] : "", - data['D'] ? data['D'] : "", - data['s'] ? data['s'] : "", - data['i'] ? data['i'] : "", - data['n'] ? data['n'] : ""); + xSnprintf(entry, sizeof(entry), "%5.5s %-7.7s %-4.4s %-10.10s %10.10s %10.10s %s", + getDataForType(data, 'f'), + getDataForType(data, 't'), + getDataForType(data, 'a'), + getDataForType(data, 'D'), + getDataForType(data, 's'), + getDataForType(data, 'i'), + getDataForType(data, 'n')); InfoScreen_addLine(this, entry); - OpenFiles_Data_clear(&fdata->data); + OpenFiles_Data_clear(data); OpenFiles_FileData* old = fdata; fdata = fdata->next; free(old); @@ -170,3 +232,12 @@ void OpenFilesScreen_scan(InfoScreen* this) { Vector_insertionSort(panel->items); Panel_setSelected(panel, idx); } + +const InfoScreenClass OpenFilesScreen_class = { + .super = { + .extends = Class(Object), + .delete = OpenFilesScreen_delete + }, + .scan = OpenFilesScreen_scan, + .draw = OpenFilesScreen_draw +}; diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index 9a12dcd0d..04a8e3956 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -9,21 +9,6 @@ in the source distribution for its full text. #include "InfoScreen.h" -typedef struct OpenFiles_Data_ { - char* data[256]; -} OpenFiles_Data; - -typedef struct OpenFiles_ProcessData_ { - OpenFiles_Data data; - int error; - struct OpenFiles_FileData_* files; -} OpenFiles_ProcessData; - -typedef struct OpenFiles_FileData_ { - OpenFiles_Data data; - struct OpenFiles_FileData_* next; -} OpenFiles_FileData; - typedef struct OpenFilesScreen_ { InfoScreen super; pid_t pid; @@ -31,12 +16,8 @@ typedef struct OpenFilesScreen_ { extern const InfoScreenClass OpenFilesScreen_class; -OpenFilesScreen* OpenFilesScreen_new(Process* process); +OpenFilesScreen* OpenFilesScreen_new(const Process* process); void OpenFilesScreen_delete(Object* this); -void OpenFilesScreen_draw(InfoScreen* this); - -void OpenFilesScreen_scan(InfoScreen* this); - #endif From 55eafd3b39eabdf60b5196d8c728b6eaf190650d Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 11 Oct 2020 14:21:59 +0200 Subject: [PATCH 286/411] Add conf*/ and callgrind.out.* to list of ignored files --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index f94f3f52e..3d522b065 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ htop *.h.gch */.dirstamp +# automake/autoconf related files .deps/ Makefile Makefile.in @@ -24,6 +25,7 @@ INSTALL aclocal.m4 autom4te.cache/ compile +conf*/ config.guess config.h config.h.in @@ -40,3 +42,6 @@ ltmain.sh m4/ missing stamp-h1 + +# files related to valgrind/callgrind +callgrind.out.* From fc301b74473f2dc87dca6a338ac17126a058f68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 7 Oct 2020 11:02:13 +0200 Subject: [PATCH 287/411] Compress size of default FunctionBar --- MainPanel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MainPanel.c b/MainPanel.c index 604749a90..2c89a073d 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -13,7 +13,7 @@ in the source distribution for its full text. #include -static const char* const MainFunctions[] = {"Help ", "Setup ", "Search ", "Filter ", "Tree ", "SortBy ", "Nice - ", "Nice + ", "Kill ", "Quit ", NULL}; +static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL}; void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) { FunctionBar* bar = MainPanel_getFunctionBar(this); From b47bc667a254c1b1a8d6b5a635ca73f6c91c2e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 15:14:54 +0200 Subject: [PATCH 288/411] Add key to pause process list updates --- Action.c | 29 +++++++++++++++++++---------- Action.h | 1 + AffinityPanel.c | 2 +- AvailableMetersPanel.c | 2 +- CRT.c | 8 +++++++- CRT.h | 1 + ColorsPanel.c | 2 +- FunctionBar.c | 35 +++++++++++++++++++++++++++++------ FunctionBar.h | 6 ++++-- IncSet.c | 19 ++++++++++--------- IncSet.h | 2 +- MainPanel.c | 2 ++ MetersPanel.c | 2 +- ScreenManager.c | 26 ++++++++++++++++---------- ScreenManager.h | 6 ++++-- htop.1.in | 3 +++ htop.c | 3 ++- 17 files changed, 103 insertions(+), 46 deletions(-) diff --git a/Action.c b/Action.c index 4ea6fdfbc..c4d71479d 100644 --- a/Action.c +++ b/Action.c @@ -37,7 +37,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) Settings* settings = st->settings; int y = panel->y; - ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, false); + ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, st, false); scr->allowFocusChange = false; ScreenManager_add(scr, list, x - 1); ScreenManager_add(scr, panel, -1); @@ -73,17 +73,17 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) // ---------------------------------------- -static void Action_runSetup(Settings* settings, Header* header, ProcessList* pl) { - ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true); - CategoriesPanel* panelCategories = CategoriesPanel_new(scr, settings, header, pl); +static void Action_runSetup(State* st) { + ScreenManager* scr = ScreenManager_new(0, st->header->height, 0, -1, HORIZONTAL, st->header, st->settings, st, true); + CategoriesPanel* panelCategories = CategoriesPanel_new(scr, st->settings, st->header, st->pl); ScreenManager_add(scr, (Panel*) panelCategories, 16); CategoriesPanel_makeMetersPage(panelCategories); Panel* panelFocus; int ch; ScreenManager_run(scr, &panelFocus, &ch); ScreenManager_delete(scr); - if (settings->changed) { - Header_writeBackToSettings(header); + if (st->settings->changed) { + Header_writeBackToSettings(st->header); } } @@ -168,6 +168,8 @@ static Htop_Reaction sortBy(State* st) { reaction |= Action_setSortKey(st->settings, field->key); } Object_delete(sortPanel); + if (st->pauseProcessUpdate) + ProcessList_sort(st->pl); return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; } @@ -346,7 +348,7 @@ Htop_Reaction Action_follow(State* st) { } static Htop_Reaction actionSetup(State* st) { - Action_runSetup(st->settings, st->header, st->pl); + Action_runSetup(st); // TODO: shouldn't need this, colors should be dynamic int headerHeight = Header_calculateHeight(st->header); Panel_move(st->panel, 0, headerHeight); @@ -392,6 +394,11 @@ static Htop_Reaction actionRedraw(ATTR_UNUSED State *st) { return HTOP_REFRESH | HTOP_REDRAW_BAR; } +static Htop_Reaction actionTogglePauseProcessUpdate(State *st) { + st->pauseProcessUpdate = !st->pauseProcessUpdate; + return HTOP_REFRESH | HTOP_REDRAW_BAR; +} + static const struct { const char* key; const char* info; } helpLeft[] = { { .key = " Arrows: ", .info = "scroll process list" }, { .key = " Digits: ", .info = "incremental PID search" }, @@ -399,6 +406,7 @@ static const struct { const char* key; const char* info; } helpLeft[] = { { .key = " F4 \\: ",.info = "incremental name filtering" }, { .key = " F5 t: ", .info = "tree view" }, { .key = " p: ", .info = "toggle program path" }, + { .key = " Z: ", .info = "pause/resume process updates" }, { .key = " u: ", .info = "show processes of a single user" }, { .key = " H: ", .info = "hide/show user process threads" }, { .key = " K: ", .info = "hide/show kernel threads" }, @@ -491,12 +499,12 @@ static Htop_Reaction actionHelp(State* st) { for (int i = 0; helpLeft[i].key; i++) { mvaddstr(9+i, 0, helpLeft[i].key); } for (int i = 0; helpRight[i].key; i++) { mvaddstr(9+i, 40, helpRight[i].key); } attrset(CRT_colors[PROCESS_THREAD]); - mvaddstr(16, 32, "threads"); - mvaddstr(17, 26, "threads"); + mvaddstr(17, 32, "threads"); + mvaddstr(18, 26, "threads"); attrset(CRT_colors[DEFAULT_COLOR]); attrset(CRT_colors[HELP_BOLD]); - mvaddstr(23,0, "Press any key to return."); + mvaddstr(24,0, "Press any key to return."); attrset(CRT_colors[DEFAULT_COLOR]); refresh(); CRT_readKey(); @@ -596,4 +604,5 @@ void Action_setBindings(Htop_Action* keys) { keys['c'] = actionTagAllChildren; keys['e'] = actionShowEnvScreen; keys['w'] = actionShowCommandScreen; + keys['Z'] = actionTogglePauseProcessUpdate; } diff --git a/Action.h b/Action.h index 4f85b4817..40300ed48 100644 --- a/Action.h +++ b/Action.h @@ -30,6 +30,7 @@ typedef struct State_ { ProcessList* pl; Panel* panel; Header* header; + bool pauseProcessUpdate; } State; typedef Htop_Reaction (*Htop_Action)(State* st); diff --git a/AffinityPanel.c b/AffinityPanel.c index 0cddd0792..82ac12e5d 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -160,7 +160,7 @@ static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) { Panel* super = (Panel*) this; FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : ""); - FunctionBar_draw(super->currentBar, NULL); + FunctionBar_draw(super->currentBar); int oldSelected = Panel_getSelectedIndex(super); Panel_prune(super); diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index 812d1f3d9..b51a9e9f4 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -29,7 +29,7 @@ static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, c Panel_add(panel, (Object*) Meter_toListItem(meter, false)); Panel_setSelected(panel, Panel_size(panel) - 1); MetersPanel_setMoving((MetersPanel*)panel, true); - FunctionBar_draw(panel->currentBar, NULL); + FunctionBar_draw(panel->currentBar); } static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { diff --git a/CRT.c b/CRT.c index a9f995454..9159450b9 100644 --- a/CRT.c +++ b/CRT.c @@ -87,6 +87,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White), [FAILED_SEARCH] = ColorPair(Red,Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), [UPTIME] = A_BOLD | ColorPair(Cyan,Black), [BATTERY] = A_BOLD | ColorPair(Cyan,Black), [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), @@ -162,6 +163,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PANEL_SELECTION_FOLLOW] = A_REVERSE, [PANEL_SELECTION_UNFOCUS] = A_BOLD, [FAILED_SEARCH] = A_REVERSE | A_BOLD, + [PAUSED] = A_BOLD | A_REVERSE, [UPTIME] = A_BOLD, [BATTERY] = A_BOLD, [LARGE_NUMBER] = A_BOLD, @@ -237,6 +239,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,White), [FAILED_SEARCH] = ColorPair(Red,Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), [UPTIME] = ColorPair(Yellow,White), [BATTERY] = ColorPair(Yellow,White), [LARGE_NUMBER] = ColorPair(Red,White), @@ -312,6 +315,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,Black), [FAILED_SEARCH] = ColorPair(Red,Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), [UPTIME] = ColorPair(Yellow,Black), [BATTERY] = ColorPair(Yellow,Black), [LARGE_NUMBER] = ColorPair(Red,Black), @@ -387,6 +391,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow,Blue), [FAILED_SEARCH] = ColorPair(Red,Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), [UPTIME] = A_BOLD | ColorPair(Yellow,Blue), [BATTERY] = A_BOLD | ColorPair(Yellow,Blue), [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Blue), @@ -461,7 +466,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White), - [FAILED_SEARCH] = ColorPair(Red,Cyan), + [FAILED_SEARCH] = ColorPair(Red,Green), + [PAUSED] = A_BOLD | ColorPair(Yellow,Green), [UPTIME] = ColorPair(Green,Black), [BATTERY] = ColorPair(Green,Black), [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), diff --git a/CRT.h b/CRT.h index e729fb3c9..629a80976 100644 --- a/CRT.h +++ b/CRT.h @@ -43,6 +43,7 @@ typedef enum ColorElements_ { FUNCTION_BAR, FUNCTION_KEY, FAILED_SEARCH, + PAUSED, PANEL_HEADER_FOCUS, PANEL_HEADER_UNFOCUS, PANEL_SELECTION_FOCUS, diff --git a/ColorsPanel.c b/ColorsPanel.c index 75d3e6548..917be98cf 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -68,7 +68,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) { clear(); Panel* menu = (Panel*) Vector_get(this->scr->panels, 0); Header_draw(header); - FunctionBar_draw(super->currentBar, NULL); + FunctionBar_draw(super->currentBar); RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]); RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]); ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); diff --git a/FunctionBar.c b/FunctionBar.c index df1fab8f4..c67e613c3 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -24,6 +24,8 @@ static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_ static const char* const FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL}; static const int FunctionBar_EnterEscEvents[] = {13, 27}; +static int currentLen = 0; + FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) { const char* functions[] = {enter, esc, NULL}; return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents); @@ -53,7 +55,7 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke this->staticData = true; this->keys.constKeys = FunctionBar_FKeys; this->events = FunctionBar_FEvents; - this->size = 10; + this->size = ARRAYSIZE(FunctionBar_FEvents); } return this; } @@ -83,11 +85,11 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) { } } -void FunctionBar_draw(const FunctionBar* this, char* buffer) { - FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]); +void FunctionBar_draw(const FunctionBar* this) { + FunctionBar_drawExtra(this, NULL, -1, false); } -void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) { +void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor) { attrset(CRT_colors[FUNCTION_BAR]); mvhline(LINES-1, 0, ' ', COLS); int x = 0; @@ -99,15 +101,36 @@ void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) { mvaddstr(LINES-1, x, this->functions[i]); x += strlen(this->functions[i]); } + if (buffer) { - attrset(attr); + if (attr == -1) + attrset(CRT_colors[FUNCTION_BAR]); + else + attrset(attr); mvaddstr(LINES-1, x, buffer); - CRT_cursorX = x + strlen(buffer); + attrset(CRT_colors[RESET_COLOR]); + x += strlen(buffer); + } + + if (setCursor) { + CRT_cursorX = x; curs_set(1); } else { curs_set(0); } + + currentLen = x; +} + +void FunctionBar_append(const char* buffer, int attr) { + if (attr == -1) + attrset(CRT_colors[FUNCTION_BAR]); + else + attrset(attr); + mvaddstr(LINES-1, currentLen, buffer); attrset(CRT_colors[RESET_COLOR]); + + currentLen += strlen(buffer); } int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) { diff --git a/FunctionBar.h b/FunctionBar.h index c650c1a40..925e323bb 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -28,9 +28,11 @@ void FunctionBar_delete(FunctionBar* this); void FunctionBar_setLabel(FunctionBar* this, int event, const char* text); -void FunctionBar_draw(const FunctionBar* this, char* buffer); +void FunctionBar_draw(const FunctionBar* this); -void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr); +void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor); + +void FunctionBar_append(const char* buffer, int attr); int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos); diff --git a/IncSet.c b/IncSet.c index 3e3a1b998..9dda3ce1e 100644 --- a/IncSet.c +++ b/IncSet.c @@ -95,10 +95,11 @@ static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa break; } } - if (found) - FunctionBar_draw(mode->bar, mode->buffer); - else - FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]); + + FunctionBar_drawExtra(mode->bar, + mode->buffer, + found ? -1 : CRT_colors[FAILED_SEARCH], + true); return found; } @@ -177,7 +178,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue } this->active = NULL; Panel_setDefaultBar(panel); - FunctionBar_draw(this->defaultBar, NULL); + FunctionBar_draw(this->defaultBar); doSearch = false; } if (doSearch) { @@ -198,15 +199,15 @@ const char* IncSet_getListItemValue(Panel* panel, int i) { void IncSet_activate(IncSet* this, IncType type, Panel* panel) { this->active = &(this->modes[type]); - FunctionBar_draw(this->active->bar, this->active->buffer); + FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true); panel->currentBar = this->active->bar; } -void IncSet_drawBar(IncSet* this) { +void IncSet_drawBar(const IncSet* this) { if (this->active) { - FunctionBar_draw(this->active->bar, this->active->buffer); + FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true); } else { - FunctionBar_draw(this->defaultBar, NULL); + FunctionBar_draw(this->defaultBar); } } diff --git a/IncSet.h b/IncSet.h index 30b63665e..f05897473 100644 --- a/IncSet.h +++ b/IncSet.h @@ -54,7 +54,7 @@ const char* IncSet_getListItemValue(Panel* panel, int i); void IncSet_activate(IncSet* this, IncType type, Panel* panel); -void IncSet_drawBar(IncSet* this); +void IncSet_drawBar(const IncSet* this); int IncSet_synthesizeEvent(IncSet* this, int x); diff --git a/MainPanel.c b/MainPanel.c index 2c89a073d..48d869fff 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -92,6 +92,8 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { if (reaction & HTOP_REDRAW_BAR) { MainPanel_updateTreeFunctions(this, this->state->settings->treeView); IncSet_drawBar(this->inc); + if (this->state->pauseProcessUpdate) + FunctionBar_append("PAUSED", CRT_colors[PAUSED]); } if (reaction & HTOP_UPDATE_PANELHDR) { ProcessList_printHeader(this->state->pl, Panel_getHeader(super)); diff --git a/MetersPanel.c b/MetersPanel.c index 36cc8f451..89c54e0b1 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -55,7 +55,7 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) { Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOLLOW]); super->currentBar = Meters_movingBar; } - FunctionBar_draw(this->super.currentBar, NULL); + FunctionBar_draw(this->super.currentBar); } static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) { diff --git a/ScreenManager.c b/ScreenManager.c index 91ad47f83..4766e069a 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -6,10 +6,12 @@ in the source distribution for its full text. */ #include "ScreenManager.h" -#include "ProcessList.h" -#include "Object.h" #include "CRT.h" +#include "MainPanel.h" +#include "Object.h" +#include "ProcessList.h" + #include #include @@ -17,7 +19,7 @@ in the source distribution for its full text. #include -ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, bool owner) { +ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, const State* state, bool owner) { ScreenManager* this; this = xMalloc(sizeof(ScreenManager)); this->x1 = x1; @@ -29,6 +31,7 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori this->panelCount = 0; this->header = header; this->settings = settings; + this->state = state; this->owner = owner; this->allowFocusChange = true; return this; @@ -101,7 +104,7 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi *timedOut = (newTime - *oldTime > this->settings->delay); *rescan = *rescan || *timedOut; if (newTime < *oldTime) *rescan = true; // clock was adjusted? - if (*rescan) { + if (*rescan && !this->state->pauseProcessUpdate) { *oldTime = newTime; ProcessList_scan(pl); if (*sortTimeout == 0 || this->settings->treeView) { @@ -128,8 +131,11 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) { } } -static Panel* setCurrentPanel(Panel* panel) { - FunctionBar_draw(panel->currentBar, NULL); +static Panel* setCurrentPanel(const ScreenManager* this, Panel* panel) { + FunctionBar_draw(panel->currentBar); + if (panel == this->state->panel && this->state->pauseProcessUpdate) + FunctionBar_append("PAUSED", CRT_colors[PAUSED]); + return panel; } @@ -137,7 +143,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { bool quit = false; int focus = 0; - Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); + Panel* panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); double oldTime = 0.0; @@ -183,7 +189,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { ch = KEY_MOUSE; if (panel == panelFocus || this->allowFocusChange) { focus = i; - panelFocus = setCurrentPanel(panel); + panelFocus = setCurrentPanel(this, panel); Object* oldSelection = Panel_getSelected(panel); Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1); if (Panel_getSelected(panel) == oldSelection) { @@ -259,7 +265,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { tryLeft: if (focus > 0) focus--; - panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); + panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); if (Panel_size(panelFocus) == 0 && focus > 0) goto tryLeft; break; @@ -274,7 +280,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { tryRight: if (focus < this->panelCount - 1) focus++; - panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); + panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) goto tryRight; break; diff --git a/ScreenManager.h b/ScreenManager.h index 722fb7f22..ad312930a 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -7,9 +7,10 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "Action.h" #include "Header.h" -#include "Settings.h" #include "Panel.h" +#include "Settings.h" #include "Vector.h" typedef enum Orientation_ { @@ -27,11 +28,12 @@ typedef struct ScreenManager_ { int panelCount; Header* header; const Settings* settings; + const State* state; bool owner; bool allowFocusChange; } ScreenManager; -ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, bool owner); +ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, const State* state, bool owner); void ScreenManager_delete(ScreenManager* this); diff --git a/htop.1.in b/htop.1.in index cd5562b66..3e95c201b 100644 --- a/htop.1.in +++ b/htop.1.in @@ -209,6 +209,9 @@ userspace processes in the process list. (This is a toggle key.) .B p Show full paths to running programs, where applicable. (This is a toggle key.) .TP +.B Z +Pause/resume process updates. +.TP .B Ctrl-L Refresh: redraw screen and recalculate values. .TP diff --git a/htop.c b/htop.c index 8d17de9b2..44182ae19 100644 --- a/htop.c +++ b/htop.c @@ -283,6 +283,7 @@ int main(int argc, char** argv) { .pl = pl, .panel = (Panel*) panel, .header = header, + .pauseProcessUpdate = false, }; MainPanel_setState(panel, &state); @@ -290,7 +291,7 @@ int main(int argc, char** argv) { setCommFilter(&state, &(flags.commFilter)); } - ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true); + ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, &state, true); ScreenManager_add(scr, (Panel*) panel, -1); ProcessList_scan(pl); From 601480003ffdee444d8e48aed4222ad8dd23bb59 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 3 Oct 2020 17:53:15 +0200 Subject: [PATCH 289/411] Centralise fault handling This should be done as all platforms essentially did the same anyway and there was nothing platform specific. --- CRT.c | 112 ++++++++++++++++++++++++++++++--- CRT.h | 5 +- Makefile.am | 22 +++---- XAlloc.c | 2 +- darwin/DarwinCRT.c | 35 ----------- darwin/DarwinCRT.h | 14 ----- dragonflybsd/DragonFlyBSDCRT.c | 35 ----------- dragonflybsd/DragonFlyBSDCRT.h | 15 ----- freebsd/FreeBSDCRT.c | 21 ------- freebsd/FreeBSDCRT.h | 14 ----- linux/LinuxCRT.c | 41 ------------ linux/LinuxCRT.h | 14 ----- openbsd/OpenBSDCRT.c | 22 ------- openbsd/OpenBSDCRT.h | 15 ----- solaris/SolarisCRT.c | 33 ---------- solaris/SolarisCRT.h | 15 ----- unsupported/UnsupportedCRT.c | 21 ------- unsupported/UnsupportedCRT.h | 14 ----- 18 files changed, 115 insertions(+), 335 deletions(-) delete mode 100644 darwin/DarwinCRT.c delete mode 100644 darwin/DarwinCRT.h delete mode 100644 dragonflybsd/DragonFlyBSDCRT.c delete mode 100644 dragonflybsd/DragonFlyBSDCRT.h delete mode 100644 freebsd/FreeBSDCRT.c delete mode 100644 freebsd/FreeBSDCRT.h delete mode 100644 linux/LinuxCRT.c delete mode 100644 linux/LinuxCRT.h delete mode 100644 openbsd/OpenBSDCRT.c delete mode 100644 openbsd/OpenBSDCRT.h delete mode 100644 solaris/SolarisCRT.c delete mode 100644 solaris/SolarisCRT.h delete mode 100644 unsupported/UnsupportedCRT.c delete mode 100644 unsupported/UnsupportedCRT.h diff --git a/CRT.c b/CRT.c index 9159450b9..a6e606ef6 100644 --- a/CRT.c +++ b/CRT.c @@ -18,8 +18,13 @@ in the source distribution for its full text. #include #include #include -#ifdef HAVE_SETUID_ENABLED #include + +#ifdef HAVE_EXECINFO_H +#include +#endif + +#ifdef HAVE_SETUID_ENABLED #include #endif @@ -545,8 +550,6 @@ char* CRT_termType; int CRT_colorScheme = 0; -void *backtraceArray[128]; - ATTR_NORETURN static void CRT_handleSIGTERM(int sgn) { (void) sgn; @@ -591,9 +594,9 @@ void CRT_restorePrivileges() { #endif /* HAVE_SETUID_ENABLED */ -// TODO: pass an instance of Settings instead. +static struct sigaction old_sig_handler[32]; -struct sigaction old_sigsegv_handler; +// TODO: pass an instance of Settings instead. void CRT_init(int delay, int colorScheme, bool allowUnicode) { initscr(); @@ -650,9 +653,15 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { struct sigaction act; sigemptyset (&act.sa_mask); - act.sa_flags = (int)SA_RESETHAND; + act.sa_flags = (int)SA_RESETHAND|SA_NODEFER; act.sa_handler = CRT_handleSIGSEGV; - sigaction (SIGSEGV, &act, &old_sigsegv_handler); + 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); @@ -740,3 +749,92 @@ void CRT_setColors(int colorScheme) { CRT_colors = CRT_colorSchemes[colorScheme]; } + +void CRT_handleSIGSEGV(int signal) { + CRT_done(); + + fprintf(stderr, "\n\n" + "FATAL PROGRAM ERROR DETECTED\n" + "============================\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" +#ifdef HAVE_EXECINFO_H + "- Backtrace of the issue (see below)\n" +#endif + "\n" + ); + + const char* signal_str = strsignal(signal); + if(!signal_str) { + signal_str = "unknown reason"; + } + fprintf(stderr, + "Error information:\n" + "------------------\n" + "A signal %d (%s) was received.\n" + "\n", + signal, signal_str + ); + +#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]; + + size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray)); + backtrace_symbols_fd(backtraceArray, size, 2); + fprintf(stderr, + "---\n" + "\n" + "To make the above information more practical to work with,\n" + "you should provide a disassembly of your binary.\n" + "This can usually be done by running the following command:\n" + "\n" +#ifdef HTOP_DARWIN + " otool -tvV `which htop` > ~/htop.otool\n" +#else + " objdump -d -S -w `which htop` > ~/htop.objdump\n" +#endif + "\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" + "\n" + ); + + /* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */ + if(sigaction (signal, &old_sig_handler[signal], NULL) < 0) { + /* This avoids an infinite loop in case the handler could not be reset. */ + fprintf(stderr, + "!!! Chained handler could not be restored. Forcing exit.\n" + ); + _exit(1); + } + + /* Trigger the previous signal handler. */ + raise(signal); + + // Always terminate, even if installed handler returns + fprintf(stderr, + "!!! Chained handler did not exit. Forcing exit.\n" + ); + _exit(1); +} diff --git a/CRT.h b/CRT.h index 629a80976..5b0b73048 100644 --- a/CRT.h +++ b/CRT.h @@ -117,8 +117,7 @@ typedef enum ColorElements_ { void CRT_fatalError(const char* note) ATTR_NORETURN; -extern struct sigaction old_sigsegv_handler; -void CRT_handleSIGSEGV(int sgn); +void CRT_handleSIGSEGV(int signal) ATTR_NORETURN; #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) @@ -147,8 +146,6 @@ extern char* CRT_termType; extern int CRT_colorScheme; -extern void *backtraceArray[128]; - #ifdef HAVE_SETUID_ENABLED void CRT_dropPrivileges(void); diff --git a/Makefile.am b/Makefile.am index f4618eb67..b6f0f975e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -124,7 +124,6 @@ linux_platform_headers = \ linux/IOPriority.h \ linux/LinuxProcess.h \ linux/LinuxProcessList.h \ - linux/LinuxCRT.h \ linux/Battery.h \ linux/PressureStallMeter.h \ zfs/ZfsArcMeter.h \ @@ -134,7 +133,7 @@ linux_platform_headers = \ if HTOP_LINUX AM_LDFLAGS += -rdynamic myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c \ -linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \ +linux/LinuxProcess.c linux/LinuxProcessList.c linux/Battery.c \ linux/PressureStallMeter.c \ zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c @@ -148,7 +147,6 @@ freebsd_platform_headers = \ freebsd/Platform.h \ freebsd/FreeBSDProcessList.h \ freebsd/FreeBSDProcess.h \ - freebsd/FreeBSDCRT.h \ freebsd/Battery.h \ zfs/ZfsArcMeter.h \ zfs/ZfsCompressedArcMeter.h \ @@ -156,8 +154,9 @@ freebsd_platform_headers = \ zfs/openzfs_sysctl.h if HTOP_FREEBSD +AM_LDFLAGS += -lexecinfo myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ -freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c \ +freebsd/FreeBSDProcess.c freebsd/Battery.c \ zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c myhtopplatheaders = $(freebsd_platform_headers) @@ -170,13 +169,12 @@ dragonflybsd_platform_headers = \ dragonflybsd/Platform.h \ dragonflybsd/DragonFlyBSDProcessList.h \ dragonflybsd/DragonFlyBSDProcess.h \ - dragonflybsd/DragonFlyBSDCRT.h \ dragonflybsd/Battery.h if HTOP_DRAGONFLYBSD AM_LDFLAGS += -lkvm -lkinfo -lexecinfo myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \ -dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/DragonFlyBSDCRT.c dragonflybsd/Battery.c +dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/Battery.c myhtopplatheaders = $(dragonflybsd_platform_headers) endif @@ -188,12 +186,11 @@ openbsd_platform_headers = \ openbsd/Platform.h \ openbsd/OpenBSDProcessList.h \ openbsd/OpenBSDProcess.h \ - openbsd/OpenBSDCRT.h \ openbsd/Battery.h if HTOP_OPENBSD myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \ -openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c +openbsd/OpenBSDProcess.c openbsd/Battery.c myhtopplatheaders = $(openbsd_platform_headers) endif @@ -205,7 +202,6 @@ darwin_platform_headers = \ darwin/Platform.h \ darwin/DarwinProcess.h \ darwin/DarwinProcessList.h \ - darwin/DarwinCRT.h \ darwin/Battery.h \ zfs/ZfsArcMeter.h \ zfs/ZfsCompressedArcMeter.h \ @@ -215,7 +211,7 @@ darwin_platform_headers = \ if HTOP_DARWIN AM_LDFLAGS += -framework IOKit -framework CoreFoundation myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \ -darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c \ +darwin/DarwinProcessList.c darwin/Battery.c \ zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c myhtopplatheaders = $(darwin_platform_headers) @@ -228,7 +224,6 @@ solaris_platform_headers = \ solaris/Platform.h \ solaris/SolarisProcess.h \ solaris/SolarisProcessList.h \ - solaris/SolarisCRT.h \ solaris/Battery.h \ zfs/ZfsArcMeter.h \ zfs/ZfsCompressedArcMeter.h \ @@ -237,7 +232,7 @@ solaris_platform_headers = \ if HTOP_SOLARIS myhtopplatsources = solaris/Platform.c \ solaris/SolarisProcess.c solaris/SolarisProcessList.c \ -solaris/SolarisCRT.c solaris/Battery.c \ +solaris/Battery.c \ zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c myhtopplatheaders = $(solaris_platform_headers) @@ -250,13 +245,12 @@ unsupported_platform_headers = \ unsupported/Platform.h \ unsupported/UnsupportedProcess.h \ unsupported/UnsupportedProcessList.h \ - unsupported/UnsupportedCRT.h \ unsupported/Battery.h if HTOP_UNSUPPORTED myhtopplatsources = unsupported/Platform.c \ unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \ -unsupported/UnsupportedCRT.c unsupported/Battery.c +unsupported/Battery.c myhtopplatheaders = $(unsupported_platform_headers) endif diff --git a/XAlloc.c b/XAlloc.c index 20ddafc8b..c832d087c 100644 --- a/XAlloc.c +++ b/XAlloc.c @@ -14,7 +14,7 @@ void fail() { curs_set(1); endwin(); - err(1, NULL); + abort(); } void* xMalloc(size_t size) { diff --git a/darwin/DarwinCRT.c b/darwin/DarwinCRT.c deleted file mode 100644 index a4f0eb3f9..000000000 --- a/darwin/DarwinCRT.c +++ /dev/null @@ -1,35 +0,0 @@ -/* -htop - DarwinCRT.c -(C) 2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" -#include "DarwinCRT.h" -#include "CRT.h" -#include -#include -#include - -void CRT_handleSIGSEGV(int sgn) { - (void) sgn; - CRT_done(); - #ifdef __APPLE__ - fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); - #ifdef HAVE_EXECINFO_H - size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); - fprintf(stderr, "\n Please include in your report the following backtrace: \n"); - backtrace_symbols_fd(backtraceArray, size, 2); - fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); - fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:"); - fprintf(stderr, "\n\n otool -tvV `which htop` > ~/htop.otool"); - fprintf(stderr, "\n\nand then attach the file ~/htop.otool to your bug report."); - fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n"); - #endif - #else - fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); - fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); - #endif - abort(); -} diff --git a/darwin/DarwinCRT.h b/darwin/DarwinCRT.h deleted file mode 100644 index 258fb68ec..000000000 --- a/darwin/DarwinCRT.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef HEADER_DarwinCRT -#define HEADER_DarwinCRT -/* -htop - DarwinCRT.h -(C) 2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Macros.h" - -void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; - -#endif diff --git a/dragonflybsd/DragonFlyBSDCRT.c b/dragonflybsd/DragonFlyBSDCRT.c deleted file mode 100644 index ae8e7fec9..000000000 --- a/dragonflybsd/DragonFlyBSDCRT.c +++ /dev/null @@ -1,35 +0,0 @@ -/* -htop - dragonflybsd/DragonFlyBSDCRT.c -(C) 2014 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" -#include "DragonFlyBSDCRT.h" -#include "CRT.h" -#include -#include -#ifdef HAVE_EXECINFO_H -#include -#endif - -void CRT_handleSIGSEGV(int sgn) { - (void) sgn; - CRT_done(); - fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); - #ifdef HAVE_EXECINFO_H - size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); - fprintf(stderr, "\n Please include in your report the following backtrace: \n"); - backtrace_symbols_fd(backtraceArray, size, 2); - fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); - fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:"); - fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump"); - fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report."); - fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n"); - #else - fprintf(stderr, "\nPlease contact your DragonFlyBSD package maintainer!\n\n"); - #endif - abort(); -} diff --git a/dragonflybsd/DragonFlyBSDCRT.h b/dragonflybsd/DragonFlyBSDCRT.h deleted file mode 100644 index 9a0fdbeb3..000000000 --- a/dragonflybsd/DragonFlyBSDCRT.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef HEADER_DragonFlyBSDCRT -#define HEADER_DragonFlyBSDCRT -/* -htop - dragonflybsd/DragonFlyBSDCRT.h -(C) 2014 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Macros.h" - -void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; - -#endif diff --git a/freebsd/FreeBSDCRT.c b/freebsd/FreeBSDCRT.c deleted file mode 100644 index e1024d30b..000000000 --- a/freebsd/FreeBSDCRT.c +++ /dev/null @@ -1,21 +0,0 @@ -/* -htop - FreeBSDCRT.c -(C) 2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" -#include "FreeBSDCRT.h" -#include "CRT.h" -#include -#include - -void CRT_handleSIGSEGV(int sgn) { - (void) sgn; - CRT_done(); - fprintf(stderr, "\n\nhtop " VERSION " aborting.\n"); - fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); - fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); - abort(); -} diff --git a/freebsd/FreeBSDCRT.h b/freebsd/FreeBSDCRT.h deleted file mode 100644 index af64cf10b..000000000 --- a/freebsd/FreeBSDCRT.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef HEADER_FreeBSDCRT -#define HEADER_FreeBSDCRT -/* -htop - FreeBSDCRT.h -(C) 2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Macros.h" - -void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; - -#endif diff --git a/linux/LinuxCRT.c b/linux/LinuxCRT.c deleted file mode 100644 index 7bbb80e09..000000000 --- a/linux/LinuxCRT.c +++ /dev/null @@ -1,41 +0,0 @@ -/* -htop - LinuxCRT.c -(C) 2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" -#include "LinuxCRT.h" -#include "CRT.h" - -#include -#include -#include -#ifdef HAVE_EXECINFO_H -#include -#endif - -void CRT_handleSIGSEGV(int sgn) { - (void) sgn; - CRT_done(); - #ifdef __linux - fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); - #ifdef HAVE_EXECINFO_H - size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray)); - fprintf(stderr, "\n Please include in your report the following backtrace: \n"); - backtrace_symbols_fd(backtraceArray, size, 2); - fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); - fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:"); - fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump"); - fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report."); - fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n"); - #endif - #else - fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); - fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); - #endif - - /* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */ - sigaction (SIGSEGV, &old_sigsegv_handler, NULL); -} diff --git a/linux/LinuxCRT.h b/linux/LinuxCRT.h deleted file mode 100644 index d9263d66b..000000000 --- a/linux/LinuxCRT.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef HEADER_LinuxCRT -#define HEADER_LinuxCRT -/* -htop - LinuxCRT.h -(C) 2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Macros.h" - -void CRT_handleSIGSEGV(int sgn); - -#endif diff --git a/openbsd/OpenBSDCRT.c b/openbsd/OpenBSDCRT.c deleted file mode 100644 index 88cb8e23d..000000000 --- a/openbsd/OpenBSDCRT.c +++ /dev/null @@ -1,22 +0,0 @@ -/* -htop - OpenBSDCRT.c -(C) 2014 Hisham H. Muhammad -(C) 2015 Michael McConville -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" -#include "OpenBSDCRT.h" -#include "CRT.h" -#include -#include - -void CRT_handleSIGSEGV(int sgn) { - (void) sgn; - CRT_done(); - fprintf(stderr, "\n\nhtop " VERSION " aborting.\n"); - fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); - fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); - abort(); -} diff --git a/openbsd/OpenBSDCRT.h b/openbsd/OpenBSDCRT.h deleted file mode 100644 index 6259b78cc..000000000 --- a/openbsd/OpenBSDCRT.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef HEADER_OpenBSDCRT -#define HEADER_OpenBSDCRT -/* -htop - OpenBSDCRT.h -(C) 2014 Hisham H. Muhammad -(C) 2015 Michael McConville -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Macros.h" - -void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; - -#endif diff --git a/solaris/SolarisCRT.c b/solaris/SolarisCRT.c deleted file mode 100644 index ef16aabc4..000000000 --- a/solaris/SolarisCRT.c +++ /dev/null @@ -1,33 +0,0 @@ -/* -htop - SolarisCRT.c -(C) 2014 Hisham H. Muhammad -(C) 2018 Guy M. Broome -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" -#include "SolarisCRT.h" -#include "CRT.h" -#include -#include -#ifdef HAVE_EXECINFO_H -#include -#endif - -void CRT_handleSIGSEGV(int sgn) { - (void) sgn; - CRT_done(); - fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); - #ifdef HAVE_EXECINFO_H - size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); - fprintf(stderr, "\n Please include in your report the following backtrace: \n"); - backtrace_symbols_fd(backtraceArray, size, 2); - fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); - fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:"); - fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump"); - fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report."); - fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n"); - #endif - abort(); -} diff --git a/solaris/SolarisCRT.h b/solaris/SolarisCRT.h deleted file mode 100644 index aa8c81bb2..000000000 --- a/solaris/SolarisCRT.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef HEADER_SolarisCRT -#define HEADER_SolarisCRT -/* -htop - SolarisCRT.h -(C) 2014 Hisham H. Muhammad -(C) 2018 Guy M. Broome -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Macros.h" - -void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; - -#endif diff --git a/unsupported/UnsupportedCRT.c b/unsupported/UnsupportedCRT.c deleted file mode 100644 index 5ee076cda..000000000 --- a/unsupported/UnsupportedCRT.c +++ /dev/null @@ -1,21 +0,0 @@ -/* -htop - UnsupportedCRT.c -(C) 2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" -#include "UnsupportedCRT.h" -#include "CRT.h" -#include -#include - -void CRT_handleSIGSEGV(int sgn) { - (void) sgn; - CRT_done(); - fprintf(stderr, "\n\nhtop " VERSION " aborting.\n"); - fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); - fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); - abort(); -} diff --git a/unsupported/UnsupportedCRT.h b/unsupported/UnsupportedCRT.h deleted file mode 100644 index f89d787cb..000000000 --- a/unsupported/UnsupportedCRT.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef HEADER_UnsupportedCRT -#define HEADER_UnsupportedCRT -/* -htop - UnsupportedCRT.h -(C) 2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Macros.h" - -void CRT_handleSIGSEGV(int sgn) ATTR_NORETURN; - -#endif From 25022c219df6d62827c4b10773288a30ec739e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 22 Sep 2020 20:04:41 +0200 Subject: [PATCH 290/411] Read CPU count every cycle to avoid issues when HT/SMT mode changes --- linux/LinuxProcessList.c | 90 ++++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 23 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5a32f3dde..7a31debfe 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -149,6 +149,43 @@ static void LinuxProcessList_initNetlinkSocket(LinuxProcessList* this) { #endif +static int LinuxProcessList_computeCPUcount(void) { + FILE* file = fopen(PROCSTATFILE, "r"); + if (file == NULL) + CRT_fatalError("Cannot open " PROCSTATFILE); + + int cpus = 0; + char buffer[PROC_LINE_LENGTH + 1]; + while(fgets(buffer, sizeof(buffer), file)) { + if (String_startsWith(buffer, "cpu")) + cpus++; + } + + fclose(file); + + /* subtract raw cpu entry */ + if (cpus > 0) + cpus--; + + return cpus; +} + +static void LinuxProcessList_updateCPUcount(LinuxProcessList* this) { + ProcessList* pl = &(this->super); + int cpus = LinuxProcessList_computeCPUcount(); + if (cpus == 0 || cpus == pl->cpuCount) + return; + + pl->cpuCount = cpus; + free(this->cpus); + this->cpus = xCalloc(cpus + 1, sizeof(CPUData)); + + for (int i = 0; i <= cpus; i++) { + this->cpus[i].totalTime = 1; + this->cpus[i].totalPeriod = 1; + } +} + ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { LinuxProcessList* this = xCalloc(1, sizeof(LinuxProcessList)); ProcessList* pl = &(this->super); @@ -169,34 +206,38 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui this->haveSmapsRollup = false; } - // Update CPU count: - file = fopen(PROCSTATFILE, "r"); - if (file == NULL) { - CRT_fatalError("Cannot open " PROCSTATFILE); - } - int cpus = 0; - do { - char buffer[PROC_LINE_LENGTH + 1]; - if (fgets(buffer, PROC_LINE_LENGTH + 1, file) == NULL) { - CRT_fatalError("No btime in " PROCSTATFILE); - } else if (String_startsWith(buffer, "cpu")) { - cpus++; - } else if (String_startsWith(buffer, "btime ")) { - if (sscanf(buffer, "btime %lld\n", &btime) != 1) - CRT_fatalError("Failed to parse btime from " PROCSTATFILE); - break; + // Read btime + { + FILE* statfile = fopen(PROCSTATFILE, "r"); + if (statfile == NULL) + CRT_fatalError("Cannot open " PROCSTATFILE); + + while(true) { + char buffer[PROC_LINE_LENGTH + 1]; + if (fgets(buffer, sizeof(buffer), statfile) == NULL) { + CRT_fatalError("No btime in " PROCSTATFILE); + } else if (String_startsWith(buffer, "btime ")) { + if (sscanf(buffer, "btime %lld\n", &btime) != 1) + CRT_fatalError("Failed to parse btime from " PROCSTATFILE); + break; + } } - } while(true); - fclose(file); + fclose(statfile); + } - pl->cpuCount = MAXIMUM(cpus - 1, 1); - this->cpus = xCalloc(cpus, sizeof(CPUData)); + // Initialze CPU count + { + int cpus = LinuxProcessList_computeCPUcount(); + pl->cpuCount = MAXIMUM(cpus, 1); + this->cpus = xCalloc(cpus + 1, sizeof(CPUData)); - for (int i = 0; i < cpus; i++) { - this->cpus[i].totalTime = 1; - this->cpus[i].totalPeriod = 1; + for (int i = 0; i <= cpus; i++) { + this->cpus[i].totalTime = 1; + this->cpus[i].totalPeriod = 1; + } } + return pl; } @@ -1332,6 +1373,9 @@ void ProcessList_goThroughEntries(ProcessList* super) { LinuxProcessList_scanMemoryInfo(super); LinuxProcessList_scanZfsArcstats(this); + + LinuxProcessList_updateCPUcount(this); + double period = LinuxProcessList_scanCPUTime(this); if (settings->showCPUFrequency) From 0b9a0014989b8557eb16697984d9fd02b59bf47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 2 Oct 2020 16:27:57 +0200 Subject: [PATCH 291/411] Meter: use explicit type for drawData --- Meter.c | 2 +- Meter.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Meter.c b/Meter.c index c8cd19eba..3edfb2331 100644 --- a/Meter.c +++ b/Meter.c @@ -259,7 +259,7 @@ static int GraphMeterMode_pixPerRow; static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData)); - GraphData* data = (GraphData*) this->drawData; + GraphData* data = this->drawData; const int nValues = METER_BUFFER_LEN; #ifdef HAVE_LIBNCURSESW diff --git a/Meter.h b/Meter.h index 0647c764d..8a0c86944 100644 --- a/Meter.h +++ b/Meter.h @@ -53,6 +53,11 @@ typedef struct MeterClass_ { #define Meter_name(this_) As_Meter(this_)->name #define Meter_uiName(this_) As_Meter(this_)->uiName +typedef struct GraphData_ { + struct timeval time; + double values[METER_BUFFER_LEN]; +} GraphData; + struct Meter_ { Object super; Meter_Draw draw; @@ -60,7 +65,7 @@ struct Meter_ { char* caption; int mode; int param; - void* drawData; + GraphData* drawData; int h; struct ProcessList_* pl; char curItems; @@ -83,11 +88,6 @@ typedef enum { LAST_METERMODE } MeterModeId; -typedef struct GraphData_ { - struct timeval time; - double values[METER_BUFFER_LEN]; -} GraphData; - extern const MeterClass Meter_class; Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type); From 9f5b50edd78111a42b5824f3725794f8762326d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 23 Sep 2020 11:58:11 +0200 Subject: [PATCH 292/411] CPUMeter: avoid crashes and leaks in case the CPU count changes E.g. if the HT/SMT mode changes Use separate data for sub-meters Do not reuse drawData for maintainability --- CPUMeter.c | 57 ++++++++++++++++++++++++++++++++++++------------------ Meter.h | 1 + 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index c1ccb12c4..446c04d20 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -27,6 +27,11 @@ static const int CPUMeter_attributes[] = { CPU_IOWAIT }; +typedef struct CPUMeterData_ { + int cpus; + Meter** meters; +} CPUMeterData; + static void CPUMeter_init(Meter* this) { int cpu = this->param; if (this->pl->cpuCount > 1) { @@ -42,6 +47,9 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { int cpu = this->param; if (cpu > this->pl->cpuCount) { xSnprintf(buffer, size, "absent"); + int items = this->curItems; + for (int i = 0; i < items; i++) + this->values[i] = 0; return; } memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT); @@ -119,7 +127,8 @@ static void CPUMeter_display(const Object* cast, RichString* out) { } static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) { - int cpus = this->pl->cpuCount; + CPUMeterData* data = this->meterData; + int cpus = data->cpus; switch(Meter_name(this)[0]) { default: case 'A': // All @@ -139,9 +148,13 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) { static void CPUMeterCommonInit(Meter *this, int ncol) { int cpus = this->pl->cpuCount; - if (!this->drawData) - this->drawData = xCalloc(cpus, sizeof(Meter*)); - Meter** meters = (Meter**) this->drawData; + CPUMeterData* data = this->meterData; + if (!data) { + data = this->meterData = xMalloc(sizeof(CPUMeterData)); + data->cpus = cpus; + data->meters = xCalloc(cpus, sizeof(Meter*)); + } + Meter** meters = data->meters; int start, count; AllCPUsMeter_getRange(this, &start, &count); for (int i = 0; i < count; i++) { @@ -156,7 +169,8 @@ static void CPUMeterCommonInit(Meter *this, int ncol) { } static void CPUMeterCommonUpdateMode(Meter* this, int mode, int ncol) { - Meter** meters = (Meter**) this->drawData; + CPUMeterData* data = this->meterData; + Meter** meters = data->meters; this->mode = mode; int h = Meter_modes[mode]->h; int start, count; @@ -168,11 +182,14 @@ static void CPUMeterCommonUpdateMode(Meter* this, int mode, int ncol) { } static void AllCPUsMeter_done(Meter* this) { - Meter** meters = (Meter**) this->drawData; + CPUMeterData* data = this->meterData; + Meter** meters = data->meters; int start, count; AllCPUsMeter_getRange(this, &start, &count); for (int i = 0; i < count; i++) Meter_delete((Object*)meters[i]); + free(data->meters); + free(data); } static void SingleColCPUsMeter_init(Meter* this) { @@ -208,18 +225,19 @@ static void OctoColCPUsMeter_updateMode(Meter* this, int mode) { } static void CPUMeterCommonDraw(Meter* this, int x, int y, int w, int ncol) { - Meter** meters = (Meter**) this->drawData; - int start, count; - AllCPUsMeter_getRange(this, &start, &count); - int colwidth = (w-ncol)/ncol + 1; - int diff = (w - (colwidth * ncol)); - int nrows = (count + ncol - 1) / ncol; - for (int i = 0; i < count; i++){ - int d = (i/nrows) > diff ? diff : (i / nrows) ; // dynamic spacer - int xpos = x + ((i / nrows) * colwidth) + d; - int ypos = y + ((i % nrows) * meters[0]->h); - meters[i]->draw(meters[i], xpos, ypos, colwidth); - } + CPUMeterData* data = this->meterData; + Meter** meters = data->meters; + int start, count; + AllCPUsMeter_getRange(this, &start, &count); + int colwidth = (w-ncol)/ncol + 1; + int diff = (w - (colwidth * ncol)); + int nrows = (count + ncol - 1) / ncol; + for (int i = 0; i < count; i++){ + int d = (i/nrows) > diff ? diff : (i / nrows) ; // dynamic spacer + int xpos = x + ((i / nrows) * colwidth) + d; + int ypos = y + ((i % nrows) * meters[0]->h); + meters[i]->draw(meters[i], xpos, ypos, colwidth); + } } static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) { @@ -236,7 +254,8 @@ static void OctoColCPUsMeter_draw(Meter* this, int x, int y, int w) { static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) { - Meter** meters = (Meter**) this->drawData; + CPUMeterData* data = this->meterData; + Meter** meters = data->meters; int start, count; AllCPUsMeter_getRange(this, &start, &count); for (int i = 0; i < count; i++) { diff --git a/Meter.h b/Meter.h index 8a0c86944..5432a768b 100644 --- a/Meter.h +++ b/Meter.h @@ -71,6 +71,7 @@ struct Meter_ { char curItems; double* values; double total; + void* meterData; }; typedef struct MeterMode_ { From 5cc20e7cb27800166499d90ca457e17097adb3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 23 Sep 2020 11:52:57 +0200 Subject: [PATCH 293/411] Settings: do not save initial cpu count Not needed and confusing with ProcessList.cpuCount --- Settings.c | 23 +++++++++++------------ Settings.h | 3 +-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Settings.c b/Settings.c index 1a8fafa0d..7a90ec477 100644 --- a/Settings.c +++ b/Settings.c @@ -53,9 +53,9 @@ static void Settings_readMeterModes(Settings* this, char* line, int column) { this->columns[column].modes = modes; } -static void Settings_defaultMeters(Settings* this) { +static void Settings_defaultMeters(Settings* this, int initialCpuCount) { int sizes[] = { 3, 3 }; - if (this->cpuCount > 4) { + if (initialCpuCount > 4) { sizes[1]++; } for (int i = 0; i < 2; i++) { @@ -64,12 +64,12 @@ static void Settings_defaultMeters(Settings* this) { this->columns[i].len = sizes[i]; } int r = 0; - if (this->cpuCount > 8) { + if (initialCpuCount > 8) { this->columns[0].names[0] = xStrdup("LeftCPUs2"); this->columns[0].modes[0] = BAR_METERMODE; this->columns[1].names[r] = xStrdup("RightCPUs2"); this->columns[1].modes[r++] = BAR_METERMODE; - } else if (this->cpuCount > 4) { + } else if (initialCpuCount > 4) { this->columns[0].names[0] = xStrdup("LeftCPUs"); this->columns[0].modes[0] = BAR_METERMODE; this->columns[1].names[r] = xStrdup("RightCPUs"); @@ -110,7 +110,7 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { String_freeArray(ids); } -static bool Settings_read(Settings* this, const char* fileName) { +static bool Settings_read(Settings* this, const char* fileName, int initialCpuCount) { FILE* fd; CRT_dropPrivileges(); fd = fopen(fileName, "r"); @@ -204,7 +204,7 @@ static bool Settings_read(Settings* this, const char* fileName) { } fclose(fd); if (!didReadMeters) { - Settings_defaultMeters(this); + Settings_defaultMeters(this, initialCpuCount); } return didReadFields; } @@ -285,7 +285,7 @@ bool Settings_write(Settings* this) { return true; } -Settings* Settings_new(int cpuCount) { +Settings* Settings_new(int initialCpuCount) { Settings* this = xCalloc(1, sizeof(Settings)); this->sortKey = PERCENT_CPU; @@ -303,7 +303,6 @@ Settings* Settings_new(int cpuCount) { this->showCPUUsage = true; this->showCPUFrequency = false; this->updateProcessNames = false; - this->cpuCount = cpuCount; this->showProgramPath = true; this->highlightThreads = true; #ifdef HAVE_LIBHWLOC @@ -358,7 +357,7 @@ Settings* Settings_new(int cpuCount) { this->delay = DEFAULT_DELAY; bool ok = false; if (legacyDotfile) { - ok = Settings_read(this, legacyDotfile); + ok = Settings_read(this, legacyDotfile, initialCpuCount); if (ok) { // Transition to new location and delete old configuration file if (Settings_write(this)) @@ -367,17 +366,17 @@ Settings* Settings_new(int cpuCount) { free(legacyDotfile); } if (!ok) { - ok = Settings_read(this, this->filename); + ok = Settings_read(this, this->filename, initialCpuCount); } if (!ok) { this->changed = true; // TODO: how to get SYSCONFDIR correctly through Autoconf? char* systemSettings = String_cat(SYSCONFDIR, "/htoprc"); - ok = Settings_read(this, systemSettings); + ok = Settings_read(this, systemSettings, initialCpuCount); free(systemSettings); } if (!ok) { - Settings_defaultMeters(this); + Settings_defaultMeters(this, initialCpuCount); this->hideKernelThreads = true; this->highlightMegabytes = true; this->highlightThreads = true; diff --git a/Settings.h b/Settings.h index 97c0cb570..73da4f07e 100644 --- a/Settings.h +++ b/Settings.h @@ -28,7 +28,6 @@ typedef struct Settings_ { int colorScheme; int delay; - int cpuCount; int direction; ProcessField sortKey; @@ -63,7 +62,7 @@ void Settings_delete(Settings* this); bool Settings_write(Settings* this); -Settings* Settings_new(int cpuCount); +Settings* Settings_new(int initialCpuCount); void Settings_invertSortOrder(Settings* this); From 7af06659e2694823c9430e1ef249d1cd4e565926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 13 Oct 2020 14:35:30 +0200 Subject: [PATCH 294/411] Mark remaining classes const --- AffinityPanel.c | 2 +- darwin/DarwinProcess.c | 2 +- darwin/DarwinProcess.h | 2 +- dragonflybsd/DragonFlyBSDProcess.c | 2 +- dragonflybsd/DragonFlyBSDProcess.h | 2 +- freebsd/FreeBSDProcess.c | 2 +- freebsd/FreeBSDProcess.h | 2 +- linux/LinuxProcess.c | 2 +- linux/LinuxProcess.h | 2 +- linux/PressureStallMeter.c | 12 ++++++------ linux/PressureStallMeter.h | 10 +++++----- openbsd/OpenBSDProcess.c | 2 +- openbsd/OpenBSDProcess.h | 2 +- solaris/SolarisProcess.c | 2 +- solaris/SolarisProcess.h | 2 +- zfs/ZfsArcMeter.c | 4 ++-- zfs/ZfsArcMeter.h | 4 +--- zfs/ZfsCompressedArcMeter.c | 4 ++-- zfs/ZfsCompressedArcMeter.h | 4 +--- 19 files changed, 30 insertions(+), 34 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index 82ac12e5d..0a9648829 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -67,7 +67,7 @@ static void MaskItem_display(const Object* cast, RichString* out) { RichString_append(out, CRT_colors[CHECK_TEXT], this->text); } -static ObjectClass MaskItem_class = { +static const ObjectClass MaskItem_class = { .display = MaskItem_display, .delete = MaskItem_delete }; diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 59853770a..8c90c2a59 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -16,7 +16,7 @@ in the source distribution for its full text. #include -ProcessClass DarwinProcess_class = { +const ProcessClass DarwinProcess_class = { .super = { .extends = Class(Process), .display = Process_display, diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index 11dc2c3cb..fc932afee 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -20,7 +20,7 @@ typedef struct DarwinProcess_ { bool taskAccess; } DarwinProcess; -extern ProcessClass DarwinProcess_class; +extern const ProcessClass DarwinProcess_class; DarwinProcess* DarwinProcess_new(Settings* settings); diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 9c5e426e5..4c2310934 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -18,7 +18,7 @@ in the source distribution for its full text. #include -ProcessClass DragonFlyBSDProcess_class = { +const ProcessClass DragonFlyBSDProcess_class = { .super = { .extends = Class(Process), .display = Process_display, diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h index 637dddb0f..1c048143b 100644 --- a/dragonflybsd/DragonFlyBSDProcess.h +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -27,7 +27,7 @@ typedef struct DragonFlyBSDProcess_ { //#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) #define Process_isUserlandThread(_process) (_process->nlwp > 1) -extern ProcessClass DragonFlyBSDProcess_class; +extern const ProcessClass DragonFlyBSDProcess_class; extern ProcessFieldData Process_fields[]; diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 6548ff681..710194942 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -17,7 +17,7 @@ in the source distribution for its full text. #include -ProcessClass FreeBSDProcess_class = { +const ProcessClass FreeBSDProcess_class = { .super = { .extends = Class(Process), .display = Process_display, diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index f6fa8b3e2..250948483 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -25,7 +25,7 @@ typedef struct FreeBSDProcess_ { #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -extern ProcessClass FreeBSDProcess_class; +extern const ProcessClass FreeBSDProcess_class; extern ProcessFieldData Process_fields[]; diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index e6f78f9fb..ba0779fbc 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -126,7 +126,7 @@ ProcessPidColumn Process_pidColumns[] = { { .id = 0, .label = NULL }, }; -ProcessClass LinuxProcess_class = { +const ProcessClass LinuxProcess_class = { .super = { .extends = Class(Process), .display = Process_display, diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 9227dd7f2..8113193f9 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -157,7 +157,7 @@ extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; -extern ProcessClass LinuxProcess_class; +extern const ProcessClass LinuxProcess_class; LinuxProcess* LinuxProcess_new(Settings* settings); diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c index a54b4375b..307e397db 100644 --- a/linux/PressureStallMeter.c +++ b/linux/PressureStallMeter.c @@ -16,7 +16,7 @@ in the source distribution for its full text. #include "Meter.h" }*/ -static int PressureStallMeter_attributes[] = { +static const int PressureStallMeter_attributes[] = { PRESSURE_STALL_TEN, PRESSURE_STALL_SIXTY, PRESSURE_STALL_THREEHUNDRED }; @@ -52,7 +52,7 @@ static void PressureStallMeter_display(const Object* cast, RichString* out) { RichString_append(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer); } -MeterClass PressureStallCPUSomeMeter_class = { +const MeterClass PressureStallCPUSomeMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -68,7 +68,7 @@ MeterClass PressureStallCPUSomeMeter_class = { .caption = "Some CPU pressure: " }; -MeterClass PressureStallIOSomeMeter_class = { +const MeterClass PressureStallIOSomeMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -84,7 +84,7 @@ MeterClass PressureStallIOSomeMeter_class = { .caption = "Some IO pressure: " }; -MeterClass PressureStallIOFullMeter_class = { +const MeterClass PressureStallIOFullMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -100,7 +100,7 @@ MeterClass PressureStallIOFullMeter_class = { .caption = "Full IO pressure: " }; -MeterClass PressureStallMemorySomeMeter_class = { +const MeterClass PressureStallMemorySomeMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, @@ -116,7 +116,7 @@ MeterClass PressureStallMemorySomeMeter_class = { .caption = "Some Mem pressure: " }; -MeterClass PressureStallMemoryFullMeter_class = { +const MeterClass PressureStallMemoryFullMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/linux/PressureStallMeter.h b/linux/PressureStallMeter.h index 823659ff0..1a0ad5847 100644 --- a/linux/PressureStallMeter.h +++ b/linux/PressureStallMeter.h @@ -12,14 +12,14 @@ in the source distribution for its full text. #include "Meter.h" -extern MeterClass PressureStallCPUSomeMeter_class; +extern const MeterClass PressureStallCPUSomeMeter_class; -extern MeterClass PressureStallIOSomeMeter_class; +extern const MeterClass PressureStallIOSomeMeter_class; -extern MeterClass PressureStallIOFullMeter_class; +extern const MeterClass PressureStallIOFullMeter_class; -extern MeterClass PressureStallMemorySomeMeter_class; +extern const MeterClass PressureStallMemorySomeMeter_class; -extern MeterClass PressureStallMemoryFullMeter_class; +extern const MeterClass PressureStallMemoryFullMeter_class; #endif diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 6b87f372e..56bc07717 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -17,7 +17,7 @@ in the source distribution for its full text. #include -ProcessClass OpenBSDProcess_class = { +const ProcessClass OpenBSDProcess_class = { .super = { .extends = Class(Process), .display = Process_display, diff --git a/openbsd/OpenBSDProcess.h b/openbsd/OpenBSDProcess.h index bd3659425..5694a524d 100644 --- a/openbsd/OpenBSDProcess.h +++ b/openbsd/OpenBSDProcess.h @@ -21,7 +21,7 @@ typedef struct OpenBSDProcess_ { #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -extern ProcessClass OpenBSDProcess_class; +extern const ProcessClass OpenBSDProcess_class; extern ProcessFieldData Process_fields[]; diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index b796c96e1..0d9946698 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -18,7 +18,7 @@ in the source distribution for its full text. #include -ProcessClass SolarisProcess_class = { +const ProcessClass SolarisProcess_class = { .super = { .extends = Class(Process), .display = Process_display, diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index 2a32f8c72..a1b3b14d5 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -44,7 +44,7 @@ typedef struct SolarisProcess_ { #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) -extern ProcessClass SolarisProcess_class; +extern const ProcessClass SolarisProcess_class; extern ProcessFieldData Process_fields[]; diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index 6301a9c43..acfe13f25 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -23,7 +23,7 @@ in the source distribution for its full text. #include "Meter.h" }*/ -int ZfsArcMeter_attributes[] = { +static const int ZfsArcMeter_attributes[] = { ZFS_MFU, ZFS_MRU, ZFS_ANON, ZFS_HEADER, ZFS_OTHER }; @@ -86,7 +86,7 @@ static void ZfsArcMeter_display(const Object* cast, RichString* out) { } } -MeterClass ZfsArcMeter_class = { +const MeterClass ZfsArcMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/zfs/ZfsArcMeter.h b/zfs/ZfsArcMeter.h index 6b9a6e168..cf552bceb 100644 --- a/zfs/ZfsArcMeter.h +++ b/zfs/ZfsArcMeter.h @@ -11,10 +11,8 @@ in the source distribution for its full text. #include "Meter.h" -extern int ZfsArcMeter_attributes[]; - void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats); -extern MeterClass ZfsArcMeter_class; +extern const MeterClass ZfsArcMeter_class; #endif diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index ccf57203a..472b5b5bd 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -23,7 +23,7 @@ in the source distribution for its full text. #include "Meter.h" }*/ -int ZfsCompressedArcMeter_attributes[] = { +static const int ZfsCompressedArcMeter_attributes[] = { ZFS_COMPRESSED }; @@ -68,7 +68,7 @@ static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) { } } -MeterClass ZfsCompressedArcMeter_class = { +const MeterClass ZfsCompressedArcMeter_class = { .super = { .extends = Class(Meter), .delete = Meter_delete, diff --git a/zfs/ZfsCompressedArcMeter.h b/zfs/ZfsCompressedArcMeter.h index 8982eddbc..1ad6447d2 100644 --- a/zfs/ZfsCompressedArcMeter.h +++ b/zfs/ZfsCompressedArcMeter.h @@ -11,10 +11,8 @@ in the source distribution for its full text. #include "Meter.h" -extern int ZfsCompressedArcMeter_attributes[]; - void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats); -extern MeterClass ZfsCompressedArcMeter_class; +extern const MeterClass ZfsCompressedArcMeter_class; #endif From 59edb2e80ce0430d13be8374d45a7eeafdf65604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 13 Oct 2020 14:39:12 +0200 Subject: [PATCH 295/411] Enclose macro argument in parentheses --- Object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Object.h b/Object.h index 36ab2544e..f601ddf05 100644 --- a/Object.h +++ b/Object.h @@ -19,7 +19,7 @@ typedef long(*Object_Compare)(const void*, const void*); typedef void(*Object_Delete)(Object*); #define Object_getClass(obj_) ((const Object*)(obj_))->klass -#define Object_setClass(obj_, class_) (((Object*)(obj_))->klass = (const ObjectClass*) class_) +#define Object_setClass(obj_, class_) (((Object*)(obj_))->klass = (const ObjectClass*) (class_)) #define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_)) #define Object_displayFn(obj_) Object_getClass(obj_)->display From 1df7fa387a1b5c9541a5b3b49c1ac0fb77bba05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 17:24:59 +0200 Subject: [PATCH 296/411] Misc CRT cleanup --- CRT.c | 55 +++++++++++++++++++------------------------------------ CRT.h | 34 +++++++++++++++------------------- 2 files changed, 34 insertions(+), 55 deletions(-) diff --git a/CRT.c b/CRT.c index a6e606ef6..1469ff3dd 100644 --- a/CRT.c +++ b/CRT.c @@ -28,20 +28,20 @@ in the source distribution for its full text. #include #endif -#define ColorIndex(i,j) ((7-i)*8+j) +#define ColorIndex(i,j) ((7-(i))*8+(j)) #define ColorPair(i,j) COLOR_PAIR(ColorIndex(i,j)) -#define Black COLOR_BLACK -#define Red COLOR_RED -#define Green COLOR_GREEN -#define Yellow COLOR_YELLOW -#define Blue COLOR_BLUE +#define Black COLOR_BLACK +#define Red COLOR_RED +#define Green COLOR_GREEN +#define Yellow COLOR_YELLOW +#define Blue COLOR_BLUE #define Magenta COLOR_MAGENTA -#define Cyan COLOR_CYAN -#define White COLOR_WHITE +#define Cyan COLOR_CYAN +#define White COLOR_WHITE -#define ColorPairGrayBlack ColorPair(Magenta,Magenta) +#define ColorPairGrayBlack ColorPair(Magenta,Magenta) #define ColorIndexGrayBlack ColorIndex(Magenta,Magenta) static const char *const CRT_treeStrAscii[TREE_STR_COUNT] = { @@ -74,11 +74,9 @@ bool CRT_utf8 = false; const char *const *CRT_treeStr = CRT_treeStrAscii; -static bool CRT_hasColors; +int CRT_delay; -int CRT_delay = 0; - -int* CRT_colors; +const int* CRT_colors; int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [COLORSCHEME_DEFAULT] = { @@ -544,9 +542,7 @@ int CRT_scrollHAmount = 5; int CRT_scrollWheelVAmount = 10; -char* CRT_termType; - -// TODO move color scheme to Settings, perhaps? +const char* CRT_termType; int CRT_colorScheme = 0; @@ -563,35 +559,29 @@ static int CRT_euid = -1; static int CRT_egid = -1; -#define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0) - void CRT_dropPrivileges() { CRT_egid = getegid(); CRT_euid = geteuid(); if (setegid(getgid()) == -1) { - DIE("Fatal error: failed dropping group privileges.\n"); + CRT_fatalError("Fatal error: failed dropping group privileges"); } if (seteuid(getuid()) == -1) { - DIE("Fatal error: failed dropping user privileges.\n"); + CRT_fatalError("Fatal error: failed dropping user privileges"); } } void CRT_restorePrivileges() { if (CRT_egid == -1 || CRT_euid == -1) { - DIE("Fatal error: internal inconsistency.\n"); + CRT_fatalError("Fatal error: internal inconsistency"); } if (setegid(CRT_egid) == -1) { - DIE("Fatal error: failed restoring group privileges.\n"); + CRT_fatalError("Fatal error: failed restoring group privileges"); } if (seteuid(CRT_euid) == -1) { - DIE("Fatal error: failed restoring user privileges.\n"); + CRT_fatalError("Fatal error: failed restoring user privileges"); } } -#else /* HAVE_SETUID_ENABLED */ - -// In this case, the setuid operations are defined as macros in CRT.h - #endif /* HAVE_SETUID_ENABLED */ static struct sigaction old_sig_handler[32]; @@ -601,10 +591,7 @@ static struct sigaction old_sig_handler[32]; void CRT_init(int delay, int colorScheme, bool allowUnicode) { initscr(); noecho(); - CRT_delay = delay; - if (CRT_delay == 0) { - CRT_delay = 1; - } + CRT_delay = CLAMP(delay, 1, 255); CRT_colors = CRT_colorSchemes[colorScheme]; CRT_colorScheme = colorScheme; @@ -619,12 +606,8 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { keypad(stdscr, true); mouseinterval(0); curs_set(0); - if (has_colors()) { + if (has_colors()) start_color(); - CRT_hasColors = true; - } else { - CRT_hasColors = false; - } CRT_termType = getenv("TERM"); if (String_eq(CRT_termType, "linux")) CRT_scrollHAmount = 20; diff --git a/CRT.h b/CRT.h index 5b0b73048..ccbb69f6b 100644 --- a/CRT.h +++ b/CRT.h @@ -11,10 +11,6 @@ in the source distribution for its full text. #include -#define KEY_WHEELUP KEY_F(20) -#define KEY_WHEELDOWN KEY_F(21) -#define KEY_RECLICK KEY_F(22) - typedef enum TreeStr_ { TREE_STR_HORZ, TREE_STR_VERT, @@ -28,13 +24,13 @@ typedef enum TreeStr_ { typedef enum ColorSchemes_ { COLORSCHEME_DEFAULT = 0, - COLORSCHEME_MONOCHROME = 1, - COLORSCHEME_BLACKONWHITE = 2, - COLORSCHEME_LIGHTTERMINAL = 3, - COLORSCHEME_MIDNIGHT = 4, - COLORSCHEME_BLACKNIGHT = 5, - COLORSCHEME_BROKENGRAY = 6, - LAST_COLORSCHEME = 7, + COLORSCHEME_MONOCHROME, + COLORSCHEME_BLACKONWHITE, + COLORSCHEME_LIGHTTERMINAL, + COLORSCHEME_MIDNIGHT, + COLORSCHEME_BLACKNIGHT, + COLORSCHEME_BROKENGRAY, + LAST_COLORSCHEME, } ColorSchemes; typedef enum ColorElements_ { @@ -119,7 +115,10 @@ void CRT_fatalError(const char* note) ATTR_NORETURN; void CRT_handleSIGSEGV(int signal) ATTR_NORETURN; -#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) +#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')) #ifdef HAVE_LIBNCURSESW @@ -132,7 +131,7 @@ extern const char *const *CRT_treeStr; extern int CRT_delay; -extern int* CRT_colors; +extern const int* CRT_colors; extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT]; @@ -142,7 +141,7 @@ extern int CRT_scrollHAmount; extern int CRT_scrollWheelVAmount; -extern char* CRT_termType; +extern const char* CRT_termType; extern int CRT_colorScheme; @@ -155,11 +154,8 @@ void CRT_restorePrivileges(void); #else /* HAVE_SETUID_ENABLED */ /* Turn setuid operations into NOPs */ - -#ifndef CRT_dropPrivileges -#define CRT_dropPrivileges() -#define CRT_restorePrivileges() -#endif +static inline void CRT_dropPrivileges(void) { } +static inline void CRT_restorePrivileges(void) { } #endif /* HAVE_SETUID_ENABLED */ From 898a6903758ab64d59412c638322395f918537e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 12 Oct 2020 13:30:23 +0200 Subject: [PATCH 297/411] Do not hard-code line numbers in help screen building code --- Action.c | 60 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/Action.c b/Action.c index c4d71479d..c09c55114 100644 --- a/Action.c +++ b/Action.c @@ -28,6 +28,7 @@ in the source distribution for its full text. #include #include #include +#include #include #include @@ -448,11 +449,14 @@ static Htop_Reaction actionHelp(State* st) { for (int i = 0; i < LINES-1; i++) mvhline(i, 0, ' ', COLS); - mvaddstr(0, 0, "htop " VERSION " - " COPYRIGHT); - mvaddstr(1, 0, "Released under the GNU GPLv2. See 'man' page for more info."); + int line = 0; + + mvaddstr(line++, 0, "htop " VERSION " - " COPYRIGHT); + mvaddstr(line++, 0, "Released under the GNU GPLv2. See 'man' page for more info."); attrset(CRT_colors[DEFAULT_COLOR]); - mvaddstr(3, 0, "CPU usage bar: "); + line++; + mvaddstr(line++, 0, "CPU usage bar: "); #define addattrstr(a,s) attrset(a);addstr(s) addattrstr(CRT_colors[BAR_BORDER], "["); if (settings->detailedCPUTime) { @@ -474,7 +478,7 @@ static Htop_Reaction actionHelp(State* st) { } addattrstr(CRT_colors[BAR_BORDER], "]"); attrset(CRT_colors[DEFAULT_COLOR]); - mvaddstr(4, 0, "Memory bar: "); + mvaddstr(line++, 0, "Memory bar: "); addattrstr(CRT_colors[BAR_BORDER], "["); addattrstr(CRT_colors[MEMORY_USED], "used"); addstr("/"); addattrstr(CRT_colors[MEMORY_BUFFERS_TEXT], "buffers"); addstr("/"); @@ -482,29 +486,49 @@ static Htop_Reaction actionHelp(State* st) { addattrstr(CRT_colors[BAR_SHADOW], " used/total"); addattrstr(CRT_colors[BAR_BORDER], "]"); attrset(CRT_colors[DEFAULT_COLOR]); - mvaddstr(5, 0, "Swap bar: "); + mvaddstr(line++, 0, "Swap bar: "); addattrstr(CRT_colors[BAR_BORDER], "["); addattrstr(CRT_colors[SWAP], "used"); addattrstr(CRT_colors[BAR_SHADOW], " used/total"); addattrstr(CRT_colors[BAR_BORDER], "]"); attrset(CRT_colors[DEFAULT_COLOR]); - mvaddstr(6,0, "Type and layout of header meters are configurable in the setup screen."); + mvaddstr(line++,0, "Type and layout of header meters are configurable in the setup screen."); if (CRT_colorScheme == COLORSCHEME_MONOCHROME) { - mvaddstr(7, 0, "In monochrome, meters display as different chars, in order: |#*@$%&."); + mvaddstr(line, 0, "In monochrome, meters display as different chars, in order: |#*@$%&."); } - mvaddstr( 8, 0, " Status: R: running; S: sleeping; T: traced/stopped; Z: zombie; D: disk sleep"); - for (int i = 0; helpLeft[i].info; i++) { mvaddstr(9+i, 9, helpLeft[i].info); } - for (int i = 0; helpRight[i].info; i++) { mvaddstr(9+i, 49, helpRight[i].info); } - attrset(CRT_colors[HELP_BOLD]); - for (int i = 0; helpLeft[i].key; i++) { mvaddstr(9+i, 0, helpLeft[i].key); } - for (int i = 0; helpRight[i].key; i++) { mvaddstr(9+i, 40, helpRight[i].key); } - attrset(CRT_colors[PROCESS_THREAD]); - mvaddstr(17, 32, "threads"); - mvaddstr(18, 26, "threads"); - attrset(CRT_colors[DEFAULT_COLOR]); + line++; + + mvaddstr(line++, 0, "Process state: R: running; S: sleeping; T: traced/stopped; Z: zombie; D: disk sleep"); + + line++; + + int item; + for (item = 0; helpLeft[item].key; item++) { + attrset(CRT_colors[DEFAULT_COLOR]); + mvaddstr(line + item, 9, helpLeft[item].info); + attrset(CRT_colors[HELP_BOLD]); + mvaddstr(line + item, 0, helpLeft[item].key); + if (0 == strcmp(helpLeft[item].key, " H: ")) { + attrset(CRT_colors[PROCESS_THREAD]); + mvaddstr(line + item, 32, "threads"); + } else if (0 == strcmp(helpLeft[item].key, " K: ")) { + attrset(CRT_colors[PROCESS_THREAD]); + mvaddstr(line + item, 26, "threads"); + } + } + int leftHelpItems = item; + + for (item = 0; helpRight[item].key; item++) { + attrset(CRT_colors[HELP_BOLD]); + mvaddstr(line + item, 40, helpRight[item].key); + attrset(CRT_colors[DEFAULT_COLOR]); + mvaddstr(line + item, 49, helpRight[item].info); + } + line += MAXIMUM(leftHelpItems, item); + line++; attrset(CRT_colors[HELP_BOLD]); - mvaddstr(24,0, "Press any key to return."); + mvaddstr(line++, 0, "Press any key to return."); attrset(CRT_colors[DEFAULT_COLOR]); refresh(); CRT_readKey(); From 2f9381d8671d560f40986faffea87f19ce965a1b Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Thu, 15 Oct 2020 07:25:03 +0200 Subject: [PATCH 298/411] Keep building on errors Doing so allows for more than one error to be detected in builds --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5eb002ccb..8e1d130ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - name: Configure run: ./configure --enable-werror --enable-linux-affinity - name: Build - run: make + run: make -k - name: Distcheck run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity" @@ -36,7 +36,7 @@ jobs: - name: Configure run: ./configure --enable-werror --enable-linux-affinity - name: Build - run: make + run: make -k - name: Distcheck run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity" @@ -51,7 +51,7 @@ jobs: - name: Configure run: ./configure --enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct - name: Build - run: make + run: make -k - name: Distcheck run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct' From bfa7d1fbe275c6b7551af3afa99f4e90eaa315e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 14 Oct 2020 15:19:23 +0200 Subject: [PATCH 299/411] Mark search parameter in Vector_indexOf const --- Vector.c | 6 +++--- Vector.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Vector.c b/Vector.c index a12d6bb5b..aa3168051 100644 --- a/Vector.c +++ b/Vector.c @@ -288,9 +288,9 @@ void Vector_add(Vector* this, void* data_) { assert(Vector_isConsistent(this)); } -int Vector_indexOf(Vector* this, void* search_, Object_Compare compare) { - Object* search = search_; - assert(Object_isA((Object*)search, this->type)); +int Vector_indexOf(Vector* this, const void* search_, Object_Compare compare) { + const Object* search = search_; + assert(Object_isA(search, this->type)); assert(compare); assert(Vector_isConsistent(this)); for (int i = 0; i < this->items; i++) { diff --git a/Vector.h b/Vector.h index d0d42c6cf..1b599d69f 100644 --- a/Vector.h +++ b/Vector.h @@ -61,7 +61,7 @@ int Vector_count(Vector* this); void Vector_add(Vector* this, void* data_); -int Vector_indexOf(Vector* this, void* search_, Object_Compare compare); +int Vector_indexOf(Vector* this, const void* search_, Object_Compare compare); void Vector_splice(Vector* this, Vector* from); From 3c08fa3c638df1b275d106062e6b3c2dd3950100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 15 Oct 2020 20:33:26 +0200 Subject: [PATCH 300/411] Keep building on errors Doing so allows for more than one error to be detected in builds --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b86e51035..d870aa543 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,5 +13,5 @@ script: - ./autogen.sh # clang might warn about C11 generic selections in isnan() - CFLAGS=-Wno-c11-extensions ./configure --enable-werror - - make + - make -k - CFLAGS=-Wno-c11-extensions make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror From 846fe8a71fd8ee5d91b297610e885b93ca039cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 15 Oct 2020 20:41:35 +0200 Subject: [PATCH 301/411] Mark Vector parameter const for non-modifying functions --- Vector.c | 10 +++++----- Vector.h | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Vector.c b/Vector.c index aa3168051..adc898e6a 100644 --- a/Vector.c +++ b/Vector.c @@ -40,7 +40,7 @@ void Vector_delete(Vector* this) { #ifndef NDEBUG -static bool Vector_isConsistent(Vector* this) { +static bool Vector_isConsistent(const Vector* this) { assert(this->items <= this->arraySize); if (this->owner) { for (int i = 0; i < this->items; i++) @@ -52,7 +52,7 @@ static bool Vector_isConsistent(Vector* this) { } } -int Vector_count(Vector* this) { +int Vector_count(const Vector* this) { int items = 0; for (int i = 0; i < this->items; i++) { if (this->array[i]) @@ -68,7 +68,7 @@ Object* Vector_get(Vector* this, int idx) { return this->array[idx]; } -int Vector_size(Vector* this) { +int Vector_size(const Vector* this) { assert(Vector_isConsistent(this)); return this->items; } @@ -288,13 +288,13 @@ void Vector_add(Vector* this, void* data_) { assert(Vector_isConsistent(this)); } -int Vector_indexOf(Vector* this, const void* search_, Object_Compare compare) { +int Vector_indexOf(const Vector* this, const void* search_, Object_Compare compare) { const Object* search = search_; assert(Object_isA(search, this->type)); assert(compare); assert(Vector_isConsistent(this)); for (int i = 0; i < this->items; i++) { - Object* o = this->array[i]; + const Object* o = this->array[i]; assert(o); if (compare(search, o) == 0) return i; diff --git a/Vector.h b/Vector.h index 1b599d69f..491779b36 100644 --- a/Vector.h +++ b/Vector.h @@ -49,8 +49,8 @@ void Vector_set(Vector* this, int idx, void* data_); #ifndef NDEBUG Object* Vector_get(Vector* this, int idx); -int Vector_size(Vector* this); -int Vector_count(Vector* this); +int Vector_size(const Vector* this); +int Vector_count(const Vector* this); #else /* NDEBUG */ @@ -61,7 +61,7 @@ int Vector_count(Vector* this); void Vector_add(Vector* this, void* data_); -int Vector_indexOf(Vector* this, const void* search_, Object_Compare compare); +int Vector_indexOf(const Vector* this, const void* search_, Object_Compare compare); void Vector_splice(Vector* this, Vector* from); From 1d00893110bd7cc68b49c751d4fd734610eac959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 15 Oct 2020 21:12:57 +0200 Subject: [PATCH 302/411] Automatically detect if backtrace(3) needs -lexecinfo --- Makefile.am | 3 +-- configure.ac | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index b6f0f975e..085f763af 100644 --- a/Makefile.am +++ b/Makefile.am @@ -154,7 +154,6 @@ freebsd_platform_headers = \ zfs/openzfs_sysctl.h if HTOP_FREEBSD -AM_LDFLAGS += -lexecinfo myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ freebsd/FreeBSDProcess.c freebsd/Battery.c \ zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c @@ -172,7 +171,7 @@ dragonflybsd_platform_headers = \ dragonflybsd/Battery.h if HTOP_DRAGONFLYBSD -AM_LDFLAGS += -lkvm -lkinfo -lexecinfo +AM_LDFLAGS += -lkvm -lkinfo myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \ dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/Battery.c diff --git a/configure.ac b/configure.ac index 31d4a57c4..b10d819ad 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,9 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM( [AC_MSG_ERROR([htop is written in C99. A newer compiler is required.])]) CFLAGS="$save_cflags" +# Add -lexecinfo if needed +AC_SEARCH_LIBS([backtrace], [execinfo]) + # Checks for features and flags. # ---------------------------------------------------------------------- PROCDIR=/proc From af4f58d0136fedca4894194daf89ab242167185d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 15 Oct 2020 22:35:44 +0200 Subject: [PATCH 303/411] Misc conversion fixes --- Action.c | 2 +- TraceScreen.c | 6 +++--- htop.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Action.c b/Action.c index c4d71479d..6d7782ca3 100644 --- a/Action.c +++ b/Action.c @@ -107,7 +107,7 @@ bool Action_setUserOnly(const char* userName, uid_t* userId) { *userId = user->pw_uid; return true; } - *userId = -1; + *userId = (uid_t)-1; return false; } diff --git a/TraceScreen.c b/TraceScreen.c index 8e5f61e70..2956b5696 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -109,13 +109,13 @@ void TraceScreen_updateTrace(InfoScreen* super) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 500; int ready = select(this->fd_strace+1, &fds, NULL, NULL, &tv); - int nread = 0; + size_t nread = 0; if (ready > 0 && FD_ISSET(this->fd_strace, &fds)) nread = fread(buffer, 1, sizeof(buffer) - 1, this->strace); if (nread && this->tracing) { - char* line = buffer; + const char* line = buffer; buffer[nread] = '\0'; - for (int i = 0; i < nread; i++) { + for (size_t i = 0; i < nread; i++) { if (buffer[i] == '\n') { buffer[i] = '\0'; if (this->contLine) { diff --git a/htop.c b/htop.c index 44182ae19..8c813564f 100644 --- a/htop.c +++ b/htop.c @@ -74,7 +74,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { CommandLineSettings flags = { .pidMatchList = NULL, .commFilter = NULL, - .userId = -1, // -1 is guaranteed to be an invalid uid_t (see setreuid(2)) + .userId = (uid_t)-1, // -1 is guaranteed to be an invalid uid_t (see setreuid(2)) .sortKey = 0, .delay = -1, .useColors = true, From d744dac7ee6a651670387b6cc83878ef82202839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 7 Oct 2020 17:18:02 +0200 Subject: [PATCH 304/411] Add SELinuxMeter --- Makefile.am | 26 ++++++++----- linux/Platform.c | 2 + linux/SELinuxMeter.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ linux/SELinuxMeter.h | 14 +++++++ 4 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 linux/SELinuxMeter.c create mode 100644 linux/SELinuxMeter.h diff --git a/Makefile.am b/Makefile.am index 085f763af..83ada4509 100644 --- a/Makefile.am +++ b/Makefile.am @@ -119,23 +119,31 @@ myhtopheaders = \ # ----- linux_platform_headers = \ - linux/Platform.h \ - linux/IOPriorityPanel.h \ + linux/Battery.h \ linux/IOPriority.h \ + linux/IOPriorityPanel.h \ linux/LinuxProcess.h \ linux/LinuxProcessList.h \ - linux/Battery.h \ + linux/Platform.h \ linux/PressureStallMeter.h \ + linux/SELinuxMeter.h \ zfs/ZfsArcMeter.h \ - zfs/ZfsCompressedArcMeter.h \ - zfs/ZfsArcStats.h + zfs/ZfsArcStats.h \ + zfs/ZfsCompressedArcMeter.h if HTOP_LINUX AM_LDFLAGS += -rdynamic -myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c \ -linux/LinuxProcess.c linux/LinuxProcessList.c linux/Battery.c \ -linux/PressureStallMeter.c \ -zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c +myhtopplatsources = \ + linux/Battery.c \ + linux/IOPriorityPanel.c \ + linux/LinuxProcess.c \ + linux/LinuxProcessList.c \ + linux/Platform.c \ + linux/PressureStallMeter.c \ + linux/SELinuxMeter.c \ + zfs/ZfsArcMeter.c \ + zfs/ZfsArcStats.c \ + zfs/ZfsCompressedArcMeter.c myhtopplatheaders = $(linux_platform_headers) endif diff --git a/linux/Platform.c b/linux/Platform.c index e0a035483..c78264182 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -28,6 +28,7 @@ in the source distribution for its full text. #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" #include "LinuxProcess.h" +#include "SELinuxMeter.h" #include "StringUtils.h" #include @@ -139,6 +140,7 @@ const MeterClass* const Platform_meterTypes[] = { &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, &DiskIOMeter_class, + &SELinuxMeter_class, NULL }; diff --git a/linux/SELinuxMeter.c b/linux/SELinuxMeter.c new file mode 100644 index 000000000..8562215b5 --- /dev/null +++ b/linux/SELinuxMeter.c @@ -0,0 +1,91 @@ +/* +htop - SELinuxMeter.c +(C) 2020 Christian Goettsche +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "SELinuxMeter.h" + +#include "CRT.h" + +#include +#include +#include +#include +#include +#include +#include + + +static const int SELinuxMeter_attributes[] = { + METER_TEXT, +}; + +static bool enabled = false; +static bool enforcing = false; + +static bool hasSELinuxMount(void) { + struct statfs sfbuf; + int r = statfs("/sys/fs/selinux", &sfbuf); + if (r != 0) + return false; + + if (sfbuf.f_type != SELINUX_MAGIC) + return false; + + struct statvfs vfsbuf; + r = statvfs("/sys/fs/selinux", &vfsbuf); + if (r != 0 || (vfsbuf.f_flag & ST_RDONLY)) + return false; + + return true; +} + +static bool isSelinuxEnabled(void) { + return hasSELinuxMount() && (0 == access("/etc/selinux/config", F_OK)); +} + +static bool isSelinuxEnforcing(void) { + if (!enabled) + return false; + + int fd = open("/sys/fs/selinux/enforce", O_RDONLY); + if (fd < 0) + return false; + + char buf[20] = {0}; + int r = read(fd, buf, sizeof(buf) - 1); + close(fd); + if (r < 0) + return false; + + int enforce = 0; + if (sscanf(buf, "%d", &enforce) != 1) + return false; + + return !!enforce; +} + +static void SELinuxMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, int len) { + enabled = isSelinuxEnabled(); + enforcing = isSelinuxEnforcing(); + + xSnprintf(buffer, len, "%s%s", enabled ? "enabled" : "disabled", enabled ? (enforcing ? "; mode: enforcing" : "; mode: permissive") : ""); +} + +const MeterClass SELinuxMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + }, + .updateValues = SELinuxMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 0, + .total = 100.0, + .attributes = SELinuxMeter_attributes, + .name = "SELinux", + .uiName = "SELinux", + .description = "SELinux state overview", + .caption = "SELinux: " +}; diff --git a/linux/SELinuxMeter.h b/linux/SELinuxMeter.h new file mode 100644 index 000000000..02362bf1e --- /dev/null +++ b/linux/SELinuxMeter.h @@ -0,0 +1,14 @@ +#ifndef HEADER_SELinuxMeter +#define HEADER_SELinuxMeter +/* +htop - SELinuxMeter.h +(C) 2020 Christian Goettsche +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern const MeterClass SELinuxMeter_class; + +#endif /* HEADER_SELinuxMeter */ From 783be7711db0081a77fbcf84fbb63ab2a31ccc05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 12 Oct 2020 12:51:18 +0200 Subject: [PATCH 305/411] Do not use extra starttime process field on Linux --- linux/LinuxProcess.c | 13 ------------- linux/LinuxProcess.h | 1 - linux/LinuxProcessList.c | 13 ++++++++++--- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index ba0779fbc..68baf96d1 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -225,13 +225,6 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) case STIME: Process_printTime(str, lp->stime); return; case CUTIME: Process_printTime(str, lp->cutime); return; case CSTIME: Process_printTime(str, lp->cstime); return; - case STARTTIME: { - struct tm date; - time_t starttimewall = btime + (lp->starttime / sysconf(_SC_CLK_TCK)); - (void) localtime_r(&starttimewall, &date); - strftime(buffer, n, ((starttimewall > time(NULL) - 86400) ? "%R " : "%b%d "), &date); - break; - } #ifdef HAVE_TASKSTATS case RCHAR: Process_colorNumber(str, lp->io_rchar, coloring); return; case WCHAR: Process_colorNumber(str, lp->io_wchar, coloring); return; @@ -334,12 +327,6 @@ long LinuxProcess_compare(const void* v1, const void* v2) { case CUTIME: diff = p2->cutime - p1->cutime; goto test_diff; case STIME: diff = p2->stime - p1->stime; goto test_diff; case CSTIME: diff = p2->cstime - p1->cstime; goto test_diff; - case STARTTIME: { - if (p1->starttime == p2->starttime) - return (p1->super.pid - p2->super.pid); - else - return (p1->starttime - p2->starttime); - } #ifdef HAVE_TASKSTATS case RCHAR: diff = p2->io_rchar - p1->io_rchar; goto test_diff; case WCHAR: diff = p2->io_wchar - p1->io_wchar; goto test_diff; diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 8113193f9..ac80317db 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -107,7 +107,6 @@ typedef struct LinuxProcess_ { long m_drs; long m_lrs; long m_dt; - unsigned long long starttime; #ifdef HAVE_TASKSTATS unsigned long long io_rchar; unsigned long long io_wchar; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 7a31debfe..ceb7f7bfd 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -260,9 +260,8 @@ void ProcessList_delete(ProcessList* pl) { free(this); } -static double jiffy = NAN; - static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { + static double jiffy = NAN; if(isnan(jiffy)) { errno = 0; long sc_jiffy = sysconf(_SC_CLK_TCK); @@ -345,7 +344,11 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, process->nlwp = strtol(location, &location, 10); location += 1; location = strchr(location, ' ')+1; - lp->starttime = strtoll(location, &location, 10); + if (process->starttime_ctime == 0) { + process->starttime_ctime = btime + LinuxProcess_adjustTime(strtoll(location, &location, 10)) / 100; + } else { + location = strchr(location, ' ')+1; + } location += 1; for (int i=0; i<15; i++) location = strchr(location, ' ')+1; process->exit_signal = strtol(location, &location, 10); @@ -1032,6 +1035,10 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* goto errorReadingProcess; } + struct tm date; + (void) localtime_r(&proc->starttime_ctime, &date); + strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date); + ProcessList_add(pl, proc); } else { if (settings->updateProcessNames && proc->state != 'Z') { From a63cfc8b7c172aa7e849521a479d39af737681a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 13 Oct 2020 14:26:40 +0200 Subject: [PATCH 306/411] Refactor generating starttime string into Process class --- Process.c | 6 ++++++ Process.h | 2 ++ darwin/DarwinProcess.c | 14 ++++---------- darwin/DarwinProcess.h | 4 +--- darwin/DarwinProcessList.c | 5 +---- freebsd/FreeBSDProcessList.c | 8 +------- linux/LinuxProcessList.c | 4 +--- openbsd/OpenBSDProcessList.c | 7 +------ solaris/SolarisProcessList.c | 7 +------ unsupported/UnsupportedProcessList.c | 2 +- 10 files changed, 19 insertions(+), 40 deletions(-) diff --git a/Process.c b/Process.c index 2d5ffb4fe..43a4c47e4 100644 --- a/Process.c +++ b/Process.c @@ -181,6 +181,12 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths) { } } +void Process_fillStarttimeBuffer(Process* this) { + struct tm date; + (void) localtime_r(&this->starttime_ctime, &date); + strftime(this->starttime_show, sizeof(this->starttime_show) - 1, (this->starttime_ctime > (time(NULL) - 86400)) ? "%R " : "%b%d ", &date); +} + static inline void Process_writeCommand(const Process* this, int attr, int baseattr, RichString* str) { int start = RichString_size(str), finish = 0; const char* comm = this->comm; diff --git a/Process.h b/Process.h index 7e1bda681..a4abf03e4 100644 --- a/Process.h +++ b/Process.h @@ -156,6 +156,8 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori void Process_printTime(RichString* str, unsigned long long totalHundredths); +void Process_fillStarttimeBuffer(Process* this); + void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring); void Process_display(const Object* cast, RichString* out); diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 8c90c2a59..48574e2f7 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -50,14 +50,6 @@ bool Process_isThread(const Process* this) { return false; } -void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now) { - struct tm date; - - proc->starttime_ctime = ep->p_starttime.tv_sec; - (void) localtime_r(&proc->starttime_ctime, &date); - strftime(proc->starttime_show, 7, ((proc->starttime_ctime > now - 86400) ? "%R " : "%b%d "), &date); -} - char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { /* This function is from the old Mac version of htop. Originally from ps? */ int mib[3], argmax, nargs, c = 0; @@ -201,7 +193,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { return retval; } -void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists) { +void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists) { struct extern_proc *ep = &ps->kp_proc; /* UNSET HERE : @@ -231,7 +223,9 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t /* e_tdev == -1 for "no device" */ proc->tty_nr = ps->kp_eproc.e_tdev & 0xff; /* TODO tty_nr is unsigned */ - DarwinProcess_setStartTime(proc, ep, now); + proc->starttime_ctime = ep->p_starttime.tv_sec; + Process_fillStarttimeBuffer(proc); + proc->comm = DarwinProcess_getCmdLine(ps, &(proc->basenameOffset)); } diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index fc932afee..69a1d63b3 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -28,11 +28,9 @@ void Process_delete(Object* cast); bool Process_isThread(const Process* this); -void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now); - char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset); -void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists); +void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists); void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl); diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index ad8488771..10d0697fb 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -150,9 +150,6 @@ void ProcessList_goThroughEntries(ProcessList* super) { struct kinfo_proc *ps; size_t count; DarwinProcess *proc; - struct timeval tv; - - gettimeofday(&tv, NULL); /* Start processing time */ /* Update the global data (CPU times and VM stats) */ ProcessList_freeCPULoadInfo(&dpl->prev_load); @@ -187,7 +184,7 @@ void ProcessList_goThroughEntries(ProcessList* super) { for(size_t i = 0; i < count; ++i) { proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new); - DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting); + DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); DarwinProcess_setFromLibprocPidinfo(proc, dpl); // Disabled for High Sierra due to bug in macOS High Sierra diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 71f87e16e..92620c9b1 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -389,14 +389,10 @@ void ProcessList_goThroughEntries(ProcessList* this) { int count = 0; struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count); - struct timeval tv; - gettimeofday(&tv, NULL); - for (int i = 0; i < count; i++) { struct kinfo_proc* kproc = &kprocs[i]; bool preExisting = false; // TODO: bool isIdleProcess = false; - struct tm date; Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, (Process_New) FreeBSDProcess_new); FreeBSDProcess* fp = (FreeBSDProcess*) proc; @@ -417,6 +413,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->pgrp = kproc->ki_pgid; proc->st_uid = kproc->ki_uid; proc->starttime_ctime = kproc->ki_start.tv_sec; + Process_fillStarttimeBuffer(proc); proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); ProcessList_add((ProcessList*)this, proc); proc->comm = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->basenameOffset); @@ -490,9 +487,6 @@ void ProcessList_goThroughEntries(ProcessList* this) { this->kernelThreads++; } - (void) localtime_r((time_t*) &proc->starttime_ctime, &date); - strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date); - this->totalTasks++; if (proc->state == 'R') this->runningTasks++; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index ceb7f7bfd..6dcc5e5a9 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1035,9 +1035,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* goto errorReadingProcess; } - struct tm date; - (void) localtime_r(&proc->starttime_ctime, &date); - strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date); + Process_fillStarttimeBuffer(proc); ProcessList_add(pl, proc); } else { diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index c3ba763af..4b0307073 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -192,8 +192,6 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { bool preExisting; Process* proc; OpenBSDProcess* fp; - struct tm date; - struct timeval tv; int count = 0; int i; @@ -201,8 +199,6 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { struct kinfo_proc* kprocs = kvm_getprocs(this->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count); //struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count); - gettimeofday(&tv, NULL); - for (i = 0; i < count; i++) { kproc = &kprocs[i]; @@ -222,11 +218,10 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { proc->pgrp = kproc->p__pgid; proc->st_uid = kproc->p_uid; proc->starttime_ctime = kproc->p_ustart_sec; + Process_fillStarttimeBuffer(proc); proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid); ProcessList_add(&this->super, proc); proc->comm = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->basenameOffset); - (void) localtime_r((time_t*) &kproc->p_ustart_sec, &date); - strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date); } else { if (settings->updateProcessNames) { free(proc->comm); diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index dbbd54c26..9662f8304 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -260,8 +260,6 @@ void ProcessList_delete(ProcessList* pl) { */ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr) { - struct timeval tv; - struct tm date; bool preExisting; pid_t getpid; @@ -281,8 +279,6 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, (Process_New) SolarisProcess_new); SolarisProcess *sproc = (SolarisProcess*) proc; - gettimeofday(&tv, NULL); - // Common code pass 1 proc->show = false; sproc->taskid = _psinfo->pr_taskid; @@ -368,8 +364,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * } else { sproc->kernel = false; } - (void) localtime_r((time_t*) &proc->starttime_ctime, &date); - strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date); + Process_fillStarttimeBuffer(proc); ProcessList_add(pl, proc); } proc->updated = true; diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index 3531d0f92..40a24c282 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -56,8 +56,8 @@ void ProcessList_goThroughEntries(ProcessList* super) { proc->priority = 0; proc->nice = 0; proc->nlwp = 1; - strncpy(proc->starttime_show, "Jun 01 ", sizeof(proc->starttime_show)); proc->starttime_ctime = 1433116800; // Jun 01, 2015 + Process_fillStarttimeBuffer(proc); proc->m_size = 100; proc->m_resident = 100; From e9246abff8010ec9a9624f004364a3851b6daad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 15 Oct 2020 21:45:38 +0200 Subject: [PATCH 307/411] Misc Vector updates - Move swap() macro to source file and implement as function - Implement Vector_get() and Vector_size() as inline functions to make them type safe and avoid lhs usage - Comment comparison statistics, they are only needed for performance testing --- ProcessList.c | 4 ++-- Vector.c | 25 +++++++++++++++++-------- Vector.h | 12 ++++++++---- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/ProcessList.c b/ProcessList.c index e509b8976..1b364cfcf 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -127,12 +127,12 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i Process* process = (Process*) (Vector_get(children, i)); if (!show) process->show = false; - int s = this->processes2->items; + int s = Vector_size(this->processes2); if (direction == 1) Vector_add(this->processes2, process); else Vector_insert(this->processes2, 0, process); - assert(this->processes2->items == s+1); (void)s; + assert(Vector_size(this->processes2) == s+1); (void)s; int nextIndent = indent | (1 << level); ProcessList_buildTree(this, process->pid, level+1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false); if (i == size - 1) diff --git a/Vector.c b/Vector.c index adc898e6a..291ef48fc 100644 --- a/Vector.c +++ b/Vector.c @@ -18,6 +18,7 @@ Vector* Vector_new(const ObjectClass* type, bool owner, int size) { if (size == DEFAULT_SIZE) size = 10; + assert(size > 0); this = xMalloc(sizeof(Vector)); this->growthRate = size; this->array = (Object**) xCalloc(size, sizeof(Object*)); @@ -87,14 +88,22 @@ void Vector_prune(Vector* this) { this->items = 0; } -static int comparisons = 0; +//static int comparisons = 0; + +static void swap(Object** array, int indexA, int indexB) { + assert(indexA >= 0); + assert(indexB >= 0); + Object* tmp = array[indexA]; + array[indexA] = array[indexB]; + array[indexB] = tmp; +} static int partition(Object** array, int left, int right, int pivotIndex, Object_Compare compare) { - void* pivotValue = array[pivotIndex]; + const Object* pivotValue = array[pivotIndex]; swap(array, pivotIndex, right); int storeIndex = left; for (int i = left; i < right; i++) { - comparisons++; + //comparisons++; if (compare(array[i], pivotValue) <= 0) { swap(array, i, storeIndex); storeIndex++; @@ -138,10 +147,10 @@ static void combSort(Object** array, int left, int right, Object_Compare compare static void insertionSort(Object** array, int left, int right, Object_Compare compare) { for (int i = left+1; i <= right; i++) { - void* t = array[i]; + Object* t = array[i]; int j = i - 1; while (j >= left) { - comparisons++; + //comparisons++; if (compare(array[j], t) <= 0) break; array[j+1] = array[j]; @@ -202,7 +211,7 @@ Object* Vector_take(Vector* this, int idx) { assert(idx >= 0 && idx < this->items); assert(Vector_isConsistent(this)); Object* removed = this->array[idx]; - //assert (removed != NULL); + assert(removed); this->items--; if(idx < this->items) { memmove(&this->array[idx], &this->array[idx + 1], (this->items - idx) * sizeof(this->array[0])); @@ -244,7 +253,7 @@ void Vector_moveDown(Vector* this, int idx) { void Vector_set(Vector* this, int idx, void* data_) { Object* data = data_; assert(idx >= 0); - assert(Object_isA((Object*)data, this->type)); + assert(Object_isA(data, this->type)); assert(Vector_isConsistent(this)); Vector_checkArraySize(this); @@ -280,7 +289,7 @@ static void Vector_merge(Vector* this, Vector* v2) { void Vector_add(Vector* this, void* data_) { Object* data = data_; - assert(Object_isA((Object*)data, this->type)); + assert(Object_isA(data, this->type)); assert(Vector_isConsistent(this)); int i = this->items; Vector_set(this, this->items, data); diff --git a/Vector.h b/Vector.h index 491779b36..428b931d0 100644 --- a/Vector.h +++ b/Vector.h @@ -9,10 +9,9 @@ in the source distribution for its full text. #include "Object.h" -#define swap(a_,x_,y_) do{ void* tmp_ = a_[x_]; a_[x_] = a_[y_]; a_[y_] = tmp_; }while(0) #ifndef DEFAULT_SIZE -#define DEFAULT_SIZE -1 +#define DEFAULT_SIZE (-1) #endif typedef struct Vector_ { @@ -54,8 +53,13 @@ int Vector_count(const Vector* this); #else /* NDEBUG */ -#define Vector_get(v_, idx_) ((v_)->array[idx_]) -#define Vector_size(v_) ((v_)->items) +static inline Object* Vector_get(Vector* this, int idx) { + return this->array[idx]; +} + +static inline int Vector_size(const Vector* this) { + return this->items; +} #endif /* NDEBUG */ From a8029612862e6ef6ab55b2f7adc2c8b4ac554cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 16 Oct 2020 19:44:53 +0200 Subject: [PATCH 308/411] Generalize Meter value colors for IO --- CRT.c | 36 ++++++++++++++++++------------------ CRT.h | 6 +++--- DiskIOMeter.c | 12 ++++++------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CRT.c b/CRT.c index 1469ff3dd..06ce04512 100644 --- a/CRT.c +++ b/CRT.c @@ -96,6 +96,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), [METER_TEXT] = ColorPair(Cyan,Black), [METER_VALUE] = A_BOLD | ColorPair(Cyan,Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Black), + [METER_VALUE_IOREAD] = ColorPair(Green,Black), + [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), [LED_COLOR] = ColorPair(Green,Black), [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black), [PROCESS] = A_NORMAL, @@ -151,9 +154,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Blue,Black), [ZFS_RATIO] = ColorPair(Magenta,Black), - [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(White,Black), - [DISKIO_READ] = ColorPair(Green,Black), - [DISKIO_WRITE] = ColorPair(Blue,Black), }, [COLORSCHEME_MONOCHROME] = { [RESET_COLOR] = A_NORMAL, @@ -172,6 +172,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = A_BOLD, [METER_TEXT] = A_NORMAL, [METER_VALUE] = A_BOLD, + [METER_VALUE_NOTICE] = A_BOLD, + [METER_VALUE_IOREAD] = A_NORMAL, + [METER_VALUE_IOWRITE] = A_NORMAL, [LED_COLOR] = A_NORMAL, [TASKS_RUNNING] = A_BOLD, [PROCESS] = A_NORMAL, @@ -227,9 +230,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_DIM, [ZFS_COMPRESSED] = A_BOLD, [ZFS_RATIO] = A_BOLD, - [DISKIO_UTIL_HIGH] = A_BOLD, - [DISKIO_READ] = A_NORMAL, - [DISKIO_WRITE] = A_NORMAL, }, [COLORSCHEME_BLACKONWHITE] = { [RESET_COLOR] = ColorPair(Black,White), @@ -248,6 +248,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = ColorPair(Red,White), [METER_TEXT] = ColorPair(Blue,White), [METER_VALUE] = ColorPair(Black,White), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,White), + [METER_VALUE_IOREAD] = ColorPair(Green,White), + [METER_VALUE_IOWRITE] = ColorPair(Yellow,White), [LED_COLOR] = ColorPair(Green,White), [TASKS_RUNNING] = ColorPair(Green,White), [PROCESS] = ColorPair(Black,White), @@ -303,9 +306,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta,White), [ZFS_COMPRESSED] = ColorPair(Cyan,White), [ZFS_RATIO] = ColorPair(Magenta,White), - [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(Yellow,White), - [DISKIO_READ] = ColorPair(Green,White), - [DISKIO_WRITE] = ColorPair(Blue,White), }, [COLORSCHEME_LIGHTTERMINAL] = { [RESET_COLOR] = ColorPair(Blue,Black), @@ -324,6 +324,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = ColorPair(Red,Black), [METER_TEXT] = ColorPair(Blue,Black), [METER_VALUE] = ColorPair(Blue,Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), + [METER_VALUE_IOREAD] = ColorPair(Green,Black), + [METER_VALUE_IOWRITE] = ColorPair(Yellow,Black), [LED_COLOR] = ColorPair(Green,Black), [TASKS_RUNNING] = ColorPair(Green,Black), [PROCESS] = ColorPair(Blue,Black), @@ -379,9 +382,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Cyan,Black), [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Black), - [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(Yellow,Black), - [DISKIO_READ] = ColorPair(Green,Black), - [DISKIO_WRITE] = ColorPair(Blue,Black), }, [COLORSCHEME_MIDNIGHT] = { [RESET_COLOR] = ColorPair(White,Blue), @@ -400,6 +400,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Blue), [METER_TEXT] = ColorPair(Cyan,Blue), [METER_VALUE] = A_BOLD | ColorPair(Cyan,Blue), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Blue), + [METER_VALUE_IOREAD] = ColorPair(Green,Blue), + [METER_VALUE_IOWRITE] = ColorPair(Black,Blue), [LED_COLOR] = ColorPair(Green,Blue), [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Blue), [PROCESS] = ColorPair(White,Blue), @@ -455,9 +458,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Blue), [ZFS_COMPRESSED] = A_BOLD | ColorPair(White,Blue), [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Blue), - [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(White,Blue), - [DISKIO_READ] = ColorPair(Green,Blue), - [DISKIO_WRITE] = ColorPair(Black,Blue), }, [COLORSCHEME_BLACKNIGHT] = { [RESET_COLOR] = ColorPair(Cyan,Black), @@ -476,6 +476,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), [METER_TEXT] = ColorPair(Cyan,Black), [METER_VALUE] = ColorPair(Green,Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), + [METER_VALUE_IOREAD] = ColorPair(Green,Black), + [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), [LED_COLOR] = ColorPair(Green,Black), [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black), [PROCESS] = ColorPair(Cyan,Black), @@ -529,9 +532,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Blue,Black), [ZFS_RATIO] = ColorPair(Magenta,Black), - [DISKIO_UTIL_HIGH] = A_BOLD | ColorPair(Green,Black), - [DISKIO_READ] = ColorPair(Green,Black), - [DISKIO_WRITE] = ColorPair(Blue,Black), }, [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. }; diff --git a/CRT.h b/CRT.h index ccbb69f6b..fa2f6de72 100644 --- a/CRT.h +++ b/CRT.h @@ -48,6 +48,9 @@ typedef enum ColorElements_ { LARGE_NUMBER, METER_TEXT, METER_VALUE, + METER_VALUE_NOTICE, + METER_VALUE_IOREAD, + METER_VALUE_IOWRITE, LED_COLOR, UPTIME, BATTERY, @@ -105,9 +108,6 @@ typedef enum ColorElements_ { ZFS_OTHER, ZFS_COMPRESSED, ZFS_RATIO, - DISKIO_UTIL_HIGH, - DISKIO_READ, - DISKIO_WRITE, LAST_COLORELEMENT } ColorElements; diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 6baca32c5..8393af705 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -14,9 +14,9 @@ in the source distribution for its full text. static const int DiskIOMeter_attributes[] = { - DISKIO_UTIL_HIGH, - DISKIO_READ, - DISKIO_WRITE, + METER_VALUE_NOTICE, + METER_VALUE_IOREAD, + METER_VALUE_IOWRITE, }; static unsigned long int cached_read_diff = 0; @@ -62,17 +62,17 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) { static void DIskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { char buffer[16]; - int color = cached_utilisation_diff > 40.0 ? DISKIO_UTIL_HIGH : METER_VALUE; + int color = cached_utilisation_diff > 40.0 ? METER_VALUE_NOTICE : METER_VALUE; xSnprintf(buffer, sizeof(buffer), "%.1f%%", cached_utilisation_diff); RichString_write(out, CRT_colors[color], buffer); RichString_append(out, CRT_colors[METER_TEXT], " read: "); Meter_humanUnit(buffer, cached_read_diff, sizeof(buffer)); - RichString_append(out, CRT_colors[DISKIO_READ], buffer); + RichString_append(out, CRT_colors[METER_VALUE_IOREAD], buffer); RichString_append(out, CRT_colors[METER_TEXT], " write: "); Meter_humanUnit(buffer, cached_write_diff, sizeof(buffer)); - RichString_append(out, CRT_colors[DISKIO_WRITE], buffer); + RichString_append(out, CRT_colors[METER_VALUE_IOWRITE], buffer); } const MeterClass DiskIOMeter_class = { From 7cd093ce95c1f59cfc1ee2786578457ea6fa1559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 8 Oct 2020 16:34:54 +0200 Subject: [PATCH 309/411] Add NetworkIOMeter --- Makefile.am | 2 + NetworkIOMeter.c | 89 +++++++++++++++++++++++++++++++++++++++++ NetworkIOMeter.h | 8 ++++ darwin/Platform.c | 11 +++++ darwin/Platform.h | 5 +++ dragonflybsd/Platform.c | 11 +++++ dragonflybsd/Platform.h | 5 +++ freebsd/Platform.c | 51 +++++++++++++++++++++++ freebsd/Platform.h | 5 +++ linux/Platform.c | 45 +++++++++++++++++++++ linux/Platform.h | 5 +++ openbsd/Platform.c | 11 +++++ openbsd/Platform.h | 5 +++ solaris/Platform.c | 11 +++++ solaris/Platform.h | 5 +++ unsupported/Platform.c | 10 +++++ unsupported/Platform.h | 5 +++ 17 files changed, 284 insertions(+) create mode 100644 NetworkIOMeter.c create mode 100644 NetworkIOMeter.h diff --git a/Makefile.am b/Makefile.am index 83ada4509..600f2afc1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -46,6 +46,7 @@ myhtopsources = \ MemoryMeter.c \ Meter.c \ MetersPanel.c \ + NetworkIOMeter.c \ Object.c \ OpenFilesScreen.c \ Panel.c \ @@ -97,6 +98,7 @@ myhtopheaders = \ MemoryMeter.h \ Meter.h \ MetersPanel.h \ + NetworkIOMeter.h \ Object.h \ OpenFilesScreen.h \ Panel.h \ diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c new file mode 100644 index 000000000..07c7dc971 --- /dev/null +++ b/NetworkIOMeter.c @@ -0,0 +1,89 @@ +#include "NetworkIOMeter.h" + +#include "CRT.h" +#include "Platform.h" + + +static const int NetworkIOMeter_attributes[] = { + METER_VALUE_IOREAD, + METER_VALUE_IOWRITE, +}; + +static unsigned long int cached_rxb_diff = 0; +static unsigned long int cached_rxp_diff = 0; +static unsigned long int cached_txb_diff = 0; +static unsigned long int cached_txp_diff = 0; + +static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, int len) { + static unsigned long int cached_rxb_total = 0; + static unsigned long int cached_rxp_total = 0; + static unsigned long int cached_txb_total = 0; + static unsigned long int cached_txp_total = 0; + static unsigned long long int cached_last_update = 0; + + struct timeval tv; + gettimeofday(&tv, NULL); + unsigned long long int timeInMilliSeconds = (unsigned long long int)tv.tv_sec * 1000 + (unsigned long long int)tv.tv_usec / 1000; + unsigned long long int passedTimeInMs = timeInMilliSeconds - cached_last_update; + + /* update only every 500ms */ + if (passedTimeInMs > 500) { + unsigned long int bytesReceived, packetsReceived, bytesTransmitted, packetsTransmitted; + + Platform_getNetworkIO(&bytesReceived, &packetsReceived, &bytesTransmitted, &packetsTransmitted); + + cached_rxb_diff = (bytesReceived - cached_rxb_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + cached_rxb_diff = 1000.0 * cached_rxb_diff / passedTimeInMs; /* convert to per second */ + cached_rxb_total = bytesReceived; + + cached_rxp_diff = packetsReceived - cached_rxp_total; + cached_rxp_total = packetsReceived; + + cached_txb_diff = (bytesTransmitted - cached_txb_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + cached_txb_diff = 1000.0 * cached_txb_diff / passedTimeInMs; /* convert to per second */ + cached_txb_total = bytesTransmitted; + + cached_txp_diff = packetsTransmitted - cached_txp_total; + cached_txp_total = packetsTransmitted; + + cached_last_update = timeInMilliSeconds; + } + + char bufferBytesReceived[12], bufferBytesTransmitted[12]; + Meter_humanUnit(bufferBytesReceived, cached_rxb_diff, sizeof(bufferBytesReceived)); + Meter_humanUnit(bufferBytesTransmitted, cached_txb_diff, sizeof(bufferBytesTransmitted)); + xSnprintf(buffer, len, "rx:%siB/s tx:%siB/s", bufferBytesReceived, bufferBytesTransmitted); +} + +static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { + char buffer[32]; + + RichString_write(out, CRT_colors[METER_TEXT], "rx: "); + Meter_humanUnit(buffer, cached_rxb_diff, sizeof(buffer)); + RichString_append(out, CRT_colors[METER_VALUE_IOREAD], buffer); + RichString_append(out, CRT_colors[METER_VALUE_IOREAD], "iB/s"); + + RichString_append(out, CRT_colors[METER_TEXT], " tx: "); + Meter_humanUnit(buffer, cached_txb_diff, sizeof(buffer)); + RichString_append(out, CRT_colors[METER_VALUE_IOWRITE], buffer); + RichString_append(out, CRT_colors[METER_VALUE_IOWRITE], "iB/s"); + + xSnprintf(buffer, sizeof(buffer), " (%lu/%lu packets) ", cached_rxp_diff, cached_txp_diff); + RichString_append(out, CRT_colors[METER_TEXT], buffer); +} + +const MeterClass NetworkIOMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = NetworkIOMeter_display + }, + .updateValues = NetworkIOMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 0, + .total = 100.0, + .attributes = NetworkIOMeter_attributes, + .name = "NetworkIO", + .uiName = "Network IO", + .caption = "Network: " +}; diff --git a/NetworkIOMeter.h b/NetworkIOMeter.h new file mode 100644 index 000000000..311b5e645 --- /dev/null +++ b/NetworkIOMeter.h @@ -0,0 +1,8 @@ +#ifndef HEADER_NetworkIOMeter +#define HEADER_NetworkIOMeter + +#include "Meter.h" + +extern const MeterClass NetworkIOMeter_class; + +#endif /* HEADER_NetworkIOMeter */ diff --git a/darwin/Platform.c b/darwin/Platform.c index 99787a277..26bcbad26 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -315,3 +315,14 @@ void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWr // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; } + +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted) { + // TODO + *bytesReceived = 0; + *packetsReceived = 0; + *bytesTransmitted = 0; + *packetsTransmitted = 0; +} diff --git a/darwin/Platform.h b/darwin/Platform.h index 9b7a324b9..d953b51c0 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -50,4 +50,9 @@ char* Platform_getProcessEnv(pid_t pid); void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted); + #endif diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 6eb1e99c5..eb1725135 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -215,3 +215,14 @@ void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWr // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; } + +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted) { + // TODO + *bytesReceived = 0; + *packetsReceived = 0; + *bytesTransmitted = 0; + *packetsTransmitted = 0; +} diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 3dc1eb1e8..50187aa40 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -44,4 +44,9 @@ char* Platform_getProcessEnv(pid_t pid); void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted); + #endif diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 2288d2f21..7827d5210 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -18,11 +18,14 @@ in the source distribution for its full text. #include "DateMeter.h" #include "DateTimeMeter.h" #include "HostnameMeter.h" +#include "NetworkIOMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" #include "FreeBSDProcess.h" #include "FreeBSDProcessList.h" +#include +#include #include #include #include @@ -107,6 +110,7 @@ const MeterClass* const Platform_meterTypes[] = { &BlankMeter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, + &NetworkIOMeter_class, NULL }; @@ -230,3 +234,50 @@ void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWr // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; } + +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted) { + int r; + + // get number of interfaces + int count; + size_t countLen = sizeof(count); + const int countMib[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT }; + + r = sysctl(countMib, ARRAYSIZE(countMib), &count, &countLen, NULL, 0); + if (r < 0) { + *bytesReceived = 0; + *packetsReceived = 0; + *bytesTransmitted = 0; + *packetsTransmitted = 0; + return; + } + + unsigned long int bytesReceivedSum = 0, packetsReceivedSum = 0, bytesTransmittedSum = 0, packetsTransmittedSum = 0; + + for (int i = 1; i <= count; i++) { + struct ifmibdata ifmd; + size_t ifmdLen = sizeof(ifmd); + + const int dataMib[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, i, IFDATA_GENERAL }; + + r = sysctl(dataMib, ARRAYSIZE(dataMib), &ifmd, &ifmdLen, NULL, 0); + if (r < 0) + continue; + + if (ifmd.ifmd_flags & IFF_LOOPBACK) + continue; + + bytesReceivedSum += ifmd.ifmd_data.ifi_ibytes; + packetsReceivedSum += ifmd.ifmd_data.ifi_ipackets; + bytesTransmittedSum += ifmd.ifmd_data.ifi_obytes; + packetsTransmittedSum += ifmd.ifmd_data.ifi_opackets; + } + + *bytesReceived = bytesReceivedSum; + *packetsReceived = packetsReceivedSum; + *bytesTransmitted = bytesTransmittedSum; + *packetsTransmitted = packetsTransmittedSum; +} diff --git a/freebsd/Platform.h b/freebsd/Platform.h index feda7416a..bd1a38ef4 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -47,4 +47,9 @@ char* Platform_getProcessEnv(pid_t pid); void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted); + #endif diff --git a/linux/Platform.c b/linux/Platform.c index c78264182..6a3ffab20 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -25,6 +25,7 @@ in the source distribution for its full text. #include "DateMeter.h" #include "DateTimeMeter.h" #include "HostnameMeter.h" +#include "NetworkIOMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" #include "LinuxProcess.h" @@ -140,6 +141,7 @@ const MeterClass* const Platform_meterTypes[] = { &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, &DiskIOMeter_class, + &NetworkIOMeter_class, &SELinuxMeter_class, NULL }; @@ -338,3 +340,46 @@ void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWr *bytesWrite = 512 * write_sum; *msTimeSpend = timeSpend_sum; } + +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted) { + FILE *fd = fopen(PROCDIR "/net/dev", "r"); + if (!fd) { + *bytesReceived = 0; + *packetsReceived = 0; + *bytesTransmitted = 0; + *packetsTransmitted = 0; + return; + } + + unsigned long int bytesReceivedSum = 0, packetsReceivedSum = 0, bytesTransmittedSum = 0, packetsTransmittedSum = 0; + char lineBuffer[512]; + while (fgets(lineBuffer, sizeof(lineBuffer), fd)) { + char interfaceName[32]; + unsigned long int bytesReceivedParsed, packetsReceivedParsed, bytesTransmittedParsed, packetsTransmittedParsed; + if (fscanf(fd, "%31s %lu %lu %*u %*u %*u %*u %*u %*u %lu %lu %*u %*u %*u %*u %*u %*u", + interfaceName, + &bytesReceivedParsed, + &packetsReceivedParsed, + &bytesTransmittedParsed, + &packetsTransmittedParsed) != 5) + continue; + + if (0 == strcmp(interfaceName, "lo:")) + continue; + + bytesReceivedSum += bytesReceivedParsed; + packetsReceivedSum += packetsReceivedParsed; + bytesTransmittedSum += bytesTransmittedParsed; + packetsTransmittedSum += packetsTransmittedParsed; + } + + fclose(fd); + + *bytesReceived = bytesReceivedSum; + *packetsReceived = packetsReceivedSum; + *bytesTransmitted = bytesTransmittedSum; + *packetsTransmitted = packetsTransmittedSum; +} diff --git a/linux/Platform.h b/linux/Platform.h index 66a60d8b6..007cd32b2 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -46,4 +46,9 @@ void Platform_getPressureStall(const char *file, bool some, double* ten, double* void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted); + #endif diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 4c2ebdfb8..7723ebc58 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -296,3 +296,14 @@ void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWr // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; } + +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted) { + // TODO + *bytesReceived = 0; + *packetsReceived = 0; + *bytesTransmitted = 0; + *packetsTransmitted = 0; +} diff --git a/openbsd/Platform.h b/openbsd/Platform.h index c71d490e9..b3edf6e8c 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -45,4 +45,9 @@ char* Platform_getProcessEnv(pid_t pid); void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted); + #endif diff --git a/solaris/Platform.c b/solaris/Platform.c index ef0d41237..4203a9648 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -268,3 +268,14 @@ void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWr // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; } + +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted) { + // TODO + *bytesReceived = 0; + *packetsReceived = 0; + *bytesTransmitted = 0; + *packetsTransmitted = 0; +} diff --git a/solaris/Platform.h b/solaris/Platform.h index a9b7712dc..130c70cd7 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -65,4 +65,9 @@ char* Platform_getProcessEnv(pid_t pid); void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted); + #endif diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 6e8968f11..cc28fd8f7 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -144,3 +144,13 @@ char* Platform_getProcessEnv(pid_t pid) { void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { *bytesRead = *bytesWrite = *msTimeSpend = 0; } + +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted) { + *bytesReceived = 0; + *packetsReceived = 0; + *bytesTransmitted = 0; + *packetsTransmitted = 0; +} diff --git a/unsupported/Platform.h b/unsupported/Platform.h index f24dcf4cd..1049919d3 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -49,4 +49,9 @@ char* Platform_getProcessEnv(pid_t pid); void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +void Platform_getNetworkIO(unsigned long int *bytesReceived, + unsigned long int *packetsReceived, + unsigned long int *bytesTransmitted, + unsigned long int *packetsTransmitted); + #endif From c6f04a9c5d33d16623f1c20f0987dd3a992379e7 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 19 Sep 2020 20:22:34 +0200 Subject: [PATCH 310/411] Move xAsprintf, xSnprintf and xStrdup to StringUtils.h --- AffinityPanel.c | 9 +++++--- AvailableColumnsPanel.c | 11 ++++----- AvailableMetersPanel.c | 1 + CPUMeter.c | 1 + ColorsPanel.c | 1 + DiskIOMeter.c | 1 + DisplayOptionsPanel.c | 7 +++--- FunctionBar.c | 1 + LoadAverageMeter.c | 1 + SignalsPanel.c | 12 +++++----- StringUtils.c | 45 +++++++++++++++++++++++++++++++++---- StringUtils.h | 11 +++++++++ TasksMeter.c | 3 ++- UptimeMeter.c | 4 +++- UsersTable.c | 8 ++++--- XAlloc.c | 34 ---------------------------- XAlloc.h | 8 ------- htop.c | 1 + linux/IOPriorityPanel.c | 2 ++ linux/LinuxProcess.c | 3 ++- linux/PressureStallMeter.c | 9 ++++---- zfs/ZfsCompressedArcMeter.c | 1 + 22 files changed, 100 insertions(+), 74 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index 0a9648829..0027d4a43 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -5,14 +5,17 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "AffinityPanel.h" -#include "CRT.h" +#include "config.h" -#include "Vector.h" +#include "AffinityPanel.h" #include #include +#include "CRT.h" +#include "StringUtils.h" +#include "Vector.h" + #ifdef HAVE_LIBHWLOC #include #endif diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index dcfbb3e27..a2a6aba67 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -6,16 +6,17 @@ in the source distribution for its full text. */ #include "AvailableColumnsPanel.h" -#include "Platform.h" - -#include "Header.h" -#include "ColumnsPanel.h" #include -#include #include +#include #include +#include "ColumnsPanel.h" +#include "Header.h" +#include "Platform.h" +#include "StringUtils.h" + static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index b51a9e9f4..b90912bde 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -12,6 +12,7 @@ in the source distribution for its full text. #include "Header.h" #include "ListItem.h" #include "Platform.h" +#include "StringUtils.h" #include #include diff --git a/CPUMeter.c b/CPUMeter.c index 446c04d20..c3133a2cd 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Settings.h" #include "Platform.h" +#include "StringUtils.h" #include #include diff --git a/ColorsPanel.c b/ColorsPanel.c index 917be98cf..45745a734 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -9,6 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "CheckItem.h" +#include "StringUtils.h" #include #include diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 8393af705..34b0f081d 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -11,6 +11,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" +#include "StringUtils.h" static const int DiskIOMeter_attributes[] = { diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 1aede655f..d65348877 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -7,13 +7,14 @@ in the source distribution for its full text. #include "DisplayOptionsPanel.h" -#include "CheckItem.h" -#include "CRT.h" - #include #include #include +#include "CheckItem.h" +#include "CRT.h" +#include "StringUtils.h" + static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/FunctionBar.c b/FunctionBar.c index c67e613c3..3e00b87e8 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -8,6 +8,7 @@ in the source distribution for its full text. #include "FunctionBar.h" #include "CRT.h" #include "RichString.h" +#include "StringUtils.h" #include "XAlloc.h" #include diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index 208b7e95b..507d3dc38 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -9,6 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" +#include "StringUtils.h" static const int LoadAverageMeter_attributes[] = { diff --git a/SignalsPanel.c b/SignalsPanel.c index 933a21ba9..e15e6c8d2 100644 --- a/SignalsPanel.c +++ b/SignalsPanel.c @@ -7,16 +7,16 @@ in the source distribution for its full text. #include "Panel.h" #include "SignalsPanel.h" -#include "Platform.h" - -#include "ListItem.h" -#include "RichString.h" -#include #include +#include #include +#include -#include +#include "ListItem.h" +#include "Platform.h" +#include "RichString.h" +#include "StringUtils.h" Panel* SignalsPanel_new() { diff --git a/StringUtils.c b/StringUtils.c index f74566f88..4eb769680 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -5,14 +5,17 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "StringUtils.h" -#include "XAlloc.h" - #include "config.h" +#include "StringUtils.h" + +#include +#include #include #include -#include + +#include "XAlloc.h" + char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); @@ -140,3 +143,37 @@ char* String_readLine(FILE* fd) { at = buffer + bufSize - step; } } + +int xAsprintf(char** strp, const char* fmt, ...) { + va_list vl; + va_start(vl, fmt); + int r = vasprintf(strp, fmt, vl); + va_end(vl); + + if (r < 0 || !*strp) { + fail(); + } + + return r; +} + +int xSnprintf(char* buf, int len, const char* fmt, ...) { + va_list vl; + va_start(vl, fmt); + int n = vsnprintf(buf, len, fmt, vl); + va_end(vl); + + if (n < 0 || n >= len) { + fail(); + } + + return n; +} + +char* xStrdup(const char* str) { + char* data = strdup(str); + if (!data) { + fail(); + } + return data; +} diff --git a/StringUtils.h b/StringUtils.h index 936617ffb..5a1af9ad9 100644 --- a/StringUtils.h +++ b/StringUtils.h @@ -9,6 +9,9 @@ in the source distribution for its full text. #include +#include "Macros.h" + + #define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) #define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL) @@ -31,4 +34,12 @@ char* String_getToken(const char* line, const unsigned short int numMatch); char* String_readLine(FILE* fd); +ATTR_FORMAT(printf, 2, 3) +int xAsprintf(char **strp, const char* fmt, ...); + +ATTR_FORMAT(printf, 3, 4) +int xSnprintf(char *buf, int len, const char* fmt, ...); + +char* xStrdup(const char* str) ATTR_NONNULL; + #endif diff --git a/TasksMeter.c b/TasksMeter.c index fb3767c55..ef7e49642 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -7,8 +7,9 @@ in the source distribution for its full text. #include "TasksMeter.h" -#include "Platform.h" #include "CRT.h" +#include "Platform.h" +#include "StringUtils.h" static const int TasksMeter_attributes[] = { diff --git a/UptimeMeter.c b/UptimeMeter.c index a11951869..c8e511f1a 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -6,8 +6,10 @@ in the source distribution for its full text. */ #include "UptimeMeter.h" -#include "Platform.h" + #include "CRT.h" +#include "Platform.h" +#include "StringUtils.h" static const int UptimeMeter_attributes[] = { diff --git a/UsersTable.c b/UsersTable.c index 722dd6e14..208fc8d84 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -5,11 +5,10 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "UsersTable.h" -#include "XAlloc.h" - #include "config.h" +#include "UsersTable.h" + #include #include #include @@ -18,6 +17,9 @@ in the source distribution for its full text. #include #include +#include "StringUtils.h" +#include "XAlloc.h" + UsersTable* UsersTable_new() { UsersTable* this; diff --git a/XAlloc.c b/XAlloc.c index c832d087c..815cf47f9 100644 --- a/XAlloc.c +++ b/XAlloc.c @@ -40,37 +40,3 @@ void* xRealloc(void* ptr, size_t size) { } return data; } - -int xAsprintf(char** strp, const char* fmt, ...) { - va_list vl; - va_start(vl, fmt); - int _r = vasprintf(strp, fmt, vl); - va_end(vl); - - if (_r < 0) { - fail(); - } - - return _r; -} - -int xSnprintf(char* buf, int len, const char* fmt, ...) { - va_list vl; - va_start(vl, fmt); - int _n=vsnprintf(buf, len, fmt, vl); - va_end(vl); - - if (!(_n > -1 && _n < len)) { - fail(); - } - - return _n; -} - -char* xStrdup(const char* str) { - char* data = strdup(str); - if (!data) { - fail(); - } - return data; -} diff --git a/XAlloc.h b/XAlloc.h index 97c155197..98a422fc2 100644 --- a/XAlloc.h +++ b/XAlloc.h @@ -19,12 +19,4 @@ void* xCalloc(size_t nmemb, size_t size); void* xRealloc(void* ptr, size_t size); -ATTR_FORMAT(printf, 2, 3) -int xAsprintf(char **strp, const char* fmt, ...); - -ATTR_FORMAT(printf, 3, 4) -int xSnprintf(char *buf, int len, const char* fmt, ...); - -char* xStrdup(const char* str) ATTR_NONNULL; - #endif diff --git a/htop.c b/htop.c index 8c813564f..9ce966f74 100644 --- a/htop.c +++ b/htop.c @@ -16,6 +16,7 @@ in the source distribution for its full text. #include "ProcessList.h" #include "ScreenManager.h" #include "Settings.h" +#include "StringUtils.h" #include "UsersTable.h" #include "Platform.h" diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index a12b8065b..ce7f01e44 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -7,6 +7,8 @@ in the source distribution for its full text. #include "IOPriorityPanel.h" +#include "StringUtils.h" + Panel* IOPriorityPanel_new(IOPriority currPrio) { Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Set ", "Cancel ")); diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 68baf96d1..9e3c2f89f 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -9,8 +9,9 @@ in the source distribution for its full text. #include "Process.h" #include "ProcessList.h" #include "LinuxProcess.h" -#include "Platform.h" #include "CRT.h" +#include "Platform.h" +#include "StringUtils.h" #include #include diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c index 307e397db..518e66c8d 100644 --- a/linux/PressureStallMeter.c +++ b/linux/PressureStallMeter.c @@ -7,14 +7,13 @@ in the source distribution for its full text. */ #include "PressureStallMeter.h" -#include "Platform.h" -#include "CRT.h" #include -/*{ -#include "Meter.h" -}*/ +#include "CRT.h" +#include "Platform.h" +#include "StringUtils.h" + static const int PressureStallMeter_attributes[] = { PRESSURE_STALL_TEN, PRESSURE_STALL_SIXTY, PRESSURE_STALL_THREEHUNDRED diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index 472b5b5bd..def88d020 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" +#include "StringUtils.h" #include #include From 872e542f4eca52ce2198ba3fc30a51bc5d672dae Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Wed, 14 Oct 2020 20:21:09 +0200 Subject: [PATCH 311/411] Rename StringUtils.[ch] to XUtils.[ch] --- Action.c | 2 +- AffinityPanel.c | 2 +- AvailableColumnsPanel.c | 2 +- AvailableMetersPanel.c | 2 +- BatteryMeter.c | 2 +- CPUMeter.c | 2 +- CRT.c | 2 +- ColorsPanel.c | 2 +- ColumnsPanel.c | 2 +- CommandScreen.c | 2 +- DiskIOMeter.c | 2 +- DisplayOptionsPanel.c | 2 +- EnvScreen.c | 2 +- FunctionBar.c | 2 +- Header.c | 2 +- IncSet.c | 3 ++- InfoScreen.c | 2 +- ListItem.c | 2 +- LoadAverageMeter.c | 2 +- Makefile.am | 8 ++++---- Meter.c | 2 +- OpenFilesScreen.c | 2 +- Panel.c | 2 +- Process.c | 2 +- ProcessList.c | 4 ++-- Settings.c | 6 +++--- SignalsPanel.c | 2 +- TasksMeter.c | 2 +- TraceScreen.c | 2 +- UptimeMeter.c | 2 +- UsersTable.c | 2 +- StringUtils.c => XUtils.c | 2 +- StringUtils.h => XUtils.h | 4 ++-- htop.c | 2 +- linux/Battery.c | 9 +++++---- linux/IOPriorityPanel.c | 2 +- linux/LinuxProcess.c | 3 ++- linux/LinuxProcessList.c | 3 ++- linux/Platform.c | 2 +- linux/PressureStallMeter.c | 2 +- zfs/ZfsCompressedArcMeter.c | 2 +- 41 files changed, 55 insertions(+), 51 deletions(-) rename StringUtils.c => XUtils.c (99%) rename StringUtils.h => XUtils.h (95%) diff --git a/Action.c b/Action.c index 6d7782ca3..f53acf7b6 100644 --- a/Action.c +++ b/Action.c @@ -19,9 +19,9 @@ in the source distribution for its full text. #include "Process.h" #include "ScreenManager.h" #include "SignalsPanel.h" -#include "StringUtils.h" #include "TraceScreen.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/AffinityPanel.c b/AffinityPanel.c index 0027d4a43..ab17b420f 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -13,8 +13,8 @@ in the source distribution for its full text. #include #include "CRT.h" -#include "StringUtils.h" #include "Vector.h" +#include "XUtils.h" #ifdef HAVE_LIBHWLOC #include diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index a2a6aba67..32bb470e9 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -15,7 +15,7 @@ in the source distribution for its full text. #include "ColumnsPanel.h" #include "Header.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index b90912bde..faa69a8f0 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -12,7 +12,7 @@ in the source distribution for its full text. #include "Header.h" #include "ListItem.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/BatteryMeter.c b/BatteryMeter.c index 060b125cc..22a63c7a1 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -12,8 +12,8 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). #include "Battery.h" #include "ProcessList.h" #include "CRT.h" -#include "StringUtils.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/CPUMeter.c b/CPUMeter.c index c3133a2cd..7e70f4549 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -10,7 +10,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Settings.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/CRT.c b/CRT.c index 06ce04512..2f9eb2b6f 100644 --- a/CRT.c +++ b/CRT.c @@ -8,8 +8,8 @@ in the source distribution for its full text. #include "config.h" #include "CRT.h" -#include "StringUtils.h" #include "RichString.h" +#include "XUtils.h" #include #include diff --git a/ColorsPanel.c b/ColorsPanel.c index 45745a734..5b189ea3d 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -9,7 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "CheckItem.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/ColumnsPanel.c b/ColumnsPanel.c index e4fe4fc1f..a0e9fd31c 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -8,7 +8,7 @@ in the source distribution for its full text. #include "ColumnsPanel.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include "ListItem.h" #include "CRT.h" diff --git a/CommandScreen.c b/CommandScreen.c index 58ed88404..df039645d 100644 --- a/CommandScreen.c +++ b/CommandScreen.c @@ -5,7 +5,7 @@ #include "IncSet.h" #include "ListItem.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 34b0f081d..d882b4333 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -11,7 +11,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int DiskIOMeter_attributes[] = { diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index d65348877..d667ab7fa 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -13,7 +13,7 @@ in the source distribution for its full text. #include "CheckItem.h" #include "CRT.h" -#include "StringUtils.h" +#include "XUtils.h" static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/EnvScreen.c b/EnvScreen.c index 1f107457e..10060ec7e 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -5,7 +5,7 @@ #include "IncSet.h" #include "ListItem.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/FunctionBar.c b/FunctionBar.c index 3e00b87e8..4e9d30cda 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -8,8 +8,8 @@ in the source distribution for its full text. #include "FunctionBar.h" #include "CRT.h" #include "RichString.h" -#include "StringUtils.h" #include "XAlloc.h" +#include "XUtils.h" #include #include diff --git a/Header.c b/Header.c index e5a64db19..f52333703 100644 --- a/Header.c +++ b/Header.c @@ -8,8 +8,8 @@ in the source distribution for its full text. #include "Header.h" #include "CRT.h" -#include "StringUtils.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/IncSet.c b/IncSet.c index 9dda3ce1e..3534f8577 100644 --- a/IncSet.c +++ b/IncSet.c @@ -6,9 +6,10 @@ in the source distribution for its full text. */ #include "IncSet.h" -#include "StringUtils.h" #include "ListItem.h" #include "CRT.h" +#include "XUtils.h" + #include #include diff --git a/InfoScreen.c b/InfoScreen.c index ecde6d91e..ed890f7d8 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -6,7 +6,7 @@ #include "IncSet.h" #include "ListItem.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/ListItem.c b/ListItem.c index d9d36f89c..c4479d73f 100644 --- a/ListItem.c +++ b/ListItem.c @@ -8,8 +8,8 @@ in the source distribution for its full text. #include "ListItem.h" #include "CRT.h" -#include "StringUtils.h" #include "RichString.h" +#include "XUtils.h" #include #include diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index 507d3dc38..c52bffc1d 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -9,7 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int LoadAverageMeter_attributes[] = { diff --git a/Makefile.am b/Makefile.am index 600f2afc1..0c3b68c01 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,14 +56,14 @@ myhtopsources = \ ScreenManager.c \ Settings.c \ SignalsPanel.c \ - StringUtils.c \ SwapMeter.c \ TasksMeter.c \ TraceScreen.c \ UptimeMeter.c \ UsersTable.c \ Vector.c \ - XAlloc.c + XAlloc.c \ + XUtils.c myhtopheaders = \ Action.h \ @@ -108,14 +108,14 @@ myhtopheaders = \ ScreenManager.h \ Settings.h \ SignalsPanel.h \ - StringUtils.h \ SwapMeter.h \ TasksMeter.h \ TraceScreen.h \ UptimeMeter.h \ UsersTable.h \ Vector.h \ - XAlloc.h + XAlloc.h \ + XUtils.h # Linux # ----- diff --git a/Meter.c b/Meter.c index 3edfb2331..154a5a642 100644 --- a/Meter.c +++ b/Meter.c @@ -10,8 +10,8 @@ in the source distribution for its full text. #include "RichString.h" #include "Object.h" #include "CRT.h" -#include "StringUtils.h" #include "Settings.h" +#include "XUtils.h" #include #include diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 1973cc45c..8e099bbe4 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -10,8 +10,8 @@ in the source distribution for its full text. #include "CRT.h" #include "ProcessList.h" #include "IncSet.h" -#include "StringUtils.h" #include "FunctionBar.h" +#include "XUtils.h" #include #include diff --git a/Panel.c b/Panel.c index 06a15c6b1..76e45d6ee 100644 --- a/Panel.c +++ b/Panel.c @@ -10,7 +10,7 @@ in the source distribution for its full text. #include "CRT.h" #include "RichString.h" #include "ListItem.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/Process.c b/Process.c index 43a4c47e4..147caee6b 100644 --- a/Process.c +++ b/Process.c @@ -12,9 +12,9 @@ in the source distribution for its full text. #include "config.h" #include "CRT.h" -#include "StringUtils.h" #include "RichString.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/ProcessList.c b/ProcessList.c index 1b364cfcf..b74454319 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -6,10 +6,10 @@ in the source distribution for its full text. */ #include "ProcessList.h" -#include "Platform.h" #include "CRT.h" -#include "StringUtils.h" +#include "Platform.h" +#include "XUtils.h" #include #include diff --git a/Settings.c b/Settings.c index 7a90ec477..fd623ad8e 100644 --- a/Settings.c +++ b/Settings.c @@ -6,11 +6,11 @@ in the source distribution for its full text. */ #include "Settings.h" -#include "Platform.h" -#include "StringUtils.h" -#include "Vector.h" #include "CRT.h" +#include "Platform.h" +#include "Vector.h" +#include "XUtils.h" #include #include diff --git a/SignalsPanel.c b/SignalsPanel.c index e15e6c8d2..0ebe16d33 100644 --- a/SignalsPanel.c +++ b/SignalsPanel.c @@ -16,7 +16,7 @@ in the source distribution for its full text. #include "ListItem.h" #include "Platform.h" #include "RichString.h" -#include "StringUtils.h" +#include "XUtils.h" Panel* SignalsPanel_new() { diff --git a/TasksMeter.c b/TasksMeter.c index ef7e49642..a13766ed0 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -9,7 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int TasksMeter_attributes[] = { diff --git a/TraceScreen.c b/TraceScreen.c index 2956b5696..314efc93b 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -11,8 +11,8 @@ in the source distribution for its full text. #include "ProcessList.h" #include "ListItem.h" #include "IncSet.h" -#include "StringUtils.h" #include "FunctionBar.h" +#include "XUtils.h" #include #include diff --git a/UptimeMeter.c b/UptimeMeter.c index c8e511f1a..1011aa108 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -9,7 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int UptimeMeter_attributes[] = { diff --git a/UsersTable.c b/UsersTable.c index 208fc8d84..e37c90382 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -17,8 +17,8 @@ in the source distribution for its full text. #include #include -#include "StringUtils.h" #include "XAlloc.h" +#include "XUtils.h" UsersTable* UsersTable_new() { diff --git a/StringUtils.c b/XUtils.c similarity index 99% rename from StringUtils.c rename to XUtils.c index 4eb769680..9228c5e83 100644 --- a/StringUtils.c +++ b/XUtils.c @@ -7,7 +7,7 @@ in the source distribution for its full text. #include "config.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/StringUtils.h b/XUtils.h similarity index 95% rename from StringUtils.h rename to XUtils.h index 5a1af9ad9..4880d1a15 100644 --- a/StringUtils.h +++ b/XUtils.h @@ -1,5 +1,5 @@ -#ifndef HEADER_StringUtils -#define HEADER_StringUtils +#ifndef HEADER_XUtils +#define HEADER_XUtils /* htop - StringUtils.h (C) 2004-2011 Hisham H. Muhammad diff --git a/htop.c b/htop.c index 9ce966f74..39aeec1a7 100644 --- a/htop.c +++ b/htop.c @@ -16,9 +16,9 @@ in the source distribution for its full text. #include "ProcessList.h" #include "ScreenManager.h" #include "Settings.h" -#include "StringUtils.h" #include "UsersTable.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/linux/Battery.c b/linux/Battery.c index 14fcc90b7..faf4064c3 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -7,11 +7,10 @@ in the source distribution for its full text. Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). */ +#include "config.h" // IWYU pragma: keep + #include "Battery.h" -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif #include #include #include @@ -20,7 +19,9 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat #include #include #include -#include "StringUtils.h" + +#include "XUtils.h" + #define SYS_POWERSUPPLY_DIR "/sys/class/power_supply" diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index ce7f01e44..cc1b3916f 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -7,7 +7,7 @@ in the source distribution for its full text. #include "IOPriorityPanel.h" -#include "StringUtils.h" +#include "XUtils.h" Panel* IOPriorityPanel_new(IOPriority currPrio) { diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 9e3c2f89f..75900b5a2 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -11,7 +11,7 @@ in the source distribution for its full text. #include "LinuxProcess.h" #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include @@ -20,6 +20,7 @@ in the source distribution for its full text. #include #include + /* semi-global */ long long btime; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6dcc5e5a9..57fab8423 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -8,7 +8,8 @@ in the source distribution for its full text. #include "LinuxProcessList.h" #include "LinuxProcess.h" #include "CRT.h" -#include "StringUtils.h" +#include "XUtils.h" + #include #include #include diff --git a/linux/Platform.c b/linux/Platform.c index 6a3ffab20..feb6b6cff 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -30,7 +30,7 @@ in the source distribution for its full text. #include "zfs/ZfsCompressedArcMeter.h" #include "LinuxProcess.h" #include "SELinuxMeter.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c index 518e66c8d..4733415fe 100644 --- a/linux/PressureStallMeter.c +++ b/linux/PressureStallMeter.c @@ -12,7 +12,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int PressureStallMeter_attributes[] = { diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index def88d020..0153fccbd 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -10,7 +10,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include From 5e4b1826168b74d8b5e71227ded12980efd5a243 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Thu, 15 Oct 2020 00:56:22 +0200 Subject: [PATCH 312/411] Combine XAlloc.[ch] into XUtils.[ch] --- FunctionBar.c | 1 - Hashtable.c | 2 +- Makefile.am | 2 -- Object.h | 3 ++- RichString.c | 3 ++- UsersTable.c | 1 - XAlloc.c | 42 ------------------------------------------ XAlloc.h | 22 ---------------------- XUtils.c | 31 ++++++++++++++++++++++++++++++- XUtils.h | 11 +++++++++++ 10 files changed, 46 insertions(+), 72 deletions(-) delete mode 100644 XAlloc.c delete mode 100644 XAlloc.h diff --git a/FunctionBar.c b/FunctionBar.c index 4e9d30cda..50bae0b14 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -8,7 +8,6 @@ in the source distribution for its full text. #include "FunctionBar.h" #include "CRT.h" #include "RichString.h" -#include "XAlloc.h" #include "XUtils.h" #include diff --git a/Hashtable.c b/Hashtable.c index 383b34a88..a086227c8 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -6,7 +6,7 @@ in the source distribution for its full text. */ #include "Hashtable.h" -#include "XAlloc.h" +#include "XUtils.h" #include #include diff --git a/Makefile.am b/Makefile.am index 0c3b68c01..fd02bb3e1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -62,7 +62,6 @@ myhtopsources = \ UptimeMeter.c \ UsersTable.c \ Vector.c \ - XAlloc.c \ XUtils.c myhtopheaders = \ @@ -114,7 +113,6 @@ myhtopheaders = \ UptimeMeter.h \ UsersTable.h \ Vector.h \ - XAlloc.h \ XUtils.h # Linux diff --git a/Object.h b/Object.h index f601ddf05..6c31fa347 100644 --- a/Object.h +++ b/Object.h @@ -9,8 +9,9 @@ in the source distribution for its full text. */ #include "RichString.h" -#include "XAlloc.h" #include "Macros.h" +#include "XUtils.h" + typedef struct Object_ Object; diff --git a/RichString.c b/RichString.c index 8019135e6..3cb19ae41 100644 --- a/RichString.c +++ b/RichString.c @@ -6,12 +6,13 @@ in the source distribution for its full text. */ #include "RichString.h" -#include "XAlloc.h" #include "Macros.h" +#include "XUtils.h" #include #include + #define charBytes(n) (sizeof(CharType) * (n)) static void RichString_extendLen(RichString* this, int len) { diff --git a/UsersTable.c b/UsersTable.c index e37c90382..41e52d3f3 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -17,7 +17,6 @@ in the source distribution for its full text. #include #include -#include "XAlloc.h" #include "XUtils.h" diff --git a/XAlloc.c b/XAlloc.c deleted file mode 100644 index 815cf47f9..000000000 --- a/XAlloc.c +++ /dev/null @@ -1,42 +0,0 @@ - -#include "XAlloc.h" -#include "RichString.h" - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include -#include -#include - - -void fail() { - curs_set(1); - endwin(); - abort(); -} - -void* xMalloc(size_t size) { - void* data = malloc(size); - if (!data && size > 0) { - fail(); - } - return data; -} - -void* xCalloc(size_t nmemb, size_t size) { - void* data = calloc(nmemb, size); - if (!data && nmemb > 0 && size > 0) { - fail(); - } - return data; -} - -void* xRealloc(void* ptr, size_t size) { - void* data = realloc(ptr, size); - if (!data && size > 0) { - fail(); - } - return data; -} diff --git a/XAlloc.h b/XAlloc.h deleted file mode 100644 index 98a422fc2..000000000 --- a/XAlloc.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef HEADER_XAlloc -#define HEADER_XAlloc - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include "Macros.h" - -#include -#include -#include - -void fail(void) ATTR_NORETURN; - -void* xMalloc(size_t size); - -void* xCalloc(size_t nmemb, size_t size); - -void* xRealloc(void* ptr, size_t size); - -#endif diff --git a/XUtils.c b/XUtils.c index 9228c5e83..f654b4bca 100644 --- a/XUtils.c +++ b/XUtils.c @@ -14,9 +14,38 @@ in the source distribution for its full text. #include #include -#include "XAlloc.h" +#include "CRT.h" +void fail() { + CRT_done(); + abort(); +} + +void* xMalloc(size_t size) { + void* data = malloc(size); + if (!data && size > 0) { + fail(); + } + return data; +} + +void* xCalloc(size_t nmemb, size_t size) { + void* data = calloc(nmemb, size); + if (!data && nmemb > 0 && size > 0) { + fail(); + } + return data; +} + +void* xRealloc(void* ptr, size_t size) { + void* data = realloc(ptr, size); + if (!data && size > 0) { + fail(); + } + return data; +} + char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); diff --git a/XUtils.h b/XUtils.h index 4880d1a15..742b8e9eb 100644 --- a/XUtils.h +++ b/XUtils.h @@ -7,11 +7,22 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include #include +#include #include "Macros.h" +void fail(void) ATTR_NORETURN; + +void* xMalloc(size_t size); + +void* xCalloc(size_t nmemb, size_t size); + +void* xRealloc(void* ptr, size_t size); + #define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) #define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL) From c138d148974ab383044d1eec9922127faeb020f0 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Thu, 15 Oct 2020 07:38:28 +0200 Subject: [PATCH 313/411] Release old memory on error Avoids leaking memory upon realloc failure. --- XUtils.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/XUtils.c b/XUtils.c index f654b4bca..4fccec3ab 100644 --- a/XUtils.c +++ b/XUtils.c @@ -13,6 +13,7 @@ in the source distribution for its full text. #include #include #include +#include #include "CRT.h" @@ -20,6 +21,8 @@ in the source distribution for its full text. void fail() { CRT_done(); abort(); + + _exit(1); // Should never reach here } void* xMalloc(size_t size) { @@ -39,8 +42,13 @@ void* xCalloc(size_t nmemb, size_t size) { } void* xRealloc(void* ptr, size_t size) { - void* data = realloc(ptr, size); - if (!data && size > 0) { + if (!size) { + free(ptr); + return NULL; + } + void* data = realloc(ptr, size); // deepcode ignore MemoryLeakOnRealloc: this goes to fail() + if (!data) { + free(ptr); fail(); } return data; From 81543253cfe9fb4649b4b00058325c092a6b5259 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 17 Oct 2020 23:28:26 +0200 Subject: [PATCH 314/411] Fix misaligned access inside taskstats structure Reported by UB sanitizer (alongside several other messages): linux/LinuxProcessList.c:782:25: runtime error: member access within misaligned address 0x614000000264 for type 'struct taskstats', which requires 8 byte alignment 0x614000000264: note: pointer points here 64 01 03 00 0a 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 4b c8 2e 00 00 00 00 00 3e 45 3c fd ^ The issue doesn't cause trouble on x86, but any architecture with stricter memory alignment requirements may inadvertedly break. --- linux/LinuxProcessList.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 57fab8423..bbb064d14 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -766,7 +766,7 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { struct nlmsghdr *nlhdr; struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1]; struct nlattr *nlattr; - struct taskstats *stats; + struct taskstats stats; int rem; unsigned long long int timeDelta; LinuxProcess* lp = (LinuxProcess*) linuxProcess; @@ -778,20 +778,21 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { } if ((nlattr = nlattrs[TASKSTATS_TYPE_AGGR_PID]) || (nlattr = nlattrs[TASKSTATS_TYPE_NULL])) { - stats = nla_data(nla_next(nla_data(nlattr), &rem)); - assert(lp->super.pid == (pid_t)stats->ac_pid); - timeDelta = (stats->ac_etime*1000 - lp->delay_read_time); + memcpy(&stats, nla_data(nla_next(nla_data(nlattr), &rem)), sizeof(stats)); + assert(lp->super.pid == (pid_t)stats.ac_pid); + + timeDelta = (stats.ac_etime*1000 - lp->delay_read_time); #define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x; #define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100); - lp->cpu_delay_percent = DELTAPERC(stats->cpu_delay_total, lp->cpu_delay_total); - lp->blkio_delay_percent = DELTAPERC(stats->blkio_delay_total, lp->blkio_delay_total); - lp->swapin_delay_percent = DELTAPERC(stats->swapin_delay_total, lp->swapin_delay_total); + lp->cpu_delay_percent = DELTAPERC(stats.cpu_delay_total, lp->cpu_delay_total); + lp->blkio_delay_percent = DELTAPERC(stats.blkio_delay_total, lp->blkio_delay_total); + lp->swapin_delay_percent = DELTAPERC(stats.swapin_delay_total, lp->swapin_delay_total); #undef DELTAPERC #undef BOUNDS - lp->swapin_delay_total = stats->swapin_delay_total; - lp->blkio_delay_total = stats->blkio_delay_total; - lp->cpu_delay_total = stats->cpu_delay_total; - lp->delay_read_time = stats->ac_etime*1000; + lp->swapin_delay_total = stats.swapin_delay_total; + lp->blkio_delay_total = stats.blkio_delay_total; + lp->cpu_delay_total = stats.cpu_delay_total; + lp->delay_read_time = stats.ac_etime*1000; } return NL_OK; } From 4dfedd3930fffcf7e5c43cea103ccf4640ae3b9e Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 17 Oct 2020 22:32:43 +0200 Subject: [PATCH 315/411] Fix various file descriptor leaks --- TraceScreen.c | 79 ++++++++++++++++++++++++++++++++++++--------------- TraceScreen.h | 9 ++++-- 2 files changed, 62 insertions(+), 26 deletions(-) diff --git a/TraceScreen.c b/TraceScreen.c index 314efc93b..957e80e5d 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -59,10 +59,11 @@ void TraceScreen_delete(Object* cast) { if (this->child > 0) { kill(this->child, SIGTERM); waitpid(this->child, NULL, 0); - fclose(this->strace); } + if (this->strace) + fclose(this->strace); CRT_enableDelay(); - free(InfoScreen_done((InfoScreen*)cast)); + free(InfoScreen_done((InfoScreen*)this)); } void TraceScreen_draw(InfoScreen* this) { @@ -74,43 +75,75 @@ void TraceScreen_draw(InfoScreen* this) { } bool TraceScreen_forkTracer(TraceScreen* this) { - int error = pipe(this->fdpair); - if (error == -1) return false; - this->child = fork(); - if (this->child == -1) return false; - if (this->child == 0) { + int fdpair[2] = {0, 0}; + + if (pipe(fdpair) == -1) + return false; + + if(fcntl(fdpair[0], F_SETFL, O_NONBLOCK) < 0) + goto err; + + if(fcntl(fdpair[1], F_SETFL, O_NONBLOCK) < 0) + goto err; + + pid_t child = fork(); + if (child == -1) + goto err; + + if (child == 0) { + close(fdpair[0]); + + dup2(fdpair[1], STDOUT_FILENO); + dup2(fdpair[1], STDERR_FILENO); + close(fdpair[1]); + CRT_dropPrivileges(); - dup2(this->fdpair[1], STDERR_FILENO); - int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK); - if (ok != -1) { - char buffer[32] = {0}; - xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid); - execlp("strace", "strace", "-T", "-tt", "-s", "512", "-p", buffer, NULL); - } + + char buffer[32] = {0}; + xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid); + execlp("strace", "strace", "-T", "-tt", "-s", "512", "-p", buffer, NULL); + + // Should never reach here, unless execlp fails ... const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH."; - ssize_t written = write(this->fdpair[1], message, strlen(message)); + ssize_t written = write(STDERR_FILENO, message, strlen(message)); (void) written; - exit(1); + + exit(127); } - int ok = fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK); - if (ok == -1) return false; - this->strace = fdopen(this->fdpair[0], "r"); - this->fd_strace = fileno(this->strace); + + FILE* fd = fdopen(fdpair[0], "r"); + if (!fd) + goto err; + + close(fdpair[1]); + + this->child = child; + this->strace = fd; return true; + +err: + close(fdpair[1]); + close(fdpair[0]); + return false; } void TraceScreen_updateTrace(InfoScreen* super) { TraceScreen* this = (TraceScreen*) super; char buffer[1025]; + + int fd_strace = fileno(this->strace); + assert(fd_strace != -1); + fd_set fds; FD_ZERO(&fds); // FD_SET(STDIN_FILENO, &fds); - FD_SET(this->fd_strace, &fds); + FD_SET(fd_strace, &fds); + struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 500; - int ready = select(this->fd_strace+1, &fds, NULL, NULL, &tv); + int ready = select(fd_strace+1, &fds, NULL, NULL, &tv); size_t nread = 0; - if (ready > 0 && FD_ISSET(this->fd_strace, &fds)) + if (ready > 0 && FD_ISSET(fd_strace, &fds)) nread = fread(buffer, 1, sizeof(buffer) - 1, this->strace); if (nread && this->tracing) { const char* line = buffer; diff --git a/TraceScreen.h b/TraceScreen.h index 513ea4612..552d14fa3 100644 --- a/TraceScreen.h +++ b/TraceScreen.h @@ -7,15 +7,18 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include +#include + #include "InfoScreen.h" + typedef struct TraceScreen_ { InfoScreen super; bool tracing; - int fdpair[2]; - int child; + pid_t child; FILE* strace; - int fd_strace; bool contLine; bool follow; } TraceScreen; From 3e5bc034e5f39601afa5c3736babb34df4be7813 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 17 Oct 2020 23:05:20 +0200 Subject: [PATCH 316/411] Ensure full initialization of all fields --- TraceScreen.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/TraceScreen.c b/TraceScreen.c index 957e80e5d..a3c57870a 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -44,11 +44,10 @@ const InfoScreenClass TraceScreen_class = { }; TraceScreen* TraceScreen_new(Process* process) { - TraceScreen* this = xMalloc(sizeof(TraceScreen)); + // This initializes all TraceScreen variables to "false" so only default = true ones need to be set below + TraceScreen* this = xCalloc(1, sizeof(TraceScreen)); Object_setClass(this, Class(TraceScreen)); this->tracing = true; - this->contLine = false; - this->follow = false; FunctionBar* fuBar = FunctionBar_new(TraceScreenFunctions, TraceScreenKeys, TraceScreenEvents); CRT_disableDelay(); return (TraceScreen*) InfoScreen_init(&this->super, process, fuBar, LINES-2, ""); From 29346d05616ce69e5988b3f1257c340f91299602 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 19 Sep 2020 14:20:03 +0200 Subject: [PATCH 317/411] Provide basic configuration for IWYU --- iwyu/htop.imp | 10 ++++++++++ iwyu/run_iwyu.sh | 12 ++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 iwyu/htop.imp create mode 100755 iwyu/run_iwyu.sh diff --git a/iwyu/htop.imp b/iwyu/htop.imp new file mode 100644 index 000000000..c95bfaffb --- /dev/null +++ b/iwyu/htop.imp @@ -0,0 +1,10 @@ +[ + { include: ["", "private", "\"ProvideCurses.h\"", "public"] }, + { include: ["", "private", "\"ProvideCurses.h\"", "public"] }, + { include: ["", "private", "\"ProvideCurses.h\"", "public"] }, + { include: ["", "private", "\"ProvideCurses.h\"", "public"] }, + + { include: ["", "private", "", "public"] }, + + { include: ["", "private", "", "public"] }, +] diff --git a/iwyu/run_iwyu.sh b/iwyu/run_iwyu.sh new file mode 100755 index 000000000..83d2c484c --- /dev/null +++ b/iwyu/run_iwyu.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +SCRIPT=$(readlink -f "$0") +SCRIPTDIR=$(dirname "$SCRIPT") +SOURCEDIR="$SCRIPTDIR/.." + +PKG_NL3=$(pkg-config --cflags libnl-3.0) + +cd "$SOURCEDIR" + +make clean +make -k CC="iwyu" CFLAGS="-Xiwyu --no_comments -Xiwyu --no_fwd_decl -Xiwyu --mapping_file='$SCRIPTDIR/htop.imp' $PKG_NL3" From 0f5262917fab34b44b43f63946fdf6bb0621875a Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 19 Sep 2020 13:55:23 +0200 Subject: [PATCH 318/411] Make all required includes explicit Information as seen by IWYU 0.12 + clang 9 on Linux --- Action.c | 22 ++++++++------ Action.h | 5 ++++ Affinity.c | 3 ++ Affinity.h | 5 ++++ AffinityPanel.c | 11 ++++++- AvailableColumnsPanel.c | 9 ++++-- AvailableMetersPanel.c | 13 ++++++--- AvailableMetersPanel.h | 1 + BatteryMeter.c | 9 ++---- CPUMeter.c | 13 +++++---- CRT.c | 18 ++++++------ CRT.h | 6 +++- CategoriesPanel.c | 20 ++++++++----- CategoriesPanel.h | 1 + CheckItem.c | 5 ++-- CheckItem.h | 2 ++ ClockMeter.c | 7 +++-- ColorsPanel.c | 14 ++++++--- ColumnsPanel.c | 17 ++++++----- ColumnsPanel.h | 2 ++ CommandScreen.c | 15 +++++----- CommandScreen.h | 3 ++ DateMeter.c | 7 +++-- DateTimeMeter.c | 7 +++-- DiskIOMeter.c | 6 +++- DisplayOptionsPanel.c | 9 ++++-- EnvScreen.c | 16 ++++++----- EnvScreen.h | 2 ++ FunctionBar.c | 11 +++---- Hashtable.h | 5 ++-- Header.c | 12 +++++--- Header.h | 1 + HostnameMeter.c | 7 +++-- IncSet.c | 12 ++++++-- IncSet.h | 2 ++ InfoScreen.c | 17 +++++------ InfoScreen.h | 24 +++++++++------- ListItem.c | 10 ++++--- ListItem.h | 2 ++ LoadAverageMeter.c | 2 ++ Macros.h | 2 ++ MainPanel.c | 14 +++++++-- MainPanel.h | 6 ++++ Makefile.am | 1 + MemoryMeter.c | 8 ++---- Meter.c | 20 +++++++------ Meter.h | 9 ++++-- MetersPanel.c | 8 +++++- MetersPanel.h | 5 ++++ NetworkIOMeter.c | 7 +++++ Object.c | 3 ++ Object.h | 6 ++-- OpenFilesScreen.c | 22 +++++++------- OpenFilesScreen.h | 4 +++ Panel.c | 17 ++++++----- Panel.h | 5 ++++ Process.c | 35 +++++++++++----------- Process.h | 12 +++++--- ProcessList.c | 7 ++--- ProcessList.h | 8 ++++++ ProvideCurses.h | 34 ++++++++++++++++++++++ RichString.c | 6 ++-- RichString.h | 20 ++----------- ScreenManager.c | 15 +++++----- ScreenManager.h | 3 ++ Settings.c | 12 ++++---- Settings.h | 5 +++- SignalsPanel.c | 9 +++--- SignalsPanel.h | 2 ++ SwapMeter.c | 8 ++---- TasksMeter.c | 6 +++- TraceScreen.c | 28 +++++++++--------- TraceScreen.h | 2 ++ UptimeMeter.c | 1 + UsersTable.c | 9 ++---- Vector.c | 3 +- Vector.h | 2 ++ XUtils.c | 3 +- XUtils.h | 7 +++-- freebsd/FreeBSDProcess.h | 8 ++++++ freebsd/FreeBSDProcessList.c | 25 +++++++++------- freebsd/FreeBSDProcessList.h | 10 +++++-- htop.c | 30 ++++++++++++------- linux/Battery.c | 10 +++++-- linux/Battery.h | 1 + linux/IOPriorityPanel.c | 6 ++++ linux/IOPriorityPanel.h | 1 - linux/LinuxProcess.c | 18 ++++++------ linux/LinuxProcess.h | 13 +++++++-- linux/LinuxProcessList.c | 56 ++++++++++++++++++++---------------- linux/LinuxProcessList.h | 7 +++++ linux/Platform.c | 51 ++++++++++++++++++-------------- linux/Platform.h | 8 ++++-- linux/PressureStallMeter.c | 4 +++ linux/SELinuxMeter.c | 12 +++++--- zfs/ZfsArcMeter.c | 13 ++------- zfs/ZfsCompressedArcMeter.c | 15 +++------- 97 files changed, 642 insertions(+), 373 deletions(-) create mode 100644 ProvideCurses.h diff --git a/Action.c b/Action.c index f53acf7b6..b5bd5b54c 100644 --- a/Action.c +++ b/Action.c @@ -8,28 +8,32 @@ in the source distribution for its full text. #include "config.h" #include "Action.h" + +#include +#include +#include + #include "Affinity.h" #include "AffinityPanel.h" #include "CategoriesPanel.h" +#include "CommandScreen.h" #include "CRT.h" #include "EnvScreen.h" -#include "CommandScreen.h" +#include "FunctionBar.h" +#include "IncSet.h" +#include "InfoScreen.h" +#include "ListItem.h" +#include "Macros.h" #include "MainPanel.h" #include "OpenFilesScreen.h" #include "Process.h" +#include "ProvideCurses.h" #include "ScreenManager.h" #include "SignalsPanel.h" #include "TraceScreen.h" -#include "Platform.h" +#include "Vector.h" #include "XUtils.h" -#include -#include -#include -#include -#include -#include -#include Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) { Panel* panel = st->panel; diff --git a/Action.h b/Action.h index 40300ed48..e63b6810c 100644 --- a/Action.h +++ b/Action.h @@ -7,8 +7,13 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include + #include "Header.h" +#include "Object.h" #include "Panel.h" +#include "Process.h" #include "ProcessList.h" #include "Settings.h" #include "UsersTable.h" diff --git a/Affinity.c b/Affinity.c index 852d4d5f4..4d78944c9 100644 --- a/Affinity.c +++ b/Affinity.c @@ -12,8 +12,11 @@ in the source distribution for its full text. #include +#include "XUtils.h" + #ifdef HAVE_LIBHWLOC #include +#include #ifdef __linux__ #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_THREAD #else diff --git a/Affinity.h b/Affinity.h index 6d744dded..0797b3664 100644 --- a/Affinity.h +++ b/Affinity.h @@ -8,6 +8,11 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" + +#include + +#include "Object.h" #include "Process.h" #include "ProcessList.h" diff --git a/AffinityPanel.c b/AffinityPanel.c index ab17b420f..a8cb66eee 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -5,21 +5,30 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "config.h" +#include "config.h" // IWYU pragma: keep #include "AffinityPanel.h" #include +#include +#include #include #include "CRT.h" +#include "FunctionBar.h" +#include "Object.h" +#include "ProvideCurses.h" +#include "RichString.h" +#include "Settings.h" #include "Vector.h" #include "XUtils.h" #ifdef HAVE_LIBHWLOC #include +#include #endif + typedef struct MaskItem_ { Object super; char* text; diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index 32bb470e9..feea5786b 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -7,14 +7,17 @@ in the source distribution for its full text. #include "AvailableColumnsPanel.h" -#include #include +#include #include -#include #include "ColumnsPanel.h" -#include "Header.h" +#include "FunctionBar.h" +#include "ListItem.h" +#include "Object.h" #include "Platform.h" +#include "Process.h" +#include "ProvideCurses.h" #include "XUtils.h" diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index faa69a8f0..33006e94e 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -6,17 +6,22 @@ in the source distribution for its full text. */ #include "AvailableMetersPanel.h" -#include "MetersPanel.h" + +#include +#include +#include #include "CPUMeter.h" +#include "FunctionBar.h" #include "Header.h" #include "ListItem.h" +#include "Meter.h" +#include "MetersPanel.h" +#include "Object.h" #include "Platform.h" +#include "ProvideCurses.h" #include "XUtils.h" -#include -#include - static void AvailableMetersPanel_delete(Object* object) { Panel* super = (Panel*) object; diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index f168869d6..f7359365f 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -7,6 +7,7 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "Header.h" #include "Panel.h" #include "ProcessList.h" #include "ScreenManager.h" diff --git a/BatteryMeter.c b/BatteryMeter.c index 22a63c7a1..c91ae9977 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -9,16 +9,13 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). #include "BatteryMeter.h" +#include + #include "Battery.h" -#include "ProcessList.h" #include "CRT.h" -#include "Platform.h" +#include "Object.h" #include "XUtils.h" -#include -#include -#include - static const int BatteryMeter_attributes[] = { BATTERY diff --git a/CPUMeter.c b/CPUMeter.c index 7e70f4549..106354784 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -7,15 +7,18 @@ in the source distribution for its full text. #include "CPUMeter.h" +#include +#include +#include + #include "CRT.h" -#include "Settings.h" +#include "Object.h" #include "Platform.h" +#include "ProcessList.h" +#include "RichString.h" +#include "Settings.h" #include "XUtils.h" -#include -#include -#include -#include static const int CPUMeter_attributes[] = { CPU_NICE, diff --git a/CRT.c b/CRT.c index 2f9eb2b6f..d3afd0eca 100644 --- a/CRT.c +++ b/CRT.c @@ -5,28 +5,26 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "config.h" -#include "CRT.h" +#include "config.h" // IWYU pragma: keep -#include "RichString.h" -#include "XUtils.h" +#include "CRT.h" -#include #include +#include +#include #include +#include #include #include -#include -#include #include +#include "ProvideCurses.h" +#include "XUtils.h" + #ifdef HAVE_EXECINFO_H #include #endif -#ifdef HAVE_SETUID_ENABLED -#include -#endif #define ColorIndex(i,j) ((7-(i))*8+(j)) diff --git a/CRT.h b/CRT.h index fa2f6de72..83cb34e65 100644 --- a/CRT.h +++ b/CRT.h @@ -7,10 +7,14 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "Macros.h" +#include "config.h" #include +#include "Macros.h" +#include "ProvideCurses.h" + + typedef enum TreeStr_ { TREE_STR_HORZ, TREE_STR_VERT, diff --git a/CategoriesPanel.c b/CategoriesPanel.c index 8adf14f63..d6c25a690 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -7,15 +7,21 @@ in the source distribution for its full text. #include "CategoriesPanel.h" +#include +#include +#include + +#include "AvailableColumnsPanel.h" #include "AvailableMetersPanel.h" -#include "MetersPanel.h" -#include "DisplayOptionsPanel.h" -#include "ColumnsPanel.h" #include "ColorsPanel.h" -#include "AvailableColumnsPanel.h" - -#include -#include +#include "ColumnsPanel.h" +#include "DisplayOptionsPanel.h" +#include "FunctionBar.h" +#include "ListItem.h" +#include "MetersPanel.h" +#include "Object.h" +#include "ProvideCurses.h" +#include "Vector.h" static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/CategoriesPanel.h b/CategoriesPanel.h index 1f17bd2e6..0582c642d 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -7,6 +7,7 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "Header.h" #include "Panel.h" #include "ProcessList.h" #include "ScreenManager.h" diff --git a/CheckItem.c b/CheckItem.c index d1f119633..5c79ab13a 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -7,11 +7,12 @@ in the source distribution for its full text. #include "CheckItem.h" -#include "CRT.h" - #include #include +#include "CRT.h" +#include "RichString.h" + static void CheckItem_delete(Object* cast) { CheckItem* this = (CheckItem*)cast; diff --git a/CheckItem.h b/CheckItem.h index b4300db40..a357111f7 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -7,6 +7,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include + #include "Object.h" typedef struct CheckItem_ { diff --git a/ClockMeter.c b/ClockMeter.c index 51fbed630..c6f2ab33a 100644 --- a/ClockMeter.c +++ b/ClockMeter.c @@ -5,12 +5,15 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "ClockMeter.h" +#include "config.h" // IWYU pragma: keep -#include "CRT.h" +#include "ClockMeter.h" #include +#include "CRT.h" +#include "Object.h" + static const int ClockMeter_attributes[] = { CLOCK diff --git a/ColorsPanel.c b/ColorsPanel.c index 5b189ea3d..24e63b0e2 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -7,13 +7,19 @@ in the source distribution for its full text. #include "ColorsPanel.h" -#include "CRT.h" +#include +#include + #include "CheckItem.h" +#include "CRT.h" +#include "FunctionBar.h" +#include "Header.h" +#include "Object.h" +#include "ProvideCurses.h" +#include "RichString.h" +#include "Vector.h" #include "XUtils.h" -#include -#include -#include // TO ADD A NEW SCHEME: // * Increment the size of bool check in ColorsPanel.h diff --git a/ColumnsPanel.c b/ColumnsPanel.c index a0e9fd31c..f82501976 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -6,15 +6,18 @@ in the source distribution for its full text. */ #include "ColumnsPanel.h" -#include "Platform.h" - -#include "XUtils.h" -#include "ListItem.h" -#include "CRT.h" -#include -#include #include +#include + +#include "CRT.h" +#include "FunctionBar.h" +#include "ListItem.h" +#include "Object.h" +#include "Platform.h" +#include "Process.h" +#include "ProvideCurses.h" +#include "XUtils.h" static const char* const ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; diff --git a/ColumnsPanel.h b/ColumnsPanel.h index e8acbb233..68f80450f 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -7,6 +7,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include + #include "Panel.h" #include "Settings.h" diff --git a/CommandScreen.c b/CommandScreen.c index df039645d..7997a64a9 100644 --- a/CommandScreen.c +++ b/CommandScreen.c @@ -1,15 +1,14 @@ -#include "CommandScreen.h" +#include "config.h" // IWYU pragma: keep -#include "config.h" -#include "CRT.h" -#include "IncSet.h" -#include "ListItem.h" -#include "Platform.h" -#include "XUtils.h" +#include "CommandScreen.h" #include #include -#include + +#include "Macros.h" +#include "Panel.h" +#include "ProvideCurses.h" +#include "XUtils.h" static void CommandScreen_scan(InfoScreen* this) { diff --git a/CommandScreen.h b/CommandScreen.h index 4f3ce9479..e56982b2e 100644 --- a/CommandScreen.h +++ b/CommandScreen.h @@ -2,6 +2,9 @@ #define HEADER_CommandScreen #include "InfoScreen.h" +#include "Object.h" +#include "Process.h" + typedef struct CommandScreen_ { InfoScreen super; diff --git a/DateMeter.c b/DateMeter.c index 6ea108e14..c1a097f65 100644 --- a/DateMeter.c +++ b/DateMeter.c @@ -5,12 +5,15 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "DateMeter.h" +#include "config.h" // IWYU pragma: keep -#include "CRT.h" +#include "DateMeter.h" #include +#include "CRT.h" +#include "Object.h" + static const int DateMeter_attributes[] = { DATE diff --git a/DateTimeMeter.c b/DateTimeMeter.c index f3c877b38..745821916 100644 --- a/DateTimeMeter.c +++ b/DateTimeMeter.c @@ -5,12 +5,15 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "DateTimeMeter.h" +#include "config.h" // IWYU pragma: keep -#include "CRT.h" +#include "DateTimeMeter.h" #include +#include "CRT.h" +#include "Object.h" + static const int DateTimeMeter_attributes[] = { DATETIME diff --git a/DiskIOMeter.c b/DiskIOMeter.c index d882b4333..432ba6f03 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -7,10 +7,14 @@ in the source distribution for its full text. #include "DiskIOMeter.h" -#include +#include +#include #include "CRT.h" +#include "Macros.h" +#include "Object.h" #include "Platform.h" +#include "RichString.h" #include "XUtils.h" diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index d667ab7fa..6fa2d39cb 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -5,14 +5,19 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "DisplayOptionsPanel.h" -#include +#include #include -#include #include "CheckItem.h" #include "CRT.h" +#include "FunctionBar.h" +#include "Header.h" +#include "Object.h" +#include "ProvideCurses.h" #include "XUtils.h" diff --git a/EnvScreen.c b/EnvScreen.c index 10060ec7e..cd8e0cb3d 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -1,16 +1,18 @@ +#include "config.h" // IWYU pragma: keep + #include "EnvScreen.h" -#include "config.h" +#include +#include + #include "CRT.h" -#include "IncSet.h" -#include "ListItem.h" +#include "Macros.h" +#include "Panel.h" #include "Platform.h" +#include "ProvideCurses.h" +#include "Vector.h" #include "XUtils.h" -#include -#include -#include - const InfoScreenClass EnvScreen_class = { .super = { diff --git a/EnvScreen.h b/EnvScreen.h index 428a121f8..bf385801d 100644 --- a/EnvScreen.h +++ b/EnvScreen.h @@ -2,6 +2,8 @@ #define HEADER_EnvScreen #include "InfoScreen.h" +#include "Object.h" +#include "Process.h" typedef struct EnvScreen_ { InfoScreen super; diff --git a/FunctionBar.c b/FunctionBar.c index 50bae0b14..1c4f395b2 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -6,13 +6,14 @@ in the source distribution for its full text. */ #include "FunctionBar.h" -#include "CRT.h" -#include "RichString.h" -#include "XUtils.h" -#include -#include #include +#include + +#include "CRT.h" +#include "Macros.h" +#include "ProvideCurses.h" +#include "XUtils.h" static const char* const FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL}; diff --git a/Hashtable.h b/Hashtable.h index f42620916..dcdc89fe1 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -9,7 +9,6 @@ in the source distribution for its full text. #include -typedef struct Hashtable_ Hashtable; typedef void(*Hashtable_PairFunction)(int, void*, void*); @@ -19,12 +18,12 @@ typedef struct HashtableItem { struct HashtableItem* next; } HashtableItem; -struct Hashtable_ { +typedef struct Hashtable_ { int size; HashtableItem** buckets; int items; bool owner; -}; +} Hashtable; #ifndef NDEBUG diff --git a/Header.c b/Header.c index f52333703..3bb24c23d 100644 --- a/Header.c +++ b/Header.c @@ -7,14 +7,18 @@ in the source distribution for its full text. #include "Header.h" +#include +#include +#include +#include + #include "CRT.h" +#include "Macros.h" +#include "Object.h" #include "Platform.h" +#include "ProvideCurses.h" #include "XUtils.h" -#include -#include -#include -#include Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) { Header* this = xCalloc(1, sizeof(Header)); diff --git a/Header.h b/Header.h index 9059a9f46..f99966c3d 100644 --- a/Header.h +++ b/Header.h @@ -8,6 +8,7 @@ in the source distribution for its full text. */ #include "Meter.h" +#include "ProcessList.h" #include "Settings.h" #include "Vector.h" diff --git a/HostnameMeter.c b/HostnameMeter.c index 24424d015..6cf9e07e7 100644 --- a/HostnameMeter.c +++ b/HostnameMeter.c @@ -5,12 +5,15 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "HostnameMeter.h" +#include "config.h" // IWYU pragma: keep -#include "CRT.h" +#include "HostnameMeter.h" #include +#include "CRT.h" +#include "Object.h" + static const int HostnameMeter_attributes[] = { HOSTNAME diff --git a/IncSet.c b/IncSet.c index 3534f8577..0d1aecf5c 100644 --- a/IncSet.c +++ b/IncSet.c @@ -5,14 +5,20 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "IncSet.h" -#include "ListItem.h" -#include "CRT.h" -#include "XUtils.h" +#include #include #include +#include "CRT.h" +#include "ListItem.h" +#include "Object.h" +#include "ProvideCurses.h" +#include "XUtils.h" + static void IncMode_reset(IncMode* mode) { mode->index = 0; diff --git a/IncSet.h b/IncSet.h index f05897473..10b3625c7 100644 --- a/IncSet.h +++ b/IncSet.h @@ -8,9 +8,11 @@ in the source distribution for its full text. */ #include +#include #include "FunctionBar.h" #include "Panel.h" +#include "Vector.h" #define INCMODE_MAX 40 diff --git a/InfoScreen.c b/InfoScreen.c index ed890f7d8..0c666234e 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -1,18 +1,19 @@ +#include "config.h" // IWYU pragma: keep + #include "InfoScreen.h" -#include "config.h" -#include "Object.h" +#include +#include +#include +#include + #include "CRT.h" #include "IncSet.h" #include "ListItem.h" -#include "Platform.h" +#include "Object.h" +#include "ProvideCurses.h" #include "XUtils.h" -#include -#include -#include -#include - static const char* const InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL}; diff --git a/InfoScreen.h b/InfoScreen.h index 79927c474..0d80367d4 100644 --- a/InfoScreen.h +++ b/InfoScreen.h @@ -1,12 +1,25 @@ #ifndef HEADER_InfoScreen #define HEADER_InfoScreen +#include + #include "FunctionBar.h" #include "IncSet.h" +#include "Macros.h" +#include "Object.h" #include "Panel.h" #include "Process.h" +#include "Vector.h" + -typedef struct InfoScreen_ InfoScreen; +typedef struct InfoScreen_ { + Object super; + const Process* process; + Panel* display; + FunctionBar* bar; + IncSet* inc; + Vector* lines; +} InfoScreen; typedef void(*InfoScreen_Scan)(InfoScreen*); typedef void(*InfoScreen_Draw)(InfoScreen*); @@ -27,15 +40,6 @@ typedef struct InfoScreenClass_ { #define InfoScreen_onErr(this_) As_InfoScreen(this_)->onErr((InfoScreen*)(this_)) #define InfoScreen_onKey(this_, ch_) As_InfoScreen(this_)->onKey((InfoScreen*)(this_), ch_) -struct InfoScreen_ { - Object super; - const Process* process; - Panel* display; - FunctionBar* bar; - IncSet* inc; - Vector* lines; -}; - InfoScreen* InfoScreen_init(InfoScreen* this, const Process* process, FunctionBar* bar, int height, const char* panelHeader); InfoScreen* InfoScreen_done(InfoScreen* this); diff --git a/ListItem.c b/ListItem.c index c4479d73f..866f20ff2 100644 --- a/ListItem.c +++ b/ListItem.c @@ -5,16 +5,18 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "ListItem.h" +#include +#include +#include + #include "CRT.h" #include "RichString.h" #include "XUtils.h" -#include -#include -#include - static void ListItem_delete(Object* cast) { ListItem* this = (ListItem*)cast; diff --git a/ListItem.h b/ListItem.h index 387e8e214..5bbcda14f 100644 --- a/ListItem.h +++ b/ListItem.h @@ -7,6 +7,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include + #include "Object.h" typedef struct ListItem_ { diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index c52bffc1d..76b89ea11 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -8,7 +8,9 @@ in the source distribution for its full text. #include "LoadAverageMeter.h" #include "CRT.h" +#include "Object.h" #include "Platform.h" +#include "RichString.h" #include "XUtils.h" diff --git a/Macros.h b/Macros.h index 00413f4ec..e42cbe53e 100644 --- a/Macros.h +++ b/Macros.h @@ -1,6 +1,8 @@ #ifndef HEADER_Macros #define HEADER_Macros +#include // IWYU pragma: keep + #ifndef MINIMUM #define MINIMUM(a, b) ((a) < (b) ? (a) : (b)) #endif diff --git a/MainPanel.c b/MainPanel.c index 48d869fff..05a55e600 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -7,12 +7,20 @@ in the source distribution for its full text. */ #include "MainPanel.h" -#include "Process.h" -#include "Platform.h" -#include "CRT.h" +#include #include +#include "CRT.h" +#include "FunctionBar.h" +#include "Platform.h" +#include "Process.h" +#include "ProcessList.h" +#include "ProvideCurses.h" +#include "Settings.h" +#include "XUtils.h" + + static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL}; void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) { diff --git a/MainPanel.h b/MainPanel.h index 9e2da305a..7f7520d6c 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -8,9 +8,15 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include + #include "Action.h" #include "IncSet.h" +#include "Object.h" #include "Panel.h" +#include "Process.h" + typedef struct MainPanel_ { Panel super; diff --git a/Makefile.am b/Makefile.am index fd02bb3e1..d5b05d060 100644 --- a/Makefile.am +++ b/Makefile.am @@ -103,6 +103,7 @@ myhtopheaders = \ Panel.h \ Process.h \ ProcessList.h \ + ProvideCurses.h \ RichString.h \ ScreenManager.h \ Settings.h \ diff --git a/MemoryMeter.c b/MemoryMeter.c index 311f17910..3d29ddf4d 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -8,13 +8,9 @@ in the source distribution for its full text. #include "MemoryMeter.h" #include "CRT.h" +#include "Object.h" #include "Platform.h" - -#include -#include -#include -#include -#include +#include "RichString.h" static const int MemoryMeter_attributes[] = { diff --git a/Meter.c b/Meter.c index 154a5a642..843703623 100644 --- a/Meter.c +++ b/Meter.c @@ -5,19 +5,23 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "Meter.h" -#include "RichString.h" -#include "Object.h" +#include +#include +#include +#include +#include + #include "CRT.h" -#include "Settings.h" +#include "Macros.h" +#include "Object.h" +#include "ProvideCurses.h" +#include "RichString.h" #include "XUtils.h" -#include -#include -#include -#include -#include #define GRAPH_HEIGHT 4 /* Unit: rows (lines) */ diff --git a/Meter.h b/Meter.h index 5432a768b..84d157bb4 100644 --- a/Meter.h +++ b/Meter.h @@ -7,12 +7,17 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include #include #include "ListItem.h" +#include "Object.h" +#include "ProcessList.h" + #define METER_BUFFER_LEN 256 +struct Meter_; typedef struct Meter_ Meter; typedef void(*Meter_Init)(Meter*); @@ -67,7 +72,7 @@ struct Meter_ { int param; GraphData* drawData; int h; - struct ProcessList_* pl; + ProcessList* pl; char curItems; double* values; double total; @@ -91,7 +96,7 @@ typedef enum { extern const MeterClass Meter_class; -Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type); +Meter* Meter_new(ProcessList* pl, int param, const MeterClass* type); int Meter_humanUnit(char* buffer, unsigned long int value, int size); diff --git a/MetersPanel.c b/MetersPanel.c index 89c54e0b1..7e47ad8b6 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -8,8 +8,14 @@ in the source distribution for its full text. #include "MetersPanel.h" #include -#include + #include "CRT.h" +#include "FunctionBar.h" +#include "Header.h" +#include "ListItem.h" +#include "Meter.h" +#include "Object.h" +#include "ProvideCurses.h" // Note: In code the meters are known to have bar/text/graph "Modes", but in UI diff --git a/MetersPanel.h b/MetersPanel.h index 760388d85..cf4de6042 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -7,10 +7,15 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include + #include "Panel.h" #include "ScreenManager.h" #include "Settings.h" +#include "Vector.h" + +struct MetersPanel_; typedef struct MetersPanel_ MetersPanel; struct MetersPanel_ { diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c index 07c7dc971..8c0cb45d3 100644 --- a/NetworkIOMeter.c +++ b/NetworkIOMeter.c @@ -1,7 +1,14 @@ #include "NetworkIOMeter.h" +#include +#include + #include "CRT.h" +#include "Macros.h" +#include "Object.h" #include "Platform.h" +#include "RichString.h" +#include "XUtils.h" static const int NetworkIOMeter_attributes[] = { diff --git a/Object.c b/Object.c index 97e913e6c..01b6c4ceb 100644 --- a/Object.c +++ b/Object.c @@ -8,6 +8,9 @@ in the source distribution for its full text. #include "Object.h" +#include + + const ObjectClass Object_class = { .extends = NULL }; diff --git a/Object.h b/Object.h index 6c31fa347..2d3fd3c44 100644 --- a/Object.h +++ b/Object.h @@ -9,10 +9,10 @@ in the source distribution for its full text. */ #include "RichString.h" -#include "Macros.h" -#include "XUtils.h" +#include "XUtils.h" // IWYU pragma: keep +struct Object_; typedef struct Object_ Object; typedef void(*Object_Display)(const Object*, RichString*); @@ -29,7 +29,7 @@ typedef void(*Object_Delete)(Object*); #define Class(class_) ((const ObjectClass*)(&(class_ ## _class))) -#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); +#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); typedef struct ObjectClass_ { const void* const extends; diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 8e099bbe4..0de9ee037 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -5,24 +5,24 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "OpenFilesScreen.h" +#include "config.h" // IWYU pragma: keep -#include "CRT.h" -#include "ProcessList.h" -#include "IncSet.h" -#include "FunctionBar.h" -#include "XUtils.h" +#include "OpenFilesScreen.h" -#include +#include #include -#include -#include -#include #include -#include +#include +#include #include #include +#include "Macros.h" +#include "Panel.h" +#include "ProvideCurses.h" +#include "Vector.h" +#include "XUtils.h" + typedef struct OpenFiles_Data_ { char* data[7]; diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index 04a8e3956..0fbafe0e1 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -7,7 +7,11 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include + #include "InfoScreen.h" +#include "Object.h" +#include "Process.h" typedef struct OpenFilesScreen_ { InfoScreen super; diff --git a/Panel.c b/Panel.c index 76e45d6ee..782cbdc1c 100644 --- a/Panel.c +++ b/Panel.c @@ -7,17 +7,20 @@ in the source distribution for its full text. #include "Panel.h" +#include +#include +#include +#include +#include +#include + #include "CRT.h" -#include "RichString.h" #include "ListItem.h" +#include "Macros.h" +#include "ProvideCurses.h" +#include "RichString.h" #include "XUtils.h" -#include -#include -#include -#include -#include -#include const PanelClass Panel_class = { .super = { diff --git a/Panel.h b/Panel.h index 4b28c42d5..878460754 100644 --- a/Panel.h +++ b/Panel.h @@ -7,10 +7,15 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include + #include "FunctionBar.h" #include "Object.h" +#include "RichString.h" #include "Vector.h" + +struct Panel_; typedef struct Panel_ Panel; typedef enum HandlerResult_ { diff --git a/Process.c b/Process.c index 147caee6b..6d9101a72 100644 --- a/Process.c +++ b/Process.c @@ -6,36 +6,35 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "Process.h" -#include "Settings.h" -#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "CRT.h" -#include "RichString.h" #include "Platform.h" +#include "RichString.h" +#include "Settings.h" #include "XUtils.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef MAJOR_IN_MKDEV +#if defined(MAJOR_IN_MKDEV) #include #elif defined(MAJOR_IN_SYSMACROS) #include #endif + static int Process_getuid = -1; char Process_pidFormat[20] = "%7d "; diff --git a/Process.h b/Process.h index a4abf03e4..190a98af1 100644 --- a/Process.h +++ b/Process.h @@ -8,6 +8,14 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include +#include + +#include "Object.h" +#include "RichString.h" + + #ifdef __ANDROID__ #define SYS_ioprio_get __NR_ioprio_get #define SYS_ioprio_set __NR_ioprio_set @@ -20,10 +28,6 @@ in the source distribution for its full text. #endif #define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K ) -#include - -#include "Object.h" - #define PROCESS_FLAG_IO 0x0001 typedef enum ProcessFields { diff --git a/ProcessList.c b/ProcessList.c index b74454319..b5a13f0aa 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -7,13 +7,12 @@ in the source distribution for its full text. #include "ProcessList.h" +#include +#include + #include "CRT.h" -#include "Platform.h" #include "XUtils.h" -#include -#include - ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { this->processes = Vector_new(klass, true, DEFAULT_SIZE); diff --git a/ProcessList.h b/ProcessList.h index 164ff7b05..2dd2c8d23 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -7,9 +7,16 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + +#include +#include + #include "Hashtable.h" +#include "Object.h" #include "Panel.h" #include "Process.h" +#include "RichString.h" #include "Settings.h" #include "UsersTable.h" #include "Vector.h" @@ -18,6 +25,7 @@ in the source distribution for its full text. #include #endif + #ifndef MAX_NAME #define MAX_NAME 128 #endif diff --git a/ProvideCurses.h b/ProvideCurses.h new file mode 100644 index 000000000..c35d696d4 --- /dev/null +++ b/ProvideCurses.h @@ -0,0 +1,34 @@ +#ifndef HEADER_ProvideCurses +#define HEADER_ProvideCurses +/* +htop - RichString.h +(C) 2004,2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + + +#include "config.h" + +// IWYU pragma: begin_exports + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#elif defined(HAVE_NCURSES_NCURSES_H) +#include +#elif defined(HAVE_NCURSES_CURSES_H) +#include +#elif defined(HAVE_NCURSES_H) +#include +#elif defined(HAVE_CURSES_H) +#include +#endif + +#ifdef HAVE_LIBNCURSESW +#include +#include +#endif + +// IWYU pragma: end_exports + +#endif // HEADER_ProvideCurses diff --git a/RichString.c b/RichString.c index 3cb19ae41..60fe8d077 100644 --- a/RichString.c +++ b/RichString.c @@ -6,12 +6,14 @@ in the source distribution for its full text. */ #include "RichString.h" -#include "Macros.h" -#include "XUtils.h" +#include #include #include +#include "Macros.h" +#include "XUtils.h" + #define charBytes(n) (sizeof(CharType) * (n)) diff --git a/RichString.h b/RichString.h index 8ba0d6ed1..2e35b827c 100644 --- a/RichString.h +++ b/RichString.h @@ -7,26 +7,10 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ - #include "config.h" -#include - -#include -#ifdef HAVE_NCURSESW_CURSES_H -#include -#elif defined(HAVE_NCURSES_NCURSES_H) -#include -#elif defined(HAVE_NCURSES_CURSES_H) -#include -#elif defined(HAVE_NCURSES_H) -#include -#elif defined(HAVE_CURSES_H) -#include -#endif -#ifdef HAVE_LIBNCURSESW -#include -#endif +#include "ProvideCurses.h" + #define RichString_size(this) ((this)->chlen) #define RichString_sizeVal(this) ((this).chlen) diff --git a/ScreenManager.c b/ScreenManager.c index 4766e069a..2fce07de2 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -7,16 +7,17 @@ in the source distribution for its full text. #include "ScreenManager.h" +#include +#include +#include +#include + #include "CRT.h" -#include "MainPanel.h" +#include "FunctionBar.h" #include "Object.h" #include "ProcessList.h" - - -#include -#include -#include -#include +#include "ProvideCurses.h" +#include "XUtils.h" ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, const State* state, bool owner) { diff --git a/ScreenManager.h b/ScreenManager.h index ad312930a..97e849f39 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -7,12 +7,15 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include + #include "Action.h" #include "Header.h" #include "Panel.h" #include "Settings.h" #include "Vector.h" + typedef enum Orientation_ { VERTICAL, HORIZONTAL diff --git a/Settings.c b/Settings.c index fd623ad8e..ac8321a0e 100644 --- a/Settings.c +++ b/Settings.c @@ -7,15 +7,17 @@ in the source distribution for its full text. #include "Settings.h" +#include +#include +#include +#include + #include "CRT.h" +#include "Macros.h" +#include "Meter.h" #include "Platform.h" -#include "Vector.h" #include "XUtils.h" -#include -#include -#include -#include void Settings_delete(Settings* this) { free(this->filename); diff --git a/Settings.h b/Settings.h index 73da4f07e..4eece3b08 100644 --- a/Settings.h +++ b/Settings.h @@ -7,12 +7,15 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#define DEFAULT_DELAY 15 +#include "config.h" // IWYU pragma: keep #include #include "Process.h" + +#define DEFAULT_DELAY 15 + typedef struct { int len; char** names; diff --git a/SignalsPanel.c b/SignalsPanel.c index 0ebe16d33..7937c5dc4 100644 --- a/SignalsPanel.c +++ b/SignalsPanel.c @@ -5,17 +5,16 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "Panel.h" #include "SignalsPanel.h" -#include -#include #include -#include +#include +#include "FunctionBar.h" #include "ListItem.h" +#include "Object.h" +#include "Panel.h" #include "Platform.h" -#include "RichString.h" #include "XUtils.h" diff --git a/SignalsPanel.h b/SignalsPanel.h index 9ded22f1b..0a90b08e5 100644 --- a/SignalsPanel.h +++ b/SignalsPanel.h @@ -7,6 +7,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "Panel.h" + typedef struct SignalItem_ { const char* name; int number; diff --git a/SwapMeter.c b/SwapMeter.c index fc4e6b289..9de7fa354 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -8,13 +8,9 @@ in the source distribution for its full text. #include "SwapMeter.h" #include "CRT.h" +#include "Object.h" #include "Platform.h" - -#include -#include -#include -#include -#include +#include "RichString.h" static const int SwapMeter_attributes[] = { diff --git a/TasksMeter.c b/TasksMeter.c index a13766ed0..2116e3226 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -8,7 +8,11 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "CRT.h" -#include "Platform.h" +#include "Macros.h" +#include "Object.h" +#include "ProcessList.h" +#include "RichString.h" +#include "Settings.h" #include "XUtils.h" diff --git a/TraceScreen.c b/TraceScreen.c index a3c57870a..e83e8a513 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -5,26 +5,28 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "TraceScreen.h" +#include "config.h" // IWYU pragma: keep -#include "CRT.h" -#include "ProcessList.h" -#include "ListItem.h" -#include "IncSet.h" -#include "FunctionBar.h" -#include "XUtils.h" +#include "TraceScreen.h" +#include +#include +#include +#include #include -#include -#include #include -#include +#include #include -#include +#include #include -#include #include -#include + +#include "CRT.h" +#include "FunctionBar.h" +#include "IncSet.h" +#include "Panel.h" +#include "ProvideCurses.h" +#include "XUtils.h" static const char* const TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL}; diff --git a/TraceScreen.h b/TraceScreen.h index 552d14fa3..819204792 100644 --- a/TraceScreen.h +++ b/TraceScreen.h @@ -12,6 +12,8 @@ in the source distribution for its full text. #include #include "InfoScreen.h" +#include "Object.h" +#include "Process.h" typedef struct TraceScreen_ { diff --git a/UptimeMeter.c b/UptimeMeter.c index 1011aa108..89e341752 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -8,6 +8,7 @@ in the source distribution for its full text. #include "UptimeMeter.h" #include "CRT.h" +#include "Object.h" #include "Platform.h" #include "XUtils.h" diff --git a/UsersTable.c b/UsersTable.c index 41e52d3f3..89fdfc4d4 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -5,17 +5,12 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "config.h" - #include "UsersTable.h" -#include -#include -#include #include -#include +#include +#include #include -#include #include "XUtils.h" diff --git a/Vector.c b/Vector.c index 291ef48fc..1dfccc446 100644 --- a/Vector.c +++ b/Vector.c @@ -10,7 +10,8 @@ in the source distribution for its full text. #include #include #include -#include + +#include "XUtils.h" Vector* Vector_new(const ObjectClass* type, bool owner, int size) { diff --git a/Vector.h b/Vector.h index 428b931d0..3cff212cf 100644 --- a/Vector.h +++ b/Vector.h @@ -9,6 +9,8 @@ in the source distribution for its full text. #include "Object.h" +#include + #ifndef DEFAULT_SIZE #define DEFAULT_SIZE (-1) diff --git a/XUtils.c b/XUtils.c index 4fccec3ab..1e77cd3ba 100644 --- a/XUtils.c +++ b/XUtils.c @@ -5,14 +5,13 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "config.h" +#include "config.h" // IWYU pragma: keep #include "XUtils.h" #include #include #include -#include #include #include "CRT.h" diff --git a/XUtils.h b/XUtils.h index 742b8e9eb..f30af6f3e 100644 --- a/XUtils.h +++ b/XUtils.h @@ -7,10 +7,11 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include -#include +#include "config.h" // IWYU pragma: keep + #include -#include +#include // IWYU pragma: keep +#include // IWYU pragma: keep #include "Macros.h" diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index 250948483..366570602 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -7,6 +7,14 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include + +#include "Object.h" +#include "Process.h" +#include "RichString.h" +#include "Settings.h" + + typedef enum FreeBSDProcessFields_ { // Add platform-specific fields here, with ids >= 100 JID = 100, diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 92620c9b1..629698769 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -5,24 +5,27 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "Macros.h" -#include "ProcessList.h" #include "FreeBSDProcessList.h" -#include "FreeBSDProcess.h" -#include "zfs/ZfsArcStats.h" -#include "zfs/openzfs_sysctl.h" -#include "Macros.h" -#include -#include -#include -#include -#include +#include #include #include #include +#include #include #include +#include +#include +#include +#include + +#include "FreeBSDProcess.h" +#include "Macros.h" +#include "ProcessList.h" +#include "zfs/ZfsArcStats.h" +#include "zfs/openzfs_sysctl.h" +#include "XUtils.h" + char jail_errmsg[JAIL_ERRMSGLEN]; diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 064433b35..75f71c123 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -7,14 +7,20 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "zfs/ZfsArcStats.h" - #include #include #include #include #include +#include "FreeBSDProcess.h" +#include "Hashtable.h" +#include "Process.h" +#include "ProcessList.h" +#include "UsersTable.h" +#include "zfs/ZfsArcStats.h" + + #define JAIL_ERRMSGLEN 1024 extern char jail_errmsg[JAIL_ERRMSGLEN]; diff --git a/htop.c b/htop.c index 39aeec1a7..7d1c1b165 100644 --- a/htop.c +++ b/htop.c @@ -5,28 +5,36 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "config.h" +#include "config.h" // IWYU pragma: keep -#include "FunctionBar.h" -#include "Hashtable.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Action.h" #include "ColumnsPanel.h" #include "CRT.h" +#include "Hashtable.h" +#include "Header.h" +#include "IncSet.h" #include "MainPanel.h" #include "MetersPanel.h" +#include "Panel.h" +#include "Platform.h" +#include "Process.h" #include "ProcessList.h" +#include "ProvideCurses.h" #include "ScreenManager.h" #include "Settings.h" #include "UsersTable.h" -#include "Platform.h" #include "XUtils.h" -#include -#include -#include -#include -#include -#include -#include //#link m diff --git a/linux/Battery.c b/linux/Battery.c index faf4064c3..f3e2ff246 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -13,13 +13,17 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat #include #include -#include +#include +#include +#include +#include #include #include -#include #include -#include +#include +#include "BatteryMeter.h" +#include "Macros.h" #include "XUtils.h" diff --git a/linux/Battery.h b/linux/Battery.h index 496ce1a62..18b0dab60 100644 --- a/linux/Battery.h +++ b/linux/Battery.h @@ -11,6 +11,7 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat #include "BatteryMeter.h" + void Battery_getData(double* level, ACPresence* isOnAC); #endif diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index cc1b3916f..50f57c10f 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -7,6 +7,12 @@ in the source distribution for its full text. #include "IOPriorityPanel.h" +#include +#include + +#include "FunctionBar.h" +#include "ListItem.h" +#include "Object.h" #include "XUtils.h" diff --git a/linux/IOPriorityPanel.h b/linux/IOPriorityPanel.h index d73582261..2ac4b3166 100644 --- a/linux/IOPriorityPanel.h +++ b/linux/IOPriorityPanel.h @@ -9,7 +9,6 @@ in the source distribution for its full text. #include "Panel.h" #include "IOPriority.h" -#include "ListItem.h" Panel* IOPriorityPanel_new(IOPriority currPrio); diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 75900b5a2..6d1e3ca63 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -6,19 +6,19 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "Process.h" -#include "ProcessList.h" #include "LinuxProcess.h" -#include "CRT.h" -#include "Platform.h" -#include "XUtils.h" +#include +#include #include -#include #include -#include -#include -#include +#include +#include + +#include "CRT.h" +#include "Process.h" +#include "ProvideCurses.h" +#include "XUtils.h" /* semi-global */ diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index ac80317db..8e7c36dc3 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -8,6 +8,17 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" + +#include +#include + +#include "IOPriority.h" +#include "Object.h" +#include "Process.h" +#include "RichString.h" +#include "Settings.h" + #define PROCESS_FLAG_LINUX_IOPRIO 0x0100 #define PROCESS_FLAG_LINUX_OPENVZ 0x0200 #define PROCESS_FLAG_LINUX_VSERVER 0x0400 @@ -87,8 +98,6 @@ typedef enum LinuxProcessFields { LAST_PROCESSFIELD = 124, } LinuxProcessField; -#include "IOPriority.h" - typedef struct LinuxProcess_ { Process super; bool isKernelThread; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index bbb064d14..1ed13826c 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -5,44 +5,52 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "LinuxProcessList.h" -#include "LinuxProcess.h" -#include "CRT.h" -#include "XUtils.h" -#include -#include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include +#include +#include #include +#include +#include +#include #include -#include -#include +#include +#include +#include +#include #include -#include -#ifdef MAJOR_IN_MKDEV -#include -#elif defined(MAJOR_IN_SYSMACROS) -#include -#endif #ifdef HAVE_DELAYACCT +#include +#include #include +#include +#include #include +#include #include #include -#include -#include -#include #endif +#include "CRT.h" +#include "LinuxProcess.h" +#include "Macros.h" +#include "Object.h" +#include "Process.h" +#include "Settings.h" +#include "XUtils.h" + +#ifdef MAJOR_IN_MKDEV +#include +#elif defined(MAJOR_IN_SYSMACROS) +#include +#endif + + static ssize_t xread(int fd, void *buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 913f3cb4f..57bc9dc0b 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -7,7 +7,14 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" + +#include +#include + +#include "Hashtable.h" #include "ProcessList.h" +#include "UsersTable.h" #include "zfs/ZfsArcStats.h" typedef struct CPUData_ { diff --git a/linux/Platform.c b/linux/Platform.c index feb6b6cff..1bb476ab2 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -5,39 +5,48 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" + #include "Platform.h" + +#include +#include +#include +#include +#include + +#include "BatteryMeter.h" +#include "ClockMeter.h" +#include "CPUMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" +#include "DiskIOMeter.h" +#include "HostnameMeter.h" #include "IOPriority.h" #include "IOPriorityPanel.h" #include "LinuxProcess.h" #include "LinuxProcessList.h" -#include "Battery.h" - +#include "LoadAverageMeter.h" +#include "Macros.h" +#include "MainPanel.h" #include "Meter.h" -#include "CPUMeter.h" -#include "DiskIOMeter.h" #include "MemoryMeter.h" +#include "NetworkIOMeter.h" +#include "Object.h" +#include "Panel.h" +#include "PressureStallMeter.h" +#include "ProcessList.h" +#include "ProvideCurses.h" +#include "SELinuxMeter.h" +#include "Settings.h" #include "SwapMeter.h" #include "TasksMeter.h" -#include "LoadAverageMeter.h" #include "UptimeMeter.h" -#include "PressureStallMeter.h" -#include "ClockMeter.h" -#include "DateMeter.h" -#include "DateTimeMeter.h" -#include "HostnameMeter.h" -#include "NetworkIOMeter.h" -#include "zfs/ZfsArcMeter.h" -#include "zfs/ZfsCompressedArcMeter.h" -#include "LinuxProcess.h" -#include "SELinuxMeter.h" #include "XUtils.h" -#include -#include -#include -#include -#include -#include +#include "zfs/ZfsArcMeter.h" +#include "zfs/ZfsArcStats.h" +#include "zfs/ZfsCompressedArcMeter.h" ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, (int)M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; diff --git a/linux/Platform.h b/linux/Platform.h index 007cd32b2..3d4cabac0 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -7,10 +7,12 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include + #include "Action.h" -#include "MainPanel.h" -#include "BatteryMeter.h" -#include "LinuxProcess.h" +#include "Meter.h" +#include "Process.h" #include "SignalsPanel.h" extern ProcessField Platform_defaultFields[]; diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c index 4733415fe..9ac0ced23 100644 --- a/linux/PressureStallMeter.c +++ b/linux/PressureStallMeter.c @@ -8,10 +8,14 @@ in the source distribution for its full text. #include "PressureStallMeter.h" +#include #include #include "CRT.h" +#include "Meter.h" +#include "Object.h" #include "Platform.h" +#include "RichString.h" #include "XUtils.h" diff --git a/linux/SELinuxMeter.c b/linux/SELinuxMeter.c index 8562215b5..275eefef0 100644 --- a/linux/SELinuxMeter.c +++ b/linux/SELinuxMeter.c @@ -10,12 +10,16 @@ in the source distribution for its full text. #include "CRT.h" #include +#include +#include +#include #include -#include +#include #include -#include -#include -#include + +#include "Macros.h" +#include "Object.h" +#include "XUtils.h" static const int SELinuxMeter_attributes[] = { diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index acfe13f25..55ef2c562 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -9,19 +9,10 @@ in the source distribution for its full text. #include "ZfsArcStats.h" #include "CRT.h" +#include "Object.h" #include "Platform.h" +#include "RichString.h" -#include -#include -#include -#include -#include - -/*{ -#include "ZfsArcStats.h" - -#include "Meter.h" -}*/ static const int ZfsArcMeter_attributes[] = { ZFS_MFU, ZFS_MRU, ZFS_ANON, ZFS_HEADER, ZFS_OTHER diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index 0153fccbd..0a67c7edf 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -6,23 +6,16 @@ in the source distribution for its full text. */ #include "ZfsCompressedArcMeter.h" -#include "ZfsArcStats.h" #include "CRT.h" +#include "Meter.h" +#include "Object.h" #include "Platform.h" +#include "RichString.h" #include "XUtils.h" -#include -#include -#include -#include -#include - -/*{ -#include "ZfsArcStats.h" +#include "zfs/ZfsArcStats.h" -#include "Meter.h" -}*/ static const int ZfsCompressedArcMeter_attributes[] = { ZFS_COMPRESSED From 0db398d4c3472071b2814505242450cd8f831501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 18 Oct 2020 17:48:24 +0200 Subject: [PATCH 319/411] Allow low and high value of CLAMP to be equal Can for example occur in RichString_setAttrn(), when pausing and resuming process tracing: htop: RichString.c:56: void RichString_setAttrn(RichString *, int, int, int): Assertion `(0) < (this->chlen - 1)' failed. ./htop(backtrace+0x5b)[0x45d9eb] ./htop(CRT_handleSIGSEGV+0x189)[0x4ebab9] /lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7fd249d35140] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x141)[0x7fd249b6ac41] /lib/x86_64-linux-gnu/libc.so.6(abort+0x123)[0x7fd249b54537] /lib/x86_64-linux-gnu/libc.so.6(+0x2540f)[0x7fd249b5440f] /lib/x86_64-linux-gnu/libc.so.6(+0x345c2)[0x7fd249b635c2] ./htop(RichString_setAttrn+0x234)[0x526de4] ./htop(RichString_setAttr+0x50)[0x5275c0] ./htop(Panel_draw+0x17b6)[0x514c26] ./htop(InfoScreen_run+0x305)[0x4fe7a5] ./htop[0x4d59d8] ./htop[0x5029cf] ./htop(ScreenManager_run+0x69f)[0x52a82f] ./htop(main+0x704)[0x4f8774] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea)[0x7fd249b55cca] ./htop(_start+0x2a)[0x4268ea] --- Macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Macros.h b/Macros.h index e42cbe53e..2f92acb12 100644 --- a/Macros.h +++ b/Macros.h @@ -12,7 +12,7 @@ #endif #ifndef CLAMP -#define CLAMP(x, low, high) (assert((low) < (high)), ((x) > (high)) ? (high) : MAXIMUM(x, low)) +#define CLAMP(x, low, high) (assert((low) <= (high)), ((x) > (high)) ? (high) : MAXIMUM(x, low)) #endif #ifndef ARRAYSIZE From 361877454fe56c95a995d5bdbb7eb70c21e39d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 15 Oct 2020 22:37:02 +0200 Subject: [PATCH 320/411] Cache PAGE_SIZE man:sysconf(3) states: The values obtained from these functions are system configuration constants. They do not change during the lifetime of a process. --- CRT.c | 7 +++++++ CRT.h | 3 +++ Process.c | 4 ++-- Process.h | 7 ------- darwin/DarwinProcess.c | 6 ++++-- dragonflybsd/DragonFlyBSDProcessList.c | 12 +++++++----- freebsd/FreeBSDProcessList.c | 9 +++++---- linux/LinuxProcess.c | 10 +++++----- linux/LinuxProcessList.c | 8 ++++---- openbsd/OpenBSDProcessList.c | 18 +++++++++--------- solaris/SolarisProcessList.c | 25 ++++++++++++++----------- 11 files changed, 60 insertions(+), 49 deletions(-) diff --git a/CRT.c b/CRT.c index d3afd0eca..f6321f4c8 100644 --- a/CRT.c +++ b/CRT.c @@ -544,6 +544,9 @@ const char* CRT_termType; int CRT_colorScheme = 0; +long CRT_pageSize = -1; +long CRT_pageSizeKB = -1; + ATTR_NORETURN static void CRT_handleSIGTERM(int sgn) { (void) sgn; @@ -675,6 +678,10 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { mousemask(BUTTON1_RELEASED, NULL); #endif + CRT_pageSize = sysconf(_SC_PAGESIZE); + if (CRT_pageSize == -1) + CRT_fatalError("Fatal error: Can not get PAGE_SIZE by sysconf(_SC_PAGESIZE)"); + CRT_pageSizeKB = CRT_pageSize / 1024; } void CRT_done() { diff --git a/CRT.h b/CRT.h index 83cb34e65..606492a4a 100644 --- a/CRT.h +++ b/CRT.h @@ -149,6 +149,9 @@ extern const char* CRT_termType; extern int CRT_colorScheme; +extern long CRT_pageSize; +extern long CRT_pageSizeKB; + #ifdef HAVE_SETUID_ENABLED void CRT_dropPrivileges(void); diff --git a/Process.c b/Process.c index 6d9101a72..5f5be13ad 100644 --- a/Process.c +++ b/Process.c @@ -311,8 +311,8 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field } case MAJFLT: Process_colorNumber(str, this->majflt, coloring); return; case MINFLT: Process_colorNumber(str, this->minflt, coloring); return; - case M_RESIDENT: Process_humanNumber(str, this->m_resident * PAGE_SIZE_KB, coloring); return; - case M_SIZE: Process_humanNumber(str, this->m_size * PAGE_SIZE_KB, coloring); return; + case M_RESIDENT: Process_humanNumber(str, this->m_resident * CRT_pageSizeKB, coloring); return; + case M_SIZE: Process_humanNumber(str, this->m_size * CRT_pageSizeKB, coloring); return; case NICE: { xSnprintf(buffer, n, "%3ld ", this->nice); attr = this->nice < 0 ? CRT_colors[PROCESS_HIGH_PRIORITY] diff --git a/Process.h b/Process.h index 190a98af1..db85f147c 100644 --- a/Process.h +++ b/Process.h @@ -21,13 +21,6 @@ in the source distribution for its full text. #define SYS_ioprio_set __NR_ioprio_set #endif -// On Linux, this works only with glibc 2.1+. On earlier versions -// the behavior is similar to have a hardcoded page size. -#ifndef PAGE_SIZE -#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) ) -#endif -#define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K ) - #define PROCESS_FLAG_IO 0x0001 typedef enum ProcessFields { diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 48574e2f7..7049cb1ed 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -15,6 +15,8 @@ in the source distribution for its full text. #include +#include "CRT.h" + const ProcessClass DarwinProcess_class = { .super = { @@ -257,8 +259,8 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList proc->super.time = (pti.pti_total_system + pti.pti_total_user) / 10000000; proc->super.nlwp = pti.pti_threadnum; - proc->super.m_size = pti.pti_virtual_size / 1024 / PAGE_SIZE_KB; - proc->super.m_resident = pti.pti_resident_size / 1024 / PAGE_SIZE_KB; + proc->super.m_size = pti.pti_virtual_size / CRT_pageSize; + proc->super.m_resident = pti.pti_resident_size / CRT_pageSize; proc->super.majflt = pti.pti_faults; proc->super.percent_mem = (double)pti.pti_resident_size * 100.0 / (double)dpl->host_info.max_mem; diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 87f16069a..0792c75be 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -9,7 +9,6 @@ in the source distribution for its full text. #include "ProcessList.h" #include "DragonFlyBSDProcessList.h" #include "DragonFlyBSDProcess.h" -#include "Macros.h" #include #include @@ -22,6 +21,9 @@ in the source distribution for its full text. #include #include +#include "CRT.h" +#include "Macros.h" + static int MIB_hw_physmem[2]; static int MIB_vm_stats_vm_v_page_count[4]; @@ -54,8 +56,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui len = sizeof(pageSize); if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1) { - pageSize = PAGE_SIZE; - pageSizeKb = PAGE_SIZE_KB; + pageSize = CRT_pageSize; + pageSizeKb = CRT_pageSizeKB; } else { pageSizeKb = pageSize / ONE_K; } @@ -431,12 +433,12 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->m_size = kproc->kp_vm_map_size / 1024 / pageSizeKb; proc->m_resident = kproc->kp_vm_rssize; - proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0; + proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(this->totalMem) * 100.0; proc->nlwp = kproc->kp_nthreads; // number of lwp thread proc->time = (kproc->kp_swtime + 5000) / 10000; proc->percent_cpu = 100.0 * ((double)kproc->kp_lwp.kl_pctcpu / (double)kernelFScale); - proc->percent_mem = 100.0 * (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem); + proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(this->totalMem); if (proc->percent_cpu > 0.1) { // system idle process should own all CPU time left regardless of CPU count diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 629698769..b13b217be 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -19,6 +19,7 @@ in the source distribution for its full text. #include #include +#include "CRT.h" #include "FreeBSDProcess.h" #include "Macros.h" #include "ProcessList.h" @@ -60,8 +61,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui len = sizeof(pageSize); if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1) { - pageSize = PAGE_SIZE; - pageSizeKb = PAGE_SIZE_KB; + pageSize = CRT_pageSize; + pageSizeKb = CRT_pageSize; } else { pageSizeKb = pageSize / ONE_K; } @@ -446,12 +447,12 @@ void ProcessList_goThroughEntries(ProcessList* this) { // from FreeBSD source /src/usr.bin/top/machine.c proc->m_size = kproc->ki_size / 1024 / pageSizeKb; proc->m_resident = kproc->ki_rssize; - proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0; + proc->percent_mem = (proc->m_resident * pageSizeKb) / (double)(this->totalMem) * 100.0; proc->nlwp = kproc->ki_numthreads; proc->time = (kproc->ki_runtime + 5000) / 10000; proc->percent_cpu = 100.0 * ((double)kproc->ki_pctcpu / (double)kernelFScale); - proc->percent_mem = 100.0 * (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem); + proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(this->totalMem); /* * TODO diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 6d1e3ca63..8003157cb 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -215,11 +215,11 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) } case CMINFLT: Process_colorNumber(str, lp->cminflt, coloring); return; case CMAJFLT: Process_colorNumber(str, lp->cmajflt, coloring); return; - case M_DRS: Process_humanNumber(str, lp->m_drs * PAGE_SIZE_KB, coloring); return; - case M_DT: Process_humanNumber(str, lp->m_dt * PAGE_SIZE_KB, coloring); return; - case M_LRS: Process_humanNumber(str, lp->m_lrs * PAGE_SIZE_KB, coloring); return; - case M_TRS: Process_humanNumber(str, lp->m_trs * PAGE_SIZE_KB, coloring); return; - case M_SHARE: Process_humanNumber(str, lp->m_share * PAGE_SIZE_KB, coloring); return; + case M_DRS: Process_humanNumber(str, lp->m_drs * CRT_pageSizeKB, coloring); return; + case M_DT: Process_humanNumber(str, lp->m_dt * CRT_pageSizeKB, coloring); return; + case M_LRS: Process_humanNumber(str, lp->m_lrs * CRT_pageSizeKB, coloring); return; + case M_TRS: Process_humanNumber(str, lp->m_trs * CRT_pageSizeKB, coloring); return; + case M_SHARE: Process_humanNumber(str, lp->m_share * CRT_pageSizeKB, coloring); return; case M_PSS: Process_humanNumber(str, lp->m_pss, coloring); return; case M_SWAP: Process_humanNumber(str, lp->m_swap, coloring); return; case M_PSSWP: Process_humanNumber(str, lp->m_psswp, coloring); return; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 1ed13826c..2739c790c 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -479,14 +479,14 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di //http://elixir.free-electrons.com/linux/v4.10/source/fs/proc/task_mmu.c#L719 //kernel will return data in chunks of size PAGE_SIZE or less. - char buffer[PAGE_SIZE];// 4k + char buffer[CRT_pageSize];// 4k char *start,*end; ssize_t nread=0; int tmp=0; if(haveSmapsRollup) {// only available in Linux 4.14+ - snprintf(buffer, PAGE_SIZE-1, "%s/%s/smaps_rollup", dirname, name); + xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps_rollup", dirname, name); } else { - snprintf(buffer, PAGE_SIZE-1, "%s/%s/smaps", dirname, name); + xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps", dirname, name); } int fd = open(buffer, O_RDONLY); if (fd == -1) @@ -1020,7 +1020,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* float percent_cpu = (lp->utime + lp->stime - lasttimes) / period * 100.0; proc->percent_cpu = CLAMP(percent_cpu, 0.0, cpus * 100.0); if (isnan(proc->percent_cpu)) proc->percent_cpu = 0.0; - proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(pl->totalMem) * 100.0; + proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(pl->totalMem) * 100.0; if(!preExisting) { diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 4b0307073..744b8a989 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -91,7 +91,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { err(1, "uvmexp sysctl call failed"); } - pl->totalMem = uvmexp.npages * PAGE_SIZE_KB; + pl->totalMem = uvmexp.npages * CRT_pageSizeKB; // Taken from OpenBSD systat/iostat.c, top/machine.c and uvm_sysctl(9) static int bcache_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT}; @@ -102,9 +102,9 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { err(1, "cannot get vfs.bcachestat"); } - pl->cachedMem = bcstats.numbufpages * PAGE_SIZE_KB; - pl->freeMem = uvmexp.free * PAGE_SIZE_KB; - pl->usedMem = (uvmexp.npages - uvmexp.free - uvmexp.paging) * PAGE_SIZE_KB; + pl->cachedMem = bcstats.numbufpages * CRT_pageSizeKB; + pl->freeMem = uvmexp.free * CRT_pageSizeKB; + pl->usedMem = (uvmexp.npages - uvmexp.free - uvmexp.paging) * CRT_pageSizeKB; /* const OpenBSDProcessList* opl = (OpenBSDProcessList*) pl; @@ -113,10 +113,10 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0); pl->totalMem /= 1024; sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(pl->usedMem), &len, NULL, 0); - pl->usedMem *= PAGE_SIZE_KB; + pl->usedMem *= CRT_pageSizeKB; pl->freeMem = pl->totalMem - pl->usedMem; sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(pl->cachedMem), &len, NULL, 0); - pl->cachedMem *= PAGE_SIZE_KB; + pl->cachedMem *= CRT_pageSizeKB; struct kvm_swap swap[16]; int nswap = kvm_getswapinfo(opl->kd, swap, ARRAYSIZE(swap), 0); @@ -126,8 +126,8 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { pl->totalSwap += swap[i].ksw_total; pl->usedSwap += swap[i].ksw_used; } - pl->totalSwap *= PAGE_SIZE_KB; - pl->usedSwap *= PAGE_SIZE_KB; + pl->totalSwap *= CRT_pageSizeKB; + pl->usedSwap *= CRT_pageSizeKB; pl->sharedMem = 0; // currently unused pl->buffersMem = 0; // not exposed to userspace @@ -231,7 +231,7 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { proc->m_size = kproc->p_vm_dsize; proc->m_resident = kproc->p_vm_rssize; - proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->super.totalMem) * 100.0; + proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(this->super.totalMem) * 100.0; proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount*100.0); //proc->nlwp = kproc->p_numthreads; //proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 10); diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 9662f8304..ea552841e 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -23,6 +23,9 @@ in the source distribution for its full text. #include #include +#include "CRT.h" + + #define MAXCMDLINE 255 char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { @@ -157,22 +160,22 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { freemem_pgs = kstat_data_lookup(meminfo, "freemem"); pages = kstat_data_lookup(meminfo, "pagestotal"); - pl->totalMem = totalmem_pgs->value.ui64 * PAGE_SIZE_KB; - if (pl->totalMem > freemem_pgs->value.ui64 * PAGE_SIZE_KB) - pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * PAGE_SIZE_KB; + pl->totalMem = totalmem_pgs->value.ui64 * CRT_pageSizeKB; + if (pl->totalMem > freemem_pgs->value.ui64 * CRT_pageSizeKB) + pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * CRT_pageSizeKB; else - pl->usedMem = 0; // This can happen in non-global zone (in theory) + pl->usedMem = 0; // This can happen in non-global zone (in theory) // Not sure how to implement this on Solaris - suggestions welcome! pl->cachedMem = 0; // Not really "buffers" but the best Solaris analogue that I can find to // "memory in use but not by programs or the kernel itself" - pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * PAGE_SIZE_KB; + pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * CRT_pageSizeKB; } else { // Fall back to basic sysconf if kstat isn't working - pl->totalMem = sysconf(_SC_PHYS_PAGES) * PAGE_SIZE; + pl->totalMem = sysconf(_SC_PHYS_PAGES) * CRT_pageSize; pl->buffersMem = 0; pl->cachedMem = 0; - pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * PAGE_SIZE); + pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * CRT_pageSize); } // Part 2 - swap @@ -198,8 +201,8 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { } free(spathbase); free(sl); - pl->totalSwap = totalswap * PAGE_SIZE_KB; - pl->usedSwap = pl->totalSwap - (totalfree * PAGE_SIZE_KB); + pl->totalSwap = totalswap * CRT_pageSizeKB; + pl->usedSwap = pl->totalSwap - (totalfree * CRT_pageSizeKB); } static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { @@ -297,8 +300,8 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * proc->pgrp = _psinfo->pr_pgid; proc->nlwp = _psinfo->pr_nlwp; proc->tty_nr = _psinfo->pr_ttydev; - proc->m_resident = _psinfo->pr_rssize/PAGE_SIZE_KB; - proc->m_size = _psinfo->pr_size/PAGE_SIZE_KB; + proc->m_resident = _psinfo->pr_rssize/CRT_pageSizeKB; + proc->m_size = _psinfo->pr_size/CRT_pageSizeKB; if (!preExisting) { sproc->realpid = _psinfo->pr_pid; From 96e2a4259eb0cdf279b83d899f805d274d13a94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 13 Oct 2020 16:03:37 +0200 Subject: [PATCH 321/411] Continue to update generic data in paused mode Generic data, as CPU and memory usage, are used by Meters. In paused mode they would stop receiving updates and especially Graph Meters would stop showing continuous data. Improves: #214 Closes: #253 --- ProcessList.c | 10 ++++++++-- ProcessList.h | 4 ++-- ScreenManager.c | 4 ++-- darwin/DarwinProcessList.c | 6 +++++- darwin/DarwinProcessList.h | 2 +- dragonflybsd/DragonFlyBSDProcessList.c | 6 +++++- dragonflybsd/DragonFlyBSDProcessList.h | 2 +- freebsd/FreeBSDProcessList.c | 6 +++++- freebsd/FreeBSDProcessList.h | 2 +- htop.c | 4 ++-- linux/LinuxProcessList.c | 6 +++++- linux/LinuxProcessList.h | 2 +- openbsd/OpenBSDProcessList.c | 9 +++++++-- openbsd/OpenBSDProcessList.h | 2 +- solaris/SolarisProcessList.c | 7 ++++++- solaris/SolarisProcessList.h | 2 +- unsupported/UnsupportedProcessList.c | 9 +++++++-- unsupported/UnsupportedProcessList.h | 2 +- 18 files changed, 61 insertions(+), 24 deletions(-) diff --git a/ProcessList.c b/ProcessList.c index b5a13f0aa..f2cdcf941 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -281,7 +281,13 @@ Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, return proc; } -void ProcessList_scan(ProcessList* this) { +void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { + + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) { + ProcessList_goThroughEntries(this, true); + return; + } // mark all process as "dirty" for (int i = 0; i < Vector_size(this->processes); i++) { @@ -295,7 +301,7 @@ void ProcessList_scan(ProcessList* this) { this->kernelThreads = 0; this->runningTasks = 0; - ProcessList_goThroughEntries(this); + ProcessList_goThroughEntries(this, false); for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { Process* p = (Process*) Vector_get(this->processes, i); diff --git a/ProcessList.h b/ProcessList.h index 2dd2c8d23..07fe48bce 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -74,7 +74,7 @@ typedef struct ProcessList_ { ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* pl); -void ProcessList_goThroughEntries(ProcessList* pl); +void ProcessList_goThroughEntries(ProcessList* pl, bool pauseProcessUpdate); ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); @@ -103,6 +103,6 @@ void ProcessList_rebuildPanel(ProcessList* this); Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor); -void ProcessList_scan(ProcessList* this); +void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate); #endif diff --git a/ScreenManager.c b/ScreenManager.c index 2fce07de2..bc5f66ac8 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -105,9 +105,9 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi *timedOut = (newTime - *oldTime > this->settings->delay); *rescan = *rescan || *timedOut; if (newTime < *oldTime) *rescan = true; // clock was adjusted? - if (*rescan && !this->state->pauseProcessUpdate) { + if (*rescan) { *oldTime = newTime; - ProcessList_scan(pl); + ProcessList_scan(pl, this->state->pauseProcessUpdate); if (*sortTimeout == 0 || this->settings->treeView) { ProcessList_sort(pl); *sortTimeout = 1; diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 10d0697fb..f6f08b502 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -144,7 +144,7 @@ void ProcessList_delete(ProcessList* this) { free(this); } -void ProcessList_goThroughEntries(ProcessList* super) { +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { DarwinProcessList *dpl = (DarwinProcessList *)super; bool preExisting = true; struct kinfo_proc *ps; @@ -158,6 +158,10 @@ void ProcessList_goThroughEntries(ProcessList* super) { ProcessList_getVMStats(&dpl->vm_stats); openzfs_sysctl_updateArcStats(&dpl->zfs); + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) + return; + /* Get the time difference */ dpl->global_diff = 0; for(int i = 0; i < dpl->super.cpuCount; ++i) { diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index 58102d355..44a847dc6 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -51,6 +51,6 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this); -void ProcessList_goThroughEntries(ProcessList* super); +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); #endif diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 87f16069a..e2a01270b 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -358,7 +358,7 @@ char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int ja return jname; } -void ProcessList_goThroughEntries(ProcessList* this) { +void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this; Settings* settings = this->settings; bool hideKernelThreads = settings->hideKernelThreads; @@ -368,6 +368,10 @@ void ProcessList_goThroughEntries(ProcessList* this) { DragonFlyBSDProcessList_scanCPUTime(this); DragonFlyBSDProcessList_scanJails(dfpl); + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) + return; + int count = 0; // TODO Kernel Threads seem to be skipped, need to figure out the correct flag diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index f35e60ebf..475312979 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -59,6 +59,6 @@ char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kpro char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid); -void ProcessList_goThroughEntries(ProcessList* this); +void ProcessList_goThroughEntries(ProcessList* this, pauseProcessUpdate); #endif diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 629698769..aec7e561a 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -379,7 +379,7 @@ IGNORE_WCASTQUAL_END return jname; } -void ProcessList_goThroughEntries(ProcessList* this) { +void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { FreeBSDProcessList* fpl = (FreeBSDProcessList*) this; Settings* settings = this->settings; bool hideKernelThreads = settings->hideKernelThreads; @@ -389,6 +389,10 @@ void ProcessList_goThroughEntries(ProcessList* this) { FreeBSDProcessList_scanMemoryInfo(this); FreeBSDProcessList_scanCPUTime(this); + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) + return; + int count = 0; struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count); diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 75f71c123..c58663340 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -62,6 +62,6 @@ char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc); -void ProcessList_goThroughEntries(ProcessList* this); +void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate); #endif diff --git a/htop.c b/htop.c index 7d1c1b165..8ff2baafb 100644 --- a/htop.c +++ b/htop.c @@ -303,9 +303,9 @@ int main(int argc, char** argv) { ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, &state, true); ScreenManager_add(scr, (Panel*) panel, -1); - ProcessList_scan(pl); + ProcessList_scan(pl, false); millisleep(75); - ProcessList_scan(pl); + ProcessList_scan(pl, false); ScreenManager_run(scr, NULL, NULL); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 1ed13826c..7e29e721a 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1382,7 +1382,7 @@ static void LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { scanCPUFreqencyFromCPUinfo(this); } -void ProcessList_goThroughEntries(ProcessList* super) { +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { LinuxProcessList* this = (LinuxProcessList*) super; const Settings* settings = super->settings; @@ -1396,6 +1396,10 @@ void ProcessList_goThroughEntries(ProcessList* super) { if (settings->showCPUFrequency) LinuxProcessList_scanCPUFrequency(this); + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) + return; + struct timeval tv; gettimeofday(&tv, NULL); LinuxProcessList_recurseProcTree(this, PROCDIR, NULL, period, tv); diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 57bc9dc0b..4427ccdfd 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -101,6 +101,6 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* pl); -void ProcessList_goThroughEntries(ProcessList* super); +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); #endif diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 4b0307073..833694948 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -340,10 +340,15 @@ static void OpenBSDProcessList_scanCPUTime(OpenBSDProcessList* this) { kernelCPUTimesToHtop(avg, this->cpus); } -void ProcessList_goThroughEntries(ProcessList* this) { +void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { OpenBSDProcessList* opl = (OpenBSDProcessList*) this; OpenBSDProcessList_scanMemoryInfo(this); - OpenBSDProcessList_scanProcs(opl); OpenBSDProcessList_scanCPUTime(opl); + + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) + return; + + OpenBSDProcessList_scanProcs(opl); } diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index ab4785716..3c3f1a334 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -45,6 +45,6 @@ void ProcessList_delete(ProcessList* this); char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); -void ProcessList_goThroughEntries(ProcessList* this); +void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate); #endif diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 9662f8304..2c59087db 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -374,10 +374,15 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * return 0; } -void ProcessList_goThroughEntries(ProcessList* this) { +void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { SolarisProcessList_scanCPUTime(this); SolarisProcessList_scanMemoryInfo(this); SolarisProcessList_scanZfsArcstats(this); + + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) + return; + this->kernelThreads = 1; proc_walk(&SolarisProcessList_walkproc, this, PR_WALK_LWP); } diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index c8a2d8d08..a138c3bff 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -60,6 +60,6 @@ void ProcessList_delete(ProcessList* pl); int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr); -void ProcessList_goThroughEntries(ProcessList* this); +void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate); #endif diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index 40a24c282..33dd9fe8f 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -24,8 +24,13 @@ void ProcessList_delete(ProcessList* this) { free(this); } -void ProcessList_goThroughEntries(ProcessList* super) { - bool preExisting = true; +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { + + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) + return; + + bool preExisting = true; Process *proc; proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new); diff --git a/unsupported/UnsupportedProcessList.h b/unsupported/UnsupportedProcessList.h index 68c0ca7e1..1c537713b 100644 --- a/unsupported/UnsupportedProcessList.h +++ b/unsupported/UnsupportedProcessList.h @@ -11,6 +11,6 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this); -void ProcessList_goThroughEntries(ProcessList* super); +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); #endif From 577416d1a946382ab9f0c523e5fae755f9d71f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 5 Oct 2020 12:49:01 +0200 Subject: [PATCH 322/411] Assert allocating non-zero size memory Allocating zero size memory results in implementation-defined behavior: man:malloc(3) : If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free(). --- Meter.c | 2 +- XUtils.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Meter.c b/Meter.c index 843703623..fa1eacb4a 100644 --- a/Meter.c +++ b/Meter.c @@ -38,7 +38,7 @@ Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type) { this->param = param; this->pl = pl; this->curItems = type->maxItems; - this->values = xCalloc(type->maxItems, sizeof(double)); + this->values = type->maxItems ? xCalloc(type->maxItems, sizeof(double)) : NULL; this->total = type->total; this->caption = xStrdup(type->caption); if (Meter_initFn(this)) diff --git a/XUtils.c b/XUtils.c index 1e77cd3ba..3bdcba84f 100644 --- a/XUtils.c +++ b/XUtils.c @@ -25,26 +25,26 @@ void fail() { } void* xMalloc(size_t size) { + assert(size > 0); void* data = malloc(size); - if (!data && size > 0) { + if (!data) { fail(); } return data; } void* xCalloc(size_t nmemb, size_t size) { + assert(nmemb > 0); + assert(size > 0); void* data = calloc(nmemb, size); - if (!data && nmemb > 0 && size > 0) { + if (!data) { fail(); } return data; } void* xRealloc(void* ptr, size_t size) { - if (!size) { - free(ptr); - return NULL; - } + assert(size > 0); void* data = realloc(ptr, size); // deepcode ignore MemoryLeakOnRealloc: this goes to fail() if (!data) { free(ptr); From 4c66eb6d4cbdddc658e5f0274d8130155c6013f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 3 Oct 2020 21:20:43 +0200 Subject: [PATCH 323/411] XUtils string related updates - allow count out-parameter of String_split() to be NULL - introduce xStrndup() - do not allow NULL pointers passed to String_eq() it is not used in any code - implement String_startsWith(), String_contains_i() and String_eq() as inline header functions - adjust several conversion issues --- Action.h | 2 ++ CRT.c | 2 +- FunctionBar.c | 2 ++ MainPanel.h | 2 ++ Meter.h | 2 ++ Settings.c | 11 +++---- UsersTable.c | 2 ++ XUtils.c | 68 +++++++++++++++++++--------------------- XUtils.h | 23 +++++++++----- htop.c | 2 +- linux/Battery.c | 4 +-- linux/LinuxProcessList.c | 18 +++++------ linux/Platform.c | 2 +- 13 files changed, 76 insertions(+), 64 deletions(-) diff --git a/Action.h b/Action.h index e63b6810c..68aa2e2ed 100644 --- a/Action.h +++ b/Action.h @@ -7,6 +7,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include #include diff --git a/CRT.c b/CRT.c index d3afd0eca..a2efb6a18 100644 --- a/CRT.c +++ b/CRT.c @@ -655,7 +655,7 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { setlocale(LC_CTYPE, ""); #ifdef HAVE_LIBNCURSESW - if (allowUnicode && strcmp(nl_langinfo(CODESET), "UTF-8") == 0) + if (allowUnicode && String_eq(nl_langinfo(CODESET), "UTF-8")) CRT_utf8 = true; else CRT_utf8 = false; diff --git a/FunctionBar.c b/FunctionBar.c index 1c4f395b2..9b454ac8d 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -5,6 +5,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "FunctionBar.h" #include diff --git a/MainPanel.h b/MainPanel.h index 7f7520d6c..3c5552940 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -8,6 +8,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include #include diff --git a/Meter.h b/Meter.h index 84d157bb4..ab8ee6e40 100644 --- a/Meter.h +++ b/Meter.h @@ -7,6 +7,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include #include diff --git a/Settings.c b/Settings.c index ac8321a0e..879d14fb6 100644 --- a/Settings.c +++ b/Settings.c @@ -31,16 +31,14 @@ void Settings_delete(Settings* this) { static void Settings_readMeters(Settings* this, char* line, int column) { char* trim = String_trim(line); - int nIds; - char** ids = String_split(trim, ' ', &nIds); + char** ids = String_split(trim, ' ', NULL); free(trim); this->columns[column].names = ids; } static void Settings_readMeterModes(Settings* this, char* line, int column) { char* trim = String_trim(line); - int nIds; - char** ids = String_split(trim, ' ', &nIds); + char** ids = String_split(trim, ' ', NULL); free(trim); int len = 0; for (int i = 0; ids[i]; i++) { @@ -94,8 +92,7 @@ static void Settings_defaultMeters(Settings* this, int initialCpuCount) { static void readFields(ProcessField* fields, int* flags, const char* line) { char* trim = String_trim(line); - int nIds; - char** ids = String_split(trim, ' ', &nIds); + char** ids = String_split(trim, ' ', NULL); free(trim); int i, j; *flags = 0; @@ -126,7 +123,7 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo if (!line) { break; } - int nOptions; + size_t nOptions; char** option = String_split(line, '=', &nOptions); free (line); if (nOptions < 2) { diff --git a/UsersTable.c b/UsersTable.c index 89fdfc4d4..83c6dbc3c 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -5,6 +5,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "UsersTable.h" #include diff --git a/XUtils.c b/XUtils.c index 3bdcba84f..a444a7f8f 100644 --- a/XUtils.c +++ b/XUtils.c @@ -54,11 +54,11 @@ void* xRealloc(void* ptr, size_t size) { } char* String_cat(const char* s1, const char* s2) { - int l1 = strlen(s1); - int l2 = strlen(s2); + const size_t l1 = strlen(s1); + const size_t l2 = strlen(s2); char* out = xMalloc(l1 + l2 + 1); memcpy(out, s1, l1); - memcpy(out+l1, s2, l2+1); + memcpy(out+l1, s2, l2); out[l1 + l2] = '\0'; return out; } @@ -67,39 +67,24 @@ char* String_trim(const char* in) { while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') { in++; } - int len = strlen(in); + + size_t len = strlen(in); while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) { len--; } - char* out = xMalloc(len+1); - strncpy(out, in, len); - out[len] = '\0'; - return out; -} -inline int String_eq(const char* s1, const char* s2) { - if (s1 == NULL || s2 == NULL) { - if (s1 == NULL && s2 == NULL) - return 1; - else - return 0; - } - return (strcmp(s1, s2) == 0); + return xStrndup(in, len); } -char** String_split(const char* s, char sep, int* n) { - *n = 0; - const int rate = 10; +char** String_split(const char* s, char sep, size_t* n) { + const unsigned int rate = 10; char** out = xCalloc(rate, sizeof(char*)); - int ctr = 0; - int blocks = rate; - char* where; + size_t ctr = 0; + unsigned int blocks = rate; + const char* where; while ((where = strchr(s, sep)) != NULL) { - int size = where - s; - char* token = xMalloc(size + 1); - strncpy(token, s, size); - token[size] = '\0'; - out[ctr] = token; + size_t size = (size_t)(where - s); + out[ctr] = xStrndup(s, size); ctr++; if (ctr == blocks) { blocks += rate; @@ -113,7 +98,10 @@ char** String_split(const char* s, char sep, int* n) { } out = xRealloc(out, sizeof(char*) * (ctr + 1)); out[ctr] = NULL; - *n = ctr; + + if (n) + *n = ctr; + return out; } @@ -121,28 +109,28 @@ void String_freeArray(char** s) { if (!s) { return; } - for (int i = 0; s[i] != NULL; i++) { + for (size_t i = 0; s[i] != NULL; i++) { free(s[i]); } free(s); } char* String_getToken(const char* line, const unsigned short int numMatch) { - const unsigned short int len = strlen(line); + const size_t len = strlen(line); char inWord = 0; unsigned short int count = 0; char match[50]; - unsigned short int foundCount = 0; + size_t foundCount = 0; - for (unsigned short int i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { char lastState = inWord; inWord = line[i] == ' ' ? 0:1; if (lastState == 0 && inWord == 1) count++; - if(inWord == 1){ + if (inWord == 1){ if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) { match[foundCount] = line[i]; foundCount++; @@ -155,8 +143,8 @@ char* String_getToken(const char* line, const unsigned short int numMatch) { } char* String_readLine(FILE* fd) { - const int step = 1024; - int bufSize = step; + const unsigned int step = 1024; + unsigned int bufSize = step; char* buffer = xMalloc(step + 1); char* at = buffer; for (;;) { @@ -213,3 +201,11 @@ char* xStrdup(const char* str) { } return data; } + +char* xStrndup(const char* str, size_t len) { + char* data = strndup(str, len); + if (!data) { + fail(); + } + return data; +} diff --git a/XUtils.h b/XUtils.h index f30af6f3e..591e98bbd 100644 --- a/XUtils.h +++ b/XUtils.h @@ -9,6 +9,7 @@ in the source distribution for its full text. #include "config.h" // IWYU pragma: keep +#include #include #include // IWYU pragma: keep #include // IWYU pragma: keep @@ -24,25 +25,31 @@ void* xCalloc(size_t nmemb, size_t size); void* xRealloc(void* ptr, size_t size); -#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) -#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL) - /* * String_startsWith gives better performance if strlen(match) can be computed * at compile time (e.g. when they are immutable string literals). :) */ +static inline bool String_startsWith(const char* s, const char* match) { + return strncmp(s, match, strlen(match)) == 0; +} + +static inline bool String_contains_i(const char* s1, const char* s2) { + return strcasestr(s1, s2) != NULL; +} + +static inline bool String_eq(const char* s1, const char* s2) { + return strcmp(s1, s2) == 0; +} char* String_cat(const char* s1, const char* s2); char* String_trim(const char* in); -int String_eq(const char* s1, const char* s2); - -char** String_split(const char* s, char sep, int* n); +char** String_split(const char* s, char sep, size_t* n); void String_freeArray(char** s); -char* String_getToken(const char* line, const unsigned short int numMatch); +char* String_getToken(const char* line, unsigned short int numMatch); char* String_readLine(FILE* fd); @@ -54,4 +61,6 @@ int xSnprintf(char *buf, int len, const char* fmt, ...); char* xStrdup(const char* str) ATTR_NONNULL; +char* xStrndup(const char* str, size_t len) ATTR_NONNULL; + #endif diff --git a/htop.c b/htop.c index 7d1c1b165..840f24c3e 100644 --- a/htop.c +++ b/htop.c @@ -122,7 +122,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { exit(0); case 's': assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */ - if (strcmp(optarg, "help") == 0) { + if (String_eq(optarg, "help")) { for (int j = 1; j < Platform_numberOfFields; j++) { const char* name = Process_fields[j].name; if (name) printf ("%s\n", name); diff --git a/linux/Battery.c b/linux/Battery.c index f3e2ff246..956a7397d 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -53,7 +53,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short if (!dirEntry) break; char* entryName = dirEntry->d_name; - if (strncmp(entryName, "BAT", 3)) + if (String_startsWith(entryName, "BAT")) continue; batteries[nBatteries] = xStrdup(entryName); nBatteries++; @@ -128,7 +128,7 @@ static ACPresence procAcpiCheck(void) { char *isOnline = String_getToken(line, 2); free(line); - if (strcmp(isOnline, "on-line") == 0) { + if (String_eq(isOnline, "on-line")) { isOn = AC_PRESENT; } else { isOn = AC_ABSENT; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 1ed13826c..4e3a804f4 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -419,9 +419,9 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna while ((line = strsep(&buf, "\n")) != NULL) { switch (line[0]) { case 'r': - if (line[1] == 'c' && strncmp(line+2, "har: ", 5) == 0) + if (line[1] == 'c' && String_startsWith(line+2, "har: ")) process->io_rchar = strtoull(line+7, NULL, 10); - else if (strncmp(line+1, "ead_bytes: ", 11) == 0) { + else if (String_startsWith(line+1, "ead_bytes: ")) { process->io_read_bytes = strtoull(line+12, NULL, 10); process->io_rate_read_bps = ((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000); @@ -429,9 +429,9 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna } break; case 'w': - if (line[1] == 'c' && strncmp(line+2, "har: ", 5) == 0) + if (line[1] == 'c' && String_startsWith(line+2, "har: ")) process->io_wchar = strtoull(line+7, NULL, 10); - else if (strncmp(line+1, "rite_bytes: ", 12) == 0) { + else if (String_startsWith(line+1, "rite_bytes: ")) { process->io_write_bytes = strtoull(line+13, NULL, 10); process->io_rate_write_bps = ((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000); @@ -439,14 +439,14 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna } break; case 's': - if (line[4] == 'r' && strncmp(line+1, "yscr: ", 6) == 0) { + if (line[4] == 'r' && String_startsWith(line+1, "yscr: ")) { process->io_syscr = strtoull(line+7, NULL, 10); - } else if (strncmp(line+1, "yscw: ", 6) == 0) { + } else if (String_startsWith(line+1, "yscw: ")) { process->io_syscw = strtoull(line+7, NULL, 10); } break; case 'c': - if (strncmp(line+1, "ancelled_write_bytes: ", 22) == 0) { + if (String_startsWith(line+1, "ancelled_write_bytes: ")) { process->io_cancelled_write_bytes = strtoull(line+23, NULL, 10); } } @@ -598,7 +598,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d switch(field) { case 1: foundEnvID = true; - if(0 != strcmp(name_value_sep, process->ctid ? process->ctid : "")) { + if(!String_eq(name_value_sep, process->ctid ? process->ctid : "")) { free(process->ctid); process->ctid = xStrdup(name_value_sep); } @@ -762,7 +762,7 @@ static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* char *newline = strchr(buffer, '\n'); if (newline) *newline = '\0'; - if (process->secattr && 0 == strcmp(process->secattr, buffer)) + if (process->secattr && String_eq(process->secattr, buffer)) return; free(process->secattr); process->secattr = xStrdup(buffer); diff --git a/linux/Platform.c b/linux/Platform.c index 1bb476ab2..afa2b7fd4 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -376,7 +376,7 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived, &packetsTransmittedParsed) != 5) continue; - if (0 == strcmp(interfaceName, "lo:")) + if (String_eq(interfaceName, "lo:")) continue; bytesReceivedSum += bytesReceivedParsed; From dea19b644f463c8409569957d008fb9d86b487e9 Mon Sep 17 00:00:00 2001 From: srajmane Date: Tue, 20 Oct 2020 11:52:34 -0400 Subject: [PATCH 324/411] s390x support for travis --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index d870aa543..bb79560df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,15 @@ os: - linux - osx +arch: + - amd64 + - s390x + +before_script: + if [[ ${TRAVIS_CPU_ARCH} == 's390x' ]]; then + sudo apt-get update && sudo apt-get install -y libncursesw5-dev ; + fi + script: - ./autogen.sh # clang might warn about C11 generic selections in isnan() From f8208f21730b21f284d9608a5b39f8ac1d15199b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 20 Oct 2020 13:14:32 +0200 Subject: [PATCH 325/411] Drop tabs in source indentions --- InfoScreen.c | 2 +- Macros.h | 6 +++--- darwin/DarwinProcessList.c | 6 +++--- dragonflybsd/DragonFlyBSDProcessList.h | 2 +- dragonflybsd/Platform.c | 4 ++-- freebsd/FreeBSDProcessList.h | 2 +- solaris/SolarisProcessList.c | 4 ++-- solaris/SolarisProcessList.h | 4 ++-- zfs/openzfs_sysctl.c | 3 +-- 9 files changed, 16 insertions(+), 17 deletions(-) diff --git a/InfoScreen.c b/InfoScreen.c index 0c666234e..7f4baa72c 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -110,7 +110,7 @@ void InfoScreen_run(InfoScreen* this) { } else if (mevent.y == LINES - 1) { ch = IncSet_synthesizeEvent(this->inc, mevent.x); } - } + } } if (this->inc->active) { diff --git a/Macros.h b/Macros.h index 2f92acb12..1064dadb8 100644 --- a/Macros.h +++ b/Macros.h @@ -4,15 +4,15 @@ #include // IWYU pragma: keep #ifndef MINIMUM -#define MINIMUM(a, b) ((a) < (b) ? (a) : (b)) +#define MINIMUM(a, b) ((a) < (b) ? (a) : (b)) #endif #ifndef MAXIMUM -#define MAXIMUM(a, b) ((a) > (b) ? (a) : (b)) +#define MAXIMUM(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef CLAMP -#define CLAMP(x, low, high) (assert((low) <= (high)), ((x) > (high)) ? (high) : MAXIMUM(x, low)) +#define CLAMP(x, low, high) (assert((low) <= (high)), ((x) > (high)) ? (high) : MAXIMUM(x, low)) #endif #ifndef ARRAYSIZE diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index f6f08b502..2c9f533f2 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -146,9 +146,9 @@ void ProcessList_delete(ProcessList* this) { void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { DarwinProcessList *dpl = (DarwinProcessList *)super; - bool preExisting = true; - struct kinfo_proc *ps; - size_t count; + bool preExisting = true; + struct kinfo_proc *ps; + size_t count; DarwinProcess *proc; /* Update the global data (CPU times and VM stats) */ diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index 475312979..0d0a128f6 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -19,7 +19,7 @@ in the source distribution for its full text. #include "Hashtable.h" #include "DragonFlyBSDProcess.h" -#define JAIL_ERRMSGLEN 1024 +#define JAIL_ERRMSGLEN 1024 extern char jail_errmsg[JAIL_ERRMSGLEN]; typedef struct CPUData_ { diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index eb1725135..ce5588997 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -202,12 +202,12 @@ void Platform_setSwapValues(Meter* this) { void Platform_setTasksValues(Meter* this) { // TODO - (void)this; // prevent unused warning + (void)this; // prevent unused warning } char* Platform_getProcessEnv(pid_t pid) { // TODO - (void)pid; // prevent unused warning + (void)pid; // prevent unused warning return NULL; } diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index c58663340..60d23f8dc 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -21,7 +21,7 @@ in the source distribution for its full text. #include "zfs/ZfsArcStats.h" -#define JAIL_ERRMSGLEN 1024 +#define JAIL_ERRMSGLEN 1024 extern char jail_errmsg[JAIL_ERRMSGLEN]; typedef struct CPUData_ { diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index eed4b89d3..85fc955b1 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -151,8 +151,8 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { // Part 1 - physical memory if (spl->kd != NULL && meminfo == NULL) { - // Look up the kstat chain just one, it never changes - meminfo = kstat_lookup(spl->kd,"unix",0,"system_pages"); + // Look up the kstat chain just one, it never changes + meminfo = kstat_lookup(spl->kd,"unix",0,"system_pages"); } if (meminfo != NULL) { ksrphyserr = kstat_read(spl->kd,meminfo,NULL); } if (ksrphyserr != -1) { diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index a138c3bff..1e6e5b8ae 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -10,8 +10,8 @@ in the source distribution for its full text. #define MAXCMDLINE 255 -#define GZONE "global " -#define UZONE "unknown " +#define GZONE "global " +#define UZONE "unknown " #include "zfs/ZfsArcStats.h" diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c index 876bf5c89..3f8f2c25d 100644 --- a/zfs/openzfs_sysctl.c +++ b/zfs/openzfs_sysctl.c @@ -32,8 +32,7 @@ void openzfs_sysctl_init(ZfsArcStats *stats) { unsigned long long int arcSize; len = sizeof(arcSize); - if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, - NULL, 0) == 0 && arcSize != 0) { + if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) { stats->enabled = 1; len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); From 803234a58d12b23cbc700a14b50e57764718f5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 20 Oct 2020 15:27:22 +0200 Subject: [PATCH 326/411] update Github CI - Add a full featured clang job - Explicit disable options otherwise enabled by default in minimal job --- .github/workflows/ci.yml | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e1d130ed..dd81407ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: CI on: [ push, pull_request ] jobs: - build-ubuntu-latest: + build-ubuntu-latest-minimal-gcc: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -12,13 +12,13 @@ jobs: - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror --enable-linux-affinity + run: ./configure --enable-werror --enable-linux-affinity --disable-taskstats --disable-unicode - name: Build run: make -k - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity" + run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity --disable-taskstats --disable-unicode" - build-ubuntu-clang-latest: + build-ubuntu-latest-minimal-clang: runs-on: ubuntu-latest env: CC: clang-10 @@ -34,13 +34,13 @@ jobs: - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror --enable-linux-affinity + run: ./configure --enable-werror --enable-linux-affinity --disable-taskstats --disable-unicode - name: Build run: make -k - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity" + run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity --disable-taskstats --disable-unicode" - build-ubuntu-latest-full-featured: + build-ubuntu-latest-full-featured-gcc: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -55,6 +55,28 @@ jobs: - name: Distcheck run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct' + build-ubuntu-latest-full-featured-clang: + runs-on: ubuntu-latest + env: + CC: clang-10 + steps: + - uses: actions/checkout@v2 + - name: install clang repo + run: | + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key 2>/dev/null | sudo apt-key add - + sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main' -y + sudo apt-get update -q + - name: Install Dependencies + run: sudo apt-get install clang-10 libncursesw5-dev libhwloc-dev libnl-3-dev libnl-genl-3-dev + - name: Bootstrap + run: ./autogen.sh + - name: Configure + run: ./configure --enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct + - name: Build + run: make -k + - name: Distcheck + run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct' + build-ubuntu-latest-clang-analyzer: runs-on: ubuntu-latest env: From 8a08a3209c093f9b1137ec5879d3804026b0df6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 19 Oct 2020 12:05:06 +0200 Subject: [PATCH 327/411] IWYU update - Add Settings forward declaration in Process.h - Add assert.h include in XUitls.c - Add conditional stdbool.h include in Object.h - Drop unneeded stddef.h include in Richstring.c - Drop unneeded unistd.h include in Process.h - Drop unneeded string.h include in linux/Platform.c - Use String_eq to avoid string.h include in Action.c - Improve script to run custom iwyu version --- Action.c | 4 ++-- Object.h | 4 ++++ Process.h | 3 ++- RichString.c | 1 - XUtils.c | 1 + iwyu/run_iwyu.sh | 6 ++++-- linux/Platform.c | 1 - 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Action.c b/Action.c index 7443c842a..3f5737fcc 100644 --- a/Action.c +++ b/Action.c @@ -511,10 +511,10 @@ static Htop_Reaction actionHelp(State* st) { mvaddstr(line + item, 9, helpLeft[item].info); attrset(CRT_colors[HELP_BOLD]); mvaddstr(line + item, 0, helpLeft[item].key); - if (0 == strcmp(helpLeft[item].key, " H: ")) { + if (String_eq(helpLeft[item].key, " H: ")) { attrset(CRT_colors[PROCESS_THREAD]); mvaddstr(line + item, 32, "threads"); - } else if (0 == strcmp(helpLeft[item].key, " K: ")) { + } else if (String_eq(helpLeft[item].key, " K: ")) { attrset(CRT_colors[PROCESS_THREAD]); mvaddstr(line + item, 26, "threads"); } diff --git a/Object.h b/Object.h index 2d3fd3c44..caa3e9199 100644 --- a/Object.h +++ b/Object.h @@ -11,6 +11,10 @@ in the source distribution for its full text. #include "RichString.h" #include "XUtils.h" // IWYU pragma: keep +#ifndef NDEBUG +#include +#endif + struct Object_; typedef struct Object_ Object; diff --git a/Process.h b/Process.h index db85f147c..a13ca86ce 100644 --- a/Process.h +++ b/Process.h @@ -9,7 +9,6 @@ in the source distribution for its full text. */ #include -#include #include #include "Object.h" @@ -55,6 +54,8 @@ typedef struct ProcessPidColumn_ { const char* label; } ProcessPidColumn; +struct Settings_; + typedef struct Process_ { Object super; diff --git a/RichString.c b/RichString.c index 60fe8d077..90cc428c9 100644 --- a/RichString.c +++ b/RichString.c @@ -7,7 +7,6 @@ in the source distribution for its full text. #include "RichString.h" -#include #include #include diff --git a/XUtils.c b/XUtils.c index a444a7f8f..811fa50f6 100644 --- a/XUtils.c +++ b/XUtils.c @@ -9,6 +9,7 @@ in the source distribution for its full text. #include "XUtils.h" +#include #include #include #include diff --git a/iwyu/run_iwyu.sh b/iwyu/run_iwyu.sh index 83d2c484c..37843dcf9 100755 --- a/iwyu/run_iwyu.sh +++ b/iwyu/run_iwyu.sh @@ -6,7 +6,9 @@ SOURCEDIR="$SCRIPTDIR/.." PKG_NL3=$(pkg-config --cflags libnl-3.0) -cd "$SOURCEDIR" +IWYU=${IWYU:-iwyu} + +cd "$SOURCEDIR" || exit make clean -make -k CC="iwyu" CFLAGS="-Xiwyu --no_comments -Xiwyu --no_fwd_decl -Xiwyu --mapping_file='$SCRIPTDIR/htop.imp' $PKG_NL3" +make --keep-going --silent CC="$IWYU" CFLAGS="-Xiwyu --no_comments -Xiwyu --no_fwd_decl -Xiwyu --mapping_file='$SCRIPTDIR/htop.imp' $PKG_NL3" diff --git a/linux/Platform.c b/linux/Platform.c index afa2b7fd4..95e0000dc 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -13,7 +13,6 @@ in the source distribution for its full text. #include #include #include -#include #include "BatteryMeter.h" #include "ClockMeter.h" From 45a22080c991f3b4462d9222f377b27f6c04174f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 20 Oct 2020 19:20:19 +0200 Subject: [PATCH 328/411] Increase print buffer in NetworkIOMeter_display In case the packet values wrap-around or have other weird values, the current buffer might be to small --- NetworkIOMeter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c index 8c0cb45d3..44792c151 100644 --- a/NetworkIOMeter.c +++ b/NetworkIOMeter.c @@ -63,7 +63,7 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i } static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { - char buffer[32]; + char buffer[64]; RichString_write(out, CRT_colors[METER_TEXT], "rx: "); Meter_humanUnit(buffer, cached_rxb_diff, sizeof(buffer)); From 7429c22201ed0b78a4bcd27ba3d29dcda2c6509c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 20 Oct 2020 22:29:16 +0200 Subject: [PATCH 329/411] Drop unnecessary cast --- linux/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/Platform.c b/linux/Platform.c index 95e0000dc..e6c1c08ce 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -224,7 +224,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { } void Platform_setMemoryValues(Meter* this) { - ProcessList* pl = (ProcessList*) this->pl; + ProcessList* pl = this->pl; LinuxProcessList* lpl = (LinuxProcessList*) this->pl; long int usedMem = pl->usedMem; From e12d48a661cee3482c038038be1eede5099fec48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 20 Oct 2020 22:30:13 +0200 Subject: [PATCH 330/411] Fix wrong strncmp replacement Fixes 4c66eb6d4cbd --- linux/Battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/Battery.c b/linux/Battery.c index 956a7397d..4eab24dd4 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -53,7 +53,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short if (!dirEntry) break; char* entryName = dirEntry->d_name; - if (String_startsWith(entryName, "BAT")) + if (!String_startsWith(entryName, "BAT")) continue; batteries[nBatteries] = xStrdup(entryName); nBatteries++; From b08b255b4114356a880ab60bed82450f2f6ec8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 21:25:56 +0200 Subject: [PATCH 331/411] Drop unused Platform functions Platform_setTasksValues --- dragonflybsd/Platform.c | 5 ----- dragonflybsd/Platform.h | 2 -- freebsd/Platform.c | 5 ----- freebsd/Platform.h | 2 -- openbsd/Platform.c | 4 ---- openbsd/Platform.h | 2 -- 6 files changed, 20 deletions(-) diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index ce5588997..b67ff8a19 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -200,11 +200,6 @@ void Platform_setSwapValues(Meter* this) { this->values[0] = pl->usedSwap; } -void Platform_setTasksValues(Meter* this) { - // TODO - (void)this; // prevent unused warning -} - char* Platform_getProcessEnv(pid_t pid) { // TODO (void)pid; // prevent unused warning diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 50187aa40..7f31f0a50 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -38,8 +38,6 @@ void Platform_setMemoryValues(Meter* this); void Platform_setSwapValues(Meter* this); -void Platform_setTasksValues(Meter* this); - char* Platform_getProcessEnv(pid_t pid); void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 7827d5210..2f7f26403 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -219,11 +219,6 @@ void Platform_setZfsCompressedArcValues(Meter* this) { ZfsCompressedArcMeter_readStats(this, &(fpl->zfs)); } -void Platform_setTasksValues(Meter* this) { - (void) this; - // TODO -} - char* Platform_getProcessEnv(pid_t pid) { (void) pid; // TODO diff --git a/freebsd/Platform.h b/freebsd/Platform.h index bd1a38ef4..c5cf659f3 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -41,8 +41,6 @@ void Platform_setZfsArcValues(Meter* this); void Platform_setZfsCompressedArcValues(Meter* this); -void Platform_setTasksValues(Meter* this); - char* Platform_getProcessEnv(pid_t pid); void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 7723ebc58..5b2492687 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -241,10 +241,6 @@ void Platform_setSwapValues(Meter* this) { free(swdev); } -void Platform_setTasksValues(Meter* this) { - // TODO -} - char* Platform_getProcessEnv(pid_t pid) { char errbuf[_POSIX2_LINE_MAX]; char *env; diff --git a/openbsd/Platform.h b/openbsd/Platform.h index b3edf6e8c..f97fdc84a 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -39,8 +39,6 @@ void Platform_setMemoryValues(Meter* this); void Platform_setSwapValues(Meter* this); -void Platform_setTasksValues(Meter* this); - char* Platform_getProcessEnv(pid_t pid); void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); From 11bf7be9c2e1d83c0e4ae2ac9f0e3ccdc09ddbf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 21:26:03 +0200 Subject: [PATCH 332/411] Mark user field of Process const It's a non-owning pointer to a hashtable entry. --- Process.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Process.h b/Process.h index a13ca86ce..440cbb1c4 100644 --- a/Process.h +++ b/Process.h @@ -86,7 +86,7 @@ typedef struct Process_ { float percent_cpu; float percent_mem; - char* user; + const char* user; long int priority; long int nice; From 0ae2bb1f8e80f34571203df7fe31ba22ce9b8670 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Fri, 23 Oct 2020 20:31:20 +0000 Subject: [PATCH 333/411] Add process environment for FreeBSD --- freebsd/Platform.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 2f7f26403..0515558f7 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -32,6 +32,7 @@ in the source distribution for its full text. #include #include #include +#include #include @@ -220,9 +221,30 @@ void Platform_setZfsCompressedArcValues(Meter* this) { } char* Platform_getProcessEnv(pid_t pid) { - (void) pid; - // TODO - return NULL; + int mib[4]; + char *env = NULL; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_ENV; + mib[3] = pid; + + size_t capacity = ARG_MAX; + env = xMalloc(capacity); + + int err = sysctl(mib, 4, env, &capacity, NULL, 0); + if (err) { + free(env); + return NULL; + } + + if (env[capacity-1] || env[capacity-2]) { + env = xRealloc(env, capacity+2); + env[capacity] = 0; + env[capacity+1] = 0; + } + + return env; } void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { From 94e32cf1e80d145c3028435e547194016dd8e93d Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Mon, 26 Oct 2020 15:40:18 +0000 Subject: [PATCH 334/411] Simplify environment-reading code Suggested PR changes, thanks @cgzones --- freebsd/Platform.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 0515558f7..b03c58bec 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -221,16 +221,10 @@ void Platform_setZfsCompressedArcValues(Meter* this) { } char* Platform_getProcessEnv(pid_t pid) { - int mib[4]; - char *env = NULL; - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_ENV; - mib[3] = pid; + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ENV, pid }; size_t capacity = ARG_MAX; - env = xMalloc(capacity); + char* env = xMalloc(capacity); int err = sysctl(mib, 4, env, &capacity, NULL, 0); if (err) { From 167adc0a2b4a940cae6c9eb71f3185b5d2d3b4fa Mon Sep 17 00:00:00 2001 From: Jan Palus Date: Fri, 23 Oct 2020 00:59:26 +0200 Subject: [PATCH 335/411] Parse POWER_SUPPLY_CAPACITY If POWER_SUPPLY_{CHARGE,ENERGY}_NOW is missing then try to use POWER_SUPPLY_CAPACITY to determine current charge level. --- linux/Battery.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/linux/Battery.c b/linux/Battery.c index 4eab24dd4..0822ee9a5 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -230,6 +230,8 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { char *line = NULL; bool full = false; bool now = false; + int fullSize = 0; + double capacityLevel = NAN; while ((line = strsep(&buf, "\n")) != NULL) { #define match(str,prefix) \ (String_startsWith(str,prefix) ? (str) + strlen(prefix) : NULL) @@ -237,6 +239,10 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { if (!ps) { continue; } + const char* capacity = match(ps, "CAPACITY="); + if (capacity) { + capacityLevel = atoi(capacity) / 100.0; + } const char* energy = match(ps, "ENERGY_"); if (!energy) { energy = match(ps, "CHARGE_"); @@ -246,7 +252,8 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { } const char* value = (!full) ? match(energy, "FULL=") : NULL; if (value) { - totalFull += atoi(value); + fullSize = atoi(value); + totalFull += fullSize; full = true; if (now) break; continue; @@ -260,6 +267,9 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { } } #undef match + if (!now && full && !isnan(capacityLevel)) { + totalRemain += (capacityLevel * fullSize); + } } else if (entryName[0] == 'A') { if (*isOnAC != AC_ERROR) { continue; From f757810f489b12d2a98dcb09751003f4ed002538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 20 Oct 2020 21:40:51 +0200 Subject: [PATCH 336/411] Improve handling of no data in Disk and Network IO Meters --- CRT.c | 6 ++++++ CRT.h | 1 + DiskIOMeter.c | 21 +++++++++++++++++---- NetworkIOMeter.c | 16 +++++++++++++--- darwin/Platform.c | 8 ++++++-- darwin/Platform.h | 6 ++++-- dragonflybsd/Platform.c | 8 ++++++-- dragonflybsd/Platform.h | 6 ++++-- freebsd/Platform.c | 18 +++++++++--------- freebsd/Platform.h | 6 ++++-- linux/Platform.c | 36 +++++++++++++++--------------------- linux/Platform.h | 6 ++++-- openbsd/Platform.c | 8 ++++++-- openbsd/Platform.h | 6 ++++-- solaris/Platform.c | 8 ++++++-- solaris/Platform.h | 6 ++++-- unsupported/Platform.c | 8 ++++++-- unsupported/Platform.h | 6 ++++-- 18 files changed, 119 insertions(+), 61 deletions(-) diff --git a/CRT.c b/CRT.c index e6f2ec9ed..888444cc3 100644 --- a/CRT.c +++ b/CRT.c @@ -94,6 +94,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), [METER_TEXT] = ColorPair(Cyan,Black), [METER_VALUE] = A_BOLD | ColorPair(Cyan,Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Black), [METER_VALUE_IOREAD] = ColorPair(Green,Black), [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), @@ -170,6 +171,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = A_BOLD, [METER_TEXT] = A_NORMAL, [METER_VALUE] = A_BOLD, + [METER_VALUE_ERROR] = A_BOLD, [METER_VALUE_NOTICE] = A_BOLD, [METER_VALUE_IOREAD] = A_NORMAL, [METER_VALUE_IOWRITE] = A_NORMAL, @@ -246,6 +248,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = ColorPair(Red,White), [METER_TEXT] = ColorPair(Blue,White), [METER_VALUE] = ColorPair(Black,White), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,White), [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,White), [METER_VALUE_IOREAD] = ColorPair(Green,White), [METER_VALUE_IOWRITE] = ColorPair(Yellow,White), @@ -322,6 +325,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = ColorPair(Red,Black), [METER_TEXT] = ColorPair(Blue,Black), [METER_VALUE] = ColorPair(Blue,Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), [METER_VALUE_IOREAD] = ColorPair(Green,Black), [METER_VALUE_IOWRITE] = ColorPair(Yellow,Black), @@ -398,6 +402,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Blue), [METER_TEXT] = ColorPair(Cyan,Blue), [METER_VALUE] = A_BOLD | ColorPair(Cyan,Blue), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Blue), [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Blue), [METER_VALUE_IOREAD] = ColorPair(Green,Blue), [METER_VALUE_IOWRITE] = ColorPair(Black,Blue), @@ -474,6 +479,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), [METER_TEXT] = ColorPair(Cyan,Black), [METER_VALUE] = ColorPair(Green,Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), [METER_VALUE_IOREAD] = ColorPair(Green,Black), [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), diff --git a/CRT.h b/CRT.h index 606492a4a..1cdc209ce 100644 --- a/CRT.h +++ b/CRT.h @@ -52,6 +52,7 @@ typedef enum ColorElements_ { LARGE_NUMBER, METER_TEXT, METER_VALUE, + METER_VALUE_ERROR, METER_VALUE_NOTICE, METER_VALUE_IOREAD, METER_VALUE_IOWRITE, diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 432ba6f03..9f311653b 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -24,6 +24,7 @@ static const int DiskIOMeter_attributes[] = { METER_VALUE_IOWRITE, }; +static bool hasData = false; static unsigned long int cached_read_diff = 0; static unsigned long int cached_write_diff = 0; static double cached_utilisation_diff = 0.0; @@ -37,12 +38,20 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) { struct timeval tv; gettimeofday(&tv, NULL); unsigned long long int timeInMilliSeconds = (unsigned long long int)tv.tv_sec * 1000 + (unsigned long long int)tv.tv_usec / 1000; + unsigned long long int passedTimeInMs = timeInMilliSeconds - cached_last_update; /* update only every 500ms */ - if (timeInMilliSeconds - cached_last_update > 500) { + if (passedTimeInMs > 500) { + cached_last_update = timeInMilliSeconds; + unsigned long int bytesRead, bytesWrite, msTimeSpend; - Platform_getDiskIO(&bytesRead, &bytesWrite, &msTimeSpend); + hasData = Platform_getDiskIO(&bytesRead, &bytesWrite, &msTimeSpend); + if (!hasData) { + this->values[0] = 0; + xSnprintf(buffer, len, "no data"); + return; + } cached_read_diff = (bytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ cached_read_total = bytesRead; @@ -50,8 +59,7 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) { cached_write_diff = (bytesWrite - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ cached_write_total = bytesWrite; - cached_utilisation_diff = 100 * (double)(msTimeSpend - cached_msTimeSpend_total) / (timeInMilliSeconds - cached_last_update); - cached_last_update = timeInMilliSeconds; + cached_utilisation_diff = 100 * (double)(msTimeSpend - cached_msTimeSpend_total) / passedTimeInMs; cached_msTimeSpend_total = msTimeSpend; } @@ -65,6 +73,11 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) { } static void DIskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { + if (!hasData) { + RichString_write(out, CRT_colors[METER_VALUE_ERROR], "no data"); + return; + } + char buffer[16]; int color = cached_utilisation_diff > 40.0 ? METER_VALUE_NOTICE : METER_VALUE; diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c index 44792c151..51d8d5ca0 100644 --- a/NetworkIOMeter.c +++ b/NetworkIOMeter.c @@ -16,6 +16,7 @@ static const int NetworkIOMeter_attributes[] = { METER_VALUE_IOWRITE, }; +static bool hasData = false; static unsigned long int cached_rxb_diff = 0; static unsigned long int cached_rxp_diff = 0; static unsigned long int cached_txb_diff = 0; @@ -35,9 +36,15 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i /* update only every 500ms */ if (passedTimeInMs > 500) { + cached_last_update = timeInMilliSeconds; + unsigned long int bytesReceived, packetsReceived, bytesTransmitted, packetsTransmitted; - Platform_getNetworkIO(&bytesReceived, &packetsReceived, &bytesTransmitted, &packetsTransmitted); + hasData = Platform_getNetworkIO(&bytesReceived, &packetsReceived, &bytesTransmitted, &packetsTransmitted); + if (!hasData) { + xSnprintf(buffer, len, "no data"); + return; + } cached_rxb_diff = (bytesReceived - cached_rxb_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ cached_rxb_diff = 1000.0 * cached_rxb_diff / passedTimeInMs; /* convert to per second */ @@ -52,8 +59,6 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i cached_txp_diff = packetsTransmitted - cached_txp_total; cached_txp_total = packetsTransmitted; - - cached_last_update = timeInMilliSeconds; } char bufferBytesReceived[12], bufferBytesTransmitted[12]; @@ -63,6 +68,11 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i } static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { + if (!hasData) { + RichString_write(out, CRT_colors[METER_VALUE_ERROR], "no data"); + return; + } + char buffer[64]; RichString_write(out, CRT_colors[METER_TEXT], "rx: "); diff --git a/darwin/Platform.c b/darwin/Platform.c index 26bcbad26..1a8b8002c 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -311,12 +311,15 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend) { // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; + return false; } -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted) { @@ -325,4 +328,5 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived, *packetsReceived = 0; *bytesTransmitted = 0; *packetsTransmitted = 0; + return false; } diff --git a/darwin/Platform.h b/darwin/Platform.h index d953b51c0..bdfe226d2 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -48,9 +48,11 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend); -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted); diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index b67ff8a19..f01749b7c 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -206,12 +206,15 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; } -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend) { // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; + return false; } -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted) { @@ -220,4 +223,5 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived, *packetsReceived = 0; *bytesTransmitted = 0; *packetsTransmitted = 0; + return false; } diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 7f31f0a50..7ea211cad 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -40,9 +40,11 @@ void Platform_setSwapValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend); -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index b03c58bec..465781a86 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -241,12 +241,15 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend) { // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; + return false; } -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted) { @@ -258,13 +261,9 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived, const int countMib[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT }; r = sysctl(countMib, ARRAYSIZE(countMib), &count, &countLen, NULL, 0); - if (r < 0) { - *bytesReceived = 0; - *packetsReceived = 0; - *bytesTransmitted = 0; - *packetsTransmitted = 0; - return; - } + if (r < 0) + return false; + unsigned long int bytesReceivedSum = 0, packetsReceivedSum = 0, bytesTransmittedSum = 0, packetsTransmittedSum = 0; @@ -291,4 +290,5 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived, *packetsReceived = packetsReceivedSum; *bytesTransmitted = bytesTransmittedSum; *packetsTransmitted = packetsTransmittedSum; + return true; } diff --git a/freebsd/Platform.h b/freebsd/Platform.h index c5cf659f3..40fb2d975 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -43,9 +43,11 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend); -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted); diff --git a/linux/Platform.c b/linux/Platform.c index e6c1c08ce..d21de0187 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -302,14 +302,11 @@ void Platform_getPressureStall(const char *file, bool some, double* ten, double* fclose(fd); } -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { FILE *fd = fopen(PROCDIR "/diskstats", "r"); - if (!fd) { - *bytesRead = 0; - *bytesWrite = 0; - *msTimeSpend = 0; - return; - } + if (!fd) + return false; + unsigned long int read_sum = 0, write_sum = 0, timeSpend_sum = 0; char lineBuffer[256]; while (fgets(lineBuffer, sizeof(lineBuffer), fd)) { @@ -347,32 +344,28 @@ void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWr *bytesRead = 512 * read_sum; *bytesWrite = 512 * write_sum; *msTimeSpend = timeSpend_sum; + return true; } -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted) { FILE *fd = fopen(PROCDIR "/net/dev", "r"); - if (!fd) { - *bytesReceived = 0; - *packetsReceived = 0; - *bytesTransmitted = 0; - *packetsTransmitted = 0; - return; - } + if (!fd) + return false; unsigned long int bytesReceivedSum = 0, packetsReceivedSum = 0, bytesTransmittedSum = 0, packetsTransmittedSum = 0; char lineBuffer[512]; while (fgets(lineBuffer, sizeof(lineBuffer), fd)) { char interfaceName[32]; unsigned long int bytesReceivedParsed, packetsReceivedParsed, bytesTransmittedParsed, packetsTransmittedParsed; - if (fscanf(fd, "%31s %lu %lu %*u %*u %*u %*u %*u %*u %lu %lu %*u %*u %*u %*u %*u %*u", - interfaceName, - &bytesReceivedParsed, - &packetsReceivedParsed, - &bytesTransmittedParsed, - &packetsTransmittedParsed) != 5) + if (sscanf(lineBuffer, "%31s %lu %lu %*u %*u %*u %*u %*u %*u %lu %lu", + interfaceName, + &bytesReceivedParsed, + &packetsReceivedParsed, + &bytesTransmittedParsed, + &packetsTransmittedParsed) != 5) continue; if (String_eq(interfaceName, "lo:")) @@ -390,4 +383,5 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived, *packetsReceived = packetsReceivedSum; *bytesTransmitted = bytesTransmittedSum; *packetsTransmitted = packetsTransmittedSum; + return true; } diff --git a/linux/Platform.h b/linux/Platform.h index 3d4cabac0..3c3986e6f 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -46,9 +46,11 @@ char* Platform_getProcessEnv(pid_t pid); void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend); -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted); diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 5b2492687..eac13c962 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -288,12 +288,15 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend) { // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; + return false; } -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted) { @@ -302,4 +305,5 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived, *packetsReceived = 0; *bytesTransmitted = 0; *packetsTransmitted = 0; + return false; } diff --git a/openbsd/Platform.h b/openbsd/Platform.h index f97fdc84a..b75d87b28 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -41,9 +41,11 @@ void Platform_setSwapValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend); -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted); diff --git a/solaris/Platform.c b/solaris/Platform.c index 4203a9648..978cca083 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -264,12 +264,15 @@ char* Platform_getProcessEnv(pid_t pid) { return envBuilder.env; } -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend) { // TODO *bytesRead = *bytesWrite = *msTimeSpend = 0; + return false; } -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted) { @@ -278,4 +281,5 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived, *packetsReceived = 0; *bytesTransmitted = 0; *packetsTransmitted = 0; + return false; } diff --git a/solaris/Platform.h b/solaris/Platform.h index 130c70cd7..f95515c61 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -63,9 +63,11 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend); -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted); diff --git a/unsupported/Platform.c b/unsupported/Platform.c index cc28fd8f7..e2d7fa6b2 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -141,11 +141,14 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; } -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend) { *bytesRead = *bytesWrite = *msTimeSpend = 0; + return false; } -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted) { @@ -153,4 +156,5 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived, *packetsReceived = 0; *bytesTransmitted = 0; *packetsTransmitted = 0; + return false; } diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 1049919d3..1558d66a2 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -47,9 +47,11 @@ bool Process_isThread(const Process* this); char* Platform_getProcessEnv(pid_t pid); -void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend); +bool Platform_getDiskIO(unsigned long int *bytesRead, + unsigned long int *bytesWrite, + unsigned long int *msTimeSpend); -void Platform_getNetworkIO(unsigned long int *bytesReceived, +bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, unsigned long int *bytesTransmitted, unsigned long int *packetsTransmitted); From 72103e9613a4767a3aad2dd63c629f4a1384880c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 21:25:50 +0200 Subject: [PATCH 337/411] Hold only a const version of the ProcessList in Meters --- Meter.c | 2 +- Meter.h | 4 ++-- TasksMeter.c | 4 ++-- darwin/Platform.c | 18 +++++++++--------- dragonflybsd/Platform.c | 8 ++++---- freebsd/Platform.c | 12 ++++++------ linux/Platform.c | 14 +++++++------- openbsd/Platform.c | 4 ++-- solaris/Platform.c | 12 ++++++------ zfs/ZfsArcMeter.c | 2 +- zfs/ZfsArcMeter.h | 2 +- zfs/ZfsCompressedArcMeter.c | 2 +- zfs/ZfsCompressedArcMeter.h | 2 +- 13 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Meter.c b/Meter.c index fa1eacb4a..a04a58321 100644 --- a/Meter.c +++ b/Meter.c @@ -31,7 +31,7 @@ const MeterClass Meter_class = { } }; -Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type) { +Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* type) { Meter* this = xCalloc(1, sizeof(Meter)); Object_setClass(this, type); this->h = 1; diff --git a/Meter.h b/Meter.h index ab8ee6e40..32c167cb3 100644 --- a/Meter.h +++ b/Meter.h @@ -74,7 +74,7 @@ struct Meter_ { int param; GraphData* drawData; int h; - ProcessList* pl; + const ProcessList* pl; char curItems; double* values; double total; @@ -98,7 +98,7 @@ typedef enum { extern const MeterClass Meter_class; -Meter* Meter_new(ProcessList* pl, int param, const MeterClass* type); +Meter* Meter_new(const ProcessList* pl, int param, const MeterClass* type); int Meter_humanUnit(char* buffer, unsigned long int value, int size); diff --git a/TasksMeter.c b/TasksMeter.c index 2116e3226..562cc8fc3 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -24,7 +24,7 @@ static const int TasksMeter_attributes[] = { }; static void TasksMeter_updateValues(Meter* this, char* buffer, int len) { - ProcessList* pl = this->pl; + const ProcessList* pl = this->pl; this->values[0] = pl->kernelThreads; this->values[1] = pl->userlandThreads; this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads; @@ -32,7 +32,7 @@ static void TasksMeter_updateValues(Meter* this, char* buffer, int len) { if (pl->totalTasks > this->total) { this->total = pl->totalTasks; } - if (this->pl->settings->hideKernelThreads) { + if (pl->settings->hideKernelThreads) { this->values[0] = 0; } xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total); diff --git a/darwin/Platform.c b/darwin/Platform.c index 1a8b8002c..965da0a15 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -176,8 +176,8 @@ ProcessPidColumn Process_pidColumns[] = { }; static double Platform_setCPUAverageValues(Meter* mtr) { - DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl; - int cpus = dpl->super.cpuCount; + const ProcessList *dpl = mtr->pl; + int cpus = dpl->cpuCount; double sumNice = 0.0; double sumNormal = 0.0; double sumKernel = 0.0; @@ -200,9 +200,9 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { return Platform_setCPUAverageValues(mtr); } - DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl; - processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1]; - processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1]; + const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl; + const processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1]; + const processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1]; double total = 0; /* Take the sums */ @@ -228,8 +228,8 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { } void Platform_setMemoryValues(Meter* mtr) { - DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl; - vm_statistics_t vm = &dpl->vm_stats; + const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl; + const struct vm_statistics* vm = &dpl->vm_stats; double page_K = (double)vm_page_size / (double)1024; mtr->total = dpl->host_info.max_mem / 1024; @@ -249,13 +249,13 @@ void Platform_setSwapValues(Meter* mtr) { } void Platform_setZfsArcValues(Meter* this) { - DarwinProcessList* dpl = (DarwinProcessList*) this->pl; + const DarwinProcessList* dpl = (const DarwinProcessList*) this->pl; ZfsArcMeter_readStats(this, &(dpl->zfs)); } void Platform_setZfsCompressedArcValues(Meter* this) { - DarwinProcessList* dpl = (DarwinProcessList*) this->pl; + const DarwinProcessList* dpl = (const DarwinProcessList*) this->pl; ZfsCompressedArcMeter_readStats(this, &(dpl->zfs)); } diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index f01749b7c..3eac7debc 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -149,9 +149,9 @@ int Platform_getMaxPid() { } double Platform_setCPUValues(Meter* this, int cpu) { - DragonFlyBSDProcessList* fpl = (DragonFlyBSDProcessList*) this->pl; + const DragonFlyBSDProcessList* fpl = (const DragonFlyBSDProcessList*) this->pl; int cpus = this->pl->cpuCount; - CPUData* cpuData; + const CPUData* cpuData; if (cpus == 1) { // single CPU box has everything in fpl->cpus[0] @@ -186,7 +186,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { void Platform_setMemoryValues(Meter* this) { // TODO - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; this->total = pl->totalMem; this->values[0] = pl->usedMem; @@ -195,7 +195,7 @@ void Platform_setMemoryValues(Meter* this) { } void Platform_setSwapValues(Meter* this) { - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[0] = pl->usedSwap; } diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 465781a86..0a27f7c48 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -157,9 +157,9 @@ int Platform_getMaxPid() { } double Platform_setCPUValues(Meter* this, int cpu) { - FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl; + const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl; int cpus = this->pl->cpuCount; - CPUData* cpuData; + const CPUData* cpuData; if (cpus == 1) { // single CPU box has everything in fpl->cpus[0] @@ -194,7 +194,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { void Platform_setMemoryValues(Meter* this) { // TODO - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; this->total = pl->totalMem; this->values[0] = pl->usedMem; @@ -203,19 +203,19 @@ void Platform_setMemoryValues(Meter* this) { } void Platform_setSwapValues(Meter* this) { - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[0] = pl->usedSwap; } void Platform_setZfsArcValues(Meter* this) { - FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl; + const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl; ZfsArcMeter_readStats(this, &(fpl->zfs)); } void Platform_setZfsCompressedArcValues(Meter* this) { - FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl; + const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl; ZfsCompressedArcMeter_readStats(this, &(fpl->zfs)); } diff --git a/linux/Platform.c b/linux/Platform.c index d21de0187..64180484c 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -189,8 +189,8 @@ int Platform_getMaxPid() { } double Platform_setCPUValues(Meter* this, int cpu) { - LinuxProcessList* pl = (LinuxProcessList*) this->pl; - CPUData* cpuData = &(pl->cpus[cpu]); + const LinuxProcessList* pl = (const LinuxProcessList*) this->pl; + const CPUData* cpuData = &(pl->cpus[cpu]); double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod); double percent; double* v = this->values; @@ -224,8 +224,8 @@ double Platform_setCPUValues(Meter* this, int cpu) { } void Platform_setMemoryValues(Meter* this) { - ProcessList* pl = this->pl; - LinuxProcessList* lpl = (LinuxProcessList*) this->pl; + const ProcessList* pl = this->pl; + const LinuxProcessList* lpl = (const LinuxProcessList*) pl; long int usedMem = pl->usedMem; long int buffersMem = pl->buffersMem; @@ -243,19 +243,19 @@ void Platform_setMemoryValues(Meter* this) { } void Platform_setSwapValues(Meter* this) { - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[0] = pl->usedSwap; } void Platform_setZfsArcValues(Meter* this) { - LinuxProcessList* lpl = (LinuxProcessList*) this->pl; + const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl; ZfsArcMeter_readStats(this, &(lpl->zfs)); } void Platform_setZfsCompressedArcValues(Meter* this) { - LinuxProcessList* lpl = (LinuxProcessList*) this->pl; + const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl; ZfsCompressedArcMeter_readStats(this, &(lpl->zfs)); } diff --git a/openbsd/Platform.c b/openbsd/Platform.c index eac13c962..9f7cd7378 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -189,7 +189,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { } void Platform_setMemoryValues(Meter* this) { - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; long int usedMem = pl->usedMem; long int buffersMem = pl->buffersMem; long int cachedMem = pl->cachedMem; @@ -207,7 +207,7 @@ void Platform_setMemoryValues(Meter* this) { * Taken almost directly from OpenBSD's top(1) */ void Platform_setSwapValues(Meter* this) { - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; struct swapent *swdev; unsigned long long int total, used; int nswap, rnswap, i; diff --git a/solaris/Platform.c b/solaris/Platform.c index 978cca083..2fa2e1de5 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -167,9 +167,9 @@ int Platform_getMaxPid() { } double Platform_setCPUValues(Meter* this, int cpu) { - SolarisProcessList* spl = (SolarisProcessList*) this->pl; + const SolarisProcessList* spl = (const SolarisProcessList*) this->pl; int cpus = this->pl->cpuCount; - CPUData* cpuData = NULL; + const CPUData* cpuData = NULL; if (cpus == 1) { // single CPU box has everything in spl->cpus[0] @@ -203,7 +203,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { } void Platform_setMemoryValues(Meter* this) { - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; this->total = pl->totalMem; this->values[0] = pl->usedMem; this->values[1] = pl->buffersMem; @@ -211,19 +211,19 @@ void Platform_setMemoryValues(Meter* this) { } void Platform_setSwapValues(Meter* this) { - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[0] = pl->usedSwap; } void Platform_setZfsArcValues(Meter* this) { - SolarisProcessList* spl = (SolarisProcessList*) this->pl; + const SolarisProcessList* spl = (const SolarisProcessList*) this->pl; ZfsArcMeter_readStats(this, &(spl->zfs)); } void Platform_setZfsCompressedArcValues(Meter* this) { - SolarisProcessList* spl = (SolarisProcessList*) this->pl; + const SolarisProcessList* spl = (const SolarisProcessList*) this->pl; ZfsCompressedArcMeter_readStats(this, &(spl->zfs)); } diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index 55ef2c562..72af3bc78 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -18,7 +18,7 @@ static const int ZfsArcMeter_attributes[] = { ZFS_MFU, ZFS_MRU, ZFS_ANON, ZFS_HEADER, ZFS_OTHER }; -void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats) { +void ZfsArcMeter_readStats(Meter* this, const ZfsArcStats* stats) { this->total = stats->max; this->values[0] = stats->MFU; this->values[1] = stats->MRU; diff --git a/zfs/ZfsArcMeter.h b/zfs/ZfsArcMeter.h index cf552bceb..52bf7842d 100644 --- a/zfs/ZfsArcMeter.h +++ b/zfs/ZfsArcMeter.h @@ -11,7 +11,7 @@ in the source distribution for its full text. #include "Meter.h" -void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats); +void ZfsArcMeter_readStats(Meter* this, const ZfsArcStats* stats); extern const MeterClass ZfsArcMeter_class; diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index 0a67c7edf..993d80e2b 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -21,7 +21,7 @@ static const int ZfsCompressedArcMeter_attributes[] = { ZFS_COMPRESSED }; -void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats) { +void ZfsCompressedArcMeter_readStats(Meter* this, const ZfsArcStats* stats) { if ( stats->isCompressed ) { this->total = stats->uncompressed; this->values[0] = stats->compressed; diff --git a/zfs/ZfsCompressedArcMeter.h b/zfs/ZfsCompressedArcMeter.h index 1ad6447d2..025a9dd8d 100644 --- a/zfs/ZfsCompressedArcMeter.h +++ b/zfs/ZfsCompressedArcMeter.h @@ -11,7 +11,7 @@ in the source distribution for its full text. #include "Meter.h" -void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats); +void ZfsCompressedArcMeter_readStats(Meter* this, const ZfsArcStats* stats); extern const MeterClass ZfsCompressedArcMeter_class; From 71091724319c85574f5dbb11230ef5fe463f12fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 21:26:01 +0200 Subject: [PATCH 338/411] Mark process parameter of Process_writeField consistently const --- dragonflybsd/DragonFlyBSDProcess.c | 6 +++--- dragonflybsd/DragonFlyBSDProcess.h | 2 +- freebsd/FreeBSDProcess.c | 6 +++--- freebsd/FreeBSDProcess.h | 2 +- linux/LinuxProcess.c | 6 +++--- linux/LinuxProcess.h | 2 +- openbsd/OpenBSDProcess.c | 4 ++-- openbsd/OpenBSDProcess.h | 2 +- solaris/SolarisProcess.c | 6 +++--- solaris/SolarisProcess.h | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 4c2310934..517fc2a11 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -25,7 +25,7 @@ const ProcessClass DragonFlyBSDProcess_class = { .delete = Process_delete, .compare = DragonFlyBSDProcess_compare }, - .writeField = (Process_WriteField) DragonFlyBSDProcess_writeField, + .writeField = DragonFlyBSDProcess_writeField, }; ProcessFieldData Process_fields[] = { @@ -83,8 +83,8 @@ void Process_delete(Object* cast) { free(this); } -void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField field) { - DragonFlyBSDProcess* fp = (DragonFlyBSDProcess*) this; +void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { + const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) this; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; int n = sizeof(buffer) - 1; diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h index 1c048143b..92e1dde24 100644 --- a/dragonflybsd/DragonFlyBSDProcess.h +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -37,7 +37,7 @@ DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings); void Process_delete(Object* cast); -void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField field); +void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, ProcessField field); long DragonFlyBSDProcess_compare(const void* v1, const void* v2); diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 710194942..684f4dfe5 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -24,7 +24,7 @@ const ProcessClass FreeBSDProcess_class = { .delete = Process_delete, .compare = FreeBSDProcess_compare }, - .writeField = (Process_WriteField) FreeBSDProcess_writeField, + .writeField = FreeBSDProcess_writeField, }; ProcessFieldData Process_fields[] = { @@ -83,8 +83,8 @@ void Process_delete(Object* cast) { free(this); } -void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField field) { - FreeBSDProcess* fp = (FreeBSDProcess*) this; +void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { + const FreeBSDProcess* fp = (const FreeBSDProcess*) this; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; int n = sizeof(buffer) - 1; diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index 366570602..d7b401015 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -43,7 +43,7 @@ FreeBSDProcess* FreeBSDProcess_new(Settings* settings); void Process_delete(Object* cast); -void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField field); +void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessField field); long FreeBSDProcess_compare(const void* v1, const void* v2); diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 8003157cb..b53692d8e 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -135,7 +135,7 @@ const ProcessClass LinuxProcess_class = { .delete = Process_delete, .compare = LinuxProcess_compare }, - .writeField = (Process_WriteField) LinuxProcess_writeField, + .writeField = LinuxProcess_writeField, }; LinuxProcess* LinuxProcess_new(Settings* settings) { @@ -197,8 +197,8 @@ void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) { } #endif -void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) { - LinuxProcess* lp = (LinuxProcess*) this; +void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField field) { + const LinuxProcess* lp = (const LinuxProcess*) this; bool coloring = this->settings->highlightMegabytes; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 8e7c36dc3..bb0c5ebb9 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -189,7 +189,7 @@ bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio); void LinuxProcess_printDelay(float delay_percent, char* buffer, int n); #endif -void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field); +void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField field); long LinuxProcess_compare(const void* v1, const void* v2); diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 56bc07717..bc6ef4a82 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -24,7 +24,7 @@ const ProcessClass OpenBSDProcess_class = { .delete = Process_delete, .compare = OpenBSDProcess_compare }, - .writeField = (Process_WriteField) OpenBSDProcess_writeField, + .writeField = OpenBSDProcess_writeField, }; ProcessFieldData Process_fields[] = { @@ -178,7 +178,7 @@ void Process_delete(Object* cast) { free(this); } -void OpenBSDProcess_writeField(Process* this, RichString* str, ProcessField field) { +void OpenBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { //OpenBSDProcess* fp = (OpenBSDProcess*) this; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; diff --git a/openbsd/OpenBSDProcess.h b/openbsd/OpenBSDProcess.h index 5694a524d..c9d4e381b 100644 --- a/openbsd/OpenBSDProcess.h +++ b/openbsd/OpenBSDProcess.h @@ -31,7 +31,7 @@ OpenBSDProcess* OpenBSDProcess_new(Settings* settings); void Process_delete(Object* cast); -void OpenBSDProcess_writeField(Process* this, RichString* str, ProcessField field); +void OpenBSDProcess_writeField(const Process* this, RichString* str, ProcessField field); long OpenBSDProcess_compare(const void* v1, const void* v2); diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index 0d9946698..13652bd34 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -25,7 +25,7 @@ const ProcessClass SolarisProcess_class = { .delete = Process_delete, .compare = SolarisProcess_compare }, - .writeField = (Process_WriteField) SolarisProcess_writeField, + .writeField = SolarisProcess_writeField, }; ProcessFieldData Process_fields[] = { @@ -93,8 +93,8 @@ void Process_delete(Object* cast) { free(sp); } -void SolarisProcess_writeField(Process* this, RichString* str, ProcessField field) { - SolarisProcess* sp = (SolarisProcess*) this; +void SolarisProcess_writeField(const Process* this, RichString* str, ProcessField field) { + const SolarisProcess* sp = (const SolarisProcess*) this; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; int n = sizeof(buffer) - 1; diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index a1b3b14d5..23012a2f1 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -54,7 +54,7 @@ SolarisProcess* SolarisProcess_new(Settings* settings); void Process_delete(Object* cast); -void SolarisProcess_writeField(Process* this, RichString* str, ProcessField field); +void SolarisProcess_writeField(const Process* this, RichString* str, ProcessField field); long SolarisProcess_compare(const void* v1, const void* v2); From 4eb443926f9944f4c100b1aabfb5553cbbd98874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 21:26:05 +0200 Subject: [PATCH 339/411] Hold only a const version of Settings in Process --- Process.c | 2 +- Process.h | 6 +++--- darwin/DarwinProcess.c | 4 ++-- darwin/DarwinProcess.h | 2 +- darwin/DarwinProcessList.c | 2 +- dragonflybsd/DragonFlyBSDProcess.c | 4 ++-- dragonflybsd/DragonFlyBSDProcess.h | 2 +- dragonflybsd/DragonFlyBSDProcessList.c | 2 +- freebsd/FreeBSDProcess.c | 4 ++-- freebsd/FreeBSDProcess.h | 2 +- freebsd/FreeBSDProcessList.c | 2 +- linux/LinuxProcess.c | 4 ++-- linux/LinuxProcess.h | 2 +- linux/LinuxProcessList.c | 2 +- openbsd/OpenBSDProcess.c | 4 ++-- openbsd/OpenBSDProcess.h | 2 +- openbsd/OpenBSDProcessList.c | 2 +- solaris/SolarisProcess.c | 4 ++-- solaris/SolarisProcess.h | 2 +- solaris/SolarisProcessList.c | 2 +- 20 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Process.c b/Process.c index 5f5be13ad..842232f70 100644 --- a/Process.c +++ b/Process.c @@ -399,7 +399,7 @@ const ProcessClass Process_class = { .writeField = Process_writeField, }; -void Process_init(Process* this, struct Settings_* settings) { +void Process_init(Process* this, const struct Settings_* settings) { this->settings = settings; this->tag = false; this->showChildren = true; diff --git a/Process.h b/Process.h index 440cbb1c4..2432918fd 100644 --- a/Process.h +++ b/Process.h @@ -59,7 +59,7 @@ struct Settings_; typedef struct Process_ { Object super; - struct Settings_* settings; + const struct Settings_* settings; unsigned long long int time; pid_t pid; @@ -119,7 +119,7 @@ extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; extern char Process_pidFormat[20]; -typedef Process*(*Process_New)(struct Settings_*); +typedef Process*(*Process_New)(const struct Settings_*); typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField); typedef struct ProcessClass_ { @@ -164,7 +164,7 @@ void Process_done(Process* this); extern const ProcessClass Process_class; -void Process_init(Process* this, struct Settings_* settings); +void Process_init(Process* this, const struct Settings_* settings); void Process_toggleTag(Process* this); diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 7049cb1ed..73214836f 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -28,7 +28,7 @@ const ProcessClass DarwinProcess_class = { .writeField = Process_writeField, }; -DarwinProcess* DarwinProcess_new(Settings* settings) { +Process* DarwinProcess_new(const Settings* settings) { DarwinProcess* this = xCalloc(1, sizeof(DarwinProcess)); Object_setClass(this, Class(DarwinProcess)); Process_init(&this->super, settings); @@ -37,7 +37,7 @@ DarwinProcess* DarwinProcess_new(Settings* settings) { this->stime = 0; this->taskAccess = true; - return this; + return &this->super; } void Process_delete(Object* cast) { diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index 69a1d63b3..1d9dc34aa 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -22,7 +22,7 @@ typedef struct DarwinProcess_ { extern const ProcessClass DarwinProcess_class; -DarwinProcess* DarwinProcess_new(Settings* settings); +Process* DarwinProcess_new(const Settings* settings); void Process_delete(Object* cast); diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 2c9f533f2..bae8e2227 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -186,7 +186,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { ps = ProcessList_getKInfoProcs(&count); for(size_t i = 0; i < count; ++i) { - proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new); + proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new); DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); DarwinProcess_setFromLibprocPidinfo(proc, dpl); diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 517fc2a11..6650cb7e4 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -69,11 +69,11 @@ ProcessPidColumn Process_pidColumns[] = { { .id = 0, .label = NULL }, }; -DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings) { +Process* DragonFlyBSDProcess_new(const Settings* settings) { DragonFlyBSDProcess* this = xCalloc(1, sizeof(DragonFlyBSDProcess)); Object_setClass(this, Class(DragonFlyBSDProcess)); Process_init(&this->super, settings); - return this; + return &this->super; } void Process_delete(Object* cast) { diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h index 92e1dde24..1befd9466 100644 --- a/dragonflybsd/DragonFlyBSDProcess.h +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -33,7 +33,7 @@ extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; -DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings); +Process* DragonFlyBSDProcess_new(const Settings* settings); void Process_delete(Object* cast); diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 73ef025ab..7fcee4105 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -385,7 +385,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { bool ATTR_UNUSED isIdleProcess = false; // note: dragonflybsd kernel processes all have the same pid, so we misuse the kernel thread address to give them a unique identifier - Process* proc = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, (Process_New) DragonFlyBSDProcess_new); + Process* proc = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, DragonFlyBSDProcess_new); DragonFlyBSDProcess* dfp = (DragonFlyBSDProcess*) proc; proc->show = ! ((hideKernelThreads && Process_isKernelThread(dfp)) || (hideUserlandThreads && Process_isUserlandThread(proc))); diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 684f4dfe5..ea3f693dd 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -69,11 +69,11 @@ ProcessPidColumn Process_pidColumns[] = { { .id = 0, .label = NULL }, }; -FreeBSDProcess* FreeBSDProcess_new(Settings* settings) { +Process* FreeBSDProcess_new(const Settings* settings) { FreeBSDProcess* this = xCalloc(1, sizeof(FreeBSDProcess)); Object_setClass(this, Class(FreeBSDProcess)); Process_init(&this->super, settings); - return this; + return &this->super; } void Process_delete(Object* cast) { diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index d7b401015..aa769d653 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -39,7 +39,7 @@ extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; -FreeBSDProcess* FreeBSDProcess_new(Settings* settings); +Process* FreeBSDProcess_new(const Settings* settings); void Process_delete(Object* cast); diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index c80570603..4e4184468 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -401,7 +401,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { struct kinfo_proc* kproc = &kprocs[i]; bool preExisting = false; // TODO: bool isIdleProcess = false; - Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, (Process_New) FreeBSDProcess_new); + Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, FreeBSDProcess_new); FreeBSDProcess* fp = (FreeBSDProcess*) proc; proc->show = ! ((hideKernelThreads && Process_isKernelThread(fp)) || (hideUserlandThreads && Process_isUserlandThread(proc))); diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index b53692d8e..23783ef0d 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -138,11 +138,11 @@ const ProcessClass LinuxProcess_class = { .writeField = LinuxProcess_writeField, }; -LinuxProcess* LinuxProcess_new(Settings* settings) { +Process* LinuxProcess_new(const Settings* settings) { LinuxProcess* this = xCalloc(1, sizeof(LinuxProcess)); Object_setClass(this, Class(LinuxProcess)); Process_init(&this->super, settings); - return this; + return &this->super; } void Process_delete(Object* cast) { diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index bb0c5ebb9..45a3127f1 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -167,7 +167,7 @@ extern ProcessPidColumn Process_pidColumns[]; extern const ProcessClass LinuxProcess_class; -LinuxProcess* LinuxProcess_new(Settings* settings); +Process* LinuxProcess_new(const Settings* settings); void Process_delete(Object* cast); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 421d0c94f..0903531a5 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -971,7 +971,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* continue; bool preExisting = false; - Process* proc = ProcessList_getProcess(pl, pid, &preExisting, (Process_New) LinuxProcess_new); + Process* proc = ProcessList_getProcess(pl, pid, &preExisting, LinuxProcess_new); proc->tgid = parent ? parent->pid : pid; LinuxProcess* lp = (LinuxProcess*) proc; diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index bc6ef4a82..c43fe2fcf 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -165,11 +165,11 @@ ProcessPidColumn Process_pidColumns[] = { { .id = 0, .label = NULL }, }; -OpenBSDProcess* OpenBSDProcess_new(Settings* settings) { +Process* OpenBSDProcess_new(const Settings* settings) { OpenBSDProcess* this = xCalloc(sizeof(OpenBSDProcess), 1); Object_setClass(this, Class(OpenBSDProcess)); Process_init(&this->super, settings); - return this; + return &this->this; } void Process_delete(Object* cast) { diff --git a/openbsd/OpenBSDProcess.h b/openbsd/OpenBSDProcess.h index c9d4e381b..12ce18409 100644 --- a/openbsd/OpenBSDProcess.h +++ b/openbsd/OpenBSDProcess.h @@ -27,7 +27,7 @@ extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; -OpenBSDProcess* OpenBSDProcess_new(Settings* settings); +Process* OpenBSDProcess_new(const Settings* settings); void Process_delete(Object* cast); diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 5838fea9d..693ec9dbe 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -203,7 +203,7 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { kproc = &kprocs[i]; preExisting = false; - proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, (Process_New) OpenBSDProcess_new); + proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, OpenBSDProcess_new); fp = (OpenBSDProcess*) proc; proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index 13652bd34..9c6c7d778 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -79,11 +79,11 @@ ProcessPidColumn Process_pidColumns[] = { { .id = 0, .label = NULL }, }; -SolarisProcess* SolarisProcess_new(Settings* settings) { +Process* SolarisProcess_new(const Settings* settings) { SolarisProcess* this = xCalloc(1, sizeof(SolarisProcess)); Object_setClass(this, Class(SolarisProcess)); Process_init(&this->super, settings); - return this; + return &this->super; } void Process_delete(Object* cast) { diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index 23012a2f1..4756634dc 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -50,7 +50,7 @@ extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; -SolarisProcess* SolarisProcess_new(Settings* settings); +Process* SolarisProcess_new(const Settings* settings); void Process_delete(Object* cast); diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 85fc955b1..72806134d 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -279,7 +279,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * } else { getpid = lwpid; } - Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, (Process_New) SolarisProcess_new); + Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, SolarisProcess_new); SolarisProcess *sproc = (SolarisProcess*) proc; // Common code pass 1 From a3bb7cbe649d9c718b65aded4c6b2445ff5d20d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 21:26:09 +0200 Subject: [PATCH 340/411] Hold only a const version of Settings in ProcessList --- ProcessList.c | 19 ++++++++++--------- ProcessList.h | 2 +- Vector.c | 6 +++--- Vector.h | 5 ++++- dragonflybsd/DragonFlyBSDProcessList.c | 2 +- freebsd/FreeBSDProcessList.c | 2 +- linux/LinuxProcessList.c | 2 +- openbsd/OpenBSDProcessList.c | 2 +- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/ProcessList.c b/ProcessList.c index f2cdcf941..dac86cb87 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -67,7 +67,7 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) { void ProcessList_printHeader(ProcessList* this, RichString* header) { RichString_prune(header); - ProcessField* fields = this->settings->fields; + const ProcessField* fields = this->settings->fields; for (int i = 0; fields[i]; i++) { const char* field = Process_fields[fields[i]].title; if (!field) field = "- "; @@ -142,20 +142,21 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i Vector_delete(children); } +static long ProcessList_treeProcessCompare(const void* v1, const void* v2) { + const Process *p1 = (const Process*)v1; + const Process *p2 = (const Process*)v2; + + return p1->pid - p2->pid; +} + void ProcessList_sort(ProcessList* this) { if (!this->settings->treeView) { Vector_insertionSort(this->processes); } else { // Save settings int direction = this->settings->direction; - int sortKey = this->settings->sortKey; // Sort by PID - this->settings->sortKey = PID; - this->settings->direction = 1; - Vector_quickSort(this->processes); - // Restore settings - this->settings->sortKey = sortKey; - this->settings->direction = direction; + Vector_quickSortCustomCompare(this->processes, ProcessList_treeProcessCompare); int vsize = Vector_size(this->processes); // Find all processes whose parent is not visible int size; @@ -214,7 +215,7 @@ void ProcessList_sort(ProcessList* this) { ProcessField ProcessList_keyAt(ProcessList* this, int at) { int x = 0; - ProcessField* fields = this->settings->fields; + const ProcessField* fields = this->settings->fields; ProcessField field; for (int i = 0; (field = fields[i]); i++) { const char* title = Process_fields[field].title; diff --git a/ProcessList.h b/ProcessList.h index 07fe48bce..4c09e4ceb 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -35,7 +35,7 @@ in the source distribution for its full text. #endif typedef struct ProcessList_ { - Settings* settings; + const Settings* settings; Vector* processes; Vector* processes2; diff --git a/Vector.c b/Vector.c index 1dfccc446..4ed0d53d6 100644 --- a/Vector.c +++ b/Vector.c @@ -161,10 +161,10 @@ static void insertionSort(Object** array, int left, int right, Object_Compare co } } -void Vector_quickSort(Vector* this) { - assert(this->type->compare); +void Vector_quickSortCustomCompare(Vector* this, Object_Compare compare) { + assert(compare); assert(Vector_isConsistent(this)); - quickSort(this->array, 0, this->items - 1, this->type->compare); + quickSort(this->array, 0, this->items - 1, compare); assert(Vector_isConsistent(this)); } diff --git a/Vector.h b/Vector.h index 3cff212cf..70df3e4a2 100644 --- a/Vector.h +++ b/Vector.h @@ -31,7 +31,10 @@ void Vector_delete(Vector* this); void Vector_prune(Vector* this); -void Vector_quickSort(Vector* this); +void Vector_quickSortCustomCompare(Vector* this, Object_Compare compare); +static inline void Vector_quickSort(Vector* this) { + Vector_quickSortCustomCompare(this, this->type->compare); +} void Vector_insertionSort(Vector* this); diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 7fcee4105..d6eb38a5b 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -362,7 +362,7 @@ char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int ja void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this; - Settings* settings = this->settings; + const Settings* settings = this->settings; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 4e4184468..28cdf859e 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -382,7 +382,7 @@ IGNORE_WCASTQUAL_END void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { FreeBSDProcessList* fpl = (FreeBSDProcessList*) this; - Settings* settings = this->settings; + const Settings* settings = this->settings; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 0903531a5..5195c6160 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -936,7 +936,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* ProcessList* pl = (ProcessList*) this; DIR* dir; struct dirent* entry; - Settings* settings = pl->settings; + const Settings* settings = pl->settings; #ifdef HAVE_TASKSTATS unsigned long long now = tv.tv_sec*1000LL+tv.tv_usec/1000LL; diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 693ec9dbe..320b693b4 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -185,7 +185,7 @@ static double getpcpu(const struct kinfo_proc *kp) { } static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { - Settings* settings = this->super.settings; + const Settings* settings = this->super.settings; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; struct kinfo_proc* kproc; From c98d4577c998047d7bd32c18b3802dd2bc09a634 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 26 Oct 2020 19:18:29 +0100 Subject: [PATCH 341/411] Refactor code for reading process environment from procfs --- linux/Platform.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/linux/Platform.c b/linux/Platform.c index 64180484c..43bf84b16 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -263,24 +263,35 @@ char* Platform_getProcessEnv(pid_t pid) { char procname[128]; xSnprintf(procname, sizeof(procname), PROCDIR "/%d/environ", pid); FILE* fd = fopen(procname, "r"); + if(!fd) + return NULL; + char *env = NULL; - if (fd) { - size_t capacity = 4096, size = 0, bytes; - env = xMalloc(capacity); - while ((bytes = fread(env+size, 1, capacity-size, fd)) > 0) { - size += bytes; - capacity *= 2; - env = xRealloc(env, capacity); - } - fclose(fd); - if (size < 2 || env[size-1] || env[size-2]) { - if (size + 2 < capacity) { - env = xRealloc(env, capacity+2); - } - env[size] = 0; - env[size+1] = 0; - } + + size_t capacity = 0; + size_t size = 0; + ssize_t bytes = 0; + + do { + size += bytes; + capacity += 4096; + env = xRealloc(env, capacity); + } while ((bytes = fread(env + size, 1, capacity - size, fd)) > 0); + + fclose(fd); + + if (bytes < 0) { + free(env); + return NULL; } + + size += bytes; + + env = xRealloc(env, size + 2); + + env[size] = '\0'; + env[size+1] = '\0'; + return env; } From 1533ea88a6b7e4206e21e6405a253f8f62a81cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 11:02:34 +0100 Subject: [PATCH 342/411] Drop duplicate and always true condition This block is only entered if this->owner is true. --- Vector.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Vector.c b/Vector.c index 4ed0d53d6..77f56a888 100644 --- a/Vector.c +++ b/Vector.c @@ -264,9 +264,7 @@ void Vector_set(Vector* this, int idx, void* data_) { if (this->owner) { Object* removed = this->array[idx]; assert (removed != NULL); - if (this->owner) { - Object_delete(removed); - } + Object_delete(removed); } } this->array[idx] = data; From 27870bd4deceff8396bbc569927716773b1aea29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 11:03:02 +0100 Subject: [PATCH 343/411] Drop unneeded variablw initialization and reduce scope --- linux/LinuxProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5195c6160..5d9bc3c44 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -482,7 +482,6 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di char buffer[CRT_pageSize];// 4k char *start,*end; ssize_t nread=0; - int tmp=0; if(haveSmapsRollup) {// only available in Linux 4.14+ xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps_rollup", dirname, name); } else { @@ -500,6 +499,7 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di start = (char *)&buffer; end = start + nread; do{//parse 4k block + int tmp; if( (tmp = (end - start)) > 0 && (start = memmem(start,tmp,"\nPss:",5)) != NULL ) From ac2b07eddd6f0b7c41b84b71653ca90fd301085f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 11:46:29 +0100 Subject: [PATCH 344/411] Avoid some unnecessary casts and mark some not changing variables const --- Action.c | 12 ++++++------ Panel.c | 2 +- UsersTable.c | 4 ++-- linux/LinuxProcess.c | 6 +++--- linux/LinuxProcess.h | 2 +- linux/LinuxProcessList.c | 5 ++--- linux/Platform.c | 2 +- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Action.c b/Action.c index 3f5737fcc..5b68811ef 100644 --- a/Action.c +++ b/Action.c @@ -93,20 +93,20 @@ static void Action_runSetup(State* st) { static bool changePriority(MainPanel* panel, int delta) { bool anyTagged; - bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged); + bool ok = MainPanel_foreachProcess(panel, Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged); if (!ok) beep(); return anyTagged; } static void addUserToVector(int key, void* userCast, void* panelCast) { - char* user = (char*) userCast; - Panel* panel = (Panel*) panelCast; + const char* user = userCast; + Panel* panel = panelCast; Panel_add(panel, (Object*) ListItem_new(user, key)); } bool Action_setUserOnly(const char* userName, uid_t* userId) { - struct passwd* user = getpwnam(userName); + const struct passwd* user = getpwnam(userName); if (user) { *userId = user->pw_uid; return true; @@ -301,7 +301,7 @@ static Htop_Reaction actionSetAffinity(State* st) { void* set = Action_pickFromVector(st, affinityPanel, width, true); if (set) { Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity2 }, NULL); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg){ .v = affinity2 }, NULL); if (!ok) beep(); Affinity_delete(affinity2); } @@ -318,7 +318,7 @@ static Htop_Reaction actionKill(State* st) { Panel_setHeader(st->panel, "Sending..."); Panel_draw(st->panel, true); refresh(); - MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (Arg){ .i = sgn->key }, NULL); + MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg){ .i = sgn->key }, NULL); napms(500); } } diff --git a/Panel.c b/Panel.c index 782cbdc1c..02440d85c 100644 --- a/Panel.c +++ b/Panel.c @@ -423,7 +423,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) { for (int try = 0; try < 2; try++) { len = strlen(buffer); for (int i = 0; i < size; i++) { - char* cur = ((ListItem*) Panel_get(this, i))->value; + const char* cur = ((ListItem*) Panel_get(this, i))->value; while (*cur == ' ') cur++; if (strncasecmp(cur, buffer, len) == 0) { Panel_setSelected(this, i); diff --git a/UsersTable.c b/UsersTable.c index 83c6dbc3c..25e448838 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -30,9 +30,9 @@ void UsersTable_delete(UsersTable* this) { } char* UsersTable_getRef(UsersTable* this, unsigned int uid) { - char* name = (char*) (Hashtable_get(this->users, uid)); + char* name = Hashtable_get(this->users, uid); if (name == NULL) { - struct passwd* userData = getpwuid(uid); + const struct passwd* userData = getpwuid(uid); if (userData != NULL) { name = xStrdup(userData->pw_name); Hashtable_put(this->users, uid, name); diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 23783ef0d..fad805559 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -179,12 +179,12 @@ IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this) { return ioprio; } -bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio) { +bool LinuxProcess_setIOPriority(Process* this, Arg ioprio) { // Other OSes masquerading as Linux (NetBSD?) don't have this syscall #ifdef SYS_ioprio_set - syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->super.pid, ioprio.i); + syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->pid, ioprio.i); #endif - return (LinuxProcess_updateIOPriority(this) == ioprio.i); + return (LinuxProcess_updateIOPriority((LinuxProcess*)this) == ioprio.i); } #ifdef HAVE_DELAYACCT diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 45a3127f1..80a4220b3 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -183,7 +183,7 @@ extern io_priority; IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this); -bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio); +bool LinuxProcess_setIOPriority(Process* this, Arg ioprio); #ifdef HAVE_DELAYACCT void LinuxProcess_printDelay(float delay_percent, char* buffer, int n); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5d9bc3c44..f7d015572 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -480,7 +480,6 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di //kernel will return data in chunks of size PAGE_SIZE or less. char buffer[CRT_pageSize];// 4k - char *start,*end; ssize_t nread=0; if(haveSmapsRollup) {// only available in Linux 4.14+ xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps_rollup", dirname, name); @@ -496,8 +495,8 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di process->m_psswp = 0; while ( ( nread = read(fd,buffer, sizeof(buffer)) ) > 0 ){ - start = (char *)&buffer; - end = start + nread; + char* start = buffer; + char* end = start + nread; do{//parse 4k block int tmp; diff --git a/linux/Platform.c b/linux/Platform.c index 43bf84b16..f6f7ba19f 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -103,7 +103,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) { void* set = Action_pickFromVector(st, ioprioPanel, 21, true); if (set) { IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio2 }, NULL); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, LinuxProcess_setIOPriority, (Arg){ .i = ioprio2 }, NULL); if (!ok) beep(); } From 059810ca65385d3feb3fc67857437bd740641c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 11:50:18 +0100 Subject: [PATCH 345/411] Drop always true condition --- darwin/Battery.c | 78 +++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/darwin/Battery.c b/darwin/Battery.c index 772f38864..d82d0ffd1 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -17,59 +17,57 @@ void Battery_getData(double* level, ACPresence* isOnAC) { return; } - if(power_sources != NULL) { - CFArrayRef list = IOPSCopyPowerSourcesList(power_sources); - CFDictionaryRef battery = NULL; - int len; + CFArrayRef list = IOPSCopyPowerSourcesList(power_sources); + CFDictionaryRef battery = NULL; + int len; - if(NULL == list) { - CFRelease(power_sources); + if(NULL == list) { + CFRelease(power_sources); - return; - } + return; + } - len = CFArrayGetCount(list); + len = CFArrayGetCount(list); - /* Get the battery */ - for(int i = 0; i < len && battery == NULL; ++i) { - CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, - CFArrayGetValueAtIndex(list, i)); /* GET rule */ - CFStringRef type; + /* Get the battery */ + for(int i = 0; i < len && battery == NULL; ++i) { + CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, + CFArrayGetValueAtIndex(list, i)); /* GET rule */ + CFStringRef type; - if(NULL != candidate) { - type = (CFStringRef) CFDictionaryGetValue(candidate, - CFSTR(kIOPSTransportTypeKey)); /* GET rule */ + if(NULL != candidate) { + type = (CFStringRef) CFDictionaryGetValue(candidate, + CFSTR(kIOPSTransportTypeKey)); /* GET rule */ - if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { - CFRetain(candidate); - battery = candidate; - } + if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { + CFRetain(candidate); + battery = candidate; } } + } - if(NULL != battery) { - /* Determine the AC state */ - CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); - - *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0)) - ? AC_PRESENT - : AC_ABSENT; + if(NULL != battery) { + /* Determine the AC state */ + CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); - /* Get the percentage remaining */ - double current; - double max; + *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0)) + ? AC_PRESENT + : AC_ABSENT; - CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)), - kCFNumberDoubleType, ¤t); - CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)), - kCFNumberDoubleType, &max); + /* Get the percentage remaining */ + double current; + double max; - *level = (current * 100.0) / max; + CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)), + kCFNumberDoubleType, ¤t); + CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)), + kCFNumberDoubleType, &max); - CFRelease(battery); - } + *level = (current * 100.0) / max; - CFRelease(list); - CFRelease(power_sources); + CFRelease(battery); } + + CFRelease(list); + CFRelease(power_sources); } From e89b2894949d6c103f49545b558744ef7712304d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 11:52:28 +0100 Subject: [PATCH 346/411] Drop duplicate assignment --- dragonflybsd/DragonFlyBSDProcessList.c | 1 - freebsd/FreeBSDProcessList.c | 1 - 2 files changed, 2 deletions(-) diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index d6eb38a5b..880df969a 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -437,7 +437,6 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { proc->m_size = kproc->kp_vm_map_size / 1024 / pageSizeKb; proc->m_resident = kproc->kp_vm_rssize; - proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(this->totalMem) * 100.0; proc->nlwp = kproc->kp_nthreads; // number of lwp thread proc->time = (kproc->kp_swtime + 5000) / 10000; diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 28cdf859e..7a034ac0d 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -451,7 +451,6 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { // from FreeBSD source /src/usr.bin/top/machine.c proc->m_size = kproc->ki_size / 1024 / pageSizeKb; proc->m_resident = kproc->ki_rssize; - proc->percent_mem = (proc->m_resident * pageSizeKb) / (double)(this->totalMem) * 100.0; proc->nlwp = kproc->ki_numthreads; proc->time = (kproc->ki_runtime + 5000) / 10000; From cf1a9ec18096029d0fa4635027622a63bcaa82df Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Tue, 27 Oct 2020 19:30:05 +0100 Subject: [PATCH 347/411] Refactor LinuxProcessList_readSmapsFile to work line-oriented --- linux/LinuxProcessList.c | 63 +++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index f7d015572..10c9d9828 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -479,54 +479,43 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di //http://elixir.free-electrons.com/linux/v4.10/source/fs/proc/task_mmu.c#L719 //kernel will return data in chunks of size PAGE_SIZE or less. - char buffer[CRT_pageSize];// 4k - ssize_t nread=0; + char buffer[256]; + if(haveSmapsRollup) {// only available in Linux 4.14+ xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps_rollup", dirname, name); } else { xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps", dirname, name); } - int fd = open(buffer, O_RDONLY); - if (fd == -1) + + FILE* f = fopen(buffer, "r"); + if (!f) return false; process->m_pss = 0; process->m_swap = 0; process->m_psswp = 0; - while ( ( nread = read(fd,buffer, sizeof(buffer)) ) > 0 ){ - char* start = buffer; - char* end = start + nread; - do{//parse 4k block - int tmp; - - if( (tmp = (end - start)) > 0 && - (start = memmem(start,tmp,"\nPss:",5)) != NULL ) - { - process->m_pss += strtol(start+5, &start, 10); - start += 3;//now we must be at the end of line "Pss: 0 kB" - }else - break; //read next 4k block - - if( (tmp = (end - start)) > 0 && - (start = memmem(start,tmp,"\nSwap:",6)) != NULL ) - { - process->m_swap += strtol(start+6, &start, 10); - start += 3; - }else - break; - - if( (tmp = (end - start)) > 0 && - (start = memmem(start,tmp,"\nSwapPss:",9)) != NULL ) - { - process->m_psswp += strtol(start+9, &start, 10); - start += 3; - }else - break; - - }while(1); - }//while read - close(fd); + while (fgets(buffer, sizeof(buffer), f)) { + if(!strchr(buffer, '\n')) { + // Partial line, skip to end of this line + while(fgets(buffer, sizeof(buffer), f)) { + if(strchr(buffer, '\n')) { + break; + } + } + continue; + } + + if (String_startsWith(buffer, "Pss:")) { + process->m_pss += strtol(buffer + 4, NULL, 10); + } else if (String_startsWith(buffer, "Swap:")) { + process->m_swap += strtol(buffer + 5, NULL, 10); + } else if (String_startsWith(buffer, "SwapPss:")) { + process->m_psswp += strtol(buffer + 8, NULL, 10); + } + } + + fclose(f); return true; } From 61bae4c9d27f23b3ebda461a922ae76e63e0a9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 21:26:28 +0100 Subject: [PATCH 348/411] Unify function argument names Name first argument of ProcessList_goThroughEntries consistently super Name first argument of ProcessList_new consistently userTable --- ProcessList.h | 4 ++-- dragonflybsd/DragonFlyBSDProcessList.c | 26 +++++++++++++------------- dragonflybsd/DragonFlyBSDProcessList.h | 2 +- freebsd/FreeBSDProcessList.c | 26 +++++++++++++------------- freebsd/FreeBSDProcessList.h | 2 +- openbsd/OpenBSDProcessList.c | 6 +++--- openbsd/OpenBSDProcessList.h | 2 +- solaris/SolarisProcessList.c | 12 ++++++------ solaris/SolarisProcessList.h | 2 +- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/ProcessList.h b/ProcessList.h index 4c09e4ceb..6b075fa7a 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -72,9 +72,9 @@ typedef struct ProcessList_ { } ProcessList; -ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidMatchList, uid_t userId); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* pl); -void ProcessList_goThroughEntries(ProcessList* pl, bool pauseProcessUpdate); +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 880df969a..8c441de5f 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -360,14 +360,14 @@ char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int ja return jname; } -void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { - DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this; - const Settings* settings = this->settings; +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { + DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) super; + const Settings* settings = super->settings; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; - DragonFlyBSDProcessList_scanMemoryInfo(this); - DragonFlyBSDProcessList_scanCPUTime(this); + DragonFlyBSDProcessList_scanMemoryInfo(super); + DragonFlyBSDProcessList_scanCPUTime(super); DragonFlyBSDProcessList_scanJails(dfpl); // in pause mode only gather global data for meters (CPU/memory/...) @@ -385,7 +385,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { bool ATTR_UNUSED isIdleProcess = false; // note: dragonflybsd kernel processes all have the same pid, so we misuse the kernel thread address to give them a unique identifier - Process* proc = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, DragonFlyBSDProcess_new); + Process* proc = ProcessList_getProcess(super, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, DragonFlyBSDProcess_new); DragonFlyBSDProcess* dfp = (DragonFlyBSDProcess*) proc; proc->show = ! ((hideKernelThreads && Process_isKernelThread(dfp)) || (hideUserlandThreads && Process_isUserlandThread(proc))); @@ -410,9 +410,9 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { proc->st_uid = kproc->kp_uid; // user ID proc->processor = kproc->kp_lwp.kl_origcpu; proc->starttime_ctime = kproc->kp_start.tv_sec; - proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); + proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); - ProcessList_add((ProcessList*)this, proc); + ProcessList_add(super, proc); proc->comm = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->basenameOffset); dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid); } else { @@ -427,7 +427,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { } if(proc->st_uid != kproc->kp_uid) { // some processes change users (eg. to lower privs) proc->st_uid = kproc->kp_uid; - proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); + proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); } if (settings->updateProcessNames) { free(proc->comm); @@ -441,7 +441,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { proc->time = (kproc->kp_swtime + 5000) / 10000; proc->percent_cpu = 100.0 * ((double)kproc->kp_lwp.kl_pctcpu / (double)kernelFScale); - proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(this->totalMem); + proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(super->totalMem); if (proc->percent_cpu > 0.1) { // system idle process should own all CPU time left regardless of CPU count @@ -523,12 +523,12 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { } if (Process_isKernelThread(dfp)) { - this->kernelThreads++; + super->kernelThreads++; } - this->totalTasks++; + super->totalTasks++; if (proc->state == 'R') - this->runningTasks++; + super->runningTasks++; proc->updated = true; } } diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index 0d0a128f6..f3965fd37 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -59,6 +59,6 @@ char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kpro char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid); -void ProcessList_goThroughEntries(ProcessList* this, pauseProcessUpdate); +void ProcessList_goThroughEntries(ProcessList* super, pauseProcessUpdate); #endif diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 7a034ac0d..ef06f9b43 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -380,15 +380,15 @@ IGNORE_WCASTQUAL_END return jname; } -void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { - FreeBSDProcessList* fpl = (FreeBSDProcessList*) this; - const Settings* settings = this->settings; +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { + FreeBSDProcessList* fpl = (FreeBSDProcessList*) super; + const Settings* settings = super->settings; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; openzfs_sysctl_updateArcStats(&fpl->zfs); - FreeBSDProcessList_scanMemoryInfo(this); - FreeBSDProcessList_scanCPUTime(this); + FreeBSDProcessList_scanMemoryInfo(super); + FreeBSDProcessList_scanCPUTime(super); // in pause mode only gather global data for meters (CPU/memory/...) if (pauseProcessUpdate) @@ -401,7 +401,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { struct kinfo_proc* kproc = &kprocs[i]; bool preExisting = false; // TODO: bool isIdleProcess = false; - Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, FreeBSDProcess_new); + Process* proc = ProcessList_getProcess(super, kproc->ki_pid, &preExisting, FreeBSDProcess_new); FreeBSDProcess* fp = (FreeBSDProcess*) proc; proc->show = ! ((hideKernelThreads && Process_isKernelThread(fp)) || (hideUserlandThreads && Process_isUserlandThread(proc))); @@ -422,8 +422,8 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { proc->st_uid = kproc->ki_uid; proc->starttime_ctime = kproc->ki_start.tv_sec; Process_fillStarttimeBuffer(proc); - proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); - ProcessList_add((ProcessList*)this, proc); + proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); + ProcessList_add(super, proc); proc->comm = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->basenameOffset); fp->jname = FreeBSDProcessList_readJailName(kproc); } else { @@ -440,7 +440,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { if(proc->st_uid != kproc->ki_uid) { // some processes change users (eg. to lower privs) proc->st_uid = kproc->ki_uid; - proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); + proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); } if (settings->updateProcessNames) { free(proc->comm); @@ -455,7 +455,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { proc->time = (kproc->ki_runtime + 5000) / 10000; proc->percent_cpu = 100.0 * ((double)kproc->ki_pctcpu / (double)kernelFScale); - proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(this->totalMem); + proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(super->totalMem); /* * TODO @@ -491,12 +491,12 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { } if (Process_isKernelThread(fp)) { - this->kernelThreads++; + super->kernelThreads++; } - this->totalTasks++; + super->totalTasks++; if (proc->state == 'R') - this->runningTasks++; + super->runningTasks++; proc->updated = true; } } diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 60d23f8dc..5fa49924e 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -62,6 +62,6 @@ char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc); -void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate); +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); #endif diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 320b693b4..86e2dca61 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -340,10 +340,10 @@ static void OpenBSDProcessList_scanCPUTime(OpenBSDProcessList* this) { kernelCPUTimesToHtop(avg, this->cpus); } -void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { - OpenBSDProcessList* opl = (OpenBSDProcessList*) this; +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { + OpenBSDProcessList* opl = (OpenBSDProcessList*) super; - OpenBSDProcessList_scanMemoryInfo(this); + OpenBSDProcessList_scanMemoryInfo(super); OpenBSDProcessList_scanCPUTime(opl); // in pause mode only gather global data for meters (CPU/memory/...) diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index 3c3f1a334..7ee48c636 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -45,6 +45,6 @@ void ProcessList_delete(ProcessList* this); char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); -void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate); +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); #endif diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 72806134d..2af82aaba 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -377,15 +377,15 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * return 0; } -void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) { - SolarisProcessList_scanCPUTime(this); - SolarisProcessList_scanMemoryInfo(this); - SolarisProcessList_scanZfsArcstats(this); +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { + SolarisProcessList_scanCPUTime(super); + SolarisProcessList_scanMemoryInfo(super); + SolarisProcessList_scanZfsArcstats(super); // in pause mode only gather global data for meters (CPU/memory/...) if (pauseProcessUpdate) return; - this->kernelThreads = 1; - proc_walk(&SolarisProcessList_walkproc, this, PR_WALK_LWP); + super->kernelThreads = 1; + proc_walk(&SolarisProcessList_walkproc, super, PR_WALK_LWP); } diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index 1e6e5b8ae..3a653eed6 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -60,6 +60,6 @@ void ProcessList_delete(ProcessList* pl); int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr); -void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate); +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); #endif From 8c1f5c5a6f341fc654808887fcbeec0ba2994f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 21:26:33 +0100 Subject: [PATCH 349/411] Enclose macro arguments in parentheses --- Panel.h | 8 ++++---- RichString.h | 6 +++--- linux/IOPriority.h | 2 +- linux/LinuxProcessList.c | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Panel.h b/Panel.h index 878460754..ec670ab54 100644 --- a/Panel.h +++ b/Panel.h @@ -27,11 +27,11 @@ typedef enum HandlerResult_ { SYNTH_KEY = 0x20, } HandlerResult; -#define EVENT_SET_SELECTED -1 +#define EVENT_SET_SELECTED (-1) -#define EVENT_HEADER_CLICK(x_) (-10000 + x_) -#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ <= -9000) -#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000) +#define EVENT_HEADER_CLICK(x_) (-10000 + (x_)) +#define EVENT_IS_HEADER_CLICK(ev_) ((ev_) >= -10000 && (ev_) <= -9000) +#define EVENT_HEADER_CLICK_GET_X(ev_) ((ev_) + 10000) typedef HandlerResult(*Panel_EventHandler)(Panel*, int); diff --git a/RichString.h b/RichString.h index 2e35b827c..1320c9381 100644 --- a/RichString.h +++ b/RichString.h @@ -15,13 +15,13 @@ in the source distribution for its full text. #define RichString_size(this) ((this)->chlen) #define RichString_sizeVal(this) ((this).chlen) -#define RichString_begin(this) RichString (this); memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr; -#define RichString_beginAllocated(this) memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr; +#define RichString_begin(this) RichString (this); memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr; +#define RichString_beginAllocated(this) memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr; #define RichString_end(this) RichString_prune(&(this)); #ifdef HAVE_LIBNCURSESW #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) -#define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + off, n) +#define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255) #define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) #define CharType cchar_t diff --git a/linux/IOPriority.h b/linux/IOPriority.h index e60eb9bae..551a7d501 100644 --- a/linux/IOPriority.h +++ b/linux/IOPriority.h @@ -28,7 +28,7 @@ enum { typedef int IOPriority; -#define IOPriority_tuple(class_, data_) (((class_) << IOPRIO_CLASS_SHIFT) | data_) +#define IOPriority_tuple(class_, data_) (((class_) << IOPRIO_CLASS_SHIFT) | (data_)) #define IOPriority_error 0xffffffff diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 10c9d9828..2530b2bb2 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1161,7 +1161,7 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { char buffer[128]; while (fgets(buffer, 128, file)) { #define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { break; } } while(0) - #define tryReadFlag(label, variable, flag) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { flag = 1; break; } else { flag = 0; } } while(0) + #define tryReadFlag(label, variable, flag) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { (flag) = 1; break; } else { (flag) = 0; } } while(0) switch (buffer[0]) { case 'c': tryRead("c_max", &lpl->zfs.max); @@ -1248,7 +1248,7 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { // Since we do a subtraction (usertime - guest) and cputime64_to_clock_t() // used in /proc/stat rounds down numbers, it can lead to a case where the // integer overflow. - #define WRAP_SUBTRACT(a,b) (a > b) ? a - b : 0 + #define WRAP_SUBTRACT(a,b) (((a) > (b)) ? (a) - (b) : 0) cpuData->userPeriod = WRAP_SUBTRACT(usertime, cpuData->userTime); cpuData->nicePeriod = WRAP_SUBTRACT(nicetime, cpuData->niceTime); cpuData->systemPeriod = WRAP_SUBTRACT(systemtime, cpuData->systemTime); From 70199495747543c97a05ca2d692780107e528ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 21:26:35 +0100 Subject: [PATCH 350/411] Implement RichString_setLen as function Make it more readable and fix unenclosed macro arguments --- RichString.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/RichString.c b/RichString.c index 90cc428c9..bda39181e 100644 --- a/RichString.c +++ b/RichString.c @@ -36,7 +36,14 @@ static void RichString_extendLen(RichString* this, int len) { this->chlen = len; } -#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0) +static void RichString_setLen(RichString* this, int len) { + if (len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { + RichString_setChar(this, len, 0); + this->chlen = len; + } else { + RichString_extendLen(this, len); + } +} #ifdef HAVE_LIBNCURSESW From 6b3dbd5c67f5f3a03c712682f603e646afa2f621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 21:26:37 +0100 Subject: [PATCH 351/411] Implement IncSet_filter as function Make it more readable and fix unenclosed macro arguments --- IncSet.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/IncSet.h b/IncSet.h index 10b3625c7..a6c1974ef 100644 --- a/IncSet.h +++ b/IncSet.h @@ -21,8 +21,6 @@ typedef enum { INC_FILTER = 1 } IncType; -#define IncSet_filter(inc_) (inc_->filtering ? inc_->modes[INC_FILTER].buffer : NULL) - typedef struct IncMode_ { char buffer[INCMODE_MAX+1]; int index; @@ -38,6 +36,10 @@ typedef struct IncSet_ { bool found; } IncSet; +static inline const char* IncSet_filter(const IncSet* this) { + return this->filtering ? this->modes[INC_FILTER].buffer : NULL; +} + typedef const char* (*IncMode_GetPanelValue)(Panel*, int); void IncSet_reset(IncSet* this, IncType type); From d33b2be2ca445badb3c3004b618c8e7c79677f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 21:26:39 +0100 Subject: [PATCH 352/411] Implement LinuxProcess_effectiveIOPriority as function Make it more readable and fix unenclosed macro arguments --- linux/LinuxProcess.c | 7 ++++++- linux/LinuxProcess.h | 10 ---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index fad805559..d607a71b2 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -167,7 +167,12 @@ effort class. The priority within the best effort class will be dynamically derived from the cpu nice level of the process: io_priority = (cpu_nice + 20) / 5. -- From ionice(1) man page */ -#define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->super.nice + 20) / 5) : p_->ioPriority) +static int LinuxProcess_effectiveIOPriority(const LinuxProcess* this) { + if (IOPriority_class(this->ioPriority) == IOPRIO_CLASS_NONE) + return IOPriority_tuple(IOPRIO_CLASS_BE, (this->super.nice + 20) / 5); + + return this->ioPriority; +} IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this) { IOPriority ioprio = 0; diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 80a4220b3..02e4af7ef 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -171,16 +171,6 @@ Process* LinuxProcess_new(const Settings* settings); void Process_delete(Object* cast); -/* -[1] Note that before kernel 2.6.26 a process that has not asked for -an io priority formally uses "none" as scheduling class, but the -io scheduler will treat such processes as if it were in the best -effort class. The priority within the best effort class will be -dynamically derived from the cpu nice level of the process: -extern io_priority; -*/ -#define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->super.nice + 20) / 5) : p_->ioPriority) - IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this); bool LinuxProcess_setIOPriority(Process* this, Arg ioprio); From 76797f8d928a9278f7356e270ef07cea1db5510a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 21:26:41 +0100 Subject: [PATCH 353/411] Implement Process_isUserlandThread as function Make it more readable and fix unenclosed macro arguments --- linux/LinuxProcess.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 02e4af7ef..3f9783469 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -157,7 +157,9 @@ typedef struct LinuxProcess_ { #define Process_isKernelThread(_process) (((const LinuxProcess*)(_process))->isKernelThread) -#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) +static inline bool Process_isUserlandThread(const Process* this) { + return this->pid != this->tgid; +} extern long long btime; From 887dfde3082bcb1057a965d365206b2ed3d0263b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 27 Oct 2020 21:26:45 +0100 Subject: [PATCH 354/411] Implement Process_getParentPid and Process_isChildOf as functions Make it more readable and fix unenclosed macro arguments --- Process.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Process.h b/Process.h index 2432918fd..b2c820808 100644 --- a/Process.h +++ b/Process.h @@ -129,9 +129,13 @@ typedef struct ProcessClass_ { #define As_Process(this_) ((const ProcessClass*)((this_)->super.klass)) -#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid) +static inline pid_t Process_getParentPid(const Process* this) { + return this->tgid == this->pid ? this->ppid : this->tgid; +} -#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_)) +static inline bool Process_isChildOf(const Process* this, pid_t pid) { + return pid == Process_getParentPid(this); +} #define Process_sortState(state) ((state) == 'I' ? 0x100 : (state)) From 6375df49c9ceabc87066bd53eadf1ababb11c902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 28 Oct 2020 18:00:50 +0100 Subject: [PATCH 355/411] Simplify RichString_begin --- RichString.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RichString.h b/RichString.h index 1320c9381..48c1e7491 100644 --- a/RichString.h +++ b/RichString.h @@ -15,7 +15,7 @@ in the source distribution for its full text. #define RichString_size(this) ((this)->chlen) #define RichString_sizeVal(this) ((this).chlen) -#define RichString_begin(this) RichString (this); memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr; +#define RichString_begin(this) RichString (this); RichString_beginAllocated(this); #define RichString_beginAllocated(this) memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr; #define RichString_end(this) RichString_prune(&(this)); From 03b773b701e8d2502449396214751131abd0dda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 18 Oct 2020 19:22:30 +0200 Subject: [PATCH 356/411] Small ListItem update --- ListItem.c | 32 ++++++++++++-------------------- ListItem.h | 6 +++--- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/ListItem.c b/ListItem.c index 866f20ff2..031c4f72f 100644 --- a/ListItem.c +++ b/ListItem.c @@ -27,11 +27,7 @@ static void ListItem_delete(Object* cast) { static void ListItem_display(const Object* cast, RichString* out) { const ListItem* const this = (const ListItem*)cast; assert (this != NULL); - /* - int len = strlen(this->value)+1; - char buffer[len+1]; - xSnprintf(buffer, len, "%s", this->value); - */ + if (this->moving) { RichString_write(out, CRT_colors[DEFAULT_COLOR], #ifdef HAVE_LIBNCURSESW @@ -41,15 +37,9 @@ static void ListItem_display(const Object* cast, RichString* out) { } else { RichString_prune(out); } - RichString_append(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/); + RichString_append(out, CRT_colors[DEFAULT_COLOR], this->value); } -const ObjectClass ListItem_class = { - .display = ListItem_display, - .delete = ListItem_delete, - .compare = ListItem_compare -}; - ListItem* ListItem_new(const char* value, int key) { ListItem* this = AllocThis(ListItem); this->value = xStrdup(value); @@ -59,20 +49,22 @@ ListItem* ListItem_new(const char* value, int key) { } void ListItem_append(ListItem* this, const char* text) { - int oldLen = strlen(this->value); - int textLen = strlen(text); - int newLen = strlen(this->value) + textLen; + size_t oldLen = strlen(this->value); + size_t textLen = strlen(text); + size_t newLen = oldLen + textLen; this->value = xRealloc(this->value, newLen + 1); memcpy(this->value + oldLen, text, textLen); this->value[newLen] = '\0'; } -const char* ListItem_getRef(ListItem* this) { - return this->value; -} - -long ListItem_compare(const void* cast1, const void* cast2) { +static long ListItem_compare(const void* cast1, const void* cast2) { const ListItem* obj1 = (const ListItem*) cast1; const ListItem* obj2 = (const ListItem*) cast2; return strcmp(obj1->value, obj2->value); } + +const ObjectClass ListItem_class = { + .display = ListItem_display, + .delete = ListItem_delete, + .compare = ListItem_compare +}; diff --git a/ListItem.h b/ListItem.h index 5bbcda14f..87a7c073f 100644 --- a/ListItem.h +++ b/ListItem.h @@ -24,8 +24,8 @@ ListItem* ListItem_new(const char* value, int key); void ListItem_append(ListItem* this, const char* text); -const char* ListItem_getRef(ListItem* this); - -long ListItem_compare(const void* cast1, const void* cast2); +static inline const char* ListItem_getRef(const ListItem* this) { + return this->value; +} #endif From ddbb0c2c35ca1070387b975e85f4fd12f4aaf93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 29 Oct 2020 21:50:38 +0100 Subject: [PATCH 357/411] Add HTOP_$platform defines to config.h header Can be used to conditionally compile platform specific code. --- configure.ac | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure.ac b/configure.ac index b10d819ad..bc8592d0b 100644 --- a/configure.ac +++ b/configure.ac @@ -26,24 +26,31 @@ AC_USE_SYSTEM_EXTENSIONS case "$target_os" in linux*|gnu*) my_htop_platform=linux + AC_DEFINE([HTOP_LINUX], [], [Building for Linux]) ;; freebsd*|kfreebsd*) my_htop_platform=freebsd + AC_DEFINE([HTOP_FREEBSD], [], [Building for FreeBSD]) ;; openbsd*) my_htop_platform=openbsd + AC_DEFINE([HTOP_OPENBSD], [], [Building for OpenBSD]) ;; dragonfly*) my_htop_platform=dragonflybsd + AC_DEFINE([HTOP_DRAGONFLYBSD], [], [Building for DragonFlyBSD]) ;; darwin*) my_htop_platform=darwin + AC_DEFINE([HTOP_DARWIN], [], [Building for Darwin]) ;; solaris*) my_htop_platform=solaris + AC_DEFINE([HTOP_SOLARIS], [], [Building for Solaris]) ;; *) my_htop_platform=unsupported + AC_DEFINE([HTOP_UNSUPPORTED], [], [Building for an unsupported platform]) ;; esac From 88eec2dc00f951913a1992a064ccefc7cff95e96 Mon Sep 17 00:00:00 2001 From: Christian Goettsche Date: Wed, 21 Oct 2020 13:56:26 +0200 Subject: [PATCH 358/411] FreeBSD: rework tty process column --- freebsd/FreeBSDProcess.c | 16 +++++++- freebsd/FreeBSDProcess.h | 5 +++ freebsd/FreeBSDProcessList.c | 79 +++++++++++++++++++++++++++++++++++- freebsd/FreeBSDProcessList.h | 2 + 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index ea3f693dd..616a7196c 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -17,6 +17,8 @@ in the source distribution for its full text. #include +const char* const nodevStr = "nodev"; + const ProcessClass FreeBSDProcess_class = { .super = { .extends = Class(Process), @@ -35,7 +37,7 @@ ProcessFieldData Process_fields[] = { [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, }, [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, }, [SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, }, - [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, }, + [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = PROCESS_FLAG_FREEBSD_TTY, }, [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, }, [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, }, [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, }, @@ -99,6 +101,16 @@ void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessFiel } break; } + case TTY_NR: + if (fp->ttyPath) { + if (fp->ttyPath == nodevStr) + attr = CRT_colors[PROCESS_SHADOW]; + xSnprintf(buffer, n, "%-8s", fp->ttyPath); + } else { + attr = CRT_colors[PROCESS_SHADOW]; + xSnprintf(buffer, n, "? "); + } + break; default: Process_writeField(this, str, field); return; @@ -122,6 +134,8 @@ long FreeBSDProcess_compare(const void* v1, const void* v2) { return (p1->jid - p2->jid); case JAIL: return strcmp(p1->jname ? p1->jname : "", p2->jname ? p2->jname : ""); + case TTY_NR: + return strcmp(p1->ttyPath ? p1->ttyPath : "", p2->ttyPath ? p2->ttyPath : ""); default: return Process_compare(v1, v2); } diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index aa769d653..d6873d099 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -15,6 +15,10 @@ in the source distribution for its full text. #include "Settings.h" +#define PROCESS_FLAG_FREEBSD_TTY 0x0100 + +extern const char* const nodevStr; + typedef enum FreeBSDProcessFields_ { // Add platform-specific fields here, with ids >= 100 JID = 100, @@ -27,6 +31,7 @@ typedef struct FreeBSDProcess_ { int kernel; int jid; char* jname; + const char* ttyPath; } FreeBSDProcess; #define Process_isKernelThread(_process) (_process->kernel == 1) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index ef06f9b43..69b4aba24 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -8,6 +8,7 @@ in the source distribution for its full text. #include "FreeBSDProcessList.h" #include +#include #include #include #include @@ -16,8 +17,10 @@ in the source distribution for its full text. #include #include #include +#include #include #include +#include #include "CRT.h" #include "FreeBSDProcess.h" @@ -138,11 +141,16 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui errx(1, "kvm_open: %s", errbuf); } + fpl->ttys = Hashtable_new(20, true); + return pl; } void ProcessList_delete(ProcessList* this) { const FreeBSDProcessList* fpl = (FreeBSDProcessList*) this; + + Hashtable_delete(fpl->ttys); + if (fpl->kd) kvm_close(fpl->kd); free(fpl->cp_time_o); @@ -311,6 +319,70 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { pl->sharedMem = 0; // currently unused } +static void FreeBSDProcessList_scanTTYs(ProcessList* pl) { + FreeBSDProcessList* fpl = (FreeBSDProcessList*) pl; + + // scan /dev/tty* + { + DIR* dirPtr = opendir("/dev"); + if (!dirPtr) + return; + + int dirFd = dirfd(dirPtr); + if (dirFd < 0) + goto err1; + + const struct dirent* entry; + while ((entry = readdir(dirPtr))) { + if (!String_startsWith(entry->d_name, "tty")) + continue; + + struct stat info; + if (fstatat(dirFd, entry->d_name, &info, 0) < 0) + continue; + + if (!S_ISCHR(info.st_mode)) + continue; + + if (!Hashtable_get(fpl->ttys, info.st_rdev)) + Hashtable_put(fpl->ttys, info.st_rdev, xStrdup(entry->d_name)); + } + +err1: + closedir(dirPtr); + } + + // scan /dev/pts/* + { + DIR* dirPtr = opendir("/dev/pts"); + if (!dirPtr) + return; + + int dirFd = dirfd(dirPtr); + if (dirFd < 0) + goto err2; + + const struct dirent* entry; + while ((entry = readdir(dirPtr))) { + struct stat info; + if (fstatat(dirFd, entry->d_name, &info, 0) < 0) + continue; + + if (!S_ISCHR(info.st_mode)) + continue; + + if (!Hashtable_get(fpl->ttys, info.st_rdev)) { + char* path; + xAsprintf(&path, "pts/%s", entry->d_name); + Hashtable_put(fpl->ttys, info.st_rdev, path); + } + } + +err2: + closedir(dirPtr); + } +} + char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { char** argv = kvm_getargv(kd, kproc, 0); if (!argv) { @@ -394,6 +466,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (pauseProcessUpdate) return; + if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) + FreeBSDProcessList_scanTTYs(super); + int count = 0; struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count); @@ -417,7 +492,6 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { proc->tpgid = kproc->ki_tpgid; proc->tgid = kproc->ki_pid; proc->session = kproc->ki_sid; - proc->tty_nr = kproc->ki_tdev; proc->pgrp = kproc->ki_pgid; proc->st_uid = kproc->ki_uid; proc->starttime_ctime = kproc->ki_start.tv_sec; @@ -490,6 +564,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { default: proc->state = '?'; } + if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) + fp->ttyPath = (kproc->ki_tdev == NODEV) ? nodevStr : Hashtable_get(fpl->ttys, kproc->ki_tdev); + if (Process_isKernelThread(fp)) { super->kernelThreads++; } diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 5fa49924e..819804150 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -46,6 +46,8 @@ typedef struct FreeBSDProcessList_ { CPUData* cpus; + Hashtable* ttys; + unsigned long *cp_time_o; unsigned long *cp_time_n; From c91061c84bcce51934f05df7a7ee4d219f01bc71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 16:19:22 +0200 Subject: [PATCH 359/411] FreeBSD: Platform update --- freebsd/Platform.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 0a27f7c48..b23a8624e 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -6,34 +6,34 @@ in the source distribution for its full text. */ #include "Platform.h" -#include "Macros.h" -#include "Meter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "CPUMeter.h" -#include "MemoryMeter.h" -#include "SwapMeter.h" -#include "TasksMeter.h" -#include "LoadAverageMeter.h" -#include "UptimeMeter.h" #include "ClockMeter.h" #include "DateMeter.h" #include "DateTimeMeter.h" +#include "FreeBSDProcess.h" +#include "FreeBSDProcessList.h" #include "HostnameMeter.h" +#include "LoadAverageMeter.h" +#include "Macros.h" +#include "MemoryMeter.h" +#include "Meter.h" #include "NetworkIOMeter.h" +#include "SwapMeter.h" +#include "TasksMeter.h" +#include "UptimeMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" -#include "FreeBSDProcess.h" -#include "FreeBSDProcessList.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; @@ -185,7 +185,6 @@ double Platform_setCPUValues(Meter* this, int cpu) { } percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) percent = 0.0; v[CPU_METER_FREQUENCY] = NAN; From c2fdfd99eb5bffee0f6d1e1838fb4708eac18425 Mon Sep 17 00:00:00 2001 From: Christian Goettsche Date: Wed, 21 Oct 2020 17:06:32 +0200 Subject: [PATCH 360/411] FreeBSD: implement Platform_getDiskIO() --- DiskIOMeter.c | 17 ++++++++------- DiskIOMeter.h | 6 ++++++ configure.ac | 3 +++ darwin/Platform.c | 6 ++---- darwin/Platform.h | 5 ++--- dragonflybsd/Platform.c | 6 ++---- dragonflybsd/Platform.h | 5 ++--- freebsd/Platform.c | 47 +++++++++++++++++++++++++++++++++++------ freebsd/Platform.h | 5 ++--- linux/Platform.c | 8 +++---- linux/Platform.h | 5 ++--- openbsd/Platform.c | 6 ++---- openbsd/Platform.h | 5 ++--- solaris/Platform.c | 6 ++---- solaris/Platform.h | 5 ++--- unsupported/Platform.c | 6 ++---- unsupported/Platform.h | 5 ++--- 17 files changed, 87 insertions(+), 59 deletions(-) diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 9f311653b..21696a339 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -44,23 +44,24 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) { if (passedTimeInMs > 500) { cached_last_update = timeInMilliSeconds; - unsigned long int bytesRead, bytesWrite, msTimeSpend; + DiskIOData data; - hasData = Platform_getDiskIO(&bytesRead, &bytesWrite, &msTimeSpend); + hasData = Platform_getDiskIO(&data); if (!hasData) { this->values[0] = 0; xSnprintf(buffer, len, "no data"); return; } - cached_read_diff = (bytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ - cached_read_total = bytesRead; + cached_read_diff = (data.totalBytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + cached_read_total = data.totalBytesRead; - cached_write_diff = (bytesWrite - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ - cached_write_total = bytesWrite; + cached_write_diff = (data.totalBytesWritten - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + cached_write_total = data.totalBytesWritten; - cached_utilisation_diff = 100 * (double)(msTimeSpend - cached_msTimeSpend_total) / passedTimeInMs; - cached_msTimeSpend_total = msTimeSpend; + cached_utilisation_diff = 100 * (double)(data.totalMsTimeSpend - cached_msTimeSpend_total) / passedTimeInMs; + + cached_msTimeSpend_total = data.totalMsTimeSpend; } this->values[0] = cached_utilisation_diff; diff --git a/DiskIOMeter.h b/DiskIOMeter.h index c7e4542ae..9fca35b1c 100644 --- a/DiskIOMeter.h +++ b/DiskIOMeter.h @@ -9,6 +9,12 @@ in the source distribution for its full text. #include "Meter.h" +typedef struct DiskIOData_ { + unsigned long int totalBytesRead; + unsigned long int totalBytesWritten; + unsigned long int totalMsTimeSpend; +} DiskIOData; + extern const MeterClass DiskIOMeter_class; #endif /* HEADER_DiskIOMeter */ diff --git a/configure.ac b/configure.ac index bc8592d0b..70289a789 100644 --- a/configure.ac +++ b/configure.ac @@ -102,6 +102,9 @@ CFLAGS="$save_cflags" # Add -lexecinfo if needed AC_SEARCH_LIBS([backtrace], [execinfo]) +# Add -ldevstat if needed +AC_SEARCH_LIBS([devstat_checkversion], [devstat]) + # Checks for features and flags. # ---------------------------------------------------------------------- PROCDIR=/proc diff --git a/darwin/Platform.c b/darwin/Platform.c index 965da0a15..b1f9283d8 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -311,11 +311,9 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(DiskIOData* data) { // TODO - *bytesRead = *bytesWrite = *msTimeSpend = 0; + (void)data; return false; } diff --git a/darwin/Platform.h b/darwin/Platform.h index bdfe226d2..471b38a9a 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -11,6 +11,7 @@ in the source distribution for its full text. #include "Action.h" #include "SignalsPanel.h" #include "CPUMeter.h" +#include "DiskIOMeter.h" #include "BatteryMeter.h" #include "DarwinProcess.h" @@ -48,9 +49,7 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend); +bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 3eac7debc..5b81c610f 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -206,11 +206,9 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; } -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(DiskIOData* data) { // TODO - *bytesRead = *bytesWrite = *msTimeSpend = 0; + (void)data; return false; } diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 7ea211cad..6c8847191 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" +#include "DiskIOMeter.h" #include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -40,9 +41,7 @@ void Platform_setSwapValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend); +bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, diff --git a/freebsd/Platform.c b/freebsd/Platform.c index b23a8624e..bdd49bf6c 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -7,6 +7,7 @@ in the source distribution for its full text. #include "Platform.h" +#include #include #include #include @@ -21,6 +22,7 @@ in the source distribution for its full text. #include "ClockMeter.h" #include "DateMeter.h" #include "DateTimeMeter.h" +#include "DiskIOMeter.h" #include "FreeBSDProcess.h" #include "FreeBSDProcessList.h" #include "HostnameMeter.h" @@ -111,6 +113,7 @@ const MeterClass* const Platform_meterTypes[] = { &BlankMeter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, + &DiskIOMeter_class, &NetworkIOMeter_class, NULL }; @@ -240,12 +243,44 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend) { - // TODO - *bytesRead = *bytesWrite = *msTimeSpend = 0; - return false; +bool Platform_getDiskIO(DiskIOData* data) { + + if (devstat_checkversion(NULL) < 0) + return false; + + struct devinfo info = { 0 }; + struct statinfo current = { .dinfo = &info }; + + // get number of devices + if (devstat_getdevs(NULL, ¤t) < 0) + return false; + + int count = current.dinfo->numdevs; + + unsigned long int bytesReadSum = 0, bytesWriteSum = 0, timeSpendSum = 0; + + // get data + for (int i = 0; i < count; i++) { + uint64_t bytes_read, bytes_write; + long double busy_time; + + devstat_compute_statistics(¤t.dinfo->devices[i], + NULL, + 1.0, + DSM_TOTAL_BYTES_READ, &bytes_read, + DSM_TOTAL_BYTES_WRITE, &bytes_write, + DSM_TOTAL_BUSY_TIME, &busy_time, + DSM_NONE); + + bytesReadSum += bytes_read; + bytesWriteSum += bytes_write; + timeSpendSum += 1000 * busy_time; + } + + data->totalBytesRead = bytesReadSum; + data->totalBytesWritten = bytesWriteSum; + data->totalMsTimeSpend = timeSpendSum; + return true; } bool Platform_getNetworkIO(unsigned long int *bytesReceived, diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 40fb2d975..894b3e252 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -9,6 +9,7 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" +#include "DiskIOMeter.h" #include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -43,9 +44,7 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend); +bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, diff --git a/linux/Platform.c b/linux/Platform.c index f6f7ba19f..fe9764bab 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -313,7 +313,7 @@ void Platform_getPressureStall(const char *file, bool some, double* ten, double* fclose(fd); } -bool Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(DiskIOData* data) { FILE *fd = fopen(PROCDIR "/diskstats", "r"); if (!fd) return false; @@ -352,9 +352,9 @@ bool Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWr } fclose(fd); /* multiply with sector size */ - *bytesRead = 512 * read_sum; - *bytesWrite = 512 * write_sum; - *msTimeSpend = timeSpend_sum; + data->totalBytesRead = 512 * read_sum; + data->totalBytesWritten = 512 * write_sum; + data->totalMsTimeSpend = timeSpend_sum; return true; } diff --git a/linux/Platform.h b/linux/Platform.h index 3c3986e6f..62402432e 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -11,6 +11,7 @@ in the source distribution for its full text. #include #include "Action.h" +#include "DiskIOMeter.h" #include "Meter.h" #include "Process.h" #include "SignalsPanel.h" @@ -46,9 +47,7 @@ char* Platform_getProcessEnv(pid_t pid); void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend); +bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 9f7cd7378..df6bc0cc1 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -288,11 +288,9 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(DiskIOData* data) { // TODO - *bytesRead = *bytesWrite = *msTimeSpend = 0; + (void)data; return false; } diff --git a/openbsd/Platform.h b/openbsd/Platform.h index b75d87b28..8cb5bdf33 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" +#include "DiskIOMeter.h" #include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -41,9 +42,7 @@ void Platform_setSwapValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend); +bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, diff --git a/solaris/Platform.c b/solaris/Platform.c index 2fa2e1de5..87247969e 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -264,11 +264,9 @@ char* Platform_getProcessEnv(pid_t pid) { return envBuilder.env; } -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend) { +bool Platform_getDiskIO(DiskIOData* data) { // TODO - *bytesRead = *bytesWrite = *msTimeSpend = 0; + (void)data; return false; } diff --git a/solaris/Platform.h b/solaris/Platform.h index f95515c61..8718dbfee 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -11,6 +11,7 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" +#include "DiskIOMeter.h" #include "SignalsPanel.h" #include #include @@ -63,9 +64,7 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend); +bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, diff --git a/unsupported/Platform.c b/unsupported/Platform.c index e2d7fa6b2..3f8cefa68 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -141,10 +141,8 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; } -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend) { - *bytesRead = *bytesWrite = *msTimeSpend = 0; +bool Platform_getDiskIO(DiskIOData* data) { + (void)data; return false; } diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 1558d66a2..902b6a9b7 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" +#include "DiskIOMeter.h" #include "SignalsPanel.h" #include "UnsupportedProcess.h" @@ -47,9 +48,7 @@ bool Process_isThread(const Process* this); char* Platform_getProcessEnv(pid_t pid); -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend); +bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, From 97ea45ca9a4ee639681e3048be4813b56c969bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 19:11:19 +0200 Subject: [PATCH 361/411] FreeBSD: update ProcessList --- freebsd/FreeBSDProcessList.c | 12 ++++++------ freebsd/FreeBSDProcessList.h | 8 ++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 69b4aba24..caa04ccd8 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -16,19 +16,19 @@ in the source distribution for its full text. #include #include #include -#include +#include #include #include +#include #include -#include #include "CRT.h" #include "FreeBSDProcess.h" #include "Macros.h" #include "ProcessList.h" +#include "XUtils.h" #include "zfs/ZfsArcStats.h" #include "zfs/openzfs_sysctl.h" -#include "XUtils.h" char jail_errmsg[JAIL_ERRMSGLEN]; @@ -383,7 +383,7 @@ static void FreeBSDProcessList_scanTTYs(ProcessList* pl) { } } -char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { +static char* FreeBSDProcessList_readProcessName(kvm_t* kd, const struct kinfo_proc* kproc, int* basenameEnd) { char** argv = kvm_getargv(kd, kproc, 0); if (!argv) { return xStrdup(kproc->ki_comm); @@ -408,7 +408,7 @@ char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in return comm; } -char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) { +static char* FreeBSDProcessList_readJailName(const struct kinfo_proc* kproc) { int jid; struct iovec jiov[6]; char* jname; @@ -419,7 +419,7 @@ char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) { IGNORE_WCASTQUAL_BEGIN *(const void **)&jiov[0].iov_base = "jid"; jiov[0].iov_len = sizeof("jid"); - jiov[1].iov_base = &kproc->ki_jid; + jiov[1].iov_base = (void*) &kproc->ki_jid; jiov[1].iov_len = sizeof(kproc->ki_jid); *(const void **)&jiov[2].iov_base = "name"; jiov[2].iov_len = sizeof("name"); diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 819804150..e97444bd8 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -8,10 +8,10 @@ in the source distribution for its full text. */ #include -#include +#include // needs to be included before for MAXPATHLEN #include -#include #include +#include #include "FreeBSDProcess.h" #include "Hashtable.h" @@ -60,10 +60,6 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this); -char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); - -char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc); - void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); #endif From 049046c700ea42e8f9bb77f5efbb5a66ed3c4651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 19:11:26 +0200 Subject: [PATCH 362/411] FreeBSD: update Process --- freebsd/FreeBSDProcess.c | 26 +++++++++++++------------- freebsd/FreeBSDProcess.h | 12 ++++++------ freebsd/FreeBSDProcessList.c | 5 ++--- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 616a7196c..fee2c2c8d 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -19,16 +19,6 @@ in the source distribution for its full text. const char* const nodevStr = "nodev"; -const ProcessClass FreeBSDProcess_class = { - .super = { - .extends = Class(Process), - .display = Process_display, - .delete = Process_delete, - .compare = FreeBSDProcess_compare - }, - .writeField = FreeBSDProcess_writeField, -}; - ProcessFieldData Process_fields[] = { [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, }, @@ -85,7 +75,7 @@ void Process_delete(Object* cast) { free(this); } -void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { +static void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { const FreeBSDProcess* fp = (const FreeBSDProcess*) this; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; @@ -118,7 +108,7 @@ void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessFiel RichString_append(str, attr, buffer); } -long FreeBSDProcess_compare(const void* v1, const void* v2) { +static long FreeBSDProcess_compare(const void* v1, const void* v2) { const FreeBSDProcess *p1, *p2; const Settings *settings = ((const Process*)v1)->settings; if (settings->direction == 1) { @@ -147,5 +137,15 @@ bool Process_isThread(const Process* this) { if (fp->kernel == 1 ) return 1; else - return (Process_isUserlandThread(this)); + return Process_isUserlandThread(this); } + +const ProcessClass FreeBSDProcess_class = { + .super = { + .extends = Class(Process), + .display = Process_display, + .delete = Process_delete, + .compare = FreeBSDProcess_compare + }, + .writeField = FreeBSDProcess_writeField, +}; diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index d6873d099..d2fee956a 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -34,9 +34,13 @@ typedef struct FreeBSDProcess_ { const char* ttyPath; } FreeBSDProcess; -#define Process_isKernelThread(_process) (_process->kernel == 1) +static inline bool Process_isKernelThread(const Process* this) { + return ((const FreeBSDProcess*)this)->kernel == 1; +} -#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) +static inline bool Process_isUserlandThread(const Process* this) { + return this->pid != this->tgid; +} extern const ProcessClass FreeBSDProcess_class; @@ -48,10 +52,6 @@ Process* FreeBSDProcess_new(const Settings* settings); void Process_delete(Object* cast); -void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessField field); - -long FreeBSDProcess_compare(const void* v1, const void* v2); - bool Process_isThread(const Process* this); #endif diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index caa04ccd8..4c4181148 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -479,7 +479,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { Process* proc = ProcessList_getProcess(super, kproc->ki_pid, &preExisting, FreeBSDProcess_new); FreeBSDProcess* fp = (FreeBSDProcess*) proc; - proc->show = ! ((hideKernelThreads && Process_isKernelThread(fp)) || (hideUserlandThreads && Process_isUserlandThread(proc))); + proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); if (!preExisting) { fp->jid = kproc->ki_jid; @@ -567,9 +567,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) fp->ttyPath = (kproc->ki_tdev == NODEV) ? nodevStr : Hashtable_get(fpl->ttys, kproc->ki_tdev); - if (Process_isKernelThread(fp)) { + if (Process_isKernelThread(proc)) super->kernelThreads++; - } super->totalTasks++; if (proc->state == 'R') From bbf01054bf943db4394027d77915f9625ebde81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 26 Oct 2020 21:16:43 +0100 Subject: [PATCH 363/411] Add compat wrapper for fstatat --- Compat.c | 46 ++++++++++++++++++++++++++++++++++++ Compat.h | 19 +++++++++++++++ Makefile.am | 2 ++ configure.ac | 2 +- freebsd/FreeBSDProcessList.c | 5 ++-- 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 Compat.c create mode 100644 Compat.h diff --git a/Compat.c b/Compat.c new file mode 100644 index 000000000..25aa9f734 --- /dev/null +++ b/Compat.c @@ -0,0 +1,46 @@ +/* +htop - Compat.c +(C) 2020 Christian Göttsche +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include +#include +#include +#include + +#include "Compat.h" +#ifndef HAVE_FSTATAT +#include "XUtils.h" +#endif + + +int Compat_fstatat(int dirfd, + const char* dirpath, + const char* pathname, + struct stat* statbuf, + int flags) { + +#ifdef HAVE_FSTATAT + + (void)dirpath; + + return fstatat(dirfd, pathname, statbuf, flags); + +#else + + (void)dirfd; + + char path[4096]; + xSnprintf(path, sizeof(path), "%s/%s", dirpath, pathname); + + if (flags & AT_SYMLINK_NOFOLLOW) + return lstat(path, statbuf); + + return stat(path, statbuf); + +#endif +} diff --git a/Compat.h b/Compat.h new file mode 100644 index 000000000..c9fd0e62d --- /dev/null +++ b/Compat.h @@ -0,0 +1,19 @@ +#ifndef HEADER_Compat +#define HEADER_Compat +/* +htop - Compat.h +(C) 2020 Christian Göttsche +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include + + +int Compat_fstatat(int dirfd, + const char* dirpath, + const char* pathname, + struct stat* statbuf, + int flags); + +#endif /* HEADER_Compat */ diff --git a/Makefile.am b/Makefile.am index d5b05d060..e7582e712 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,6 +26,7 @@ myhtopsources = \ ColorsPanel.c \ ColumnsPanel.c \ CommandScreen.c \ + Compat.c \ CPUMeter.c \ CRT.c \ DateMeter.c \ @@ -79,6 +80,7 @@ myhtopheaders = \ ColorsPanel.h \ ColumnsPanel.h \ CommandScreen.h \ + Compat.h \ DateMeter.h \ DateTimeMeter.h \ DiskIOMeter.h \ diff --git a/configure.ac b/configure.ac index 70289a789..b70a509f5 100644 --- a/configure.ac +++ b/configure.ac @@ -88,7 +88,7 @@ AC_TYPE_UID_T # ---------------------------------------------------------------------- AC_FUNC_CLOSEDIR_VOID AC_FUNC_STAT -AC_CHECK_FUNCS([memmove strncasecmp strstr strdup]) +AC_CHECK_FUNCS([fstatat memmove strncasecmp strstr strdup]) save_cflags="${CFLAGS}" CFLAGS="${CFLAGS} -std=c99" diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 4c4181148..df06546cc 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -22,6 +22,7 @@ in the source distribution for its full text. #include #include +#include "Compat.h" #include "CRT.h" #include "FreeBSDProcess.h" #include "Macros.h" @@ -338,7 +339,7 @@ static void FreeBSDProcessList_scanTTYs(ProcessList* pl) { continue; struct stat info; - if (fstatat(dirFd, entry->d_name, &info, 0) < 0) + if (Compat_fstatat(dirFd, "/dev", entry->d_name, &info, 0) < 0) continue; if (!S_ISCHR(info.st_mode)) @@ -365,7 +366,7 @@ static void FreeBSDProcessList_scanTTYs(ProcessList* pl) { const struct dirent* entry; while ((entry = readdir(dirPtr))) { struct stat info; - if (fstatat(dirFd, entry->d_name, &info, 0) < 0) + if (Compat_fstatat(dirFd, "/dev/pts", entry->d_name, &info, 0) < 0) continue; if (!S_ISCHR(info.st_mode)) From dde71c6637905e1707bd1020c93e930f4b0a480b Mon Sep 17 00:00:00 2001 From: Adam Saponara Date: Fri, 30 Oct 2020 21:56:16 -0400 Subject: [PATCH 364/411] Highlight new and old processes (#74) --- CRT.c | 12 +++++++ CRT.h | 2 ++ DisplayOptionsPanel.c | 1 + Panel.c | 12 ++++--- Process.c | 17 ++++++++++ Process.h | 11 ++++++- ProcessList.c | 42 +++++++++++++++++++++--- ProcessList.h | 2 ++ RichString.h | 1 + ScreenManager.c | 1 + Settings.c | 7 ++++ Settings.h | 2 ++ htop.1.in | 5 ++- htop.c | 75 +++++++++++++++++++++++++++++-------------- 14 files changed, 155 insertions(+), 35 deletions(-) diff --git a/CRT.c b/CRT.c index 888444cc3..28a2add71 100644 --- a/CRT.c +++ b/CRT.c @@ -111,6 +111,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), [PROCESS_LOW_PRIORITY] = ColorPair(Green,Black), + [PROCESS_NEW] = ColorPair(Black,Green), + [PROCESS_TOMB] = ColorPair(Black,Red), [PROCESS_THREAD] = ColorPair(Green,Black), [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Black), [BAR_BORDER] = A_BOLD, @@ -188,6 +190,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD, [PROCESS_HIGH_PRIORITY] = A_BOLD, [PROCESS_LOW_PRIORITY] = A_DIM, + [PROCESS_NEW] = A_BOLD, + [PROCESS_TOMB] = A_DIM, [PROCESS_THREAD] = A_BOLD, [PROCESS_THREAD_BASENAME] = A_REVERSE, [BAR_BORDER] = A_BOLD, @@ -265,6 +269,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,White), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,White), [PROCESS_LOW_PRIORITY] = ColorPair(Green,White), + [PROCESS_NEW] = ColorPair(White,Green), + [PROCESS_TOMB] = ColorPair(White,Red), [PROCESS_THREAD] = ColorPair(Blue,White), [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,White), [BAR_BORDER] = ColorPair(Blue,White), @@ -342,6 +348,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), [PROCESS_LOW_PRIORITY] = ColorPair(Green,Black), + [PROCESS_NEW] = ColorPair(Black,Green), + [PROCESS_TOMB] = ColorPair(Black,Red), [PROCESS_THREAD] = ColorPair(Blue,Black), [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black), [BAR_BORDER] = ColorPair(Blue,Black), @@ -419,6 +427,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Blue), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Blue), [PROCESS_LOW_PRIORITY] = ColorPair(Green,Blue), + [PROCESS_NEW] = ColorPair(Blue,Green), + [PROCESS_TOMB] = ColorPair(Blue,Red), [PROCESS_THREAD] = ColorPair(Green,Blue), [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Blue), [BAR_BORDER] = A_BOLD | ColorPair(Yellow,Blue), @@ -498,6 +508,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), [PROCESS_LOW_PRIORITY] = ColorPair(Green,Black), + [PROCESS_NEW] = ColorPair(Black,Green), + [PROCESS_TOMB] = ColorPair(Black,Red), [BAR_BORDER] = A_BOLD | ColorPair(Green,Black), [BAR_SHADOW] = ColorPair(Cyan,Black), [SWAP] = ColorPair(Red,Black), diff --git a/CRT.h b/CRT.h index 1cdc209ce..818148ef0 100644 --- a/CRT.h +++ b/CRT.h @@ -72,6 +72,8 @@ typedef enum ColorElements_ { PROCESS_BASENAME, PROCESS_HIGH_PRIORITY, PROCESS_LOW_PRIORITY, + PROCESS_NEW, + PROCESS_TOMB, PROCESS_THREAD, PROCESS_THREAD_BASENAME, BAR_BORDER, diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 64fd303c4..e539906c0 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -93,6 +93,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU percentage numerically"), &(settings->showCPUUsage))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU frequency"), &(settings->showCPUFrequency))); Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Enable the mouse"), &(settings->enableMouse))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight new and old processes"), &(settings->highlightChanges))); #ifdef HAVE_LIBHWLOC Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show topology when selecting affinity by default"), &(settings->topologyAffinity))); #endif diff --git a/Panel.c b/Panel.c index 02440d85c..f3a48bc97 100644 --- a/Panel.c +++ b/Panel.c @@ -266,16 +266,18 @@ void Panel_draw(Panel* this, bool focus) { Object_display(itemObj, &item); int itemLen = RichString_sizeVal(item); int amt = MINIMUM(itemLen - scrollH, this->w); - bool selected = (i == this->selected); - if (selected) { - attrset(selectionColor); - RichString_setAttr(&item, selectionColor); + if (i == this->selected) { + item.highlightAttr = selectionColor; + } + if (item.highlightAttr) { + attrset(item.highlightAttr); + RichString_setAttr(&item, item.highlightAttr); this->selectedLen = itemLen; } mvhline(y + line, x, ' ', this->w); if (amt > 0) RichString_printoffnVal(item, y + line, x, scrollH, amt); - if (selected) + if (item.highlightAttr) attrset(CRT_colors[RESET_COLOR]); RichString_end(item); line++; diff --git a/Process.c b/Process.c index 842232f70..f78720a50 100644 --- a/Process.c +++ b/Process.c @@ -6,6 +6,7 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ + #include "config.h" // IWYU pragma: keep #include "Process.h" @@ -381,6 +382,12 @@ void Process_display(const Object* cast, RichString* out) { RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]); if (this->tag == true) RichString_setAttr(out, CRT_colors[PROCESS_TAG]); + if (this->settings->highlightChanges) { + if (Process_isNew(this)) + out->highlightAttr = CRT_colors[PROCESS_NEW]; + if (Process_isTomb(this)) + out->highlightAttr = CRT_colors[PROCESS_TOMB]; + } assert(out->chlen > 0); } @@ -413,6 +420,16 @@ void Process_toggleTag(Process* this) { this->tag = this->tag == true ? false : true; } +bool Process_isNew(const Process* this) { + if (this->processList && this->processList->scanTs >= this->seenTs) + return (this->processList->scanTs - this->seenTs <= this->processList->settings->highlightDelaySecs); + return false; +} + +bool Process_isTomb(const Process* this) { + return (this->tombTs > 0); +} + bool Process_setPriority(Process* this, int priority) { CRT_dropPrivileges(); int old_prio = getpriority(PRIO_PROCESS, this->pid); diff --git a/Process.h b/Process.h index b2c820808..e3ff333fa 100644 --- a/Process.h +++ b/Process.h @@ -10,17 +10,18 @@ in the source distribution for its full text. #include #include +#include #include "Object.h" #include "RichString.h" - #ifdef __ANDROID__ #define SYS_ioprio_get __NR_ioprio_get #define SYS_ioprio_set __NR_ioprio_set #endif #define PROCESS_FLAG_IO 0x0001 +#define DEFAULT_HIGHLIGHT_SECS 5 typedef enum ProcessFields { NULL_PROCESSFIELD = 0, @@ -59,6 +60,7 @@ struct Settings_; typedef struct Process_ { Object super; + const struct ProcessList_* processList; const struct Settings_* settings; unsigned long long int time; @@ -99,6 +101,9 @@ typedef struct Process_ { int exit_signal; + time_t seenTs; + time_t tombTs; + unsigned long int minflt; unsigned long int majflt; } Process; @@ -172,6 +177,10 @@ void Process_init(Process* this, const struct Settings_* settings); void Process_toggleTag(Process* this); +bool Process_isNew(const Process* this); + +bool Process_isTomb(const Process* this); + bool Process_setPriority(Process* this, int priority); bool Process_changePriorityBy(Process* this, Arg delta); diff --git a/ProcessList.c b/ProcessList.c index dac86cb87..1ae7b9cc4 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -9,11 +9,11 @@ in the source distribution for its full text. #include #include +#include #include "CRT.h" #include "XUtils.h" - ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { this->processes = Vector_new(klass, true, DEFAULT_SIZE); this->processTable = Hashtable_new(140, false); @@ -27,6 +27,9 @@ ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, Users // set later by platform-specific code this->cpuCount = 0; + this->scanTs = 0; + this->firstScanTs = 0; + #ifdef HAVE_LIBHWLOC this->topologyOk = false; if (hwloc_topology_init(&this->topology) == 0) { @@ -81,6 +84,14 @@ void ProcessList_printHeader(ProcessList* this, RichString* header) { void ProcessList_add(ProcessList* this, Process* p) { assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1); assert(Hashtable_get(this->processTable, p->pid) == NULL); + p->processList = this; + + if (this->scanTs == this->firstScanTs) { + // prevent highlighting processes found in first scan + p->seenTs = this->firstScanTs - this->settings->highlightDelaySecs - 1; + } else { + p->seenTs = this->scanTs; + } Vector_add(this->processes, p); Hashtable_put(this->processTable, p->pid, p); @@ -283,6 +294,7 @@ Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, } void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { + struct timespec now; // in pause mode only gather global data for meters (CPU/memory/...) if (pauseProcessUpdate) { @@ -302,13 +314,35 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { this->kernelThreads = 0; this->runningTasks = 0; + + // set scanTs + if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) { + if (this->firstScanTs == 0) { + this->firstScanTs = now.tv_sec; + } + this->scanTs = now.tv_sec; + } + ProcessList_goThroughEntries(this, false); for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { Process* p = (Process*) Vector_get(this->processes, i); - if (p->updated == false) - ProcessList_remove(this, p); - else + if (p->tombTs > 0) { + // remove tombed process + if (this->scanTs >= p->tombTs) { + ProcessList_remove(this, p); + } + } else if (p->updated == false) { + // process no longer exists + if (this->settings->highlightChanges) { + // mark tombed + p->tombTs = this->scanTs + this->settings->highlightDelaySecs; + } else { + // immediately remove + ProcessList_remove(this, p); + } + } else { p->updated = false; + } } } diff --git a/ProcessList.h b/ProcessList.h index 6b075fa7a..db0549a65 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -70,6 +70,8 @@ typedef struct ProcessList_ { int cpuCount; + time_t scanTs; + time_t firstScanTs; } ProcessList; ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); diff --git a/RichString.h b/RichString.h index 48c1e7491..9ee3a2d0e 100644 --- a/RichString.h +++ b/RichString.h @@ -39,6 +39,7 @@ typedef struct RichString_ { int chlen; CharType* chptr; CharType chstr[RICHSTRING_MAXLEN+1]; + int highlightAttr; } RichString; void RichString_setAttrn(RichString* this, int attrs, int start, int finish); diff --git a/ScreenManager.c b/ScreenManager.c index bc5f66ac8..2d43babc4 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -102,6 +102,7 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi struct timeval tv; gettimeofday(&tv, NULL); double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000); + *timedOut = (newTime - *oldTime > this->settings->delay); *rescan = *rescan || *timedOut; if (newTime < *oldTime) *rescan = true; // clock was adjusted? diff --git a/Settings.c b/Settings.c index 9ac275656..a0a05042d 100644 --- a/Settings.c +++ b/Settings.c @@ -158,6 +158,10 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo this->highlightMegabytes = atoi(option[1]); } else if (String_eq(option[0], "highlight_threads")) { this->highlightThreads = atoi(option[1]); + } else if (String_eq(option[0], "highlight_changes")) { + this->highlightChanges = atoi(option[1]); + } else if (String_eq(option[0], "highlight_changes_delay_secs")) { + this->highlightDelaySecs = atoi(option[1]); } else if (String_eq(option[0], "header_margin")) { this->headerMargin = atoi(option[1]); } else if (String_eq(option[0], "expand_system_time")) { @@ -265,6 +269,8 @@ bool Settings_write(Settings* this) { fprintf(fd, "highlight_base_name=%d\n", (int) this->highlightBaseName); fprintf(fd, "highlight_megabytes=%d\n", (int) this->highlightMegabytes); fprintf(fd, "highlight_threads=%d\n", (int) this->highlightThreads); + fprintf(fd, "highlight_changes=%d\n", (int) this->highlightChanges); + fprintf(fd, "highlight_changes_delay_secs=%d\n", (int) this->highlightDelaySecs); fprintf(fd, "tree_view=%d\n", (int) this->treeView); fprintf(fd, "header_margin=%d\n", (int) this->headerMargin); fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime); @@ -307,6 +313,7 @@ Settings* Settings_new(int initialCpuCount) { this->updateProcessNames = false; this->showProgramPath = true; this->highlightThreads = true; + this->highlightDelaySecs = DEFAULT_HIGHLIGHT_SECS; #ifdef HAVE_LIBHWLOC this->topologyAffinity = false; #endif diff --git a/Settings.h b/Settings.h index bbd40e162..b04a43082 100644 --- a/Settings.h +++ b/Settings.h @@ -48,6 +48,8 @@ typedef struct Settings_ { bool highlightBaseName; bool highlightMegabytes; bool highlightThreads; + bool highlightChanges; + int highlightDelaySecs; bool updateProcessNames; bool accountGuestInCPUMeter; bool headerMargin; diff --git a/htop.1.in b/htop.1.in index 3e95c201b..b688d87d7 100644 --- a/htop.1.in +++ b/htop.1.in @@ -4,7 +4,7 @@ htop \- interactive process viewer .SH "SYNOPSIS" .LP .B htop -.RB [ \-dCFhpustv ] +.RB [ \-dCFhpustvH ] .SH "DESCRIPTION" .LP .B htop @@ -62,6 +62,9 @@ Output version information and exit .TP \fB\-t \-\-tree Show processes in tree view +.TP +\fB\-H \-\-highlight-changes=DELAY\fR +Highlight new and old processes .SH "INTERACTIVE COMMANDS" .LP The following commands are supported while in diff --git a/htop.c b/htop.c index e4d437b93..351f58672 100644 --- a/htop.c +++ b/htop.c @@ -46,17 +46,18 @@ static void printHelpFlag(void) { fputs("htop " VERSION "\n" COPYRIGHT "\n" "Released under the GNU GPLv2.\n\n" - "-C --no-color Use a monochrome color scheme\n" - "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" - "-F --filter=FILTER Show only the commands matching the given filter\n" - "-h --help Print this help screen\n" - "-M --no-mouse Disable the mouse\n" - "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n" - "-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n" - "-t --tree Show the tree view by default\n" - "-u --user[=USERNAME] Show only processes for a given user (or $USER)\n" - "-U --no-unicode Do not use unicode but plain ASCII\n" - "-V --version Print version info\n" + "-C --no-color Use a monochrome color scheme\n" + "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" + "-F --filter=FILTER Show only the commands matching the given filter\n" + "-h --help Print this help screen\n" + "-M --no-mouse Disable the mouse\n" + "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n" + "-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n" + "-t --tree Show the tree view by default\n" + "-u --user[=USERNAME] Show only processes for a given user (or $USER)\n" + "-U --no-unicode Do not use unicode but plain ASCII\n" + "-V --version Print version info\n" + "-H --highlight-changes[=DELAY] Highlight new and old processes\n" "\n" "Long options may be passed with a single dash.\n\n" "Press F1 inside htop for online help.\n" @@ -76,6 +77,8 @@ typedef struct CommandLineSettings_ { bool enableMouse; bool treeView; bool allowUnicode; + bool highlightChanges; + int highlightDelaySecs; } CommandLineSettings; static CommandLineSettings parseArguments(int argc, char** argv) { @@ -90,28 +93,31 @@ static CommandLineSettings parseArguments(int argc, char** argv) { .enableMouse = true, .treeView = false, .allowUnicode = true, + .highlightChanges = false, + .highlightDelaySecs = -1, }; static struct option long_opts[] = { - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {"delay", required_argument, 0, 'd'}, - {"sort-key", required_argument, 0, 's'}, - {"user", optional_argument, 0, 'u'}, - {"no-color", no_argument, 0, 'C'}, - {"no-colour", no_argument, 0, 'C'}, - {"no-mouse", no_argument, 0, 'M'}, - {"no-unicode", no_argument, 0, 'U'}, - {"tree", no_argument, 0, 't'}, - {"pid", required_argument, 0, 'p'}, - {"filter", required_argument, 0, 'F'}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {"delay", required_argument, 0, 'd'}, + {"sort-key", required_argument, 0, 's'}, + {"user", optional_argument, 0, 'u'}, + {"no-color", no_argument, 0, 'C'}, + {"no-colour", no_argument, 0, 'C'}, + {"no-mouse", no_argument, 0, 'M'}, + {"no-unicode", no_argument, 0, 'U'}, + {"tree", no_argument, 0, 't'}, + {"pid", required_argument, 0, 'p'}, + {"filter", required_argument, 0, 'F'}, + {"highlight-changes", optional_argument, 0, 'H'}, {0,0,0,0} }; int opt, opti=0; /* Parse arguments */ - while ((opt = getopt_long(argc, argv, "hVMCs:td:u::Up:F:", long_opts, &opti))) { + while ((opt = getopt_long(argc, argv, "hVMCs:td:u::Up:F:H::", long_opts, &opti))) { if (opt == EOF) break; switch (opt) { case 'h': @@ -198,6 +204,23 @@ static CommandLineSettings parseArguments(int argc, char** argv) { break; } + case 'H': { + const char *delay = optarg; + if (!delay && optind < argc && argv[optind] != NULL && + (argv[optind][0] != '\0' && argv[optind][0] != '-')) { + delay = argv[optind++]; + } + if (delay) { + if (sscanf(delay, "%16d", &(flags.highlightDelaySecs)) == 1) { + if (flags.highlightDelaySecs < 1) flags.highlightDelaySecs = 1; + } else { + fprintf(stderr, "Error: invalid highlight delay value \"%s\".\n", delay); + exit(1); + } + } + flags.highlightChanges = true; + break; + } default: exit(1); } @@ -271,6 +294,10 @@ int main(int argc, char** argv) { settings->enableMouse = false; if (flags.treeView) settings->treeView = true; + if (flags.highlightChanges) + settings->highlightChanges = true; + if (flags.highlightDelaySecs != -1) + settings->highlightDelaySecs = flags.highlightDelaySecs; CRT_init(settings->delay, settings->colorScheme, flags.allowUnicode); From de884d17bb568bbce8881a1f4a937a2edcdb0e5a Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 11:04:31 +0100 Subject: [PATCH 365/411] Documentation on the repository style guide --- CONTRIBUTING.md | 11 +++ docs/styleguide.md | 185 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 docs/styleguide.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7110e44c8..65eb95c9a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,3 +32,14 @@ Feature Requests Please label Github issues that are feature requests with the [`feature request`](https://github.com/htop-dev/htop/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22feature+request%22+) label. + +Style Guide +----------- + +To make working with the code easier a set of guidelines have evolved in +the past that new contributions should try to follow. While they are not set +in stone and always up for changes should the need arise they still provide +a first orientation to go by when contributing to this repository. + +The details of the coding style as well as what to take care about with your +contributions can be found in our [style guide](docs/styleguide.md). diff --git a/docs/styleguide.md b/docs/styleguide.md new file mode 100644 index 000000000..4c0ac1f55 --- /dev/null +++ b/docs/styleguide.md @@ -0,0 +1,185 @@ +htop coding style guide +======================= + +Naming conventions +------------------ + +Names are important to convey what all those things inside the project are for. +Filenames for source code traditionally used camel-case naming with the first letter written in uppercase. +The file extension is always lowercase. + +The only exception here is `htop.c` which is the main entrance point into the code. + +Folders for e.g. platform-specific code or complex features spawning multiple files are written in lowercase, e.g. `linux`, `freebsd`, `zfs`. + +Inside files, the naming somewhat depends on the context. +For functions names should include a camel-case prefix before the actual name, separated by an underscore. +While this prefix usually coincides with the module name, this is not required, yet strongly advised. +One important exception to this rule are the memory management and the string utility functions from `XUtils.h`. + +Variable names inside functions should be short and precise. +Using `i` for some loop counter is totally fine, using `someCounterValueForThisSimpleLoop` is not. +On the other hand, when you need to hold global storage try to keep this local to your module, i.e. declare such variables `static` within the C source file. +Only if your variable really needs to be visible for the whole project (which is really rare) it deserves a declaration in the header, marked `extern`. + +File content structure +---------------------- + +The content within each file is usually structured according to the following loose template: + +* Copyright declaration +* Inclusion of used headers +* Necessary data structures and forward declarations +* Static module-private function implementations +* Externally visible function implementations +* Externally visible constant structures (pseudo-OOP definitions) + +For header files header guards based on `#ifdef` should be used. +These header guards are historically placed **before** the Copyright declaration. +Stick to that for consistency please. + +Example: + +```c +#ifndef HEADER_FILENAME +#define HEADER_FILENAME +/* +htop - Filename.h +(C) 2020 htop dev team +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ +``` + +Import and use of headers +------------------------- + +Every file should import headers for all symbols it's using. +Thus when using a symbol from a header, even if that symbol is already imported by something else you use, you should declare an import for that header. +Doing so allows for easier restructuring of the code when things need to be moved around. +If you are unsure if all necessary headers are included you might use IWYU to tell you. + +The list of includes should be the first thing in the file, after the copyright comment and be followed by two blank lines. +The include list should be in the following order, with each group separated by one blank line: + +1. `include "config.h" // IWYU pragma: keep` if the global configuration + from automake&autoconfigure or any of the feature guards for C library headers + (like `__GNU_SOURCE`) are required, optional otherwise. Beware of the IWYU comment. +2. Accompanying module header file (for C source files only, missing inside headers) +3. List of used system headers (non-conditional includes) +4. List of used program headers +5. Conditionally included header files, system headers first + +The list of headers should be sorted with includes from subdirectories following after files inside their parent directory. +Thus `unistd.h` sorts before `sys/time.h`. + +Symbol Exports +-------------- + +Exports of symbols should be used sparingly. +Thus unless a function you write is intended to become public API of a module you should mark it as `static`. +If a function should be public API an appropriate declaration for that function has to be placed in the accompaying header file. + +Please avoid function-like macros, in particular when exporting them in a header file. +They have several downsides (re-evaluation of arguments, syntactic escapes, weak typing) for which usually a better alternative like an actual function exists. +Furthermore when using function-like `define`s you may need to mark certain headers for IWYU so tracking of used symbols works. + +Memory Management +----------------- + +When allocating memory make sure to free resources properly. +For allocation this project uses a set of tiny wrappers around the common functions `malloc`, `calloc` and `realloc` named `xMalloc`, `xCalloc` and `xRealloc`. +These functions check that memory allocation worked and error out on failure. + +Allocation functions assert the amount of memory requested is non-zero. +Trying to allocate 0 bytes of memory is an error. +Please use the explicit value `NULL` in this case and handle it in your code accordingly. + +Working with Strings +-------------------- + +It is strongly encouraged to use the functions starting with `String_` from `XUtils.h` for working with zero-terminated strings as these make the API easier to use and are intended to make the intent of your code easier to grasp. + +Thus instead of `!strcmp(foo, "foo")` it's preferred to use `String_eq(foo, "foo")` instead. +While sometimes a bit more to type, this helps a lot with making the code easier to follow. + +Styling the code +---------------- + +Now for the style details that can mostly be automated: Indentation, spacing and bracing. +While there is no definitve code style we use, a set of rules loosely enforced has evolved. + +Indentation in the code is done by three (3) spaces. No tabs are used. Ever. + +Before and after keywords should be a space, e.g. `if (condition)` and `do { … } while (condition);`. + +After opening and before closing braces a new line should be started. +Content of such encoded blocks should be indented one level further than their enclosing block. + +If a line of source code becomes too long, or when structuring it into multiple parts for clarity, the continuation line should be indented one more level than the first line it continues: + +```c +if (very_long_condition && + another_very_complex_expression && + something_else_to_check) { + // Code follows as normal ... +} else { + +} +``` + +While braces around single code statements are strongly encouraged, they are usually left out for single statements when only redirecting code flow: + +```c +if (termination condition) + return 42; +``` + +Control flow statements and the instruction making up their body should not be put on a single line, i.e. after the condition of an if statement a new line should be inserted and the body indented accordingly. +When an if statement uses more than just the true branch it should use braces for all statements that follow: + +```c +if (condition1) { + // Some code +} else if (condition2) { + // Some more code +} else { + // something else +} +``` + +While this code style isn't fully consistent in the existing code base it is strongly recommended that new code follows these rules. +Adapting surrounding code near places you need to touch is encouraged. +Try to separate such changes into a single, clean-up only commit to reduce noise while reviewing your changes. + +If you want to automate formatting your code, the following command gives you a good baseline of how it should look: + +```bash +astyle -r -j -xb -s3 -p -xg -c -k1 -W1 \*.c \*.h +``` + +Working with System APIs +------------------------ + +Please try to be considerate when using modern platform features. +While they usually provide quite a performance gain or make your life easier, it is benefitial if `htop` runs on rather ancient systems. +Thus when you want to use such features you should try to have an alternative available that works as a fallback. + +An example for this are functions like `fstatat` on Linux that extend the kernel API on modern systems. +But even though it has been around for over a decade you are asked to provide a POSIX alternative like emulating such calls by `fstat` if this is doable. +If an alternative can not be provided you should gracefully downgrade. That could make a feature that requires this shiny API unavailable on systems that lack support for that API. Make this case visually clear to the user. + +In general, code written for the project should be able to compile on any C99-compliant compiler. + +Writing documentation +--------------------- + +The primary user documentation should be the man file which you can find in `htop.1.in`. + +Additional documentation, like this file, should be written in gh-style markdown. +Make each sentence one line. +Markdown will combined these in output formats. +It does only insert a paragraph if you insert a blank line into the source file. +This way git can better diff and present the changes when documentation is altered. + +Documentation files reside in the `docs/` directory and have a `.md` extension. From 59ef15b2ad6037f40d7fe4207b2b59dd11b14b8b Mon Sep 17 00:00:00 2001 From: Erdem Ersoy Date: Fri, 30 Oct 2020 19:12:17 +0300 Subject: [PATCH 366/411] Fix segmentation fault when column name is NULL. So, some columns (ex: SECATTR) can be sortable now. --- ColumnsPanel.c | 9 --------- ColumnsPanel.h | 2 -- htop.c | 10 +++++++++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ColumnsPanel.c b/ColumnsPanel.c index f82501976..36127bd5a 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -135,15 +135,6 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings) { return this; } -int ColumnsPanel_fieldNameToIndex(const char* name) { - for (int j = 1; j <= Platform_numberOfFields; j++) { - if (String_eq(name, Process_fields[j].name)) { - return j; - } - } - return -1; -} - void ColumnsPanel_update(Panel* super) { ColumnsPanel* this = (ColumnsPanel*) super; int size = Panel_size(super); diff --git a/ColumnsPanel.h b/ColumnsPanel.h index 68f80450f..173e039bf 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -23,8 +23,6 @@ extern const PanelClass ColumnsPanel_class; ColumnsPanel* ColumnsPanel_new(Settings* settings); -int ColumnsPanel_fieldNameToIndex(const char* name); - void ColumnsPanel_update(Panel* super); #endif diff --git a/htop.c b/htop.c index e4d437b93..e02f388ab 100644 --- a/htop.c +++ b/htop.c @@ -129,7 +129,15 @@ static CommandLineSettings parseArguments(int argc, char** argv) { } exit(0); } - flags.sortKey = ColumnsPanel_fieldNameToIndex(optarg); + flags.sortKey = -1; + for (int j = 1; j < Platform_numberOfFields; j++) { + if (Process_fields[j].name == NULL) + continue; + if (String_eq(optarg, Process_fields[j].name)) { + flags.sortKey = j; + break; + } + } if (flags.sortKey == -1) { fprintf(stderr, "Error: invalid column \"%s\".\n", optarg); exit(1); From 43d274a6179846e5dfaf1bd0b75b57f6e65a8e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 29 Oct 2020 23:17:12 +0100 Subject: [PATCH 367/411] Use integer type for item count instead of char --- CPUMeter.c | 3 +-- Meter.c | 8 +++----- Meter.h | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 106354784..4997f6f8e 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -51,8 +51,7 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { int cpu = this->param; if (cpu > this->pl->cpuCount) { xSnprintf(buffer, size, "absent"); - int items = this->curItems; - for (int i = 0; i < items; i++) + for (uint8_t i = 0; i < this->curItems; i++) this->values[i] = 0; return; } diff --git a/Meter.c b/Meter.c index a04a58321..59daa0f55 100644 --- a/Meter.c +++ b/Meter.c @@ -195,8 +195,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { // First draw in the bar[] buffer... int offset = 0; - int items = this->curItems; - for (int i = 0; i < items; i++) { + for (uint8_t i = 0; i < this->curItems; i++) { double value = this->values[i]; value = CLAMP(value, 0.0, this->total); if (value > 0) { @@ -220,7 +219,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { // ...then print the buffer. offset = 0; - for (int i = 0; i < items; i++) { + for (uint8_t i = 0; i < this->curItems; i++) { attrset(CRT_colors[Meter_attributes(this)[i]]); mvaddnstr(y, x + offset, bar + offset, blockSizes[i]); offset += blockSizes[i]; @@ -296,8 +295,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { Meter_updateValues(this, buffer, nValues - 1); double value = 0.0; - int items = this->curItems; - for (int i = 0; i < items; i++) + for (uint8_t i = 0; i < this->curItems; i++) value += this->values[i]; value /= this->total; data->values[nValues - 1] = value; diff --git a/Meter.h b/Meter.h index 32c167cb3..125c0cd50 100644 --- a/Meter.h +++ b/Meter.h @@ -42,7 +42,7 @@ typedef struct MeterClass_ { const char* const uiName; const char* const caption; const char* const description; - const char maxItems; + const uint8_t maxItems; } MeterClass; #define As_Meter(this_) ((const MeterClass*)((this_)->super.klass)) @@ -75,7 +75,7 @@ struct Meter_ { GraphData* drawData; int h; const ProcessList* pl; - char curItems; + uint8_t curItems; double* values; double total; void* meterData; From ab17ef4dc0a306b7481cb47149b1c25f7f200932 Mon Sep 17 00:00:00 2001 From: Murloc Knight Date: Tue, 22 Sep 2020 18:54:15 +0700 Subject: [PATCH 368/411] Zram Meter feature --- CRT.c | 6 ++++ CRT.h | 1 + Makefile.am | 3 ++ linux/LinuxProcessList.c | 50 ++++++++++++++++++++++++++- linux/LinuxProcessList.h | 3 ++ linux/Platform.c | 9 +++++ linux/Platform.h | 2 ++ linux/ZramMeter.c | 75 ++++++++++++++++++++++++++++++++++++++++ linux/ZramMeter.h | 8 +++++ linux/ZramStats.h | 10 ++++++ 10 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 linux/ZramMeter.c create mode 100644 linux/ZramMeter.h create mode 100644 linux/ZramStats.h diff --git a/CRT.c b/CRT.c index 888444cc3..a13f531a9 100644 --- a/CRT.c +++ b/CRT.c @@ -153,6 +153,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Blue,Black), [ZFS_RATIO] = ColorPair(Magenta,Black), + [ZRAM] = ColorPair(Yellow,Black), }, [COLORSCHEME_MONOCHROME] = { [RESET_COLOR] = A_NORMAL, @@ -230,6 +231,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_DIM, [ZFS_COMPRESSED] = A_BOLD, [ZFS_RATIO] = A_BOLD, + [ZRAM] = A_NORMAL, }, [COLORSCHEME_BLACKONWHITE] = { [RESET_COLOR] = ColorPair(Black,White), @@ -307,6 +309,7 @@ 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) }, [COLORSCHEME_LIGHTTERMINAL] = { [RESET_COLOR] = ColorPair(Blue,Black), @@ -384,6 +387,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Cyan,Black), [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Black), + [ZRAM] = ColorPair(Yellow,Black), }, [COLORSCHEME_MIDNIGHT] = { [RESET_COLOR] = ColorPair(White,Blue), @@ -461,6 +465,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Blue), [ZFS_COMPRESSED] = A_BOLD | ColorPair(White,Blue), [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Blue), + [ZRAM] = A_BOLD | ColorPair(Yellow,Blue), }, [COLORSCHEME_BLACKNIGHT] = { [RESET_COLOR] = ColorPair(Cyan,Black), @@ -536,6 +541,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta,Black), [ZFS_COMPRESSED] = ColorPair(Blue,Black), [ZFS_RATIO] = ColorPair(Magenta,Black), + [ZRAM] = ColorPair(Yellow,Black), }, [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. }; diff --git a/CRT.h b/CRT.h index 1cdc209ce..49ed4ed0c 100644 --- a/CRT.h +++ b/CRT.h @@ -113,6 +113,7 @@ typedef enum ColorElements_ { ZFS_OTHER, ZFS_COMPRESSED, ZFS_RATIO, + ZRAM, LAST_COLORELEMENT } ColorElements; diff --git a/Makefile.am b/Makefile.am index e7582e712..a6629f6d9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -130,6 +130,8 @@ linux_platform_headers = \ linux/Platform.h \ linux/PressureStallMeter.h \ linux/SELinuxMeter.h \ + linux/ZramMeter.h \ + linux/ZramStats.h \ zfs/ZfsArcMeter.h \ zfs/ZfsArcStats.h \ zfs/ZfsCompressedArcMeter.h @@ -144,6 +146,7 @@ myhtopplatsources = \ linux/Platform.c \ linux/PressureStallMeter.c \ linux/SELinuxMeter.c \ + linux/ZramMeter.c \ zfs/ZfsArcMeter.c \ zfs/ZfsArcStats.c \ zfs/ZfsCompressedArcMeter.c diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 2530b2bb2..f32aba417 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1148,6 +1148,54 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { fclose(file); } +static inline void LinuxProcessList_scanZramInfo(LinuxProcessList* this) { + unsigned long long int totalZram = 0; + unsigned long long int usedZramComp = 0; + unsigned long long int usedZramOrig = 0; + + char mm_stat[34]; + char disksize[34]; + + unsigned int i = 0; + for(;;) { + xSnprintf(mm_stat, sizeof(mm_stat), "/sys/block/zram%u/mm_stat", i); + xSnprintf(disksize, sizeof(disksize), "/sys/block/zram%u/disksize", i); + i++; + FILE* disksize_file = fopen(disksize, "r"); + FILE* mm_stat_file = fopen(mm_stat, "r"); + if (disksize_file == NULL || mm_stat_file == NULL) { + if (disksize_file) { + fclose(disksize_file); + } + if (mm_stat_file) { + fclose(mm_stat_file); + } + break; + } + unsigned long long int size = 0; + unsigned long long int orig_data_size = 0; + unsigned long long int compr_data_size = 0; + + if (!fscanf(disksize_file, "%llu\n", &size) || + !fscanf(mm_stat_file, " %llu %llu", &orig_data_size, &compr_data_size)) { + fclose(disksize_file); + fclose(mm_stat_file); + break; + } + + totalZram += size; + usedZramComp += compr_data_size; + usedZramOrig += orig_data_size; + + fclose(disksize_file); + fclose(mm_stat_file); + } + + this->zram.totalZram = totalZram / 1024; + this->zram.usedZramComp = usedZramComp / 1024; + this->zram.usedZramOrig = usedZramOrig / 1024; +} + static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { unsigned long long int dbufSize = 0; unsigned long long int dnodeSize = 0; @@ -1376,8 +1424,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { LinuxProcessList_scanMemoryInfo(super); LinuxProcessList_scanZfsArcstats(this); - LinuxProcessList_updateCPUcount(this); + LinuxProcessList_scanZramInfo(this); double period = LinuxProcessList_scanCPUTime(this); diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 4427ccdfd..1795543f3 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -15,8 +15,10 @@ in the source distribution for its full text. #include "Hashtable.h" #include "ProcessList.h" #include "UsersTable.h" +#include "ZramStats.h" #include "zfs/ZfsArcStats.h" + typedef struct CPUData_ { unsigned long long int totalTime; unsigned long long int userTime; @@ -67,6 +69,7 @@ typedef struct LinuxProcessList_ { #endif ZfsArcStats zfs; + ZramStats zram; } LinuxProcessList; #ifndef PROCDIR diff --git a/linux/Platform.c b/linux/Platform.c index fe9764bab..f7a768c9b 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -42,6 +42,7 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "UptimeMeter.h" #include "XUtils.h" +#include "ZramMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsArcStats.h" @@ -148,6 +149,7 @@ const MeterClass* const Platform_meterTypes[] = { &PressureStallMemoryFullMeter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, + &ZramMeter_class, &DiskIOMeter_class, &NetworkIOMeter_class, &SELinuxMeter_class, @@ -248,6 +250,13 @@ void Platform_setSwapValues(Meter* this) { this->values[0] = pl->usedSwap; } +void Platform_setZramValues(Meter* this) { + const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl; + this->total = lpl->zram.totalZram; + this->values[0] = lpl->zram.usedZramComp; + this->values[1] = lpl->zram.usedZramOrig; +} + void Platform_setZfsArcValues(Meter* this) { const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl; diff --git a/linux/Platform.h b/linux/Platform.h index 62402432e..b61a4db81 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -40,6 +40,8 @@ void Platform_setMemoryValues(Meter* this); void Platform_setSwapValues(Meter* this); +void Platform_setZramValues(Meter* this); + void Platform_setZfsArcValues(Meter* this); void Platform_setZfsCompressedArcValues(Meter* this); diff --git a/linux/ZramMeter.c b/linux/ZramMeter.c new file mode 100644 index 000000000..f855488eb --- /dev/null +++ b/linux/ZramMeter.c @@ -0,0 +1,75 @@ +#include "ZramMeter.h" + +#include "CRT.h" +#include "Meter.h" +#include "Platform.h" + +static const int ZramMeter_attributes[] = { + ZRAM +}; + +static void ZramMeter_updateValues(Meter* this, char* buffer, int size) { + int written; + + Platform_setZramValues(this); + + /* on print bar for compressed data size, not uncompressed */ + this->curItems = 1; + + written = Meter_humanUnit(buffer, this->values[0], size); + buffer += written; + size -= written; + if(size <= 0) { + return; + } + *buffer++ = '('; + size--; + if(size <= 0) { + return; + } + written = Meter_humanUnit(buffer, this->values[1], size); + buffer += written; + size -= written; + if(size <= 0) { + return; + } + *buffer++ = ')'; + size--; + if ((size -= written) > 0) { + *buffer++ = '/'; + size--; + Meter_humanUnit(buffer, this->total, size); + } +} + +static void ZramMeter_display(const Object* cast, RichString* out) { + char buffer[50]; + const Meter* this = (const Meter*)cast; + RichString_write(out, CRT_colors[METER_TEXT], ":"); + Meter_humanUnit(buffer, this->total, sizeof(buffer)); + + RichString_append(out, CRT_colors[METER_VALUE], buffer); + Meter_humanUnit(buffer, this->values[0], sizeof(buffer)); + RichString_append(out, CRT_colors[METER_TEXT], " used:"); + RichString_append(out, CRT_colors[METER_VALUE], buffer); + + Meter_humanUnit(buffer, this->values[1], sizeof(buffer)); + RichString_append(out, CRT_colors[METER_TEXT], " uncompressed:"); + RichString_append(out, CRT_colors[METER_VALUE], buffer); +} + +const MeterClass ZramMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = ZramMeter_display, + }, + .updateValues = ZramMeter_updateValues, + .defaultMode = BAR_METERMODE, + .maxItems = 2, + .total = 100.0, + .attributes = ZramMeter_attributes, + .name = "Zram", + .uiName = "Zram", + .caption = "zrm" +}; diff --git a/linux/ZramMeter.h b/linux/ZramMeter.h new file mode 100644 index 000000000..7cf7861ec --- /dev/null +++ b/linux/ZramMeter.h @@ -0,0 +1,8 @@ +#ifndef HEADER_ZramMeter +#define HEADER_ZramMeter + +#include "Meter.h" + +extern const MeterClass ZramMeter_class; + +#endif diff --git a/linux/ZramStats.h b/linux/ZramStats.h new file mode 100644 index 000000000..2305cfd2b --- /dev/null +++ b/linux/ZramStats.h @@ -0,0 +1,10 @@ +#ifndef HEADER_ZramStats +#define HEADER_ZramStats + +typedef struct ZramStats_ { + unsigned long long int totalZram; + unsigned long long int usedZramComp; + unsigned long long int usedZramOrig; +} ZramStats; + +#endif From 2a9e8ca07475e61e74d7b6f0afd0a5fd272cb07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 7 Oct 2020 15:42:13 +0200 Subject: [PATCH 369/411] Add SystemdMeter --- CRT.c | 18 ++- CRT.h | 3 +- Makefile.am | 2 + configure.ac | 2 + linux/Platform.c | 2 + linux/SystemdMeter.c | 329 +++++++++++++++++++++++++++++++++++++++++++ linux/SystemdMeter.h | 15 ++ 7 files changed, 364 insertions(+), 7 deletions(-) create mode 100644 linux/SystemdMeter.c create mode 100644 linux/SystemdMeter.h diff --git a/CRT.c b/CRT.c index a13f531a9..cc64bb8bf 100644 --- a/CRT.c +++ b/CRT.c @@ -95,9 +95,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Cyan,Black), [METER_VALUE] = A_BOLD | ColorPair(Cyan,Black), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Black), [METER_VALUE_IOREAD] = ColorPair(Green,Black), [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Black), + [METER_VALUE_OK] = ColorPair(Green,Black), [LED_COLOR] = ColorPair(Green,Black), [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black), [PROCESS] = A_NORMAL, @@ -173,9 +174,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = A_NORMAL, [METER_VALUE] = A_BOLD, [METER_VALUE_ERROR] = A_BOLD, - [METER_VALUE_NOTICE] = A_BOLD, [METER_VALUE_IOREAD] = A_NORMAL, [METER_VALUE_IOWRITE] = A_NORMAL, + [METER_VALUE_NOTICE] = A_BOLD, + [METER_VALUE_OK] = A_NORMAL, [LED_COLOR] = A_NORMAL, [TASKS_RUNNING] = A_BOLD, [PROCESS] = A_NORMAL, @@ -251,9 +253,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Blue,White), [METER_VALUE] = ColorPair(Black,White), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,White), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,White), [METER_VALUE_IOREAD] = ColorPair(Green,White), [METER_VALUE_IOWRITE] = ColorPair(Yellow,White), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,White), + [METER_VALUE_OK] = ColorPair(Green,White), [LED_COLOR] = ColorPair(Green,White), [TASKS_RUNNING] = ColorPair(Green,White), [PROCESS] = ColorPair(Black,White), @@ -329,9 +332,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Blue,Black), [METER_VALUE] = ColorPair(Blue,Black), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), [METER_VALUE_IOREAD] = ColorPair(Green,Black), [METER_VALUE_IOWRITE] = ColorPair(Yellow,Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), + [METER_VALUE_OK] = ColorPair(Green,Black), [LED_COLOR] = ColorPair(Green,Black), [TASKS_RUNNING] = ColorPair(Green,Black), [PROCESS] = ColorPair(Blue,Black), @@ -407,9 +411,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Cyan,Blue), [METER_VALUE] = A_BOLD | ColorPair(Cyan,Blue), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Blue), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Blue), [METER_VALUE_IOREAD] = ColorPair(Green,Blue), [METER_VALUE_IOWRITE] = ColorPair(Black,Blue), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Blue), + [METER_VALUE_OK] = ColorPair(Green,Blue), [LED_COLOR] = ColorPair(Green,Blue), [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Blue), [PROCESS] = ColorPair(White,Blue), @@ -485,9 +490,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Cyan,Black), [METER_VALUE] = ColorPair(Green,Black), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), [METER_VALUE_IOREAD] = ColorPair(Green,Black), [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), + [METER_VALUE_OK] = ColorPair(Green,Black), [LED_COLOR] = ColorPair(Green,Black), [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black), [PROCESS] = ColorPair(Cyan,Black), diff --git a/CRT.h b/CRT.h index 49ed4ed0c..9186a131d 100644 --- a/CRT.h +++ b/CRT.h @@ -53,9 +53,10 @@ typedef enum ColorElements_ { METER_TEXT, METER_VALUE, METER_VALUE_ERROR, - METER_VALUE_NOTICE, METER_VALUE_IOREAD, METER_VALUE_IOWRITE, + METER_VALUE_NOTICE, + METER_VALUE_OK, LED_COLOR, UPTIME, BATTERY, diff --git a/Makefile.am b/Makefile.am index a6629f6d9..f8a5c9089 100644 --- a/Makefile.am +++ b/Makefile.am @@ -130,6 +130,7 @@ linux_platform_headers = \ linux/Platform.h \ linux/PressureStallMeter.h \ linux/SELinuxMeter.h \ + linux/SystemdMeter.h \ linux/ZramMeter.h \ linux/ZramStats.h \ zfs/ZfsArcMeter.h \ @@ -146,6 +147,7 @@ myhtopplatsources = \ linux/Platform.c \ linux/PressureStallMeter.c \ linux/SELinuxMeter.c \ + linux/SystemdMeter.c \ linux/ZramMeter.c \ zfs/ZfsArcMeter.c \ zfs/ZfsArcStats.c \ diff --git a/configure.ac b/configure.ac index b70a509f5..80c4f0757 100644 --- a/configure.ac +++ b/configure.ac @@ -90,6 +90,8 @@ AC_FUNC_CLOSEDIR_VOID AC_FUNC_STAT AC_CHECK_FUNCS([fstatat memmove strncasecmp strstr strdup]) +AC_SEARCH_LIBS([dlopen], [dl dld]) + save_cflags="${CFLAGS}" CFLAGS="${CFLAGS} -std=c99" AC_MSG_CHECKING([whether cc -std=c99 option works]) diff --git a/linux/Platform.c b/linux/Platform.c index f7a768c9b..5b55588be 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -39,6 +39,7 @@ in the source distribution for its full text. #include "SELinuxMeter.h" #include "Settings.h" #include "SwapMeter.h" +#include "SystemdMeter.h" #include "TasksMeter.h" #include "UptimeMeter.h" #include "XUtils.h" @@ -153,6 +154,7 @@ const MeterClass* const Platform_meterTypes[] = { &DiskIOMeter_class, &NetworkIOMeter_class, &SELinuxMeter_class, + &SystemdMeter_class, NULL }; diff --git a/linux/SystemdMeter.c b/linux/SystemdMeter.c new file mode 100644 index 000000000..368d5ccaf --- /dev/null +++ b/linux/SystemdMeter.c @@ -0,0 +1,329 @@ +/* +htop - SystemdMeter.c +(C) 2020 Christian Göttsche +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "SystemdMeter.h" + +#include +#include +#include +#include +#include +#include + +#include "CRT.h" +#include "XUtils.h" + + +#define INVALID_VALUE ((unsigned int)-1) + +typedef void sd_bus; +typedef void sd_bus_error; +static int (*sym_sd_bus_open_system)(sd_bus**); +static int (*sym_sd_bus_get_property_string)(sd_bus*, const char*, const char*, const char*, const char*, sd_bus_error*, char**); +static int (*sym_sd_bus_get_property_trivial)(sd_bus*, const char*, const char*, const char*, const char*, sd_bus_error*, char, void*); +static sd_bus* (*sym_sd_bus_unref)(sd_bus*); + +static char* systemState = NULL; +static unsigned int nFailedUnits = INVALID_VALUE; +static unsigned int nInstalledJobs = INVALID_VALUE; +static unsigned int nNames = INVALID_VALUE; +static unsigned int nJobs = INVALID_VALUE; +static void* dlopenHandle = NULL; +static sd_bus* bus = NULL; + +static void SystemdMeter_done(ATTR_UNUSED Meter* this) { + free(systemState); + systemState = NULL; + + if (bus && dlopenHandle) { + sym_sd_bus_unref(bus); + } + bus = NULL; + + if (dlopenHandle) { + dlclose(dlopenHandle); + dlopenHandle = NULL; + } +} + +static int updateViaLib(void) { + if (!dlopenHandle) { + dlopenHandle = dlopen("libsystemd.so.0", RTLD_LAZY); + if (!dlopenHandle) + goto dlfailure; + + /* Clear any errors */ + dlerror(); + + #define resolve(symbolname) do { \ + *(void **)(&sym_##symbolname) = dlsym(dlopenHandle, #symbolname); \ + if (!sym_##symbolname || dlerror() != NULL) \ + goto dlfailure; \ + } while(0) + + resolve(sd_bus_open_system); + resolve(sd_bus_get_property_string); + resolve(sd_bus_get_property_trivial); + resolve(sd_bus_unref); + + #undef resolve + } + + int r; + + /* Connect to the system bus */ + if (!bus) { + r = sym_sd_bus_open_system(&bus); + if (r < 0) + goto busfailure; + } + + static const char* const busServiceName = "org.freedesktop.systemd1"; + static const char* const busObjectPath = "/org/freedesktop/systemd1"; + static const char* const busInterfaceName = "org.freedesktop.systemd1.Manager"; + + r = sym_sd_bus_get_property_string(bus, + busServiceName, /* service to contact */ + busObjectPath, /* object path */ + busInterfaceName, /* interface name */ + "SystemState", /* property name */ + NULL, /* object to return error in */ + &systemState); + if (r < 0) + goto busfailure; + + r = sym_sd_bus_get_property_trivial(bus, + busServiceName, /* service to contact */ + busObjectPath, /* object path */ + busInterfaceName, /* interface name */ + "NFailedUnits", /* property name */ + NULL, /* object to return error in */ + 'u', /* property type */ + &nFailedUnits); + if (r < 0) + goto busfailure; + + r = sym_sd_bus_get_property_trivial(bus, + busServiceName, /* service to contact */ + busObjectPath, /* object path */ + busInterfaceName, /* interface name */ + "NInstalledJobs", /* property name */ + NULL, /* object to return error in */ + 'u', /* property type */ + &nInstalledJobs); + if (r < 0) + goto busfailure; + + r = sym_sd_bus_get_property_trivial(bus, + busServiceName, /* service to contact */ + busObjectPath, /* object path */ + busInterfaceName, /* interface name */ + "NNames", /* property name */ + NULL, /* object to return error in */ + 'u', /* property type */ + &nNames); + if (r < 0) + goto busfailure; + + r = sym_sd_bus_get_property_trivial(bus, + busServiceName, /* service to contact */ + busObjectPath, /* object path */ + busInterfaceName, /* interface name */ + "NJobs", /* property name */ + NULL, /* object to return error in */ + 'u', /* property type */ + &nJobs); + if (r < 0) + goto busfailure; + + /* success */ + return 0; + +busfailure: + sym_sd_bus_unref(bus); + bus = NULL; + return -2; + +dlfailure: + if (dlopenHandle) { + dlclose(dlopenHandle); + dlopenHandle = NULL; + } + return -1; +} + +static void updateViaExec(void) { + int fdpair[2]; + if (pipe(fdpair) < 0) + return; + + pid_t child = fork(); + if (child < 0) { + close(fdpair[1]); + close(fdpair[0]); + return; + } + + if (child == 0) { + close(fdpair[0]); + dup2(fdpair[1], STDOUT_FILENO); + close(fdpair[1]); + int fdnull = open("/dev/null", O_WRONLY); + if (fdnull < 0) + exit(1); + dup2(fdnull, STDERR_FILENO); + close(fdnull); + execl("/bin/systemctl", + "/bin/systemctl", + "show", + "--property=SystemState", + "--property=NFailedUnits", + "--property=NNames", + "--property=NJobs", + "--property=NInstalledJobs", + NULL); + exit(127); + } + close(fdpair[1]); + + int wstatus; + if (waitpid(child, &wstatus, 0) < 0 || !WIFEXITED(wstatus) || WEXITSTATUS(wstatus) != 0) { + close(fdpair[0]); + return; + } + + FILE* commandOutput = fdopen(fdpair[0], "r"); + if (!commandOutput) { + close(fdpair[0]); + return; + } + + char lineBuffer[128]; + while (fgets(lineBuffer, sizeof(lineBuffer), commandOutput)) { + if (String_startsWith(lineBuffer, "SystemState=")) { + char* newline = strchr(lineBuffer + strlen("SystemState="), '\n'); + if (newline) + *newline = '\0'; + systemState = xStrdup(lineBuffer + strlen("SystemState=")); + } else if (String_startsWith(lineBuffer, "NFailedUnits=")) { + nFailedUnits = strtoul(lineBuffer + strlen("NFailedUnits="), NULL, 10); + } else if (String_startsWith(lineBuffer, "NNames=")) { + nNames = strtoul(lineBuffer + strlen("NNames="), NULL, 10); + } else if (String_startsWith(lineBuffer, "NJobs=")) { + nJobs = strtoul(lineBuffer + strlen("NJobs="), NULL, 10); + } else if (String_startsWith(lineBuffer, "NInstalledJobs=")) { + nInstalledJobs = strtoul(lineBuffer + strlen("NInstalledJobs="), NULL, 10); + } + } + + fclose(commandOutput); +} + +static void SystemdMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, int size) { + free(systemState); + systemState = NULL; + nFailedUnits = nInstalledJobs = nNames = nJobs = INVALID_VALUE; + + if (updateViaLib() < 0) + updateViaExec(); + + xSnprintf(buffer, size, "%s", systemState ? systemState : "???"); +} + +static int zeroDigitColor(unsigned int value) { + switch (value) { + case 0: + return CRT_colors[METER_VALUE]; + case INVALID_VALUE: + return CRT_colors[METER_VALUE_ERROR]; + default: + return CRT_colors[METER_VALUE_NOTICE]; + } +} + +static int valueDigitColor(unsigned int value) { + switch (value) { + case 0: + return CRT_colors[METER_VALUE_NOTICE]; + case INVALID_VALUE: + return CRT_colors[METER_VALUE_ERROR]; + default: + return CRT_colors[METER_VALUE]; + } +} + + +static void SystemdMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { + char buffer[16]; + + int color = (systemState && 0 == strcmp(systemState, "running")) ? METER_VALUE_OK : METER_VALUE_ERROR; + RichString_write(out, CRT_colors[color], systemState ? systemState : "???"); + + RichString_append(out, CRT_colors[METER_TEXT], " ("); + + if (nFailedUnits == INVALID_VALUE) { + buffer[0] = '?'; + buffer[1] = '\0'; + } else { + xSnprintf(buffer, sizeof(buffer), "%u", nFailedUnits); + } + RichString_append(out, zeroDigitColor(nFailedUnits), buffer); + + RichString_append(out, CRT_colors[METER_TEXT], "/"); + + if (nNames == INVALID_VALUE) { + buffer[0] = '?'; + buffer[1] = '\0'; + } else { + xSnprintf(buffer, sizeof(buffer), "%u", nNames); + } + RichString_append(out, valueDigitColor(nNames), buffer); + + RichString_append(out, CRT_colors[METER_TEXT], " failed) ("); + + if (nJobs == INVALID_VALUE) { + buffer[0] = '?'; + buffer[1] = '\0'; + } else { + xSnprintf(buffer, sizeof(buffer), "%u", nJobs); + } + RichString_append(out, zeroDigitColor(nJobs), buffer); + + RichString_append(out, CRT_colors[METER_TEXT], "/"); + + if (nInstalledJobs == INVALID_VALUE) { + buffer[0] = '?'; + buffer[1] = '\0'; + } else { + xSnprintf(buffer, sizeof(buffer), "%u", nInstalledJobs); + } + RichString_append(out, valueDigitColor(nInstalledJobs), buffer); + + RichString_append(out, CRT_colors[METER_TEXT], " jobs)"); +} + +static const int SystemdMeter_attributes[] = { + METER_VALUE +}; + +const MeterClass SystemdMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = SystemdMeter_display + }, + .updateValues = SystemdMeter_updateValues, + .done = SystemdMeter_done, + .defaultMode = TEXT_METERMODE, + .maxItems = 0, + .total = 100.0, + .attributes = SystemdMeter_attributes, + .name = "Systemd", + .uiName = "Systemd state", + .description = "Systemd system state and unit overview", + .caption = "Systemd: ", +}; diff --git a/linux/SystemdMeter.h b/linux/SystemdMeter.h new file mode 100644 index 000000000..6ab4834de --- /dev/null +++ b/linux/SystemdMeter.h @@ -0,0 +1,15 @@ +#ifndef HEADER_SystemdMeter +#define HEADER_SystemdMeter + +/* +htop - SystemdMeter.h +(C) 2020 Christian Göttsche +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern const MeterClass SystemdMeter_class; + +#endif /* HEADER_SystemdMeter */ From 15652e7b8102e86b3405254405d8ee5d2a239004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 31 Oct 2020 19:39:32 +0100 Subject: [PATCH 370/411] Enclose macro arguments in parentheses --- RichString.h | 2 +- linux/LinuxProcessList.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RichString.h b/RichString.h index 48c1e7491..aab2d8916 100644 --- a/RichString.h +++ b/RichString.h @@ -27,7 +27,7 @@ in the source distribution for its full text. #define CharType cchar_t #else #define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr) -#define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + off, n) +#define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i]) #define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = ch; } while(0) #define CharType chtype diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index f32aba417..5e06e8c99 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -778,8 +778,8 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { assert(lp->super.pid == (pid_t)stats.ac_pid); timeDelta = (stats.ac_etime*1000 - lp->delay_read_time); - #define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x; - #define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100); + #define BOUNDS(x) isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x); + #define DELTAPERC(x,y) BOUNDS((float) ((x) - (y)) / timeDelta * 100); lp->cpu_delay_percent = DELTAPERC(stats.cpu_delay_total, lp->cpu_delay_total); lp->blkio_delay_percent = DELTAPERC(stats.blkio_delay_total, lp->blkio_delay_total); lp->swapin_delay_percent = DELTAPERC(stats.swapin_delay_total, lp->swapin_delay_total); From a83f515f0fb75a079601be0d2e0e24b9402c9e15 Mon Sep 17 00:00:00 2001 From: Adam Saponara Date: Sat, 31 Oct 2020 20:36:53 -0400 Subject: [PATCH 371/411] Address items from review --- Process.c | 12 ++++++------ Process.h | 3 ++- ProcessList.c | 4 +++- Settings.c | 1 + htop.c | 7 ++++--- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Process.c b/Process.c index f78720a50..d3e6f4c69 100644 --- a/Process.c +++ b/Process.c @@ -6,7 +6,6 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ - #include "config.h" // IWYU pragma: keep #include "Process.h" @@ -383,10 +382,10 @@ void Process_display(const Object* cast, RichString* out) { if (this->tag == true) RichString_setAttr(out, CRT_colors[PROCESS_TAG]); if (this->settings->highlightChanges) { - if (Process_isNew(this)) - out->highlightAttr = CRT_colors[PROCESS_NEW]; if (Process_isTomb(this)) out->highlightAttr = CRT_colors[PROCESS_TOMB]; + else if (Process_isNew(this)) + out->highlightAttr = CRT_colors[PROCESS_NEW]; } assert(out->chlen > 0); } @@ -421,13 +420,14 @@ void Process_toggleTag(Process* this) { } bool Process_isNew(const Process* this) { - if (this->processList && this->processList->scanTs >= this->seenTs) - return (this->processList->scanTs - this->seenTs <= this->processList->settings->highlightDelaySecs); + assert(this->processList); + if (this->processList->scanTs >= this->seenTs) + return this->processList->scanTs - this->seenTs <= this->processList->settings->highlightDelaySecs; return false; } bool Process_isTomb(const Process* this) { - return (this->tombTs > 0); + return this->tombTs > 0; } bool Process_setPriority(Process* this, int priority) { diff --git a/Process.h b/Process.h index e3ff333fa..c75ee501d 100644 --- a/Process.h +++ b/Process.h @@ -9,8 +9,8 @@ in the source distribution for its full text. */ #include -#include #include +#include #include "Object.h" #include "RichString.h" @@ -78,6 +78,7 @@ typedef struct Process_ { bool tag; bool showChildren; bool show; + bool wasShown; unsigned int pgrp; unsigned int session; unsigned int tty_nr; diff --git a/ProcessList.c b/ProcessList.c index 1ae7b9cc4..364de1e01 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -14,6 +14,7 @@ in the source distribution for its full text. #include "CRT.h" #include "XUtils.h" + ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { this->processes = Vector_new(klass, true, DEFAULT_SIZE); this->processTable = Hashtable_new(140, false); @@ -306,6 +307,7 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { for (int i = 0; i < Vector_size(this->processes); i++) { Process* p = (Process*) Vector_get(this->processes, i); p->updated = false; + p->wasShown = p->show; p->show = true; } @@ -334,7 +336,7 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { } } else if (p->updated == false) { // process no longer exists - if (this->settings->highlightChanges) { + if (this->settings->highlightChanges && p->wasShown) { // mark tombed p->tombTs = this->scanTs + this->settings->highlightDelaySecs; } else { diff --git a/Settings.c b/Settings.c index a0a05042d..8310eecba 100644 --- a/Settings.c +++ b/Settings.c @@ -313,6 +313,7 @@ Settings* Settings_new(int initialCpuCount) { this->updateProcessNames = false; this->showProgramPath = true; this->highlightThreads = true; + this->highlightChanges = false; this->highlightDelaySecs = DEFAULT_HIGHLIGHT_SECS; #ifdef HAVE_LIBHWLOC this->topologyAffinity = false; diff --git a/htop.c b/htop.c index 351f58672..48c6f8d01 100644 --- a/htop.c +++ b/htop.c @@ -50,14 +50,14 @@ static void printHelpFlag(void) { "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" "-F --filter=FILTER Show only the commands matching the given filter\n" "-h --help Print this help screen\n" + "-H --highlight-changes[=DELAY] Highlight new and old processes\n" "-M --no-mouse Disable the mouse\n" - "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n" + "-p --pid=PID[,PID,PID...] Show only the given PIDs\n" "-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n" "-t --tree Show the tree view by default\n" "-u --user[=USERNAME] Show only processes for a given user (or $USER)\n" "-U --no-unicode Do not use unicode but plain ASCII\n" "-V --version Print version info\n" - "-H --highlight-changes[=DELAY] Highlight new and old processes\n" "\n" "Long options may be passed with a single dash.\n\n" "Press F1 inside htop for online help.\n" @@ -212,7 +212,8 @@ static CommandLineSettings parseArguments(int argc, char** argv) { } if (delay) { if (sscanf(delay, "%16d", &(flags.highlightDelaySecs)) == 1) { - if (flags.highlightDelaySecs < 1) flags.highlightDelaySecs = 1; + if (flags.highlightDelaySecs < 1) + flags.highlightDelaySecs = 1; } else { fprintf(stderr, "Error: invalid highlight delay value \"%s\".\n", delay); exit(1); From 0c1908832b50886cd1fa4ea296aa2570625bfa15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 2 Nov 2020 14:46:42 +0100 Subject: [PATCH 372/411] Handle data wraparounds in IO Meters If the current data is smaller than the previous one, either by a retrieve error or a device removal or a original data wraparound, sanitize the value to zero. Fixes: #299 --- DiskIOMeter.c | 19 +++++++++++++++---- NetworkIOMeter.c | 28 ++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 21696a339..e2d025247 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -53,14 +53,25 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) { return; } - cached_read_diff = (data.totalBytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + if (data.totalBytesRead > cached_read_total) { + cached_read_diff = (data.totalBytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + } else { + cached_read_diff = 0; + } cached_read_total = data.totalBytesRead; - cached_write_diff = (data.totalBytesWritten - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + if (data.totalBytesWritten > cached_write_total) { + cached_write_diff = (data.totalBytesWritten - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + } else { + cached_write_diff = 0; + } cached_write_total = data.totalBytesWritten; - cached_utilisation_diff = 100 * (double)(data.totalMsTimeSpend - cached_msTimeSpend_total) / passedTimeInMs; - + if (data.totalMsTimeSpend > cached_msTimeSpend_total) { + cached_utilisation_diff = 100 * (double)(data.totalMsTimeSpend - cached_msTimeSpend_total) / passedTimeInMs; + } else { + cached_utilisation_diff = 0.0; + } cached_msTimeSpend_total = data.totalMsTimeSpend; } diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c index 51d8d5ca0..a13e3f1ca 100644 --- a/NetworkIOMeter.c +++ b/NetworkIOMeter.c @@ -46,18 +46,34 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i return; } - cached_rxb_diff = (bytesReceived - cached_rxb_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ - cached_rxb_diff = 1000.0 * cached_rxb_diff / passedTimeInMs; /* convert to per second */ + if (bytesReceived > cached_rxb_total) { + cached_rxb_diff = (bytesReceived - cached_rxb_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + cached_rxb_diff = 1000.0 * cached_rxb_diff / passedTimeInMs; /* convert to per second */ + } else { + cached_rxb_diff = 0; + } cached_rxb_total = bytesReceived; - cached_rxp_diff = packetsReceived - cached_rxp_total; + if (packetsReceived > cached_rxp_total) { + cached_rxp_diff = packetsReceived - cached_rxp_total; + } else { + cached_rxp_diff = 0; + } cached_rxp_total = packetsReceived; - cached_txb_diff = (bytesTransmitted - cached_txb_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ - cached_txb_diff = 1000.0 * cached_txb_diff / passedTimeInMs; /* convert to per second */ + if (bytesTransmitted > cached_txb_total) { + cached_txb_diff = (bytesTransmitted - cached_txb_total) / 1024; /* Meter_humanUnit() expects unit in kilo */ + cached_txb_diff = 1000.0 * cached_txb_diff / passedTimeInMs; /* convert to per second */ + } else { + cached_txb_diff = 0; + } cached_txb_total = bytesTransmitted; - cached_txp_diff = packetsTransmitted - cached_txp_total; + if (packetsTransmitted > cached_txp_total) { + cached_txp_diff = packetsTransmitted - cached_txp_total; + } else { + cached_txp_diff = 0; + } cached_txp_total = packetsTransmitted; } From 0806a7958b5b5ee29da043d3e4f3f854c164059d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 31 Oct 2020 20:57:22 +0100 Subject: [PATCH 373/411] Assert Vector_get returns an object It is generally assumed Vector_get returns a non-NULL object. Use a generic assert in Vector_get instead of in callers. --- Panel.c | 2 -- Vector.c | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Panel.c b/Panel.c index 02440d85c..ab3f60090 100644 --- a/Panel.c +++ b/Panel.c @@ -261,7 +261,6 @@ void Panel_draw(Panel* this, bool focus) { int line = 0; for(int i = first; line < h && i < upTo; i++) { Object* itemObj = Vector_get(this->items, i); - assert(itemObj); if(!itemObj) continue; RichString_begin(item); Object_display(itemObj, &item); int itemLen = RichString_sizeVal(item); @@ -288,7 +287,6 @@ void Panel_draw(Panel* this, bool focus) { } else { Object* oldObj = Vector_get(this->items, this->oldSelected); - assert(oldObj); RichString_begin(old); Object_display(oldObj, &old); int oldLen = RichString_sizeVal(old); diff --git a/Vector.c b/Vector.c index 77f56a888..63b647237 100644 --- a/Vector.c +++ b/Vector.c @@ -65,8 +65,9 @@ int Vector_count(const Vector* this) { } Object* Vector_get(Vector* this, int idx) { - assert(idx < this->items); + assert(idx >= 0 && idx < this->items); assert(Vector_isConsistent(this)); + assert(this->array[idx]); return this->array[idx]; } From 7ab0915a6c8bab76273085ac563102e7ef8a6756 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:08:44 +0100 Subject: [PATCH 374/411] Remove unnecessary trailing semicolon on macros --- Object.h | 2 +- RichString.h | 6 +++--- linux/LinuxProcessList.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Object.h b/Object.h index caa3e9199..05a9a72db 100644 --- a/Object.h +++ b/Object.h @@ -33,7 +33,7 @@ typedef void(*Object_Delete)(Object*); #define Class(class_) ((const ObjectClass*)(&(class_ ## _class))) -#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); +#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)) typedef struct ObjectClass_ { const void* const extends; diff --git a/RichString.h b/RichString.h index aab2d8916..3fb85279f 100644 --- a/RichString.h +++ b/RichString.h @@ -15,9 +15,9 @@ in the source distribution for its full text. #define RichString_size(this) ((this)->chlen) #define RichString_sizeVal(this) ((this).chlen) -#define RichString_begin(this) RichString (this); RichString_beginAllocated(this); -#define RichString_beginAllocated(this) memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr; -#define RichString_end(this) RichString_prune(&(this)); +#define RichString_begin(this) RichString (this); RichString_beginAllocated(this) +#define RichString_beginAllocated(this) memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr +#define RichString_end(this) RichString_prune(&(this)) #ifdef HAVE_LIBNCURSESW #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5e06e8c99..d40249fc2 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -778,8 +778,8 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { assert(lp->super.pid == (pid_t)stats.ac_pid); timeDelta = (stats.ac_etime*1000 - lp->delay_read_time); - #define BOUNDS(x) isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x); - #define DELTAPERC(x,y) BOUNDS((float) ((x) - (y)) / timeDelta * 100); + #define BOUNDS(x) isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x) + #define DELTAPERC(x,y) BOUNDS((float) ((x) - (y)) / timeDelta * 100) lp->cpu_delay_percent = DELTAPERC(stats.cpu_delay_total, lp->cpu_delay_total); lp->blkio_delay_percent = DELTAPERC(stats.blkio_delay_total, lp->blkio_delay_total); lp->swapin_delay_percent = DELTAPERC(stats.swapin_delay_total, lp->swapin_delay_total); From c790b6ae67cc4af9f8b4dbba2e4590d36523f2a9 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:18:40 +0100 Subject: [PATCH 375/411] Remove accidental syntax collision --- linux/LinuxProcessList.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index d40249fc2..577412a9f 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1111,7 +1111,12 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { char buffer[128]; while (fgets(buffer, 128, file)) { - #define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %32llu kB", variable)) { break; } } while(0) + #define tryRead(label, variable) \ + if (String_startsWith(buffer, label)) { \ + sscanf(buffer + strlen(label), " %32llu kB", variable); \ + break; \ + } + switch (buffer[0]) { case 'M': tryRead("MemTotal:", &this->totalMem); @@ -1208,8 +1213,17 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { } char buffer[128]; while (fgets(buffer, 128, file)) { - #define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { break; } } while(0) - #define tryReadFlag(label, variable, flag) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { (flag) = 1; break; } else { (flag) = 0; } } while(0) + #define tryRead(label, variable) \ + if (String_startsWith(buffer, label)) { \ + sscanf(buffer + strlen(label), " %*2u %32llu", variable); \ + break; \ + } + #define tryReadFlag(label, variable, flag) \ + if (String_startsWith(buffer, label)) { \ + (flag) = sscanf(buffer + strlen(label), " %*2u %32llu", variable); \ + break; \ + } + switch (buffer[0]) { case 'c': tryRead("c_max", &lpl->zfs.max); From db0a13970ed512a75ade9770f0a1aa468f657f8b Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:26:53 +0100 Subject: [PATCH 376/411] Convert addattrstr to static inline function NB: The macro could have been a braced while(0) loop, which without optimization produces more code --- Action.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Action.c b/Action.c index 5b68811ef..303eeeafe 100644 --- a/Action.c +++ b/Action.c @@ -443,6 +443,11 @@ static const struct { const char* key; const char* info; } helpRight[] = { { .key = NULL, .info = NULL } }; +static inline void addattrstr( int attr, const char* str) { + attrset(attr); + addstr(str); +} + static Htop_Reaction actionHelp(State* st) { Settings* settings = st->settings; @@ -460,7 +465,7 @@ static Htop_Reaction actionHelp(State* st) { attrset(CRT_colors[DEFAULT_COLOR]); line++; mvaddstr(line++, 0, "CPU usage bar: "); - #define addattrstr(a,s) attrset(a);addstr(s) + addattrstr(CRT_colors[BAR_BORDER], "["); if (settings->detailedCPUTime) { addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/"); From 1877325329b282ce59d8d6733b3728913cb2c6b2 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:33:01 +0100 Subject: [PATCH 377/411] Spacing after keywords (#define) --- Panel.h | 2 +- RichString.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Panel.h b/Panel.h index ec670ab54..1ada9243d 100644 --- a/Panel.h +++ b/Panel.h @@ -61,7 +61,7 @@ struct Panel_ { int selectionColor; }; -#define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0) +#define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while(0) #define KEY_CTRL(l) ((l)-'A'+1) diff --git a/RichString.h b/RichString.h index 3fb85279f..d360299eb 100644 --- a/RichString.h +++ b/RichString.h @@ -23,13 +23,13 @@ in the source distribution for its full text. #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) #define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255) -#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) +#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) #define CharType cchar_t #else #define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr) #define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i]) -#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = ch; } while(0) +#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = ch; } while(0) #define CharType chtype #endif From 0a51eae11fdd741c295d7b0390c6d9dbf04468d8 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:39:01 +0100 Subject: [PATCH 378/411] Spacing after keywords (while) --- Panel.h | 2 +- RichString.h | 4 ++-- darwin/Platform.c | 4 ++-- htop.c | 4 ++-- linux/LinuxProcessList.c | 14 +++++++------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Panel.h b/Panel.h index 1ada9243d..604750a58 100644 --- a/Panel.h +++ b/Panel.h @@ -61,7 +61,7 @@ struct Panel_ { int selectionColor; }; -#define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while(0) +#define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while (0) #define KEY_CTRL(l) ((l)-'A'+1) diff --git a/RichString.h b/RichString.h index d360299eb..11be41372 100644 --- a/RichString.h +++ b/RichString.h @@ -23,13 +23,13 @@ in the source distribution for its full text. #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) #define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255) -#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) +#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while (0) #define CharType cchar_t #else #define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr) #define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i]) -#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = ch; } while(0) +#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = ch; } while (0) #define CharType chtype #endif diff --git a/darwin/Platform.c b/darwin/Platform.c index b1f9283d8..17be92b2b 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -286,7 +286,7 @@ char* Platform_getProcessEnv(pid_t pid) { p = strchr(p, 0)+1; // skip padding - while(!*p && p < endp) + while (!*p && p < endp) ++p; // skip argv @@ -294,7 +294,7 @@ char* Platform_getProcessEnv(pid_t pid) { ; // skip padding - while(!*p && p < endp) + while (!*p && p < endp) ++p; size_t size = endp - p; diff --git a/htop.c b/htop.c index e02f388ab..f5c35929d 100644 --- a/htop.c +++ b/htop.c @@ -190,7 +190,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { flags.pidMatchList = Hashtable_new(8, false); } - while(pid) { + while (pid) { unsigned int num_pid = atoi(pid); // deepcode ignore CastIntegerToAddress: we just want a non-NUll pointer here Hashtable_put(flags.pidMatchList, num_pid, (void *) 1); @@ -218,7 +218,7 @@ static void millisleep(unsigned long millisec) { .tv_sec = 0, .tv_nsec = millisec * 1000000L }; - while(nanosleep(&req,&req)==-1) { + while (nanosleep(&req,&req)==-1) { continue; } } diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 577412a9f..e500f9dc0 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -165,7 +165,7 @@ static int LinuxProcessList_computeCPUcount(void) { int cpus = 0; char buffer[PROC_LINE_LENGTH + 1]; - while(fgets(buffer, sizeof(buffer), file)) { + while (fgets(buffer, sizeof(buffer), file)) { if (String_startsWith(buffer, "cpu")) cpus++; } @@ -221,7 +221,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui if (statfile == NULL) CRT_fatalError("Cannot open " PROCSTATFILE); - while(true) { + while (true) { char buffer[PROC_LINE_LENGTH + 1]; if (fgets(buffer, sizeof(buffer), statfile) == NULL) { CRT_fatalError("No btime in " PROCSTATFILE); @@ -498,7 +498,7 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di while (fgets(buffer, sizeof(buffer), f)) { if(!strchr(buffer, '\n')) { // Partial line, skip to end of this line - while(fgets(buffer, sizeof(buffer), f)) { + while (fgets(buffer, sizeof(buffer), f)) { if(strchr(buffer, '\n')) { break; } @@ -542,10 +542,10 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d bool foundEnvID = false; bool foundVPid = false; char linebuf[256]; - while(fgets(linebuf, sizeof(linebuf), file) != NULL) { + while (fgets(linebuf, sizeof(linebuf), file) != NULL) { if(strchr(linebuf, '\n') == NULL) { // Partial line, skip to end of this line - while(fgets(linebuf, sizeof(linebuf), file) != NULL) { + while (fgets(linebuf, sizeof(linebuf), file) != NULL) { if(strchr(linebuf, '\n') != NULL) { break; } @@ -569,11 +569,11 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d do { name_value_sep++; - } while(*name_value_sep != '\0' && *name_value_sep <= 32); + } while (*name_value_sep != '\0' && *name_value_sep <= 32); char* value_end = name_value_sep; - while(*value_end != '\0' && *value_end > 32) { + while (*value_end != '\0' && *value_end > 32) { value_end++; } From 374edb9ed5e9d5fa24cfe358258d82f69d9d430d Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:52:20 +0100 Subject: [PATCH 379/411] Spacing after keywords (if) --- CRT.c | 4 ++-- Process.c | 2 +- TraceScreen.c | 4 ++-- Vector.c | 4 ++-- darwin/Battery.c | 10 ++++---- darwin/DarwinProcess.c | 6 ++--- darwin/DarwinProcessList.c | 10 ++++---- darwin/Platform.c | 2 +- dragonflybsd/DragonFlyBSDProcessList.c | 4 ++-- freebsd/FreeBSDProcessList.c | 4 ++-- htop.c | 6 ++--- linux/LinuxProcess.c | 6 ++--- linux/LinuxProcessList.c | 32 +++++++++++++------------- linux/Platform.c | 2 +- linux/ZramMeter.c | 6 ++--- solaris/SolarisProcessList.c | 2 +- 16 files changed, 52 insertions(+), 52 deletions(-) diff --git a/CRT.c b/CRT.c index a13f531a9..d91d0d79f 100644 --- a/CRT.c +++ b/CRT.c @@ -770,7 +770,7 @@ void CRT_handleSIGSEGV(int signal) { ); const char* signal_str = strsignal(signal); - if(!signal_str) { + if (!signal_str) { signal_str = "unknown reason"; } fprintf(stderr, @@ -821,7 +821,7 @@ void CRT_handleSIGSEGV(int signal) { ); /* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */ - if(sigaction (signal, &old_sig_handler[signal], NULL) < 0) { + if (sigaction (signal, &old_sig_handler[signal], NULL) < 0) { /* This avoids an infinite loop in case the handler could not be reset. */ fprintf(stderr, "!!! Chained handler could not be restored. Forcing exit.\n" diff --git a/Process.c b/Process.c index 842232f70..bbc85ce1a 100644 --- a/Process.c +++ b/Process.c @@ -325,7 +325,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field case PID: xSnprintf(buffer, n, Process_pidFormat, this->pid); break; case PPID: xSnprintf(buffer, n, Process_pidFormat, this->ppid); break; case PRIORITY: { - if(this->priority <= -100) + if (this->priority <= -100) xSnprintf(buffer, n, " RT "); else xSnprintf(buffer, n, "%3ld ", this->priority); diff --git a/TraceScreen.c b/TraceScreen.c index e83e8a513..18dad58cd 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -81,10 +81,10 @@ bool TraceScreen_forkTracer(TraceScreen* this) { if (pipe(fdpair) == -1) return false; - if(fcntl(fdpair[0], F_SETFL, O_NONBLOCK) < 0) + if (fcntl(fdpair[0], F_SETFL, O_NONBLOCK) < 0) goto err; - if(fcntl(fdpair[1], F_SETFL, O_NONBLOCK) < 0) + if (fcntl(fdpair[1], F_SETFL, O_NONBLOCK) < 0) goto err; pid_t child = fork(); diff --git a/Vector.c b/Vector.c index 63b647237..ea276671c 100644 --- a/Vector.c +++ b/Vector.c @@ -201,7 +201,7 @@ void Vector_insert(Vector* this, int idx, void* data_) { Vector_checkArraySize(this); //assert(this->array[this->items] == NULL); - if(idx < this->items) { + if (idx < this->items) { memmove(&this->array[idx + 1], &this->array[idx], (this->items - idx) * sizeof(this->array[0])); } this->array[idx] = data; @@ -215,7 +215,7 @@ Object* Vector_take(Vector* this, int idx) { Object* removed = this->array[idx]; assert(removed); this->items--; - if(idx < this->items) { + if (idx < this->items) { memmove(&this->array[idx], &this->array[idx + 1], (this->items - idx) * sizeof(this->array[0])); } //this->array[this->items] = NULL; diff --git a/darwin/Battery.c b/darwin/Battery.c index d82d0ffd1..df644643f 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -13,7 +13,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { *level = NAN; *isOnAC = AC_ERROR; - if(NULL == power_sources) { + if (NULL == power_sources) { return; } @@ -21,7 +21,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFDictionaryRef battery = NULL; int len; - if(NULL == list) { + if (NULL == list) { CFRelease(power_sources); return; @@ -35,18 +35,18 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFArrayGetValueAtIndex(list, i)); /* GET rule */ CFStringRef type; - if(NULL != candidate) { + if (NULL != candidate) { type = (CFStringRef) CFDictionaryGetValue(candidate, CFSTR(kIOPSTransportTypeKey)); /* GET rule */ - if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { + if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { CFRetain(candidate); battery = candidate; } } } - if(NULL != battery) { + if (NULL != battery) { /* Determine the AC state */ CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 73214836f..8ad7a6d8d 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -212,7 +212,7 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e */ /* First, the "immutable" parts */ - if(!exists) { + if (!exists) { /* Set the PID/PGID/etc. */ proc->pid = ep->p_pid; proc->ppid = ps->kp_eproc.e_ppid; @@ -244,8 +244,8 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl) { struct proc_taskinfo pti; - if(sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { - if(0 != proc->utime || 0 != proc->stime) { + if (sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { + if (0 != proc->utime || 0 != proc->stime) { uint64_t diff = (pti.pti_total_system - proc->stime) + (pti.pti_total_user - proc->utime); diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index bae8e2227..59ec9d31e 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -57,14 +57,14 @@ int CompareKernelVersion(short int major, short int minor, short int component) void ProcessList_getHostInfo(host_basic_info_data_t *p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; - if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { + if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { CRT_fatalError("Unable to retrieve host info\n"); } } void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { - if(NULL != p && NULL != *p) { - if(0 != munmap(*p, vm_page_size)) { + if (NULL != p && NULL != *p) { + if (0 != munmap(*p, vm_page_size)) { CRT_fatalError("Unable to free old CPU load information\n"); } *p = NULL; @@ -76,7 +76,7 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { unsigned cpu_count; // TODO Improving the accuracy of the load counts woule help a lot. - if(0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) { + if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) { CRT_fatalError("Unable to retrieve CPU info\n"); } @@ -200,7 +200,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { super->totalTasks += 1; - if(!preExisting) { + if (!preExisting) { proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid); ProcessList_add(super, &proc->super); diff --git a/darwin/Platform.c b/darwin/Platform.c index 17be92b2b..a7adaeee2 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -149,7 +149,7 @@ int Platform_getUptime() { void Platform_getLoadAverage(double* one, double* five, double* fifteen) { double results[3]; - if(3 == getloadavg(results, 3)) { + if (3 == getloadavg(results, 3)) { *one = results[0]; *five = results[1]; *fifteen = results[2]; diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 8c441de5f..2fe20daee 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -417,7 +417,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid); } else { proc->processor = kproc->kp_lwp.kl_cpuid; - if(dfp->jid != kproc->kp_jailid) { // process can enter jail anytime + if (dfp->jid != kproc->kp_jailid) { // process can enter jail anytime dfp->jid = kproc->kp_jailid; free(dfp->jname); dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid); @@ -425,7 +425,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (proc->ppid != kproc->kp_ppid) { // if there are reapers in the system, process can get reparented anytime proc->ppid = kproc->kp_ppid; } - if(proc->st_uid != kproc->kp_uid) { // some processes change users (eg. to lower privs) + if (proc->st_uid != kproc->kp_uid) { // some processes change users (eg. to lower privs) proc->st_uid = kproc->kp_uid; proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); } diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index df06546cc..bfa046b84 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -502,7 +502,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { proc->comm = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->basenameOffset); fp->jname = FreeBSDProcessList_readJailName(kproc); } else { - if(fp->jid != kproc->ki_jid) { + if (fp->jid != kproc->ki_jid) { // process can enter jail anytime fp->jid = kproc->ki_jid; free(fp->jname); @@ -512,7 +512,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { // if there are reapers in the system, process can get reparented anytime proc->ppid = kproc->ki_ppid; } - if(proc->st_uid != kproc->ki_uid) { + if (proc->st_uid != kproc->ki_uid) { // some processes change users (eg. to lower privs) proc->st_uid = kproc->ki_uid; proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); diff --git a/htop.c b/htop.c index f5c35929d..2e11a949e 100644 --- a/htop.c +++ b/htop.c @@ -186,7 +186,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { char* saveptr; char* pid = strtok_r(argCopy, ",", &saveptr); - if(!flags.pidMatchList) { + if (!flags.pidMatchList) { flags.pidMatchList = Hashtable_new(8, false); } @@ -243,7 +243,7 @@ static void setCommFilter(State* state, char** commFilter) { int main(int argc, char** argv) { char *lc_ctype = getenv("LC_CTYPE"); - if(lc_ctype != NULL) + if (lc_ctype != NULL) setlocale(LC_CTYPE, lc_ctype); else if ((lc_ctype = getenv("LC_ALL"))) setlocale(LC_CTYPE, lc_ctype); @@ -334,7 +334,7 @@ int main(int argc, char** argv) { UsersTable_delete(ut); Settings_delete(settings); - if(flags.pidMatchList) { + if (flags.pidMatchList) { Hashtable_delete(flags.pidMatchList); } return 0; diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index d607a71b2..94b43896a 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -244,11 +244,11 @@ void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField case IO_WRITE_RATE: Process_outputRate(str, buffer, n, lp->io_rate_write_bps, coloring); return; case IO_RATE: { double totalRate = NAN; - if(!isnan(lp->io_rate_read_bps) && !isnan(lp->io_rate_write_bps)) + if (!isnan(lp->io_rate_read_bps) && !isnan(lp->io_rate_write_bps)) totalRate = lp->io_rate_read_bps + lp->io_rate_write_bps; - else if(!isnan(lp->io_rate_read_bps)) + else if (!isnan(lp->io_rate_read_bps)) totalRate = lp->io_rate_read_bps; - else if(!isnan(lp->io_rate_write_bps)) + else if (!isnan(lp->io_rate_write_bps)) totalRate = lp->io_rate_write_bps; else totalRate = NAN; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index e500f9dc0..86dd4c757 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -208,7 +208,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui // Check for /proc/*/smaps_rollup availability (improves smaps parsing speed, Linux 4.14+) FILE* file = fopen(PROCDIR "/self/smaps_rollup", "r"); - if(file != NULL) { + if (file != NULL) { this->haveSmapsRollup = true; fclose(file); } else { @@ -271,10 +271,10 @@ void ProcessList_delete(ProcessList* pl) { static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { static double jiffy = NAN; - if(isnan(jiffy)) { + if (isnan(jiffy)) { errno = 0; long sc_jiffy = sysconf(_SC_CLK_TCK); - if(errno || -1 == sc_jiffy) { + if (errno || -1 == sc_jiffy) { jiffy = NAN; return t; // Assume 100Hz clock } @@ -481,7 +481,7 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di char buffer[256]; - if(haveSmapsRollup) {// only available in Linux 4.14+ + if (haveSmapsRollup) {// only available in Linux 4.14+ xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps_rollup", dirname, name); } else { xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps", dirname, name); @@ -496,10 +496,10 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di process->m_psswp = 0; while (fgets(buffer, sizeof(buffer), f)) { - if(!strchr(buffer, '\n')) { + if (!strchr(buffer, '\n')) { // Partial line, skip to end of this line while (fgets(buffer, sizeof(buffer), f)) { - if(strchr(buffer, '\n')) { + if (strchr(buffer, '\n')) { break; } } @@ -543,10 +543,10 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d bool foundVPid = false; char linebuf[256]; while (fgets(linebuf, sizeof(linebuf), file) != NULL) { - if(strchr(linebuf, '\n') == NULL) { + if (strchr(linebuf, '\n') == NULL) { // Partial line, skip to end of this line while (fgets(linebuf, sizeof(linebuf), file) != NULL) { - if(strchr(linebuf, '\n') != NULL) { + if (strchr(linebuf, '\n') != NULL) { break; } } @@ -554,14 +554,14 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d } char* name_value_sep = strchr(linebuf, ':'); - if(name_value_sep == NULL) { + if (name_value_sep == NULL) { continue; } int field; - if(0 == strncasecmp(linebuf, "envID", name_value_sep - linebuf)) { + if (0 == strncasecmp(linebuf, "envID", name_value_sep - linebuf)) { field = 1; - } else if(0 == strncasecmp(linebuf, "VPid", name_value_sep - linebuf)) { + } else if (0 == strncasecmp(linebuf, "VPid", name_value_sep - linebuf)) { field = 2; } else { continue; @@ -577,7 +577,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d value_end++; } - if(name_value_sep == value_end) { + if (name_value_sep == value_end) { continue; } @@ -586,7 +586,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d switch(field) { case 1: foundEnvID = true; - if(!String_eq(name_value_sep, process->ctid ? process->ctid : "")) { + if (!String_eq(name_value_sep, process->ctid ? process->ctid : "")) { free(process->ctid); process->ctid = xStrdup(name_value_sep); } @@ -603,12 +603,12 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d fclose(file); - if(!foundEnvID) { + if (!foundEnvID) { free(process->ctid); process->ctid = NULL; } - if(!foundVPid) { + if (!foundVPid) { process->vpid = process->super.pid; } } @@ -1010,7 +1010,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* if (isnan(proc->percent_cpu)) proc->percent_cpu = 0.0; proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(pl->totalMem) * 100.0; - if(!preExisting) { + if (!preExisting) { if (! LinuxProcessList_statProcessDir(proc, dirname, name)) goto errorReadingProcess; diff --git a/linux/Platform.c b/linux/Platform.c index f7a768c9b..674952b09 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -272,7 +272,7 @@ char* Platform_getProcessEnv(pid_t pid) { char procname[128]; xSnprintf(procname, sizeof(procname), PROCDIR "/%d/environ", pid); FILE* fd = fopen(procname, "r"); - if(!fd) + if (!fd) return NULL; char *env = NULL; diff --git a/linux/ZramMeter.c b/linux/ZramMeter.c index f855488eb..30d78eaac 100644 --- a/linux/ZramMeter.c +++ b/linux/ZramMeter.c @@ -19,18 +19,18 @@ static void ZramMeter_updateValues(Meter* this, char* buffer, int size) { written = Meter_humanUnit(buffer, this->values[0], size); buffer += written; size -= written; - if(size <= 0) { + if (size <= 0) { return; } *buffer++ = '('; size--; - if(size <= 0) { + if (size <= 0) { return; } written = Meter_humanUnit(buffer, this->values[1], size); buffer += written; size -= written; - if(size <= 0) { + if (size <= 0) { return; } *buffer++ = ')'; diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 2af82aaba..e219d1ee4 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -322,7 +322,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * // See note above (in common section) about this BINARY FRACTION proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu/(double)32768)*(double)100.0; proc->time = _psinfo->pr_time.tv_sec; - if(!preExisting) { // Tasks done only for NEW processes + if (!preExisting) { // Tasks done only for NEW processes sproc->is_lwp = false; proc->starttime_ctime = _psinfo->pr_start.tv_sec; } From adf797c295db2e0b24cc49efc7af70dafc3f10c2 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:55:36 +0100 Subject: [PATCH 380/411] Spacing after keywords (for) --- IncSet.c | 2 +- Meter.c | 2 +- Panel.c | 2 +- darwin/Battery.c | 2 +- darwin/DarwinProcessList.c | 6 +++--- darwin/Platform.c | 2 +- linux/Battery.c | 4 ++-- linux/LinuxProcessList.c | 10 +++++----- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/IncSet.c b/IncSet.c index 0d1aecf5c..40fe95320 100644 --- a/IncSet.c +++ b/IncSet.c @@ -114,7 +114,7 @@ static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getP int size = Panel_size(panel); int here = Panel_getSelectedIndex(panel); int i = here; - for(;;) { + for (;;) { i+=step; if (i == size) i = 0; if (i == -1) i = size - 1; diff --git a/Meter.c b/Meter.c index 59daa0f55..0cf7ee0b6 100644 --- a/Meter.c +++ b/Meter.c @@ -52,7 +52,7 @@ int Meter_humanUnit(char* buffer, unsigned long int value, int size) { unsigned long int powi = 1; unsigned int written, powj = 1, precision = 2; - for(;;) { + for (;;) { if (value / 1024 < powi) break; diff --git a/Panel.c b/Panel.c index ab3f60090..7507efdac 100644 --- a/Panel.c +++ b/Panel.c @@ -259,7 +259,7 @@ void Panel_draw(Panel* this, bool focus) { if (this->needsRedraw) { int line = 0; - for(int i = first; line < h && i < upTo; i++) { + for (int i = first; line < h && i < upTo; i++) { Object* itemObj = Vector_get(this->items, i); RichString_begin(item); Object_display(itemObj, &item); diff --git a/darwin/Battery.c b/darwin/Battery.c index df644643f..854425b34 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -30,7 +30,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { len = CFArrayGetCount(list); /* Get the battery */ - for(int i = 0; i < len && battery == NULL; ++i) { + for (int i = 0; i < len && battery == NULL; ++i) { CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, CFArrayGetValueAtIndex(list, i)); /* GET rule */ CFStringRef type; diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 59ec9d31e..3f72a3a7f 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -164,8 +164,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { /* Get the time difference */ dpl->global_diff = 0; - for(int i = 0; i < dpl->super.cpuCount; ++i) { - for(size_t j = 0; j < CPU_STATE_MAX; ++j) { + for (int i = 0; i < dpl->super.cpuCount; ++i) { + for (size_t j = 0; j < CPU_STATE_MAX; ++j) { dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j]; } } @@ -185,7 +185,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { */ ps = ProcessList_getKInfoProcs(&count); - for(size_t i = 0; i < count; ++i) { + for (size_t i = 0; i < count; ++i) { proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new); DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); diff --git a/darwin/Platform.c b/darwin/Platform.c index a7adaeee2..9086c6dec 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -206,7 +206,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { double total = 0; /* Take the sums */ - for(size_t i = 0; i < CPU_STATE_MAX; ++i) { + for (size_t i = 0; i < CPU_STATE_MAX; ++i) { total += (double)curr->cpu_ticks[i] - (double)prev->cpu_ticks[i]; } diff --git a/linux/Battery.c b/linux/Battery.c index 0822ee9a5..0d0a0ac49 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -168,7 +168,7 @@ static void Battery_getProcData(double* level, ACPresence* isOnAC) { static inline ssize_t xread(int fd, void *buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; - for(;;) { + for (;;) { ssize_t res = read(fd, buf, count); if (res == -1 && errno == EINTR) continue; if (res > 0) { @@ -282,7 +282,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { return; } char buffer[2] = ""; - for(;;) { + for (;;) { ssize_t res = read(fd3, buffer, 1); if (res == -1 && errno == EINTR) continue; break; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 86dd4c757..050607c72 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -54,7 +54,7 @@ in the source distribution for its full text. static ssize_t xread(int fd, void *buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; - for(;;) { + for (;;) { ssize_t res = read(fd, buf, count); if (res == -1 && errno == EINTR) continue; if (res > 0) { @@ -81,7 +81,7 @@ static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { char* buf = NULL; int bufSize = MAX_READ; int bufLen = 0; - for(;;) { + for (;;) { buf = xRealloc(buf, bufSize); int size = xread(fd, buf + bufLen, MAX_READ); if (size <= 0) { @@ -255,7 +255,7 @@ void ProcessList_delete(ProcessList* pl) { ProcessList_done(pl); free(this->cpus); if (this->ttyDrivers) { - for(int i = 0; this->ttyDrivers[i].path; i++) { + for (int i = 0; this->ttyDrivers[i].path; i++) { free(this->ttyDrivers[i].path); } free(this->ttyDrivers); @@ -900,7 +900,7 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in unsigned int idx = min - ttyDrivers[i].minorFrom; struct stat sstat; char* fullPath; - for(;;) { + for (;;) { xAsprintf(&fullPath, "%s/%d", ttyDrivers[i].path, idx); int err = stat(fullPath, &sstat); if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath; @@ -1162,7 +1162,7 @@ static inline void LinuxProcessList_scanZramInfo(LinuxProcessList* this) { char disksize[34]; unsigned int i = 0; - for(;;) { + for (;;) { xSnprintf(mm_stat, sizeof(mm_stat), "/sys/block/zram%u/mm_stat", i); xSnprintf(disksize, sizeof(disksize), "/sys/block/zram%u/disksize", i); i++; From 493217e8145079e552d9da8d69f2767bb1b9e8c7 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 21:10:12 +0100 Subject: [PATCH 381/411] Fix indentation to 3 spaces --- linux/Battery.c | 26 +++++++++++++------------- linux/LinuxProcessList.c | 36 ++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/linux/Battery.c b/linux/Battery.c index 0d0a0ac49..3554d7990 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -166,19 +166,19 @@ static void Battery_getProcData(double* level, ACPresence* isOnAC) { // ---------------------------------------- static inline ssize_t xread(int fd, void *buf, size_t count) { - // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. - size_t alreadyRead = 0; - for (;;) { - ssize_t res = read(fd, buf, count); - if (res == -1 && errno == EINTR) continue; - if (res > 0) { - buf = ((char*)buf)+res; - count -= res; - alreadyRead += res; - } - if (res == -1) return -1; - if (count == 0 || res == 0) return alreadyRead; - } + // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. + size_t alreadyRead = 0; + for (;;) { + ssize_t res = read(fd, buf, count); + if (res == -1 && errno == EINTR) continue; + if (res > 0) { + buf = ((char*)buf)+res; + count -= res; + alreadyRead += res; + } + if (res == -1) return -1; + if (count == 0 || res == 0) return alreadyRead; + } } static void Battery_getSysData(double* level, ACPresence* isOnAC) { diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 050607c72..fb8bfc53d 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -52,19 +52,19 @@ in the source distribution for its full text. static ssize_t xread(int fd, void *buf, size_t count) { - // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. - size_t alreadyRead = 0; - for (;;) { - ssize_t res = read(fd, buf, count); - if (res == -1 && errno == EINTR) continue; - if (res > 0) { - buf = ((char*)buf)+res; - count -= res; - alreadyRead += res; - } - if (res == -1) return -1; - if (count == 0 || res == 0) return alreadyRead; - } + // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. + size_t alreadyRead = 0; + for (;;) { + ssize_t res = read(fd, buf, count); + if (res == -1 && errno == EINTR) continue; + if (res > 0) { + buf = ((char*)buf)+res; + count -= res; + alreadyRead += res; + } + if (res == -1) return -1; + if (count == 0 || res == 0) return alreadyRead; + } } static int sortTtyDrivers(const void* va, const void* vb) { @@ -448,7 +448,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna case 'c': if (String_startsWith(line+1, "ancelled_write_bytes: ")) { process->io_cancelled_write_bytes = strtoull(line+23, NULL, 10); - } + } } } } @@ -981,14 +981,14 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* // Read smaps file of each process only every second pass to improve performance static int smaps_flag = 0; if ((pid & 1) == smaps_flag){ - LinuxProcessList_readSmapsFile(lp, dirname, name, this->haveSmapsRollup); + LinuxProcessList_readSmapsFile(lp, dirname, name, this->haveSmapsRollup); } if (pid == 1) { smaps_flag = !smaps_flag; } - } else { + } else { lp->m_pss = ((LinuxProcess*)parent)->m_pss; - } + } } proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); @@ -1336,8 +1336,8 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { cpuData->stealTime = steal; cpuData->guestTime = virtalltime; cpuData->totalTime = totaltime; - } + double period = (double)this->cpus[0].totalPeriod / cpus; fclose(file); return period; From 9a16b1079ec1e831a449eb23ff23bf13b1b2a935 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 21:11:39 +0100 Subject: [PATCH 382/411] Make scope of match macro symmetric --- linux/Battery.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/linux/Battery.c b/linux/Battery.c index 3554d7990..c185258ae 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -232,9 +232,11 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { bool now = false; int fullSize = 0; double capacityLevel = NAN; + + #define match(str,prefix) \ + (String_startsWith(str,prefix) ? (str) + strlen(prefix) : NULL) + while ((line = strsep(&buf, "\n")) != NULL) { - #define match(str,prefix) \ - (String_startsWith(str,prefix) ? (str) + strlen(prefix) : NULL) const char* ps = match(line, "POWER_SUPPLY_"); if (!ps) { continue; @@ -266,7 +268,9 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { continue; } } - #undef match + + #undef match + if (!now && full && !isnan(capacityLevel)) { totalRemain += (capacityLevel * fullSize); } From b23f8235e28472c410dcb00893e0e3d403892673 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 22:14:27 +0100 Subject: [PATCH 383/411] Whitespace and indentation issues --- Affinity.c | 2 +- AffinityPanel.c | 4 +- IncSet.c | 2 +- ListItem.c | 4 +- Panel.c | 4 +- Process.c | 4 +- Settings.c | 5 +- darwin/Battery.c | 12 +- darwin/DarwinProcess.c | 18 +-- darwin/DarwinProcessList.c | 178 +++++++++++++------------ darwin/Platform.c | 18 +-- dragonflybsd/DragonFlyBSDProcessList.c | 47 +++---- dragonflybsd/Platform.c | 6 +- freebsd/FreeBSDProcessList.c | 42 +++--- freebsd/Platform.c | 6 +- linux/LinuxProcess.c | 13 +- linux/LinuxProcessList.c | 24 ++-- linux/PressureStallMeter.c | 32 ++--- openbsd/OpenBSDProcess.c | 75 +++++++---- openbsd/Platform.c | 10 +- solaris/Platform.c | 6 +- solaris/SolarisProcessList.c | 54 +++++--- unsupported/UnsupportedProcessList.c | 78 +++++------ zfs/openzfs_sysctl.c | 33 ++--- 24 files changed, 368 insertions(+), 309 deletions(-) diff --git a/Affinity.c b/Affinity.c index 4d78944c9..96591a658 100644 --- a/Affinity.c +++ b/Affinity.c @@ -65,7 +65,7 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { } else { unsigned int id; hwloc_bitmap_foreach_begin(id, cpuset); - Affinity_add(affinity, id); + Affinity_add(affinity, id); hwloc_bitmap_foreach_end(); } } diff --git a/AffinityPanel.c b/AffinityPanel.c index a8cb66eee..e184d64b2 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -285,7 +285,7 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u left -= len; } xSnprintf(&indent_buf[off], left, "%s", - obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]); + obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]); // Uncomment when further appending to indent_buf //size_t len = strlen(&indent_buf[off]); //off += len; @@ -417,7 +417,7 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) { #ifdef HAVE_LIBHWLOC int i; hwloc_bitmap_foreach_begin(i, this->workCpuset) - Affinity_add(affinity, i); + Affinity_add(affinity, i); hwloc_bitmap_foreach_end(); #else for (int i = 0; i < this->pl->cpuCount; i++) { diff --git a/IncSet.c b/IncSet.c index 40fe95320..3deda7375 100644 --- a/IncSet.c +++ b/IncSet.c @@ -170,7 +170,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue doSearch = false; } } else if (ch == KEY_RESIZE) { - Panel_resize(panel, COLS, LINES-panel->y-1); + Panel_resize(panel, COLS, LINES - panel->y - 1); } else { if (mode->isFilter) { filterChanged = true; diff --git a/ListItem.c b/ListItem.c index 031c4f72f..c3c1a7d3a 100644 --- a/ListItem.c +++ b/ListItem.c @@ -31,9 +31,9 @@ static void ListItem_display(const Object* cast, RichString* out) { if (this->moving) { RichString_write(out, CRT_colors[DEFAULT_COLOR], #ifdef HAVE_LIBNCURSESW - CRT_utf8 ? "↕ " : + CRT_utf8 ? "↕ " : #endif - "+ "); + "+ "); } else { RichString_prune(out); } diff --git a/Panel.c b/Panel.c index 7507efdac..4c3339636 100644 --- a/Panel.c +++ b/Panel.c @@ -254,8 +254,8 @@ void Panel_draw(Panel* this, bool focus) { int upTo = MINIMUM(first + h, size); int selectionColor = focus - ? this->selectionColor - : CRT_colors[PANEL_SELECTION_UNFOCUS]; + ? this->selectionColor + : CRT_colors[PANEL_SELECTION_UNFOCUS]; if (this->needsRedraw) { int line = 0; diff --git a/Process.c b/Process.c index bbc85ce1a..11b99b8bc 100644 --- a/Process.c +++ b/Process.c @@ -287,8 +287,8 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field for (int i = 0; i < 32; i++) if (indent & (1U << i)) - maxIndent = i+1; - for (int i = 0; i < maxIndent - 1; i++) { + maxIndent = i + 1; + for (int i = 0; i < maxIndent - 1; i++) { int written, ret; if (indent & (1 << i)) ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]); diff --git a/Settings.c b/Settings.c index 9ac275656..2cb560ed4 100644 --- a/Settings.c +++ b/Settings.c @@ -182,8 +182,9 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo this->delay = atoi(option[1]); } else if (String_eq(option[0], "color_scheme")) { this->colorScheme = atoi(option[1]); - if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0; - } else if (String_eq(option[0], "enable_mouse")) { + if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) + this->colorScheme = 0; + } else if (String_eq(option[0], "enable_mouse")) { this->enableMouse = atoi(option[1]); } else if (String_eq(option[0], "left_meters")) { Settings_readMeters(this, option[1], 0); diff --git a/darwin/Battery.c b/darwin/Battery.c index 854425b34..c89f5b30f 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -32,12 +32,12 @@ void Battery_getData(double* level, ACPresence* isOnAC) { /* Get the battery */ for (int i = 0; i < len && battery == NULL; ++i) { CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, - CFArrayGetValueAtIndex(list, i)); /* GET rule */ + CFArrayGetValueAtIndex(list, i)); /* GET rule */ CFStringRef type; if (NULL != candidate) { type = (CFStringRef) CFDictionaryGetValue(candidate, - CFSTR(kIOPSTransportTypeKey)); /* GET rule */ + CFSTR(kIOPSTransportTypeKey)); /* GET rule */ if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { CFRetain(candidate); @@ -51,17 +51,17 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0)) - ? AC_PRESENT - : AC_ABSENT; + ? AC_PRESENT + : AC_ABSENT; /* Get the percentage remaining */ double current; double max; CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)), - kCFNumberDoubleType, ¤t); + kCFNumberDoubleType, ¤t); CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)), - kCFNumberDoubleType, &max); + kCFNumberDoubleType, &max); *level = (current * 100.0) / max; diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 8ad7a6d8d..a92f26618 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -158,12 +158,12 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { /* Convert previous '\0'. */ *np = ' '; } - /* Note location of current '\0'. */ - np = cp; - if (*basenameOffset == 0) { - *basenameOffset = cp - sp; - } - } + /* Note location of current '\0'. */ + np = cp; + if (*basenameOffset == 0) { + *basenameOffset = cp - sp; + } + } } /* @@ -247,10 +247,10 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList if (sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { if (0 != proc->utime || 0 != proc->stime) { uint64_t diff = (pti.pti_total_system - proc->stime) - + (pti.pti_total_user - proc->utime); + + (pti.pti_total_user - proc->utime); proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount - / ((double)dpl->global_diff * 100000.0); + / ((double)dpl->global_diff * 100000.0); // fprintf(stderr, "%f %llu %llu %llu %llu %llu\n", proc->super.percent_cpu, // proc->stime, proc->utime, pti.pti_total_system, pti.pti_total_user, dpl->global_diff); @@ -263,7 +263,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList proc->super.m_resident = pti.pti_resident_size / CRT_pageSize; proc->super.majflt = pti.pti_faults; proc->super.percent_mem = (double)pti.pti_resident_size * 100.0 - / (double)dpl->host_info.max_mem; + / (double)dpl->host_info.max_mem; proc->stime = pti.pti_total_system; proc->utime = pti.pti_total_user; diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 3f72a3a7f..bb7c56dbf 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -24,7 +24,7 @@ in the source distribution for its full text. #include struct kern { - short int version[3]; + short int version[3]; }; void GetKernelVersion(struct kern *k) { @@ -35,9 +35,11 @@ void GetKernelVersion(struct kern *k) { char str[256] = {0}; size_t size = sizeof(str); int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0); - if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]); - } - memcpy(k->version, version_, sizeof(version_)); + if (ret == 0) { + sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]); + } + } + memcpy(k->version, version_, sizeof(version_)); } /* compare the given os version with the one installed returns: @@ -46,28 +48,36 @@ positive value if less than the installed version negative value if more than the installed version */ int CompareKernelVersion(short int major, short int minor, short int component) { - struct kern k; - GetKernelVersion(&k); - if ( k.version[0] != major) return k.version[0] - major; - if ( k.version[1] != minor) return k.version[1] - minor; - if ( k.version[2] != component) return k.version[2] - component; - return 0; + struct kern k; + GetKernelVersion(&k); + + if (k.version[0] != major) { + return k.version[0] - major; + } + if (k.version[1] != minor) { + return k.version[1] - minor; + } + if (k.version[2] != component) { + return k.version[2] - component; + } + + return 0; } void ProcessList_getHostInfo(host_basic_info_data_t *p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { - CRT_fatalError("Unable to retrieve host info\n"); + CRT_fatalError("Unable to retrieve host info\n"); } } void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { if (NULL != p && NULL != *p) { - if (0 != munmap(*p, vm_page_size)) { - CRT_fatalError("Unable to free old CPU load information\n"); - } - *p = NULL; + if (0 != munmap(*p, vm_page_size)) { + CRT_fatalError("Unable to free old CPU load information\n"); + } + *p = NULL; } } @@ -76,18 +86,19 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { unsigned cpu_count; // TODO Improving the accuracy of the load counts woule help a lot. - if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) { - CRT_fatalError("Unable to retrieve CPU info\n"); + if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t*)p, &info_size)) { + CRT_fatalError("Unable to retrieve CPU info\n"); } return cpu_count; } void ProcessList_getVMStats(vm_statistics_t p) { - mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT; + mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT; - if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0) - CRT_fatalError("Unable to retrieve VM statistics\n"); + if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0) { + CRT_fatalError("Unable to retrieve VM statistics\n"); + } } struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { @@ -145,67 +156,68 @@ void ProcessList_delete(ProcessList* this) { } void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { - DarwinProcessList *dpl = (DarwinProcessList *)super; - bool preExisting = true; - struct kinfo_proc *ps; - size_t count; - DarwinProcess *proc; - - /* Update the global data (CPU times and VM stats) */ - ProcessList_freeCPULoadInfo(&dpl->prev_load); - dpl->prev_load = dpl->curr_load; - ProcessList_allocateCPULoadInfo(&dpl->curr_load); - ProcessList_getVMStats(&dpl->vm_stats); - openzfs_sysctl_updateArcStats(&dpl->zfs); - - // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) - return; - - /* Get the time difference */ - dpl->global_diff = 0; - for (int i = 0; i < dpl->super.cpuCount; ++i) { - for (size_t j = 0; j < CPU_STATE_MAX; ++j) { - dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j]; - } - } - - /* Clear the thread counts */ - super->kernelThreads = 0; - super->userlandThreads = 0; - super->totalTasks = 0; - super->runningTasks = 0; - - /* We use kinfo_procs for initial data since : - * - * 1) They always succeed. - * 2) The contain the basic information. - * - * We attempt to fill-in additional information with libproc. - */ - ps = ProcessList_getKInfoProcs(&count); - - for (size_t i = 0; i < count; ++i) { - proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new); - - DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); - DarwinProcess_setFromLibprocPidinfo(proc, dpl); - - // Disabled for High Sierra due to bug in macOS High Sierra - bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0); - - if (isScanThreadSupported){ - DarwinProcess_scanThreads(proc); - } - - super->totalTasks += 1; - - if (!preExisting) { - proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid); - - ProcessList_add(super, &proc->super); - } - } - - free(ps); + DarwinProcessList* dpl = (DarwinProcessList*)super; + bool preExisting = true; + struct kinfo_proc* ps; + size_t count; + DarwinProcess* proc; + + /* Update the global data (CPU times and VM stats) */ + ProcessList_freeCPULoadInfo(&dpl->prev_load); + dpl->prev_load = dpl->curr_load; + ProcessList_allocateCPULoadInfo(&dpl->curr_load); + ProcessList_getVMStats(&dpl->vm_stats); + openzfs_sysctl_updateArcStats(&dpl->zfs); + + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) { + return; + } + + /* Get the time difference */ + dpl->global_diff = 0; + for (int i = 0; i < dpl->super.cpuCount; ++i) { + for (size_t j = 0; j < CPU_STATE_MAX; ++j) { + dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j]; + } + } + + /* Clear the thread counts */ + super->kernelThreads = 0; + super->userlandThreads = 0; + super->totalTasks = 0; + super->runningTasks = 0; + + /* We use kinfo_procs for initial data since : + * + * 1) They always succeed. + * 2) The contain the basic information. + * + * We attempt to fill-in additional information with libproc. + */ + ps = ProcessList_getKInfoProcs(&count); + + for (size_t i = 0; i < count; ++i) { + proc = (DarwinProcess*)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new); + + DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); + DarwinProcess_setFromLibprocPidinfo(proc, dpl); + + // Disabled for High Sierra due to bug in macOS High Sierra + bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0); + + if (isScanThreadSupported) { + DarwinProcess_scanThreads(proc); + } + + super->totalTasks += 1; + + if (!preExisting) { + proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid); + + ProcessList_add(super, &proc->super); + } + } + + free(ps); } diff --git a/darwin/Platform.c b/darwin/Platform.c index 9086c6dec..c5a22da4c 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -211,11 +211,11 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { } mtr->values[CPU_METER_NICE] - = ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE])* 100.0 / total; + = ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE]) * 100.0 / total; mtr->values[CPU_METER_NORMAL] - = ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER])* 100.0 / total; + = ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER]) * 100.0 / total; mtr->values[CPU_METER_KERNEL] - = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total; + = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM]) * 100.0 / total; mtr->curItems = 3; @@ -239,13 +239,13 @@ void Platform_setMemoryValues(Meter* mtr) { } void Platform_setSwapValues(Meter* mtr) { - int mib[2] = {CTL_VM, VM_SWAPUSAGE}; - struct xsw_usage swapused; - size_t swlen = sizeof(swapused); - sysctl(mib, 2, &swapused, &swlen, NULL, 0); + int mib[2] = {CTL_VM, VM_SWAPUSAGE}; + struct xsw_usage swapused; + size_t swlen = sizeof(swapused); + sysctl(mib, 2, &swapused, &swlen, NULL, 0); - mtr->total = swapused.xsu_total / 1024; - mtr->values[0] = swapused.xsu_used / 1024; + mtr->total = swapused.xsu_total / 1024; + mtr->values[0] = swapused.xsu_used / 1024; } void Platform_setZfsArcValues(Meter* this) { diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 2fe20daee..90bc7f7ab 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -101,10 +101,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui pl->cpuCount = MAXIMUM(cpus, 1); if (cpus == 1 ) { - dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData)); + dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData)); } else { - // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) - dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); + // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) + dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); } len = sizeof(kernelFScale); @@ -161,12 +161,12 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { // get rest of CPUs if (cpus > 1) { - // on smp systems DragonFlyBSD kernel concats all CPU states into one long array in - // kern.cp_times sysctl OID - // we store averages in dfpl->cpus[0], and actual cores after that - maxcpu = cpus + 1; - sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; - sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); + // on smp systems DragonFlyBSD kernel concats all CPU states into one long array in + // kern.cp_times sysctl OID + // we store averages in dfpl->cpus[0], and actual cores after that + maxcpu = cpus + 1; + sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; + sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); } for (int i = 0; i < maxcpu; i++) { @@ -176,14 +176,14 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { cp_time_o = dfpl->cp_time_o; } else { if (i == 0 ) { - // average - cp_time_n = dfpl->cp_time_n; - cp_time_o = dfpl->cp_time_o; + // average + cp_time_n = dfpl->cp_time_n; + cp_time_o = dfpl->cp_time_o; } else { - // specific smp cores - cp_times_offset = i - 1; - cp_time_n = dfpl->cp_times_n + (cp_times_offset * CPUSTATES); - cp_time_o = dfpl->cp_times_o + (cp_times_offset * CPUSTATES); + // specific smp cores + cp_times_offset = i - 1; + cp_time_n = dfpl->cp_times_n + (cp_times_offset * CPUSTATES); + cp_time_o = dfpl->cp_times_o + (cp_times_offset * CPUSTATES); } } @@ -192,9 +192,9 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { unsigned long long total_n = 0; unsigned long long total_d = 0; for (int s = 0; s < CPUSTATES; s++) { - cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; - total_o += cp_time_o[s]; - total_n += cp_time_n[s]; + cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; + total_o += cp_time_o[s]; + total_n += cp_time_n[s]; } // totals @@ -203,8 +203,8 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { // save current state as old and calc percentages for (int s = 0; s < CPUSTATES; ++s) { - cp_time_o[s] = cp_time_n[s]; - cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; + cp_time_o[s] = cp_time_n[s]; + cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; } CPUData* cpuData = &(dfpl->cpus[i]); @@ -344,8 +344,9 @@ static inline void DragonFlyBSDProcessList_scanJails(DragonFlyBSDProcessList* df } curpos = nextpos; - } - free(jls); + } + + free(jls); } char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid) { diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 5b81c610f..6f8c2023a 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -154,10 +154,10 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData; if (cpus == 1) { - // single CPU box has everything in fpl->cpus[0] - cpuData = &(fpl->cpus[0]); + // single CPU box has everything in fpl->cpus[0] + cpuData = &(fpl->cpus[0]); } else { - cpuData = &(fpl->cpus[cpu]); + cpuData = &(fpl->cpus[cpu]); } double percent; diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index bfa046b84..8be627c9e 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -124,10 +124,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui pl->cpuCount = MAXIMUM(cpus, 1); if (cpus == 1 ) { - fpl->cpus = xRealloc(fpl->cpus, sizeof(CPUData)); + fpl->cpus = xRealloc(fpl->cpus, sizeof(CPUData)); } else { - // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) - fpl->cpus = xRealloc(fpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); + // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) + fpl->cpus = xRealloc(fpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); } @@ -187,12 +187,12 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { // get rest of CPUs if (cpus > 1) { - // on smp systems FreeBSD kernel concats all CPU states into one long array in - // kern.cp_times sysctl OID - // we store averages in fpl->cpus[0], and actual cores after that - maxcpu = cpus + 1; - sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; - sysctl(MIB_kern_cp_times, 2, fpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); + // on smp systems FreeBSD kernel concats all CPU states into one long array in + // kern.cp_times sysctl OID + // we store averages in fpl->cpus[0], and actual cores after that + maxcpu = cpus + 1; + sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; + sysctl(MIB_kern_cp_times, 2, fpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); } for (int i = 0; i < maxcpu; i++) { @@ -202,14 +202,14 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { cp_time_o = fpl->cp_time_o; } else { if (i == 0 ) { - // average - cp_time_n = fpl->cp_time_n; - cp_time_o = fpl->cp_time_o; + // average + cp_time_n = fpl->cp_time_n; + cp_time_o = fpl->cp_time_o; } else { - // specific smp cores - cp_times_offset = i - 1; - cp_time_n = fpl->cp_times_n + (cp_times_offset * CPUSTATES); - cp_time_o = fpl->cp_times_o + (cp_times_offset * CPUSTATES); + // specific smp cores + cp_times_offset = i - 1; + cp_time_n = fpl->cp_times_n + (cp_times_offset * CPUSTATES); + cp_time_o = fpl->cp_times_o + (cp_times_offset * CPUSTATES); } } @@ -218,9 +218,9 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { unsigned long long total_n = 0; unsigned long long total_d = 0; for (int s = 0; s < CPUSTATES; s++) { - cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; - total_o += cp_time_o[s]; - total_n += cp_time_n[s]; + cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; + total_o += cp_time_o[s]; + total_n += cp_time_n[s]; } // totals @@ -229,8 +229,8 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { // save current state as old and calc percentages for (int s = 0; s < CPUSTATES; ++s) { - cp_time_o[s] = cp_time_n[s]; - cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; + cp_time_o[s] = cp_time_n[s]; + cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; } CPUData* cpuData = &(fpl->cpus[i]); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index bdd49bf6c..32b542939 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -165,10 +165,10 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData; if (cpus == 1) { - // single CPU box has everything in fpl->cpus[0] - cpuData = &(fpl->cpus[0]); + // single CPU box has everything in fpl->cpus[0] + cpuData = &(fpl->cpus[0]); } else { - cpuData = &(fpl->cpus[cpu]); + cpuData = &(fpl->cpus[cpu]); } double percent; diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 94b43896a..a5d7eccf9 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -194,11 +194,11 @@ bool LinuxProcess_setIOPriority(Process* this, Arg ioprio) { #ifdef HAVE_DELAYACCT void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) { - if (isnan(delay_percent)) { - xSnprintf(buffer, n, " N/A "); - } else { - xSnprintf(buffer, n, "%4.1f ", delay_percent); - } + if (isnan(delay_percent)) { + xSnprintf(buffer, n, " N/A "); + } else { + xSnprintf(buffer, n, "%4.1f ", delay_percent); + } } #endif @@ -379,7 +379,8 @@ long LinuxProcess_compare(const void* v1, const void* v2) { default: return Process_compare(v1, v2); } - test_diff: + +test_diff: return (diff > 0) ? 1 : (diff < 0 ? -1 : 0); } diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index fb8bfc53d..6065d4295 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -419,20 +419,20 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna while ((line = strsep(&buf, "\n")) != NULL) { switch (line[0]) { case 'r': - if (line[1] == 'c' && String_startsWith(line+2, "har: ")) - process->io_rchar = strtoull(line+7, NULL, 10); - else if (String_startsWith(line+1, "ead_bytes: ")) { - process->io_read_bytes = strtoull(line+12, NULL, 10); + if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) { + process->io_rchar = strtoull(line + 7, NULL, 10); + } else if (String_startsWith(line + 1, "ead_bytes: ")) { + process->io_read_bytes = strtoull(line + 12, NULL, 10); process->io_rate_read_bps = ((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000); process->io_rate_read_time = now; } break; case 'w': - if (line[1] == 'c' && String_startsWith(line+2, "har: ")) - process->io_wchar = strtoull(line+7, NULL, 10); - else if (String_startsWith(line+1, "rite_bytes: ")) { - process->io_write_bytes = strtoull(line+13, NULL, 10); + if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) { + process->io_wchar = strtoull(line + 7, NULL, 10); + } else if (String_startsWith(line + 1, "rite_bytes: ")) { + process->io_write_bytes = strtoull(line + 13, NULL, 10); process->io_rate_write_bps = ((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000); process->io_rate_write_time = now; @@ -446,8 +446,8 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna } break; case 'c': - if (String_startsWith(line+1, "ancelled_write_bytes: ")) { - process->io_cancelled_write_bytes = strtoull(line+23, NULL, 10); + if (String_startsWith(line + 1, "ancelled_write_bytes: ")) { + process->io_cancelled_write_bytes = strtoull(line + 23, NULL, 10); } } } @@ -1087,7 +1087,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* continue; // Exception handler. - errorReadingProcess: { + +errorReadingProcess: + { if (preExisting) { ProcessList_remove(pl, proc); } else { diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c index 9ac0ced23..3b5415c5f 100644 --- a/linux/PressureStallMeter.c +++ b/linux/PressureStallMeter.c @@ -24,24 +24,24 @@ static const int PressureStallMeter_attributes[] = { }; static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) { - const char *file; - if (strstr(Meter_name(this), "CPU")) { - file = "cpu"; - } else if (strstr(Meter_name(this), "IO")) { - file = "io"; - } else { - file = "memory"; - } + const char* file; + if (strstr(Meter_name(this), "CPU")) { + file = "cpu"; + } else if (strstr(Meter_name(this), "IO")) { + file = "io"; + } else { + file = "memory"; + } - bool some; - if (strstr(Meter_name(this), "Some")) { - some = true; - } else { - some = false; - } + bool some; + if (strstr(Meter_name(this), "Some")) { + some = true; + } else { + some = false; + } - Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]); - xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]); + Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]); + xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]); } static void PressureStallMeter_display(const Object* cast, RichString* out) { diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index c43fe2fcf..5eb61b161 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -32,127 +32,152 @@ ProcessFieldData Process_fields[] = { .name = "", .title = NULL, .description = NULL, - .flags = 0, }, + .flags = 0, + }, [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", - .flags = 0, }, + .flags = 0, + }, [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", - .flags = 0, }, + .flags = 0, + }, [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", - .flags = 0, }, + .flags = 0, + }, [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", - .flags = 0, }, + .flags = 0, + }, [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", - .flags = 0, }, + .flags = 0, + }, [SESSION] = { .name = "SESSION", .title = " SESN ", .description = "Process's session ID", - .flags = 0, }, + .flags = 0, + }, [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", - .flags = 0, }, + .flags = 0, + }, [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", - .flags = 0, }, + .flags = 0, + }, [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", - .flags = 0, }, + .flags = 0, + }, [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", - .flags = 0, }, + .flags = 0, + }, [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", - .flags = 0, }, + .flags = 0, + }, [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", - .flags = 0, }, + .flags = 0, + }, [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", - .flags = 0, }, + .flags = 0, + }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", - .flags = 0, }, + .flags = 0, + }, [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", - .flags = 0, }, + .flags = 0, + }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", - .flags = 0, }, + .flags = 0, + }, [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", - .flags = 0, }, + .flags = 0, + }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", - .flags = 0, }, + .flags = 0, + }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", - .flags = 0, }, + .flags = 0, + }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", - .flags = 0, }, + .flags = 0, + }, [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", - .flags = 0, }, + .flags = 0, + }, [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", - .flags = 0, }, + .flags = 0, + }, [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", - .flags = 0, }, + .flags = 0, + }, [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, - .flags = 0, }, + .flags = 0, + }, }; ProcessPidColumn Process_pidColumns[] = { diff --git a/openbsd/Platform.c b/openbsd/Platform.c index df6bc0cc1..d9737c393 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -254,7 +254,7 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; if ((kproc = kvm_getprocs(kt, KERN_PROC_PID, pid, - sizeof(struct kinfo_proc), &count)) == NULL) {\ + sizeof(struct kinfo_proc), &count)) == NULL) { (void) kvm_close(kt); return NULL; } @@ -278,10 +278,10 @@ char* Platform_getProcessEnv(pid_t pid) { } if (size < 2 || env[size - 1] || env[size - 2]) { - if (size + 2 < capacity) - env = xRealloc(env, capacity + 2); - env[size] = 0; - env[size+1] = 0; + if (size + 2 < capacity) + env = xRealloc(env, capacity + 2); + env[size] = 0; + env[size + 1] = 0; } (void) kvm_close(kt); diff --git a/solaris/Platform.c b/solaris/Platform.c index 87247969e..be2d25ed3 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -172,10 +172,10 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData = NULL; if (cpus == 1) { - // single CPU box has everything in spl->cpus[0] - cpuData = &(spl->cpus[0]); + // single CPU box has everything in spl->cpus[0] + cpuData = &(spl->cpus[0]); } else { - cpuData = &(spl->cpus[cpu]); + cpuData = &(spl->cpus[cpu]); } double percent; diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index e219d1ee4..cbef6c8f7 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -29,16 +29,18 @@ in the source distribution for its full text. #define MAXCMDLINE 255 char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { - char* zname; - if ( sproc->zoneid == 0 ) { - zname = xStrdup(GZONE); - } else if ( kd == NULL ) { - zname = xStrdup(UZONE); - } else { - kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL ); - zname = xStrdup(ks == NULL ? UZONE : ks->ks_name); - } - return zname; + char* zname; + + if ( sproc->zoneid == 0 ) { + zname = xStrdup(GZONE); + } else if ( kd == NULL ) { + zname = xStrdup(UZONE); + } else { + kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL ); + zname = xStrdup(ks == NULL ? UZONE : ks->ks_name); + } + + return zname; } ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { @@ -78,15 +80,19 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { assert(cpus > 0); if (cpus > 1) { - // Store values for the stats loop one extra element up in the array - // to leave room for the average to be calculated afterwards - arrskip++; + // Store values for the stats loop one extra element up in the array + // to leave room for the average to be calculated afterwards + arrskip++; } // Calculate per-CPU statistics first for (int i = 0; i < cpus; i++) { - if (spl->kd != NULL) { cpuinfo = kstat_lookup(spl->kd,"cpu",i,"sys"); } - if (cpuinfo != NULL) { kchain = kstat_read(spl->kd,cpuinfo,NULL); } + if (spl->kd != NULL) { + cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys"); + } + if (cpuinfo != NULL) { + kchain = kstat_read(spl->kd, cpuinfo, NULL); + } if (kchain != -1 ) { idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle"); intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr"); @@ -170,7 +176,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { // Not really "buffers" but the best Solaris analogue that I can find to // "memory in use but not by programs or the kernel itself" pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * CRT_pageSizeKB; - } else { + } else { // Fall back to basic sysconf if kstat isn't working pl->totalMem = sysconf(_SC_PHYS_PAGES) * CRT_pageSize; pl->buffersMem = 0; @@ -180,8 +186,12 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { // Part 2 - swap nswap = swapctl(SC_GETNSWP, NULL); - if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); } - if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); } + if (nswap > 0) { + sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); + } + if (sl != NULL) { + spathbase = xMalloc( nswap * MAXPATHLEN ); + } if (spathbase != NULL) { spath = spathbase; swapdev = sl->swt_ent; @@ -211,8 +221,12 @@ static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { int ksrphyserr = -1; kstat_named_t *cur_kstat = NULL; - if (spl->kd != NULL) { arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats"); } - if (arcstats != NULL) { ksrphyserr = kstat_read(spl->kd, arcstats, NULL); } + if (spl->kd != NULL) { + arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats"); + } + if (arcstats != NULL) { + ksrphyserr = kstat_read(spl->kd, arcstats, NULL); + } if (ksrphyserr != -1) { cur_kstat = kstat_data_lookup( arcstats, "size" ); spl->zfs.size = cur_kstat->value.ui64 / 1024; diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index 33dd9fe8f..24668b69b 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -30,43 +30,43 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (pauseProcessUpdate) return; - bool preExisting = true; - Process *proc; - - proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new); - - /* Empty values */ - proc->time = proc->time + 10; - proc->pid = 1; - proc->ppid = 1; - proc->tgid = 0; - proc->comm = ""; - proc->basenameOffset = 0; - proc->updated = true; - - proc->state = 'R'; - proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */ - proc->pgrp = 0; - proc->session = 0; - proc->tty_nr = 0; - proc->tpgid = 0; - proc->st_uid = 0; - proc->flags = 0; - proc->processor = 0; - - proc->percent_cpu = 2.5; - proc->percent_mem = 2.5; - proc->user = "nobody"; - - proc->priority = 0; - proc->nice = 0; - proc->nlwp = 1; - proc->starttime_ctime = 1433116800; // Jun 01, 2015 - Process_fillStarttimeBuffer(proc); - - proc->m_size = 100; - proc->m_resident = 100; - - proc->minflt = 20; - proc->majflt = 20; + bool preExisting = true; + Process* proc; + + proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new); + + /* Empty values */ + proc->time = proc->time + 10; + proc->pid = 1; + proc->ppid = 1; + proc->tgid = 0; + proc->comm = ""; + proc->basenameOffset = 0; + proc->updated = true; + + proc->state = 'R'; + proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */ + proc->pgrp = 0; + proc->session = 0; + proc->tty_nr = 0; + proc->tpgid = 0; + proc->st_uid = 0; + proc->flags = 0; + proc->processor = 0; + + proc->percent_cpu = 2.5; + proc->percent_mem = 2.5; + proc->user = "nobody"; + + proc->priority = 0; + proc->nice = 0; + proc->nlwp = 1; + proc->starttime_ctime = 1433116800; // Jun 01, 2015 + Process_fillStarttimeBuffer(proc); + + proc->m_size = 100; + proc->m_resident = 100; + + proc->minflt = 20; + proc->majflt = 20; } diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c index 3f8f2c25d..c09d48df8 100644 --- a/zfs/openzfs_sysctl.c +++ b/zfs/openzfs_sysctl.c @@ -33,21 +33,24 @@ void openzfs_sysctl_init(ZfsArcStats *stats) { len = sizeof(arcSize); if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) { - stats->enabled = 1; - len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); - - sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); - if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) { - stats->isCompressed = 1; - sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len); - } else { - stats->isCompressed = 0; - } + stats->enabled = 1; + + len = 5; + sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); + + sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); + + if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) { + stats->isCompressed = 1; + sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len); + } else { + stats->isCompressed = 0; + } } else { stats->enabled = 0; } From 61e14d4bb25268593019e6df3eb02264b4ac8e0e Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 23:28:02 +0100 Subject: [PATCH 384/411] Spacing around operators --- Action.c | 12 +- Affinity.c | 4 +- AffinityPanel.c | 14 +- BatteryMeter.c | 2 +- CPUMeter.c | 14 +- CRT.c | 738 ++++++++++++------------- CRT.h | 2 +- ClockMeter.c | 2 +- ColumnsPanel.c | 2 +- DateMeter.c | 4 +- DateTimeMeter.c | 4 +- EnvScreen.c | 4 +- FunctionBar.c | 10 +- Header.c | 2 +- HostnameMeter.c | 2 +- IncSet.h | 2 +- InfoScreen.c | 17 +- MainPanel.c | 6 +- MainPanel.h | 2 +- Meter.c | 36 +- OpenFilesScreen.c | 2 +- Panel.c | 10 +- Panel.h | 2 +- Process.c | 22 +- Process.h | 2 +- ProcessList.c | 8 +- RichString.c | 2 +- RichString.h | 2 +- ScreenManager.c | 16 +- Settings.c | 6 +- TraceScreen.c | 11 +- UptimeMeter.c | 6 +- Vector.c | 14 +- Vector.h | 2 +- XUtils.c | 8 +- XUtils.h | 4 +- darwin/DarwinProcess.c | 12 +- darwin/DarwinProcess.h | 8 +- darwin/DarwinProcessList.c | 12 +- darwin/DarwinProcessList.h | 10 +- darwin/Platform.c | 26 +- darwin/Platform.h | 8 +- dragonflybsd/DragonFlyBSDProcess.c | 2 +- dragonflybsd/DragonFlyBSDProcessList.c | 16 +- dragonflybsd/DragonFlyBSDProcessList.h | 10 +- dragonflybsd/Platform.c | 12 +- dragonflybsd/Platform.h | 8 +- freebsd/FreeBSDProcess.c | 2 +- freebsd/FreeBSDProcessList.c | 16 +- freebsd/FreeBSDProcessList.h | 8 +- freebsd/Platform.c | 18 +- freebsd/Platform.h | 8 +- htop.c | 10 +- linux/Battery.c | 22 +- linux/IOPriorityPanel.c | 2 +- linux/LinuxProcess.h | 2 +- linux/LinuxProcessList.c | 94 ++-- linux/LinuxProcessList.h | 2 +- linux/Platform.c | 35 +- linux/Platform.h | 10 +- openbsd/Battery.c | 2 +- openbsd/OpenBSDProcessList.c | 12 +- openbsd/OpenBSDProcessList.h | 2 +- openbsd/Platform.c | 26 +- openbsd/Platform.h | 8 +- solaris/Platform.c | 32 +- solaris/Platform.h | 10 +- solaris/SolarisProcessList.c | 62 ++- solaris/SolarisProcessList.h | 2 +- unsupported/Platform.c | 8 +- unsupported/Platform.h | 8 +- zfs/ZfsCompressedArcMeter.c | 2 +- zfs/openzfs_sysctl.c | 22 +- zfs/openzfs_sysctl.h | 4 +- 74 files changed, 784 insertions(+), 765 deletions(-) diff --git a/Action.c b/Action.c index 303eeeafe..879014325 100644 --- a/Action.c +++ b/Action.c @@ -59,7 +59,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) } ScreenManager_delete(scr); Panel_move(panel, 0, y); - Panel_resize(panel, COLS, LINES-y-1); + Panel_resize(panel, COLS, LINES - y - 1); if (panelFocus == list && ch == 13) { if (followProcess) { Process* selected = (Process*)Panel_getSelected(panel); @@ -181,7 +181,7 @@ static Htop_Reaction sortBy(State* st) { static Htop_Reaction actionResize(State* st) { clear(); - Panel_resize(st->panel, COLS, LINES-(st->panel->y)-1); + Panel_resize(st->panel, COLS, LINES - (st->panel->y) - 1); return HTOP_REDRAW_BAR; } @@ -393,12 +393,12 @@ static Htop_Reaction actionTag(State* st) { return HTOP_OK; } -static Htop_Reaction actionRedraw(ATTR_UNUSED State *st) { +static Htop_Reaction actionRedraw(ATTR_UNUSED State* st) { clear(); return HTOP_REFRESH | HTOP_REDRAW_BAR; } -static Htop_Reaction actionTogglePauseProcessUpdate(State *st) { +static Htop_Reaction actionTogglePauseProcessUpdate(State* st) { st->pauseProcessUpdate = !st->pauseProcessUpdate; return HTOP_REFRESH | HTOP_REDRAW_BAR; } @@ -454,7 +454,7 @@ static Htop_Reaction actionHelp(State* st) { clear(); attrset(CRT_colors[HELP_BOLD]); - for (int i = 0; i < LINES-1; i++) + for (int i = 0; i < LINES - 1; i++) mvhline(i, 0, ' ', COLS); int line = 0; @@ -500,7 +500,7 @@ static Htop_Reaction actionHelp(State* st) { addattrstr(CRT_colors[BAR_SHADOW], " used/total"); addattrstr(CRT_colors[BAR_BORDER], "]"); attrset(CRT_colors[DEFAULT_COLOR]); - mvaddstr(line++,0, "Type and layout of header meters are configurable in the setup screen."); + mvaddstr(line++, 0, "Type and layout of header meters are configurable in the setup screen."); if (CRT_colorScheme == COLORSCHEME_MONOCHROME) { mvaddstr(line, 0, "In monochrome, meters display as different chars, in order: |#*@$%&."); } diff --git a/Affinity.c b/Affinity.c index 96591a658..bfa7ceb5f 100644 --- a/Affinity.c +++ b/Affinity.c @@ -74,7 +74,7 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { } bool Affinity_set(Process* proc, Arg arg) { - Affinity *this = arg.v; + Affinity* this = arg.v; hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); for (int i = 0; i < this->used; i++) { hwloc_bitmap_set(cpuset, this->cpus[i]); @@ -99,7 +99,7 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { } bool Affinity_set(Process* proc, Arg arg) { - Affinity *this = arg.v; + Affinity* this = arg.v; cpu_set_t cpuset; CPU_ZERO(&cpuset); for (int i = 0; i < this->used; i++) { diff --git a/AffinityPanel.c b/AffinityPanel.c index e184d64b2..85094b4c8 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -35,7 +35,7 @@ typedef struct MaskItem_ { char* indent; /* used also as an condition whether this is a tree node */ int value; /* tri-state: 0 - off, 1 - some set, 2 - all set */ int sub_tree; /* tri-state: 0 - no sub-tree, 1 - open sub-tree, 2 - closed sub-tree */ - Vector *children; + Vector* children; #ifdef HAVE_LIBHWLOC bool ownCpuset; hwloc_bitmap_t cpuset; @@ -123,11 +123,11 @@ typedef struct AffinityPanel_ { Panel super; ProcessList* pl; bool topoView; - Vector *cpuids; + Vector* cpuids; unsigned width; #ifdef HAVE_LIBHWLOC - MaskItem *topoRoot; + MaskItem* topoRoot; hwloc_const_cpuset_t allCpuset; hwloc_bitmap_t workCpuset; #endif @@ -262,7 +262,7 @@ static HandlerResult AffinityPanel_eventHandler(Panel* super, int ch) { #ifdef HAVE_LIBHWLOC -static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem *parent) { +static MaskItem* AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem* parent) { const char* type_name = hwloc_obj_type_string(obj->type); const char* index_prefix = "#"; unsigned depth = obj->depth; @@ -294,7 +294,7 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u xSnprintf(buf, 64, "%s %s%u", type_name, index_prefix, index); - MaskItem *item = MaskItem_newMask(buf, indent_buf, obj->complete_cpuset, false); + MaskItem* item = MaskItem_newMask(buf, indent_buf, obj->complete_cpuset, false); if (parent) Vector_add(parent->children, item); @@ -316,8 +316,8 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u return item; } -static MaskItem *AffinityPanel_buildTopology(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem *parent) { - MaskItem *item = AffinityPanel_addObject(this, obj, indent, parent); +static MaskItem* AffinityPanel_buildTopology(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem* parent) { + MaskItem* item = AffinityPanel_addObject(this, obj, indent, parent); if (obj->next_sibling) { indent |= (1u << obj->depth); } else { diff --git a/BatteryMeter.c b/BatteryMeter.c index c91ae9977..ac126cea7 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -21,7 +21,7 @@ static const int BatteryMeter_attributes[] = { BATTERY }; -static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) { +static void BatteryMeter_updateValues(Meter* this, char* buffer, int len) { ACPresence isOnAC; double percent; diff --git a/CPUMeter.c b/CPUMeter.c index 4997f6f8e..b1bb8f459 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -149,7 +149,7 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) { } } -static void CPUMeterCommonInit(Meter *this, int ncol) { +static void CPUMeterCommonInit(Meter* this, int ncol) { int cpus = this->pl->cpuCount; CPUMeterData* data = this->meterData; if (!data) { @@ -162,13 +162,13 @@ static void CPUMeterCommonInit(Meter *this, int ncol) { AllCPUsMeter_getRange(this, &start, &count); for (int i = 0; i < count; i++) { if (!meters[i]) - meters[i] = Meter_new(this->pl, start+i+1, (const MeterClass*) Class(CPUMeter)); + meters[i] = Meter_new(this->pl, start + i + 1, (const MeterClass*) Class(CPUMeter)); Meter_init(meters[i]); } if (this->mode == 0) this->mode = BAR_METERMODE; int h = Meter_modes[this->mode]->h; - this->h = h * ((count + ncol - 1)/ ncol); + this->h = h * ((count + ncol - 1) / ncol); } static void CPUMeterCommonUpdateMode(Meter* this, int mode, int ncol) { @@ -181,7 +181,7 @@ static void CPUMeterCommonUpdateMode(Meter* this, int mode, int ncol) { for (int i = 0; i < count; i++) { Meter_setMode(meters[i], mode); } - this->h = h * ((count + ncol - 1)/ ncol); + this->h = h * ((count + ncol - 1) / ncol); } static void AllCPUsMeter_done(Meter* this) { @@ -232,11 +232,11 @@ static void CPUMeterCommonDraw(Meter* this, int x, int y, int w, int ncol) { Meter** meters = data->meters; int start, count; AllCPUsMeter_getRange(this, &start, &count); - int colwidth = (w-ncol)/ncol + 1; + int colwidth = (w - ncol) / ncol + 1; int diff = (w - (colwidth * ncol)); int nrows = (count + ncol - 1) / ncol; - for (int i = 0; i < count; i++){ - int d = (i/nrows) > diff ? diff : (i / nrows) ; // dynamic spacer + for (int i = 0; i < count; i++) { + int d = (i / nrows) > diff ? diff : (i / nrows); // dynamic spacer int xpos = x + ((i / nrows) * colwidth) + d; int ypos = y + ((i % nrows) * meters[0]->h); meters[i]->draw(meters[i], xpos, ypos, colwidth); diff --git a/CRT.c b/CRT.c index d91d0d79f..38ba9da3c 100644 --- a/CRT.c +++ b/CRT.c @@ -42,7 +42,7 @@ in the source distribution for its full text. #define ColorPairGrayBlack ColorPair(Magenta,Magenta) #define ColorIndexGrayBlack ColorIndex(Magenta,Magenta) -static const char *const CRT_treeStrAscii[TREE_STR_COUNT] = { +static const char* const CRT_treeStrAscii[TREE_STR_COUNT] = { "-", // TREE_STR_HORZ "|", // TREE_STR_VERT "`", // TREE_STR_RTEE @@ -54,7 +54,7 @@ static const char *const CRT_treeStrAscii[TREE_STR_COUNT] = { #ifdef HAVE_LIBNCURSESW -static const char *const CRT_treeStrUtf8[TREE_STR_COUNT] = { +static const char* const CRT_treeStrUtf8[TREE_STR_COUNT] = { "\xe2\x94\x80", // TREE_STR_HORZ ─ "\xe2\x94\x82", // TREE_STR_VERT │ "\xe2\x94\x9c", // TREE_STR_RTEE ├ @@ -70,7 +70,7 @@ bool CRT_utf8 = false; #endif -const char *const *CRT_treeStr = CRT_treeStrAscii; +const char* const* CRT_treeStr = CRT_treeStrAscii; int CRT_delay; @@ -78,82 +78,82 @@ const int* CRT_colors; int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [COLORSCHEME_DEFAULT] = { - [RESET_COLOR] = ColorPair(White,Black), - [DEFAULT_COLOR] = ColorPair(White,Black), - [FUNCTION_BAR] = ColorPair(Black,Cyan), - [FUNCTION_KEY] = ColorPair(White,Black), - [PANEL_HEADER_FOCUS] = ColorPair(Black,Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White), - [FAILED_SEARCH] = ColorPair(Red,Cyan), - [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), - [UPTIME] = A_BOLD | ColorPair(Cyan,Black), - [BATTERY] = A_BOLD | ColorPair(Cyan,Black), - [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), - [METER_TEXT] = ColorPair(Cyan,Black), - [METER_VALUE] = A_BOLD | ColorPair(Cyan,Black), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Black), - [METER_VALUE_IOREAD] = ColorPair(Green,Black), - [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), - [LED_COLOR] = ColorPair(Green,Black), - [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black), + [RESET_COLOR] = ColorPair(White, Black), + [DEFAULT_COLOR] = ColorPair(White, Black), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = ColorPair(White, Black), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Black, White), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = A_BOLD | ColorPair(Cyan, Black), + [BATTERY] = A_BOLD | ColorPair(Cyan, Black), + [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black), + [METER_TEXT] = ColorPair(Cyan, Black), + [METER_VALUE] = A_BOLD | ColorPair(Cyan, Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Black), + [METER_VALUE_IOREAD] = ColorPair(Green, Black), + [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), + [LED_COLOR] = ColorPair(Green, Black), + [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), [PROCESS] = A_NORMAL, [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black), - [PROCESS_MEGABYTES] = ColorPair(Cyan,Black), - [PROCESS_GIGABYTES] = ColorPair(Green,Black), - [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Black), - [PROCESS_TREE] = ColorPair(Cyan,Black), - [PROCESS_R_STATE] = ColorPair(Green,Black), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,Black), - [PROCESS_THREAD] = ColorPair(Green,Black), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Black), + [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Black), + [PROCESS_MEGABYTES] = ColorPair(Cyan, Black), + [PROCESS_GIGABYTES] = ColorPair(Green, Black), + [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Black), + [PROCESS_TREE] = ColorPair(Cyan, Black), + [PROCESS_R_STATE] = ColorPair(Green, Black), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), + [PROCESS_THREAD] = ColorPair(Green, Black), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Black), [BAR_BORDER] = A_BOLD, [BAR_SHADOW] = A_BOLD | ColorPairGrayBlack, - [SWAP] = ColorPair(Red,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), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Cyan,Black), - [LOAD_AVERAGE_FIVE] = A_BOLD | ColorPair(Cyan,Black), - [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White,Black), + [SWAP] = ColorPair(Red, 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), + [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_BOLD] = A_BOLD | ColorPair(Cyan, Black), [CLOCK] = A_BOLD, [DATE] = A_BOLD, [DATETIME] = A_BOLD, - [CHECK_BOX] = ColorPair(Cyan,Black), + [CHECK_BOX] = ColorPair(Cyan, Black), [CHECK_MARK] = A_BOLD, [CHECK_TEXT] = A_NORMAL, [HOSTNAME] = A_BOLD, - [CPU_NICE] = ColorPair(Blue,Black), - [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black), - [CPU_NORMAL] = ColorPair(Green,Black), - [CPU_SYSTEM] = ColorPair(Red,Black), + [CPU_NICE] = ColorPair(Blue, Black), + [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue, Black), + [CPU_NORMAL] = ColorPair(Green, Black), + [CPU_SYSTEM] = ColorPair(Red, Black), [CPU_IOWAIT] = A_BOLD | ColorPairGrayBlack, - [CPU_IRQ] = ColorPair(Yellow,Black), - [CPU_SOFTIRQ] = ColorPair(Magenta,Black), - [CPU_STEAL] = ColorPair(Cyan,Black), - [CPU_GUEST] = ColorPair(Cyan,Black), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan,Black), - [PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan,Black), - [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Black), - [ZFS_MFU] = ColorPair(Blue,Black), - [ZFS_MRU] = ColorPair(Yellow,Black), - [ZFS_ANON] = ColorPair(Magenta,Black), - [ZFS_HEADER] = ColorPair(Cyan,Black), - [ZFS_OTHER] = ColorPair(Magenta,Black), - [ZFS_COMPRESSED] = ColorPair(Blue,Black), - [ZFS_RATIO] = ColorPair(Magenta,Black), - [ZRAM] = ColorPair(Yellow,Black), + [CPU_IRQ] = ColorPair(Yellow, Black), + [CPU_SOFTIRQ] = ColorPair(Magenta, Black), + [CPU_STEAL] = ColorPair(Cyan, Black), + [CPU_GUEST] = ColorPair(Cyan, Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan, Black), + [PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan, Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Black), + [ZFS_MFU] = ColorPair(Blue, Black), + [ZFS_MRU] = ColorPair(Yellow, Black), + [ZFS_ANON] = ColorPair(Magenta, Black), + [ZFS_HEADER] = ColorPair(Cyan, Black), + [ZFS_OTHER] = ColorPair(Magenta, Black), + [ZFS_COMPRESSED] = ColorPair(Blue, Black), + [ZFS_RATIO] = ColorPair(Magenta, Black), + [ZRAM] = ColorPair(Yellow, Black), }, [COLORSCHEME_MONOCHROME] = { [RESET_COLOR] = A_NORMAL, @@ -234,314 +234,314 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZRAM] = A_NORMAL, }, [COLORSCHEME_BLACKONWHITE] = { - [RESET_COLOR] = ColorPair(Black,White), - [DEFAULT_COLOR] = ColorPair(Black,White), - [FUNCTION_BAR] = ColorPair(Black,Cyan), - [FUNCTION_KEY] = ColorPair(Black,White), - [PANEL_HEADER_FOCUS] = ColorPair(Black,Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,White), - [FAILED_SEARCH] = ColorPair(Red,Cyan), - [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), - [UPTIME] = ColorPair(Yellow,White), - [BATTERY] = ColorPair(Yellow,White), - [LARGE_NUMBER] = ColorPair(Red,White), - [METER_TEXT] = ColorPair(Blue,White), - [METER_VALUE] = ColorPair(Black,White), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,White), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,White), - [METER_VALUE_IOREAD] = ColorPair(Green,White), - [METER_VALUE_IOWRITE] = ColorPair(Yellow,White), - [LED_COLOR] = ColorPair(Green,White), - [TASKS_RUNNING] = ColorPair(Green,White), - [PROCESS] = ColorPair(Black,White), - [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,White), - [PROCESS_TAG] = ColorPair(White,Blue), - [PROCESS_MEGABYTES] = ColorPair(Blue,White), - [PROCESS_GIGABYTES] = ColorPair(Green,White), - [PROCESS_BASENAME] = ColorPair(Blue,White), - [PROCESS_TREE] = ColorPair(Green,White), - [PROCESS_R_STATE] = ColorPair(Green,White), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,White), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,White), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,White), - [PROCESS_THREAD] = ColorPair(Blue,White), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,White), - [BAR_BORDER] = ColorPair(Blue,White), - [BAR_SHADOW] = ColorPair(Black,White), - [SWAP] = ColorPair(Red,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), - [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), - [CLOCK] = ColorPair(Black,White), - [DATE] = ColorPair(Black,White), - [DATETIME] = ColorPair(Black,White), - [CHECK_BOX] = ColorPair(Blue,White), - [CHECK_MARK] = ColorPair(Black,White), - [CHECK_TEXT] = ColorPair(Black,White), - [HOSTNAME] = ColorPair(Black,White), - [CPU_NICE] = ColorPair(Cyan,White), - [CPU_NICE_TEXT] = ColorPair(Cyan,White), - [CPU_NORMAL] = ColorPair(Green,White), - [CPU_SYSTEM] = ColorPair(Red,White), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black,White), - [CPU_IRQ] = ColorPair(Blue,White), - [CPU_SOFTIRQ] = ColorPair(Blue,White), - [CPU_STEAL] = ColorPair(Cyan,White), - [CPU_GUEST] = ColorPair(Cyan,White), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,White), - [PRESSURE_STALL_SIXTY] = ColorPair(Black,White), - [PRESSURE_STALL_TEN] = ColorPair(Black,White), - [ZFS_MFU] = ColorPair(Cyan,White), - [ZFS_MRU] = ColorPair(Yellow,White), - [ZFS_ANON] = ColorPair(Magenta,White), - [ZFS_HEADER] = ColorPair(Yellow,White), - [ZFS_OTHER] = ColorPair(Magenta,White), - [ZFS_COMPRESSED] = ColorPair(Cyan,White), - [ZFS_RATIO] = ColorPair(Magenta,White), - [ZRAM] = ColorPair(Yellow,White) + [RESET_COLOR] = ColorPair(Black, White), + [DEFAULT_COLOR] = ColorPair(Black, White), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = ColorPair(Black, White), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue, White), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = ColorPair(Yellow, White), + [BATTERY] = ColorPair(Yellow, White), + [LARGE_NUMBER] = ColorPair(Red, White), + [METER_TEXT] = ColorPair(Blue, White), + [METER_VALUE] = ColorPair(Black, White), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, White), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, White), + [METER_VALUE_IOREAD] = ColorPair(Green, White), + [METER_VALUE_IOWRITE] = ColorPair(Yellow, White), + [LED_COLOR] = ColorPair(Green, White), + [TASKS_RUNNING] = ColorPair(Green, White), + [PROCESS] = ColorPair(Black, White), + [PROCESS_SHADOW] = A_BOLD | ColorPair(Black, White), + [PROCESS_TAG] = ColorPair(White, Blue), + [PROCESS_MEGABYTES] = ColorPair(Blue, White), + [PROCESS_GIGABYTES] = ColorPair(Green, White), + [PROCESS_BASENAME] = ColorPair(Blue, White), + [PROCESS_TREE] = ColorPair(Green, White), + [PROCESS_R_STATE] = ColorPair(Green, White), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, White), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, White), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, White), + [PROCESS_THREAD] = ColorPair(Blue, White), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, White), + [BAR_BORDER] = ColorPair(Blue, White), + [BAR_SHADOW] = ColorPair(Black, White), + [SWAP] = ColorPair(Red, 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), + [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), + [CLOCK] = ColorPair(Black, White), + [DATE] = ColorPair(Black, White), + [DATETIME] = ColorPair(Black, White), + [CHECK_BOX] = ColorPair(Blue, White), + [CHECK_MARK] = ColorPair(Black, White), + [CHECK_TEXT] = ColorPair(Black, White), + [HOSTNAME] = ColorPair(Black, White), + [CPU_NICE] = ColorPair(Cyan, White), + [CPU_NICE_TEXT] = ColorPair(Cyan, White), + [CPU_NORMAL] = ColorPair(Green, White), + [CPU_SYSTEM] = ColorPair(Red, White), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black, White), + [CPU_IRQ] = ColorPair(Blue, White), + [CPU_SOFTIRQ] = ColorPair(Blue, White), + [CPU_STEAL] = ColorPair(Cyan, White), + [CPU_GUEST] = ColorPair(Cyan, White), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black, White), + [PRESSURE_STALL_SIXTY] = ColorPair(Black, White), + [PRESSURE_STALL_TEN] = ColorPair(Black, White), + [ZFS_MFU] = ColorPair(Cyan, White), + [ZFS_MRU] = ColorPair(Yellow, White), + [ZFS_ANON] = ColorPair(Magenta, White), + [ZFS_HEADER] = ColorPair(Yellow, White), + [ZFS_OTHER] = ColorPair(Magenta, White), + [ZFS_COMPRESSED] = ColorPair(Cyan, White), + [ZFS_RATIO] = ColorPair(Magenta, White), + [ZRAM] = ColorPair(Yellow, White) }, [COLORSCHEME_LIGHTTERMINAL] = { - [RESET_COLOR] = ColorPair(Blue,Black), - [DEFAULT_COLOR] = ColorPair(Blue,Black), - [FUNCTION_BAR] = ColorPair(Black,Cyan), - [FUNCTION_KEY] = ColorPair(Blue,Black), - [PANEL_HEADER_FOCUS] = ColorPair(Black,Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,Black), - [FAILED_SEARCH] = ColorPair(Red,Cyan), - [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), - [UPTIME] = ColorPair(Yellow,Black), - [BATTERY] = ColorPair(Yellow,Black), - [LARGE_NUMBER] = ColorPair(Red,Black), - [METER_TEXT] = ColorPair(Blue,Black), - [METER_VALUE] = ColorPair(Blue,Black), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), - [METER_VALUE_IOREAD] = ColorPair(Green,Black), - [METER_VALUE_IOWRITE] = ColorPair(Yellow,Black), - [LED_COLOR] = ColorPair(Green,Black), - [TASKS_RUNNING] = ColorPair(Green,Black), - [PROCESS] = ColorPair(Blue,Black), + [RESET_COLOR] = ColorPair(Blue, Black), + [DEFAULT_COLOR] = ColorPair(Blue, Black), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = ColorPair(Blue, Black), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue, Black), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = ColorPair(Yellow, Black), + [BATTERY] = ColorPair(Yellow, Black), + [LARGE_NUMBER] = ColorPair(Red, Black), + [METER_TEXT] = ColorPair(Blue, Black), + [METER_VALUE] = ColorPair(Blue, Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, Black), + [METER_VALUE_IOREAD] = ColorPair(Green, Black), + [METER_VALUE_IOWRITE] = ColorPair(Yellow, Black), + [LED_COLOR] = ColorPair(Green, Black), + [TASKS_RUNNING] = ColorPair(Green, Black), + [PROCESS] = ColorPair(Blue, Black), [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = ColorPair(Yellow,Blue), - [PROCESS_MEGABYTES] = ColorPair(Blue,Black), - [PROCESS_GIGABYTES] = ColorPair(Green,Black), - [PROCESS_BASENAME] = ColorPair(Green,Black), - [PROCESS_TREE] = ColorPair(Blue,Black), - [PROCESS_R_STATE] = ColorPair(Green,Black), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,Black), - [PROCESS_THREAD] = ColorPair(Blue,Black), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black), - [BAR_BORDER] = ColorPair(Blue,Black), + [PROCESS_TAG] = ColorPair(Yellow, Blue), + [PROCESS_MEGABYTES] = ColorPair(Blue, Black), + [PROCESS_GIGABYTES] = ColorPair(Green, Black), + [PROCESS_BASENAME] = ColorPair(Green, Black), + [PROCESS_TREE] = ColorPair(Blue, Black), + [PROCESS_R_STATE] = ColorPair(Green, Black), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), + [PROCESS_THREAD] = ColorPair(Blue, Black), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black), + [BAR_BORDER] = ColorPair(Blue, Black), [BAR_SHADOW] = ColorPairGrayBlack, - [SWAP] = ColorPair(Red,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), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Blue,Black), - [LOAD_AVERAGE_FIVE] = ColorPair(Blue,Black), - [LOAD_AVERAGE_ONE] = ColorPair(Yellow,Black), - [LOAD] = ColorPair(Yellow,Black), - [HELP_BOLD] = ColorPair(Blue,Black), - [CLOCK] = ColorPair(Yellow,Black), - [DATE] = ColorPair(White,Black), - [DATETIME] = ColorPair(White,Black), - [CHECK_BOX] = ColorPair(Blue,Black), - [CHECK_MARK] = ColorPair(Blue,Black), - [CHECK_TEXT] = ColorPair(Blue,Black), - [HOSTNAME] = ColorPair(Yellow,Black), - [CPU_NICE] = ColorPair(Cyan,Black), - [CPU_NICE_TEXT] = ColorPair(Cyan,Black), - [CPU_NORMAL] = ColorPair(Green,Black), - [CPU_SYSTEM] = ColorPair(Red,Black), - [CPU_IOWAIT] = A_BOLD | ColorPair(Blue,Black), - [CPU_IRQ] = A_BOLD | ColorPair(Blue,Black), - [CPU_SOFTIRQ] = ColorPair(Blue,Black), - [CPU_STEAL] = ColorPair(Blue,Black), - [CPU_GUEST] = ColorPair(Blue,Black), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Blue,Black), - [PRESSURE_STALL_SIXTY] = ColorPair(Blue,Black), - [PRESSURE_STALL_TEN] = ColorPair(Blue,Black), - [ZFS_MFU] = ColorPair(Cyan,Black), - [ZFS_MRU] = ColorPair(Yellow,Black), - [ZFS_ANON] = A_BOLD | ColorPair(Magenta,Black), - [ZFS_HEADER] = ColorPair(Blue,Black), - [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black), - [ZFS_COMPRESSED] = ColorPair(Cyan,Black), - [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Black), - [ZRAM] = ColorPair(Yellow,Black), + [SWAP] = ColorPair(Red, 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), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Blue, Black), + [LOAD_AVERAGE_FIVE] = ColorPair(Blue, Black), + [LOAD_AVERAGE_ONE] = ColorPair(Yellow, Black), + [LOAD] = ColorPair(Yellow, Black), + [HELP_BOLD] = ColorPair(Blue, Black), + [CLOCK] = ColorPair(Yellow, Black), + [DATE] = ColorPair(White, Black), + [DATETIME] = ColorPair(White, Black), + [CHECK_BOX] = ColorPair(Blue, Black), + [CHECK_MARK] = ColorPair(Blue, Black), + [CHECK_TEXT] = ColorPair(Blue, Black), + [HOSTNAME] = ColorPair(Yellow, Black), + [CPU_NICE] = ColorPair(Cyan, Black), + [CPU_NICE_TEXT] = ColorPair(Cyan, Black), + [CPU_NORMAL] = ColorPair(Green, Black), + [CPU_SYSTEM] = ColorPair(Red, Black), + [CPU_IOWAIT] = A_BOLD | ColorPair(Blue, Black), + [CPU_IRQ] = A_BOLD | ColorPair(Blue, Black), + [CPU_SOFTIRQ] = ColorPair(Blue, Black), + [CPU_STEAL] = ColorPair(Blue, Black), + [CPU_GUEST] = ColorPair(Blue, Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Blue, Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Blue, Black), + [PRESSURE_STALL_TEN] = ColorPair(Blue, Black), + [ZFS_MFU] = ColorPair(Cyan, Black), + [ZFS_MRU] = ColorPair(Yellow, Black), + [ZFS_ANON] = A_BOLD | ColorPair(Magenta, Black), + [ZFS_HEADER] = ColorPair(Blue, Black), + [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Black), + [ZFS_COMPRESSED] = ColorPair(Cyan, Black), + [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Black), + [ZRAM] = ColorPair(Yellow, Black), }, [COLORSCHEME_MIDNIGHT] = { - [RESET_COLOR] = ColorPair(White,Blue), - [DEFAULT_COLOR] = ColorPair(White,Blue), - [FUNCTION_BAR] = ColorPair(Black,Cyan), + [RESET_COLOR] = ColorPair(White, Blue), + [DEFAULT_COLOR] = ColorPair(White, Blue), + [FUNCTION_BAR] = ColorPair(Black, Cyan), [FUNCTION_KEY] = A_NORMAL, - [PANEL_HEADER_FOCUS] = ColorPair(Black,Cyan), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,White), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow,Blue), - [FAILED_SEARCH] = ColorPair(Red,Cyan), - [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), - [UPTIME] = A_BOLD | ColorPair(Yellow,Blue), - [BATTERY] = A_BOLD | ColorPair(Yellow,Blue), - [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Blue), - [METER_TEXT] = ColorPair(Cyan,Blue), - [METER_VALUE] = A_BOLD | ColorPair(Cyan,Blue), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Blue), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Blue), - [METER_VALUE_IOREAD] = ColorPair(Green,Blue), - [METER_VALUE_IOWRITE] = ColorPair(Black,Blue), - [LED_COLOR] = ColorPair(Green,Blue), - [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Blue), - [PROCESS] = ColorPair(White,Blue), - [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Blue), - [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Blue), - [PROCESS_MEGABYTES] = ColorPair(Cyan,Blue), - [PROCESS_GIGABYTES] = ColorPair(Green,Blue), - [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Blue), - [PROCESS_TREE] = ColorPair(Cyan,Blue), - [PROCESS_R_STATE] = ColorPair(Green,Blue), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Blue), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Blue), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,Blue), - [PROCESS_THREAD] = ColorPair(Green,Blue), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Blue), - [BAR_BORDER] = A_BOLD | ColorPair(Yellow,Blue), - [BAR_SHADOW] = ColorPair(Cyan,Blue), - [SWAP] = ColorPair(Red,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), - [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), - [CLOCK] = ColorPair(White,Blue), - [DATE] = ColorPair(White,Blue), - [DATETIME] = ColorPair(White,Blue), - [CHECK_BOX] = ColorPair(Cyan,Blue), - [CHECK_MARK] = A_BOLD | ColorPair(White,Blue), - [CHECK_TEXT] = A_NORMAL | ColorPair(White,Blue), - [HOSTNAME] = ColorPair(White,Blue), - [CPU_NICE] = A_BOLD | ColorPair(Cyan,Blue), - [CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan,Blue), - [CPU_NORMAL] = A_BOLD | ColorPair(Green,Blue), - [CPU_SYSTEM] = A_BOLD | ColorPair(Red,Blue), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black,Blue), - [CPU_IRQ] = A_BOLD | ColorPair(Black,Blue), - [CPU_SOFTIRQ] = ColorPair(Black,Blue), - [CPU_STEAL] = ColorPair(White,Blue), - [CPU_GUEST] = ColorPair(White,Blue), - [PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black,Blue), - [PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White,Blue), - [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Blue), - [ZFS_MFU] = A_BOLD | ColorPair(White,Blue), - [ZFS_MRU] = A_BOLD | ColorPair(Yellow,Blue), - [ZFS_ANON] = A_BOLD | ColorPair(Magenta,Blue), - [ZFS_HEADER] = A_BOLD | ColorPair(Yellow,Blue), - [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Blue), - [ZFS_COMPRESSED] = A_BOLD | ColorPair(White,Blue), - [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Blue), - [ZRAM] = A_BOLD | ColorPair(Yellow,Blue), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Cyan), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, White), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow, Blue), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = A_BOLD | ColorPair(Yellow, Blue), + [BATTERY] = A_BOLD | ColorPair(Yellow, Blue), + [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Blue), + [METER_TEXT] = ColorPair(Cyan, Blue), + [METER_VALUE] = A_BOLD | ColorPair(Cyan, Blue), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Blue), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Blue), + [METER_VALUE_IOREAD] = ColorPair(Green, Blue), + [METER_VALUE_IOWRITE] = ColorPair(Black, Blue), + [LED_COLOR] = ColorPair(Green, Blue), + [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Blue), + [PROCESS] = ColorPair(White, Blue), + [PROCESS_SHADOW] = A_BOLD | ColorPair(Black, Blue), + [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Blue), + [PROCESS_MEGABYTES] = ColorPair(Cyan, Blue), + [PROCESS_GIGABYTES] = ColorPair(Green, Blue), + [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Blue), + [PROCESS_TREE] = ColorPair(Cyan, Blue), + [PROCESS_R_STATE] = ColorPair(Green, Blue), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Blue), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Blue), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Blue), + [PROCESS_THREAD] = ColorPair(Green, Blue), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Blue), + [BAR_BORDER] = A_BOLD | ColorPair(Yellow, Blue), + [BAR_SHADOW] = ColorPair(Cyan, Blue), + [SWAP] = ColorPair(Red, 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), + [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), + [CLOCK] = ColorPair(White, Blue), + [DATE] = ColorPair(White, Blue), + [DATETIME] = ColorPair(White, Blue), + [CHECK_BOX] = ColorPair(Cyan, Blue), + [CHECK_MARK] = A_BOLD | ColorPair(White, Blue), + [CHECK_TEXT] = A_NORMAL | ColorPair(White, Blue), + [HOSTNAME] = ColorPair(White, Blue), + [CPU_NICE] = A_BOLD | ColorPair(Cyan, Blue), + [CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan, Blue), + [CPU_NORMAL] = A_BOLD | ColorPair(Green, Blue), + [CPU_SYSTEM] = A_BOLD | ColorPair(Red, Blue), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Blue), + [CPU_IRQ] = A_BOLD | ColorPair(Black, Blue), + [CPU_SOFTIRQ] = ColorPair(Black, Blue), + [CPU_STEAL] = ColorPair(White, Blue), + [CPU_GUEST] = ColorPair(White, Blue), + [PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black, Blue), + [PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White, Blue), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Blue), + [ZFS_MFU] = A_BOLD | ColorPair(White, Blue), + [ZFS_MRU] = A_BOLD | ColorPair(Yellow, Blue), + [ZFS_ANON] = A_BOLD | ColorPair(Magenta, Blue), + [ZFS_HEADER] = A_BOLD | ColorPair(Yellow, Blue), + [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Blue), + [ZFS_COMPRESSED] = A_BOLD | ColorPair(White, Blue), + [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Blue), + [ZRAM] = A_BOLD | ColorPair(Yellow, Blue), }, [COLORSCHEME_BLACKNIGHT] = { - [RESET_COLOR] = ColorPair(Cyan,Black), - [DEFAULT_COLOR] = ColorPair(Cyan,Black), - [FUNCTION_BAR] = ColorPair(Black,Green), - [FUNCTION_KEY] = ColorPair(Cyan,Black), - [PANEL_HEADER_FOCUS] = ColorPair(Black,Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White), - [FAILED_SEARCH] = ColorPair(Red,Green), - [PAUSED] = A_BOLD | ColorPair(Yellow,Green), - [UPTIME] = ColorPair(Green,Black), - [BATTERY] = ColorPair(Green,Black), - [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), - [METER_TEXT] = ColorPair(Cyan,Black), - [METER_VALUE] = ColorPair(Green,Black), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), - [METER_VALUE_IOREAD] = ColorPair(Green,Black), - [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), - [LED_COLOR] = ColorPair(Green,Black), - [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black), - [PROCESS] = ColorPair(Cyan,Black), + [RESET_COLOR] = ColorPair(Cyan, Black), + [DEFAULT_COLOR] = ColorPair(Cyan, Black), + [FUNCTION_BAR] = ColorPair(Black, Green), + [FUNCTION_KEY] = ColorPair(Cyan, Black), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Black, White), + [FAILED_SEARCH] = ColorPair(Red, Green), + [PAUSED] = A_BOLD | ColorPair(Yellow, Green), + [UPTIME] = ColorPair(Green, Black), + [BATTERY] = ColorPair(Green, Black), + [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black), + [METER_TEXT] = ColorPair(Cyan, Black), + [METER_VALUE] = ColorPair(Green, Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, Black), + [METER_VALUE_IOREAD] = ColorPair(Green, Black), + [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), + [LED_COLOR] = ColorPair(Green, Black), + [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), + [PROCESS] = ColorPair(Cyan, Black), [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black), - [PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black), - [PROCESS_GIGABYTES] = A_BOLD | ColorPair(Yellow,Black), - [PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black), - [PROCESS_TREE] = ColorPair(Cyan,Black), - [PROCESS_THREAD] = ColorPair(Green,Black), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black), - [PROCESS_R_STATE] = ColorPair(Green,Black), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,Black), - [BAR_BORDER] = A_BOLD | ColorPair(Green,Black), - [BAR_SHADOW] = ColorPair(Cyan,Black), - [SWAP] = ColorPair(Red,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), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Green,Black), - [LOAD_AVERAGE_FIVE] = ColorPair(Green,Black), - [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(Green,Black), + [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Black), + [PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green, Black), + [PROCESS_GIGABYTES] = A_BOLD | ColorPair(Yellow, Black), + [PROCESS_BASENAME] = A_BOLD | ColorPair(Green, Black), + [PROCESS_TREE] = ColorPair(Cyan, Black), + [PROCESS_THREAD] = ColorPair(Green, Black), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black), + [PROCESS_R_STATE] = ColorPair(Green, Black), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), + [BAR_BORDER] = A_BOLD | ColorPair(Green, Black), + [BAR_SHADOW] = ColorPair(Cyan, Black), + [SWAP] = ColorPair(Red, 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), + [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), - [CLOCK] = ColorPair(Green,Black), - [CHECK_BOX] = ColorPair(Green,Black), - [CHECK_MARK] = A_BOLD | ColorPair(Green,Black), - [CHECK_TEXT] = ColorPair(Cyan,Black), - [HOSTNAME] = ColorPair(Green,Black), - [CPU_NICE] = ColorPair(Blue,Black), - [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black), - [CPU_NORMAL] = ColorPair(Green,Black), - [CPU_SYSTEM] = ColorPair(Red,Black), - [CPU_IOWAIT] = ColorPair(Yellow,Black), - [CPU_IRQ] = A_BOLD | ColorPair(Blue,Black), - [CPU_SOFTIRQ] = ColorPair(Blue,Black), - [CPU_STEAL] = ColorPair(Cyan,Black), - [CPU_GUEST] = ColorPair(Cyan,Black), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green,Black), - [PRESSURE_STALL_SIXTY] = ColorPair(Green,Black), - [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green,Black), - [ZFS_MFU] = ColorPair(Blue,Black), - [ZFS_MRU] = ColorPair(Yellow,Black), - [ZFS_ANON] = ColorPair(Magenta,Black), - [ZFS_HEADER] = ColorPair(Yellow,Black), - [ZFS_OTHER] = ColorPair(Magenta,Black), - [ZFS_COMPRESSED] = ColorPair(Blue,Black), - [ZFS_RATIO] = ColorPair(Magenta,Black), - [ZRAM] = ColorPair(Yellow,Black), + [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Black), + [CLOCK] = ColorPair(Green, Black), + [CHECK_BOX] = ColorPair(Green, Black), + [CHECK_MARK] = A_BOLD | ColorPair(Green, Black), + [CHECK_TEXT] = ColorPair(Cyan, Black), + [HOSTNAME] = ColorPair(Green, Black), + [CPU_NICE] = ColorPair(Blue, Black), + [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue, Black), + [CPU_NORMAL] = ColorPair(Green, Black), + [CPU_SYSTEM] = ColorPair(Red, Black), + [CPU_IOWAIT] = ColorPair(Yellow, Black), + [CPU_IRQ] = A_BOLD | ColorPair(Blue, Black), + [CPU_SOFTIRQ] = ColorPair(Blue, Black), + [CPU_STEAL] = ColorPair(Cyan, Black), + [CPU_GUEST] = ColorPair(Cyan, Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green, Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Green, Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green, Black), + [ZFS_MFU] = ColorPair(Blue, Black), + [ZFS_MRU] = ColorPair(Yellow, Black), + [ZFS_ANON] = ColorPair(Magenta, Black), + [ZFS_HEADER] = ColorPair(Yellow, Black), + [ZFS_OTHER] = ColorPair(Magenta, Black), + [ZFS_COMPRESSED] = ColorPair(Blue, Black), + [ZFS_RATIO] = ColorPair(Magenta, Black), + [ZRAM] = ColorPair(Yellow, Black), }, [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. }; @@ -610,7 +610,7 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { for (int i = 0; i < LAST_COLORELEMENT; i++) { unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][i]; - CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPairGrayBlack) ? ColorPair(White,Black) : color; + CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPairGrayBlack) ? ColorPair(White, Black) : color; } halfdelay(CRT_delay); @@ -649,7 +649,7 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { struct sigaction act; sigemptyset (&act.sa_mask); - act.sa_flags = (int)SA_RESETHAND|SA_NODEFER; + 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]); @@ -732,11 +732,11 @@ void CRT_setColors(int colorScheme) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { - if (ColorIndex(i,j) != ColorPairGrayBlack) { + if (ColorIndex(i, j) != ColorPairGrayBlack) { int bg = (colorScheme != COLORSCHEME_BLACKNIGHT) - ? (j==0 ? -1 : j) + ? (j == 0 ? -1 : j) : j; - init_pair(ColorIndex(i,j), i, bg); + init_pair(ColorIndex(i, j), i, bg); } } } diff --git a/CRT.h b/CRT.h index 49ed4ed0c..fccf65c14 100644 --- a/CRT.h +++ b/CRT.h @@ -133,7 +133,7 @@ extern bool CRT_utf8; #endif -extern const char *const *CRT_treeStr; +extern const char* const* CRT_treeStr; extern int CRT_delay; diff --git a/ClockMeter.c b/ClockMeter.c index c6f2ab33a..3cc9dd032 100644 --- a/ClockMeter.c +++ b/ClockMeter.c @@ -22,7 +22,7 @@ static const int ClockMeter_attributes[] = { static void ClockMeter_updateValues(Meter* this, char* buffer, int size) { time_t t = time(NULL); struct tm result; - struct tm *lt = localtime_r(&t, &result); + struct tm* lt = localtime_r(&t, &result); this->values[0] = lt->tm_hour * 60 + lt->tm_min; strftime(buffer, size, "%H:%M:%S", lt); } diff --git a/ColumnsPanel.c b/ColumnsPanel.c index 36127bd5a..ffd4d0bbe 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -139,7 +139,7 @@ void ColumnsPanel_update(Panel* super) { ColumnsPanel* this = (ColumnsPanel*) super; int size = Panel_size(super); this->settings->changed = true; - this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size+1)); + this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size + 1)); this->settings->flags = 0; for (int i = 0; i < size; i++) { int key = ((ListItem*) Panel_get(super, i))->key; diff --git a/DateMeter.c b/DateMeter.c index c1a097f65..bfe0cbf19 100644 --- a/DateMeter.c +++ b/DateMeter.c @@ -22,10 +22,10 @@ static const int DateMeter_attributes[] = { static void DateMeter_updateValues(Meter* this, char* buffer, int size) { time_t t = time(NULL); struct tm result; - struct tm *lt = localtime_r(&t, &result); + struct tm* lt = localtime_r(&t, &result); this->values[0] = lt->tm_yday; int year = lt->tm_year + 1900; - if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) { + if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { this->total = 366; } else { diff --git a/DateTimeMeter.c b/DateTimeMeter.c index 745821916..ad5e81ea4 100644 --- a/DateTimeMeter.c +++ b/DateTimeMeter.c @@ -22,9 +22,9 @@ static const int DateTimeMeter_attributes[] = { static void DateTimeMeter_updateValues(Meter* this, char* buffer, int size) { time_t t = time(NULL); struct tm result; - struct tm *lt = localtime_r(&t, &result); + struct tm* lt = localtime_r(&t, &result); int year = lt->tm_year + 1900; - if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) { + if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { this->total = 366; } else { diff --git a/EnvScreen.c b/EnvScreen.c index cd8e0cb3d..30faaaba1 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -26,7 +26,7 @@ const InfoScreenClass EnvScreen_class = { EnvScreen* EnvScreen_new(Process* process) { EnvScreen* this = xMalloc(sizeof(EnvScreen)); Object_setClass(this, Class(EnvScreen)); - return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " "); + return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 3, " "); } void EnvScreen_delete(Object* this) { @@ -47,7 +47,7 @@ void EnvScreen_scan(InfoScreen* this) { char* env = Platform_getProcessEnv(this->process->pid); CRT_restorePrivileges(); if (env) { - for (char *p = env; *p; p = strrchr(p, 0)+1) + for (char* p = env; *p; p = strrchr(p, 0) + 1) InfoScreen_addLine(this, p); free(env); } diff --git a/FunctionBar.c b/FunctionBar.c index 9b454ac8d..934565831 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -94,14 +94,14 @@ void FunctionBar_draw(const FunctionBar* this) { void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor) { attrset(CRT_colors[FUNCTION_BAR]); - mvhline(LINES-1, 0, ' ', COLS); + mvhline(LINES - 1, 0, ' ', COLS); int x = 0; for (int i = 0; i < this->size; i++) { attrset(CRT_colors[FUNCTION_KEY]); - mvaddstr(LINES-1, x, this->keys.constKeys[i]); + mvaddstr(LINES - 1, x, this->keys.constKeys[i]); x += strlen(this->keys.constKeys[i]); attrset(CRT_colors[FUNCTION_BAR]); - mvaddstr(LINES-1, x, this->functions[i]); + mvaddstr(LINES - 1, x, this->functions[i]); x += strlen(this->functions[i]); } @@ -110,7 +110,7 @@ void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr attrset(CRT_colors[FUNCTION_BAR]); else attrset(attr); - mvaddstr(LINES-1, x, buffer); + mvaddstr(LINES - 1, x, buffer); attrset(CRT_colors[RESET_COLOR]); x += strlen(buffer); } @@ -130,7 +130,7 @@ void FunctionBar_append(const char* buffer, int attr) { attrset(CRT_colors[FUNCTION_BAR]); else attrset(attr); - mvaddstr(LINES-1, currentLen, buffer); + mvaddstr(LINES - 1, currentLen, buffer); attrset(CRT_colors[RESET_COLOR]); currentLen += strlen(buffer); diff --git a/Header.c b/Header.c index 3bb24c23d..4448baa69 100644 --- a/Header.c +++ b/Header.c @@ -63,7 +63,7 @@ void Header_writeBackToSettings(const Header* this) { Vector* vec = this->columns[col]; int len = Vector_size(vec); - colSettings->names = xCalloc(len+1, sizeof(char*)); + colSettings->names = xCalloc(len + 1, sizeof(char*)); colSettings->modes = xCalloc(len, sizeof(int)); colSettings->len = len; diff --git a/HostnameMeter.c b/HostnameMeter.c index 6cf9e07e7..000bc3fd8 100644 --- a/HostnameMeter.c +++ b/HostnameMeter.c @@ -21,7 +21,7 @@ static const int HostnameMeter_attributes[] = { static void HostnameMeter_updateValues(Meter* this, char* buffer, int size) { (void) this; - gethostname(buffer, size-1); + gethostname(buffer, size - 1); } const MeterClass HostnameMeter_class = { diff --git a/IncSet.h b/IncSet.h index a6c1974ef..b07840f7e 100644 --- a/IncSet.h +++ b/IncSet.h @@ -22,7 +22,7 @@ typedef enum { } IncType; typedef struct IncMode_ { - char buffer[INCMODE_MAX+1]; + char buffer[INCMODE_MAX + 1]; int index; FunctionBar* bar; bool isFilter; diff --git a/InfoScreen.c b/InfoScreen.c index 7f4baa72c..102f0ba76 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -65,21 +65,23 @@ void InfoScreen_addLine(InfoScreen* this, const char* line) { Vector_add(this->lines, (Object*) ListItem_new(line, 0)); const char* incFilter = IncSet_filter(this->inc); if (!incFilter || String_contains_i(line, incFilter)) - Panel_add(this->display, Vector_get(this->lines, Vector_size(this->lines)-1)); + Panel_add(this->display, Vector_get(this->lines, Vector_size(this->lines) - 1)); } void InfoScreen_appendLine(InfoScreen* this, const char* line) { - ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines)-1); + ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines) - 1); ListItem_append(last, line); const char* incFilter = IncSet_filter(this->inc); - if (incFilter && Panel_get(this->display, Panel_size(this->display)-1) != (Object*)last && String_contains_i(line, incFilter)) + if (incFilter && Panel_get(this->display, Panel_size(this->display) - 1) != (Object*)last && String_contains_i(line, incFilter)) Panel_add(this->display, (Object*)last); } void InfoScreen_run(InfoScreen* this) { Panel* panel = this->display; - if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + if (As_InfoScreen(this)->scan) + InfoScreen_scan(this); + InfoScreen_draw(this); bool looping = true; @@ -88,7 +90,7 @@ void InfoScreen_run(InfoScreen* this) { Panel_draw(panel, true); if (this->inc->active) { - (void) move(LINES-1, CRT_cursorX); + (void) move(LINES - 1, CRT_cursorX); } set_escdelay(25); int ch = getch(); @@ -144,8 +146,9 @@ void InfoScreen_run(InfoScreen* this) { looping = false; break; case KEY_RESIZE: - Panel_resize(panel, COLS, LINES-2); - if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + Panel_resize(panel, COLS, LINES - 2); + if (As_InfoScreen(this)->scan) + InfoScreen_scan(this); InfoScreen_draw(this); break; default: diff --git a/MainPanel.c b/MainPanel.c index 05a55e600..9322fe027 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -36,7 +36,7 @@ void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) { void MainPanel_pidSearch(MainPanel* this, int ch) { Panel* super = (Panel*) this; - pid_t pid = ch-48 + this->pidSearch; + pid_t pid = ch - 48 + this->pidSearch; for (int i = 0; i < Panel_size(super); i++) { Process* p = (Process*) Panel_get(super, i); if (p && p->pid == pid) { @@ -153,7 +153,9 @@ bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Ar } if (!anyTagged) { Process* p = (Process*) Panel_getSelected(super); - if (p) ok = fn(p, arg) && ok; + if (p) { + ok &= fn(p, arg); + } } if (wasAnyTagged) *wasAnyTagged = anyTagged; diff --git a/MainPanel.h b/MainPanel.h index 3c5552940..03a1affde 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -24,7 +24,7 @@ typedef struct MainPanel_ { Panel super; State* state; IncSet* inc; - Htop_Action *keys; + Htop_Action* keys; pid_t pidSearch; } MainPanel; diff --git a/Meter.c b/Meter.c index 0cf7ee0b6..d17ba95a8 100644 --- a/Meter.c +++ b/Meter.c @@ -48,7 +48,7 @@ Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* typ } int Meter_humanUnit(char* buffer, unsigned long int value, int size) { - const char * prefix = "KMGTPEZY"; + const char* prefix = "KMGTPEZY"; unsigned long int powi = 1; unsigned int written, powj = 1, precision = 2; @@ -199,7 +199,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { double value = this->values[i]; value = CLAMP(value, 0.0, this->total); if (value > 0) { - blockSizes[i] = ceil((value/this->total) * w); + blockSizes[i] = ceil((value / this->total) * w); } else { blockSizes[i] = 0; } @@ -285,11 +285,11 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { struct timeval now; gettimeofday(&now, NULL); if (!timercmp(&now, &(data->time), <)) { - struct timeval delay = { .tv_sec = CRT_delay/10, .tv_usec = (CRT_delay-((CRT_delay/10)*10)) * 100000 }; + struct timeval delay = { .tv_sec = CRT_delay / 10, .tv_usec = (CRT_delay - ((CRT_delay / 10) * 10)) * 100000 }; timeradd(&now, &delay, &(data->time)); for (int i = 0; i < nValues - 1; i++) - data->values[i] = data->values[i+1]; + data->values[i] = data->values[i + 1]; char buffer[nValues]; Meter_updateValues(this, buffer, nValues - 1); @@ -301,15 +301,15 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { data->values[nValues - 1] = value; } - int i = nValues - (w*2) + 2, k = 0; + int i = nValues - (w * 2) + 2, k = 0; if (i < 0) { - k = -i/2; + k = -i / 2; i = 0; } - for (; i < nValues - 1; i+=2, k++) { + for (; i < nValues - 1; i += 2, k++) { int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT; int v1 = CLAMP((int) lround(data->values[i] * pix), 1, pix); - int v2 = CLAMP((int) lround(data->values[i+1] * pix), 1, pix); + int v2 = CLAMP((int) lround(data->values[i + 1] * pix), 1, pix); int colorIdx = GRAPH_1; for (int line = 0; line < GRAPH_HEIGHT; line++) { @@ -317,7 +317,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { int line2 = CLAMP(v2 - (GraphMeterMode_pixPerRow * (GRAPH_HEIGHT - 1 - line)), 0, GraphMeterMode_pixPerRow); attrset(CRT_colors[colorIdx]); - mvaddstr(y+line, x+k, GraphMeterMode_dots[line1 * (GraphMeterMode_pixPerRow + 1) + line2]); + mvaddstr(y + line, x + k, GraphMeterMode_dots[line1 * (GraphMeterMode_pixPerRow + 1) + line2]); colorIdx = GRAPH_2; } } @@ -327,17 +327,17 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { /* ---------- LEDMeterMode ---------- */ static const char* const LEDMeterMode_digitsAscii[] = { - " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ ", - "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|", - "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|" + " __ ", " ", " __ ", " __ ", " ", " __ ", " __ ", " __ ", " __ ", " __ ", + "| |", " |", " __|", " __|", "|__|", "|__ ", "|__ ", " |", "|__|", "|__|", + "|__|", " |", "|__ ", " __|", " |", " __|", "|__|", " |", "|__|", " __|" }; #ifdef HAVE_LIBNCURSESW static const char* const LEDMeterMode_digitsUtf8[] = { - "┌──┐"," ┐ ","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐", - "│ │"," │ ","┌──┘"," ──┤","└──┤","└──┐","├──┐"," │","├──┤","└──┤", - "└──┘"," ╵ ","└──╴","╶──┘"," ╵","╶──┘","└──┘"," ╵","└──┘"," ──┘" + "┌──┐", " ┐ ", "╶──┐", "╶──┐", "╷ ╷", "┌──╴", "┌──╴", "╶──┐", "┌──┐", "┌──┐", + "│ │", " │ ", "┌──┘", " ──┤", "└──┤", "└──┐", "├──┐", " │", "├──┤", "└──┤", + "└──┘", " ╵ ", "└──╴", "╶──┘", " ╵", "╶──┘", "└──┘", " ╵", "└──┘", " ──┘" }; #endif @@ -367,9 +367,9 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { int yText = #ifdef HAVE_LIBNCURSESW - CRT_utf8 ? y+1 : + CRT_utf8 ? y + 1 : #endif - y+2; + y + 2; attrset(CRT_colors[LED_COLOR]); mvaddstr(yText, x, this->caption); int xx = x + strlen(this->caption); @@ -377,7 +377,7 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { for (int i = 0; i < len; i++) { char c = RichString_getCharVal(out, i); if (c >= '0' && c <= '9') { - LEDMeterMode_drawDigit(xx, y, c-48); + LEDMeterMode_drawDigit(xx, y, c - 48); xx += 4; } else { mvaddch(yText, xx, c); diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 0de9ee037..829fafee1 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -73,7 +73,7 @@ OpenFilesScreen* OpenFilesScreen_new(const Process* process) { this->pid = process->tgid; else this->pid = process->pid; - return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " FD TYPE MODE DEVICE SIZE NODE NAME"); + return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 3, " FD TYPE MODE DEVICE SIZE NODE NAME"); } void OpenFilesScreen_delete(Object* this) { diff --git a/Panel.c b/Panel.c index 4c3339636..5e92c9c7e 100644 --- a/Panel.c +++ b/Panel.c @@ -201,7 +201,7 @@ void Panel_setSelected(Panel* this, int selected) { } } -void Panel_splice(Panel *this, Vector* from) { +void Panel_splice(Panel* this, Vector* from) { assert (this != NULL); assert (from != NULL); @@ -295,15 +295,15 @@ void Panel_draw(Panel* this, bool focus) { Object_display(newObj, &new); int newLen = RichString_sizeVal(new); this->selectedLen = newLen; - mvhline(y+ this->oldSelected - first, x+0, ' ', this->w); + mvhline(y + this->oldSelected - first, x + 0, ' ', this->w); if (scrollH < oldLen) - RichString_printoffnVal(old, y+this->oldSelected - first, x, + RichString_printoffnVal(old, y + this->oldSelected - first, x, scrollH, MINIMUM(oldLen - scrollH, this->w)); attrset(selectionColor); - mvhline(y+this->selected - first, x+0, ' ', this->w); + mvhline(y + this->selected - first, x + 0, ' ', this->w); RichString_setAttr(&new, selectionColor); if (scrollH < newLen) - RichString_printoffnVal(new, y+this->selected - first, x, + RichString_printoffnVal(new, y + this->selected - first, x, scrollH, MINIMUM(newLen - scrollH, this->w)); attrset(CRT_colors[RESET_COLOR]); RichString_end(new); diff --git a/Panel.h b/Panel.h index 604750a58..1ea5c7b82 100644 --- a/Panel.h +++ b/Panel.h @@ -111,7 +111,7 @@ void Panel_setSelected(Panel* this, int selected); void Panel_draw(Panel* this, bool focus); -void Panel_splice(Panel *this, Vector* from); +void Panel_splice(Panel* this, Vector* from); bool Panel_onKey(Panel* this, int key); diff --git a/Process.c b/Process.c index 11b99b8bc..af7bf79d7 100644 --- a/Process.c +++ b/Process.c @@ -74,7 +74,7 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori RichString_appendn(str, processColor, buffer, len); } else if (number < 100000) { //2 digit MB, 3 digit KB - len = snprintf(buffer, 10, "%2llu", number/1000); + len = snprintf(buffer, 10, "%2llu", number / 1000); RichString_appendn(str, processMegabytesColor, buffer, len); number %= 1000; len = snprintf(buffer, 10, "%03llu ", number); @@ -87,7 +87,7 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori } else if (number < 10000 * ONE_K) { //1 digit GB, 3 digit MB number /= ONE_K; - len = snprintf(buffer, 10, "%1llu", number/1000); + len = snprintf(buffer, 10, "%1llu", number / 1000); RichString_appendn(str, processGigabytesColor, buffer, len); number %= 1000; len = snprintf(buffer, 10, "%03lluM ", number); @@ -95,7 +95,7 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori } else if (number < 100000 * ONE_K) { //2 digit GB, 1 digit MB number /= 100 * ONE_K; - len = snprintf(buffer, 10, "%2llu", number/10); + len = snprintf(buffer, 10, "%2llu", number / 10); RichString_appendn(str, processGigabytesColor, buffer, len); number %= 10; len = snprintf(buffer, 10, ".%1lluG ", number); @@ -108,14 +108,14 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori } else if (number < 10000ULL * ONE_M) { //1 digit TB, 3 digit GB number /= ONE_M; - len = snprintf(buffer, 10, "%1llu", number/1000); + len = snprintf(buffer, 10, "%1llu", number / 1000); RichString_appendn(str, largeNumberColor, buffer, len); number %= 1000; len = snprintf(buffer, 10, "%03lluG ", number); RichString_appendn(str, processGigabytesColor, buffer, len); } else { //2 digit TB and above - len = snprintf(buffer, 10, "%4.1lfT ", (double)number/ONE_G); + len = snprintf(buffer, 10, "%4.1lfT ", (double)number / ONE_G); RichString_appendn(str, largeNumberColor, buffer, len); } } @@ -142,18 +142,18 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori } else if (number >= 100LL * ONE_DECIMAL_T) { xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_M); RichString_appendn(str, largeNumberColor, buffer, 8); - RichString_appendn(str, processMegabytesColor, buffer+8, 4); + RichString_appendn(str, processMegabytesColor, buffer + 8, 4); } else if (number >= 10LL * ONE_DECIMAL_G) { xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_K); RichString_appendn(str, largeNumberColor, buffer, 5); - RichString_appendn(str, processMegabytesColor, buffer+5, 3); - RichString_appendn(str, processColor, buffer+8, 4); + RichString_appendn(str, processMegabytesColor, buffer + 5, 3); + RichString_appendn(str, processColor, buffer + 8, 4); } else { xSnprintf(buffer, 13, "%11llu ", number); RichString_appendn(str, largeNumberColor, buffer, 2); - RichString_appendn(str, processMegabytesColor, buffer+2, 3); - RichString_appendn(str, processColor, buffer+5, 3); - RichString_appendn(str, processShadowColor, buffer+8, 4); + RichString_appendn(str, processMegabytesColor, buffer + 2, 3); + RichString_appendn(str, processColor, buffer + 5, 3); + RichString_appendn(str, processShadowColor, buffer + 8, 4); } } diff --git a/Process.h b/Process.h index b2c820808..465fed683 100644 --- a/Process.h +++ b/Process.h @@ -119,7 +119,7 @@ extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; extern char Process_pidFormat[20]; -typedef Process*(*Process_New)(const struct Settings_*); +typedef Process* (* Process_New)(const struct Settings_*); typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField); typedef struct ProcessClass_ { diff --git a/ProcessList.c b/ProcessList.c index dac86cb87..ff4aa9b32 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -131,9 +131,9 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i Vector_add(this->processes2, process); else Vector_insert(this->processes2, 0, process); - assert(Vector_size(this->processes2) == s+1); (void)s; + assert(Vector_size(this->processes2) == s + 1); (void)s; int nextIndent = indent | (1 << level); - ProcessList_buildTree(this, process->pid, level+1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false); + ProcessList_buildTree(this, process->pid, level + 1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false); if (i == size - 1) process->indent = -nextIndent; else @@ -143,8 +143,8 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i } static long ProcessList_treeProcessCompare(const void* v1, const void* v2) { - const Process *p1 = (const Process*)v1; - const Process *p2 = (const Process*)v2; + const Process* p1 = (const Process*)v1; + const Process* p2 = (const Process*)v2; return p1->pid - p2->pid; } diff --git a/RichString.c b/RichString.c index bda39181e..99c535b1d 100644 --- a/RichString.c +++ b/RichString.c @@ -48,7 +48,7 @@ static void RichString_setLen(RichString* this, int len) { #ifdef HAVE_LIBNCURSESW static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { - wchar_t data[len+1]; + wchar_t data[len + 1]; len = mbstowcs(data, data_c, len); if (len < 0) return; diff --git a/RichString.h b/RichString.h index 11be41372..5bcda6029 100644 --- a/RichString.h +++ b/RichString.h @@ -38,7 +38,7 @@ in the source distribution for its full text. typedef struct RichString_ { int chlen; CharType* chptr; - CharType chstr[RICHSTRING_MAXLEN+1]; + CharType chstr[RICHSTRING_MAXLEN + 1]; } RichString; void RichString_setAttrn(RichString* this, int attrs, int start, int finish); diff --git a/ScreenManager.c b/ScreenManager.c index bc5f66ac8..f586d04a0 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -58,7 +58,7 @@ void ScreenManager_add(ScreenManager* this, Panel* item, int size) { if (size > 0) { Panel_resize(item, size, height); } else { - Panel_resize(item, COLS-this->x1+this->x2-lastX, height); + Panel_resize(item, COLS - this->x1 + this->x2 - lastX, height); } Panel_move(item, lastX, this->y1); } @@ -85,18 +85,18 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) { int lastX = 0; for (int i = 0; i < panels - 1; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); - Panel_resize(panel, panel->w, LINES-y1+y2); + Panel_resize(panel, panel->w, LINES - y1 + y2); Panel_move(panel, lastX, y1); lastX = panel->x + panel->w + 1; } - Panel* panel = (Panel*) Vector_get(this->panels, panels-1); - Panel_resize(panel, COLS-x1+x2-lastX, LINES-y1+y2); + Panel* panel = (Panel*) Vector_get(this->panels, panels - 1); + Panel_resize(panel, COLS - x1 + x2 - lastX, LINES - y1 + y2); Panel_move(panel, lastX, y1); } // TODO: VERTICAL } -static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool *rescan, bool *timedOut) { +static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut) { ProcessList* pl = this->header->pl; struct timeval tv; @@ -127,7 +127,7 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) { Panel* panel = (Panel*) Vector_get(this->panels, i); Panel_draw(panel, i == focus); if (this->orientation == HORIZONTAL) { - mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1); + mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1); } } } @@ -182,11 +182,11 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { } else { for (int i = 0; i < this->panelCount; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); - if (mevent.x >= panel->x && mevent.x <= panel->x+panel->w) { + if (mevent.x >= panel->x && mevent.x <= panel->x + panel->w) { if (mevent.y == panel->y) { ch = EVENT_HEADER_CLICK(mevent.x - panel->x); break; - } else if (mevent.y > panel->y && mevent.y <= panel->y+panel->h) { + } else if (mevent.y > panel->y && mevent.y <= panel->y + panel->h) { ch = KEY_MOUSE; if (panel == panelFocus || this->allowFocusChange) { focus = i; diff --git a/Settings.c b/Settings.c index 2cb560ed4..2e274e949 100644 --- a/Settings.c +++ b/Settings.c @@ -217,7 +217,7 @@ static void writeFields(FILE* fd, ProcessField* fields, const char* name) { const char* sep = ""; for (int i = 0; fields[i]; i++) { // This "-1" is for compatibility with the older enum format. - fprintf(fd, "%s%d", sep, (int) fields[i]-1); + fprintf(fd, "%s%d", sep, (int) fields[i] - 1); sep = " "; } fprintf(fd, "\n"); @@ -255,7 +255,7 @@ bool Settings_write(Settings* this) { fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n"); writeFields(fd, this->fields, "fields"); // This "-1" is for compatibility with the older enum format. - fprintf(fd, "sort_key=%d\n", (int) this->sortKey-1); + fprintf(fd, "sort_key=%d\n", (int) this->sortKey - 1); fprintf(fd, "sort_direction=%d\n", (int) this->direction); fprintf(fd, "hide_threads=%d\n", (int) this->hideThreads); fprintf(fd, "hide_kernel_threads=%d\n", (int) this->hideKernelThreads); @@ -311,7 +311,7 @@ Settings* Settings_new(int initialCpuCount) { #ifdef HAVE_LIBHWLOC this->topologyAffinity = false; #endif - this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); + this->fields = xCalloc(Platform_numberOfFields + 1, sizeof(ProcessField)); // TODO: turn 'fields' into a Vector, // (and ProcessFields into proper objects). this->flags = 0; diff --git a/TraceScreen.c b/TraceScreen.c index 18dad58cd..7346a0f8d 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -52,7 +52,7 @@ TraceScreen* TraceScreen_new(Process* process) { this->tracing = true; FunctionBar* fuBar = FunctionBar_new(TraceScreenFunctions, TraceScreenKeys, TraceScreenEvents); CRT_disableDelay(); - return (TraceScreen*) InfoScreen_init(&this->super, process, fuBar, LINES-2, ""); + return (TraceScreen*) InfoScreen_init(&this->super, process, fuBar, LINES - 2, ""); } void TraceScreen_delete(Object* cast) { @@ -141,8 +141,9 @@ void TraceScreen_updateTrace(InfoScreen* super) { FD_SET(fd_strace, &fds); struct timeval tv; - tv.tv_sec = 0; tv.tv_usec = 500; - int ready = select(fd_strace+1, &fds, NULL, NULL, &tv); + tv.tv_sec = 0; + tv.tv_usec = 500; + int ready = select(fd_strace + 1, &fds, NULL, NULL, &tv); size_t nread = 0; if (ready > 0 && FD_ISSET(fd_strace, &fds)) nread = fread(buffer, 1, sizeof(buffer) - 1, this->strace); @@ -158,10 +159,10 @@ void TraceScreen_updateTrace(InfoScreen* super) { } else { InfoScreen_addLine(&this->super, line); } - line = buffer+i+1; + line = buffer + i + 1; } } - if (line < buffer+nread) { + if (line < buffer + nread) { InfoScreen_addLine(&this->super, line); buffer[nread] = '\0'; this->contLine = true; diff --git a/UptimeMeter.c b/UptimeMeter.c index 89e341752..790702869 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -24,9 +24,9 @@ static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) { return; } int seconds = totalseconds % 60; - int minutes = (totalseconds/60) % 60; - int hours = (totalseconds/3600) % 24; - int days = (totalseconds/86400); + int minutes = (totalseconds / 60) % 60; + int hours = (totalseconds / 3600) % 24; + int days = (totalseconds / 86400); this->values[0] = days; if (days > this->total) { this->total = days; diff --git a/Vector.c b/Vector.c index ea276671c..eb80e1459 100644 --- a/Vector.c +++ b/Vector.c @@ -118,7 +118,8 @@ static int partition(Object** array, int left, int right, int pivotIndex, Object static void quickSort(Object** array, int left, int right, Object_Compare compare) { if (left >= right) return; - int pivotIndex = (left+right) / 2; + + int pivotIndex = (left + right) / 2; int pivotNewIndex = partition(array, left, right, pivotIndex, compare); quickSort(array, left, pivotNewIndex - 1, compare); quickSort(array, pivotNewIndex + 1, right, compare); @@ -148,17 +149,18 @@ static void combSort(Object** array, int left, int right, Object_Compare compare */ static void insertionSort(Object** array, int left, int right, Object_Compare compare) { - for (int i = left+1; i <= right; i++) { + for (int i = left + 1; i <= right; i++) { Object* t = array[i]; int j = i - 1; while (j >= left) { //comparisons++; if (compare(array[j], t) <= 0) break; - array[j+1] = array[j]; + + array[j + 1] = array[j]; j--; } - array[j+1] = t; + array[j + 1] = t; } } @@ -260,7 +262,7 @@ void Vector_set(Vector* this, int idx, void* data_) { Vector_checkArraySize(this); if (idx >= this->items) { - this->items = idx+1; + this->items = idx + 1; } else { if (this->owner) { Object* removed = this->array[idx]; @@ -293,7 +295,7 @@ void Vector_add(Vector* this, void* data_) { assert(Vector_isConsistent(this)); int i = this->items; Vector_set(this, this->items, data); - assert(this->items == i+1); (void)(i); + assert(this->items == i + 1); (void)(i); assert(Vector_isConsistent(this)); } diff --git a/Vector.h b/Vector.h index 70df3e4a2..706881527 100644 --- a/Vector.h +++ b/Vector.h @@ -17,7 +17,7 @@ in the source distribution for its full text. #endif typedef struct Vector_ { - Object **array; + Object** array; const ObjectClass* type; int arraySize; int growthRate; diff --git a/XUtils.c b/XUtils.c index 811fa50f6..dcc8b390b 100644 --- a/XUtils.c +++ b/XUtils.c @@ -59,7 +59,7 @@ char* String_cat(const char* s1, const char* s2) { const size_t l2 = strlen(s2); char* out = xMalloc(l1 + l2 + 1); memcpy(out, s1, l1); - memcpy(out+l1, s2, l2); + memcpy(out + l1, s2, l2); out[l1 + l2] = '\0'; return out; } @@ -70,7 +70,7 @@ char* String_trim(const char* in) { } size_t len = strlen(in); - while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) { + while (len > 0 && (in[len - 1] == ' ' || in[len - 1] == '\t' || in[len - 1] == '\n')) { len--; } @@ -126,12 +126,12 @@ char* String_getToken(const char* line, const unsigned short int numMatch) { for (size_t i = 0; i < len; i++) { char lastState = inWord; - inWord = line[i] == ' ' ? 0:1; + inWord = line[i] == ' ' ? 0 : 1; if (lastState == 0 && inWord == 1) count++; - if (inWord == 1){ + if (inWord == 1) { if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) { match[foundCount] = line[i]; foundCount++; diff --git a/XUtils.h b/XUtils.h index 591e98bbd..a978a0eda 100644 --- a/XUtils.h +++ b/XUtils.h @@ -54,10 +54,10 @@ char* String_getToken(const char* line, unsigned short int numMatch); char* String_readLine(FILE* fd); ATTR_FORMAT(printf, 2, 3) -int xAsprintf(char **strp, const char* fmt, ...); +int xAsprintf(char** strp, const char* fmt, ...); ATTR_FORMAT(printf, 3, 4) -int xSnprintf(char *buf, int len, const char* fmt, ...); +int xSnprintf(char* buf, int len, const char* fmt, ...); char* xStrdup(const char* str) ATTR_NONNULL; diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index a92f26618..c06ec4a6c 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -52,7 +52,7 @@ bool Process_isThread(const Process* this) { return false; } -char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { +char* DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { /* This function is from the old Mac version of htop. Originally from ps? */ int mib[3], argmax, nargs, c = 0; size_t size; @@ -68,7 +68,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { } /* Allocate space for the arguments. */ - procargs = ( char * ) xMalloc( argmax ); + procargs = (char*)xMalloc(argmax); if ( procargs == NULL ) { goto ERROR_A; } @@ -195,8 +195,8 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { return retval; } -void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists) { - struct extern_proc *ep = &ps->kp_proc; +void DarwinProcess_setFromKInfoProc(Process* proc, struct kinfo_proc* ps, bool exists) { + struct extern_proc* ep = &ps->kp_proc; /* UNSET HERE : * @@ -241,7 +241,7 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e proc->updated = true; } -void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl) { +void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessList* dpl) { struct proc_taskinfo pti; if (sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { @@ -280,7 +280,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList * Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread * and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c */ -void DarwinProcess_scanThreads(DarwinProcess *dp) { +void DarwinProcess_scanThreads(DarwinProcess* dp) { Process* proc = (Process*) dp; kern_return_t ret; diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index 1d9dc34aa..627a6bcba 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -28,17 +28,17 @@ void Process_delete(Object* cast); bool Process_isThread(const Process* this); -char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset); +char* DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset); -void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists); +void DarwinProcess_setFromKInfoProc(Process* proc, struct kinfo_proc* ps, bool exists); -void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl); +void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessList* dpl); /* * Scan threads for process state information. * Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread * and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c */ -void DarwinProcess_scanThreads(DarwinProcess *dp); +void DarwinProcess_scanThreads(DarwinProcess* dp); #endif diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index bb7c56dbf..673d9e614 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -27,7 +27,7 @@ struct kern { short int version[3]; }; -void GetKernelVersion(struct kern *k) { +void GetKernelVersion(struct kern* k) { static short int version_[3] = {0}; if (!version_[0]) { // just in case it fails someday @@ -64,7 +64,7 @@ int CompareKernelVersion(short int major, short int minor, short int component) return 0; } -void ProcessList_getHostInfo(host_basic_info_data_t *p) { +void ProcessList_getHostInfo(host_basic_info_data_t* p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { @@ -72,7 +72,7 @@ void ProcessList_getHostInfo(host_basic_info_data_t *p) { } } -void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { +void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t* p) { if (NULL != p && NULL != *p) { if (0 != munmap(*p, vm_page_size)) { CRT_fatalError("Unable to free old CPU load information\n"); @@ -81,7 +81,7 @@ void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { } } -unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { +unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t* p) { mach_msg_type_number_t info_size = sizeof(processor_cpu_load_info_t); unsigned cpu_count; @@ -101,9 +101,9 @@ void ProcessList_getVMStats(vm_statistics_t p) { } } -struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { +struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count) { int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 }; - struct kinfo_proc *processes = NULL; + struct kinfo_proc* processes = NULL; /* Note the two calls to sysctl(). One to get length and one to get the * data. This -does- mean that the second call could end up with a missing diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index 44a847dc6..bdcbb183c 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -9,7 +9,7 @@ in the source distribution for its full text. struct kern; -void GetKernelVersion(struct kern *k); +void GetKernelVersion(struct kern* k); /* compare the given os version with the one installed returns: 0 if equals the installed version @@ -37,15 +37,15 @@ typedef struct DarwinProcessList_ { ZfsArcStats zfs; } DarwinProcessList; -void ProcessList_getHostInfo(host_basic_info_data_t *p); +void ProcessList_getHostInfo(host_basic_info_data_t* p); -void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p); +void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t* p); -unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p); +unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t* p); void ProcessList_getVMStats(vm_statistics_t p); -struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count); +struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count); ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); diff --git a/darwin/Platform.c b/darwin/Platform.c index c5a22da4c..e48fbbd3d 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -176,7 +176,7 @@ ProcessPidColumn Process_pidColumns[] = { }; static double Platform_setCPUAverageValues(Meter* mtr) { - const ProcessList *dpl = mtr->pl; + const ProcessList* dpl = mtr->pl; int cpus = dpl->cpuCount; double sumNice = 0.0; double sumNormal = 0.0; @@ -200,9 +200,9 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { return Platform_setCPUAverageValues(mtr); } - const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl; - const processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1]; - const processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1]; + const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl; + const processor_cpu_load_info_t prev = &dpl->prev_load[cpu - 1]; + const processor_cpu_load_info_t curr = &dpl->curr_load[cpu - 1]; double total = 0; /* Take the sums */ @@ -228,7 +228,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { } void Platform_setMemoryValues(Meter* mtr) { - const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl; + const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl; const struct vm_statistics* vm = &dpl->vm_stats; double page_K = (double)vm_page_size / (double)1024; @@ -283,14 +283,14 @@ char* Platform_getProcessEnv(pid_t pid) { p += sizeof(int); // skip exe - p = strchr(p, 0)+1; + p = strchr(p, 0) + 1; // skip padding while (!*p && p < endp) ++p; // skip argv - for (; argc-- && p < endp; p = strrchr(p, 0)+1) + for (; argc-- && p < endp; p = strrchr(p, 0) + 1) ; // skip padding @@ -298,10 +298,10 @@ char* Platform_getProcessEnv(pid_t pid) { ++p; size_t size = endp - p; - env = xMalloc(size+2); + env = xMalloc(size + 2); memcpy(env, p, size); env[size] = 0; - env[size+1] = 0; + env[size + 1] = 0; } } free(buf); @@ -317,10 +317,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; diff --git a/darwin/Platform.h b/darwin/Platform.h index 471b38a9a..7d3f41978 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -51,9 +51,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 6650cb7e4..457a488a5 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -92,7 +92,7 @@ void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, Proces // add Platform-specific fields here case PID: xSnprintf(buffer, n, Process_pidFormat, (fp->kernel ? -1 : this->pid)); break; case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break; - case JAIL:{ + case JAIL: { xSnprintf(buffer, n, "%-11s ", fp->jname); if (buffer[11] != '\0') { buffer[11] = ' '; diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 90bc7f7ab..d3acf73d9 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -149,8 +149,8 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { size_t sizeof_cp_time_array; - unsigned long *cp_time_n; // old clicks state - unsigned long *cp_time_o; // current clicks state + unsigned long* cp_time_n; // old clicks state + unsigned long* cp_time_o; // current clicks state unsigned long cp_time_d[CPUSTATES]; double cp_time_p[CPUSTATES]; @@ -296,9 +296,9 @@ char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kpro static inline void DragonFlyBSDProcessList_scanJails(DragonFlyBSDProcessList* dfpl) { size_t len; - char *jls; /* Jail list */ - char *curpos; - char *nextpos; + char* jls; /* Jail list */ + char* curpos; + char* nextpos; if (sysctlbyname("jail.list", NULL, &len, NULL, 0) == -1) { fprintf(stderr, "initial sysctlbyname / jail.list failed\n"); @@ -329,7 +329,7 @@ static inline void DragonFlyBSDProcessList_scanJails(DragonFlyBSDProcessList* df curpos = jls; while (curpos) { int jailid; - char *str_hostname; + char* str_hostname; nextpos = strchr(curpos, '\n'); if (nextpos) *nextpos++ = 0; @@ -337,7 +337,7 @@ static inline void DragonFlyBSDProcessList_scanJails(DragonFlyBSDProcessList* df jailid = atoi(strtok(curpos, " ")); str_hostname = strtok(NULL, " "); - char *jname = (char *) (Hashtable_get(dfpl->jails, jailid)); + char* jname = (char*) (Hashtable_get(dfpl->jails, jailid)); if (jname == NULL) { jname = xStrdup(str_hostname); Hashtable_put(dfpl->jails, jailid, jname); @@ -353,7 +353,7 @@ char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int ja char* hostname; char* jname; - if (jailid != 0 && dfpl->jails && (hostname = (char *)Hashtable_get(dfpl->jails, jailid))) { + if (jailid != 0 && dfpl->jails && (hostname = (char*)Hashtable_get(dfpl->jails, jailid))) { jname = xStrdup(hostname); } else { jname = xStrdup("-"); diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index f3965fd37..ff65a6369 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -42,13 +42,13 @@ typedef struct DragonFlyBSDProcessList_ { CPUData* cpus; - unsigned long *cp_time_o; - unsigned long *cp_time_n; + unsigned long* cp_time_o; + unsigned long* cp_time_n; - unsigned long *cp_times_o; - unsigned long *cp_times_n; + unsigned long* cp_times_o; + unsigned long* cp_times_n; - Hashtable *jails; + Hashtable* jails; } DragonFlyBSDProcessList; ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 6f8c2023a..5e9fe335b 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -169,11 +169,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0]+v[1]+v[2]+v[3]; + percent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0]+v[1]+v[2]; + percent = v[0] + v[1] + v[2]; } percent = CLAMP(percent, 0.0, 100.0); @@ -212,10 +212,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 6c8847191..e31fbeac4 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -43,9 +43,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index fee2c2c8d..a4516d041 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -83,7 +83,7 @@ static void FreeBSDProcess_writeField(const Process* this, RichString* str, Proc switch ((int) field) { // add FreeBSD-specific fields here case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break; - case JAIL:{ + case JAIL: { xSnprintf(buffer, n, "%-11s ", fp->jname); if (buffer[11] != '\0') { buffer[11] = ' '; diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 8be627c9e..4594b992f 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -175,8 +175,8 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { size_t sizeof_cp_time_array; - unsigned long *cp_time_n; // old clicks state - unsigned long *cp_time_o; // current clicks state + unsigned long* cp_time_n; // old clicks state + unsigned long* cp_time_o; // current clicks state unsigned long cp_time_d[CPUSTATES]; double cp_time_p[CPUSTATES]; @@ -415,18 +415,18 @@ static char* FreeBSDProcessList_readJailName(const struct kinfo_proc* kproc) { char* jname; char jnamebuf[MAXHOSTNAMELEN]; - if (kproc->ki_jid != 0 ){ + if (kproc->ki_jid != 0 ) { memset(jnamebuf, 0, sizeof(jnamebuf)); IGNORE_WCASTQUAL_BEGIN - *(const void **)&jiov[0].iov_base = "jid"; + *(const void**)&jiov[0].iov_base = "jid"; jiov[0].iov_len = sizeof("jid"); jiov[1].iov_base = (void*) &kproc->ki_jid; jiov[1].iov_len = sizeof(kproc->ki_jid); - *(const void **)&jiov[2].iov_base = "name"; + *(const void**)&jiov[2].iov_base = "name"; jiov[2].iov_len = sizeof("name"); jiov[3].iov_base = jnamebuf; jiov[3].iov_len = sizeof(jnamebuf); - *(const void **)&jiov[4].iov_base = "errmsg"; + *(const void**)&jiov[4].iov_base = "errmsg"; jiov[4].iov_len = sizeof("errmsg"); jiov[5].iov_base = jail_errmsg; jiov[5].iov_len = JAIL_ERRMSGLEN; @@ -446,8 +446,8 @@ IGNORE_WCASTQUAL_END return NULL; } } else { - jnamebuf[0]='-'; - jnamebuf[1]='\0'; + jnamebuf[0] = '-'; + jnamebuf[1] = '\0'; jname = xStrdup(jnamebuf); } return jname; diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index e97444bd8..cbe4742c6 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -48,11 +48,11 @@ typedef struct FreeBSDProcessList_ { Hashtable* ttys; - unsigned long *cp_time_o; - unsigned long *cp_time_n; + unsigned long* cp_time_o; + unsigned long* cp_time_n; - unsigned long *cp_times_o; - unsigned long *cp_times_n; + unsigned long* cp_times_o; + unsigned long* cp_times_n; } FreeBSDProcessList; diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 32b542939..a8edd0365 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -180,11 +180,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0]+v[1]+v[2]+v[3]; + percent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0]+v[1]+v[2]; + percent = v[0] + v[1] + v[2]; } percent = CLAMP(percent, 0.0, 100.0); @@ -234,10 +234,10 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; } - if (env[capacity-1] || env[capacity-2]) { - env = xRealloc(env, capacity+2); + if (env[capacity - 1] || env[capacity - 2]) { + env = xRealloc(env, capacity + 2); env[capacity] = 0; - env[capacity+1] = 0; + env[capacity + 1] = 0; } return env; @@ -283,10 +283,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return true; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { int r; // get number of interfaces diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 894b3e252..c396f2af3 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -46,9 +46,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/htop.c b/htop.c index 2e11a949e..76754462f 100644 --- a/htop.c +++ b/htop.c @@ -106,10 +106,10 @@ static CommandLineSettings parseArguments(int argc, char** argv) { {"tree", no_argument, 0, 't'}, {"pid", required_argument, 0, 'p'}, {"filter", required_argument, 0, 'F'}, - {0,0,0,0} + {0, 0, 0, 0} }; - int opt, opti=0; + int opt, opti = 0; /* Parse arguments */ while ((opt = getopt_long(argc, argv, "hVMCs:td:u::Up:F:", long_opts, &opti))) { if (opt == EOF) break; @@ -218,7 +218,7 @@ static void millisleep(unsigned long millisec) { .tv_sec = 0, .tv_nsec = millisec * 1000000L }; - while (nanosleep(&req,&req)==-1) { + while (nanosleep(&req, &req) == -1) { continue; } } @@ -242,7 +242,7 @@ static void setCommFilter(State* state, char** commFilter) { int main(int argc, char** argv) { - char *lc_ctype = getenv("LC_CTYPE"); + char* lc_ctype = getenv("LC_CTYPE"); if (lc_ctype != NULL) setlocale(LC_CTYPE, lc_ctype); else if ((lc_ctype = getenv("LC_ALL"))) @@ -318,7 +318,7 @@ int main(int argc, char** argv) { ScreenManager_run(scr, NULL, NULL); attron(CRT_colors[RESET_COLOR]); - mvhline(LINES-1, 0, ' ', COLS); + mvhline(LINES - 1, 0, ' ', COLS); attroff(CRT_colors[RESET_COLOR]); refresh(); diff --git a/linux/Battery.c b/linux/Battery.c index c185258ae..326f35fd5 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -37,7 +37,7 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat // but I think this is on the way out so I did not rewrite it. // The /sys implementation below does things the right way. -static unsigned long int parseBatInfo(const char *fileName, const unsigned short int lineNum, const unsigned short int wordNum) { +static unsigned long int parseBatInfo(const char* fileName, const unsigned short int lineNum, const unsigned short int wordNum) { const char batteryPath[] = PROCDIR "/acpi/battery/"; DIR* batteryDir = opendir(batteryPath); if (!batteryDir) @@ -81,7 +81,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short if (!line) break; - char *foundNumStr = String_getToken(line, wordNum); + char* foundNumStr = String_getToken(line, wordNum); const unsigned long int foundNum = atoi(foundNumStr); free(foundNumStr); free(line); @@ -98,8 +98,8 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short static ACPresence procAcpiCheck(void) { ACPresence isOn = AC_ERROR; - const char *power_supplyPath = PROCDIR "/acpi/ac_adapter"; - DIR *dir = opendir(power_supplyPath); + const char* power_supplyPath = PROCDIR "/acpi/ac_adapter"; + DIR* dir = opendir(power_supplyPath); if (!dir) { return AC_ERROR; } @@ -115,7 +115,7 @@ static ACPresence procAcpiCheck(void) { continue; char statePath[256]; - xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName); + xSnprintf(statePath, sizeof(statePath), "%s/%s/state", power_supplyPath, entryName); FILE* file = fopen(statePath, "r"); if (!file) { isOn = AC_ERROR; @@ -125,7 +125,7 @@ static ACPresence procAcpiCheck(void) { fclose(file); if (!line) continue; - char *isOnline = String_getToken(line, 2); + char* isOnline = String_getToken(line, 2); free(line); if (String_eq(isOnline, "on-line")) { @@ -165,14 +165,14 @@ static void Battery_getProcData(double* level, ACPresence* isOnAC) { // READ FROM /sys // ---------------------------------------- -static inline ssize_t xread(int fd, void *buf, size_t count) { +static inline ssize_t xread(int fd, void* buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; for (;;) { ssize_t res = read(fd, buf, count); if (res == -1 && errno == EINTR) continue; if (res > 0) { - buf = ((char*)buf)+res; + buf = ((char*)buf) + res; count -= res; alreadyRead += res; } @@ -186,7 +186,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { *level = NAN; *isOnAC = AC_ERROR; - DIR *dir = opendir(SYS_POWERSUPPLY_DIR); + DIR* dir = opendir(SYS_POWERSUPPLY_DIR); if (!dir) return; @@ -226,8 +226,8 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { return; } buffer[buflen] = '\0'; - char *buf = buffer; - char *line = NULL; + char* buf = buffer; + char* line = NULL; bool full = false; bool now = false; int fullSize = 0; diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index 50f57c10f..9f85e7929 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -30,7 +30,7 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { for (int c = 0; classes[c].name; c++) { for (int i = 0; i < 8; i++) { char name[50]; - xSnprintf(name, sizeof(name)-1, "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : "")); + xSnprintf(name, sizeof(name) - 1, "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : "")); IOPriority ioprio = IOPriority_tuple(classes[c].klass, i); Panel_add(this, (Object*) ListItem_new(name, ioprio)); if (currPrio == ioprio) Panel_setSelected(this, Panel_size(this) - 1); diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 3f9783469..1285529a9 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -152,7 +152,7 @@ typedef struct LinuxProcess_ { #endif unsigned long ctxt_total; unsigned long ctxt_diff; - char *secattr; + char* secattr; } LinuxProcess; #define Process_isKernelThread(_process) (((const LinuxProcess*)(_process))->isKernelThread) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6065d4295..6e7906d59 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -51,14 +51,14 @@ in the source distribution for its full text. #endif -static ssize_t xread(int fd, void *buf, size_t count) { +static ssize_t xread(int fd, void* buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; for (;;) { ssize_t res = read(fd, buf, count); if (res == -1 && errno == EINTR) continue; if (res > 0) { - buf = ((char*)buf)+res; + buf = ((char*)buf) + res; count -= res; alreadyRead += res; } @@ -284,17 +284,17 @@ static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { return t * jiffytime * 100; } -static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, const char* name, char* command, int* commLen) { +static bool LinuxProcessList_readStatFile(Process* process, const char* dirname, const char* name, char* command, int* commLen) { LinuxProcess* lp = (LinuxProcess*) process; const int commLenIn = *commLen; *commLen = 0; - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name); int fd = open(filename, O_RDONLY); if (fd == -1) return false; - static char buf[MAX_READ+1]; + static char buf[MAX_READ + 1]; int size = xread(fd, buf, MAX_READ); close(fd); @@ -302,11 +302,11 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, buf[size] = '\0'; assert(process->pid == atoi(buf)); - char *location = strchr(buf, ' '); + char* location = strchr(buf, ' '); if (!location) return false; location += 2; - char *end = strrchr(location, ')'); + char* end = strrchr(location, ')'); if (!end) return false; int commsize = MINIMUM(end - location, commLenIn - 1); @@ -352,14 +352,15 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, location += 1; process->nlwp = strtol(location, &location, 10); location += 1; - location = strchr(location, ' ')+1; + location = strchr(location, ' ') + 1; if (process->starttime_ctime == 0) { process->starttime_ctime = btime + LinuxProcess_adjustTime(strtoll(location, &location, 10)) / 100; } else { - location = strchr(location, ' ')+1; + location = strchr(location, ' ') + 1; } location += 1; - for (int i=0; i<15; i++) location = strchr(location, ' ')+1; + for (int i = 0; i < 15; i++) + location = strchr(location, ' ') + 1; process->exit_signal = strtol(location, &location, 10); location += 1; assert(location != NULL); @@ -372,7 +373,7 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, static bool LinuxProcessList_statProcessDir(Process* process, const char* dirname, char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; filename[MAX_NAME] = '\0'; xSnprintf(filename, MAX_NAME, "%s/%s", dirname, name); @@ -387,7 +388,7 @@ static bool LinuxProcessList_statProcessDir(Process* process, const char* dirnam #ifdef HAVE_TASKSTATS static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirname, char* name, unsigned long long now) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; filename[MAX_NAME] = '\0'; xSnprintf(filename, MAX_NAME, "%s/%s/io", dirname, name); @@ -414,8 +415,8 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna buffer[buflen] = '\0'; unsigned long long last_read = process->io_read_bytes; unsigned long long last_write = process->io_write_bytes; - char *buf = buffer; - char *line = NULL; + char* buf = buffer; + char* line = NULL; while ((line = strsep(&buf, "\n")) != NULL) { switch (line[0]) { case 'r': @@ -424,7 +425,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna } else if (String_startsWith(line + 1, "ead_bytes: ")) { process->io_read_bytes = strtoull(line + 12, NULL, 10); process->io_rate_read_bps = - ((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000); + ((double)(process->io_read_bytes - last_read)) / (((double)(now - process->io_rate_read_time)) / 1000); process->io_rate_read_time = now; } break; @@ -434,15 +435,15 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna } else if (String_startsWith(line + 1, "rite_bytes: ")) { process->io_write_bytes = strtoull(line + 13, NULL, 10); process->io_rate_write_bps = - ((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000); + ((double)(process->io_write_bytes - last_write)) / (((double)(now - process->io_rate_write_time)) / 1000); process->io_rate_write_time = now; } break; case 's': - if (line[4] == 'r' && String_startsWith(line+1, "yscr: ")) { - process->io_syscr = strtoull(line+7, NULL, 10); - } else if (String_startsWith(line+1, "yscw: ")) { - process->io_syscw = strtoull(line+7, NULL, 10); + if (line[4] == 'r' && String_startsWith(line + 1, "yscr: ")) { + process->io_syscr = strtoull(line + 7, NULL, 10); + } else if (String_startsWith(line + 1, "yscw: ")) { + process->io_syscw = strtoull(line + 7, NULL, 10); } break; case 'c': @@ -458,7 +459,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, sizeof(filename), "%s/%s/statm", dirname, name); FILE* statmfile = fopen(filename, "r"); if (!statmfile) @@ -529,7 +530,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d return; } - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, sizeof(filename), "%s/%s/status", dirname, name); FILE* file = fopen(filename, "r"); if (!file) { @@ -618,7 +619,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d #ifdef HAVE_CGROUP static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/cgroup", dirname, name); FILE* file = fopen(filename, "r"); if (!file) { @@ -634,7 +635,7 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d int left = PROC_LINE_LENGTH; while (!feof(file) && left > 0) { char buffer[PROC_LINE_LENGTH + 1]; - char *ok = fgets(buffer, PROC_LINE_LENGTH, file); + char* ok = fgets(buffer, PROC_LINE_LENGTH, file); if (!ok) break; char* group = strchr(buffer, ':'); if (!group) break; @@ -656,7 +657,7 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d #ifdef HAVE_VSERVER static void LinuxProcessList_readVServerData(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/status", dirname, name); FILE* file = fopen(filename, "r"); if (!file) @@ -687,7 +688,7 @@ static void LinuxProcessList_readVServerData(LinuxProcess* process, const char* #endif static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/oom_score", dirname, name); FILE* file = fopen(filename, "r"); if (!file) { @@ -705,7 +706,7 @@ static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirn } static void LinuxProcessList_readCtxtData(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/status", dirname, name); FILE* file = fopen(filename, "r"); if (!file) @@ -731,7 +732,7 @@ static void LinuxProcessList_readCtxtData(LinuxProcess* process, const char* dir } static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, sizeof(filename), "%s/%s/attr/current", dirname, name); FILE* file = fopen(filename, "r"); if (!file) { @@ -740,14 +741,14 @@ static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* return; } char buffer[PROC_LINE_LENGTH + 1]; - char *res = fgets(buffer, sizeof(buffer), file); + char* res = fgets(buffer, sizeof(buffer), file); fclose(file); if (!res) { free(process->secattr); process->secattr = NULL; return; } - char *newline = strchr(buffer, '\n'); + char* newline = strchr(buffer, '\n'); if (newline) *newline = '\0'; if (process->secattr && String_eq(process->secattr, buffer)) @@ -758,10 +759,10 @@ static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* #ifdef HAVE_DELAYACCT -static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { - struct nlmsghdr *nlhdr; - struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1]; - struct nlattr *nlattr; +static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) { + struct nlmsghdr* nlhdr; + struct nlattr* nlattrs[TASKSTATS_TYPE_MAX + 1]; + struct nlattr* nlattr; struct taskstats stats; int rem; unsigned long long int timeDelta; @@ -777,24 +778,25 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { memcpy(&stats, nla_data(nla_next(nla_data(nlattr), &rem)), sizeof(stats)); assert(lp->super.pid == (pid_t)stats.ac_pid); - timeDelta = (stats.ac_etime*1000 - lp->delay_read_time); - #define BOUNDS(x) isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x) + timeDelta = (stats.ac_etime * 1000 - lp->delay_read_time); + #define BOUNDS(x) (isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x)) #define DELTAPERC(x,y) BOUNDS((float) ((x) - (y)) / timeDelta * 100) lp->cpu_delay_percent = DELTAPERC(stats.cpu_delay_total, lp->cpu_delay_total); lp->blkio_delay_percent = DELTAPERC(stats.blkio_delay_total, lp->blkio_delay_total); lp->swapin_delay_percent = DELTAPERC(stats.swapin_delay_total, lp->swapin_delay_total); #undef DELTAPERC #undef BOUNDS + lp->swapin_delay_total = stats.swapin_delay_total; lp->blkio_delay_total = stats.blkio_delay_total; lp->cpu_delay_total = stats.cpu_delay_total; - lp->delay_read_time = stats.ac_etime*1000; + lp->delay_read_time = stats.ac_etime * 1000; } return NL_OK; } static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProcess* process) { - struct nl_msg *msg; + struct nl_msg* msg; if (nl_socket_modify_cb(this->netlink_socket, NL_CB_VALID, NL_CB_CUSTOM, handleNetlinkMsg, process) < 0) { return; @@ -837,13 +839,13 @@ static void setCommand(Process* process, const char* command, int len) { } static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name); int fd = open(filename, O_RDONLY); if (fd == -1) return false; - char command[4096+1]; // max cmdline length on Linux + char command[4096 + 1]; // max cmdline length on Linux int amtRead = xread(fd, command, sizeof(command) - 1); close(fd); int tokenEnd = 0; @@ -927,7 +929,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* const Settings* settings = pl->settings; #ifdef HAVE_TASKSTATS - unsigned long long now = tv.tv_sec*1000LL+tv.tv_usec/1000LL; + unsigned long long now = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL; #endif dir = opendir(dirname); @@ -964,7 +966,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* LinuxProcess* lp = (LinuxProcess*) proc; - char subdirname[MAX_NAME+1]; + char subdirname[MAX_NAME + 1]; xSnprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name); LinuxProcessList_recurseProcTree(this, subdirname, proc, period, tv); @@ -976,11 +978,11 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* if (! LinuxProcessList_readStatmFile(lp, dirname, name)) goto errorReadingProcess; - if ((settings->flags & PROCESS_FLAG_LINUX_SMAPS) && !Process_isKernelThread(proc)){ - if (!parent){ + if ((settings->flags & PROCESS_FLAG_LINUX_SMAPS) && !Process_isKernelThread(proc)) { + if (!parent) { // Read smaps file of each process only every second pass to improve performance static int smaps_flag = 0; - if ((pid & 1) == smaps_flag){ + if ((pid & 1) == smaps_flag) { LinuxProcessList_readSmapsFile(lp, dirname, name, this->haveSmapsRollup); } if (pid == 1) { @@ -993,7 +995,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); - char command[MAX_NAME+1]; + char command[MAX_NAME + 1]; unsigned long long int lasttimes = (lp->utime + lp->stime); int commLen = sizeof(command); unsigned int tty_nr = proc->tty_nr; diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 1795543f3..6ecf2103c 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -64,7 +64,7 @@ typedef struct LinuxProcessList_ { bool haveSmapsRollup; #ifdef HAVE_DELAYACCT - struct nl_sock *netlink_socket; + struct nl_sock* netlink_socket; int netlink_family; #endif diff --git a/linux/Platform.c b/linux/Platform.c index 674952b09..3da3f029a 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -169,8 +169,11 @@ int Platform_getUptime() { void Platform_getLoadAverage(double* one, double* five, double* fifteen) { int activeProcs, totalProcs, lastProc; - *one = 0; *five = 0; *fifteen = 0; - FILE *fd = fopen(PROCDIR "/loadavg", "r"); + *one = 0; + *five = 0; + *fifteen = 0; + + FILE* fd = fopen(PROCDIR "/loadavg", "r"); if (fd) { int total = fscanf(fd, "%32lf %32lf %32lf %32d/%32d %32d", one, five, fifteen, &activeProcs, &totalProcs, &lastProc); @@ -207,15 +210,15 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_IOWAIT] = cpuData->ioWaitPeriod / total * 100.0; this->curItems = 8; if (this->pl->settings->accountGuestInCPUMeter) { - percent = v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6]; + percent = v[0] + v[1] + v[2] + v[3] + v[4] + v[5] + v[6]; } else { - percent = v[0]+v[1]+v[2]+v[3]+v[4]; + percent = v[0] + v[1] + v[2] + v[3] + v[4]; } } else { v[2] = cpuData->systemAllPeriod / total * 100.0; v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0; this->curItems = 4; - percent = v[0]+v[1]+v[2]+v[3]; + percent = v[0] + v[1] + v[2] + v[3]; } percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; @@ -275,7 +278,7 @@ char* Platform_getProcessEnv(pid_t pid) { if (!fd) return NULL; - char *env = NULL; + char* env = NULL; size_t capacity = 0; size_t size = 0; @@ -299,16 +302,16 @@ char* Platform_getProcessEnv(pid_t pid) { env = xRealloc(env, size + 2); env[size] = '\0'; - env[size+1] = '\0'; + env[size + 1] = '\0'; return env; } -void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred) { +void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred) { *ten = *sixty = *threehundred = 0; - char procname[128+1]; + char procname[128 + 1]; xSnprintf(procname, 128, PROCDIR "/pressure/%s", file); - FILE *fd = fopen(procname, "r"); + FILE* fd = fopen(procname, "r"); if (!fd) { *ten = *sixty = *threehundred = NAN; return; @@ -323,7 +326,7 @@ void Platform_getPressureStall(const char *file, bool some, double* ten, double* } bool Platform_getDiskIO(DiskIOData* data) { - FILE *fd = fopen(PROCDIR "/diskstats", "r"); + FILE* fd = fopen(PROCDIR "/diskstats", "r"); if (!fd) return false; @@ -367,11 +370,11 @@ bool Platform_getDiskIO(DiskIOData* data) { return true; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { - FILE *fd = fopen(PROCDIR "/net/dev", "r"); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { + FILE* fd = fopen(PROCDIR "/net/dev", "r"); if (!fd) return false; diff --git a/linux/Platform.h b/linux/Platform.h index b61a4db81..8b2b3bb93 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -47,13 +47,13 @@ void Platform_setZfsArcValues(Meter* this); void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); +void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/openbsd/Battery.c b/openbsd/Battery.c index 232b12558..b72253e0c 100644 --- a/openbsd/Battery.c +++ b/openbsd/Battery.c @@ -53,7 +53,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { mib[4] = 3; if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { double charge = s.value; - *level = 100*(charge / last_full_capacity); + *level = 100 * (charge / last_full_capacity); if (charge >= last_full_capacity) { *level = 100; } diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 86e2dca61..bfac535d4 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -56,7 +56,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui } for (i = 0; i <= pl->cpuCount; i++) { - CPUData *d = opl->cpus + i; + CPUData* d = opl->cpus + i; d->totalTime = 1; d->totalPeriod = 1; } @@ -134,7 +134,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { */ } -char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { +char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { char *s, **arg; size_t len = 0, n; int i; @@ -163,7 +163,7 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in n = strlcat(s, arg[i], len); if (i == 0) { /* TODO: rename all basenameEnd to basenameLen, make size_t */ - *basenameEnd = MINIMUM(n, len-1); + *basenameEnd = MINIMUM(n, len - 1); } /* the trailing space should get truncated anyway */ strlcat(s, " ", len); @@ -175,9 +175,9 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in /* * Taken from OpenBSD's ps(1). */ -static double getpcpu(const struct kinfo_proc *kp) { +static double getpcpu(const struct kinfo_proc* kp) { if (fscale == 0) - return (0.0); + return 0.0; #define fxtofl(fixpt) ((double)(fixpt) / fscale) @@ -232,7 +232,7 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { proc->m_size = kproc->p_vm_dsize; proc->m_resident = kproc->p_vm_rssize; proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(this->super.totalMem) * 100.0; - proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount*100.0); + proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount * 100.0); //proc->nlwp = kproc->p_numthreads; //proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 10); proc->nice = kproc->p_nice - 20; diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index 7ee48c636..1b40faf1f 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -43,7 +43,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this); -char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); +char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); diff --git a/openbsd/Platform.c b/openbsd/Platform.c index d9737c393..21a33d1ed 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -162,7 +162,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData = &(pl->cpus[cpu]); double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod; double totalPercent; - double *v = this->values; + double* v = this->values; v[CPU_METER_NICE] = cpuData->nicePeriod / total * 100.0; v[CPU_METER_NORMAL] = cpuData->userPeriod / total * 100.0; @@ -175,11 +175,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_IOWAIT] = 0.0; v[CPU_METER_FREQUENCY] = NAN; this->curItems = 8; - totalPercent = v[0]+v[1]+v[2]+v[3]; + totalPercent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->sysAllPeriod / total * 100.0; v[3] = 0.0; // No steal nor guest on OpenBSD - totalPercent = v[0]+v[1]+v[2]; + totalPercent = v[0] + v[1] + v[2]; this->curItems = 4; } @@ -208,7 +208,7 @@ void Platform_setMemoryValues(Meter* this) { */ void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; - struct swapent *swdev; + struct swapent* swdev; unsigned long long int total, used; int nswap, rnswap, i; nswap = swapctl(SWAP_NSWAP, 0, 0); @@ -243,11 +243,11 @@ void Platform_setSwapValues(Meter* this) { char* Platform_getProcessEnv(pid_t pid) { char errbuf[_POSIX2_LINE_MAX]; - char *env; - char **ptr; + char* env; + char** ptr; int count; - kvm_t *kt; - struct kinfo_proc *kproc; + kvm_t* kt; + struct kinfo_proc* kproc; size_t capacity = 4096, size = 0; if ((kt = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) @@ -265,7 +265,7 @@ char* Platform_getProcessEnv(pid_t pid) { } env = xMalloc(capacity); - for (char **p = ptr; *p; p++) { + for (char** p = ptr; *p; p++) { size_t len = strlen(*p) + 1; if (size + len > capacity) { @@ -294,10 +294,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; diff --git a/openbsd/Platform.h b/openbsd/Platform.h index 8cb5bdf33..7e3261a9f 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -44,9 +44,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/solaris/Platform.c b/solaris/Platform.c index be2d25ed3..697777267 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -130,7 +130,7 @@ extern char Process_pidFormat[20]; int Platform_getUptime() { int boot_time = 0; int curr_time = time(NULL); - struct utmpx * ent; + struct utmpx* ent; while (( ent = getutxent() )) { if ( !strcmp("system boot", ent->ut_line )) { @@ -140,7 +140,7 @@ int Platform_getUptime() { endutxent(); - return (curr_time-boot_time); + return (curr_time - boot_time); } void Platform_getLoadAverage(double* one, double* five, double* fifteen) { @@ -151,9 +151,9 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { } int Platform_getMaxPid() { - kstat_ctl_t *kc = NULL; - kstat_t *kshandle = NULL; - kvar_t *ksvar = NULL; + kstat_ctl_t* kc = NULL; + kstat_t* kshandle = NULL; + kvar_t* ksvar = NULL; int vproc = 32778; // Reasonable Solaris default kc = kstat_open(); if (kc != NULL) { kshandle = kstat_lookup(kc,"unix",0,"var"); } @@ -187,11 +187,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0]+v[1]+v[2]+v[3]; + percent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0]+v[1]+v[2]; + percent = v[0] + v[1] + v[2]; } percent = CLAMP(percent, 0.0, 100.0); @@ -228,8 +228,8 @@ void Platform_setZfsCompressedArcValues(Meter* this) { ZfsCompressedArcMeter_readStats(this, &(spl->zfs)); } -static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) { - envAccum *accump = accum; +static int Platform_buildenv(void* accum, struct ps_prochandle* Phandle, uintptr_t addr, const char* str) { + envAccum* accump = accum; (void) Phandle; (void) addr; size_t thissz = strlen(str); @@ -247,16 +247,16 @@ char* Platform_getProcessEnv(pid_t pid) { envAccum envBuilder; pid_t realpid = pid / 1024; int graberr; - struct ps_prochandle *Phandle; + struct ps_prochandle* Phandle; - if ((Phandle = Pgrab(realpid,PGRAB_RDONLY,&graberr)) == NULL) + if ((Phandle = Pgrab(realpid, PGRAB_RDONLY, &graberr)) == NULL) return "Unable to read process environment."; envBuilder.capacity = 4096; envBuilder.size = 0; envBuilder.env = xMalloc(envBuilder.capacity); - (void) Penv_iter(Phandle,Platform_buildenv,&envBuilder); + (void) Penv_iter(Phandle, Platform_buildenv, &envBuilder); Prelease(Phandle, 0); @@ -270,10 +270,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; diff --git a/solaris/Platform.h b/solaris/Platform.h index 8718dbfee..701bc77d3 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -27,7 +27,7 @@ typedef struct envAccum_ { size_t capacity; size_t size; size_t bytes; - char *env; + char* env; } envAccum; extern double plat_loadavg[3]; @@ -66,9 +66,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index cbef6c8f7..31507506e 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -64,12 +64,12 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { const SolarisProcessList* spl = (SolarisProcessList*) pl; int cpus = pl->cpuCount; - kstat_t *cpuinfo = NULL; + kstat_t* cpuinfo = NULL; int kchain = 0; - kstat_named_t *idletime = NULL; - kstat_named_t *intrtime = NULL; - kstat_named_t *krnltime = NULL; - kstat_named_t *usertime = NULL; + kstat_named_t* idletime = NULL; + kstat_named_t* intrtime = NULL; + kstat_named_t* krnltime = NULL; + kstat_named_t* usertime = NULL; double idlebuf = 0; double intrbuf = 0; double krnlbuf = 0; @@ -94,16 +94,16 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { kchain = kstat_read(spl->kd, cpuinfo, NULL); } if (kchain != -1 ) { - idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle"); - intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr"); - krnltime = kstat_data_lookup(cpuinfo,"cpu_nsec_kernel"); - usertime = kstat_data_lookup(cpuinfo,"cpu_nsec_user"); + idletime = kstat_data_lookup(cpuinfo, "cpu_nsec_idle"); + intrtime = kstat_data_lookup(cpuinfo, "cpu_nsec_intr"); + krnltime = kstat_data_lookup(cpuinfo, "cpu_nsec_kernel"); + usertime = kstat_data_lookup(cpuinfo, "cpu_nsec_user"); } assert( (idletime != NULL) && (intrtime != NULL) && (krnltime != NULL) && (usertime != NULL) ); - CPUData* cpuData = &(spl->cpus[i+arrskip]); + CPUData* cpuData = &(spl->cpus[i + arrskip]); totaltime = (idletime->value.ui64 - cpuData->lidle) + (intrtime->value.ui64 - cpuData->lintr) + (krnltime->value.ui64 - cpuData->lkrnl) @@ -158,9 +158,11 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { // Part 1 - physical memory if (spl->kd != NULL && meminfo == NULL) { // Look up the kstat chain just one, it never changes - meminfo = kstat_lookup(spl->kd,"unix",0,"system_pages"); + meminfo = kstat_lookup(spl->kd, "unix", 0, "system_pages"); + } + if (meminfo != NULL) { + ksrphyserr = kstat_read(spl->kd, meminfo, NULL); } - if (meminfo != NULL) { ksrphyserr = kstat_read(spl->kd,meminfo,NULL); } if (ksrphyserr != -1) { totalmem_pgs = kstat_data_lookup(meminfo, "physmem"); freemem_pgs = kstat_data_lookup(meminfo, "freemem"); @@ -276,13 +278,13 @@ void ProcessList_delete(ProcessList* pl) { * system for more info. */ -int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr) { +int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* listptr) { bool preExisting; pid_t getpid; // Setup process list - ProcessList *pl = (ProcessList*) listptr; - SolarisProcessList *spl = (SolarisProcessList*) listptr; + ProcessList* pl = (ProcessList*) listptr; + SolarisProcessList* spl = (SolarisProcessList*) listptr; id_t lwpid_real = _lwpsinfo->pr_lwpid; if (lwpid_real > 1023) return 0; @@ -293,8 +295,8 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * } else { getpid = lwpid; } - Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, SolarisProcess_new); - SolarisProcess *sproc = (SolarisProcess*) proc; + Process* proc = ProcessList_getProcess(pl, getpid, &preExisting, SolarisProcess_new); + SolarisProcess* sproc = (SolarisProcess*) proc; // Common code pass 1 proc->show = false; @@ -309,22 +311,22 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * // NOTE: This 'percentage' is a 16-bit BINARY FRACTIONS where 1.0 = 0x8000 // Source: https://docs.oracle.com/cd/E19253-01/816-5174/proc-4/index.html // (accessed on 18 November 2017) - proc->percent_mem = ((uint16_t)_psinfo->pr_pctmem/(double)32768)*(double)100.0; + proc->percent_mem = ((uint16_t)_psinfo->pr_pctmem / (double)32768) * (double)100.0; proc->st_uid = _psinfo->pr_euid; proc->pgrp = _psinfo->pr_pgid; proc->nlwp = _psinfo->pr_nlwp; proc->tty_nr = _psinfo->pr_ttydev; - proc->m_resident = _psinfo->pr_rssize/CRT_pageSizeKB; - proc->m_size = _psinfo->pr_size/CRT_pageSizeKB; + proc->m_resident = _psinfo->pr_rssize / CRT_pageSizeKB; + proc->m_size = _psinfo->pr_size / CRT_pageSizeKB; if (!preExisting) { sproc->realpid = _psinfo->pr_pid; sproc->lwpid = lwpid_real; sproc->zoneid = _psinfo->pr_zoneid; - sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc); + sproc->zname = SolarisProcessList_readZoneName(spl->kd, sproc); proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid); proc->comm = xStrdup(_psinfo->pr_fname); - proc->commLen = strnlen(_psinfo->pr_fname,PRFNSZ); + proc->commLen = strnlen(_psinfo->pr_fname, PRFNSZ); } // End common code pass 1 @@ -334,7 +336,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * proc->tgid = (_psinfo->pr_ppid * 1024); sproc->realppid = _psinfo->pr_ppid; // See note above (in common section) about this BINARY FRACTION - proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu/(double)32768)*(double)100.0; + proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu / (double)32768) * (double)100.0; proc->time = _psinfo->pr_time.tv_sec; if (!preExisting) { // Tasks done only for NEW processes sproc->is_lwp = false; @@ -344,7 +346,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * // Update proc and thread counts based on settings if (sproc->kernel && !pl->settings->hideKernelThreads) { pl->kernelThreads += proc->nlwp; - pl->totalTasks += proc->nlwp+1; + pl->totalTasks += proc->nlwp + 1; if (proc->state == 'O') pl->runningTasks++; } else if (!sproc->kernel) { if (proc->state == 'O') pl->runningTasks++; @@ -352,12 +354,12 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * pl->totalTasks++; } else { pl->userlandThreads += proc->nlwp; - pl->totalTasks += proc->nlwp+1; + pl->totalTasks += proc->nlwp + 1; } } proc->show = !(pl->settings->hideKernelThreads && sproc->kernel); } else { // We are not in the master LWP, so jump to the LWP handling code - proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu/(double)32768)*(double)100.0; + proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu / (double)32768) * (double)100.0; proc->time = _lwpsinfo->pr_time.tv_sec; if (!preExisting) { // Tasks done only for NEW LWPs sproc->is_lwp = true; @@ -369,8 +371,12 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * } // Top-level process only gets this for the representative LWP - if (sproc->kernel && !pl->settings->hideKernelThreads) proc->show = true; - if (!sproc->kernel && !pl->settings->hideUserlandThreads) proc->show = true; + if (sproc->kernel && !pl->settings->hideKernelThreads) { + proc->show = true; + } + if (!sproc->kernel && !pl->settings->hideUserlandThreads) { + proc->show = true; + } } // Top-level LWP or subordinate LWP // Common code pass 2 diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index 3a653eed6..f800d9da9 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -58,7 +58,7 @@ void ProcessList_delete(ProcessList* pl); * system for more info. */ -int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr); +int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* listptr); void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 3f8cefa68..afc5bf356 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -146,10 +146,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { *bytesReceived = 0; *packetsReceived = 0; *bytesTransmitted = 0; diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 902b6a9b7..91ac7481b 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -50,9 +50,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index 993d80e2b..d0278a9df 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -33,7 +33,7 @@ void ZfsCompressedArcMeter_readStats(Meter* this, const ZfsArcStats* stats) { } static void ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buffer, int size) { - xSnprintf(buffer, size, "%.2f:1", this->total/this->values[0]); + xSnprintf(buffer, size, "%.2f:1", this->total / this->values[0]); } static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int size) { diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c index c09d48df8..59d7469f8 100644 --- a/zfs/openzfs_sysctl.c +++ b/zfs/openzfs_sysctl.c @@ -27,7 +27,7 @@ static int MIB_kstat_zfs_misc_arcstats_uncompressed_size[5]; #include "zfs/ZfsArcStats.h" }*/ -void openzfs_sysctl_init(ZfsArcStats *stats) { +void openzfs_sysctl_init(ZfsArcStats* stats) { size_t len; unsigned long long int arcSize; @@ -56,45 +56,45 @@ void openzfs_sysctl_init(ZfsArcStats *stats) { } } -void openzfs_sysctl_updateArcStats(ZfsArcStats *stats) { +void openzfs_sysctl_updateArcStats(ZfsArcStats* stats) { size_t len; if (stats->enabled) { len = sizeof(stats->size); - sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(stats->size), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(stats->size), &len, NULL, 0); stats->size /= 1024; len = sizeof(stats->max); - sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(stats->max), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(stats->max), &len, NULL, 0); stats->max /= 1024; len = sizeof(stats->MFU); - sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(stats->MFU), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(stats->MFU), &len, NULL, 0); stats->MFU /= 1024; len = sizeof(stats->MRU); - sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(stats->MRU), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(stats->MRU), &len, NULL, 0); stats->MRU /= 1024; len = sizeof(stats->anon); - sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(stats->anon), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(stats->anon), &len, NULL, 0); stats->anon /= 1024; len = sizeof(stats->header); - sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(stats->header), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(stats->header), &len, NULL, 0); stats->header /= 1024; len = sizeof(stats->other); - sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(stats->other), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(stats->other), &len, NULL, 0); stats->other /= 1024; if (stats->isCompressed) { len = sizeof(stats->compressed); - sysctl(MIB_kstat_zfs_misc_arcstats_compressed_size, 5, &(stats->compressed), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_compressed_size, 5, &(stats->compressed), &len, NULL, 0); stats->compressed /= 1024; len = sizeof(stats->uncompressed); - sysctl(MIB_kstat_zfs_misc_arcstats_uncompressed_size, 5, &(stats->uncompressed), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_uncompressed_size, 5, &(stats->uncompressed), &len, NULL, 0); stats->uncompressed /= 1024; } } diff --git a/zfs/openzfs_sysctl.h b/zfs/openzfs_sysctl.h index 1bc5d3e07..b49128e36 100644 --- a/zfs/openzfs_sysctl.h +++ b/zfs/openzfs_sysctl.h @@ -9,8 +9,8 @@ in the source distribution for its full text. #include "zfs/ZfsArcStats.h" -void openzfs_sysctl_init(ZfsArcStats *stats); +void openzfs_sysctl_init(ZfsArcStats* stats); -void openzfs_sysctl_updateArcStats(ZfsArcStats *stats); +void openzfs_sysctl_updateArcStats(ZfsArcStats* stats); #endif From 45869513bfebba80cc2ab42e4218f68b34b1e6ac Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 1 Nov 2020 01:09:51 +0100 Subject: [PATCH 385/411] Embracing branches --- Action.c | 64 ++++++++--- Affinity.c | 7 +- AffinityPanel.c | 33 ++++-- CPUMeter.c | 3 + CRT.c | 16 ++- CategoriesPanel.c | 1 + CheckItem.c | 15 ++- ColorsPanel.c | 1 + CommandScreen.c | 4 +- FunctionBar.c | 10 +- Hashtable.c | 9 +- Header.c | 9 +- IncSet.c | 37 +++++-- InfoScreen.c | 11 +- MainPanel.c | 9 +- Meter.c | 29 +++-- Object.c | 6 +- OpenFilesScreen.c | 14 ++- Panel.c | 22 ++-- Process.c | 43 +++++--- ProcessList.c | 46 ++++++-- RichString.c | 4 +- ScreenManager.c | 52 ++++++--- Settings.c | 16 ++- TraceScreen.c | 12 +- Vector.c | 32 ++++-- darwin/DarwinProcessList.c | 9 +- dragonflybsd/Battery.c | 10 +- dragonflybsd/DragonFlyBSDProcess.c | 5 +- dragonflybsd/DragonFlyBSDProcessList.c | 14 ++- dragonflybsd/Platform.c | 4 +- freebsd/Battery.c | 10 +- freebsd/FreeBSDProcess.c | 5 +- freebsd/FreeBSDProcessList.c | 36 ++++-- htop.c | 19 ++-- linux/Battery.c | 43 ++++++-- linux/IOPriorityPanel.c | 14 ++- linux/LinuxProcess.c | 6 +- linux/LinuxProcessList.c | 146 ++++++++++++++++++------- linux/Platform.c | 21 +++- linux/SELinuxMeter.c | 21 ++-- openbsd/OpenBSDProcessList.c | 3 +- openbsd/Platform.c | 7 +- solaris/Platform.c | 25 +++-- solaris/SolarisProcessList.c | 27 +++-- unsupported/UnsupportedProcessList.c | 3 +- 46 files changed, 656 insertions(+), 277 deletions(-) diff --git a/Action.c b/Action.c index 879014325..8a6e2cbe0 100644 --- a/Action.c +++ b/Action.c @@ -65,13 +65,13 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) Process* selected = (Process*)Panel_getSelected(panel); if (selected && selected->pid == pid) return Panel_getSelected(list); - else - beep(); + + beep(); } else { return Panel_getSelected(list); } - } + return NULL; } @@ -93,7 +93,7 @@ static void Action_runSetup(State* st) { static bool changePriority(MainPanel* panel, int delta) { bool anyTagged; - bool ok = MainPanel_foreachProcess(panel, Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged); + bool ok = MainPanel_foreachProcess(panel, Process_changePriorityBy, (Arg) { .i = delta }, &anyTagged); if (!ok) beep(); return anyTagged; @@ -128,14 +128,18 @@ static void tagAllChildren(Panel* panel, Process* parent) { static bool expandCollapse(Panel* panel) { Process* p = (Process*) Panel_getSelected(panel); - if (!p) return false; + if (!p) + return false; + p->showChildren = !p->showChildren; return true; } static bool collapseIntoParent(Panel* panel) { Process* p = (Process*) Panel_getSelected(panel); - if (!p) return false; + if (!p) + return false; + pid_t ppid = Process_getParentPid(p); for (int i = 0; i < Panel_size(panel); i++) { Process* q = (Process*) Panel_get(panel, i); @@ -165,6 +169,7 @@ static Htop_Reaction sortBy(State* st) { Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i])); if (fields[i] == st->settings->sortKey) Panel_setSelected(sortPanel, i); + free(name); } ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false); @@ -172,8 +177,10 @@ static Htop_Reaction sortBy(State* st) { reaction |= Action_setSortKey(st->settings, field->key); } Object_delete(sortPanel); + if (st->pauseProcessUpdate) ProcessList_sort(st->pl); + return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; } @@ -215,7 +222,10 @@ static Htop_Reaction actionToggleProgramPath(State* st) { static Htop_Reaction actionToggleTreeView(State* st) { st->settings->treeView = !st->settings->treeView; - if (st->settings->treeView) st->settings->direction = 1; + if (st->settings->treeView) { + st->settings->direction = 1; + } + ProcessList_expandTree(st->pl); return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; } @@ -286,13 +296,18 @@ static Htop_Reaction actionQuit(ATTR_UNUSED State* st) { static Htop_Reaction actionSetAffinity(State* st) { if (st->pl->cpuCount == 1) return HTOP_OK; + #if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) Panel* panel = st->panel; Process* p = (Process*) Panel_getSelected(panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + Affinity* affinity1 = Affinity_get(p, st->pl); - if (!affinity1) return HTOP_OK; + if (!affinity1) + return HTOP_OK; + int width; Panel* affinityPanel = AffinityPanel_new(st->pl, affinity1, &width); width += 1; /* we add a gap between the panels */ @@ -301,8 +316,9 @@ static Htop_Reaction actionSetAffinity(State* st) { void* set = Action_pickFromVector(st, affinityPanel, width, true); if (set) { Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg){ .v = affinity2 }, NULL); - if (!ok) beep(); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg) { .v = affinity2 }, NULL); + if (!ok) + beep(); Affinity_delete(affinity2); } Object_delete(affinityPanel); @@ -318,7 +334,7 @@ static Htop_Reaction actionKill(State* st) { Panel_setHeader(st->panel, "Sending..."); Panel_draw(st->panel, true); refresh(); - MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg){ .i = sgn->key }, NULL); + MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL); napms(500); } } @@ -362,7 +378,9 @@ static Htop_Reaction actionSetup(State* st) { static Htop_Reaction actionLsof(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + OpenFilesScreen* ofs = OpenFilesScreen_new(p); InfoScreen_run((InfoScreen*)ofs); OpenFilesScreen_delete((Object*)ofs); @@ -373,7 +391,9 @@ static Htop_Reaction actionLsof(State* st) { static Htop_Reaction actionStrace(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + TraceScreen* ts = TraceScreen_new(p); bool ok = TraceScreen_forkTracer(ts); if (ok) { @@ -387,7 +407,9 @@ static Htop_Reaction actionStrace(State* st) { static Htop_Reaction actionTag(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + Process_toggleTag(p); Panel_onKey(st->panel, KEY_DOWN); return HTOP_OK; @@ -555,14 +577,18 @@ static Htop_Reaction actionUntagAll(State* st) { static Htop_Reaction actionTagAllChildren(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + tagAllChildren(st->panel, p); return HTOP_OK; } static Htop_Reaction actionShowEnvScreen(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + EnvScreen* es = EnvScreen_new(p); InfoScreen_run((InfoScreen*)es); EnvScreen_delete((Object*)es); @@ -573,7 +599,9 @@ static Htop_Reaction actionShowEnvScreen(State* st) { static Htop_Reaction actionShowCommandScreen(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + CommandScreen* cmdScr = CommandScreen_new(p); InfoScreen_run((InfoScreen*)cmdScr); CommandScreen_delete((Object*)cmdScr); diff --git a/Affinity.c b/Affinity.c index bfa7ceb5f..6fb5846c7 100644 --- a/Affinity.c +++ b/Affinity.c @@ -89,11 +89,14 @@ bool Affinity_set(Process* proc, Arg arg) { Affinity* Affinity_get(Process* proc, ProcessList* pl) { cpu_set_t cpuset; bool ok = (sched_getaffinity(proc->pid, sizeof(cpu_set_t), &cpuset) == 0); - if (!ok) return NULL; + if (!ok) + return NULL; + Affinity* affinity = Affinity_new(pl); for (int i = 0; i < pl->cpuCount; i++) { - if (CPU_ISSET(i, &cpuset)) + if (CPU_ISSET(i, &cpuset)) { Affinity_add(affinity, i); + } } return affinity; } diff --git a/AffinityPanel.c b/AffinityPanel.c index 85094b4c8..9c2a6e7c4 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -60,12 +60,13 @@ static void MaskItem_display(const Object* cast, RichString* out) { const MaskItem* this = (const MaskItem*)cast; assert (this != NULL); RichString_append(out, CRT_colors[CHECK_BOX], "["); - if (this->value == 2) + if (this->value == 2) { RichString_append(out, CRT_colors[CHECK_MARK], "x"); - else if (this->value == 1) + } else if (this->value == 1) { RichString_append(out, CRT_colors[CHECK_MARK], "o"); - else + } else { RichString_append(out, CRT_colors[CHECK_MARK], " "); + } RichString_append(out, CRT_colors[CHECK_BOX], "]"); RichString_append(out, CRT_colors[CHECK_TEXT], " "); if (this->indent) { @@ -178,11 +179,12 @@ static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) { Panel_prune(super); #ifdef HAVE_LIBHWLOC - if (this->topoView) + if (this->topoView) { AffinityPanel_updateTopo(this, this->topoRoot); - else { - for (int i = 0; i < Vector_size(this->cpuids); i++) + } else { + for (int i = 0; i < Vector_size(this->cpuids); i++) { AffinityPanel_updateItem(this, (MaskItem*) Vector_get(this->cpuids, i)); + } } #else Panel_splice(super, this->cpuids); @@ -304,14 +306,16 @@ static MaskItem* AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u hwloc_bitmap_and(result, obj->complete_cpuset, this->workCpuset); int weight = hwloc_bitmap_weight(result); hwloc_bitmap_free(result); - if (weight == 0 || weight == (hwloc_bitmap_weight(this->workCpuset) + hwloc_bitmap_weight(obj->complete_cpuset))) + if (weight == 0 || weight == (hwloc_bitmap_weight(this->workCpuset) + hwloc_bitmap_weight(obj->complete_cpuset))) { item->sub_tree = 2; + } } /* "[x] " + "|- " * depth + ("- ")?(if root node) + name */ unsigned width = 4 + 3 * depth + (2 * !depth) + strlen(buf); - if (width > this->width) + if (width > this->width) { this->width = width; + } return item; } @@ -323,8 +327,10 @@ static MaskItem* AffinityPanel_buildTopology(AffinityPanel* this, hwloc_obj_t ob } else { indent &= ~(1u << obj->depth); } - for (unsigned i = 0; i < obj->arity; i++) + + for (unsigned i = 0; i < obj->arity; i++) { AffinityPanel_buildTopology(this, obj->children[i], indent, item); + } return parent == NULL ? item : NULL; } @@ -382,8 +388,9 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) { char number[16]; xSnprintf(number, 9, "CPU %d", Settings_cpuId(pl->settings, i)); unsigned cpu_width = 4 + strlen(number); - if (cpu_width > this->width) + if (cpu_width > this->width) { this->width = cpu_width; + } bool isSet = false; if (curCpu < affinity->used && affinity->cpus[curCpu] == i) { @@ -402,8 +409,9 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) { this->topoRoot = AffinityPanel_buildTopology(this, hwloc_get_root_obj(pl->topology), 0, NULL); #endif - if (width) + if (width) { *width = this->width; + } AffinityPanel_update(this, false); @@ -422,8 +430,9 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) { #else for (int i = 0; i < this->pl->cpuCount; i++) { MaskItem* item = (MaskItem*)Vector_get(this->cpuids, i); - if (item->value) + if (item->value) { Affinity_add(affinity, item->cpu); + } } #endif diff --git a/CPUMeter.c b/CPUMeter.c index b1bb8f459..ff129cd25 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -163,10 +163,13 @@ static void CPUMeterCommonInit(Meter* this, int ncol) { for (int i = 0; i < count; i++) { if (!meters[i]) meters[i] = Meter_new(this->pl, start + i + 1, (const MeterClass*) Class(CPUMeter)); + Meter_init(meters[i]); } + if (this->mode == 0) this->mode = BAR_METERMODE; + int h = Meter_modes[this->mode]->h; this->h = h * ((count + ncol - 1) / ncol); } diff --git a/CRT.c b/CRT.c index 38ba9da3c..08f1cef35 100644 --- a/CRT.c +++ b/CRT.c @@ -619,13 +619,18 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { keypad(stdscr, true); mouseinterval(0); curs_set(0); - if (has_colors()) + + if (has_colors()) { start_color(); + } + CRT_termType = getenv("TERM"); - if (String_eq(CRT_termType, "linux")) + if (String_eq(CRT_termType, "linux")) { CRT_scrollHAmount = 20; - else + } else { CRT_scrollHAmount = 5; + } + if (String_startsWith(CRT_termType, "xterm") || String_eq(CRT_termType, "vt220")) { define_key("\033[H", KEY_HOME); define_key("\033[F", KEY_END); @@ -670,10 +675,11 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { setlocale(LC_CTYPE, ""); #ifdef HAVE_LIBNCURSESW - if (allowUnicode && String_eq(nl_langinfo(CODESET), "UTF-8")) + if (allowUnicode && String_eq(nl_langinfo(CODESET), "UTF-8")) { CRT_utf8 = true; - else + } else { CRT_utf8 = false; + } #else (void) allowUnicode; #endif diff --git a/CategoriesPanel.c b/CategoriesPanel.c index d6c25a690..2dc1c3bfb 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -97,6 +97,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) { int size = ScreenManager_size(this->scr); for (int i = 1; i < size; i++) ScreenManager_remove(this->scr, 1); + switch (selected) { case 0: CategoriesPanel_makeMetersPage(this); diff --git a/CheckItem.c b/CheckItem.c index 5c79ab13a..5fcae96bd 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -26,10 +26,11 @@ static void CheckItem_display(const Object* cast, RichString* out) { const CheckItem* this = (const CheckItem*)cast; assert (this != NULL); RichString_write(out, CRT_colors[CHECK_BOX], "["); - if (CheckItem_get(this)) + if (CheckItem_get(this)) { RichString_append(out, CRT_colors[CHECK_MARK], "x"); - else + } else { RichString_append(out, CRT_colors[CHECK_MARK], " "); + } RichString_append(out, CRT_colors[CHECK_BOX], "] "); RichString_append(out, CRT_colors[CHECK_TEXT], this->text); } @@ -56,15 +57,17 @@ CheckItem* CheckItem_newByVal(char* text, bool value) { } void CheckItem_set(CheckItem* this, bool value) { - if (this->ref) + if (this->ref) { *(this->ref) = value; - else + } else { this->value = value; + } } bool CheckItem_get(const CheckItem* this) { - if (this->ref) + if (this->ref) { return *(this->ref); - else + } else { return this->value; + } } diff --git a/ColorsPanel.c b/ColorsPanel.c index 24e63b0e2..9da71545b 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -64,6 +64,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) { for (int i = 0; ColorSchemeNames[i] != NULL; i++) CheckItem_set((CheckItem*)Panel_get(super, i), false); CheckItem_set((CheckItem*)Panel_get(super, mark), true); + this->settings->colorScheme = mark; result = HANDLED; } diff --git a/CommandScreen.c b/CommandScreen.c index 7997a64a9..578b3ae1a 100644 --- a/CommandScreen.c +++ b/CommandScreen.c @@ -21,7 +21,9 @@ static void CommandScreen_scan(InfoScreen* this) { int line_offset = 0, last_spc = -1, len; for (; *p != '\0'; p++, line_offset++) { line[line_offset] = *p; - if (*p == ' ') last_spc = line_offset; + if (*p == ' ') { + last_spc = line_offset; + } if (line_offset == COLS) { len = (last_spc == -1) ? line_offset : last_spc; diff --git a/FunctionBar.c b/FunctionBar.c index 934565831..627bc777a 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -106,10 +106,11 @@ void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr } if (buffer) { - if (attr == -1) + if (attr == -1) { attrset(CRT_colors[FUNCTION_BAR]); - else + } else { attrset(attr); + } mvaddstr(LINES - 1, x, buffer); attrset(CRT_colors[RESET_COLOR]); x += strlen(buffer); @@ -126,10 +127,11 @@ void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr } void FunctionBar_append(const char* buffer, int attr) { - if (attr == -1) + if (attr == -1) { attrset(CRT_colors[FUNCTION_BAR]); - else + } else { attrset(attr); + } mvaddstr(LINES - 1, currentLen, buffer); attrset(CRT_colors[RESET_COLOR]); diff --git a/Hashtable.c b/Hashtable.c index a086227c8..92337822f 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -70,6 +70,7 @@ void Hashtable_delete(Hashtable* this) { while (walk != NULL) { if (this->owner) free(walk->value); + HashtableItem* savedWalk = walk; walk = savedWalk->next; free(savedWalk); @@ -90,10 +91,13 @@ void Hashtable_put(Hashtable* this, unsigned int key, void* value) { } else if ((*bucketPtr)->key == key) { if (this->owner && (*bucketPtr)->value != value) free((*bucketPtr)->value); + (*bucketPtr)->value = value; break; - } else + } else { bucketPtr = &((*bucketPtr)->next); + } + assert(Hashtable_isConsistent(this)); } @@ -134,8 +138,9 @@ void* Hashtable_get(Hashtable* this, unsigned int key) { } else if (bucketPtr->key == key) { assert(Hashtable_isConsistent(this)); return bucketPtr->value; - } else + } else { bucketPtr = bucketPtr->next; + } } } diff --git a/Header.c b/Header.c index 4448baa69..0b522f54d 100644 --- a/Header.c +++ b/Header.c @@ -88,7 +88,8 @@ MeterModeId Header_addMeterByName(Header* this, char* name, int column) { int param = 0; if (paren) { int ok = sscanf(paren, "(%10d)", ¶m); - if (!ok) param = 0; + if (!ok) + param = 0; *paren = '\0'; } MeterModeId mode = TEXT_METERMODE; @@ -100,8 +101,10 @@ MeterModeId Header_addMeterByName(Header* this, char* name, int column) { break; } } + if (paren) *paren = '('; + return mode; } @@ -110,6 +113,7 @@ void Header_setMode(Header* this, int i, MeterModeId mode, int column) { if (i >= Vector_size(meters)) return; + Meter* meter = (Meter*) Vector_get(meters, i); Meter_setMode(meter, mode); } @@ -153,8 +157,9 @@ void Header_reinit(Header* this) { Header_forEachColumn(this, col) { for (int i = 0; i < Vector_size(this->columns[col]); i++) { Meter* meter = (Meter*) Vector_get(this->columns[col], i); - if (Meter_initFn(meter)) + if (Meter_initFn(meter)) { Meter_init(meter); + } } } } diff --git a/IncSet.c b/IncSet.c index 3deda7375..d280caf42 100644 --- a/IncSet.c +++ b/IncSet.c @@ -79,7 +79,10 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { ListItem* line = (ListItem*)Vector_get(lines, i); if (String_contains_i(line->value, incFilter)) { Panel_add(panel, (Object*)line); - if (selected == (Object*)line) Panel_setSelected(panel, n); + if (selected == (Object*)line) { + Panel_setSelected(panel, n); + } + n++; } } @@ -87,7 +90,9 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { for (int i = 0; i < Vector_size(lines); i++) { Object* line = Vector_get(lines, i); Panel_add(panel, line); - if (selected == line) Panel_setSelected(panel, i); + if (selected == line) { + Panel_setSelected(panel, i); + } } } } @@ -115,10 +120,17 @@ static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getP int here = Panel_getSelectedIndex(panel); int i = here; for (;;) { - i+=step; - if (i == size) i = 0; - if (i == -1) i = size - 1; - if (i == here) return false; + i += step; + if (i == size) { + i = 0; + } + if (i == -1) { + i = size - 1; + } + if (i == here) { + return false; + } + if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { Panel_setSelected(panel, i); return true; @@ -137,12 +149,15 @@ bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) { if (ch == ERR) return true; + IncMode* mode = this->active; int size = Panel_size(panel); bool filterChanged = false; bool doSearch = true; if (ch == KEY_F(3)) { - if (size == 0) return true; + if (size == 0) + return true; + IncMode_find(mode, panel, getPanelValue, 1); doSearch = false; } else if (0 < ch && ch < 255 && isprint((unsigned char)ch)) { @@ -152,7 +167,9 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue mode->buffer[mode->index] = 0; if (mode->isFilter) { filterChanged = true; - if (mode->index == 1) this->filtering = true; + if (mode->index == 1) { + this->filtering = true; + } } } } else if ((ch == KEY_BACKSPACE || ch == 127)) { @@ -199,9 +216,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue const char* IncSet_getListItemValue(Panel* panel, int i) { ListItem* l = (ListItem*) Panel_get(panel, i); - if (l) - return l->value; - return ""; + return l ? l->value : ""; } void IncSet_activate(IncSet* this, IncType type, Panel* panel) { diff --git a/InfoScreen.c b/InfoScreen.c index 102f0ba76..b7cbd4c64 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -64,16 +64,18 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) { void InfoScreen_addLine(InfoScreen* this, const char* line) { Vector_add(this->lines, (Object*) ListItem_new(line, 0)); const char* incFilter = IncSet_filter(this->inc); - if (!incFilter || String_contains_i(line, incFilter)) + if (!incFilter || String_contains_i(line, incFilter)) { Panel_add(this->display, Vector_get(this->lines, Vector_size(this->lines) - 1)); + } } void InfoScreen_appendLine(InfoScreen* this, const char* line) { ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines) - 1); ListItem_append(last, line); const char* incFilter = IncSet_filter(this->inc); - if (incFilter && Panel_get(this->display, Panel_size(this->display) - 1) != (Object*)last && String_contains_i(line, incFilter)) + if (incFilter && Panel_get(this->display, Panel_size(this->display) - 1) != (Object*)last && String_contains_i(line, incFilter)) { Panel_add(this->display, (Object*)last); + } } void InfoScreen_run(InfoScreen* this) { @@ -133,7 +135,9 @@ void InfoScreen_run(InfoScreen* this) { break; case KEY_F(5): clear(); - if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + if (As_InfoScreen(this)->scan) + InfoScreen_scan(this); + InfoScreen_draw(this); break; case '\014': // Ctrl+L @@ -149,6 +153,7 @@ void InfoScreen_run(InfoScreen* this) { Panel_resize(panel, COLS, LINES - 2); if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + InfoScreen_draw(this); break; default: diff --git a/MainPanel.c b/MainPanel.c index 9322fe027..be59abd39 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -100,8 +100,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { if (reaction & HTOP_REDRAW_BAR) { MainPanel_updateTreeFunctions(this, this->state->settings->treeView); IncSet_drawBar(this->inc); - if (this->state->pauseProcessUpdate) + if (this->state->pauseProcessUpdate) { FunctionBar_append("PAUSED", CRT_colors[PAUSED]); + } } if (reaction & HTOP_UPDATE_PANELHDR) { ProcessList_printHeader(this->state->pl, Panel_getHeader(super)); @@ -135,9 +136,7 @@ int MainPanel_selectedPid(MainPanel* this) { const char* MainPanel_getValue(MainPanel* this, int i) { Process* p = (Process*) Panel_get((Panel*)this, i); - if (p) - return p->comm; - return ""; + return p ? p->comm : ""; } bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged) { @@ -157,8 +156,10 @@ bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Ar ok &= fn(p, arg); } } + if (wasAnyTagged) *wasAnyTagged = anyTagged; + return ok; } diff --git a/Meter.c b/Meter.c index d17ba95a8..cf8ccc52b 100644 --- a/Meter.c +++ b/Meter.c @@ -41,8 +41,9 @@ Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* typ this->values = type->maxItems ? xCalloc(type->maxItems, sizeof(double)) : NULL; this->total = type->total; this->caption = xStrdup(type->caption); - if (Meter_initFn(this)) + if (Meter_initFn(this)) { Meter_init(this); + } Meter_setMode(this, type->defaultMode); return this; } @@ -81,6 +82,7 @@ int Meter_humanUnit(char* buffer, unsigned long int value, int size) { void Meter_delete(Object* cast) { if (!cast) return; + Meter* this = (Meter*) cast; if (Meter_doneFn(this)) { Meter_done(this); @@ -105,15 +107,20 @@ static inline void Meter_displayBuffer(const Meter* this, const char* buffer, Ri } void Meter_setMode(Meter* this, int modeIndex) { - if (modeIndex > 0 && modeIndex == this->mode) + if (modeIndex > 0 && modeIndex == this->mode) { return; - if (!modeIndex) + } + + if (!modeIndex) { modeIndex = 1; + } + assert(modeIndex < LAST_METERMODE); if (Meter_defaultMode(this) == CUSTOM_METERMODE) { this->draw = Meter_drawFn(this); - if (Meter_updateModeFn(this)) + if (Meter_updateModeFn(this)) { Meter_updateMode(this, modeIndex); + } } else { assert(modeIndex >= 1); free(this->drawData); @@ -128,15 +135,17 @@ void Meter_setMode(Meter* this, int modeIndex) { ListItem* Meter_toListItem(Meter* this, bool moving) { char mode[21]; - if (this->mode) + if (this->mode) { xSnprintf(mode, 20, " [%s]", Meter_modes[this->mode]->uiName); - else + } else { mode[0] = '\0'; + } char number[11]; - if (this->param > 0) + if (this->param > 0) { xSnprintf(number, 10, " %d", this->param); - else + } else { number[0] = '\0'; + } char buffer[51]; xSnprintf(buffer, 50, "%s%s%s", Meter_uiName(this), number, mode); ListItem* li = ListItem_new(buffer, 0); @@ -261,7 +270,9 @@ static int GraphMeterMode_pixPerRow; static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { - if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData)); + if (!this->drawData) { + this->drawData = xCalloc(1, sizeof(GraphData)); + } GraphData* data = this->drawData; const int nValues = METER_BUFFER_LEN; diff --git a/Object.c b/Object.c index 01b6c4ceb..975c8d483 100644 --- a/Object.c +++ b/Object.c @@ -20,12 +20,16 @@ const ObjectClass Object_class = { bool Object_isA(const Object* o, const ObjectClass* klass) { if (!o) return false; + const ObjectClass* type = o->klass; while (type) { - if (type == klass) + if (type == klass) { return true; + } + type = type->extends; } + return false; } diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 829fafee1..cd309648b 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -69,10 +69,11 @@ static const char* getDataForType(const OpenFiles_Data* data, char type) { OpenFilesScreen* OpenFilesScreen_new(const Process* process) { OpenFilesScreen* this = xMalloc(sizeof(OpenFilesScreen)); Object_setClass(this, Class(OpenFilesScreen)); - if (Process_isThread(process)) + if (Process_isThread(process)) { this->pid = process->tgid; - else + } else { this->pid = process->pid; + } return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 3, " FD TYPE MODE DEVICE SIZE NODE NAME"); } @@ -106,8 +107,10 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { dup2(fdpair[1], STDOUT_FILENO); close(fdpair[1]); int fdnull = open("/dev/null", O_WRONLY); - if (fdnull < 0) + if (fdnull < 0) { exit(1); + } + dup2(fdnull, STDERR_FILENO); close(fdnull); char buffer[32] = {0}; @@ -182,10 +185,11 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { return pdata; } - if (!WIFEXITED(wstatus)) + if (!WIFEXITED(wstatus)) { pdata->error = 1; - else + } else { pdata->error = WEXITSTATUS(wstatus); + } return pdata; } diff --git a/Panel.c b/Panel.c index 5e92c9c7e..870f89cc6 100644 --- a/Panel.c +++ b/Panel.c @@ -97,8 +97,10 @@ void Panel_move(Panel* this, int x, int y) { void Panel_resize(Panel* this, int w, int h) { assert (this != NULL); - if (RichString_sizeVal(this->header) > 0) + if (RichString_sizeVal(this->header) > 0) { h--; + } + this->w = w; this->h = h; this->needsRedraw = true; @@ -145,33 +147,38 @@ Object* Panel_remove(Panel* this, int i) { this->needsRedraw = true; Object* removed = Vector_remove(this->items, i); - if (this->selected > 0 && this->selected >= Vector_size(this->items)) + if (this->selected > 0 && this->selected >= Vector_size(this->items)) { this->selected--; + } + return removed; } Object* Panel_getSelected(Panel* this) { assert (this != NULL); - if (Vector_size(this->items) > 0) + if (Vector_size(this->items) > 0) { return Vector_get(this->items, this->selected); - else + } else { return NULL; + } } void Panel_moveSelectedUp(Panel* this) { assert (this != NULL); Vector_moveUp(this->items, this->selected); - if (this->selected > 0) + if (this->selected > 0) { this->selected--; + } } void Panel_moveSelectedDown(Panel* this) { assert (this != NULL); Vector_moveDown(this->items, this->selected); - if (this->selected + 1 < Vector_size(this->items)) + if (this->selected + 1 < Vector_size(this->items)) { this->selected++; + } } int Panel_getSelectedIndex(Panel* this) { @@ -193,8 +200,9 @@ void Panel_setSelected(Panel* this, int selected) { if (selected >= size) { selected = size - 1; } - if (selected < 0) + if (selected < 0) { selected = 0; + } this->selected = selected; if (Panel_eventHandlerFn(this)) { Panel_eventHandler(this, EVENT_SET_SELECTED); diff --git a/Process.c b/Process.c index af7bf79d7..72360e396 100644 --- a/Process.c +++ b/Process.c @@ -43,7 +43,9 @@ static char Process_titleBuffer[20][20]; void Process_setupColumnWidths() { int maxPid = Platform_getMaxPid(); - if (maxPid == -1) return; + if (maxPid == -1) + return; + int digits = ceil(log10(maxPid)); assert(digits < 20); for (int i = 0; Process_pidColumns[i].label; i++) { @@ -201,10 +203,11 @@ static inline void Process_writeCommand(const Process* this, int attr, int basea } } if (!finish) { - if (this->settings->showProgramPath) + if (this->settings->showProgramPath) { start += basename; - else + } else { comm += basename; + } finish = this->basenameOffset - basename; } finish += start - 1; @@ -212,8 +215,9 @@ static inline void Process_writeCommand(const Process* this, int attr, int basea RichString_append(str, attr, comm); - if (this->settings->highlightBaseName) + if (this->settings->highlightBaseName) { RichString_setAttrn(str, baseattr, start, finish); + } } void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring) { @@ -285,15 +289,19 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field bool lastItem = (this->indent < 0); int indent = (this->indent < 0 ? -this->indent : this->indent); - for (int i = 0; i < 32; i++) - if (indent & (1U << i)) + for (int i = 0; i < 32; i++) { + if (indent & (1U << i)) { maxIndent = i + 1; + } + } + for (int i = 0; i < maxIndent - 1; i++) { int written, ret; - if (indent & (1 << i)) + if (indent & (1 << i)) { ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]); - else + } else { ret = snprintf(buf, n, " "); + } if (ret < 0 || ret >= n) { written = n; } else { @@ -377,10 +385,15 @@ void Process_display(const Object* cast, RichString* out) { RichString_prune(out); for (int i = 0; fields[i]; i++) As_Process(this)->writeField(this, out, fields[i]); - if (this->settings->shadowOtherUsers && (int)this->st_uid != Process_getuid) + + if (this->settings->shadowOtherUsers && (int)this->st_uid != Process_getuid) { RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]); - if (this->tag == true) + } + + if (this->tag == true) { RichString_setAttr(out, CRT_colors[PROCESS_TAG]); + } + assert(out->chlen > 0); } @@ -406,7 +419,10 @@ void Process_init(Process* this, const struct Settings_* settings) { this->show = true; this->updated = false; this->basenameOffset = -1; - if (Process_getuid == -1) Process_getuid = getuid(); + + if (Process_getuid == -1) { + Process_getuid = getuid(); + } } void Process_toggleTag(Process* this) { @@ -483,10 +499,11 @@ long Process_compare(const void* v1, const void* v2) { case SESSION: return (p1->session - p2->session); case STARTTIME: { - if (p1->starttime_ctime == p2->starttime_ctime) + if (p1->starttime_ctime == p2->starttime_ctime) { return (p1->pid - p2->pid); - else + } else { return (p1->starttime_ctime - p2->starttime_ctime); + } } case STATE: return (Process_sortState(p1->state) - Process_sortState(p2->state)); diff --git a/ProcessList.c b/ProcessList.c index ff4aa9b32..2323c99ad 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -70,11 +70,15 @@ void ProcessList_printHeader(ProcessList* this, RichString* header) { const ProcessField* fields = this->settings->fields; for (int i = 0; fields[i]; i++) { const char* field = Process_fields[fields[i]].title; - if (!field) field = "- "; - if (!this->settings->treeView && this->settings->sortKey == fields[i]) + if (!field) { + field = "- "; + } + + if (!this->settings->treeView && this->settings->sortKey == fields[i]) { RichString_append(header, CRT_colors[PANEL_SELECTION_FOCUS], field); - else + } else { RichString_append(header, CRT_colors[PANEL_HEADER_FOCUS], field); + } } } @@ -93,12 +97,18 @@ void ProcessList_add(ProcessList* this, Process* p) { void ProcessList_remove(ProcessList* this, Process* p) { assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1); assert(Hashtable_get(this->processTable, p->pid) != NULL); + Process* pp = Hashtable_remove(this->processTable, p->pid); assert(pp == p); (void)pp; + unsigned int pid = p->pid; int idx = Vector_indexOf(this->processes, p, Process_pidCompare); assert(idx != -1); - if (idx >= 0) Vector_remove(this->processes, idx); + + if (idx >= 0) { + Vector_remove(this->processes, idx); + } + assert(Hashtable_get(this->processTable, pid) == NULL); (void)pid; assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); } @@ -124,20 +134,27 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i int size = Vector_size(children); for (int i = 0; i < size; i++) { Process* process = (Process*) (Vector_get(children, i)); - if (!show) + if (!show) { process->show = false; + } + int s = Vector_size(this->processes2); - if (direction == 1) + if (direction == 1) { Vector_add(this->processes2, process); - else + } else { Vector_insert(this->processes2, 0, process); + } + assert(Vector_size(this->processes2) == s + 1); (void)s; + int nextIndent = indent | (1 << level); ProcessList_buildTree(this, process->pid, level + 1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false); - if (i == size - 1) + + if (i == size - 1) { process->indent = -nextIndent; - else + } else { process->indent = nextIndent; + } } Vector_delete(children); } @@ -180,6 +197,7 @@ void ProcessList_sort(ProcessList* this) { // root. if (process->pid == ppid) r = 0; + while (l < r) { int c = (l + r) / 2; pid_t pid = ((Process*)(Vector_get(this->processes, c)))->pid; @@ -219,7 +237,10 @@ ProcessField ProcessList_keyAt(ProcessList* this, int at) { ProcessField field; for (int i = 0; (field = fields[i]); i++) { const char* title = Process_fields[field].title; - if (!title) title = "- "; + if (!title) { + title = "- "; + } + int len = strlen(title); if (at >= x && at <= x + len) { return field; @@ -306,9 +327,10 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { Process* p = (Process*) Vector_get(this->processes, i); - if (p->updated == false) + if (p->updated == false) { ProcessList_remove(this, p); - else + } else { p->updated = false; + } } } diff --git a/RichString.c b/RichString.c index 99c535b1d..904b44b65 100644 --- a/RichString.c +++ b/RichString.c @@ -52,6 +52,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char* len = mbstowcs(data, data_c, len); if (len < 0) return; + int newLen = from + len; RichString_setLen(this, newLen); for (int i = from, j = 0; i < newLen; i++, j++) { @@ -84,8 +85,9 @@ int RichString_findChar(RichString* this, char c, int start) { static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { int newLen = from + len; RichString_setLen(this, newLen); - for (int i = from, j = 0; i < newLen; i++, j++) + for (int i = from, j = 0; i < newLen; i++, j++) { this->chptr[i] = (data_c[j] >= 32 ? data_c[j] : '?') | attrs; + } this->chptr[newLen] = 0; } diff --git a/ScreenManager.c b/ScreenManager.c index f586d04a0..b8e1713af 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -103,8 +103,12 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi gettimeofday(&tv, NULL); double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000); *timedOut = (newTime - *oldTime > this->settings->delay); - *rescan = *rescan || *timedOut; - if (newTime < *oldTime) *rescan = true; // clock was adjusted? + *rescan |= *timedOut; + + if (newTime < *oldTime) { + *rescan = true; // clock was adjusted? + } + if (*rescan) { *oldTime = newTime; ProcessList_scan(pl, this->state->pauseProcessUpdate); @@ -134,8 +138,9 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) { static Panel* setCurrentPanel(const ScreenManager* this, Panel* panel) { FunctionBar_draw(panel->currentBar); - if (panel == this->state->panel && this->state->pauseProcessUpdate) + if (panel == this->state->panel && this->state->pauseProcessUpdate) { FunctionBar_append("PAUSED", CRT_colors[PAUSED]); + } return panel; } @@ -218,8 +223,9 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (closeTimeout == 100) { break; } - } else + } else { closeTimeout = 0; + } redraw = false; continue; } @@ -261,14 +267,21 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (this->panelCount < 2) { goto defaultHandler; } - if (!this->allowFocusChange) + + if (!this->allowFocusChange) { break; - tryLeft: - if (focus > 0) + } + +tryLeft: + if (focus > 0) { focus--; + } + panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); - if (Panel_size(panelFocus) == 0 && focus > 0) + if (Panel_size(panelFocus) == 0 && focus > 0) { goto tryLeft; + } + break; case KEY_RIGHT: case KEY_CTRL('F'): @@ -276,14 +289,20 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (this->panelCount < 2) { goto defaultHandler; } - if (!this->allowFocusChange) + if (!this->allowFocusChange) { break; - tryRight: - if (focus < this->panelCount - 1) + } + +tryRight: + if (focus < this->panelCount - 1) { focus++; + } + panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); - if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) + if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) { goto tryRight; + } + break; case KEY_F(10): case 'q': @@ -291,15 +310,18 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { quit = true; continue; default: - defaultHandler: +defaultHandler: sortTimeout = resetSortTimeout; Panel_onKey(panelFocus, ch); break; } } - if (lastFocus) + if (lastFocus) { *lastFocus = panelFocus; - if (lastKey) + } + + if (lastKey) { *lastKey = ch; + } } diff --git a/Settings.c b/Settings.c index 2e274e949..1ecee5694 100644 --- a/Settings.c +++ b/Settings.c @@ -116,6 +116,7 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo CRT_restorePrivileges(); if (!fd) return false; + bool didReadMeters = false; bool didReadFields = false; for (;;) { @@ -182,8 +183,9 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo this->delay = atoi(option[1]); } else if (String_eq(option[0], "color_scheme")) { this->colorScheme = atoi(option[1]); - if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) + if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) { this->colorScheme = 0; + } } else if (String_eq(option[0], "enable_mouse")) { this->enableMouse = atoi(option[1]); } else if (String_eq(option[0], "left_meters")) { @@ -327,7 +329,9 @@ Settings* Settings_new(int initialCpuCount) { this->filename = xStrdup(rcfile); } else { const char* home = getenv("HOME"); - if (!home) home = ""; + if (!home) + home = ""; + const char* xdgConfigHome = getenv("XDG_CONFIG_HOME"); char* configDir = NULL; char* htopDir = NULL; @@ -363,8 +367,9 @@ Settings* Settings_new(int initialCpuCount) { ok = Settings_read(this, legacyDotfile, initialCpuCount); if (ok) { // Transition to new location and delete old configuration file - if (Settings_write(this)) + if (Settings_write(this)) { unlink(legacyDotfile); + } } free(legacyDotfile); } @@ -389,8 +394,9 @@ Settings* Settings_new(int initialCpuCount) { } void Settings_invertSortOrder(Settings* this) { - if (this->direction == 1) + if (this->direction == 1) { this->direction = -1; - else + } else { this->direction = 1; + } } diff --git a/TraceScreen.c b/TraceScreen.c index 7346a0f8d..b12774882 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -61,8 +61,11 @@ void TraceScreen_delete(Object* cast) { kill(this->child, SIGTERM); waitpid(this->child, NULL, 0); } - if (this->strace) + + if (this->strace) { fclose(this->strace); + } + CRT_enableDelay(); free(InfoScreen_done((InfoScreen*)this)); } @@ -144,9 +147,11 @@ void TraceScreen_updateTrace(InfoScreen* super) { tv.tv_sec = 0; tv.tv_usec = 500; int ready = select(fd_strace + 1, &fds, NULL, NULL, &tv); + size_t nread = 0; if (ready > 0 && FD_ISSET(fd_strace, &fds)) nread = fread(buffer, 1, sizeof(buffer) - 1, this->strace); + if (nread && this->tracing) { const char* line = buffer; buffer[nread] = '\0'; @@ -167,8 +172,9 @@ void TraceScreen_updateTrace(InfoScreen* super) { buffer[nread] = '\0'; this->contLine = true; } - if (this->follow) - Panel_setSelected(this->super.display, Panel_size(this->super.display)-1); + if (this->follow) { + Panel_setSelected(this->super.display, Panel_size(this->super.display) - 1); + } } } diff --git a/Vector.c b/Vector.c index eb80e1459..09d1612e2 100644 --- a/Vector.c +++ b/Vector.c @@ -17,8 +17,10 @@ in the source distribution for its full text. Vector* Vector_new(const ObjectClass* type, bool owner, int size) { Vector* this; - if (size == DEFAULT_SIZE) + if (size == DEFAULT_SIZE) { size = 10; + } + assert(size > 0); this = xMalloc(sizeof(Vector)); this->growthRate = size; @@ -32,9 +34,11 @@ Vector* Vector_new(const ObjectClass* type, bool owner, int size) { void Vector_delete(Vector* this) { if (this->owner) { - for (int i = 0; i < this->items; i++) - if (this->array[i]) + for (int i = 0; i < this->items; i++) { + if (this->array[i]) { Object_delete(this->array[i]); + } + } } free(this->array); free(this); @@ -45,9 +49,11 @@ void Vector_delete(Vector* this) { static bool Vector_isConsistent(const Vector* this) { assert(this->items <= this->arraySize); if (this->owner) { - for (int i = 0; i < this->items; i++) - if (this->array[i] && !Object_isA(this->array[i], this->type)) + for (int i = 0; i < this->items; i++) { + if (this->array[i] && !Object_isA(this->array[i], this->type)) { return false; + } + } return true; } else { return true; @@ -57,8 +63,9 @@ static bool Vector_isConsistent(const Vector* this) { int Vector_count(const Vector* this) { int items = 0; for (int i = 0; i < this->items; i++) { - if (this->array[i]) + if (this->array[i]) { items++; + } } assert(items == this->items); return items; @@ -230,15 +237,18 @@ Object* Vector_remove(Vector* this, int idx) { if (this->owner) { Object_delete(removed); return NULL; - } else + } else { return removed; + } } void Vector_moveUp(Vector* this, int idx) { assert(idx >= 0 && idx < this->items); assert(Vector_isConsistent(this)); + if (idx == 0) return; + Object* temp = this->array[idx]; this->array[idx] = this->array[idx - 1]; this->array[idx - 1] = temp; @@ -247,8 +257,10 @@ void Vector_moveUp(Vector* this, int idx) { void Vector_moveDown(Vector* this, int idx) { assert(idx >= 0 && idx < this->items); assert(Vector_isConsistent(this)); + if (idx == this->items - 1) return; + Object* temp = this->array[idx]; this->array[idx] = this->array[idx + 1]; this->array[idx + 1] = temp; @@ -307,8 +319,9 @@ int Vector_indexOf(const Vector* this, const void* search_, Object_Compare compa for (int i = 0; i < this->items; i++) { const Object* o = this->array[i]; assert(o); - if (compare(search, o) == 0) + if (compare(search, o) == 0) { return i; + } } return -1; } @@ -321,6 +334,7 @@ void Vector_splice(Vector* this, Vector* from) { int olditems = this->items; this->items += from->items; Vector_checkArraySize(this); - for (int j = 0; j < from->items; j++) + for (int j = 0; j < from->items; j++) { this->array[olditems + j] = from->array[j]; + } } diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 673d9e614..99f49d5c7 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -110,15 +110,18 @@ struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count) { * process entry or two. */ *count = 0; - if (sysctl(mib, 4, NULL, count, NULL, 0) < 0) + if (sysctl(mib, 4, NULL, count, NULL, 0) < 0) { CRT_fatalError("Unable to get size of kproc_infos"); + } processes = xMalloc(*count); - if (processes == NULL) + if (processes == NULL) { CRT_fatalError("Out of memory for kproc_infos"); + } - if (sysctl(mib, 4, processes, count, NULL, 0) < 0) + if (sysctl(mib, 4, processes, count, NULL, 0) < 0) { CRT_fatalError("Unable to get kinfo_procs"); + } *count = *count / sizeof(struct kinfo_proc); diff --git a/dragonflybsd/Battery.c b/dragonflybsd/Battery.c index 4bae3aa5d..1a690ee31 100644 --- a/dragonflybsd/Battery.c +++ b/dragonflybsd/Battery.c @@ -14,15 +14,17 @@ in the source distribution for its full text. void Battery_getData(double* level, ACPresence* isOnAC) { int life; size_t life_len = sizeof(life); - if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) + if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) { *level = NAN; - else + } else { *level = life; + } int acline; size_t acline_len = sizeof(acline); - if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) + if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) { *isOnAC = AC_ERROR; - else + } else { *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; + } } diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 457a488a5..bd2093277 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -131,8 +131,9 @@ long DragonFlyBSDProcess_compare(const void* v1, const void* v2) { bool Process_isThread(const Process* this) { const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) this; - if (fp->kernel == 1 ) + if (fp->kernel == 1 ) { return 1; - else + } else { return (Process_isUserlandThread(this)); + } } diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index d3acf73d9..b66dc0e83 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -123,7 +123,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this) { const DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this; - if (dfpl->kd) kvm_close(dfpl->kd); + if (dfpl->kd) { + kvm_close(dfpl->kd); + } if (dfpl->jails) { Hashtable_delete(dfpl->jails); @@ -199,7 +201,9 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { // totals total_d = total_n - total_o; - if (total_d < 1 ) total_d = 1; + if (total_d < 1 ) { + total_d = 1; + } // save current state as old and calc percentages for (int s = 0; s < CPUSTATES; ++s) { @@ -331,8 +335,9 @@ static inline void DragonFlyBSDProcessList_scanJails(DragonFlyBSDProcessList* df int jailid; char* str_hostname; nextpos = strchr(curpos, '\n'); - if (nextpos) + if (nextpos) { *nextpos++ = 0; + } jailid = atoi(strtok(curpos, " ")); str_hostname = strtok(NULL, " "); @@ -372,8 +377,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { DragonFlyBSDProcessList_scanJails(dfpl); // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } int count = 0; diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 5e9fe335b..5f9f6373c 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -177,7 +177,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { } percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) percent = 0.0; + if (isnan(percent)) { + percent = 0.0; + } v[CPU_METER_FREQUENCY] = NAN; diff --git a/freebsd/Battery.c b/freebsd/Battery.c index 50691c8b4..26b42da92 100644 --- a/freebsd/Battery.c +++ b/freebsd/Battery.c @@ -13,15 +13,17 @@ in the source distribution for its full text. void Battery_getData(double* level, ACPresence* isOnAC) { int life; size_t life_len = sizeof(life); - if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) + if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) { *level = NAN; - else + } else { *level = life; + } int acline; size_t acline_len = sizeof(acline); - if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) + if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) { *isOnAC = AC_ERROR; - else + } else { *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; + } } diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index a4516d041..baad5d13c 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -134,10 +134,11 @@ static long FreeBSDProcess_compare(const void* v1, const void* v2) { bool Process_isThread(const Process* this) { const FreeBSDProcess* fp = (const FreeBSDProcess*) this; - if (fp->kernel == 1 ) + if (fp->kernel == 1 ) { return 1; - else + } else { return Process_isUserlandThread(this); + } } const ProcessClass FreeBSDProcess_class = { diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 4594b992f..7ce787f84 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -98,7 +98,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui if (smp) { int err = sysctlbyname("kern.smp.cpus", &cpus, &len, NULL, 0); - if (err) cpus = 1; + if (err) { + cpus = 1; + } } else { cpus = 1; } @@ -152,7 +154,9 @@ void ProcessList_delete(ProcessList* this) { Hashtable_delete(fpl->ttys); - if (fpl->kd) kvm_close(fpl->kd); + if (fpl->kd) { + kvm_close(fpl->kd); + } free(fpl->cp_time_o); free(fpl->cp_time_n); @@ -225,7 +229,9 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { // totals total_d = total_n - total_o; - if (total_d < 1 ) total_d = 1; + if (total_d < 1 ) { + total_d = 1; + } // save current state as old and calc percentages for (int s = 0; s < CPUSTATES; ++s) { @@ -434,13 +440,15 @@ IGNORE_WCASTQUAL_END jail_errmsg[0] = 0; jid = jail_get(jiov, 6, 0); if (jid < 0) { - if (!jail_errmsg[0]) + if (!jail_errmsg[0]) { xSnprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s", strerror(errno)); + } return NULL; } else if (jid == kproc->ki_jid) { jname = xStrdup(jnamebuf); - if (jname == NULL) + if (jname == NULL) { strerror_r(errno, jail_errmsg, JAIL_ERRMSGLEN); + } return jname; } else { return NULL; @@ -464,11 +472,13 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { FreeBSDProcessList_scanCPUTime(super); // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } - if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) + if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) { FreeBSDProcessList_scanTTYs(super); + } int count = 0; struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count); @@ -485,10 +495,11 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (!preExisting) { fp->jid = kproc->ki_jid; proc->pid = kproc->ki_pid; - if ( ! ((kproc->ki_pid == 0) || (kproc->ki_pid == 1) ) && kproc->ki_flag & P_SYSTEM) - fp->kernel = 1; - else - fp->kernel = 0; + if ( ! ((kproc->ki_pid == 0) || (kproc->ki_pid == 1) ) && kproc->ki_flag & P_SYSTEM) { + fp->kernel = 1; + } else { + fp->kernel = 0; + } proc->ppid = kproc->ki_ppid; proc->tpgid = kproc->ki_tpgid; proc->tgid = kproc->ki_pid; @@ -565,8 +576,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { default: proc->state = '?'; } - if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) + if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) { fp->ttyPath = (kproc->ki_tdev == NODEV) ? nodevStr : Hashtable_get(fpl->ttys, kproc->ki_tdev); + } if (Process_isKernelThread(proc)) super->kernelThreads++; diff --git a/htop.c b/htop.c index 76754462f..7fbc04c9c 100644 --- a/htop.c +++ b/htop.c @@ -243,12 +243,13 @@ static void setCommFilter(State* state, char** commFilter) { int main(int argc, char** argv) { char* lc_ctype = getenv("LC_CTYPE"); - if (lc_ctype != NULL) + if (lc_ctype != NULL) { setlocale(LC_CTYPE, lc_ctype); - else if ((lc_ctype = getenv("LC_ALL"))) + } else if ((lc_ctype = getenv("LC_ALL"))) { setlocale(LC_CTYPE, lc_ctype); - else + } else { setlocale(LC_CTYPE, ""); + } CommandLineSettings flags = parseArguments(argc, argv); // may exit() @@ -271,14 +272,18 @@ int main(int argc, char** argv) { Header_populateFromSettings(header); - if (flags.delay != -1) + if (flags.delay != -1) { settings->delay = flags.delay; - if (!flags.useColors) + } + if (!flags.useColors) { settings->colorScheme = COLORSCHEME_MONOCHROME; - if (!flags.enableMouse) + } + if (!flags.enableMouse) { settings->enableMouse = false; - if (flags.treeView) + } + if (flags.treeView) { settings->treeView = true; + } CRT_init(settings->delay, settings->colorScheme, flags.allowUnicode); diff --git a/linux/Battery.c b/linux/Battery.c index 326f35fd5..ba7d153a8 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -52,9 +52,11 @@ static unsigned long int parseBatInfo(const char* fileName, const unsigned short struct dirent* dirEntry = readdir(batteryDir); if (!dirEntry) break; + char* entryName = dirEntry->d_name; if (!String_startsWith(entryName, "BAT")) continue; + batteries[nBatteries] = xStrdup(entryName); nBatteries++; } @@ -74,12 +76,14 @@ static unsigned long int parseBatInfo(const char* fileName, const unsigned short for (unsigned short int j = 0; j < lineNum; j++) { free(line); line = String_readLine(file); - if (!line) break; + if (!line) + break; } fclose(file); - if (!line) break; + if (!line) + break; char* foundNumStr = String_getToken(line, wordNum); const unsigned long int foundNum = atoi(foundNumStr); @@ -122,8 +126,11 @@ static ACPresence procAcpiCheck(void) { continue; } char* line = String_readLine(file); + fclose(file); - if (!line) continue; + + if (!line) + continue; char* isOnline = String_getToken(line, 2); free(line); @@ -139,8 +146,10 @@ static ACPresence procAcpiCheck(void) { } } - if (dir) + if (dir) { closedir(dir); + } + return isOn; } @@ -170,14 +179,21 @@ static inline ssize_t xread(int fd, void* buf, size_t count) { size_t alreadyRead = 0; for (;;) { ssize_t res = read(fd, buf, count); - if (res == -1 && errno == EINTR) continue; + if (res == -1) { + if (errno == EINTR) + continue; + return -1; + } + if (res > 0) { buf = ((char*)buf) + res; count -= res; alreadyRead += res; } - if (res == -1) return -1; - if (count == 0 || res == 0) return alreadyRead; + + if (count == 0 || res == 0) { + return alreadyRead; + } } } @@ -197,6 +213,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { struct dirent* dirEntry = readdir(dir); if (!dirEntry) break; + const char* entryName = dirEntry->d_name; char filePath[256]; @@ -257,14 +274,18 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { fullSize = atoi(value); totalFull += fullSize; full = true; - if (now) break; + if (now) { + break; + } continue; } value = (!now) ? match(energy, "NOW=") : NULL; if (value) { totalRemain += atoi(value); now = true; - if (full) break; + if (full) { + break; + } continue; } } @@ -288,7 +309,9 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { char buffer[2] = ""; for (;;) { ssize_t res = read(fd3, buffer, 1); - if (res == -1 && errno == EINTR) continue; + if (res == -1 && errno == EINTR) { + continue; + } break; } close(fd3); diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index 9f85e7929..cd4b2e608 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -21,7 +21,11 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { Panel_setHeader(this, "IO Priority:"); Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None)); - if (currPrio == IOPriority_None) Panel_setSelected(this, 0); + + if (currPrio == IOPriority_None) { + Panel_setSelected(this, 0); + } + static const struct { int klass; const char* name; } classes[] = { { .klass = IOPRIO_CLASS_RT, .name = "Realtime" }, { .klass = IOPRIO_CLASS_BE, .name = "Best-effort" }, @@ -33,11 +37,15 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { xSnprintf(name, sizeof(name) - 1, "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : "")); IOPriority ioprio = IOPriority_tuple(classes[c].klass, i); Panel_add(this, (Object*) ListItem_new(name, ioprio)); - if (currPrio == ioprio) Panel_setSelected(this, Panel_size(this) - 1); + if (currPrio == ioprio) { + Panel_setSelected(this, Panel_size(this) - 1); + } } } Panel_add(this, (Object*) ListItem_new("Idle", IOPriority_Idle)); - if (currPrio == IOPriority_Idle) Panel_setSelected(this, Panel_size(this) - 1); + if (currPrio == IOPriority_Idle) { + Panel_setSelected(this, Panel_size(this) - 1); + } return this; } diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index a5d7eccf9..b1bd24d53 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -168,8 +168,9 @@ dynamically derived from the cpu nice level of the process: io_priority = (cpu_nice + 20) / 5. -- From ionice(1) man page */ static int LinuxProcess_effectiveIOPriority(const LinuxProcess* this) { - if (IOPriority_class(this->ioPriority) == IOPRIO_CLASS_NONE) + if (IOPriority_class(this->ioPriority) == IOPRIO_CLASS_NONE) { return IOPriority_tuple(IOPRIO_CLASS_BE, (this->super.nice + 20) / 5); + } return this->ioPriority; } @@ -290,8 +291,9 @@ void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField case PERCENT_SWAP_DELAY: LinuxProcess_printDelay(lp->swapin_delay_percent, buffer, n); break; #endif case CTXT: - if (lp->ctxt_diff > 1000) + if (lp->ctxt_diff > 1000) { attr |= A_BOLD; + } xSnprintf(buffer, n, "%5lu ", lp->ctxt_diff); break; case SECATTR: snprintf(buffer, n, "%-30s ", lp->secattr ? lp->secattr : "?"); break; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6e7906d59..e91666d04 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -56,14 +56,21 @@ static ssize_t xread(int fd, void* buf, size_t count) { size_t alreadyRead = 0; for (;;) { ssize_t res = read(fd, buf, count); - if (res == -1 && errno == EINTR) continue; + if (res == -1) { + if (errno == EINTR) + continue; + return -1; + } + if (res > 0) { buf = ((char*)buf) + res; count -= res; alreadyRead += res; } - if (res == -1) return -1; - if (count == 0 || res == 0) return alreadyRead; + + if (count == 0 || res == 0) { + return alreadyRead; + } } } @@ -78,6 +85,7 @@ static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { int fd = open(PROCTTYDRIVERSFILE, O_RDONLY); if (fd == -1) return; + char* buf = NULL; int bufSize = MAX_READ; int bufLen = 0; @@ -160,21 +168,24 @@ static void LinuxProcessList_initNetlinkSocket(LinuxProcessList* this) { static int LinuxProcessList_computeCPUcount(void) { FILE* file = fopen(PROCSTATFILE, "r"); - if (file == NULL) + if (file == NULL) { CRT_fatalError("Cannot open " PROCSTATFILE); + } int cpus = 0; char buffer[PROC_LINE_LENGTH + 1]; while (fgets(buffer, sizeof(buffer), file)) { - if (String_startsWith(buffer, "cpu")) + if (String_startsWith(buffer, "cpu")) { cpus++; + } } fclose(file); /* subtract raw cpu entry */ - if (cpus > 0) + if (cpus > 0) { cpus--; + } return cpus; } @@ -218,16 +229,18 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui // Read btime { FILE* statfile = fopen(PROCSTATFILE, "r"); - if (statfile == NULL) + if (statfile == NULL) { CRT_fatalError("Cannot open " PROCSTATFILE); + } while (true) { char buffer[PROC_LINE_LENGTH + 1]; if (fgets(buffer, sizeof(buffer), statfile) == NULL) { CRT_fatalError("No btime in " PROCSTATFILE); } else if (String_startsWith(buffer, "btime ")) { - if (sscanf(buffer, "btime %lld\n", &btime) != 1) + if (sscanf(buffer, "btime %lld\n", &btime) != 1) { CRT_fatalError("Failed to parse btime from " PROCSTATFILE); + } break; } } @@ -298,16 +311,19 @@ static bool LinuxProcessList_readStatFile(Process* process, const char* dirname, int size = xread(fd, buf, MAX_READ); close(fd); - if (size <= 0) return false; + if (size <= 0) + return false; buf[size] = '\0'; assert(process->pid == atoi(buf)); char* location = strchr(buf, ' '); - if (!location) return false; + if (!location) + return false; location += 2; char* end = strrchr(location, ')'); - if (!end) return false; + if (!end) + return false; int commsize = MINIMUM(end - location, commLenIn - 1); // deepcode ignore BufferOverflow: commsize is bounded by the allocated length passed in by commLen, saved into commLenIn @@ -359,8 +375,9 @@ static bool LinuxProcessList_readStatFile(Process* process, const char* dirname, location = strchr(location, ' ') + 1; } location += 1; - for (int i = 0; i < 15; i++) + for (int i = 0; i < 15; i++) { location = strchr(location, ' ') + 1; + } process->exit_signal = strtol(location, &location, 10); location += 1; assert(location != NULL); @@ -411,7 +428,9 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna char buffer[1024]; ssize_t buflen = xread(fd, buffer, 1023); close(fd); - if (buflen < 1) return; + if (buflen < 1) + return; + buffer[buflen] = '\0'; unsigned long long last_read = process->io_read_bytes; unsigned long long last_write = process->io_write_bytes; @@ -464,6 +483,7 @@ static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* di FILE* statmfile = fopen(filename, "r"); if (!statmfile) return false; + int r = fscanf(statmfile, "%ld %ld %ld %ld %ld %ld %ld", &process->super.m_size, &process->super.m_resident, @@ -636,9 +656,13 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d while (!feof(file) && left > 0) { char buffer[PROC_LINE_LENGTH + 1]; char* ok = fgets(buffer, PROC_LINE_LENGTH, file); - if (!ok) break; + if (!ok) + break; + char* group = strchr(buffer, ':'); - if (!group) break; + if (!group) + break; + if (at != output) { *at = ';'; at++; @@ -662,6 +686,7 @@ static void LinuxProcessList_readVServerData(LinuxProcess* process, const char* FILE* file = fopen(filename, "r"); if (!file) return; + char buffer[PROC_LINE_LENGTH + 1]; process->vxid = 0; while (fgets(buffer, PROC_LINE_LENGTH, file)) { @@ -711,19 +736,22 @@ static void LinuxProcessList_readCtxtData(LinuxProcess* process, const char* dir FILE* file = fopen(filename, "r"); if (!file) return; + char buffer[PROC_LINE_LENGTH + 1]; unsigned long ctxt = 0; while (fgets(buffer, PROC_LINE_LENGTH, file)) { if (String_startsWith(buffer, "voluntary_ctxt_switches:")) { unsigned long vctxt; int ok = sscanf(buffer, "voluntary_ctxt_switches:\t%lu", &vctxt); - if (ok >= 1) + if (ok >= 1) { ctxt += vctxt; + } } else if (String_startsWith(buffer, "nonvoluntary_ctxt_switches:")) { unsigned long nvctxt; int ok = sscanf(buffer, "nonvoluntary_ctxt_switches:\t%lu", &nvctxt); - if (ok >= 1) + if (ok >= 1) { ctxt += nvctxt; + } } } fclose(file); @@ -749,10 +777,12 @@ static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* return; } char* newline = strchr(buffer, '\n'); - if (newline) + if (newline) { *newline = '\0'; - if (process->secattr && String_eq(process->secattr, buffer)) + } + if (process->secattr && String_eq(process->secattr, buffer)) { return; + } free(process->secattr); process->secattr = xStrdup(buffer); } @@ -905,17 +935,28 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in for (;;) { xAsprintf(&fullPath, "%s/%d", ttyDrivers[i].path, idx); int err = stat(fullPath, &sstat); - if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath; + if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) { + return fullPath; + } free(fullPath); + xAsprintf(&fullPath, "%s%d", ttyDrivers[i].path, idx); err = stat(fullPath, &sstat); - if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath; + if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) { + return fullPath; + } free(fullPath); - if (idx == min) break; + + if (idx == min) { + break; + } + idx = min; } int err = stat(ttyDrivers[i].path, &sstat); - if (err == 0 && tty_nr == sstat.st_rdev) return xStrdup(ttyDrivers[i].path); + if (err == 0 && tty_nr == sstat.st_rdev) { + return xStrdup(ttyDrivers[i].path); + } } char* out; xAsprintf(&out, "/dev/%u:%u", maj, min); @@ -933,7 +974,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* #endif dir = opendir(dirname); - if (!dir) return false; + if (!dir) + return false; + int cpus = pl->cpuCount; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; @@ -1001,15 +1044,21 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* unsigned int tty_nr = proc->tty_nr; if (! LinuxProcessList_readStatFile(proc, dirname, name, command, &commLen)) goto errorReadingProcess; + if (tty_nr != proc->tty_nr && this->ttyDrivers) { free(lp->ttyDevice); lp->ttyDevice = LinuxProcessList_updateTtyDevice(this->ttyDrivers, proc->tty_nr); } - if (settings->flags & PROCESS_FLAG_LINUX_IOPRIO) + + if (settings->flags & PROCESS_FLAG_LINUX_IOPRIO) { LinuxProcess_updateIOPriority(lp); + } + float percent_cpu = (lp->utime + lp->stime - lasttimes) / period * 100.0; proc->percent_cpu = CLAMP(percent_cpu, 0.0, cpus * 100.0); - if (isnan(proc->percent_cpu)) proc->percent_cpu = 0.0; + if (isnan(proc->percent_cpu)) + proc->percent_cpu = 0.0; + proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(pl->totalMem) * 100.0; if (!preExisting) { @@ -1051,18 +1100,22 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* #endif #ifdef HAVE_CGROUP - if (settings->flags & PROCESS_FLAG_LINUX_CGROUP) + if (settings->flags & PROCESS_FLAG_LINUX_CGROUP) { LinuxProcessList_readCGroupFile(lp, dirname, name); + } #endif - if (settings->flags & PROCESS_FLAG_LINUX_OOM) + if (settings->flags & PROCESS_FLAG_LINUX_OOM) { LinuxProcessList_readOomData(lp, dirname, name); + } - if (settings->flags & PROCESS_FLAG_LINUX_CTXT) + if (settings->flags & PROCESS_FLAG_LINUX_CTXT) { LinuxProcessList_readCtxtData(lp, dirname, name); + } - if (settings->flags & PROCESS_FLAG_LINUX_SECATTR) + if (settings->flags & PROCESS_FLAG_LINUX_SECATTR) { LinuxProcessList_readSecattrData(lp, dirname, name); + } if (proc->state == 'Z' && (proc->basenameOffset == 0)) { proc->basenameOffset = -1; @@ -1072,8 +1125,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* proc->basenameOffset = -1; setCommand(proc, command, commLen); } else if (settings->showThreadNames) { - if (! LinuxProcessList_readCmdlineFile(proc, dirname, name)) + if (! LinuxProcessList_readCmdlineFile(proc, dirname, name)) { goto errorReadingProcess; + } } if (Process_isKernelThread(proc)) { pl->kernelThreads++; @@ -1293,10 +1347,13 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { // 5, 7, 8 or 9 of these fields will be set. // The rest will remain at zero. char* ok = fgets(buffer, PROC_LINE_LENGTH, file); - if (!ok) buffer[0] = '\0'; - if (i == 0) + if (!ok) { + buffer[0] = '\0'; + } + + if (i == 0) { (void) sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice); - else { + } else { int cpuid; (void) sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice); assert(cpuid == i - 1); @@ -1404,13 +1461,15 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) { (sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) || (sscanf(buffer, "cpu MHz: %lf", &frequency) == 1) ) { - if (cpuid < 0 || cpuid > (cpus - 1)) + if (cpuid < 0 || cpuid > (cpus - 1)) { continue; + } CPUData* cpuData = &(this->cpus[cpuid + 1]); /* do not override sysfs data */ - if (isnan(cpuData->frequency)) + if (isnan(cpuData->frequency)) { cpuData->frequency = frequency; + } numCPUsWithFrequency++; totalFrequency += frequency; } else if (buffer[0] == '\n') { @@ -1419,19 +1478,22 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) { } fclose(file); - if (numCPUsWithFrequency > 0) + if (numCPUsWithFrequency > 0) { this->cpus[0].frequency = totalFrequency / numCPUsWithFrequency; + } } static void LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { int cpus = this->super.cpuCount; assert(cpus > 0); - for (int i = 0; i <= cpus; i++) + for (int i = 0; i <= cpus; i++) { this->cpus[i].frequency = NAN; + } - if (scanCPUFreqencyFromSysCPUFreq(this) == 0) + if (scanCPUFreqencyFromSysCPUFreq(this) == 0) { return; + } scanCPUFreqencyFromCPUinfo(this); } @@ -1447,12 +1509,14 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { double period = LinuxProcessList_scanCPUTime(this); - if (settings->showCPUFrequency) + if (settings->showCPUFrequency) { LinuxProcessList_scanCPUFrequency(this); + } // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } struct timeval tv; gettimeofday(&tv, NULL); diff --git a/linux/Platform.c b/linux/Platform.c index 3da3f029a..66200acce 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -98,15 +98,18 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) { Panel* panel = st->panel; LinuxProcess* p = (LinuxProcess*) Panel_getSelected(panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + IOPriority ioprio1 = p->ioPriority; Panel* ioprioPanel = IOPriorityPanel_new(ioprio1); void* set = Action_pickFromVector(st, ioprioPanel, 21, true); if (set) { IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, LinuxProcess_setIOPriority, (Arg){ .i = ioprio2 }, NULL); - if (!ok) + bool ok = MainPanel_foreachProcess((MainPanel*)panel, LinuxProcess_setIOPriority, (Arg) { .i = ioprio2 }, NULL); + if (!ok) { beep(); + } } Panel_delete((Object*)ioprioPanel); return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; @@ -162,7 +165,9 @@ int Platform_getUptime() { if (fd) { int n = fscanf(fd, "%64lf", &uptime); fclose(fd); - if (n <= 0) return 0; + if (n <= 0) { + return 0; + } } return floor(uptime); } @@ -185,7 +190,9 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { int Platform_getMaxPid() { FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); - if (!file) return -1; + if (!file) + return -1; + int maxPid = 4194303; int match = fscanf(file, "%32d", &maxPid); (void) match; @@ -221,7 +228,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = v[0] + v[1] + v[2] + v[3]; } percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) percent = 0.0; + if (isnan(percent)) { + percent = 0.0; + } v[CPU_METER_FREQUENCY] = cpuData->frequency; diff --git a/linux/SELinuxMeter.c b/linux/SELinuxMeter.c index 275eefef0..ee1d84701 100644 --- a/linux/SELinuxMeter.c +++ b/linux/SELinuxMeter.c @@ -32,16 +32,19 @@ static bool enforcing = false; static bool hasSELinuxMount(void) { struct statfs sfbuf; int r = statfs("/sys/fs/selinux", &sfbuf); - if (r != 0) + if (r != 0) { return false; + } - if (sfbuf.f_type != SELINUX_MAGIC) + if (sfbuf.f_type != SELINUX_MAGIC) { return false; + } struct statvfs vfsbuf; r = statvfs("/sys/fs/selinux", &vfsbuf); - if (r != 0 || (vfsbuf.f_flag & ST_RDONLY)) + if (r != 0 || (vfsbuf.f_flag & ST_RDONLY)) { return false; + } return true; } @@ -51,22 +54,26 @@ static bool isSelinuxEnabled(void) { } static bool isSelinuxEnforcing(void) { - if (!enabled) + if (!enabled) { return false; + } int fd = open("/sys/fs/selinux/enforce", O_RDONLY); - if (fd < 0) + if (fd < 0) { return false; + } char buf[20] = {0}; int r = read(fd, buf, sizeof(buf) - 1); close(fd); - if (r < 0) + if (r < 0) { return false; + } int enforce = 0; - if (sscanf(buf, "%d", &enforce) != 1) + if (sscanf(buf, "%d", &enforce) != 1) { return false; + } return !!enforce; } diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index bfac535d4..aec13477d 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -347,8 +347,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { OpenBSDProcessList_scanCPUTime(opl); // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } OpenBSDProcessList_scanProcs(opl); } diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 21a33d1ed..055ffa991 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -184,7 +184,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { } totalPercent = CLAMP(totalPercent, 0.0, 100.0); - if (isnan(totalPercent)) totalPercent = 0.0; + if (isnan(totalPercent)) { + totalPercent = 0.0; + } return totalPercent; } @@ -250,8 +252,9 @@ char* Platform_getProcessEnv(pid_t pid) { struct kinfo_proc* kproc; size_t capacity = 4096, size = 0; - if ((kt = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) + if ((kt = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) { return NULL; + } if ((kproc = kvm_getprocs(kt, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count)) == NULL) { diff --git a/solaris/Platform.c b/solaris/Platform.c index 697777267..6159c3575 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -156,13 +156,19 @@ int Platform_getMaxPid() { kvar_t* ksvar = NULL; int vproc = 32778; // Reasonable Solaris default kc = kstat_open(); - if (kc != NULL) { kshandle = kstat_lookup(kc,"unix",0,"var"); } - if (kshandle != NULL) { kstat_read(kc,kshandle,NULL); } + if (kc != NULL) { + kshandle = kstat_lookup(kc, "unix", 0, "var"); + } + if (kshandle != NULL) { + kstat_read(kc, kshandle, NULL); + } ksvar = kshandle->ks_data; if (ksvar->v_proc > 0 ) { vproc = ksvar->v_proc; } - if (kc != NULL) { kstat_close(kc); } + if (kc != NULL) { + kstat_close(kc); + } return vproc; } @@ -195,7 +201,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { } percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) percent = 0.0; + if (isnan(percent)) { + percent = 0.0; + } v[CPU_METER_FREQUENCY] = NAN; @@ -233,10 +241,12 @@ static int Platform_buildenv(void* accum, struct ps_prochandle* Phandle, uintptr (void) Phandle; (void) addr; size_t thissz = strlen(str); - if ((thissz + 2) > (accump->capacity - accump->size)) + if ((thissz + 2) > (accump->capacity - accump->size)) { accump->env = xRealloc(accump->env, accump->capacity *= 2); - if ((thissz + 2) > (accump->capacity - accump->size)) + } + if ((thissz + 2) > (accump->capacity - accump->size)) { return 1; + } strlcpy( accump->env + accump->size, str, (accump->capacity - accump->size)); strncpy( accump->env + accump->size + thissz + 1, "\n", 1); accump->size = accump->size + thissz + 1; @@ -249,8 +259,9 @@ char* Platform_getProcessEnv(pid_t pid) { int graberr; struct ps_prochandle* Phandle; - if ((Phandle = Pgrab(realpid, PGRAB_RDONLY, &graberr)) == NULL) + if ((Phandle = Pgrab(realpid, PGRAB_RDONLY, &graberr)) == NULL) { return "Unable to read process environment."; + } envBuilder.capacity = 4096; envBuilder.size = 0; diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 31507506e..49aeb24c5 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -169,10 +169,11 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { pages = kstat_data_lookup(meminfo, "pagestotal"); pl->totalMem = totalmem_pgs->value.ui64 * CRT_pageSizeKB; - if (pl->totalMem > freemem_pgs->value.ui64 * CRT_pageSizeKB) + if (pl->totalMem > freemem_pgs->value.ui64 * CRT_pageSizeKB) { pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * CRT_pageSizeKB; - else - pl->usedMem = 0; // This can happen in non-global zone (in theory) + } else { + pl->usedMem = 0; // This can happen in non-global zone (in theory) + } // Not sure how to implement this on Solaris - suggestions welcome! pl->cachedMem = 0; // Not really "buffers" but the best Solaris analogue that I can find to @@ -268,7 +269,9 @@ void ProcessList_delete(ProcessList* pl) { SolarisProcessList* spl = (SolarisProcessList*) pl; ProcessList_done(pl); free(spl->cpus); - if (spl->kd) kstat_close(spl->kd); + if (spl->kd) { + kstat_close(spl->kd); + } free(spl); } @@ -287,7 +290,10 @@ int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* SolarisProcessList* spl = (SolarisProcessList*) listptr; id_t lwpid_real = _lwpsinfo->pr_lwpid; - if (lwpid_real > 1023) return 0; + if (lwpid_real > 1023) { + return 0; + } + pid_t lwpid = (_psinfo->pr_pid * 1024) + lwpid_real; bool onMasterLWP = (_lwpsinfo->pr_lwpid == _psinfo->pr_lwp.pr_lwpid); if (onMasterLWP) { @@ -347,9 +353,13 @@ int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* if (sproc->kernel && !pl->settings->hideKernelThreads) { pl->kernelThreads += proc->nlwp; pl->totalTasks += proc->nlwp + 1; - if (proc->state == 'O') pl->runningTasks++; + if (proc->state == 'O') { + pl->runningTasks++; + } } else if (!sproc->kernel) { - if (proc->state == 'O') pl->runningTasks++; + if (proc->state == 'O') { + pl->runningTasks++; + } if (pl->settings->hideUserlandThreads) { pl->totalTasks++; } else { @@ -403,8 +413,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { SolarisProcessList_scanZfsArcstats(super); // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } super->kernelThreads = 1; proc_walk(&SolarisProcessList_walkproc, super, PR_WALK_LWP); diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index 24668b69b..6c0e0229f 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -27,8 +27,9 @@ void ProcessList_delete(ProcessList* this) { void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } bool preExisting = true; Process* proc; From 0d64ca92627a42f78dc980ec53081eeadd49b262 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 1 Nov 2020 01:49:54 +0100 Subject: [PATCH 386/411] Wrap inline structure definitions --- Action.c | 10 ++++++++-- linux/IOPriorityPanel.c | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Action.c b/Action.c index 8a6e2cbe0..45128fadd 100644 --- a/Action.c +++ b/Action.c @@ -425,7 +425,10 @@ static Htop_Reaction actionTogglePauseProcessUpdate(State* st) { return HTOP_REFRESH | HTOP_REDRAW_BAR; } -static const struct { const char* key; const char* info; } helpLeft[] = { +static const struct { + const char* key; + const char* info; +} helpLeft[] = { { .key = " Arrows: ", .info = "scroll process list" }, { .key = " Digits: ", .info = "incremental PID search" }, { .key = " F3 /: ", .info = "incremental name search" }, @@ -444,7 +447,10 @@ static const struct { const char* key; const char* info; } helpLeft[] = { { .key = NULL, .info = NULL } }; -static const struct { const char* key; const char* info; } helpRight[] = { +static const struct { + const char* key; + const char* info; +} helpRight[] = { { .key = " Space: ", .info = "tag process" }, { .key = " c: ", .info = "tag process and its children" }, { .key = " U: ", .info = "untag all processes" }, diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index cd4b2e608..bd84241e2 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -21,12 +21,13 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { Panel_setHeader(this, "IO Priority:"); Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None)); - if (currPrio == IOPriority_None) { Panel_setSelected(this, 0); } - - static const struct { int klass; const char* name; } classes[] = { + static const struct { + int klass; + const char* name; + } classes[] = { { .klass = IOPRIO_CLASS_RT, .name = "Realtime" }, { .klass = IOPRIO_CLASS_BE, .name = "Best-effort" }, { .klass = 0, .name = NULL } From 1c060a9d6bde6109b5c2d003a9c275b419dd2d62 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 2 Nov 2020 21:30:47 +0100 Subject: [PATCH 387/411] Avoid RichString_beginAllocated being ammendable --- RichString.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RichString.h b/RichString.h index 5bcda6029..fdf6ba35c 100644 --- a/RichString.h +++ b/RichString.h @@ -16,7 +16,7 @@ in the source distribution for its full text. #define RichString_sizeVal(this) ((this).chlen) #define RichString_begin(this) RichString (this); RichString_beginAllocated(this) -#define RichString_beginAllocated(this) memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr +#define RichString_beginAllocated(this) do { memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr; } while(0) #define RichString_end(this) RichString_prune(&(this)) #ifdef HAVE_LIBNCURSESW From cb8bb12974af25fc845acc008c529eb86835fe6f Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 2 Nov 2020 21:32:20 +0100 Subject: [PATCH 388/411] Shorten initializer --- TraceScreen.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TraceScreen.c b/TraceScreen.c index b12774882..1280b1e4c 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -143,9 +143,7 @@ void TraceScreen_updateTrace(InfoScreen* super) { // FD_SET(STDIN_FILENO, &fds); FD_SET(fd_strace, &fds); - struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = 500; + struct timeval tv = { .tv_sec = 0, .tv_usec = 500 }; int ready = select(fd_strace + 1, &fds, NULL, NULL, &tv); size_t nread = 0; From 0e922d4085f0285cf353323fd5a96edae604d5da Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 2 Nov 2020 21:36:20 +0100 Subject: [PATCH 389/411] Integrate NAN check into assignment The check for NAN is kept to avoid relying on implementation details of the CLAMP macro/function --- dragonflybsd/Platform.c | 5 +---- linux/LinuxProcessList.c | 5 +---- solaris/Platform.c | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 5f9f6373c..604994c4f 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -176,10 +176,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = v[0] + v[1] + v[2]; } - percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) { - percent = 0.0; - } + percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); v[CPU_METER_FREQUENCY] = NAN; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index e91666d04..d3416de54 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1055,10 +1055,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* } float percent_cpu = (lp->utime + lp->stime - lasttimes) / period * 100.0; - proc->percent_cpu = CLAMP(percent_cpu, 0.0, cpus * 100.0); - if (isnan(proc->percent_cpu)) - proc->percent_cpu = 0.0; - + proc->percent_cpu = isnan(percent_cpu) ? 0.0 : CLAMP(percent_cpu, 0.0, cpus * 100.0); proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(pl->totalMem) * 100.0; if (!preExisting) { diff --git a/solaris/Platform.c b/solaris/Platform.c index 6159c3575..e7a70c2c7 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -200,10 +200,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = v[0] + v[1] + v[2]; } - percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) { - percent = 0.0; - } + percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); v[CPU_METER_FREQUENCY] = NAN; From e7b95feee4f375738cb339a58337fdab83f6abbf Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 2 Nov 2020 21:37:25 +0100 Subject: [PATCH 390/411] Remove unnecessary braces --- linux/LinuxProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index d3416de54..4227dd381 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -808,7 +808,7 @@ static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) { memcpy(&stats, nla_data(nla_next(nla_data(nlattr), &rem)), sizeof(stats)); assert(lp->super.pid == (pid_t)stats.ac_pid); - timeDelta = (stats.ac_etime * 1000 - lp->delay_read_time); + timeDelta = stats.ac_etime * 1000 - lp->delay_read_time; #define BOUNDS(x) (isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x)) #define DELTAPERC(x,y) BOUNDS((float) ((x) - (y)) / timeDelta * 100) lp->cpu_delay_percent = DELTAPERC(stats.cpu_delay_total, lp->cpu_delay_total); From 84dad4c38ee4eb16ea8716891419b0a3780f3818 Mon Sep 17 00:00:00 2001 From: Fynn Wulf Date: Fri, 9 Oct 2020 21:02:27 +0200 Subject: [PATCH 391/411] Implement screen for active file locks --- Action.c | 23 ++++ Makefile.am | 2 + configure.ac | 2 +- htop.1.in | 3 + linux/ProcessLocksScreen.c | 258 +++++++++++++++++++++++++++++++++++++ linux/ProcessLocksScreen.h | 26 ++++ 6 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 linux/ProcessLocksScreen.c create mode 100644 linux/ProcessLocksScreen.h diff --git a/Action.c b/Action.c index 5b68811ef..aa9614a52 100644 --- a/Action.c +++ b/Action.c @@ -34,6 +34,10 @@ in the source distribution for its full text. #include "Vector.h" #include "XUtils.h" +#ifdef HTOP_LINUX +#include "linux/ProcessLocksScreen.h" +#endif + Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) { Panel* panel = st->panel; @@ -371,6 +375,19 @@ static Htop_Reaction actionLsof(State* st) { return HTOP_REFRESH | HTOP_REDRAW_BAR; } +#ifdef HTOP_LINUX +static Htop_Reaction actionShowLocks(State* st) { + Process* p = (Process*) Panel_getSelected(st->panel); + if (!p) return HTOP_OK; + ProcessLocksScreen* pls = ProcessLocksScreen_new(p); + InfoScreen_run((InfoScreen*)pls); + ProcessLocksScreen_delete((Object*)pls); + clear(); + CRT_enableDelay(); + return HTOP_REFRESH | HTOP_REDRAW_BAR; +} +#endif + static Htop_Reaction actionStrace(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); if (!p) return HTOP_OK; @@ -435,6 +452,9 @@ static const struct { const char* key; const char* info; } helpRight[] = { { .key = " e: ", .info = "show process environment" }, { .key = " i: ", .info = "set IO priority" }, { .key = " l: ", .info = "list open files with lsof" }, +#ifdef HTOP_LINUX + { .key = " x: ", .info = "list file locks of process" }, +#endif { .key = " s: ", .info = "trace syscalls with strace" }, { .key = " w: ", .info = "wrap process command in multiple lines" }, { .key = " F2 C S: ", .info = "setup" }, @@ -620,6 +640,9 @@ void Action_setBindings(Htop_Action* keys) { keys['S'] = actionSetup; keys['C'] = actionSetup; keys[KEY_F(2)] = actionSetup; +#ifdef HTOP_LINUX + keys['x'] = actionShowLocks; +#endif keys['l'] = actionLsof; keys['s'] = actionStrace; keys[' '] = actionTag; diff --git a/Makefile.am b/Makefile.am index a6629f6d9..c9193a868 100644 --- a/Makefile.am +++ b/Makefile.am @@ -129,6 +129,7 @@ linux_platform_headers = \ linux/LinuxProcessList.h \ linux/Platform.h \ linux/PressureStallMeter.h \ + linux/ProcessLocksScreen.h \ linux/SELinuxMeter.h \ linux/ZramMeter.h \ linux/ZramStats.h \ @@ -145,6 +146,7 @@ myhtopplatsources = \ linux/LinuxProcessList.c \ linux/Platform.c \ linux/PressureStallMeter.c \ + linux/ProcessLocksScreen.c \ linux/SELinuxMeter.c \ linux/ZramMeter.c \ zfs/ZfsArcMeter.c \ diff --git a/configure.ac b/configure.ac index b70a509f5..95a8f9098 100644 --- a/configure.ac +++ b/configure.ac @@ -88,7 +88,7 @@ AC_TYPE_UID_T # ---------------------------------------------------------------------- AC_FUNC_CLOSEDIR_VOID AC_FUNC_STAT -AC_CHECK_FUNCS([fstatat memmove strncasecmp strstr strdup]) +AC_CHECK_FUNCS([fstatat memmove readlinkat strdup strncasecmp strstr]) save_cflags="${CFLAGS}" CFLAGS="${CFLAGS} -std=c99" diff --git a/htop.1.in b/htop.1.in index 3e95c201b..cf337b09d 100644 --- a/htop.1.in +++ b/htop.1.in @@ -123,6 +123,9 @@ will display the list of file descriptors opened by the process. Display the command line of the selected process in a separate screen, wrapped onto multiple lines as needed. .TP +.B x +Display the active file locks of the selected process in a separate screen. +.TP .B F1, h, ? Go to the help screen .TP diff --git a/linux/ProcessLocksScreen.c b/linux/ProcessLocksScreen.c new file mode 100644 index 000000000..bdbf22ff0 --- /dev/null +++ b/linux/ProcessLocksScreen.c @@ -0,0 +1,258 @@ +/* +htop - ProcessLocksScreen.c +(C) 2020 htop dev team +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include "ProcessLocksScreen.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "CRT.h" +#include "FunctionBar.h" +#include "IncSet.h" +#include "ProcessList.h" +#include "XUtils.h" + + +typedef struct FileLocks_Data_ { + char* data[4]; + int id; + unsigned int dev[2]; + uint64_t inode; + uint64_t start; + uint64_t end; +} FileLocks_Data; + +typedef struct FileLocks_ProcessData_ { + bool error; + struct FileLocks_LockData_* locks; +} FileLocks_ProcessData; + +typedef struct FileLocks_LockData_ { + FileLocks_Data data; + struct FileLocks_LockData_* next; +} FileLocks_LockData; + +ProcessLocksScreen* ProcessLocksScreen_new(const Process* process) { + ProcessLocksScreen* this = xMalloc(sizeof(ProcessLocksScreen)); + Object_setClass(this, Class(ProcessLocksScreen)); + if (Process_isThread(process)) + this->pid = process->tgid; + else + this->pid = process->pid; + return (ProcessLocksScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " ID TYPE EXCLUSION READ/WRITE DEVICE:INODE START END FILENAME"); +} + +void ProcessLocksScreen_delete(Object* this) { + free(InfoScreen_done((InfoScreen*)this)); +} + +static void ProcessLocksScreen_draw(InfoScreen* this) { + InfoScreen_drawTitled(this, "Snapshot of file locks of process %d - %s", ((ProcessLocksScreen*)this)->pid, this->process->comm); +} + +/* + * Return the absolute path of a file given its pid&inode number + * + * Based on implementation of lslocks from util-linux: + * https://sources.debian.org/src/util-linux/2.36-3/misc-utils/lslocks.c/#L162 + */ +static char *ProcessLocksScreen_getInodeFilename(pid_t pid, ino_t inode) { + struct stat sb; + struct dirent *de; + DIR *dirp; + size_t len; + int fd; + + char path[PATH_MAX]; + char sym[PATH_MAX]; + char* ret = NULL; + + memset(path, 0, sizeof(path)); + memset(sym, 0, sizeof(sym)); + + xSnprintf(path, sizeof(path), "%s/%d/fd/", PROCDIR, pid); + if (strlen(path) >= (sizeof(path) - 2)) + return NULL; + + if (!(dirp = opendir(path))) + return NULL; + + if ((fd = dirfd(dirp)) < 0 ) + goto out; + + while ((de = readdir(dirp))) { + if (String_eq(de->d_name, ".") || String_eq(de->d_name, "..")) + continue; + + /* care only for numerical descriptors */ + if (!strtoull(de->d_name, (char **) NULL, 10)) + continue; + +#if !defined(HAVE_FSTATAT) || !defined(HAVE_READLINKAT) + char filepath[PATH_MAX + 1]; + xSnprintf(filepath, sizeof(filepath), "%s/%s", path, de->d_name); +#endif + +#ifdef HAVE_FSTATAT + if (!fstatat(fd, de->d_name, &sb, 0) && inode != sb.st_ino) + continue; +#else + if (!stat(filepath, &sb)) && inode != sb.st_ino) + continue; +#endif + +#ifdef HAVE_READLINKAT + if ((len = readlinkat(fd, de->d_name, sym, sizeof(sym) - 1)) < 1) + goto out; +#else + if ((len = readlink(filepath, sym, sizeof(sym) - 1)) < 1) + goto out; +#endif + + sym[len] = '\0'; + + ret = xStrdup(sym); + break; + } + +out: + closedir(dirp); + return ret; +} + +static FileLocks_ProcessData* ProcessLocksScreen_getProcessData(pid_t pid) { + FileLocks_ProcessData* pdata = xCalloc(1, sizeof(FileLocks_ProcessData)); + + FILE* f = fopen(PROCDIR "/locks", "r"); + if (!f) { + pdata->error = true; + return pdata; + } + + char buffer[1024]; + FileLocks_LockData** data_ref = &pdata->locks; + while(fgets(buffer, sizeof(buffer), f)) { + if (!strchr(buffer, '\n')) + continue; + + int lock_id; + char lock_type[16]; + char lock_excl[16]; + char lock_rw[16]; + pid_t lock_pid; + unsigned int lock_dev[2]; + uint64_t lock_inode; + char lock_start[25]; + char lock_end[25]; + + if (10 != sscanf(buffer, "%d: %15s %15s %15s %d %x:%x:%"PRIu64" %24s %24s", + &lock_id, lock_type, lock_excl, lock_rw, &lock_pid, + &lock_dev[0], &lock_dev[1], &lock_inode, + lock_start, lock_end)) + continue; + + if (pid != lock_pid) + continue; + + FileLocks_LockData* ldata = xCalloc(1, sizeof(FileLocks_LockData)); + FileLocks_Data* data = &ldata->data; + data->id = lock_id; + data->data[0] = xStrdup(lock_type); + data->data[1] = xStrdup(lock_excl); + data->data[2] = xStrdup(lock_rw); + data->data[3] = ProcessLocksScreen_getInodeFilename(lock_pid, lock_inode); + data->dev[0] = lock_dev[0]; + data->dev[1] = lock_dev[1]; + data->inode = lock_inode; + data->start = strtoull(lock_start, NULL, 10); + if (!String_eq(lock_end, "EOF")) { + data->end = strtoull(lock_end, NULL, 10); + } else { + data->end = ULLONG_MAX; + } + + *data_ref = ldata; + data_ref = &ldata->next; + } + + fclose(f); + return pdata; +} + +static inline void FileLocks_Data_clear(FileLocks_Data* data) { + for (size_t i = 0; i < ARRAYSIZE(data->data); i++) + free(data->data[i]); +} + +static void ProcessLocksScreen_scan(InfoScreen* this) { + Panel* panel = this->display; + int idx = Panel_getSelectedIndex(panel); + Panel_prune(panel); + FileLocks_ProcessData* pdata = ProcessLocksScreen_getProcessData(((ProcessLocksScreen*)this)->pid); + if (pdata->error) { + InfoScreen_addLine(this, "Could not read file locks."); + } else { + FileLocks_LockData* ldata = pdata->locks; + if (!ldata) { + InfoScreen_addLine(this, "No locks have been found for the selected process."); + } + while (ldata) { + FileLocks_Data* data = &ldata->data; + + char entry[512]; + if (ULLONG_MAX == data->end) { + xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20s %s", + data->id, + data->data[0], data->data[1], data->data[2], + data->dev[0], data->dev[1], data->inode, + data->start, "", + data->data[3] ? data->data[3] : "" + ); + } else { + xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20"PRIu64" %s", + data->id, + data->data[0], data->data[1], data->data[2], + data->dev[0], data->dev[1], data->inode, + data->start, data->end, + data->data[3] ? data->data[3] : "" + ); + } + + InfoScreen_addLine(this, entry); + FileLocks_Data_clear(&ldata->data); + + FileLocks_LockData* old = ldata; + ldata = ldata->next; + free(old); + } + } + free(pdata); + Vector_insertionSort(this->lines); + Vector_insertionSort(panel->items); + Panel_setSelected(panel, idx); +} + +const InfoScreenClass ProcessLocksScreen_class = { + .super = { + .extends = Class(Object), + .delete = ProcessLocksScreen_delete + }, + .scan = ProcessLocksScreen_scan, + .draw = ProcessLocksScreen_draw +}; diff --git a/linux/ProcessLocksScreen.h b/linux/ProcessLocksScreen.h new file mode 100644 index 000000000..ec940fba3 --- /dev/null +++ b/linux/ProcessLocksScreen.h @@ -0,0 +1,26 @@ +#ifndef HEADER_ProcessLocksScreen +#define HEADER_ProcessLocksScreen +/* +htop - ProcessLocksScreen.h +(C) 2020 htop dev team +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "InfoScreen.h" + +#include + + +typedef struct ProcessLocksScreen_ { + InfoScreen super; + pid_t pid; +} ProcessLocksScreen; + +extern const InfoScreenClass ProcessLocksScreen_class; + +ProcessLocksScreen* ProcessLocksScreen_new(const Process* process); + +void ProcessLocksScreen_delete(Object* this); + +#endif From 2d6da2e52066067e4c82a2e16f73438319e1db81 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Thu, 29 Oct 2020 23:02:57 +0100 Subject: [PATCH 392/411] Add compat wrapper for readlinkat --- Compat.c | 26 ++++++++++++++++++++++++-- Compat.h | 7 +++++++ linux/ProcessLocksScreen.c | 20 +++----------------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Compat.c b/Compat.c index 25aa9f734..6401f696a 100644 --- a/Compat.c +++ b/Compat.c @@ -13,9 +13,7 @@ in the source distribution for its full text. #include #include "Compat.h" -#ifndef HAVE_FSTATAT #include "XUtils.h" -#endif int Compat_fstatat(int dirfd, @@ -44,3 +42,27 @@ int Compat_fstatat(int dirfd, #endif } + +int Compat_readlinkat(int dirfd, + const char* dirpath, + const char* pathname, + char* buf, + size_t bufsize) { + +#ifdef HAVE_READLINKAT + + (void)dirpath; + + return readlinkat(dirfd, pathname, buf, bufsize); + +#else + + (void)dirfd; + + char path[4096]; + xSnprintf(path, sizeof(path), "%s/%s", dirpath, pathname); + + return readlink(path, buf, bufsize); + +#endif +} diff --git a/Compat.h b/Compat.h index c9fd0e62d..c0085d5ce 100644 --- a/Compat.h +++ b/Compat.h @@ -7,6 +7,7 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include #include @@ -16,4 +17,10 @@ int Compat_fstatat(int dirfd, struct stat* statbuf, int flags); +int Compat_readlinkat(int dirfd, + const char* dirpath, + const char* pathname, + char* buf, + size_t bufsize); + #endif /* HEADER_Compat */ diff --git a/linux/ProcessLocksScreen.c b/linux/ProcessLocksScreen.c index bdbf22ff0..c93d28458 100644 --- a/linux/ProcessLocksScreen.c +++ b/linux/ProcessLocksScreen.c @@ -23,6 +23,7 @@ in the source distribution for its full text. #include #include "CRT.h" +#include "Compat.h" #include "FunctionBar.h" #include "IncSet.h" #include "ProcessList.h" @@ -104,26 +105,11 @@ static char *ProcessLocksScreen_getInodeFilename(pid_t pid, ino_t inode) { if (!strtoull(de->d_name, (char **) NULL, 10)) continue; -#if !defined(HAVE_FSTATAT) || !defined(HAVE_READLINKAT) - char filepath[PATH_MAX + 1]; - xSnprintf(filepath, sizeof(filepath), "%s/%s", path, de->d_name); -#endif - -#ifdef HAVE_FSTATAT - if (!fstatat(fd, de->d_name, &sb, 0) && inode != sb.st_ino) - continue; -#else - if (!stat(filepath, &sb)) && inode != sb.st_ino) + if (!Compat_fstatat(fd, path, de->d_name, &sb, 0) && inode != sb.st_ino) continue; -#endif -#ifdef HAVE_READLINKAT - if ((len = readlinkat(fd, de->d_name, sym, sizeof(sym) - 1)) < 1) - goto out; -#else - if ((len = readlink(filepath, sym, sizeof(sym) - 1)) < 1) + if ((len = Compat_readlinkat(fd, path, de->d_name, sym, sizeof(sym) - 1)) < 1) goto out; -#endif sym[len] = '\0'; From 18763051a2c5a5d3a39bfabc284b3d72b1f6fc9b Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Wed, 11 Nov 2020 22:15:35 +0100 Subject: [PATCH 393/411] Split platform dependent parts for file locks screen --- Action.c | 11 +- Makefile.am | 4 +- ProcessLocksScreen.c | 114 ++++++++ ...ocessLocksScreen.h => ProcessLocksScreen.h | 19 ++ darwin/Platform.c | 12 + darwin/Platform.h | 15 +- dragonflybsd/Platform.c | 11 + dragonflybsd/Platform.h | 8 + freebsd/Platform.c | 11 + freebsd/Platform.h | 8 + linux/Platform.c | 119 +++++++++ linux/Platform.h | 6 + linux/ProcessLocksScreen.c | 244 ------------------ openbsd/Platform.c | 11 + openbsd/Platform.h | 8 + solaris/Platform.c | 11 + solaris/Platform.h | 17 +- unsupported/Platform.c | 11 + unsupported/Platform.h | 5 + 19 files changed, 382 insertions(+), 263 deletions(-) create mode 100644 ProcessLocksScreen.c rename linux/ProcessLocksScreen.h => ProcessLocksScreen.h (57%) delete mode 100644 linux/ProcessLocksScreen.c diff --git a/Action.c b/Action.c index aa9614a52..ee5b9af8d 100644 --- a/Action.c +++ b/Action.c @@ -27,6 +27,7 @@ in the source distribution for its full text. #include "MainPanel.h" #include "OpenFilesScreen.h" #include "Process.h" +#include "ProcessLocksScreen.h" #include "ProvideCurses.h" #include "ScreenManager.h" #include "SignalsPanel.h" @@ -34,10 +35,6 @@ in the source distribution for its full text. #include "Vector.h" #include "XUtils.h" -#ifdef HTOP_LINUX -#include "linux/ProcessLocksScreen.h" -#endif - Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) { Panel* panel = st->panel; @@ -375,7 +372,6 @@ static Htop_Reaction actionLsof(State* st) { return HTOP_REFRESH | HTOP_REDRAW_BAR; } -#ifdef HTOP_LINUX static Htop_Reaction actionShowLocks(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); if (!p) return HTOP_OK; @@ -386,7 +382,6 @@ static Htop_Reaction actionShowLocks(State* st) { CRT_enableDelay(); return HTOP_REFRESH | HTOP_REDRAW_BAR; } -#endif static Htop_Reaction actionStrace(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); @@ -452,9 +447,7 @@ static const struct { const char* key; const char* info; } helpRight[] = { { .key = " e: ", .info = "show process environment" }, { .key = " i: ", .info = "set IO priority" }, { .key = " l: ", .info = "list open files with lsof" }, -#ifdef HTOP_LINUX { .key = " x: ", .info = "list file locks of process" }, -#endif { .key = " s: ", .info = "trace syscalls with strace" }, { .key = " w: ", .info = "wrap process command in multiple lines" }, { .key = " F2 C S: ", .info = "setup" }, @@ -640,9 +633,7 @@ void Action_setBindings(Htop_Action* keys) { keys['S'] = actionSetup; keys['C'] = actionSetup; keys[KEY_F(2)] = actionSetup; -#ifdef HTOP_LINUX keys['x'] = actionShowLocks; -#endif keys['l'] = actionLsof; keys['s'] = actionStrace; keys[' '] = actionTag; diff --git a/Makefile.am b/Makefile.am index c9193a868..9a3067fff 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,6 +53,7 @@ myhtopsources = \ Panel.c \ Process.c \ ProcessList.c \ + ProcessLocksScreen.c \ RichString.c \ ScreenManager.c \ Settings.c \ @@ -105,6 +106,7 @@ myhtopheaders = \ Panel.h \ Process.h \ ProcessList.h \ + ProcessLocksScreen.h \ ProvideCurses.h \ RichString.h \ ScreenManager.h \ @@ -129,7 +131,6 @@ linux_platform_headers = \ linux/LinuxProcessList.h \ linux/Platform.h \ linux/PressureStallMeter.h \ - linux/ProcessLocksScreen.h \ linux/SELinuxMeter.h \ linux/ZramMeter.h \ linux/ZramStats.h \ @@ -146,7 +147,6 @@ myhtopplatsources = \ linux/LinuxProcessList.c \ linux/Platform.c \ linux/PressureStallMeter.c \ - linux/ProcessLocksScreen.c \ linux/SELinuxMeter.c \ linux/ZramMeter.c \ zfs/ZfsArcMeter.c \ diff --git a/ProcessLocksScreen.c b/ProcessLocksScreen.c new file mode 100644 index 000000000..480afccb2 --- /dev/null +++ b/ProcessLocksScreen.c @@ -0,0 +1,114 @@ +/* +htop - ProcessLocksScreen.c +(C) 2020 htop dev team +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include "ProcessLocksScreen.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "CRT.h" +#include "Compat.h" +#include "FunctionBar.h" +#include "IncSet.h" +#include "Platform.h" +#include "ProcessList.h" +#include "XUtils.h" + + +ProcessLocksScreen* ProcessLocksScreen_new(const Process* process) { + ProcessLocksScreen* this = xMalloc(sizeof(ProcessLocksScreen)); + Object_setClass(this, Class(ProcessLocksScreen)); + if (Process_isThread(process)) + this->pid = process->tgid; + else + this->pid = process->pid; + return (ProcessLocksScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " ID TYPE EXCLUSION READ/WRITE DEVICE:INODE START END FILENAME"); +} + +void ProcessLocksScreen_delete(Object* this) { + free(InfoScreen_done((InfoScreen*)this)); +} + +static void ProcessLocksScreen_draw(InfoScreen* this) { + InfoScreen_drawTitled(this, "Snapshot of file locks of process %d - %s", ((ProcessLocksScreen*)this)->pid, this->process->comm); +} + +static inline void FileLocks_Data_clear(FileLocks_Data* data) { + for (size_t i = 0; i < ARRAYSIZE(data->data); i++) + free(data->data[i]); +} + +static void ProcessLocksScreen_scan(InfoScreen* this) { + Panel* panel = this->display; + int idx = Panel_getSelectedIndex(panel); + Panel_prune(panel); + FileLocks_ProcessData* pdata = Platform_getProcessLocks(((ProcessLocksScreen*)this)->pid); + if (!pdata) { + InfoScreen_addLine(this, "This feature is not supported on your platform."); + } else if (pdata->error) { + InfoScreen_addLine(this, "Could not determine file locks."); + } else { + FileLocks_LockData* ldata = pdata->locks; + if (!ldata) { + InfoScreen_addLine(this, "No locks have been found for the selected process."); + } + while (ldata) { + FileLocks_Data* data = &ldata->data; + + char entry[512]; + if (ULLONG_MAX == data->end) { + xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20s %s", + data->id, + data->data[0], data->data[1], data->data[2], + data->dev[0], data->dev[1], data->inode, + data->start, "", + data->data[3] ? data->data[3] : "" + ); + } else { + xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20"PRIu64" %s", + data->id, + data->data[0], data->data[1], data->data[2], + data->dev[0], data->dev[1], data->inode, + data->start, data->end, + data->data[3] ? data->data[3] : "" + ); + } + + InfoScreen_addLine(this, entry); + FileLocks_Data_clear(&ldata->data); + + FileLocks_LockData* old = ldata; + ldata = ldata->next; + free(old); + } + } + free(pdata); + Vector_insertionSort(this->lines); + Vector_insertionSort(panel->items); + Panel_setSelected(panel, idx); +} + +const InfoScreenClass ProcessLocksScreen_class = { + .super = { + .extends = Class(Object), + .delete = ProcessLocksScreen_delete + }, + .scan = ProcessLocksScreen_scan, + .draw = ProcessLocksScreen_draw +}; diff --git a/linux/ProcessLocksScreen.h b/ProcessLocksScreen.h similarity index 57% rename from linux/ProcessLocksScreen.h rename to ProcessLocksScreen.h index ec940fba3..5da53adc4 100644 --- a/linux/ProcessLocksScreen.h +++ b/ProcessLocksScreen.h @@ -17,6 +17,25 @@ typedef struct ProcessLocksScreen_ { pid_t pid; } ProcessLocksScreen; +typedef struct FileLocks_Data_ { + char* data[4]; + int id; + unsigned int dev[2]; + uint64_t inode; + uint64_t start; + uint64_t end; +} FileLocks_Data; + +typedef struct FileLocks_LockData_ { + FileLocks_Data data; + struct FileLocks_LockData_* next; +} FileLocks_LockData; + +typedef struct FileLocks_ProcessData_ { + bool error; + struct FileLocks_LockData_* locks; +} FileLocks_ProcessData; + extern const InfoScreenClass ProcessLocksScreen_class; ProcessLocksScreen* ProcessLocksScreen_new(const Process* process); diff --git a/darwin/Platform.c b/darwin/Platform.c index b1f9283d8..1f9120cbd 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -17,6 +17,7 @@ in the source distribution for its full text. #include "DateMeter.h" #include "DateTimeMeter.h" #include "HostnameMeter.h" +#include "ProcessLocksScreen.h" #include "UptimeMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" @@ -311,6 +312,17 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } +char* Platform_getInodeFilename(pid_t pid, ino_t inode) { + (void)pid; + (void)inode; + return NULL; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + bool Platform_getDiskIO(DiskIOData* data) { // TODO (void)data; diff --git a/darwin/Platform.h b/darwin/Platform.h index 471b38a9a..2eb34372a 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -8,12 +8,17 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include + #include "Action.h" -#include "SignalsPanel.h" -#include "CPUMeter.h" -#include "DiskIOMeter.h" #include "BatteryMeter.h" +#include "CPUMeter.h" #include "DarwinProcess.h" +#include "DiskIOMeter.h" +#include "ProcessLocksScreen.h" +#include "SignalsPanel.h" + extern ProcessField Platform_defaultFields[]; @@ -49,6 +54,10 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +char* Platform_getInodeFilename(pid_t pid, ino_t inode); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 5b81c610f..d0cda8c27 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -206,6 +206,17 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; } +char* Platform_getInodeFilename(pid_t pid, ino_t inode) { + (void)pid; + (void)inode; + return NULL; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + bool Platform_getDiskIO(DiskIOData* data) { // TODO (void)data; diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 6c8847191..41fe44cd2 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -8,9 +8,13 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include + #include "Action.h" #include "BatteryMeter.h" #include "DiskIOMeter.h" +#include "ProcessLocksScreen.h" #include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -41,6 +45,10 @@ void Platform_setSwapValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +char* Platform_getInodeFilename(pid_t pid, ino_t inode); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, diff --git a/freebsd/Platform.c b/freebsd/Platform.c index bdd49bf6c..a49cfd259 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -243,6 +243,17 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } +char* Platform_getInodeFilename(pid_t pid, ino_t inode) { + (void)pid; + (void)inode; + return NULL; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + bool Platform_getDiskIO(DiskIOData* data) { if (devstat_checkversion(NULL) < 0) diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 894b3e252..2cdd068dd 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -7,9 +7,13 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include + #include "Action.h" #include "BatteryMeter.h" #include "DiskIOMeter.h" +#include "ProcessLocksScreen.h" #include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -44,6 +48,10 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +char* Platform_getInodeFilename(pid_t pid, ino_t inode); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, diff --git a/linux/Platform.c b/linux/Platform.c index f7a768c9b..7e51bf61e 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -11,11 +11,16 @@ in the source distribution for its full text. #include #include +#include +#include +#include +#include #include #include #include "BatteryMeter.h" #include "ClockMeter.h" +#include "Compat.h" #include "CPUMeter.h" #include "DateMeter.h" #include "DateTimeMeter.h" @@ -304,6 +309,120 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } +/* + * Return the absolute path of a file given its pid&inode number + * + * Based on implementation of lslocks from util-linux: + * https://sources.debian.org/src/util-linux/2.36-3/misc-utils/lslocks.c/#L162 + */ +char* Platform_getInodeFilename(pid_t pid, ino_t inode) { + struct stat sb; + struct dirent *de; + DIR *dirp; + size_t len; + int fd; + + char path[PATH_MAX]; + char sym[PATH_MAX]; + char* ret = NULL; + + memset(path, 0, sizeof(path)); + memset(sym, 0, sizeof(sym)); + + xSnprintf(path, sizeof(path), "%s/%d/fd/", PROCDIR, pid); + if (strlen(path) >= (sizeof(path) - 2)) + return NULL; + + if (!(dirp = opendir(path))) + return NULL; + + if ((fd = dirfd(dirp)) < 0 ) + goto out; + + while ((de = readdir(dirp))) { + if (String_eq(de->d_name, ".") || String_eq(de->d_name, "..")) + continue; + + /* care only for numerical descriptors */ + if (!strtoull(de->d_name, (char **) NULL, 10)) + continue; + + if (!Compat_fstatat(fd, path, de->d_name, &sb, 0) && inode != sb.st_ino) + continue; + + if ((len = Compat_readlinkat(fd, path, de->d_name, sym, sizeof(sym) - 1)) < 1) + goto out; + + sym[len] = '\0'; + + ret = xStrdup(sym); + break; + } + +out: + closedir(dirp); + return ret; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + FileLocks_ProcessData* pdata = xCalloc(1, sizeof(FileLocks_ProcessData)); + + FILE* f = fopen(PROCDIR "/locks", "r"); + if (!f) { + pdata->error = true; + return pdata; + } + + char buffer[1024]; + FileLocks_LockData** data_ref = &pdata->locks; + while(fgets(buffer, sizeof(buffer), f)) { + if (!strchr(buffer, '\n')) + continue; + + int lock_id; + char lock_type[16]; + char lock_excl[16]; + char lock_rw[16]; + pid_t lock_pid; + unsigned int lock_dev[2]; + uint64_t lock_inode; + char lock_start[25]; + char lock_end[25]; + + if (10 != sscanf(buffer, "%d: %15s %15s %15s %d %x:%x:%"PRIu64" %24s %24s", + &lock_id, lock_type, lock_excl, lock_rw, &lock_pid, + &lock_dev[0], &lock_dev[1], &lock_inode, + lock_start, lock_end)) + continue; + + if (pid != lock_pid) + continue; + + FileLocks_LockData* ldata = xCalloc(1, sizeof(FileLocks_LockData)); + FileLocks_Data* data = &ldata->data; + data->id = lock_id; + data->data[0] = xStrdup(lock_type); + data->data[1] = xStrdup(lock_excl); + data->data[2] = xStrdup(lock_rw); + data->data[3] = Platform_getInodeFilename(lock_pid, lock_inode); + data->dev[0] = lock_dev[0]; + data->dev[1] = lock_dev[1]; + data->inode = lock_inode; + data->start = strtoull(lock_start, NULL, 10); + if (!String_eq(lock_end, "EOF")) { + data->end = strtoull(lock_end, NULL, 10); + } else { + data->end = ULLONG_MAX; + } + + *data_ref = ldata; + data_ref = &ldata->next; + } + + fclose(f); + return pdata; +} + void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred) { *ten = *sixty = *threehundred = 0; char procname[128+1]; diff --git a/linux/Platform.h b/linux/Platform.h index b61a4db81..5a661a040 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -14,6 +14,7 @@ in the source distribution for its full text. #include "DiskIOMeter.h" #include "Meter.h" #include "Process.h" +#include "ProcessLocksScreen.h" #include "SignalsPanel.h" extern ProcessField Platform_defaultFields[]; @@ -45,8 +46,13 @@ void Platform_setZramValues(Meter* this); void Platform_setZfsArcValues(Meter* this); void Platform_setZfsCompressedArcValues(Meter* this); + char* Platform_getProcessEnv(pid_t pid); +char* Platform_getInodeFilename(pid_t pid, ino_t inode); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); bool Platform_getDiskIO(DiskIOData* data); diff --git a/linux/ProcessLocksScreen.c b/linux/ProcessLocksScreen.c deleted file mode 100644 index c93d28458..000000000 --- a/linux/ProcessLocksScreen.c +++ /dev/null @@ -1,244 +0,0 @@ -/* -htop - ProcessLocksScreen.c -(C) 2020 htop dev team -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" // IWYU pragma: keep - -#include "ProcessLocksScreen.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "CRT.h" -#include "Compat.h" -#include "FunctionBar.h" -#include "IncSet.h" -#include "ProcessList.h" -#include "XUtils.h" - - -typedef struct FileLocks_Data_ { - char* data[4]; - int id; - unsigned int dev[2]; - uint64_t inode; - uint64_t start; - uint64_t end; -} FileLocks_Data; - -typedef struct FileLocks_ProcessData_ { - bool error; - struct FileLocks_LockData_* locks; -} FileLocks_ProcessData; - -typedef struct FileLocks_LockData_ { - FileLocks_Data data; - struct FileLocks_LockData_* next; -} FileLocks_LockData; - -ProcessLocksScreen* ProcessLocksScreen_new(const Process* process) { - ProcessLocksScreen* this = xMalloc(sizeof(ProcessLocksScreen)); - Object_setClass(this, Class(ProcessLocksScreen)); - if (Process_isThread(process)) - this->pid = process->tgid; - else - this->pid = process->pid; - return (ProcessLocksScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " ID TYPE EXCLUSION READ/WRITE DEVICE:INODE START END FILENAME"); -} - -void ProcessLocksScreen_delete(Object* this) { - free(InfoScreen_done((InfoScreen*)this)); -} - -static void ProcessLocksScreen_draw(InfoScreen* this) { - InfoScreen_drawTitled(this, "Snapshot of file locks of process %d - %s", ((ProcessLocksScreen*)this)->pid, this->process->comm); -} - -/* - * Return the absolute path of a file given its pid&inode number - * - * Based on implementation of lslocks from util-linux: - * https://sources.debian.org/src/util-linux/2.36-3/misc-utils/lslocks.c/#L162 - */ -static char *ProcessLocksScreen_getInodeFilename(pid_t pid, ino_t inode) { - struct stat sb; - struct dirent *de; - DIR *dirp; - size_t len; - int fd; - - char path[PATH_MAX]; - char sym[PATH_MAX]; - char* ret = NULL; - - memset(path, 0, sizeof(path)); - memset(sym, 0, sizeof(sym)); - - xSnprintf(path, sizeof(path), "%s/%d/fd/", PROCDIR, pid); - if (strlen(path) >= (sizeof(path) - 2)) - return NULL; - - if (!(dirp = opendir(path))) - return NULL; - - if ((fd = dirfd(dirp)) < 0 ) - goto out; - - while ((de = readdir(dirp))) { - if (String_eq(de->d_name, ".") || String_eq(de->d_name, "..")) - continue; - - /* care only for numerical descriptors */ - if (!strtoull(de->d_name, (char **) NULL, 10)) - continue; - - if (!Compat_fstatat(fd, path, de->d_name, &sb, 0) && inode != sb.st_ino) - continue; - - if ((len = Compat_readlinkat(fd, path, de->d_name, sym, sizeof(sym) - 1)) < 1) - goto out; - - sym[len] = '\0'; - - ret = xStrdup(sym); - break; - } - -out: - closedir(dirp); - return ret; -} - -static FileLocks_ProcessData* ProcessLocksScreen_getProcessData(pid_t pid) { - FileLocks_ProcessData* pdata = xCalloc(1, sizeof(FileLocks_ProcessData)); - - FILE* f = fopen(PROCDIR "/locks", "r"); - if (!f) { - pdata->error = true; - return pdata; - } - - char buffer[1024]; - FileLocks_LockData** data_ref = &pdata->locks; - while(fgets(buffer, sizeof(buffer), f)) { - if (!strchr(buffer, '\n')) - continue; - - int lock_id; - char lock_type[16]; - char lock_excl[16]; - char lock_rw[16]; - pid_t lock_pid; - unsigned int lock_dev[2]; - uint64_t lock_inode; - char lock_start[25]; - char lock_end[25]; - - if (10 != sscanf(buffer, "%d: %15s %15s %15s %d %x:%x:%"PRIu64" %24s %24s", - &lock_id, lock_type, lock_excl, lock_rw, &lock_pid, - &lock_dev[0], &lock_dev[1], &lock_inode, - lock_start, lock_end)) - continue; - - if (pid != lock_pid) - continue; - - FileLocks_LockData* ldata = xCalloc(1, sizeof(FileLocks_LockData)); - FileLocks_Data* data = &ldata->data; - data->id = lock_id; - data->data[0] = xStrdup(lock_type); - data->data[1] = xStrdup(lock_excl); - data->data[2] = xStrdup(lock_rw); - data->data[3] = ProcessLocksScreen_getInodeFilename(lock_pid, lock_inode); - data->dev[0] = lock_dev[0]; - data->dev[1] = lock_dev[1]; - data->inode = lock_inode; - data->start = strtoull(lock_start, NULL, 10); - if (!String_eq(lock_end, "EOF")) { - data->end = strtoull(lock_end, NULL, 10); - } else { - data->end = ULLONG_MAX; - } - - *data_ref = ldata; - data_ref = &ldata->next; - } - - fclose(f); - return pdata; -} - -static inline void FileLocks_Data_clear(FileLocks_Data* data) { - for (size_t i = 0; i < ARRAYSIZE(data->data); i++) - free(data->data[i]); -} - -static void ProcessLocksScreen_scan(InfoScreen* this) { - Panel* panel = this->display; - int idx = Panel_getSelectedIndex(panel); - Panel_prune(panel); - FileLocks_ProcessData* pdata = ProcessLocksScreen_getProcessData(((ProcessLocksScreen*)this)->pid); - if (pdata->error) { - InfoScreen_addLine(this, "Could not read file locks."); - } else { - FileLocks_LockData* ldata = pdata->locks; - if (!ldata) { - InfoScreen_addLine(this, "No locks have been found for the selected process."); - } - while (ldata) { - FileLocks_Data* data = &ldata->data; - - char entry[512]; - if (ULLONG_MAX == data->end) { - xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20s %s", - data->id, - data->data[0], data->data[1], data->data[2], - data->dev[0], data->dev[1], data->inode, - data->start, "", - data->data[3] ? data->data[3] : "" - ); - } else { - xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20"PRIu64" %s", - data->id, - data->data[0], data->data[1], data->data[2], - data->dev[0], data->dev[1], data->inode, - data->start, data->end, - data->data[3] ? data->data[3] : "" - ); - } - - InfoScreen_addLine(this, entry); - FileLocks_Data_clear(&ldata->data); - - FileLocks_LockData* old = ldata; - ldata = ldata->next; - free(old); - } - } - free(pdata); - Vector_insertionSort(this->lines); - Vector_insertionSort(panel->items); - Panel_setSelected(panel, idx); -} - -const InfoScreenClass ProcessLocksScreen_class = { - .super = { - .extends = Class(Object), - .delete = ProcessLocksScreen_delete - }, - .scan = ProcessLocksScreen_scan, - .draw = ProcessLocksScreen_draw -}; diff --git a/openbsd/Platform.c b/openbsd/Platform.c index df6bc0cc1..a24d6a2d0 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -288,6 +288,17 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } +char* Platform_getInodeFilename(pid_t pid, ino_t inode) { + (void)pid; + (void)inode; + return NULL; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + bool Platform_getDiskIO(DiskIOData* data) { // TODO (void)data; diff --git a/openbsd/Platform.h b/openbsd/Platform.h index 8cb5bdf33..c7f4e4d72 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -8,9 +8,13 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include + #include "Action.h" #include "BatteryMeter.h" #include "DiskIOMeter.h" +#include "ProcessLocksScreen.h" #include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -42,6 +46,10 @@ void Platform_setSwapValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +char* Platform_getInodeFilename(pid_t pid, ino_t inode); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, diff --git a/solaris/Platform.c b/solaris/Platform.c index 87247969e..8e08c0253 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -264,6 +264,17 @@ char* Platform_getProcessEnv(pid_t pid) { return envBuilder.env; } +char* Platform_getInodeFilename(pid_t pid, ino_t inode) { + (void)pid; + (void)inode; + return NULL; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + bool Platform_getDiskIO(DiskIOData* data) { // TODO (void)data; diff --git a/solaris/Platform.h b/solaris/Platform.h index 8718dbfee..5db271ce7 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -9,14 +9,19 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include +#include +#include +#include +#include + #include "Action.h" #include "BatteryMeter.h" #include "DiskIOMeter.h" +#include "ProcessLocksScreen.h" #include "SignalsPanel.h" -#include -#include -#include -#include + #define kill(pid, signal) kill(pid / 1024, signal) @@ -64,6 +69,10 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +char* Platform_getInodeFilename(pid_t pid, ino_t inode); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 3f8cefa68..4208b73c2 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -141,6 +141,17 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; } +char* Platform_getInodeFilename(pid_t pid, ino_t inode) { + (void)pid; + (void)inode; + return NULL; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + bool Platform_getDiskIO(DiskIOData* data) { (void)data; return false; diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 902b6a9b7..8ca201c1d 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -11,6 +11,7 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" #include "DiskIOMeter.h" +#include "ProcessLocksScreen.h" #include "SignalsPanel.h" #include "UnsupportedProcess.h" @@ -48,6 +49,10 @@ bool Process_isThread(const Process* this); char* Platform_getProcessEnv(pid_t pid); +char* Platform_getInodeFilename(pid_t pid, ino_t inode); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, From d431786fca6213f4b98555deed9ea6b58677ae20 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Fri, 13 Nov 2020 21:34:21 +0100 Subject: [PATCH 394/411] Split data array for file lock information into separate fields --- ProcessLocksScreen.c | 14 ++++++++------ ProcessLocksScreen.h | 5 ++++- linux/Platform.c | 8 ++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ProcessLocksScreen.c b/ProcessLocksScreen.c index 480afccb2..67743c941 100644 --- a/ProcessLocksScreen.c +++ b/ProcessLocksScreen.c @@ -50,8 +50,10 @@ static void ProcessLocksScreen_draw(InfoScreen* this) { } static inline void FileLocks_Data_clear(FileLocks_Data* data) { - for (size_t i = 0; i < ARRAYSIZE(data->data); i++) - free(data->data[i]); + free(data->locktype); + free(data->exclusive); + free(data->readwrite); + free(data->filename); } static void ProcessLocksScreen_scan(InfoScreen* this) { @@ -75,18 +77,18 @@ static void ProcessLocksScreen_scan(InfoScreen* this) { if (ULLONG_MAX == data->end) { xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20s %s", data->id, - data->data[0], data->data[1], data->data[2], + data->locktype, data->exclusive, data->readwrite, data->dev[0], data->dev[1], data->inode, data->start, "", - data->data[3] ? data->data[3] : "" + data->filename ? data->filename : "" ); } else { xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20"PRIu64" %s", data->id, - data->data[0], data->data[1], data->data[2], + data->locktype, data->exclusive, data->readwrite, data->dev[0], data->dev[1], data->inode, data->start, data->end, - data->data[3] ? data->data[3] : "" + data->filename ? data->filename : "" ); } diff --git a/ProcessLocksScreen.h b/ProcessLocksScreen.h index 5da53adc4..daffd6299 100644 --- a/ProcessLocksScreen.h +++ b/ProcessLocksScreen.h @@ -18,7 +18,10 @@ typedef struct ProcessLocksScreen_ { } ProcessLocksScreen; typedef struct FileLocks_Data_ { - char* data[4]; + char* locktype; + char* exclusive; + char* readwrite; + char* filename; int id; unsigned int dev[2]; uint64_t inode; diff --git a/linux/Platform.c b/linux/Platform.c index 7e51bf61e..7b859c3ad 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -401,10 +401,10 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { FileLocks_LockData* ldata = xCalloc(1, sizeof(FileLocks_LockData)); FileLocks_Data* data = &ldata->data; data->id = lock_id; - data->data[0] = xStrdup(lock_type); - data->data[1] = xStrdup(lock_excl); - data->data[2] = xStrdup(lock_rw); - data->data[3] = Platform_getInodeFilename(lock_pid, lock_inode); + data->locktype = xStrdup(lock_type); + data->exclusive = xStrdup(lock_excl); + data->readwrite = xStrdup(lock_rw); + data->filename = Platform_getInodeFilename(lock_pid, lock_inode); data->dev[0] = lock_dev[0]; data->dev[1] = lock_dev[1]; data->inode = lock_inode; From da2dcf9505299eae607e29cc85691b8163c1a36e Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Sun, 15 Nov 2020 14:16:23 +0100 Subject: [PATCH 395/411] Remove duplicate test for NUL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #308, thanks @qarmin (Rafał Mikrut) --- linux/LinuxProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5e06e8c99..027d59167 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -573,7 +573,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d char* value_end = name_value_sep; - while(*value_end != '\0' && *value_end > 32) { + while(*value_end > 32) { value_end++; } From d785b1bbc3e30e41bacd283712455090eb2fe99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 15 Nov 2020 17:42:16 +0100 Subject: [PATCH 396/411] Fixup of SystemdMeter merge --- CRT.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CRT.c b/CRT.c index 2406e6023..f0f697673 100644 --- a/CRT.c +++ b/CRT.c @@ -95,9 +95,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Cyan, Black), [METER_VALUE] = A_BOLD | ColorPair(Cyan, Black), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Black), [METER_VALUE_IOREAD] = ColorPair(Green, Black), [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Black), + [METER_VALUE_OK] = ColorPair(Green, Black), [LED_COLOR] = ColorPair(Green, Black), [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), [PROCESS] = A_NORMAL, @@ -252,9 +253,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Blue, White), [METER_VALUE] = ColorPair(Black, White), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, White), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, White), [METER_VALUE_IOREAD] = ColorPair(Green, White), [METER_VALUE_IOWRITE] = ColorPair(Yellow, White), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, White), + [METER_VALUE_OK] = ColorPair(Green, White), [LED_COLOR] = ColorPair(Green, White), [TASKS_RUNNING] = ColorPair(Green, White), [PROCESS] = ColorPair(Black, White), @@ -330,9 +332,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Blue, Black), [METER_VALUE] = ColorPair(Blue, Black), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, Black), [METER_VALUE_IOREAD] = ColorPair(Green, Black), [METER_VALUE_IOWRITE] = ColorPair(Yellow, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, Black), + [METER_VALUE_OK] = ColorPair(Green, Black), [LED_COLOR] = ColorPair(Green, Black), [TASKS_RUNNING] = ColorPair(Green, Black), [PROCESS] = ColorPair(Blue, Black), @@ -408,9 +411,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Cyan, Blue), [METER_VALUE] = A_BOLD | ColorPair(Cyan, Blue), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Blue), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Blue), [METER_VALUE_IOREAD] = ColorPair(Green, Blue), [METER_VALUE_IOWRITE] = ColorPair(Black, Blue), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Blue), + [METER_VALUE_OK] = ColorPair(Green, Blue), [LED_COLOR] = ColorPair(Green, Blue), [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Blue), [PROCESS] = ColorPair(White, Blue), @@ -486,9 +490,10 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [METER_TEXT] = ColorPair(Cyan, Black), [METER_VALUE] = ColorPair(Green, Black), [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, Black), [METER_VALUE_IOREAD] = ColorPair(Green, Black), [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, Black), + [METER_VALUE_OK] = ColorPair(Green, Black), [LED_COLOR] = ColorPair(Green, Black), [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), [PROCESS] = ColorPair(Cyan, Black), From 397b5c4bd09115d0df0846fee1b06797b68ae11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 4 Nov 2020 17:46:24 +0100 Subject: [PATCH 397/411] Introduce spaceship comparison for Processes If currently two unsigned values are compared via `a - b`, in the case b is actually bigger than a, the result will not be an negative number (as -1 is expected) but a huge positive number as the subtraction is an unsigned subtraction. Avoid over-/underflow affected operations; use comparisons. Modern compilers will generate sane code, like: xor eax, eax cmp rdi, rsi seta al sbb eax, 0 ret --- Macros.h | 16 ++++-- Process.c | 59 ++++++++++---------- dragonflybsd/DragonFlyBSDProcess.c | 6 ++- freebsd/FreeBSDProcess.c | 8 +-- linux/LinuxProcess.c | 86 +++++++++++++++++------------- openbsd/OpenBSDProcess.c | 2 + solaris/SolarisProcess.c | 18 ++++--- 7 files changed, 111 insertions(+), 84 deletions(-) diff --git a/Macros.h b/Macros.h index 1064dadb8..64aaefa5a 100644 --- a/Macros.h +++ b/Macros.h @@ -4,19 +4,27 @@ #include // IWYU pragma: keep #ifndef MINIMUM -#define MINIMUM(a, b) ((a) < (b) ? (a) : (b)) +#define MINIMUM(a, b) ((a) < (b) ? (a) : (b)) #endif #ifndef MAXIMUM -#define MAXIMUM(a, b) ((a) > (b) ? (a) : (b)) +#define MAXIMUM(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef CLAMP -#define CLAMP(x, low, high) (assert((low) <= (high)), ((x) > (high)) ? (high) : MAXIMUM(x, low)) +#define CLAMP(x, low, high) (assert((low) <= (high)), ((x) > (high)) ? (high) : MAXIMUM(x, low)) #endif #ifndef ARRAYSIZE -#define ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0])) +#define ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + +#ifndef SPACESHIP_NUMBER +#define SPACESHIP_NUMBER(a, b) (((a) > (b)) - ((a) < (b))) +#endif + +#ifndef SPACESHIP_NULLSTR +#define SPACESHIP_NULLSTR(a, b) strcmp((a) ? (a) : "", (b) ? (b) : "") #endif #ifdef __GNUC__ // defined by GCC and Clang diff --git a/Process.c b/Process.c index 72360e396..427b5f62f 100644 --- a/Process.c +++ b/Process.c @@ -460,6 +460,8 @@ long Process_pidCompare(const void* v1, const void* v2) { long Process_compare(const void* v1, const void* v2) { const Process *p1, *p2; const Settings *settings = ((const Process*)v1)->settings; + int r; + if (settings->direction == 1) { p1 = (const Process*)v1; p2 = (const Process*)v2; @@ -467,59 +469,56 @@ long Process_compare(const void* v1, const void* v2) { p2 = (const Process*)v1; p1 = (const Process*)v2; } + switch (settings->sortKey) { case PERCENT_CPU: - return (p2->percent_cpu > p1->percent_cpu ? 1 : -1); + return SPACESHIP_NUMBER(p2->percent_cpu, p1->percent_cpu); case PERCENT_MEM: - return (p2->m_resident - p1->m_resident); + return SPACESHIP_NUMBER(p2->m_resident, p1->m_resident); case COMM: - return strcmp(p1->comm, p2->comm); + return SPACESHIP_NULLSTR(p1->comm, p2->comm); case MAJFLT: - return (p2->majflt - p1->majflt); + return SPACESHIP_NUMBER(p2->majflt, p1->majflt); case MINFLT: - return (p2->minflt - p1->minflt); + return SPACESHIP_NUMBER(p2->minflt, p1->minflt); case M_RESIDENT: - return (p2->m_resident - p1->m_resident); + return SPACESHIP_NUMBER(p2->m_resident, p1->m_resident); case M_SIZE: - return (p2->m_size - p1->m_size); + return SPACESHIP_NUMBER(p2->m_size, p1->m_size); case NICE: - return (p1->nice - p2->nice); + return SPACESHIP_NUMBER(p1->nice, p2->nice); case NLWP: - return (p1->nlwp - p2->nlwp); + return SPACESHIP_NUMBER(p1->nlwp, p2->nlwp); case PGRP: - return (p1->pgrp - p2->pgrp); + return SPACESHIP_NUMBER(p1->pgrp, p2->pgrp); case PID: - return (p1->pid - p2->pid); + return SPACESHIP_NUMBER(p1->pid, p2->pid); case PPID: - return (p1->ppid - p2->ppid); + return SPACESHIP_NUMBER(p1->ppid, p2->ppid); case PRIORITY: - return (p1->priority - p2->priority); + return SPACESHIP_NUMBER(p1->priority, p2->priority); case PROCESSOR: - return (p1->processor - p2->processor); + return SPACESHIP_NUMBER(p1->processor, p2->processor); case SESSION: - return (p1->session - p2->session); - case STARTTIME: { - if (p1->starttime_ctime == p2->starttime_ctime) { - return (p1->pid - p2->pid); - } else { - return (p1->starttime_ctime - p2->starttime_ctime); - } - } + return SPACESHIP_NUMBER(p1->session, p2->session); + case STARTTIME: + r = SPACESHIP_NUMBER(p1->starttime_ctime, p2->starttime_ctime); + return r != 0 ? r : SPACESHIP_NUMBER(p1->pid, p2->pid); case STATE: - return (Process_sortState(p1->state) - Process_sortState(p2->state)); + return SPACESHIP_NUMBER(Process_sortState(p1->state), Process_sortState(p2->state)); case ST_UID: - return (p1->st_uid - p2->st_uid); + return SPACESHIP_NUMBER(p1->st_uid, p2->st_uid); case TIME: - return ((p2->time) - (p1->time)); + return SPACESHIP_NUMBER(p2->time, p1->time); case TGID: - return (p1->tgid - p2->tgid); + return SPACESHIP_NUMBER(p1->tgid, p2->tgid); case TPGID: - return (p1->tpgid - p2->tpgid); + return SPACESHIP_NUMBER(p1->tpgid, p2->tpgid); case TTY_NR: - return (p1->tty_nr - p2->tty_nr); + return SPACESHIP_NUMBER(p1->tty_nr, p2->tty_nr); case USER: - return strcmp(p1->user ? p1->user : "", p2->user ? p2->user : ""); + return SPACESHIP_NULLSTR(p1->user, p2->user); default: - return (p1->pid - p2->pid); + return SPACESHIP_NUMBER(p1->pid, p2->pid); } } diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index bd2093277..55e4fbac1 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -110,6 +110,7 @@ void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, Proces long DragonFlyBSDProcess_compare(const void* v1, const void* v2) { const DragonFlyBSDProcess *p1, *p2; const Settings *settings = ((const Process*)v1)->settings; + if (settings->direction == 1) { p1 = (const DragonFlyBSDProcess*)v1; p2 = (const DragonFlyBSDProcess*)v2; @@ -117,12 +118,13 @@ long DragonFlyBSDProcess_compare(const void* v1, const void* v2) { p2 = (const DragonFlyBSDProcess*)v1; p1 = (const DragonFlyBSDProcess*)v2; } + switch ((int) settings->sortKey) { // add Platform-specific fields here case JID: - return (p1->jid - p2->jid); + return SPACESHIP_NUMBER(p1->jid, p2->jid); case JAIL: - return strcmp(p1->jname ? p1->jname : "", p2->jname ? p2->jname : ""); + return SPACESHIP_NULLSTR(p1->jname, p2->jname); default: return Process_compare(v1, v2); } diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index baad5d13c..695594e8b 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -111,6 +111,7 @@ static void FreeBSDProcess_writeField(const Process* this, RichString* str, Proc static long FreeBSDProcess_compare(const void* v1, const void* v2) { const FreeBSDProcess *p1, *p2; const Settings *settings = ((const Process*)v1)->settings; + if (settings->direction == 1) { p1 = (const FreeBSDProcess*)v1; p2 = (const FreeBSDProcess*)v2; @@ -118,14 +119,15 @@ static long FreeBSDProcess_compare(const void* v1, const void* v2) { p2 = (const FreeBSDProcess*)v1; p1 = (const FreeBSDProcess*)v2; } + switch ((int) settings->sortKey) { // add FreeBSD-specific fields here case JID: - return (p1->jid - p2->jid); + return SPACESHIP_NUMBER(p1->jid, p2->jid); case JAIL: - return strcmp(p1->jname ? p1->jname : "", p2->jname ? p2->jname : ""); + return SPACESHIP_NULLSTR(p1->jname, p2->jname); case TTY_NR: - return strcmp(p1->ttyPath ? p1->ttyPath : "", p2->ttyPath ? p2->ttyPath : ""); + return SPACESHIP_NULLSTR(p1->ttyPath, p2->ttyPath); default: return Process_compare(v1, v2); } diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index b1bd24d53..cd8db3d0c 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -307,6 +307,7 @@ void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField long LinuxProcess_compare(const void* v1, const void* v2) { const LinuxProcess *p1, *p2; const Settings *settings = ((const Process*)v1)->settings; + if (settings->direction == 1) { p1 = (const LinuxProcess*)v1; p2 = (const LinuxProcess*)v2; @@ -314,76 +315,87 @@ long LinuxProcess_compare(const void* v1, const void* v2) { p2 = (const LinuxProcess*)v1; p1 = (const LinuxProcess*)v2; } - long long diff; + switch ((int)settings->sortKey) { case M_DRS: - return (p2->m_drs - p1->m_drs); + return SPACESHIP_NUMBER(p2->m_drs, p1->m_drs); case M_DT: - return (p2->m_dt - p1->m_dt); + return SPACESHIP_NUMBER(p2->m_dt, p1->m_dt); case M_LRS: - return (p2->m_lrs - p1->m_lrs); + return SPACESHIP_NUMBER(p2->m_lrs, p1->m_lrs); case M_TRS: - return (p2->m_trs - p1->m_trs); + return SPACESHIP_NUMBER(p2->m_trs, p1->m_trs); case M_SHARE: - return (p2->m_share - p1->m_share); + return SPACESHIP_NUMBER(p2->m_share, p1->m_share); case M_PSS: - return (p2->m_pss - p1->m_pss); + return SPACESHIP_NUMBER(p2->m_pss, p1->m_pss); case M_SWAP: - return (p2->m_swap - p1->m_swap); + return SPACESHIP_NUMBER(p2->m_swap, p1->m_swap); case M_PSSWP: - return (p2->m_psswp - p1->m_psswp); - case UTIME: diff = p2->utime - p1->utime; goto test_diff; - case CUTIME: diff = p2->cutime - p1->cutime; goto test_diff; - case STIME: diff = p2->stime - p1->stime; goto test_diff; - case CSTIME: diff = p2->cstime - p1->cstime; goto test_diff; + return SPACESHIP_NUMBER(p2->m_psswp, p1->m_psswp); + case UTIME: + return SPACESHIP_NUMBER(p2->utime, p1->utime); + case CUTIME: + return SPACESHIP_NUMBER(p2->cutime, p1->cutime); + case STIME: + return SPACESHIP_NUMBER(p2->stime, p1->stime); + case CSTIME: + return SPACESHIP_NUMBER(p2->cstime, p1->cstime); #ifdef HAVE_TASKSTATS - case RCHAR: diff = p2->io_rchar - p1->io_rchar; goto test_diff; - case WCHAR: diff = p2->io_wchar - p1->io_wchar; goto test_diff; - case SYSCR: diff = p2->io_syscr - p1->io_syscr; goto test_diff; - case SYSCW: diff = p2->io_syscw - p1->io_syscw; goto test_diff; - case RBYTES: diff = p2->io_read_bytes - p1->io_read_bytes; goto test_diff; - case WBYTES: diff = p2->io_write_bytes - p1->io_write_bytes; goto test_diff; - case CNCLWB: diff = p2->io_cancelled_write_bytes - p1->io_cancelled_write_bytes; goto test_diff; - case IO_READ_RATE: diff = p2->io_rate_read_bps - p1->io_rate_read_bps; goto test_diff; - case IO_WRITE_RATE: diff = p2->io_rate_write_bps - p1->io_rate_write_bps; goto test_diff; - case IO_RATE: diff = (p2->io_rate_read_bps + p2->io_rate_write_bps) - (p1->io_rate_read_bps + p1->io_rate_write_bps); goto test_diff; + case RCHAR: + return SPACESHIP_NUMBER(p2->io_rchar, p1->io_rchar); + case WCHAR: + return SPACESHIP_NUMBER(p2->io_wchar, p1->io_wchar); + case SYSCR: + return SPACESHIP_NUMBER(p2->io_syscr, p1->io_syscr); + case SYSCW: + return SPACESHIP_NUMBER(p2->io_syscw, p1->io_syscw); + case RBYTES: + return SPACESHIP_NUMBER(p2->io_read_bytes, p1->io_read_bytes); + case WBYTES: + return SPACESHIP_NUMBER(p2->io_write_bytes, p1->io_write_bytes); + case CNCLWB: + return SPACESHIP_NUMBER(p2->io_cancelled_write_bytes, p1->io_cancelled_write_bytes); + case IO_READ_RATE: + return SPACESHIP_NUMBER(p2->io_rate_read_bps, p1->io_rate_read_bps); + case IO_WRITE_RATE: + return SPACESHIP_NUMBER(p2->io_rate_write_bps, p1->io_rate_write_bps); + case IO_RATE: + return SPACESHIP_NUMBER(p2->io_rate_read_bps + p2->io_rate_write_bps, p1->io_rate_read_bps + p1->io_rate_write_bps); #endif #ifdef HAVE_OPENVZ case CTID: - return strcmp(p1->ctid ? p1->ctid : "", p2->ctid ? p2->ctid : ""); + return SPACESHIP_NULLSTR(p1->ctid, p2->ctid); case VPID: - return (p2->vpid - p1->vpid); + return SPACESHIP_NUMBER(p2->vpid, p1->vpid); #endif #ifdef HAVE_VSERVER case VXID: - return (p2->vxid - p1->vxid); + return SPACESHIP_NUMBER(p2->vxid, p1->vxid); #endif #ifdef HAVE_CGROUP case CGROUP: - return strcmp(p1->cgroup ? p1->cgroup : "", p2->cgroup ? p2->cgroup : ""); + return SPACESHIP_NULLSTR(p1->cgroup, p2->cgroup); #endif case OOM: - return ((int)p2->oom - (int)p1->oom); + return SPACESHIP_NUMBER(p2->oom, p1->oom); #ifdef HAVE_DELAYACCT case PERCENT_CPU_DELAY: - return (p2->cpu_delay_percent > p1->cpu_delay_percent ? 1 : -1); + return SPACESHIP_NUMBER(p2->cpu_delay_percent, p1->cpu_delay_percent); case PERCENT_IO_DELAY: - return (p2->blkio_delay_percent > p1->blkio_delay_percent ? 1 : -1); + return SPACESHIP_NUMBER(p2->blkio_delay_percent, p1->blkio_delay_percent); case PERCENT_SWAP_DELAY: - return (p2->swapin_delay_percent > p1->swapin_delay_percent ? 1 : -1); + return SPACESHIP_NUMBER(p2->swapin_delay_percent, p1->swapin_delay_percent); #endif case IO_PRIORITY: - return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2); + return SPACESHIP_NUMBER(LinuxProcess_effectiveIOPriority(p1), LinuxProcess_effectiveIOPriority(p2)); case CTXT: - return ((long)p2->ctxt_diff - (long)p1->ctxt_diff); + return SPACESHIP_NUMBER(p2->ctxt_diff, p1->ctxt_diff); case SECATTR: - return strcmp(p1->secattr ? p1->secattr : "", p2->secattr ? p2->secattr : ""); + return SPACESHIP_NULLSTR(p1->secattr, p2->secattr); default: return Process_compare(v1, v2); } - -test_diff: - return (diff > 0) ? 1 : (diff < 0 ? -1 : 0); } bool Process_isThread(const Process* this) { diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 5eb61b161..1013d3b43 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -220,6 +220,7 @@ void OpenBSDProcess_writeField(const Process* this, RichString* str, ProcessFiel long OpenBSDProcess_compare(const void* v1, const void* v2) { const OpenBSDProcess *p1, *p2; const Settings *settings = ((const Process*)v1)->settings; + if (settings->direction == 1) { p1 = (const OpenBSDProcess*)v1; p2 = (const OpenBSDProcess*)v2; @@ -227,6 +228,7 @@ long OpenBSDProcess_compare(const void* v1, const void* v2) { p2 = (const OpenBSDProcess*)v1; p1 = (const OpenBSDProcess*)v2; } + switch (settings->sortKey) { // add OpenBSD-specific fields here default: diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index 9c6c7d778..7d833fe9f 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -119,6 +119,7 @@ void SolarisProcess_writeField(const Process* this, RichString* str, ProcessFiel long SolarisProcess_compare(const void* v1, const void* v2) { const SolarisProcess *p1, *p2; const Settings* settings = ((const Process*)v1)->settings; + if (settings->direction == 1) { p1 = (const SolarisProcess*)v1; p2 = (const SolarisProcess*)v2; @@ -126,25 +127,26 @@ long SolarisProcess_compare(const void* v1, const void* v2) { p2 = (const SolarisProcess*)v1; p1 = (const SolarisProcess*)v2; } + switch ((int) settings->sortKey) { case ZONEID: - return (p1->zoneid - p2->zoneid); + return SPACESHIP_NUMBER(p1->zoneid, p2->zoneid); case PROJID: - return (p1->projid - p2->projid); + return SPACESHIP_NUMBER(p1->projid, p2->projid); case TASKID: - return (p1->taskid - p2->taskid); + return SPACESHIP_NUMBER(p1->taskid, p2->taskid); case POOLID: - return (p1->poolid - p2->poolid); + return SPACESHIP_NUMBER(p1->poolid, p2->poolid); case CONTID: - return (p1->contid - p2->contid); + return SPACESHIP_NUMBER(p1->contid, p2->contid); case ZONE: return strcmp(p1->zname ? p1->zname : "global", p2->zname ? p2->zname : "global"); case PID: - return (p1->realpid - p2->realpid); + return SPACESHIP_NUMBER(p1->realpid, p2->realpid); case PPID: - return (p1->realppid - p2->realppid); + return SPACESHIP_NUMBER(p1->realppid, p2->realppid); case LWPID: - return (p1->lwpid - p2->lwpid); + return SPACESHIP_NUMBER(p1->lwpid, p2->lwpid); default: return Process_compare(v1, v2); } From 42073babb913497fba58700dc0c5ccdfa7a52b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 4 Nov 2020 17:46:04 +0100 Subject: [PATCH 398/411] Use uid_t type for Process_getuid --- Process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Process.c b/Process.c index 427b5f62f..6ca383fe1 100644 --- a/Process.c +++ b/Process.c @@ -35,7 +35,7 @@ in the source distribution for its full text. #endif -static int Process_getuid = -1; +static uid_t Process_getuid = (uid_t)-1; char Process_pidFormat[20] = "%7d "; @@ -360,7 +360,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field case TPGID: xSnprintf(buffer, n, Process_pidFormat, this->tpgid); break; case TTY_NR: xSnprintf(buffer, n, "%3u:%3u ", major(this->tty_nr), minor(this->tty_nr)); break; case USER: { - if (Process_getuid != (int) this->st_uid) + if (Process_getuid != this->st_uid) attr = CRT_colors[PROCESS_SHADOW]; if (this->user) { xSnprintf(buffer, n, "%-9s ", this->user); @@ -386,7 +386,7 @@ void Process_display(const Object* cast, RichString* out) { for (int i = 0; fields[i]; i++) As_Process(this)->writeField(this, out, fields[i]); - if (this->settings->shadowOtherUsers && (int)this->st_uid != Process_getuid) { + if (this->settings->shadowOtherUsers && this->st_uid != Process_getuid) { RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]); } @@ -420,7 +420,7 @@ void Process_init(Process* this, const struct Settings_* settings) { this->updated = false; this->basenameOffset = -1; - if (Process_getuid == -1) { + if (Process_getuid == (uid_t)-1) { Process_getuid = getuid(); } } From 91317322fee239082f04f410a5f6506a61a7ac9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 4 Nov 2020 17:46:11 +0100 Subject: [PATCH 399/411] Mark ProcessList_keyAt argument const --- MainPanel.c | 2 +- ProcessList.c | 2 +- ProcessList.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MainPanel.c b/MainPanel.c index be59abd39..5a1fe8f56 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -59,7 +59,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { if (EVENT_IS_HEADER_CLICK(ch)) { int x = EVENT_HEADER_CLICK_GET_X(ch); - ProcessList* pl = this->state->pl; + const ProcessList* pl = this->state->pl; Settings* settings = this->state->settings; int hx = super->scrollH + x + 1; ProcessField field = ProcessList_keyAt(pl, hx); diff --git a/ProcessList.c b/ProcessList.c index 2323c99ad..457761a22 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -231,7 +231,7 @@ void ProcessList_sort(ProcessList* this) { } -ProcessField ProcessList_keyAt(ProcessList* this, int at) { +ProcessField ProcessList_keyAt(const ProcessList* this, int at) { int x = 0; const ProcessField* fields = this->settings->fields; ProcessField field; diff --git a/ProcessList.h b/ProcessList.h index 6b075fa7a..737fffb3e 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -95,7 +95,7 @@ int ProcessList_size(ProcessList* this); void ProcessList_sort(ProcessList* this); -ProcessField ProcessList_keyAt(ProcessList* this, int at); +ProcessField ProcessList_keyAt(const ProcessList* this, int at); void ProcessList_expandTree(ProcessList* this); From 9f67b95308d11ee922e92f0649c2796bac58c1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 4 Nov 2020 17:46:14 +0100 Subject: [PATCH 400/411] Mark local functions static --- linux/LinuxProcess.c | 24 ++++++++++++------------ linux/LinuxProcess.h | 4 ---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index cd8db3d0c..2fec52f1d 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -128,16 +128,6 @@ ProcessPidColumn Process_pidColumns[] = { { .id = 0, .label = NULL }, }; -const ProcessClass LinuxProcess_class = { - .super = { - .extends = Class(Process), - .display = Process_display, - .delete = Process_delete, - .compare = LinuxProcess_compare - }, - .writeField = LinuxProcess_writeField, -}; - Process* LinuxProcess_new(const Settings* settings) { LinuxProcess* this = xCalloc(1, sizeof(LinuxProcess)); Object_setClass(this, Class(LinuxProcess)); @@ -203,7 +193,7 @@ void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) { } #endif -void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField field) { +static void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField field) { const LinuxProcess* lp = (const LinuxProcess*) this; bool coloring = this->settings->highlightMegabytes; char buffer[256]; buffer[255] = '\0'; @@ -304,7 +294,7 @@ void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField RichString_append(str, attr, buffer); } -long LinuxProcess_compare(const void* v1, const void* v2) { +static long LinuxProcess_compare(const void* v1, const void* v2) { const LinuxProcess *p1, *p2; const Settings *settings = ((const Process*)v1)->settings; @@ -401,3 +391,13 @@ long LinuxProcess_compare(const void* v1, const void* v2) { bool Process_isThread(const Process* this) { return (Process_isUserlandThread(this) || Process_isKernelThread(this)); } + +const ProcessClass LinuxProcess_class = { + .super = { + .extends = Class(Process), + .display = Process_display, + .delete = Process_delete, + .compare = LinuxProcess_compare + }, + .writeField = LinuxProcess_writeField +}; diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 1285529a9..856b7bee4 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -181,10 +181,6 @@ bool LinuxProcess_setIOPriority(Process* this, Arg ioprio); void LinuxProcess_printDelay(float delay_percent, char* buffer, int n); #endif -void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField field); - -long LinuxProcess_compare(const void* v1, const void* v2); - bool Process_isThread(const Process* this); #endif From ad72b747fa526b663c61d5cf4efc7c66e629c500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 15 Nov 2020 20:07:24 +0100 Subject: [PATCH 401/411] Drop hideThreads Setting It is only used to read process directories on RedHat beginning with a dot. Unconditionally accept directories with a starting dot. --- Action.c | 1 - Settings.c | 4 ---- Settings.h | 1 - linux/LinuxProcessList.c | 2 +- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Action.c b/Action.c index e226bc535..11e870093 100644 --- a/Action.c +++ b/Action.c @@ -212,7 +212,6 @@ static Htop_Reaction actionToggleKernelThreads(State* st) { static Htop_Reaction actionToggleUserlandThreads(State* st) { st->settings->hideUserlandThreads = !st->settings->hideUserlandThreads; - st->settings->hideThreads = st->settings->hideUserlandThreads; return HTOP_RECALCULATE | HTOP_SAVE_SETTINGS; } diff --git a/Settings.c b/Settings.c index 1ecee5694..ea32ebbe1 100644 --- a/Settings.c +++ b/Settings.c @@ -141,8 +141,6 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo this->direction = atoi(option[1]); } else if (String_eq(option[0], "tree_view")) { this->treeView = atoi(option[1]); - } else if (String_eq(option[0], "hide_threads")) { - this->hideThreads = atoi(option[1]); } else if (String_eq(option[0], "hide_kernel_threads")) { this->hideKernelThreads = atoi(option[1]); } else if (String_eq(option[0], "hide_userland_threads")) { @@ -259,7 +257,6 @@ bool Settings_write(Settings* this) { // This "-1" is for compatibility with the older enum format. fprintf(fd, "sort_key=%d\n", (int) this->sortKey - 1); fprintf(fd, "sort_direction=%d\n", (int) this->direction); - fprintf(fd, "hide_threads=%d\n", (int) this->hideThreads); fprintf(fd, "hide_kernel_threads=%d\n", (int) this->hideKernelThreads); fprintf(fd, "hide_userland_threads=%d\n", (int) this->hideUserlandThreads); fprintf(fd, "shadow_other_users=%d\n", (int) this->shadowOtherUsers); @@ -295,7 +292,6 @@ Settings* Settings_new(int initialCpuCount) { this->sortKey = PERCENT_CPU; this->direction = 1; - this->hideThreads = false; this->shadowOtherUsers = false; this->showThreadNames = false; this->hideKernelThreads = false; diff --git a/Settings.h b/Settings.h index bbd40e162..3d8e05813 100644 --- a/Settings.h +++ b/Settings.h @@ -40,7 +40,6 @@ typedef struct Settings_ { bool showCPUFrequency; bool treeView; bool showProgramPath; - bool hideThreads; bool shadowOtherUsers; bool showThreadNames; bool hideKernelThreads; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index b0045509c..42560ca6a 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -985,7 +985,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* // The RedHat kernel hides threads with a dot. // I believe this is non-standard. - if ((!settings->hideThreads) && name[0] == '.') { + if (name[0] == '.') { name++; } From f856fe6463ee904f962c8a92e353bbe956ca78c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 15 Nov 2020 20:09:50 +0100 Subject: [PATCH 402/411] Early skip non-directories when searching for process information --- linux/LinuxProcessList.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 42560ca6a..8dd1b83e5 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -389,7 +389,7 @@ static bool LinuxProcessList_readStatFile(Process* process, const char* dirname, } -static bool LinuxProcessList_statProcessDir(Process* process, const char* dirname, char* name) { +static bool LinuxProcessList_statProcessDir(Process* process, const char* dirname, const char* name) { char filename[MAX_NAME + 1]; filename[MAX_NAME] = '\0'; @@ -404,7 +404,7 @@ static bool LinuxProcessList_statProcessDir(Process* process, const char* dirnam #ifdef HAVE_TASKSTATS -static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirname, char* name, unsigned long long now) { +static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirname, const char* name, unsigned long long now) { char filename[MAX_NAME + 1]; filename[MAX_NAME] = '\0'; @@ -966,7 +966,7 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* dirname, Process* parent, double period, struct timeval tv) { ProcessList* pl = (ProcessList*) this; DIR* dir; - struct dirent* entry; + const struct dirent* entry; const Settings* settings = pl->settings; #ifdef HAVE_TASKSTATS @@ -981,7 +981,12 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; while ((entry = readdir(dir)) != NULL) { - char* name = entry->d_name; + const char* name = entry->d_name; + + // Ignore all non-directories + if (entry->d_type != DT_DIR && entry->d_type != DT_UNKNOWN) { + continue; + } // The RedHat kernel hides threads with a dot. // I believe this is non-standard. From 0411fdbcef51c1b2a39d9eeaa140a5b7c00bd3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 15 Nov 2020 20:12:38 +0100 Subject: [PATCH 403/411] Use spaceship comparison for TTYs --- linux/LinuxProcessList.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 8dd1b83e5..63b77326c 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -77,7 +77,12 @@ static ssize_t xread(int fd, void* buf, size_t count) { static int sortTtyDrivers(const void* va, const void* vb) { const TtyDriver* a = (const TtyDriver*) va; const TtyDriver* b = (const TtyDriver*) vb; - return (a->major == b->major) ? ((int)a->minorFrom - (int)b->minorFrom) : ((int)a->major - (int)b->major); + + int r = SPACESHIP_NUMBER(a->major, b->major); + if (r) + return r; + + return SPACESHIP_NUMBER(a->minorFrom, b->minorFrom); } static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { From 8f2d129dcebe1e6aad1eb2d7147204d056e41619 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 16 Nov 2020 12:17:28 +0100 Subject: [PATCH 404/411] Apply patch from BenBE as per https://github.com/htop-dev/htop/pull/241#issuecomment-720081138 --- ProcessList.c | 18 +++++++----------- ProcessList.h | 1 - 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/ProcessList.c b/ProcessList.c index a88c1e7b5..8c3f6403e 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -29,7 +29,6 @@ ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, Users this->cpuCount = 0; this->scanTs = 0; - this->firstScanTs = 0; #ifdef HAVE_LIBHWLOC this->topologyOk = false; @@ -91,12 +90,8 @@ void ProcessList_add(ProcessList* this, Process* p) { assert(Hashtable_get(this->processTable, p->pid) == NULL); p->processList = this; - if (this->scanTs == this->firstScanTs) { - // prevent highlighting processes found in first scan - p->seenTs = this->firstScanTs - this->settings->highlightDelaySecs - 1; - } else { - p->seenTs = this->scanTs; - } + // highlighting processes found in first scan by first scan marked "far in the past" + p->seenTs = this->scanTs; Vector_add(this->processes, p); Hashtable_put(this->processTable, p->pid, p); @@ -339,10 +334,11 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { // set scanTs - if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) { - if (this->firstScanTs == 0) { - this->firstScanTs = now.tv_sec; - } + static bool firstScanDone = false; + if (!firstScanDone) { + this->scanTs = 0; + firstScanDone = true; + } else if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) { this->scanTs = now.tv_sec; } diff --git a/ProcessList.h b/ProcessList.h index db288104b..a4b0cd6fa 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -71,7 +71,6 @@ typedef struct ProcessList_ { int cpuCount; time_t scanTs; - time_t firstScanTs; } ProcessList; ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); From 19868a3c29e2ad000e87650ea33c40a92ec10c2f Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 16 Nov 2020 13:18:29 +0100 Subject: [PATCH 405/411] Fix whitespace before comma in the new color definitions --- CRT.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CRT.c b/CRT.c index 487f8b0c8..96bc15662 100644 --- a/CRT.c +++ b/CRT.c @@ -112,8 +112,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), - [PROCESS_NEW] = ColorPair(Black,Green), - [PROCESS_TOMB] = ColorPair(Black,Red), + [PROCESS_NEW] = ColorPair(Black, Green), + [PROCESS_TOMB] = ColorPair(Black, Red), [PROCESS_THREAD] = ColorPair(Green, Black), [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Black), [BAR_BORDER] = A_BOLD, @@ -274,8 +274,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, White), [PROCESS_HIGH_PRIORITY] = ColorPair(Red, White), [PROCESS_LOW_PRIORITY] = ColorPair(Green, White), - [PROCESS_NEW] = ColorPair(White,Green), - [PROCESS_TOMB] = ColorPair(White,Red), + [PROCESS_NEW] = ColorPair(White, Green), + [PROCESS_TOMB] = ColorPair(White, Red), [PROCESS_THREAD] = ColorPair(Blue, White), [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, White), [BAR_BORDER] = ColorPair(Blue, White), @@ -355,8 +355,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), - [PROCESS_NEW] = ColorPair(Black,Green), - [PROCESS_TOMB] = ColorPair(Black,Red), + [PROCESS_NEW] = ColorPair(Black, Green), + [PROCESS_TOMB] = ColorPair(Black, Red), [PROCESS_THREAD] = ColorPair(Blue, Black), [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black), [BAR_BORDER] = ColorPair(Blue, Black), @@ -436,8 +436,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Blue), [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Blue), [PROCESS_LOW_PRIORITY] = ColorPair(Green, Blue), - [PROCESS_NEW] = ColorPair(Blue,Green), - [PROCESS_TOMB] = ColorPair(Blue,Red), + [PROCESS_NEW] = ColorPair(Blue, Green), + [PROCESS_TOMB] = ColorPair(Blue, Red), [PROCESS_THREAD] = ColorPair(Green, Blue), [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Blue), [BAR_BORDER] = A_BOLD | ColorPair(Yellow, Blue), @@ -519,8 +519,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), - [PROCESS_NEW] = ColorPair(Black,Green), - [PROCESS_TOMB] = ColorPair(Black,Red), + [PROCESS_NEW] = ColorPair(Black, Green), + [PROCESS_TOMB] = ColorPair(Black, Red), [BAR_BORDER] = A_BOLD | ColorPair(Green, Black), [BAR_SHADOW] = ColorPair(Cyan, Black), [SWAP] = ColorPair(Red, Black), From 309f1d7282ec8efa4ff6b24a001a4908f5fd28d0 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 16 Nov 2020 13:29:37 +0100 Subject: [PATCH 406/411] hwloc = (portable) HardWare LOCality, not related to lock --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6e76240dc..8bdd67e3d 100644 --- a/configure.ac +++ b/configure.ac @@ -387,6 +387,6 @@ AC_MSG_RESULT([ (Linux) affinity: $enable_linux_affinity (Linux) delay accounting: $enable_delayacct unicode: $enable_unicode - hwlock: $enable_hwloc + hwloc: $enable_hwloc setuid: $enable_setuid ]) From a8a723ffe919cc3e8e3ef7ad6c07adb0ee0f715b Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 16 Nov 2020 17:01:51 +0100 Subject: [PATCH 407/411] Add debug state to the configure report (thanks @benbe for the idea) --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 8bdd67e3d..f774c8efb 100644 --- a/configure.ac +++ b/configure.ac @@ -389,4 +389,5 @@ AC_MSG_RESULT([ unicode: $enable_unicode hwloc: $enable_hwloc setuid: $enable_setuid + debug: $enable_debug ]) From 15eab2012d2100e1ddd20c186db23a8172b5858d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 30 Oct 2020 17:02:20 +0100 Subject: [PATCH 408/411] Add process column for normalized CPU usage Shows the process CPU usage divided by the number of CPU cores --- Process.c | 18 ++++++++++++------ Process.h | 1 + dragonflybsd/DragonFlyBSDProcess.c | 1 + freebsd/FreeBSDProcess.c | 1 + linux/LinuxProcess.c | 1 + openbsd/OpenBSDProcess.c | 6 ++++++ solaris/SolarisProcess.c | 1 + 7 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Process.c b/Process.c index 28cc03070..b24e3a2f5 100644 --- a/Process.c +++ b/Process.c @@ -257,13 +257,18 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field bool coloring = this->settings->highlightMegabytes; switch (field) { - case PERCENT_CPU: { - if (this->percent_cpu > 999.9) { - xSnprintf(buffer, n, "%4u ", (unsigned int)this->percent_cpu); - } else if (this->percent_cpu > 99.9) { - xSnprintf(buffer, n, "%3u. ", (unsigned int)this->percent_cpu); + case PERCENT_CPU: + case PERCENT_NORM_CPU: { + float cpuPercentage = this->percent_cpu; + if (field == PERCENT_NORM_CPU) { + cpuPercentage /= this->processList->cpuCount; + } + if (cpuPercentage > 999.9) { + xSnprintf(buffer, n, "%4u ", (unsigned int)cpuPercentage); + } else if (cpuPercentage > 99.9) { + xSnprintf(buffer, n, "%3u. ", (unsigned int)cpuPercentage); } else { - xSnprintf(buffer, n, "%4.1f ", this->percent_cpu); + xSnprintf(buffer, n, "%4.1f ", cpuPercentage); } break; } @@ -492,6 +497,7 @@ long Process_compare(const void* v1, const void* v2) { switch (settings->sortKey) { case PERCENT_CPU: + case PERCENT_NORM_CPU: return SPACESHIP_NUMBER(p2->percent_cpu, p1->percent_cpu); case PERCENT_MEM: return SPACESHIP_NUMBER(p2->m_resident, p1->m_resident); diff --git a/Process.h b/Process.h index c75ee501d..631eba74c 100644 --- a/Process.h +++ b/Process.h @@ -48,6 +48,7 @@ typedef enum ProcessFields { TIME = 50, NLWP = 51, TGID = 52, + PERCENT_NORM_CPU = 53, } ProcessField; typedef struct ProcessPidColumn_ { diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 55e4fbac1..4130e799d 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -48,6 +48,7 @@ ProcessFieldData Process_fields[] = { [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, + [PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, }, diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 695594e8b..57e64118c 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -40,6 +40,7 @@ ProcessFieldData Process_fields[] = { [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, + [PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, }, diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 2fec52f1d..5868ea29d 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -73,6 +73,7 @@ ProcessFieldData Process_fields[] = { [M_DT] = { .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process (unused since Linux 2.6; always 0)", .flags = 0, }, [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, + [PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, }, diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 1013d3b43..de823ce4d 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -142,6 +142,12 @@ ProcessFieldData Process_fields[] = { .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, + [PERCENT_NORM_CPU] = { + .name = "PERCENT_NORM_CPU", + .title = "NCPU%", + .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", + .flags = 0, + }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index 7d833fe9f..c11c6de8a 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -48,6 +48,7 @@ ProcessFieldData Process_fields[] = { [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, + [PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, }, From 7914ec201ef19fa0c0caed99dc150a953eb9bc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 21 Oct 2020 21:25:59 +0200 Subject: [PATCH 409/411] Hashtable update - use consistent type for key by introducing a new typedef - use unsigned types for sizes - name parameters in foreach function typedef --- Action.c | 2 +- Hashtable.c | 26 +++++++++++++------------- Hashtable.h | 24 +++++++++++++----------- Vector.c | 6 +++--- Vector.h | 2 +- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Action.c b/Action.c index 11e870093..822c9174b 100644 --- a/Action.c +++ b/Action.c @@ -100,7 +100,7 @@ static bool changePriority(MainPanel* panel, int delta) { return anyTagged; } -static void addUserToVector(int key, void* userCast, void* panelCast) { +static void addUserToVector(hkey_t key, void* userCast, void* panelCast) { const char* user = userCast; Panel* panel = panelCast; Panel_add(panel, (Object*) ListItem_new(user, key)); diff --git a/Hashtable.c b/Hashtable.c index 92337822f..606dfd603 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -14,9 +14,9 @@ in the source distribution for its full text. #ifndef NDEBUG -static bool Hashtable_isConsistent(Hashtable* this) { - int items = 0; - for (int i = 0; i < this->size; i++) { +static bool Hashtable_isConsistent(const Hashtable* this) { + unsigned int items = 0; + for (unsigned int i = 0; i < this->size; i++) { HashtableItem* bucket = this->buckets[i]; while (bucket) { items++; @@ -26,9 +26,9 @@ static bool Hashtable_isConsistent(Hashtable* this) { return items == this->items; } -int Hashtable_count(Hashtable* this) { - int items = 0; - for (int i = 0; i < this->size; i++) { +unsigned int Hashtable_count(const Hashtable* this) { + unsigned int items = 0; + for (unsigned int i = 0; i < this->size; i++) { HashtableItem* bucket = this->buckets[i]; while (bucket) { items++; @@ -41,7 +41,7 @@ int Hashtable_count(Hashtable* this) { #endif /* NDEBUG */ -static HashtableItem* HashtableItem_new(unsigned int key, void* value) { +static HashtableItem* HashtableItem_new(hkey_t key, void* value) { HashtableItem* this; this = xMalloc(sizeof(HashtableItem)); @@ -51,7 +51,7 @@ static HashtableItem* HashtableItem_new(unsigned int key, void* value) { return this; } -Hashtable* Hashtable_new(int size, bool owner) { +Hashtable* Hashtable_new(unsigned int size, bool owner) { Hashtable* this; this = xMalloc(sizeof(Hashtable)); @@ -65,7 +65,7 @@ Hashtable* Hashtable_new(int size, bool owner) { void Hashtable_delete(Hashtable* this) { assert(Hashtable_isConsistent(this)); - for (int i = 0; i < this->size; i++) { + for (unsigned int i = 0; i < this->size; i++) { HashtableItem* walk = this->buckets[i]; while (walk != NULL) { if (this->owner) @@ -80,7 +80,7 @@ void Hashtable_delete(Hashtable* this) { free(this); } -void Hashtable_put(Hashtable* this, unsigned int key, void* value) { +void Hashtable_put(Hashtable* this, hkey_t key, void* value) { unsigned int index = key % this->size; HashtableItem** bucketPtr = &(this->buckets[index]); while (true) @@ -101,7 +101,7 @@ void Hashtable_put(Hashtable* this, unsigned int key, void* value) { assert(Hashtable_isConsistent(this)); } -void* Hashtable_remove(Hashtable* this, unsigned int key) { +void* Hashtable_remove(Hashtable* this, hkey_t key) { unsigned int index = key % this->size; assert(Hashtable_isConsistent(this)); @@ -128,7 +128,7 @@ void* Hashtable_remove(Hashtable* this, unsigned int key) { return NULL; } -void* Hashtable_get(Hashtable* this, unsigned int key) { +void* Hashtable_get(Hashtable* this, hkey_t key) { unsigned int index = key % this->size; HashtableItem* bucketPtr = this->buckets[index]; while (true) { @@ -146,7 +146,7 @@ void* Hashtable_get(Hashtable* this, unsigned int key) { void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData) { assert(Hashtable_isConsistent(this)); - for (int i = 0; i < this->size; i++) { + for (unsigned int i = 0; i < this->size; i++) { HashtableItem* walk = this->buckets[i]; while (walk != NULL) { f(walk->key, walk->value, userData); diff --git a/Hashtable.h b/Hashtable.h index dcdc89fe1..15af9e0d4 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -10,36 +10,38 @@ in the source distribution for its full text. #include -typedef void(*Hashtable_PairFunction)(int, void*, void*); +typedef unsigned int hkey_t; -typedef struct HashtableItem { - unsigned int key; +typedef void(*Hashtable_PairFunction)(hkey_t key, void* value, void* userdata); + +typedef struct HashtableItem_ { + hkey_t key; void* value; - struct HashtableItem* next; + struct HashtableItem_* next; } HashtableItem; typedef struct Hashtable_ { - int size; + unsigned int size; HashtableItem** buckets; - int items; + unsigned int items; bool owner; } Hashtable; #ifndef NDEBUG -int Hashtable_count(Hashtable* this); +unsigned int Hashtable_count(const Hashtable* this); #endif /* NDEBUG */ -Hashtable* Hashtable_new(int size, bool owner); +Hashtable* Hashtable_new(unsigned int size, bool owner); void Hashtable_delete(Hashtable* this); -void Hashtable_put(Hashtable* this, unsigned int key, void* value); +void Hashtable_put(Hashtable* this, hkey_t key, void* value); -void* Hashtable_remove(Hashtable* this, unsigned int key); +void* Hashtable_remove(Hashtable* this, hkey_t key); -void* Hashtable_get(Hashtable* this, unsigned int key); +void* Hashtable_get(Hashtable* this, hkey_t key); void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData); diff --git a/Vector.c b/Vector.c index 09d1612e2..721ebdd35 100644 --- a/Vector.c +++ b/Vector.c @@ -60,14 +60,14 @@ static bool Vector_isConsistent(const Vector* this) { } } -int Vector_count(const Vector* this) { - int items = 0; +unsigned int Vector_count(const Vector* this) { + unsigned int items = 0; for (int i = 0; i < this->items; i++) { if (this->array[i]) { items++; } } - assert(items == this->items); + assert(items == (unsigned int)this->items); return items; } diff --git a/Vector.h b/Vector.h index 706881527..ec354b168 100644 --- a/Vector.h +++ b/Vector.h @@ -54,7 +54,7 @@ void Vector_set(Vector* this, int idx, void* data_); Object* Vector_get(Vector* this, int idx); int Vector_size(const Vector* this); -int Vector_count(const Vector* this); +unsigned int Vector_count(const Vector* this); #else /* NDEBUG */ From 307c34b028d353154aa268eceb38e0331c8275cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 22 Oct 2020 15:43:26 +0200 Subject: [PATCH 410/411] Hashtable: use dynamic growth and use primes as size Dynamically increase the hashmap size to not exceed the load factor and avoid too long chains. Switch from Separate Chaining to Robin Hood linear probing to improve cache locality. Use primes as size to further avoid collisions. E.g. on a standard kde system the number of entries in the ProcessTable might be around 650. --- Hashtable.c | 274 ++++++++++++++++++++++++++++++++++++++------------- Hashtable.h | 6 +- UsersTable.c | 2 +- 3 files changed, 209 insertions(+), 73 deletions(-) diff --git a/Hashtable.c b/Hashtable.c index 606dfd603..cdfb4ec3b 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -8,32 +8,55 @@ in the source distribution for its full text. #include "Hashtable.h" #include "XUtils.h" -#include #include +#include +#include #ifndef NDEBUG +static void Hashtable_dump(const Hashtable* this) { + fprintf(stderr, "Hashtable %p: size=%u items=%u owner=%s\n", + (const void*)this, + this->size, + this->items, + this->owner ? "yes" : "no"); + + unsigned int items = 0; + for (unsigned int i = 0; i < this->size; i++) { + fprintf(stderr, " item %5u: key = %5u probe = %2u value = %p\n", + i, + this->buckets[i].key, + this->buckets[i].probe, + this->buckets[i].value ? (const void*)this->buckets[i].value : "(nil)"); + + if (this->buckets[i].value) + items++; + } + + fprintf(stderr, "Hashtable %p: items=%u counted=%u\n", + (const void*)this, + this->items, + items); +} + static bool Hashtable_isConsistent(const Hashtable* this) { unsigned int items = 0; for (unsigned int i = 0; i < this->size; i++) { - HashtableItem* bucket = this->buckets[i]; - while (bucket) { + if (this->buckets[i].value) items++; - bucket = bucket->next; - } } - return items == this->items; + bool res = items == this->items; + if (!res) + Hashtable_dump(this); + return res; } unsigned int Hashtable_count(const Hashtable* this) { unsigned int items = 0; for (unsigned int i = 0; i < this->size; i++) { - HashtableItem* bucket = this->buckets[i]; - while (bucket) { + if (this->buckets[i].value) items++; - bucket = bucket->next; - } } assert(items == this->items); return items; @@ -41,14 +64,25 @@ unsigned int Hashtable_count(const Hashtable* this) { #endif /* NDEBUG */ -static HashtableItem* HashtableItem_new(hkey_t key, void* value) { - HashtableItem* this; +/* https://oeis.org/A014234 */ +static const uint64_t OEISprimes[] = { + 2, 3, 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, + 16381, 32749, 65521, 131071, 262139, 524287, 1048573, + 2097143, 4194301, 8388593, 16777213, 33554393, + 67108859, 134217689, 268435399, 536870909, 1073741789, + 2147483647, 4294967291, 8589934583, 17179869143, + 34359738337, 68719476731, 137438953447 +}; - this = xMalloc(sizeof(HashtableItem)); - this->key = key; - this->value = value; - this->next = NULL; - return this; +static uint64_t nextPrime(unsigned int n) { + assert(n <= OEISprimes[ARRAYSIZE(OEISprimes) - 1]); + + for (unsigned int i = 0; i < ARRAYSIZE(OEISprimes); i++) { + if (n <= OEISprimes[i]) + return OEISprimes[i]; + } + + return OEISprimes[ARRAYSIZE(OEISprimes) - 1]; } Hashtable* Hashtable_new(unsigned int size, bool owner) { @@ -56,102 +90,202 @@ Hashtable* Hashtable_new(unsigned int size, bool owner) { this = xMalloc(sizeof(Hashtable)); this->items = 0; - this->size = size; - this->buckets = (HashtableItem**) xCalloc(size, sizeof(HashtableItem*)); + this->size = size ? nextPrime(size) : 13; + this->buckets = (HashtableItem*) xCalloc(this->size, sizeof(HashtableItem)); this->owner = owner; assert(Hashtable_isConsistent(this)); return this; } void Hashtable_delete(Hashtable* this) { + assert(Hashtable_isConsistent(this)); - for (unsigned int i = 0; i < this->size; i++) { - HashtableItem* walk = this->buckets[i]; - while (walk != NULL) { - if (this->owner) - free(walk->value); - - HashtableItem* savedWalk = walk; - walk = savedWalk->next; - free(savedWalk); - } + + if (this->owner) { + for (unsigned int i = 0; i < this->size; i++) + free(this->buckets[i].value); } + free(this->buckets); free(this); } -void Hashtable_put(Hashtable* this, hkey_t key, void* value) { +static void insert(Hashtable* this, hkey_t key, void* value) { unsigned int index = key % this->size; - HashtableItem** bucketPtr = &(this->buckets[index]); - while (true) - if (*bucketPtr == NULL) { - *bucketPtr = HashtableItem_new(key, value); + unsigned int probe = 0; +#ifndef NDEBUG + unsigned int origIndex = index; +#endif + + for (;;) { + if (!this->buckets[index].value) { this->items++; - break; - } else if ((*bucketPtr)->key == key) { - if (this->owner && (*bucketPtr)->value != value) - free((*bucketPtr)->value); + this->buckets[index].key = key; + this->buckets[index].probe = probe; + this->buckets[index].value = value; + return; + } - (*bucketPtr)->value = value; - break; - } else { - bucketPtr = &((*bucketPtr)->next); + if (this->buckets[index].key == key) { + if (this->owner && this->buckets[index].value != value) + free(this->buckets[index].value); + this->buckets[index].value = value; + return; } + /* Robin Hood swap */ + if (probe > this->buckets[index].probe) { + HashtableItem tmp = this->buckets[index]; + + this->buckets[index].key = key; + this->buckets[index].probe = probe; + this->buckets[index].value = value; + + key = tmp.key; + probe = tmp.probe; + value = tmp.value; + } + + index = (index + 1) % this->size; + probe++; + + assert(index != origIndex); + } +} + +void Hashtable_setSize(Hashtable* this, unsigned int size) { + + assert(Hashtable_isConsistent(this)); + + if (size <= this->items) + return; + + HashtableItem* oldBuckets = this->buckets; + unsigned int oldSize = this->size; + + this->size = nextPrime(size); + this->buckets = (HashtableItem*) xCalloc(this->size, sizeof(HashtableItem)); + this->items = 0; + + /* rehash */ + for (unsigned int i = 0; i < oldSize; i++) { + if (!oldBuckets[i].value) + continue; + + insert(this, oldBuckets[i].key, oldBuckets[i].value); + } + + free(oldBuckets); + assert(Hashtable_isConsistent(this)); } +void Hashtable_put(Hashtable* this, hkey_t key, void* value) { + + assert(Hashtable_isConsistent(this)); + assert(this->size > 0); + assert(value); + + /* grow on load-factor > 0.7 */ + if (10 * this->items > 7 * this->size) + Hashtable_setSize(this, 2 * this->size); + + insert(this, key, value); + + assert(Hashtable_isConsistent(this)); + assert(Hashtable_get(this, key) != NULL); + assert(this->size > this->items); +} + void* Hashtable_remove(Hashtable* this, hkey_t key) { unsigned int index = key % this->size; + unsigned int probe = 0; +#ifndef NDEBUG + unsigned int origIndex = index; +#endif assert(Hashtable_isConsistent(this)); - HashtableItem** bucket; - for (bucket = &(this->buckets[index]); *bucket; bucket = &((*bucket)->next) ) { - if ((*bucket)->key == key) { - void* value = (*bucket)->value; - HashtableItem* next = (*bucket)->next; - free(*bucket); - (*bucket) = next; - this->items--; + void* res = NULL; + + while (this->buckets[index].value) { + if (this->buckets[index].key == key) { if (this->owner) { - free(value); - assert(Hashtable_isConsistent(this)); - return NULL; + free(this->buckets[index].value); } else { - assert(Hashtable_isConsistent(this)); - return value; + res = this->buckets[index].value; } + + unsigned int next = (index + 1) % this->size; + + while (this->buckets[next].value && this->buckets[next].probe > 0) { + this->buckets[index] = this->buckets[next]; + this->buckets[index].probe -= 1; + + index = next; + next = (index + 1) % this->size; + } + + /* set empty after backward shifting */ + this->buckets[index].value = NULL; + this->items--; + + break; } + + if (this->buckets[index].probe < probe) + break; + + index = (index + 1) % this->size; + probe++; + + assert(index != origIndex); } + assert(Hashtable_isConsistent(this)); - return NULL; + assert(Hashtable_get(this, key) == NULL); + + /* shrink on load-factor < 0.125 */ + if (8 * this->items < this->size) + Hashtable_setSize(this, this->size / 2); + + return res; } void* Hashtable_get(Hashtable* this, hkey_t key) { unsigned int index = key % this->size; - HashtableItem* bucketPtr = this->buckets[index]; - while (true) { - if (bucketPtr == NULL) { - assert(Hashtable_isConsistent(this)); - return NULL; - } else if (bucketPtr->key == key) { - assert(Hashtable_isConsistent(this)); - return bucketPtr->value; - } else { - bucketPtr = bucketPtr->next; + unsigned int probe = 0; + void* res = NULL; +#ifndef NDEBUG + unsigned int origIndex = index; +#endif + + assert(Hashtable_isConsistent(this)); + + while (this->buckets[index].value) { + if (this->buckets[index].key == key) { + res = this->buckets[index].value; + break; } + + if (this->buckets[index].probe < probe) + break; + + index = (index + 1) != this->size ? (index + 1) : 0; + probe++; + + assert(index != origIndex); } + + return res; } void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData) { assert(Hashtable_isConsistent(this)); for (unsigned int i = 0; i < this->size; i++) { - HashtableItem* walk = this->buckets[i]; - while (walk != NULL) { + HashtableItem* walk = &this->buckets[i]; + if (walk->value) f(walk->key, walk->value, userData); - walk = walk->next; - } } assert(Hashtable_isConsistent(this)); } diff --git a/Hashtable.h b/Hashtable.h index 15af9e0d4..f7d1aae24 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -16,13 +16,13 @@ typedef void(*Hashtable_PairFunction)(hkey_t key, void* value, void* userdata); typedef struct HashtableItem_ { hkey_t key; + unsigned int probe; void* value; - struct HashtableItem_* next; } HashtableItem; typedef struct Hashtable_ { unsigned int size; - HashtableItem** buckets; + HashtableItem* buckets; unsigned int items; bool owner; } Hashtable; @@ -37,6 +37,8 @@ Hashtable* Hashtable_new(unsigned int size, bool owner); void Hashtable_delete(Hashtable* this); +void Hashtable_setSize(Hashtable* this, unsigned int size); + void Hashtable_put(Hashtable* this, hkey_t key, void* value); void* Hashtable_remove(Hashtable* this, hkey_t key); diff --git a/UsersTable.c b/UsersTable.c index 25e448838..fdbfd68fb 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -20,7 +20,7 @@ in the source distribution for its full text. UsersTable* UsersTable_new() { UsersTable* this; this = xMalloc(sizeof(UsersTable)); - this->users = Hashtable_new(20, true); + this->users = Hashtable_new(10, true); return this; } From 351f93e182270b9e7c12d959ee3a0fa1e17c90c1 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 17 Nov 2020 18:00:38 +1100 Subject: [PATCH 411/411] Merge individual Battery.[ch] files into Platform.[ch] Consistent with everything else involving platform-specific calls from core htop code. --- BatteryMeter.c | 4 +- Makefile.am | 26 +-- darwin/Battery.c | 73 -------- darwin/Battery.h | 8 - darwin/Platform.c | 68 ++++++++ darwin/Platform.h | 2 + dragonflybsd/Battery.c | 30 ---- dragonflybsd/Battery.h | 15 -- dragonflybsd/Platform.c | 16 ++ dragonflybsd/Platform.h | 2 + freebsd/Battery.c | 29 ---- freebsd/Battery.h | 14 -- freebsd/Platform.c | 16 ++ freebsd/Platform.h | 2 + linux/Battery.c | 366 ---------------------------------------- linux/Battery.h | 17 -- linux/Platform.c | 323 +++++++++++++++++++++++++++++++++++ linux/Platform.h | 3 + openbsd/Battery.c | 74 -------- openbsd/Battery.h | 15 -- openbsd/Platform.c | 59 +++++++ solaris/Battery.c | 8 - solaris/Battery.h | 8 - solaris/Platform.c | 5 + solaris/Platform.h | 2 + unsupported/Battery.c | 8 - unsupported/Battery.h | 8 - unsupported/Platform.c | 5 + unsupported/Platform.h | 2 + 29 files changed, 515 insertions(+), 693 deletions(-) delete mode 100644 darwin/Battery.c delete mode 100644 darwin/Battery.h delete mode 100644 dragonflybsd/Battery.c delete mode 100644 dragonflybsd/Battery.h delete mode 100644 freebsd/Battery.c delete mode 100644 freebsd/Battery.h delete mode 100644 linux/Battery.c delete mode 100644 linux/Battery.h delete mode 100644 openbsd/Battery.c delete mode 100644 openbsd/Battery.h delete mode 100644 solaris/Battery.c delete mode 100644 solaris/Battery.h delete mode 100644 unsupported/Battery.c delete mode 100644 unsupported/Battery.h diff --git a/BatteryMeter.c b/BatteryMeter.c index ac126cea7..cd8439c4c 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -11,7 +11,7 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). #include -#include "Battery.h" +#include "Platform.h" #include "CRT.h" #include "Object.h" #include "XUtils.h" @@ -25,7 +25,7 @@ static void BatteryMeter_updateValues(Meter* this, char* buffer, int len) { ACPresence isOnAC; double percent; - Battery_getData(&percent, &isOnAC); + Platform_getBattery(&percent, &isOnAC); if (isnan(percent)) { this->values[0] = NAN; diff --git a/Makefile.am b/Makefile.am index 41d8c9fb0..7b90dfd06 100644 --- a/Makefile.am +++ b/Makefile.am @@ -124,7 +124,6 @@ myhtopheaders = \ # ----- linux_platform_headers = \ - linux/Battery.h \ linux/IOPriority.h \ linux/IOPriorityPanel.h \ linux/LinuxProcess.h \ @@ -142,7 +141,6 @@ linux_platform_headers = \ if HTOP_LINUX AM_LDFLAGS += -rdynamic myhtopplatsources = \ - linux/Battery.c \ linux/IOPriorityPanel.c \ linux/LinuxProcess.c \ linux/LinuxProcessList.c \ @@ -165,7 +163,6 @@ freebsd_platform_headers = \ freebsd/Platform.h \ freebsd/FreeBSDProcessList.h \ freebsd/FreeBSDProcess.h \ - freebsd/Battery.h \ zfs/ZfsArcMeter.h \ zfs/ZfsCompressedArcMeter.h \ zfs/ZfsArcStats.h \ @@ -173,7 +170,7 @@ freebsd_platform_headers = \ if HTOP_FREEBSD myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ -freebsd/FreeBSDProcess.c freebsd/Battery.c \ +freebsd/FreeBSDProcess.c \ zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c myhtopplatheaders = $(freebsd_platform_headers) @@ -185,13 +182,12 @@ endif dragonflybsd_platform_headers = \ dragonflybsd/Platform.h \ dragonflybsd/DragonFlyBSDProcessList.h \ - dragonflybsd/DragonFlyBSDProcess.h \ - dragonflybsd/Battery.h + dragonflybsd/DragonFlyBSDProcess.h if HTOP_DRAGONFLYBSD AM_LDFLAGS += -lkvm -lkinfo myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \ -dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/Battery.c +dragonflybsd/DragonFlyBSDProcess.c myhtopplatheaders = $(dragonflybsd_platform_headers) endif @@ -202,12 +198,11 @@ endif openbsd_platform_headers = \ openbsd/Platform.h \ openbsd/OpenBSDProcessList.h \ - openbsd/OpenBSDProcess.h \ - openbsd/Battery.h + openbsd/OpenBSDProcess.h if HTOP_OPENBSD myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \ -openbsd/OpenBSDProcess.c openbsd/Battery.c +openbsd/OpenBSDProcess.c myhtopplatheaders = $(openbsd_platform_headers) endif @@ -219,7 +214,6 @@ darwin_platform_headers = \ darwin/Platform.h \ darwin/DarwinProcess.h \ darwin/DarwinProcessList.h \ - darwin/Battery.h \ zfs/ZfsArcMeter.h \ zfs/ZfsCompressedArcMeter.h \ zfs/ZfsArcStats.h \ @@ -228,7 +222,7 @@ darwin_platform_headers = \ if HTOP_DARWIN AM_LDFLAGS += -framework IOKit -framework CoreFoundation myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \ -darwin/DarwinProcessList.c darwin/Battery.c \ +darwin/DarwinProcessList.c zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c myhtopplatheaders = $(darwin_platform_headers) @@ -241,7 +235,6 @@ solaris_platform_headers = \ solaris/Platform.h \ solaris/SolarisProcess.h \ solaris/SolarisProcessList.h \ - solaris/Battery.h \ zfs/ZfsArcMeter.h \ zfs/ZfsCompressedArcMeter.h \ zfs/ZfsArcStats.h @@ -249,7 +242,6 @@ solaris_platform_headers = \ if HTOP_SOLARIS myhtopplatsources = solaris/Platform.c \ solaris/SolarisProcess.c solaris/SolarisProcessList.c \ -solaris/Battery.c \ zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c myhtopplatheaders = $(solaris_platform_headers) @@ -261,13 +253,11 @@ endif unsupported_platform_headers = \ unsupported/Platform.h \ unsupported/UnsupportedProcess.h \ - unsupported/UnsupportedProcessList.h \ - unsupported/Battery.h + unsupported/UnsupportedProcessList.h if HTOP_UNSUPPORTED myhtopplatsources = unsupported/Platform.c \ -unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \ -unsupported/Battery.c +unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c myhtopplatheaders = $(unsupported_platform_headers) endif diff --git a/darwin/Battery.c b/darwin/Battery.c deleted file mode 100644 index c89f5b30f..000000000 --- a/darwin/Battery.c +++ /dev/null @@ -1,73 +0,0 @@ -#include "Battery.h" - -#include - -#include -#include -#include -#include - -void Battery_getData(double* level, ACPresence* isOnAC) { - CFTypeRef power_sources = IOPSCopyPowerSourcesInfo(); - - *level = NAN; - *isOnAC = AC_ERROR; - - if (NULL == power_sources) { - return; - } - - CFArrayRef list = IOPSCopyPowerSourcesList(power_sources); - CFDictionaryRef battery = NULL; - int len; - - if (NULL == list) { - CFRelease(power_sources); - - return; - } - - len = CFArrayGetCount(list); - - /* Get the battery */ - for (int i = 0; i < len && battery == NULL; ++i) { - CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, - CFArrayGetValueAtIndex(list, i)); /* GET rule */ - CFStringRef type; - - if (NULL != candidate) { - type = (CFStringRef) CFDictionaryGetValue(candidate, - CFSTR(kIOPSTransportTypeKey)); /* GET rule */ - - if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { - CFRetain(candidate); - battery = candidate; - } - } - } - - if (NULL != battery) { - /* Determine the AC state */ - CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); - - *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0)) - ? AC_PRESENT - : AC_ABSENT; - - /* Get the percentage remaining */ - double current; - double max; - - CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)), - kCFNumberDoubleType, ¤t); - CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)), - kCFNumberDoubleType, &max); - - *level = (current * 100.0) / max; - - CFRelease(battery); - } - - CFRelease(list); - CFRelease(power_sources); -} diff --git a/darwin/Battery.h b/darwin/Battery.h deleted file mode 100644 index 74a27fc58..000000000 --- a/darwin/Battery.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef HEADER_Battery -#define HEADER_Battery - -#include "BatteryMeter.h" - -void Battery_getData(double* level, ACPresence* isOnAC); - -#endif diff --git a/darwin/Platform.c b/darwin/Platform.c index cd505b9df..9051de7c0 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -26,6 +26,10 @@ in the source distribution for its full text. #include #include +#include +#include +#include +#include ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; @@ -340,3 +344,67 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, *packetsTransmitted = 0; return false; } + +void Platform_getBattery(double* level, ACPresence* isOnAC) { + CFTypeRef power_sources = IOPSCopyPowerSourcesInfo(); + + *level = NAN; + *isOnAC = AC_ERROR; + + if (NULL == power_sources) + return; + + CFArrayRef list = IOPSCopyPowerSourcesList(power_sources); + CFDictionaryRef battery = NULL; + int len; + + if (NULL == list) { + CFRelease(power_sources); + + return; + } + + len = CFArrayGetCount(list); + + /* Get the battery */ + for (int i = 0; i < len && battery == NULL; ++i) { + CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, + CFArrayGetValueAtIndex(list, i)); /* GET rule */ + CFStringRef type; + + if (NULL != candidate) { + type = (CFStringRef) CFDictionaryGetValue(candidate, + CFSTR(kIOPSTransportTypeKey)); /* GET rule */ + + if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { + CFRetain(candidate); + battery = candidate; + } + } + } + + if (NULL != battery) { + /* Determine the AC state */ + CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); + + *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0)) + ? AC_PRESENT + : AC_ABSENT; + + /* Get the percentage remaining */ + double current; + double max; + + CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)), + kCFNumberDoubleType, ¤t); + CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)), + kCFNumberDoubleType, &max); + + *level = (current * 100.0) / max; + + CFRelease(battery); + } + + CFRelease(list); + CFRelease(power_sources); +} diff --git a/darwin/Platform.h b/darwin/Platform.h index f42b72092..40b7d7304 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -65,4 +65,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, unsigned long int* bytesTransmitted, unsigned long int* packetsTransmitted); +void Platform_getBattery(double *percent, ACPresence *isOnAC); + #endif diff --git a/dragonflybsd/Battery.c b/dragonflybsd/Battery.c deleted file mode 100644 index 1a690ee31..000000000 --- a/dragonflybsd/Battery.c +++ /dev/null @@ -1,30 +0,0 @@ -/* -htop - dragonflybsd/Battery.c -(C) 2015 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Battery.h" - -#include -#include - -void Battery_getData(double* level, ACPresence* isOnAC) { - int life; - size_t life_len = sizeof(life); - if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) { - *level = NAN; - } else { - *level = life; - } - - int acline; - size_t acline_len = sizeof(acline); - if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) { - *isOnAC = AC_ERROR; - } else { - *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; - } -} diff --git a/dragonflybsd/Battery.h b/dragonflybsd/Battery.h deleted file mode 100644 index eed0f630f..000000000 --- a/dragonflybsd/Battery.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef HEADER_Battery -#define HEADER_Battery -/* -htop - dragonflybsd/Battery.h -(C) 2015 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "BatteryMeter.h" - -void Battery_getData(double* level, ACPresence* isOnAC); - -#endif diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 36f4f806b..78d11fb0d 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -233,3 +233,19 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, *packetsTransmitted = 0; return false; } + +void Platform_getBattery(double* level, ACPresence* isOnAC) { + int life; + size_t life_len = sizeof(life); + if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) + *level = NAN; + else + *level = life; + + int acline; + size_t acline_len = sizeof(acline); + if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) + *isOnAC = AC_ERROR; + else + *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; +} diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 1da8811b6..267b8f37f 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -56,4 +56,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, unsigned long int* bytesTransmitted, unsigned long int* packetsTransmitted); +void Platform_getBattery(double* level, ACPresence* isOnAC); + #endif diff --git a/freebsd/Battery.c b/freebsd/Battery.c deleted file mode 100644 index 26b42da92..000000000 --- a/freebsd/Battery.c +++ /dev/null @@ -1,29 +0,0 @@ -/* -htop - freebsd/Battery.c -(C) 2015 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Battery.h" - -#include -#include - -void Battery_getData(double* level, ACPresence* isOnAC) { - int life; - size_t life_len = sizeof(life); - if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) { - *level = NAN; - } else { - *level = life; - } - - int acline; - size_t acline_len = sizeof(acline); - if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) { - *isOnAC = AC_ERROR; - } else { - *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; - } -} diff --git a/freebsd/Battery.h b/freebsd/Battery.h deleted file mode 100644 index 98adb6eef..000000000 --- a/freebsd/Battery.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef HEADER_Battery -#define HEADER_Battery -/* -htop - freebsd/Battery.h -(C) 2015 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "BatteryMeter.h" - -void Battery_getData(double* level, ACPresence* isOnAC); - -#endif diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 9fd2f4d02..9c53ba818 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -337,3 +337,19 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, *packetsTransmitted = packetsTransmittedSum; return true; } + +void Platform_getBattery(double* level, ACPresence* isOnAC) { + int life; + size_t life_len = sizeof(life); + if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) + *level = NAN; + else + *level = life; + + int acline; + size_t acline_len = sizeof(acline); + if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) + *isOnAC = AC_ERROR; + else + *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; +} diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 72e964aa1..5e3b29fb6 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -59,4 +59,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, unsigned long int* bytesTransmitted, unsigned long int* packetsTransmitted); +void Platform_getBattery(double* level, ACPresence* isOnAC); + #endif diff --git a/linux/Battery.c b/linux/Battery.c deleted file mode 100644 index ba7d153a8..000000000 --- a/linux/Battery.c +++ /dev/null @@ -1,366 +0,0 @@ -/* -htop - linux/Battery.c -(C) 2004-2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. - -Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). -*/ - -#include "config.h" // IWYU pragma: keep - -#include "Battery.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "BatteryMeter.h" -#include "Macros.h" -#include "XUtils.h" - - -#define SYS_POWERSUPPLY_DIR "/sys/class/power_supply" - -// ---------------------------------------- -// READ FROM /proc -// ---------------------------------------- - -// This implementation reading from from /proc/acpi is really inefficient, -// but I think this is on the way out so I did not rewrite it. -// The /sys implementation below does things the right way. - -static unsigned long int parseBatInfo(const char* fileName, const unsigned short int lineNum, const unsigned short int wordNum) { - const char batteryPath[] = PROCDIR "/acpi/battery/"; - DIR* batteryDir = opendir(batteryPath); - if (!batteryDir) - return 0; - - #define MAX_BATTERIES 64 - char* batteries[MAX_BATTERIES]; - unsigned int nBatteries = 0; - memset(batteries, 0, MAX_BATTERIES * sizeof(char*)); - - while (nBatteries < MAX_BATTERIES) { - struct dirent* dirEntry = readdir(batteryDir); - if (!dirEntry) - break; - - char* entryName = dirEntry->d_name; - if (!String_startsWith(entryName, "BAT")) - continue; - - batteries[nBatteries] = xStrdup(entryName); - nBatteries++; - } - closedir(batteryDir); - - unsigned long int total = 0; - for (unsigned int i = 0; i < nBatteries; i++) { - char infoPath[30]; - xSnprintf(infoPath, sizeof infoPath, "%s%s/%s", batteryPath, batteries[i], fileName); - - FILE* file = fopen(infoPath, "r"); - if (!file) { - break; - } - - char* line = NULL; - for (unsigned short int j = 0; j < lineNum; j++) { - free(line); - line = String_readLine(file); - if (!line) - break; - } - - fclose(file); - - if (!line) - break; - - char* foundNumStr = String_getToken(line, wordNum); - const unsigned long int foundNum = atoi(foundNumStr); - free(foundNumStr); - free(line); - - total += foundNum; - } - - for (unsigned int i = 0; i < nBatteries; i++) { - free(batteries[i]); - } - - return total; -} - -static ACPresence procAcpiCheck(void) { - ACPresence isOn = AC_ERROR; - const char* power_supplyPath = PROCDIR "/acpi/ac_adapter"; - DIR* dir = opendir(power_supplyPath); - if (!dir) { - return AC_ERROR; - } - - for (;;) { - struct dirent* dirEntry = readdir(dir); - if (!dirEntry) - break; - - const char* entryName = dirEntry->d_name; - - if (entryName[0] != 'A') - continue; - - char statePath[256]; - xSnprintf(statePath, sizeof(statePath), "%s/%s/state", power_supplyPath, entryName); - FILE* file = fopen(statePath, "r"); - if (!file) { - isOn = AC_ERROR; - continue; - } - char* line = String_readLine(file); - - fclose(file); - - if (!line) - continue; - - char* isOnline = String_getToken(line, 2); - free(line); - - if (String_eq(isOnline, "on-line")) { - isOn = AC_PRESENT; - } else { - isOn = AC_ABSENT; - } - free(isOnline); - if (isOn == AC_PRESENT) { - break; - } - } - - if (dir) { - closedir(dir); - } - - return isOn; -} - -static double Battery_getProcBatData(void) { - const unsigned long int totalFull = parseBatInfo("info", 3, 4); - if (totalFull == 0) - return NAN; - - const unsigned long int totalRemain = parseBatInfo("state", 5, 3); - if (totalRemain == 0) - return NAN; - - return totalRemain * 100.0 / (double) totalFull; -} - -static void Battery_getProcData(double* level, ACPresence* isOnAC) { - *isOnAC = procAcpiCheck(); - *level = AC_ERROR != *isOnAC ? Battery_getProcBatData() : NAN; -} - -// ---------------------------------------- -// READ FROM /sys -// ---------------------------------------- - -static inline ssize_t xread(int fd, void* buf, size_t count) { - // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. - size_t alreadyRead = 0; - for (;;) { - ssize_t res = read(fd, buf, count); - if (res == -1) { - if (errno == EINTR) - continue; - return -1; - } - - if (res > 0) { - buf = ((char*)buf) + res; - count -= res; - alreadyRead += res; - } - - if (count == 0 || res == 0) { - return alreadyRead; - } - } -} - -static void Battery_getSysData(double* level, ACPresence* isOnAC) { - - *level = NAN; - *isOnAC = AC_ERROR; - - DIR* dir = opendir(SYS_POWERSUPPLY_DIR); - if (!dir) - return; - - unsigned long int totalFull = 0; - unsigned long int totalRemain = 0; - - for (;;) { - struct dirent* dirEntry = readdir(dir); - if (!dirEntry) - break; - - const char* entryName = dirEntry->d_name; - char filePath[256]; - - xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); - int fd1 = open(filePath, O_RDONLY); - if (fd1 == -1) - continue; - - char type[8]; - ssize_t typelen = xread(fd1, type, 7); - close(fd1); - if (typelen < 1) - continue; - - if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') { - xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); - int fd2 = open(filePath, O_RDONLY); - if (fd2 == -1) { - closedir(dir); - return; - } - char buffer[1024]; - ssize_t buflen = xread(fd2, buffer, 1023); - close(fd2); - if (buflen < 1) { - closedir(dir); - return; - } - buffer[buflen] = '\0'; - char* buf = buffer; - char* line = NULL; - bool full = false; - bool now = false; - int fullSize = 0; - double capacityLevel = NAN; - - #define match(str,prefix) \ - (String_startsWith(str,prefix) ? (str) + strlen(prefix) : NULL) - - while ((line = strsep(&buf, "\n")) != NULL) { - const char* ps = match(line, "POWER_SUPPLY_"); - if (!ps) { - continue; - } - const char* capacity = match(ps, "CAPACITY="); - if (capacity) { - capacityLevel = atoi(capacity) / 100.0; - } - const char* energy = match(ps, "ENERGY_"); - if (!energy) { - energy = match(ps, "CHARGE_"); - } - if (!energy) { - continue; - } - const char* value = (!full) ? match(energy, "FULL=") : NULL; - if (value) { - fullSize = atoi(value); - totalFull += fullSize; - full = true; - if (now) { - break; - } - continue; - } - value = (!now) ? match(energy, "NOW=") : NULL; - if (value) { - totalRemain += atoi(value); - now = true; - if (full) { - break; - } - continue; - } - } - - #undef match - - if (!now && full && !isnan(capacityLevel)) { - totalRemain += (capacityLevel * fullSize); - } - } else if (entryName[0] == 'A') { - if (*isOnAC != AC_ERROR) { - continue; - } - - xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); - int fd3 = open(filePath, O_RDONLY); - if (fd3 == -1) { - closedir(dir); - return; - } - char buffer[2] = ""; - for (;;) { - ssize_t res = read(fd3, buffer, 1); - if (res == -1 && errno == EINTR) { - continue; - } - break; - } - close(fd3); - if (buffer[0] == '0') { - *isOnAC = AC_ABSENT; - } else if (buffer[0] == '1') { - *isOnAC = AC_PRESENT; - } - } - } - closedir(dir); - - *level = totalFull > 0 ? ((double) totalRemain * 100.0) / (double) totalFull : NAN; -} - -static enum { BAT_PROC, BAT_SYS, BAT_ERR } Battery_method = BAT_PROC; - -static time_t Battery_cacheTime = 0; -static double Battery_cacheLevel = NAN; -static ACPresence Battery_cacheIsOnAC = 0; - -void Battery_getData(double* level, ACPresence* isOnAC) { - time_t now = time(NULL); - // update battery reading is slow. Update it each 10 seconds only. - if (now < Battery_cacheTime + 10) { - *level = Battery_cacheLevel; - *isOnAC = Battery_cacheIsOnAC; - return; - } - - if (Battery_method == BAT_PROC) { - Battery_getProcData(level, isOnAC); - if (isnan(*level)) { - Battery_method = BAT_SYS; - } - } - if (Battery_method == BAT_SYS) { - Battery_getSysData(level, isOnAC); - if (isnan(*level)) { - Battery_method = BAT_ERR; - } - } - if (Battery_method == BAT_ERR) { - *level = NAN; - *isOnAC = AC_ERROR; - } else { - *level = CLAMP(*level, 0.0, 100.0); - } - Battery_cacheLevel = *level; - Battery_cacheIsOnAC = *isOnAC; - Battery_cacheTime = now; -} diff --git a/linux/Battery.h b/linux/Battery.h deleted file mode 100644 index 18b0dab60..000000000 --- a/linux/Battery.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef HEADER_Battery -#define HEADER_Battery -/* -htop - linux/Battery.h -(C) 2004-2014 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. - -Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). -*/ - -#include "BatteryMeter.h" - - -void Battery_getData(double* level, ACPresence* isOnAC); - -#endif diff --git a/linux/Platform.c b/linux/Platform.c index 28eb9f3c8..575e6e01f 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -17,6 +17,8 @@ in the source distribution for its full text. #include #include #include +#include +#include #include "BatteryMeter.h" #include "ClockMeter.h" @@ -287,6 +289,7 @@ void Platform_setZfsCompressedArcValues(Meter* this) { ZfsCompressedArcMeter_readStats(this, &(lpl->zfs)); } + char* Platform_getProcessEnv(pid_t pid) { char procname[128]; xSnprintf(procname, sizeof(procname), PROCDIR "/%d/environ", pid); @@ -538,3 +541,323 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, *packetsTransmitted = packetsTransmittedSum; return true; } + +// Linux battery reading by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). + +#define MAX_BATTERIES 64 +#define PROC_BATTERY_DIR PROCDIR "/acpi/battery" +#define PROC_POWERSUPPLY_DIR PROCDIR "/acpi/ac_adapter" +#define SYS_POWERSUPPLY_DIR "/sys/class/power_supply" + +// ---------------------------------------- +// READ FROM /proc +// ---------------------------------------- + +static unsigned long int parseBatInfo(const char* fileName, const unsigned short int lineNum, const unsigned short int wordNum) { + const char batteryPath[] = PROC_BATTERY_DIR; + DIR* batteryDir = opendir(batteryPath); + if (!batteryDir) + return 0; + + char* batteries[MAX_BATTERIES]; + unsigned int nBatteries = 0; + memset(batteries, 0, MAX_BATTERIES * sizeof(char*)); + + while (nBatteries < MAX_BATTERIES) { + struct dirent* dirEntry = readdir(batteryDir); + if (!dirEntry) + break; + + char* entryName = dirEntry->d_name; + if (!String_startsWith(entryName, "BAT")) + continue; + + batteries[nBatteries] = xStrdup(entryName); + nBatteries++; + } + closedir(batteryDir); + + unsigned long int total = 0; + for (unsigned int i = 0; i < nBatteries; i++) { + char infoPath[30]; + xSnprintf(infoPath, sizeof infoPath, "%s%s/%s", batteryPath, batteries[i], fileName); + + FILE* file = fopen(infoPath, "r"); + if (!file) + break; + + char* line = NULL; + for (unsigned short int j = 0; j < lineNum; j++) { + free(line); + line = String_readLine(file); + if (!line) + break; + } + + fclose(file); + + if (!line) + break; + + char* foundNumStr = String_getToken(line, wordNum); + const unsigned long int foundNum = atoi(foundNumStr); + free(foundNumStr); + free(line); + + total += foundNum; + } + + for (unsigned int i = 0; i < nBatteries; i++) + free(batteries[i]); + + return total; +} + +static ACPresence procAcpiCheck(void) { + ACPresence isOn = AC_ERROR; + const char* power_supplyPath = PROC_POWERSUPPLY_DIR; + DIR* dir = opendir(power_supplyPath); + if (!dir) + return AC_ERROR; + + for (;;) { + struct dirent* dirEntry = readdir(dir); + if (!dirEntry) + break; + + const char* entryName = dirEntry->d_name; + + if (entryName[0] != 'A') + continue; + + char statePath[256]; + xSnprintf(statePath, sizeof(statePath), "%s/%s/state", power_supplyPath, entryName); + FILE* file = fopen(statePath, "r"); + if (!file) { + isOn = AC_ERROR; + continue; + } + char* line = String_readLine(file); + + fclose(file); + + if (!line) + continue; + + char* isOnline = String_getToken(line, 2); + free(line); + + if (String_eq(isOnline, "on-line")) + isOn = AC_PRESENT; + else + isOn = AC_ABSENT; + free(isOnline); + if (isOn == AC_PRESENT) + break; + } + + if (dir) + closedir(dir); + + return isOn; +} + +static double Platform_Battery_getProcBatInfo(void) { + const unsigned long int totalFull = parseBatInfo("info", 3, 4); + if (totalFull == 0) + return NAN; + + const unsigned long int totalRemain = parseBatInfo("state", 5, 3); + if (totalRemain == 0) + return NAN; + + return totalRemain * 100.0 / (double) totalFull; +} + +static void Platform_Battery_getProcData(double* level, ACPresence* isOnAC) { + *isOnAC = procAcpiCheck(); + *level = AC_ERROR != *isOnAC ? Platform_Battery_getProcBatInfo() : NAN; +} + +// ---------------------------------------- +// READ FROM /sys +// ---------------------------------------- + +static inline ssize_t xread(int fd, void* buf, size_t count) { + // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. + size_t alreadyRead = 0; + for (;;) { + ssize_t res = read(fd, buf, count); + if (res == -1) { + if (errno == EINTR) + continue; + return -1; + } + + if (res > 0) { + buf = ((char*)buf) + res; + count -= res; + alreadyRead += res; + } + + if (count == 0 || res == 0) + return alreadyRead; + } +} + +static void Platform_Battery_getSysData(double* level, ACPresence* isOnAC) { + + *level = NAN; + *isOnAC = AC_ERROR; + + DIR* dir = opendir(SYS_POWERSUPPLY_DIR); + if (!dir) + return; + + unsigned long int totalFull = 0; + unsigned long int totalRemain = 0; + + for (;;) { + struct dirent* dirEntry = readdir(dir); + if (!dirEntry) + break; + + const char* entryName = dirEntry->d_name; + char filePath[256]; + + xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); + int fd1 = open(filePath, O_RDONLY); + if (fd1 == -1) + continue; + + char type[8]; + ssize_t typelen = xread(fd1, type, 7); + close(fd1); + if (typelen < 1) + continue; + + if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') { + xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); + int fd2 = open(filePath, O_RDONLY); + if (fd2 == -1) { + closedir(dir); + return; + } + char buffer[1024]; + ssize_t buflen = xread(fd2, buffer, 1023); + close(fd2); + if (buflen < 1) { + closedir(dir); + return; + } + buffer[buflen] = '\0'; + char* buf = buffer; + char* line = NULL; + bool full = false; + bool now = false; + int fullSize = 0; + double capacityLevel = NAN; + + #define match(str,prefix) \ + (String_startsWith(str,prefix) ? (str) + strlen(prefix) : NULL) + + while ((line = strsep(&buf, "\n")) != NULL) { + const char* ps = match(line, "POWER_SUPPLY_"); + if (!ps) + continue; + const char* capacity = match(ps, "CAPACITY="); + if (capacity) + capacityLevel = atoi(capacity) / 100.0; + const char* energy = match(ps, "ENERGY_"); + if (!energy) + energy = match(ps, "CHARGE_"); + if (!energy) + continue; + const char* value = (!full) ? match(energy, "FULL=") : NULL; + if (value) { + fullSize = atoi(value); + totalFull += fullSize; + full = true; + if (now) + break; + continue; + } + value = (!now) ? match(energy, "NOW=") : NULL; + if (value) { + totalRemain += atoi(value); + now = true; + if (full) + break; + continue; + } + } + + #undef match + + if (!now && full && !isnan(capacityLevel)) + totalRemain += (capacityLevel * fullSize); + + } else if (entryName[0] == 'A') { + if (*isOnAC != AC_ERROR) + continue; + + xSnprintf(filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); + int fd3 = open(filePath, O_RDONLY); + if (fd3 == -1) { + closedir(dir); + return; + } + char buffer[2] = ""; + for (;;) { + ssize_t res = read(fd3, buffer, 1); + if (res == -1 && errno == EINTR) + continue; + break; + } + close(fd3); + if (buffer[0] == '0') + *isOnAC = AC_ABSENT; + else if (buffer[0] == '1') + *isOnAC = AC_PRESENT; + } + } + closedir(dir); + + *level = totalFull > 0 ? ((double) totalRemain * 100.0) / (double) totalFull : NAN; +} + +static enum { BAT_PROC, BAT_SYS, BAT_ERR } Platform_Battery_method = BAT_PROC; + +static time_t Platform_Battery_cacheTime; +static double Platform_Battery_cacheLevel = NAN; +static ACPresence Platform_Battery_cacheIsOnAC; + +void Platform_getBattery(double* level, ACPresence* isOnAC) { + time_t now = time(NULL); + // update battery reading is slow. Update it each 10 seconds only. + if (now < Platform_Battery_cacheTime + 10) { + *level = Platform_Battery_cacheLevel; + *isOnAC = Platform_Battery_cacheIsOnAC; + return; + } + + if (Platform_Battery_method == BAT_PROC) { + Platform_Battery_getProcData(level, isOnAC); + if (isnan(*level)) + Platform_Battery_method = BAT_SYS; + } + if (Platform_Battery_method == BAT_SYS) { + Platform_Battery_getSysData(level, isOnAC); + if (isnan(*level)) + Platform_Battery_method = BAT_ERR; + } + if (Platform_Battery_method == BAT_ERR) { + *level = NAN; + *isOnAC = AC_ERROR; + } else { + *level = CLAMP(*level, 0.0, 100.0); + } + Platform_Battery_cacheLevel = *level; + Platform_Battery_cacheIsOnAC = *isOnAC; + Platform_Battery_cacheTime = now; +} diff --git a/linux/Platform.h b/linux/Platform.h index fc249095e..dbd6bb462 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -11,6 +11,7 @@ in the source distribution for its full text. #include #include "Action.h" +#include "BatteryMeter.h" #include "DiskIOMeter.h" #include "Meter.h" #include "Process.h" @@ -62,4 +63,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, unsigned long int* bytesTransmitted, unsigned long int* packetsTransmitted); +void Platform_getBattery(double *percent, ACPresence *isOnAC); + #endif diff --git a/openbsd/Battery.c b/openbsd/Battery.c deleted file mode 100644 index b72253e0c..000000000 --- a/openbsd/Battery.c +++ /dev/null @@ -1,74 +0,0 @@ -/* -htop - openbsd/Battery.c -(C) 2015 Hisham H. Muhammad -(C) 2015 Michael McConville -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Battery.h" - -#include -#include -#include -#include -#include - -static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) { - for (int devn = 0;; devn++) { - mib[2] = devn; - if (sysctl(mib, 3, snsrdev, sdlen, NULL, 0) == -1) { - if (errno == ENXIO) - continue; - if (errno == ENOENT) - return false; - } - if (strcmp(name, snsrdev->xname) == 0) { - return true; - } - } -} - -void Battery_getData(double* level, ACPresence* isOnAC) { - static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0}; - struct sensor s; - size_t slen = sizeof(struct sensor); - struct sensordev snsrdev; - size_t sdlen = sizeof(struct sensordev); - - bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen); - - *level = NAN; - if (found) { - /* last full capacity */ - mib[3] = 7; - mib[4] = 0; - double last_full_capacity = 0; - if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { - last_full_capacity = s.value; - } - if (last_full_capacity > 0) { - /* remaining capacity */ - mib[3] = 7; - mib[4] = 3; - if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { - double charge = s.value; - *level = 100 * (charge / last_full_capacity); - if (charge >= last_full_capacity) { - *level = 100; - } - } - } - } - - found = findDevice("acpiac0", mib, &snsrdev, &sdlen); - - *isOnAC = AC_ERROR; - if (found) { - mib[3] = 9; - mib[4] = 0; - if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { - *isOnAC = s.value; - } - } -} diff --git a/openbsd/Battery.h b/openbsd/Battery.h deleted file mode 100644 index 60b632d25..000000000 --- a/openbsd/Battery.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef HEADER_Battery -#define HEADER_Battery -/* -htop - openbsd/Battery.h -(C) 2015 Hisham H. Muhammad -(C) 2015 Michael McConville -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "BatteryMeter.h" - -void Battery_getData(double* level, ACPresence* isOnAC); - -#endif diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 8e2a58222..b7cc5190c 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -25,6 +25,7 @@ in the source distribution for its full text. #include #include +#include #include #include @@ -38,6 +39,7 @@ in the source distribution for its full text. #include #include #include +#include #include @@ -319,3 +321,60 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, *packetsTransmitted = 0; return false; } + +static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) { + for (int devn = 0;; devn++) { + mib[2] = devn; + if (sysctl(mib, 3, snsrdev, sdlen, NULL, 0) == -1) { + if (errno == ENXIO) + continue; + if (errno == ENOENT) + return false; + } + if (strcmp(name, snsrdev->xname) == 0) { + return true; + } + } +} + +void Platform_getBattery(double* level, ACPresence* isOnAC) { + static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0}; + struct sensor s; + size_t slen = sizeof(struct sensor); + struct sensordev snsrdev; + size_t sdlen = sizeof(struct sensordev); + + bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen); + + *level = NAN; + if (found) { + /* last full capacity */ + mib[3] = 7; + mib[4] = 0; + double last_full_capacity = 0; + if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) + last_full_capacity = s.value; + if (last_full_capacity > 0) { + /* remaining capacity */ + mib[3] = 7; + mib[4] = 3; + if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { + double charge = s.value; + *level = 100 * (charge / last_full_capacity); + if (charge >= last_full_capacity) { + *level = 100; + } + } + } + } + + found = findDevice("acpiac0", mib, &snsrdev, &sdlen); + + *isOnAC = AC_ERROR; + if (found) { + mib[3] = 9; + mib[4] = 0; + if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) + *isOnAC = s.value; + } +} diff --git a/solaris/Battery.c b/solaris/Battery.c deleted file mode 100644 index c824df249..000000000 --- a/solaris/Battery.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "Battery.h" - -#include - -void Battery_getData(double* level, ACPresence* isOnAC) { - *level = NAN; - *isOnAC = AC_ERROR; -} diff --git a/solaris/Battery.h b/solaris/Battery.h deleted file mode 100644 index 74a27fc58..000000000 --- a/solaris/Battery.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef HEADER_Battery -#define HEADER_Battery - -#include "BatteryMeter.h" - -void Battery_getData(double* level, ACPresence* isOnAC); - -#endif diff --git a/solaris/Platform.c b/solaris/Platform.c index 1a505f844..1a032758b 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -300,3 +300,8 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, *packetsTransmitted = 0; return false; } + +void Platform_getBattery(double* level, ACPresence* isOnAC) { + *level = NAN; + *isOnAC = AC_ERROR; +} diff --git a/solaris/Platform.h b/solaris/Platform.h index 4d83dc7e5..051a64dad 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -80,4 +80,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, unsigned long int* bytesTransmitted, unsigned long int* packetsTransmitted); +void Platform_getBattery(double* level, ACPresence* isOnAC); + #endif diff --git a/unsupported/Battery.c b/unsupported/Battery.c deleted file mode 100644 index c824df249..000000000 --- a/unsupported/Battery.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "Battery.h" - -#include - -void Battery_getData(double* level, ACPresence* isOnAC) { - *level = NAN; - *isOnAC = AC_ERROR; -} diff --git a/unsupported/Battery.h b/unsupported/Battery.h deleted file mode 100644 index 74a27fc58..000000000 --- a/unsupported/Battery.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef HEADER_Battery -#define HEADER_Battery - -#include "BatteryMeter.h" - -void Battery_getData(double* level, ACPresence* isOnAC); - -#endif diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 80df7395c..c7c2a2cf0 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -167,3 +167,8 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, *packetsTransmitted = 0; return false; } + +void Platform_getBattery(double* level, ACPresence* isOnAC) { + *level = NAN; + *isOnAC = AC_ERROR; +} diff --git a/unsupported/Platform.h b/unsupported/Platform.h index a00f644ef..c75a283ad 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -60,4 +60,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, unsigned long int* bytesTransmitted, unsigned long int* packetsTransmitted); +void Platform_getBattery(double *percent, ACPresence *isOnAC); + #endif