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 diff --git a/CRT.c b/CRT.c index 031d76a4..03f71ca7 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) @@ -180,7 +181,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 +299,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 +358,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 +417,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 +478,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), @@ -585,15 +586,11 @@ void CRT_init(int delay, int colorScheme) { CRT_colorScheme = 1; CRT_setColors(CRT_colorScheme); + /* initialize locale */ + setlocale(LC_CTYPE, ""); + #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; 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); 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/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); 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 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) { 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/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); 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))); 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) 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(); 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; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 926bebbc..d532c4c3 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); @@ -674,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); 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; }