This commit is contained in:
Hisham Muhammad 2015-08-12 17:11:28 -03:00
commit 2ed83d6902
16 changed files with 52 additions and 37 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ htop
*.gcno
*/*.gcno
*.h.gch
*/.dirstamp
.deps/
Makefile

23
CRT.c
View File

@ -16,6 +16,7 @@ in the source distribution for its full text.
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <langinfo.h>
#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;

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -27,6 +27,11 @@ in the source distribution for its full text.
#include <time.h>
#include <assert.h>
#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

View File

@ -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

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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)));

View File

@ -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)

14
htop.c
View File

@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -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;
}