From 08829cbc3b5682809333aa005b0bc669760c895a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 15 May 2015 11:33:25 +0200 Subject: [PATCH 01/16] fix compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc gives warnings like this: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result Assign value to a variable, cast to (void) to discard it. --- TraceScreen.c | 3 ++- linux/LinuxProcessList.c | 3 ++- linux/Platform.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/TraceScreen.c b/TraceScreen.c index 6f871267..197a0fd1 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -93,7 +93,8 @@ void TraceScreen_run(TraceScreen* this) { execlp("strace", "strace", "-p", buffer, NULL); } const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH."; - write(fdpair[1], message, strlen(message)); + ssize_t written = write(fdpair[1], message, strlen(message)); + (void) written; exit(1); } fcntl(fdpair[0], F_SETFL, O_NONBLOCK); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 926bebbc..e4bc8e50 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -94,7 +94,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui int cpus = -1; do { cpus++; - fgets(buffer, 255, file); + char * s = fgets(buffer, 255, file); + (void) s; } while (String_startsWith(buffer, "cpu")); fclose(file); diff --git a/linux/Platform.c b/linux/Platform.c index f14c38c7..fad0e6b7 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -110,7 +110,8 @@ int Platform_getMaxPid() { FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); if (!file) return -1; int maxPid = 4194303; - (void) fscanf(file, "%32d", &maxPid); + int match = fscanf(file, "%32d", &maxPid); + (void) match; fclose(file); return maxPid; } From 867dece8fec560e0da9c893152e3f6d5bf12648e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 15 May 2015 11:38:16 +0200 Subject: [PATCH 02/16] add */.dirstamp to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 85f580bf..091afc8c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ htop *.gcno */*.gcno *.h.gch +*/.dirstamp .deps/ Makefile From a8e1c1c63f88ad4cbe7f164fcfcfa34fb60ae73b Mon Sep 17 00:00:00 2001 From: sherpya Date: Wed, 20 May 2015 04:30:11 +0200 Subject: [PATCH 03/16] added missing defines for android --- Process.c | 5 +++++ Process.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Process.c b/Process.c index 267d1733..1962c5d0 100644 --- a/Process.c +++ b/Process.c @@ -27,6 +27,11 @@ in the source distribution for its full text. #include #include +#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 diff --git a/Process.h b/Process.h index e1b7a8fa..ab7acb28 100644 --- a/Process.h +++ b/Process.h @@ -9,6 +9,11 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#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 From 1efa544e1ba1e45a1a4f53e6dc6908682e60e519 Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Sun, 7 Jun 2015 17:17:46 +0800 Subject: [PATCH 04/16] Re-run MakeHeader.py on freebsd/FreeBSDProcess.c Several functions and struct had changed in b291fba02b8d9bb52cd8a23ef5fffbba4f89ff0a --- freebsd/FreeBSDProcess.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h index d0a1882c..bf0acae8 100644 --- a/freebsd/FreeBSDProcess.h +++ b/freebsd/FreeBSDProcess.h @@ -28,6 +28,8 @@ typedef struct FreeBSDProcess_ { #endif +extern ProcessClass FreeBSDProcess_class; + extern ProcessFieldData Process_fields[]; extern char* Process_pidFormat; @@ -39,9 +41,9 @@ FreeBSDProcess* FreeBSDProcess_new(Settings* settings); void Process_delete(Object* cast); -void Process_writeField(Process* this, RichString* str, ProcessField field); +void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField field); -long Process_compare(const void* v1, const void* v2); +long FreeBSDProcess_compare(const void* v1, const void* v2); bool Process_isThread(Process* this); From 5a5dc7177080054649f46c1a73af5d885a978aa3 Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Sun, 7 Jun 2015 17:20:36 +0800 Subject: [PATCH 05/16] Cast FreeBSDProcess_new to Process_New `Process_new_fn` had been renamed to `Process_New` in d880def0e9b5dcce07917aa7cc71e49bddf21c16 --- freebsd/FreeBSDProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index aaebc928..cc51a7cd 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -146,7 +146,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { struct kinfo_proc* kproc = &kprocs[i]; bool preExisting = false; - Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, (Process_new_fn) FreeBSDProcess_new); + Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, (Process_New) FreeBSDProcess_new); FreeBSDProcess* fp = (FreeBSDProcess*) proc; proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); From 16d8cc7c38664e7470f767705fdb04428170c915 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Tue, 9 Jun 2015 00:08:06 +0100 Subject: [PATCH 06/16] Changed MemoryMeter and SwapMeter to use short memory sizes The MemoryMeter and SwapMeter now use the short GNU Coreutils style format to represent memory sizes. --- MemoryMeter.c | 2 +- SwapMeter.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MemoryMeter.c b/MemoryMeter.c index 27ed0dc7..f1c1e357 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -26,7 +26,7 @@ int MemoryMeter_attributes[] = { static void MemoryMeter_setValues(Meter* this, char* buffer, int size) { Platform_setMemoryValues(this); - snprintf(buffer, size, "%ld/%ldMB", (long int) this->values[0] / 1024, (long int) this->total / 1024); + snprintf(buffer, size, "%ld/%ldM", (long int) this->values[0] / 1024, (long int) this->total / 1024); } static void MemoryMeter_display(Object* cast, RichString* out) { diff --git a/SwapMeter.c b/SwapMeter.c index b8bb1814..a19c0300 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -35,7 +35,7 @@ static void SwapMeter_humanNumber(char* buffer, const long int* value) { static void SwapMeter_setValues(Meter* this, char* buffer, int len) { Platform_setSwapValues(this); - snprintf(buffer, len, "%ld/%ldMB", (long int) this->values[0] / MEGABYTE, (long int) this->total / MEGABYTE); + snprintf(buffer, len, "%ld/%ldM", (long int) this->values[0] / MEGABYTE, (long int) this->total / MEGABYTE); } static void SwapMeter_display(Object* cast, RichString* out) { From 03826fbc54b47fbba4ee20e423ec20bb9d2b68e5 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Tue, 9 Jun 2015 00:11:43 +0100 Subject: [PATCH 07/16] Added information about memory sizes to man page The man page now contains the section "MEMORY SIZES" which talks about the convention used for representing memory sizes and why it was chosen. --- htop.1.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htop.1.in b/htop.1.in index 4908c806..ce11a5e0 100644 --- a/htop.1.in +++ b/htop.1.in @@ -353,6 +353,15 @@ 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) +.LP +The decision to use this convention was made in order to conserve screen space +and make memory size representations consistent throughout htop. + .SH "SEE ALSO" proc(5), top(1), free(1), ps(1), uptime(1) From a804f1f848b95f7fdd6fa369f3f1a1d72dbc5236 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 12 Jun 2015 01:35:12 +0200 Subject: [PATCH 08/16] write header length (number of columns) back to configuration --- Header.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Header.c b/Header.c index baeb267b..303928cd 100644 --- a/Header.c +++ b/Header.c @@ -85,6 +85,7 @@ void Header_writeBackToSettings(const Header* this) { colSettings->names = calloc(len+1, sizeof(char*)); colSettings->modes = calloc(len, sizeof(int)); + colSettings->len = len; for (int i = 0; i < len; i++) { Meter* meter = (Meter*) Vector_get(vec, i); From b796362e90d604aa2d04305262b8c3bd823e5057 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 15 Jun 2015 11:09:32 +0200 Subject: [PATCH 09/16] ignore enter, delete and space on empty panel --- MetersPanel.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MetersPanel.c b/MetersPanel.c index 4050dc9e..f0106daf 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -76,6 +76,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { case 0x0d: case KEY_ENTER: { + if (!Vector_size(this->meters)) + break; this->moving = !(this->moving); ((ListItem*)Panel_getSelected(super))->moving = this->moving; result = HANDLED; @@ -85,6 +87,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { case KEY_F(4): case 't': { + if (!Vector_size(this->meters)) + break; Meter* meter = (Meter*) Vector_get(this->meters, selected); int mode = meter->mode + 1; if (mode == LAST_METERMODE) mode = 1; @@ -147,6 +151,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { case KEY_F(9): case KEY_DC: { + if (!Vector_size(this->meters)) + break; if (selected < Vector_size(this->meters)) { Vector_remove(this->meters, selected); Panel_remove(super, selected); From a588c6d179c8b8070cab1f33a8e54b5a17f9ae63 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 14 Jul 2015 12:43:38 +0200 Subject: [PATCH 10/16] paint PROCESS_LOW_PRIORITY in green ... and thus make it use a different color than PROCESS_HIGH_PRIORITY. --- CRT.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CRT.c b/CRT.c index 031d76a4..983c601f 100644 --- a/CRT.c +++ b/CRT.c @@ -180,7 +180,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_R_STATE] = ColorPair(Green,Black), [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), - [PROCESS_LOW_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, @@ -298,7 +298,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_R_STATE] = ColorPair(Green,White), [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,White), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,White), - [PROCESS_LOW_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), @@ -357,7 +357,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_R_STATE] = ColorPair(Green,Black), [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), - [PROCESS_LOW_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), @@ -416,7 +416,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_R_STATE] = ColorPair(Green,Blue), [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Blue), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Blue), - [PROCESS_LOW_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), @@ -477,7 +477,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [PROCESS_R_STATE] = ColorPair(Green,Black), [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), - [PROCESS_LOW_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), From 016dbbe6a479d186ca618e9d85a56c045e6f788e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 16 Jul 2015 08:08:18 +0200 Subject: [PATCH 11/16] initialize locale This has two effects: * The locale may have impact on string formatting. So depending on the locale we may end up with different decimal point. * We can use nl_langinfo() for UTF-8 detection. --- CRT.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CRT.c b/CRT.c index 983c601f..e341c249 100644 --- a/CRT.c +++ b/CRT.c @@ -585,6 +585,9 @@ void CRT_init(int delay, int colorScheme) { CRT_colorScheme = 1; CRT_setColors(CRT_colorScheme); + /* initialize locale */ + setlocale(LC_ALL, ""); + #ifdef HAVE_LIBNCURSESW char *locale = setlocale(LC_ALL, NULL); if (locale == NULL || locale[0] == '\0') From 1728483aa280f9f58bca50a7fc26596869770e6a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 16 Jul 2015 08:12:48 +0200 Subject: [PATCH 12/16] simplify UTF-8 detection --- CRT.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/CRT.c b/CRT.c index e341c249..8de964a5 100644 --- a/CRT.c +++ b/CRT.c @@ -16,6 +16,7 @@ in the source distribution for its full text. #include #include #include +#include #define ColorPair(i,j) COLOR_PAIR((7-i)*8+j) @@ -589,14 +590,7 @@ void CRT_init(int delay, int colorScheme) { setlocale(LC_ALL, ""); #ifdef HAVE_LIBNCURSESW - char *locale = setlocale(LC_ALL, NULL); - if (locale == NULL || locale[0] == '\0') - locale = setlocale(LC_CTYPE, NULL); - if (locale != NULL && - (strstr(locale, "UTF-8") || - strstr(locale, "utf-8") || - strstr(locale, "UTF8") || - strstr(locale, "utf8"))) + if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) CRT_utf8 = true; else CRT_utf8 = false; From 77df258636621ec66c688482861aca95f0950ab7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 16 Jul 2015 08:17:12 +0200 Subject: [PATCH 13/16] remove duplicate code --- htop.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/htop.c b/htop.c index 211489bb..a031cde3 100644 --- a/htop.c +++ b/htop.c @@ -184,20 +184,6 @@ int main(int argc, char** argv) { } #endif -#ifdef HAVE_LIBNCURSESW - char *locale = setlocale(LC_ALL, NULL); - if (locale == NULL || locale[0] == '\0') - locale = setlocale(LC_CTYPE, NULL); - if (locale != NULL && - (strstr(locale, "UTF-8") || - strstr(locale, "utf-8") || - strstr(locale, "UTF8") || - strstr(locale, "utf8"))) - CRT_utf8 = true; - else - CRT_utf8 = false; -#endif - Process_setupColumnWidths(); UsersTable* ut = UsersTable_new(); From 1bdee6b6ba559fdd9ab0c4240cef450e37112335 Mon Sep 17 00:00:00 2001 From: Maks Naumov Date: Thu, 23 Jul 2015 14:24:39 +0300 Subject: [PATCH 14/16] Fix sort by cstime --- linux/LinuxProcess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 8a997862..16e7f55b 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -390,7 +390,7 @@ long LinuxProcess_compare(const void* v1, const void* v2) { 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 - p2->cstime; goto test_diff; + case CSTIME: diff = p2->cstime - p1->cstime; goto test_diff; #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; From cea591181d58d7cc161fc9ab1407ce940a421925 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 29 Jul 2015 11:28:15 +0200 Subject: [PATCH 15/16] initialize locale for LC_CTYPE only htop uses scanf functions to parse values from proc filesystem. This breaks when initializing locale for LC_NUMERIC because of unexpected commas. So initialize locale for LC_CTYPE only. --- CRT.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRT.c b/CRT.c index 8de964a5..03f71ca7 100644 --- a/CRT.c +++ b/CRT.c @@ -587,7 +587,7 @@ void CRT_init(int delay, int colorScheme) { CRT_setColors(CRT_colorScheme); /* initialize locale */ - setlocale(LC_ALL, ""); + setlocale(LC_CTYPE, ""); #ifdef HAVE_LIBNCURSESW if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) From 6f6f0e36ad2d3c265cc5b832bf2b100891fac0d8 Mon Sep 17 00:00:00 2001 From: peter-warhzner Date: Tue, 4 Aug 2015 18:48:34 +0500 Subject: [PATCH 16/16] Fix typo in comment --- linux/LinuxProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index e4bc8e50..d532c4c3 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -675,7 +675,7 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { unsigned long long int ioWait, irq, softIrq, steal, guest, guestnice; unsigned long long int systemalltime, idlealltime, totaltime, virtalltime; ioWait = irq = softIrq = steal = guest = guestnice = 0; - // Dependending on your kernel version, + // Depending on your kernel version, // 5, 7, 8 or 9 of these fields will be set. // The rest will remain at zero. char* ok = fgets(buffer, 255, file);