Merge branch 'hishamhm-pull-960'

This commit is contained in:
Nathan Scott 2020-08-20 14:19:53 +10:00
commit a82fd262d7
48 changed files with 155 additions and 155 deletions

View File

@ -14,3 +14,4 @@ charset = utf-8
[*.{c,h}] [*.{c,h}]
indent_style = space indent_style = space
indent_size = 3 indent_size = 3
trim_trailing_whitespace = true

View File

@ -66,7 +66,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
Panel* panel = st->panel; Panel* panel = st->panel;
Header* header = st->header; Header* header = st->header;
Settings* settings = st->settings; Settings* settings = st->settings;
int y = panel->y; 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, false);
scr->allowFocusChange = false; scr->allowFocusChange = false;
@ -313,7 +313,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
return HTOP_OK; return HTOP_OK;
#if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY) #if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY)
Panel* panel = st->panel; Panel* panel = st->panel;
Process* p = (Process*) Panel_getSelected(panel); Process* p = (Process*) Panel_getSelected(panel);
if (!p) return HTOP_OK; if (!p) return HTOP_OK;
Affinity* affinity = Affinity_get(p, st->pl); Affinity* affinity = Affinity_get(p, st->pl);

View File

@ -52,7 +52,7 @@ static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, M
static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
AvailableMetersPanel* this = (AvailableMetersPanel*) super; AvailableMetersPanel* this = (AvailableMetersPanel*) super;
Header* header = this->header; Header* header = this->header;
ListItem* selected = (ListItem*) Panel_getSelected(super); ListItem* selected = (ListItem*) Panel_getSelected(super);
int param = selected->key & 0xff; int param = selected->key & 0xff;
int type = selected->key >> 16; int type = selected->key >> 16;
@ -104,7 +104,7 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade
Panel* super = (Panel*) this; Panel* super = (Panel*) this;
FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done "); FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done ");
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
this->settings = settings; this->settings = settings;
this->header = header; this->header = header;
this->leftPanel = leftMeters; this->leftPanel = leftMeters;

View File

@ -35,7 +35,7 @@ int BatteryMeter_attributes[] = {
static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) { static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) {
ACPresence isOnAC; ACPresence isOnAC;
double percent; double percent;
Battery_getData(&percent, &isOnAC); Battery_getData(&percent, &isOnAC);
if (percent == -1) { if (percent == -1) {

View File

@ -219,7 +219,7 @@ MeterClass CPUMeter_class = {
.defaultMode = BAR_METERMODE, .defaultMode = BAR_METERMODE,
.maxItems = CPU_METER_ITEMCOUNT, .maxItems = CPU_METER_ITEMCOUNT,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "CPU", .name = "CPU",
.uiName = "CPU", .uiName = "CPU",
.caption = "CPU", .caption = "CPU",
@ -234,7 +234,7 @@ MeterClass AllCPUsMeter_class = {
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "AllCPUs", .name = "AllCPUs",
.uiName = "CPUs (1/1)", .uiName = "CPUs (1/1)",
.description = "CPUs (1/1): all CPUs", .description = "CPUs (1/1): all CPUs",
@ -253,7 +253,7 @@ MeterClass AllCPUs2Meter_class = {
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "AllCPUs2", .name = "AllCPUs2",
.uiName = "CPUs (1&2/2)", .uiName = "CPUs (1&2/2)",
.description = "CPUs (1&2/2): all CPUs in 2 shorter columns", .description = "CPUs (1&2/2): all CPUs in 2 shorter columns",
@ -272,7 +272,7 @@ MeterClass LeftCPUsMeter_class = {
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "LeftCPUs", .name = "LeftCPUs",
.uiName = "CPUs (1/2)", .uiName = "CPUs (1/2)",
.description = "CPUs (1/2): first half of list", .description = "CPUs (1/2): first half of list",
@ -291,7 +291,7 @@ MeterClass RightCPUsMeter_class = {
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "RightCPUs", .name = "RightCPUs",
.uiName = "CPUs (2/2)", .uiName = "CPUs (2/2)",
.description = "CPUs (2/2): second half of list", .description = "CPUs (2/2): second half of list",
@ -310,7 +310,7 @@ MeterClass LeftCPUs2Meter_class = {
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "LeftCPUs2", .name = "LeftCPUs2",
.uiName = "CPUs (1&2/4)", .uiName = "CPUs (1&2/4)",
.description = "CPUs (1&2/4): first half in 2 shorter columns", .description = "CPUs (1&2/4): first half in 2 shorter columns",
@ -329,7 +329,7 @@ MeterClass RightCPUs2Meter_class = {
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "RightCPUs2", .name = "RightCPUs2",
.uiName = "CPUs (3&4/4)", .uiName = "CPUs (3&4/4)",
.description = "CPUs (3&4/4): second half in 2 shorter columns", .description = "CPUs (3&4/4): second half in 2 shorter columns",

4
CRT.c
View File

@ -625,12 +625,12 @@ void CRT_init(int delay, int colorScheme) {
} }
CRT_colors = CRT_colorSchemes[colorScheme]; CRT_colors = CRT_colorSchemes[colorScheme];
CRT_colorScheme = colorScheme; CRT_colorScheme = colorScheme;
for (int i = 0; i < LAST_COLORELEMENT; i++) { for (int i = 0; i < LAST_COLORELEMENT; i++) {
unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][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); halfdelay(CRT_delay);
nonl(); nonl();
intrflush(stdscr, false); intrflush(stdscr, false);

View File

@ -66,14 +66,14 @@ CheckItem* CheckItem_newByVal(char* text, bool value) {
} }
void CheckItem_set(CheckItem* this, bool value) { void CheckItem_set(CheckItem* this, bool value) {
if (this->ref) if (this->ref)
*(this->ref) = value; *(this->ref) = value;
else else
this->value = value; this->value = value;
} }
bool CheckItem_get(CheckItem* this) { bool CheckItem_get(CheckItem* this) {
if (this->ref) if (this->ref)
return *(this->ref); return *(this->ref);
else else
return this->value; return this->value;

View File

@ -56,7 +56,7 @@ static void ColorsPanel_delete(Object* object) {
static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) { static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
ColorsPanel* this = (ColorsPanel*) super; ColorsPanel* this = (ColorsPanel*) super;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
int mark = Panel_getSelectedIndex(super); int mark = Panel_getSelectedIndex(super);

View File

@ -40,7 +40,7 @@ static void ColumnsPanel_delete(Object* object) {
static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
ColumnsPanel* const this = (ColumnsPanel*) super; ColumnsPanel* const this = (ColumnsPanel*) super;
int selected = Panel_getSelectedIndex(super); int selected = Panel_getSelectedIndex(super);
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
int size = Panel_size(super); int size = Panel_size(super);
@ -87,7 +87,7 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
case ']': case ']':
case '+': case '+':
{ {
if (selected < size - 2) if (selected < size - 2)
Panel_moveSelectedDown(super); Panel_moveSelectedDown(super);
result = HANDLED; result = HANDLED;
break; break;

View File

@ -39,7 +39,7 @@ static void DisplayOptionsPanel_delete(Object* object) {
static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super; DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
CheckItem* selected = (CheckItem*) Panel_getSelected(super); CheckItem* selected = (CheckItem*) Panel_getSelected(super);

View File

@ -52,7 +52,7 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke
this->functions[i] = xStrdup(functions[i]); this->functions[i] = xStrdup(functions[i]);
} }
if (keys && events) { if (keys && events) {
this->staticData = false; this->staticData = false;
this->keys = xCalloc(15, sizeof(char*)); this->keys = xCalloc(15, sizeof(char*));
this->events = xCalloc(15, sizeof(int)); this->events = xCalloc(15, sizeof(int));
int i = 0; int i = 0;

View File

@ -63,7 +63,7 @@ int Hashtable_count(Hashtable* this) {
static HashtableItem* HashtableItem_new(unsigned int key, void* value) { static HashtableItem* HashtableItem_new(unsigned int key, void* value) {
HashtableItem* this; HashtableItem* this;
this = xMalloc(sizeof(HashtableItem)); this = xMalloc(sizeof(HashtableItem));
this->key = key; this->key = key;
this->value = value; this->value = value;
@ -73,7 +73,7 @@ static HashtableItem* HashtableItem_new(unsigned int key, void* value) {
Hashtable* Hashtable_new(int size, bool owner) { Hashtable* Hashtable_new(int size, bool owner) {
Hashtable* this; Hashtable* this;
this = xMalloc(sizeof(Hashtable)); this = xMalloc(sizeof(Hashtable));
this->items = 0; this->items = 0;
this->size = size; 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) { void* Hashtable_remove(Hashtable* this, unsigned int key) {
unsigned int index = key % this->size; unsigned int index = key % this->size;
assert(Hashtable_isConsistent(this)); assert(Hashtable_isConsistent(this));
HashtableItem** bucket; HashtableItem** bucket;
for (bucket = &(this->buckets[index]); *bucket; bucket = &((*bucket)->next) ) { for (bucket = &(this->buckets[index]); *bucket; bucket = &((*bucket)->next) ) {
if ((*bucket)->key == key) { if ((*bucket)->key == key) {
void* value = (*bucket)->value; void* value = (*bucket)->value;

View File

@ -76,17 +76,17 @@ void Header_populateFromSettings(Header* this) {
void Header_writeBackToSettings(const Header* this) { void Header_writeBackToSettings(const Header* this) {
Header_forEachColumn(this, col) { Header_forEachColumn(this, col) {
MeterColumnSettings* colSettings = &this->settings->columns[col]; MeterColumnSettings* colSettings = &this->settings->columns[col];
String_freeArray(colSettings->names); String_freeArray(colSettings->names);
free(colSettings->modes); free(colSettings->modes);
Vector* vec = this->columns[col]; Vector* vec = this->columns[col];
int len = Vector_size(vec); 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->modes = xCalloc(len, sizeof(int));
colSettings->len = len; colSettings->len = len;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
Meter* meter = (Meter*) Vector_get(vec, i); Meter* meter = (Meter*) Vector_get(vec, i);
char* name = xCalloc(64, sizeof(char)); char* name = xCalloc(64, sizeof(char));
@ -188,7 +188,7 @@ void Header_draw(const Header* this) {
} }
int width = COLS / this->nrColumns - (pad * this->nrColumns - 1) - 1; int width = COLS / this->nrColumns - (pad * this->nrColumns - 1) - 1;
int x = pad; int x = pad;
Header_forEachColumn(this, col) { Header_forEachColumn(this, col) {
Vector* meters = this->columns[col]; Vector* meters = this->columns[col];
for (int y = (pad / 2), i = 0; i < Vector_size(meters); i++) { for (int y = (pad / 2), i = 0; i < Vector_size(meters); i++) {

View File

@ -120,7 +120,7 @@ void InfoScreen_run(InfoScreen* this) {
} }
set_escdelay(25); set_escdelay(25);
int ch = getch(); int ch = getch();
if (ch == ERR) { if (ch == ERR) {
if (As_InfoScreen(this)->onErr) { if (As_InfoScreen(this)->onErr) {
InfoScreen_onErr(this); InfoScreen_onErr(this);
@ -144,7 +144,7 @@ void InfoScreen_run(InfoScreen* this) {
IncSet_handleKey(this->inc, ch, panel, IncSet_getListItemValue, this->lines); IncSet_handleKey(this->inc, ch, panel, IncSet_getListItemValue, this->lines);
continue; continue;
} }
switch(ch) { switch(ch) {
case ERR: case ERR:
continue; continue;

View File

@ -65,7 +65,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
MainPanel* this = (MainPanel*) super; MainPanel* this = (MainPanel*) super;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
Htop_Reaction reaction = HTOP_OK; Htop_Reaction reaction = HTOP_OK;
if (EVENT_IS_HEADER_CLICK(ch)) { if (EVENT_IS_HEADER_CLICK(ch)) {
@ -80,7 +80,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
} else { } else {
reaction |= Action_setSortKey(settings, field); 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; result = HANDLED;
} else if (ch != ERR && this->inc->active) { } else if (ch != ERR && this->inc->active) {
bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL); bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
@ -117,7 +117,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
} }
if (reaction & HTOP_REFRESH) { if (reaction & HTOP_REFRESH) {
result |= REDRAW; result |= REDRAW;
} }
if (reaction & HTOP_RECALCULATE) { if (reaction & HTOP_RECALCULATE) {
result |= RESCAN; result |= RESCAN;
} }

View File

@ -60,7 +60,7 @@ MeterClass MemoryMeter_class = {
.delete = Meter_delete, .delete = Meter_delete,
.display = MemoryMeter_display, .display = MemoryMeter_display,
}, },
.updateValues = MemoryMeter_updateValues, .updateValues = MemoryMeter_updateValues,
.defaultMode = BAR_METERMODE, .defaultMode = BAR_METERMODE,
.maxItems = 3, .maxItems = 3,
.total = 100.0, .total = 100.0,

16
Meter.c
View File

@ -78,7 +78,7 @@ typedef struct MeterClass_ {
struct Meter_ { struct Meter_ {
Object super; Object super;
Meter_Draw draw; Meter_Draw draw;
char* caption; char* caption;
int mode; int mode;
int param; int param;
@ -275,7 +275,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
attrset(CRT_colors[BAR_BORDER]); attrset(CRT_colors[BAR_BORDER]);
mvaddch(y, x, '['); mvaddch(y, x, '[');
mvaddch(y, x + w, ']'); mvaddch(y, x + w, ']');
w--; w--;
x++; x++;
@ -284,7 +284,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
return; return;
} }
char bar[w + 1]; char bar[w + 1];
int blockSizes[10]; int blockSizes[10];
xSnprintf(bar, w + 1, "%*.*s", w, w, buffer); 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); mvaddnstr(y, x, this->caption, captionLen);
x += captionLen; x += captionLen;
w -= captionLen; w -= captionLen;
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if (!timercmp(&now, &(data->time), <)) { 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++) 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]; char buffer[nValues];
Meter_updateValues(this, buffer, nValues - 1); Meter_updateValues(this, buffer, nValues - 1);
double value = 0.0; double value = 0.0;
int items = Meter_getItems(this); int items = Meter_getItems(this);
for (int i = 0; i < items; i++) 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; value /= this->total;
data->values[nValues - 1] = value; data->values[nValues - 1] = value;
} }
int i = nValues - (w*2) + 2, k = 0; int i = nValues - (w*2) + 2, k = 0;
if (i < 0) { if (i < 0) {
k = -i/2; k = -i/2;
@ -459,7 +459,7 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
char buffer[METER_BUFFER_LEN]; char buffer[METER_BUFFER_LEN];
Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1); Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1);
RichString_begin(out); RichString_begin(out);
Meter_displayBuffer(this, buffer, &out); Meter_displayBuffer(this, buffer, &out);

View File

@ -65,7 +65,7 @@ typedef struct MeterClass_ {
struct Meter_ { struct Meter_ {
Object super; Object super;
Meter_Draw draw; Meter_Draw draw;
char* caption; char* caption;
int mode; int mode;
int param; int param;

View File

@ -93,7 +93,7 @@ static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int
static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
MetersPanel* this = (MetersPanel*) super; MetersPanel* this = (MetersPanel*) super;
int selected = Panel_getSelectedIndex(super); int selected = Panel_getSelectedIndex(super);
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
bool sideMove = false; bool sideMove = false;

View File

@ -29,7 +29,7 @@ typedef void(*Object_Delete)(Object*);
#define Class(class_) ((ObjectClass*)(&(class_ ## _class))) #define Class(class_) ((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_ { typedef struct ObjectClass_ {
const void* extends; const void* extends;
const Object_Display display; const Object_Display display;

View File

@ -30,7 +30,7 @@ typedef void(*Object_Delete)(Object*);
#define Class(class_) ((ObjectClass*)(&(class_ ## _class))) #define Class(class_) ((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_ { typedef struct ObjectClass_ {
const void* extends; const void* extends;
const Object_Display display; const Object_Display display;

View File

@ -372,7 +372,7 @@ void Panel_draw(Panel* this, bool focus) {
bool Panel_onKey(Panel* this, int key) { bool Panel_onKey(Panel* this, int key) {
assert (this != NULL); assert (this != NULL);
int size = Vector_size(this->items); int size = Vector_size(this->items);
switch (key) { switch (key) {
case KEY_DOWN: case KEY_DOWN:
@ -455,7 +455,7 @@ bool Panel_onKey(Panel* this, int key) {
if (this->selected < 0 || size == 0) { if (this->selected < 0 || size == 0) {
this->selected = 0; this->selected = 0;
this->needsRedraw = true; this->needsRedraw = true;
} else if (this->selected >= size) { } else if (this->selected >= size) {
this->selected = size - 1; this->selected = size - 1;
this->needsRedraw = true; this->needsRedraw = true;
} }

View File

@ -220,7 +220,7 @@ void Process_setupColumnWidths() {
void Process_humanNumber(RichString* str, unsigned long number, bool coloring) { void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
char buffer[11]; char buffer[11];
int len; int len;
int largeNumberColor = CRT_colors[LARGE_NUMBER]; int largeNumberColor = CRT_colors[LARGE_NUMBER];
int processMegabytesColor = CRT_colors[PROCESS_MEGABYTES]; int processMegabytesColor = CRT_colors[PROCESS_MEGABYTES];
int processColor = CRT_colors[PROCESS]; int processColor = CRT_colors[PROCESS];
@ -228,7 +228,7 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
largeNumberColor = CRT_colors[PROCESS]; largeNumberColor = CRT_colors[PROCESS];
processMegabytesColor = CRT_colors[PROCESS]; processMegabytesColor = CRT_colors[PROCESS];
} }
if(number >= (10 * ONE_DECIMAL_M)) { if(number >= (10 * ONE_DECIMAL_M)) {
#ifdef __LP64__ #ifdef __LP64__
if(number >= (100 * ONE_DECIMAL_G)) { if(number >= (100 * ONE_DECIMAL_G)) {
@ -394,9 +394,9 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
switch (field) { switch (field) {
case PERCENT_CPU: { case PERCENT_CPU: {
if (this->percent_cpu > 999.9) { 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) { } 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 { } else {
xSnprintf(buffer, n, "%4.1f ", this->percent_cpu); xSnprintf(buffer, n, "%4.1f ", this->percent_cpu);
} }
@ -404,7 +404,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
} }
case PERCENT_MEM: { case PERCENT_MEM: {
if (this->percent_mem > 99.9) { if (this->percent_mem > 99.9) {
xSnprintf(buffer, n, "100. "); xSnprintf(buffer, n, "100. ");
} else { } else {
xSnprintf(buffer, n, "%4.1f ", this->percent_mem); xSnprintf(buffer, n, "%4.1f ", this->percent_mem);
} }

View File

@ -84,10 +84,10 @@ ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable*
this->usersTable = usersTable; this->usersTable = usersTable;
this->pidWhiteList = pidWhiteList; this->pidWhiteList = pidWhiteList;
this->userId = userId; this->userId = userId;
// tree-view auxiliary buffer // tree-view auxiliary buffer
this->processes2 = Vector_new(klass, true, DEFAULT_SIZE); this->processes2 = Vector_new(klass, true, DEFAULT_SIZE);
// set later by platform-specific code // set later by platform-specific code
this->cpuCount = 0; this->cpuCount = 0;
@ -138,10 +138,10 @@ void ProcessList_printHeader(ProcessList* this, RichString* header) {
void ProcessList_add(ProcessList* this, Process* p) { void ProcessList_add(ProcessList* this, Process* p) {
assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1); assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1);
assert(Hashtable_get(this->processTable, p->pid) == NULL); assert(Hashtable_get(this->processTable, p->pid) == NULL);
Vector_add(this->processes, p); Vector_add(this->processes, p);
Hashtable_put(this->processTable, p->pid, p); Hashtable_put(this->processTable, p->pid, p);
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1); assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
assert(Hashtable_get(this->processTable, p->pid) != NULL); assert(Hashtable_get(this->processTable, p->pid) != NULL);
assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
@ -353,7 +353,7 @@ void ProcessList_scan(ProcessList* this) {
this->runningTasks = 0; this->runningTasks = 0;
ProcessList_goThroughEntries(this); ProcessList_goThroughEntries(this);
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
Process* p = (Process*) Vector_get(this->processes, i); Process* p = (Process*) Vector_get(this->processes, i);
if (p->updated == false) if (p->updated == false)

View File

@ -67,7 +67,7 @@ typedef struct RichString_ {
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
#endif #endif
#define charBytes(n) (sizeof(CharType) * (n)) #define charBytes(n) (sizeof(CharType) * (n))
static void RichString_extendLen(RichString* this, int len) { static void RichString_extendLen(RichString* this, int len) {
if (this->chlen <= RICHSTRING_MAXLEN) { if (this->chlen <= RICHSTRING_MAXLEN) {

View File

@ -63,7 +63,7 @@ typedef struct RichString_ {
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
#endif #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) #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)

View File

@ -163,7 +163,7 @@ static Panel* setCurrentPanel(Panel* panel) {
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
bool quit = false; bool quit = false;
int focus = 0; int focus = 0;
Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
double oldTime = 0.0; double oldTime = 0.0;
@ -181,7 +181,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if (this->header) { if (this->header) {
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut); checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut);
} }
if (redraw) { if (redraw) {
ScreenManager_drawPanels(this, focus); ScreenManager_drawPanels(this, focus);
} }
@ -269,7 +269,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
quit = true; quit = true;
continue; continue;
} }
switch (ch) { switch (ch) {
case KEY_RESIZE: case KEY_RESIZE:
{ {

View File

@ -31,7 +31,7 @@ typedef struct {
typedef struct Settings_ { typedef struct Settings_ {
char* filename; char* filename;
MeterColumnSettings columns[2]; MeterColumnSettings columns[2];
ProcessField* fields; ProcessField* fields;
@ -114,7 +114,7 @@ static void Settings_defaultMeters(Settings* this) {
this->columns[i].modes = xCalloc(sizes[i], sizeof(int)); this->columns[i].modes = xCalloc(sizes[i], sizeof(int));
this->columns[i].len = sizes[i]; this->columns[i].len = sizes[i];
} }
int r = 0; int r = 0;
if (this->cpuCount > 8) { if (this->cpuCount > 8) {
this->columns[0].names[0] = xStrdup("LeftCPUs2"); 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].modes[1] = BAR_METERMODE;
this->columns[0].names[2] = xStrdup("Swap"); this->columns[0].names[2] = xStrdup("Swap");
this->columns[0].modes[2] = BAR_METERMODE; this->columns[0].modes[2] = BAR_METERMODE;
this->columns[1].names[r] = xStrdup("Tasks"); this->columns[1].names[r] = xStrdup("Tasks");
this->columns[1].modes[r++] = TEXT_METERMODE; this->columns[1].modes[r++] = TEXT_METERMODE;
this->columns[1].names[r] = xStrdup("LoadAverage"); 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) { static bool Settings_read(Settings* this, const char* fileName) {
FILE* fd; FILE* fd;
CRT_dropPrivileges(); CRT_dropPrivileges();
fd = fopen(fileName, "r"); fd = fopen(fileName, "r");
CRT_restorePrivileges(); CRT_restorePrivileges();
if (!fd) if (!fd)
return false; return false;
bool didReadMeters = false; bool didReadMeters = false;
bool didReadFields = false; bool didReadFields = false;
for (;;) { for (;;) {
@ -325,7 +325,7 @@ bool Settings_write(Settings* this) {
} }
Settings* Settings_new(int cpuCount) { Settings* Settings_new(int cpuCount) {
Settings* this = xCalloc(1, sizeof(Settings)); Settings* this = xCalloc(1, sizeof(Settings));
this->sortKey = PERCENT_CPU; this->sortKey = PERCENT_CPU;
@ -344,7 +344,7 @@ Settings* Settings_new(int cpuCount) {
this->cpuCount = cpuCount; this->cpuCount = cpuCount;
this->showProgramPath = true; this->showProgramPath = true;
this->highlightThreads = true; this->highlightThreads = true;
this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
// TODO: turn 'fields' into a Vector, // TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects). // (and ProcessFields into proper objects).
@ -375,7 +375,7 @@ Settings* Settings_new(int cpuCount) {
htopDir = String_cat(home, "/.config/htop"); htopDir = String_cat(home, "/.config/htop");
} }
legacyDotfile = String_cat(home, "/.htoprc"); legacyDotfile = String_cat(home, "/.htoprc");
CRT_dropPrivileges(); CRT_dropPrivileges();
(void) mkdir(configDir, 0700); (void) mkdir(configDir, 0700);
(void) mkdir(htopDir, 0700); (void) mkdir(htopDir, 0700);

View File

@ -22,7 +22,7 @@ typedef struct {
typedef struct Settings_ { typedef struct Settings_ {
char* filename; char* filename;
MeterColumnSettings columns[2]; MeterColumnSettings columns[2];
ProcessField* fields; ProcessField* fields;

View File

@ -117,7 +117,7 @@ char* String_getToken(const char* line, const unsigned short int numMatch) {
if (lastState == 0 && inWord == 1) if (lastState == 0 && inWord == 1)
count++; count++;
if(inWord == 1){ if(inWord == 1){
if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) { if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) {
match[foundCount] = line[i]; match[foundCount] = line[i];

View File

@ -37,9 +37,9 @@ static void TasksMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast; Meter* this = (Meter*)cast;
Settings* settings = this->pl->settings; Settings* settings = this->pl->settings;
char buffer[20]; char buffer[20];
int processes = (int) this->values[2]; int processes = (int) this->values[2];
xSnprintf(buffer, sizeof(buffer), "%d", processes); xSnprintf(buffer, sizeof(buffer), "%d", processes);
RichString_write(out, CRT_colors[METER_VALUE], buffer); RichString_write(out, CRT_colors[METER_VALUE], buffer);
int threadValueColor = CRT_colors[METER_VALUE]; int threadValueColor = CRT_colors[METER_VALUE];
@ -76,7 +76,7 @@ MeterClass TasksMeter_class = {
.defaultMode = TEXT_METERMODE, .defaultMode = TEXT_METERMODE,
.maxItems = 4, .maxItems = 4,
.total = 100.0, .total = 100.0,
.attributes = TasksMeter_attributes, .attributes = TasksMeter_attributes,
.name = "Tasks", .name = "Tasks",
.uiName = "Task counter", .uiName = "Task counter",
.caption = "Tasks: " .caption = "Tasks: "

View File

@ -195,7 +195,7 @@ void Vector_insert(Vector* this, int idx, void* data_) {
if (idx > this->items) { if (idx > this->items) {
idx = this->items; idx = this->items;
} }
Vector_checkArraySize(this); Vector_checkArraySize(this);
//assert(this->array[this->items] == NULL); //assert(this->array[this->items] == NULL);
for (int i = this->items; i > idx; i--) { 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) { static void Vector_merge(Vector* this, Vector* v2) {
int i; int i;
assert(Vector_isConsistent(this)); assert(Vector_isConsistent(this));
for (i = 0; i < v2->items; i++) for (i = 0; i < v2->items; i++)
Vector_add(this, v2->array[i]); Vector_add(this, v2->array[i]);
v2->items = 0; v2->items = 0;

View File

@ -212,7 +212,7 @@ ERROR_B:
ERROR_A: ERROR_A:
retval = xStrdup(k->kp_proc.p_comm); retval = xStrdup(k->kp_proc.p_comm);
*basenameOffset = strlen(retval); *basenameOffset = strlen(retval);
return retval; return retval;
} }
@ -302,11 +302,11 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
void DarwinProcess_scanThreads(DarwinProcess *dp) { void DarwinProcess_scanThreads(DarwinProcess *dp) {
Process* proc = (Process*) dp; Process* proc = (Process*) dp;
kern_return_t ret; kern_return_t ret;
if (!dp->taskAccess) { if (!dp->taskAccess) {
return; return;
} }
if (proc->state == 'Z') { if (proc->state == 'Z') {
return; return;
} }
@ -317,7 +317,7 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) {
dp->taskAccess = false; dp->taskAccess = false;
return; return;
} }
task_info_data_t tinfo; task_info_data_t tinfo;
mach_msg_type_number_t task_info_count = TASK_INFO_MAX; 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); 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; dp->taskAccess = false;
return; return;
} }
thread_array_t thread_list; thread_array_t thread_list;
mach_msg_type_number_t thread_count; mach_msg_type_number_t thread_count;
ret = task_threads(port, &thread_list, &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); mach_port_deallocate(mach_task_self(), port);
return; return;
} }
integer_t run_state = 999; integer_t run_state = 999;
for (unsigned int i = 0; i < thread_count; i++) { for (unsigned int i = 0; i < thread_count; i++) {
thread_info_data_t thinfo; thread_info_data_t thinfo;

View File

@ -565,7 +565,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
if (kproc->kp_flags & P_JAILED) { if (kproc->kp_flags & P_JAILED) {
proc->state = 'J'; proc->state = 'J';
} }
if (Process_isKernelThread(dfp)) { if (Process_isKernelThread(dfp)) {
this->kernelThreads++; this->kernelThreads++;
} }

26
htop.c
View File

@ -34,7 +34,7 @@ static void printVersionFlag() {
stdout); stdout);
exit(0); exit(0);
} }
static void printHelpFlag() { static void printHelpFlag() {
fputs("htop " VERSION " - " COPYRIGHT "\n" fputs("htop " VERSION " - " COPYRIGHT "\n"
"Released under the GNU GPL.\n\n" "Released under the GNU GPL.\n\n"
@ -196,12 +196,12 @@ int main(int argc, char** argv) {
exit(1); exit(1);
} }
#endif #endif
Process_setupColumnWidths(); Process_setupColumnWidths();
UsersTable* ut = UsersTable_new(); UsersTable* ut = UsersTable_new();
ProcessList* pl = ProcessList_new(ut, flags.pidWhiteList, flags.userId); ProcessList* pl = ProcessList_new(ut, flags.pidWhiteList, flags.userId);
Settings* settings = Settings_new(pl->cpuCount); Settings* settings = Settings_new(pl->cpuCount);
pl->settings = settings; pl->settings = settings;
@ -211,18 +211,18 @@ int main(int argc, char** argv) {
if (flags.delay != -1) if (flags.delay != -1)
settings->delay = flags.delay; settings->delay = flags.delay;
if (!flags.useColors) if (!flags.useColors)
settings->colorScheme = COLORSCHEME_MONOCHROME; settings->colorScheme = COLORSCHEME_MONOCHROME;
if (flags.treeView) if (flags.treeView)
settings->treeView = true; settings->treeView = true;
CRT_init(settings->delay, settings->colorScheme); CRT_init(settings->delay, settings->colorScheme);
MainPanel* panel = MainPanel_new(); MainPanel* panel = MainPanel_new();
ProcessList_setPanel(pl, (Panel*) panel); ProcessList_setPanel(pl, (Panel*) panel);
MainPanel_updateTreeFunctions(panel, settings->treeView); MainPanel_updateTreeFunctions(panel, settings->treeView);
if (flags.sortKey > 0) { if (flags.sortKey > 0) {
settings->sortKey = flags.sortKey; settings->sortKey = flags.sortKey;
settings->treeView = false; settings->treeView = false;
@ -238,7 +238,7 @@ int main(int argc, char** argv) {
.header = header, .header = header,
}; };
MainPanel_setState(panel, &state); MainPanel_setState(panel, &state);
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, true);
ScreenManager_add(scr, (Panel*) panel, -1); ScreenManager_add(scr, (Panel*) panel, -1);
@ -246,13 +246,13 @@ int main(int argc, char** argv) {
millisleep(75); millisleep(75);
ProcessList_scan(pl); ProcessList_scan(pl);
ScreenManager_run(scr, NULL, NULL); ScreenManager_run(scr, NULL, NULL);
attron(CRT_colors[RESET_COLOR]); attron(CRT_colors[RESET_COLOR]);
mvhline(LINES-1, 0, ' ', COLS); mvhline(LINES-1, 0, ' ', COLS);
attroff(CRT_colors[RESET_COLOR]); attroff(CRT_colors[RESET_COLOR]);
refresh(); refresh();
CRT_done(); CRT_done();
if (settings->changed) if (settings->changed)
Settings_write(settings); Settings_write(settings);
@ -260,10 +260,10 @@ int main(int argc, char** argv) {
ProcessList_delete(pl); ProcessList_delete(pl);
ScreenManager_delete(scr); ScreenManager_delete(scr);
UsersTable_delete(ut); UsersTable_delete(ut);
Settings_delete(settings); Settings_delete(settings);
if(flags.pidWhiteList) { if(flags.pidWhiteList) {
Hashtable_delete(flags.pidWhiteList); Hashtable_delete(flags.pidWhiteList);
} }

View File

@ -78,7 +78,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
const unsigned long int foundNum = atoi(foundNumStr); const unsigned long int foundNum = atoi(foundNumStr);
free(foundNumStr); free(foundNumStr);
free(line); free(line);
total += foundNum; 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) { static void Battery_getSysData(double* level, ACPresence* isOnAC) {
*level = 0; *level = 0;
*isOnAC = AC_ERROR; *isOnAC = AC_ERROR;
@ -205,7 +205,6 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
continue; continue;
if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') { if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') {
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName);
int fd = open(filePath, O_RDONLY); int fd = open(filePath, O_RDONLY);
if (fd == -1) { if (fd == -1) {
@ -258,7 +257,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
if (*isOnAC != AC_ERROR) { if (*isOnAC != AC_ERROR) {
continue; continue;
} }
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName);
int fd = open(filePath, O_RDONLY); int fd = open(filePath, O_RDONLY);
if (fd == -1) { if (fd == -1) {

View File

@ -4,7 +4,7 @@ htop - IOPriority.c
Released under the GNU GPL, see the COPYING file Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
Based on ionice, Based on ionice,
Copyright (C) 2005 Jens Axboe <jens@axboe.dk> Copyright (C) 2005 Jens Axboe <jens@axboe.dk>
Released under the terms of the GNU General Public License version 2 Released under the terms of the GNU General Public License version 2
*/ */

View File

@ -8,7 +8,7 @@ htop - IOPriority.h
Released under the GNU GPL, see the COPYING file Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
Based on ionice, Based on ionice,
Copyright (C) 2005 Jens Axboe <jens@axboe.dk> Copyright (C) 2005 Jens Axboe <jens@axboe.dk>
Released under the terms of the GNU General Public License version 2 Released under the terms of the GNU General Public License version 2
*/ */

View File

@ -125,7 +125,7 @@ typedef struct LinuxProcess_ {
unsigned long long io_write_bytes; unsigned long long io_write_bytes;
unsigned long long io_cancelled_write_bytes; unsigned long long io_cancelled_write_bytes;
unsigned long long io_rate_read_time; 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_read_bps;
double io_rate_write_bps; double io_rate_write_bps;
#endif #endif
@ -409,7 +409,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
attr = CRT_colors[PROCESS_HIGH_PRIORITY]; attr = CRT_colors[PROCESS_HIGH_PRIORITY];
xSnprintf(buffer, n, "R%1d ", IOPriority_data(lp->ioPriority)); xSnprintf(buffer, n, "R%1d ", IOPriority_data(lp->ioPriority));
} else if (klass == IOPRIO_CLASS_IDLE) { } else if (klass == IOPRIO_CLASS_IDLE) {
attr = CRT_colors[PROCESS_LOW_PRIORITY]; attr = CRT_colors[PROCESS_LOW_PRIORITY];
xSnprintf(buffer, n, "id "); xSnprintf(buffer, n, "id ");
} else { } else {
xSnprintf(buffer, n, "?? "); xSnprintf(buffer, n, "?? ");

View File

@ -116,7 +116,7 @@ typedef struct LinuxProcess_ {
unsigned long long io_write_bytes; unsigned long long io_write_bytes;
unsigned long long io_cancelled_write_bytes; unsigned long long io_cancelled_write_bytes;
unsigned long long io_rate_read_time; 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_read_bps;
double io_rate_write_bps; double io_rate_write_bps;
#endif #endif

View File

@ -61,7 +61,7 @@ typedef struct CPUData_ {
unsigned long long int softIrqTime; unsigned long long int softIrqTime;
unsigned long long int stealTime; unsigned long long int stealTime;
unsigned long long int guestTime; unsigned long long int guestTime;
unsigned long long int totalPeriod; unsigned long long int totalPeriod;
unsigned long long int userPeriod; unsigned long long int userPeriod;
unsigned long long int systemPeriod; unsigned long long int systemPeriod;
@ -85,11 +85,11 @@ typedef struct TtyDriver_ {
typedef struct LinuxProcessList_ { typedef struct LinuxProcessList_ {
ProcessList super; ProcessList super;
CPUData* cpus; CPUData* cpus;
TtyDriver* ttyDrivers; TtyDriver* ttyDrivers;
bool haveSmapsRollup; bool haveSmapsRollup;
#ifdef HAVE_DELAYACCT #ifdef HAVE_DELAYACCT
struct nl_sock *netlink_socket; struct nl_sock *netlink_socket;
int netlink_family; int netlink_family;
@ -328,7 +328,7 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
location += 2; location += 2;
char *end = strrchr(location, ')'); char *end = strrchr(location, ')');
if (!end) return false; if (!end) return false;
int commsize = end - location; int commsize = end - location;
memcpy(command, location, commsize); memcpy(command, location, commsize);
command[commsize] = '\0'; command[commsize] = '\0';
@ -379,9 +379,9 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
location += 1; location += 1;
assert(location != NULL); assert(location != NULL);
process->processor = strtol(location, &location, 10); process->processor = strtol(location, &location, 10);
process->time = lp->utime + lp->stime; process->time = lp->utime + lp->stime;
return true; return true;
} }
@ -421,7 +421,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
process->io_rate_write_time = -1LL; process->io_rate_write_time = -1LL;
return; return;
} }
char buffer[1024]; char buffer[1024];
ssize_t buflen = xread(fd, buffer, 1023); ssize_t buflen = xread(fd, buffer, 1023);
close(fd); close(fd);
@ -438,7 +438,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
process->io_rchar = strtoull(line+7, NULL, 10); process->io_rchar = strtoull(line+7, NULL, 10);
else if (strncmp(line+1, "ead_bytes: ", 11) == 0) { else if (strncmp(line+1, "ead_bytes: ", 11) == 0) {
process->io_read_bytes = strtoull(line+12, NULL, 10); 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); ((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000);
process->io_rate_read_time = now; process->io_rate_read_time = now;
} }
@ -448,7 +448,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
process->io_wchar = strtoull(line+7, NULL, 10); process->io_wchar = strtoull(line+7, NULL, 10);
else if (strncmp(line+1, "rite_bytes: ", 12) == 0) { else if (strncmp(line+1, "rite_bytes: ", 12) == 0) {
process->io_write_bytes = strtoull(line+13, NULL, 10); 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); ((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000);
process->io_rate_write_time = now; process->io_rate_write_time = now;
} }
@ -726,7 +726,7 @@ static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProc
process->cpu_delay_percent = -1LL; process->cpu_delay_percent = -1LL;
return; return;
} }
if (nl_recvmsgs_default(this->netlink_socket) < 0) { if (nl_recvmsgs_default(this->netlink_socket) < 0) {
return; return;
} }
@ -750,11 +750,11 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
int fd = open(filename, O_RDONLY); int fd = open(filename, O_RDONLY);
if (fd == -1) if (fd == -1)
return false; 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); int amtRead = xread(fd, command, sizeof(command) - 1);
close(fd); close(fd);
int tokenEnd = 0; int tokenEnd = 0;
int lastChar = 0; int lastChar = 0;
if (amtRead == 0) { if (amtRead == 0) {
((LinuxProcess*)process)->isKernelThread = true; ((LinuxProcess*)process)->isKernelThread = true;
@ -791,13 +791,13 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in
i++; i++;
if ((!ttyDrivers[i].path) || maj < ttyDrivers[i].major) { if ((!ttyDrivers[i].path) || maj < ttyDrivers[i].major) {
break; break;
} }
if (maj > ttyDrivers[i].major) { if (maj > ttyDrivers[i].major) {
continue; continue;
} }
if (min < ttyDrivers[i].minorFrom) { if (min < ttyDrivers[i].minorFrom) {
break; break;
} }
if (min > ttyDrivers[i].minorTo) { if (min > ttyDrivers[i].minorTo) {
continue; continue;
} }
@ -855,17 +855,17 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
// filename is a number: process directory // filename is a number: process directory
int pid = atoi(name); int pid = atoi(name);
if (parent && pid == parent->pid) if (parent && pid == parent->pid)
continue; continue;
if (pid <= 0) if (pid <= 0)
continue; continue;
bool preExisting = false; bool preExisting = false;
Process* proc = ProcessList_getProcess(pl, pid, &preExisting, (Process_New) LinuxProcess_new); Process* proc = ProcessList_getProcess(pl, pid, &preExisting, (Process_New) LinuxProcess_new);
proc->tgid = parent ? parent->pid : pid; proc->tgid = parent ? parent->pid : pid;
LinuxProcess* lp = (LinuxProcess*) proc; LinuxProcess* lp = (LinuxProcess*) proc;
char subdirname[MAX_NAME+1]; char subdirname[MAX_NAME+1];
@ -926,7 +926,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
LinuxProcessList_readOpenVZData(lp, dirname, name); LinuxProcessList_readOpenVZData(lp, dirname, name);
} }
#endif #endif
#ifdef HAVE_VSERVER #ifdef HAVE_VSERVER
if (settings->flags & PROCESS_FLAG_LINUX_VSERVER) { if (settings->flags & PROCESS_FLAG_LINUX_VSERVER) {
LinuxProcessList_readVServerData(lp, dirname, name); LinuxProcessList_readVServerData(lp, dirname, name);
@ -954,7 +954,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
if (settings->flags & PROCESS_FLAG_LINUX_CGROUP) if (settings->flags & PROCESS_FLAG_LINUX_CGROUP)
LinuxProcessList_readCGroupFile(lp, dirname, name); LinuxProcessList_readCGroupFile(lp, dirname, name);
#endif #endif
if (settings->flags & PROCESS_FLAG_LINUX_OOM) if (settings->flags & PROCESS_FLAG_LINUX_OOM)
LinuxProcessList_readOomData(lp, dirname, name); LinuxProcessList_readOomData(lp, dirname, name);

View File

@ -34,7 +34,7 @@ typedef struct CPUData_ {
unsigned long long int softIrqTime; unsigned long long int softIrqTime;
unsigned long long int stealTime; unsigned long long int stealTime;
unsigned long long int guestTime; unsigned long long int guestTime;
unsigned long long int totalPeriod; unsigned long long int totalPeriod;
unsigned long long int userPeriod; unsigned long long int userPeriod;
unsigned long long int systemPeriod; unsigned long long int systemPeriod;
@ -58,11 +58,11 @@ typedef struct TtyDriver_ {
typedef struct LinuxProcessList_ { typedef struct LinuxProcessList_ {
ProcessList super; ProcessList super;
CPUData* cpus; CPUData* cpus;
TtyDriver* ttyDrivers; TtyDriver* ttyDrivers;
bool haveSmapsRollup; bool haveSmapsRollup;
#ifdef HAVE_DELAYACCT #ifdef HAVE_DELAYACCT
struct nl_sock *netlink_socket; struct nl_sock *netlink_socket;
int netlink_family; int netlink_family;

View File

@ -35,7 +35,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
size_t sdlen = sizeof(struct sensordev); size_t sdlen = sizeof(struct sensordev);
bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen); bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen);
*level = -1; *level = -1;
if (found) { if (found) {
/* last full capacity */ /* last full capacity */
@ -58,9 +58,9 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
} }
} }
} }
found = findDevice("acpiac0", mib, &snsrdev, &sdlen); found = findDevice("acpiac0", mib, &snsrdev, &sdlen);
*isOnAC = AC_ERROR; *isOnAC = AC_ERROR;
if (found) { if (found) {
mib[3] = 9; mib[3] = 9;

View File

@ -48,7 +48,7 @@ typedef struct var kvar_t;
typedef struct envAccum_ { typedef struct envAccum_ {
size_t capacity; size_t capacity;
size_t size; size_t size;
size_t bytes; size_t bytes;
char *env; char *env;
} envAccum; } envAccum;
@ -136,7 +136,7 @@ extern char Process_pidFormat[20];
int Platform_getUptime() { int Platform_getUptime() {
int boot_time = 0; int boot_time = 0;
int curr_time = time(NULL); int curr_time = time(NULL);
struct utmpx * ent; struct utmpx * ent;
while (( ent = getutxent() )) { while (( ent = getutxent() )) {
@ -170,7 +170,7 @@ int Platform_getMaxPid() {
vproc = ksvar->v_proc; vproc = ksvar->v_proc;
} }
if (kc != NULL) { kstat_close(kc); } if (kc != NULL) { kstat_close(kc); }
return vproc; return vproc;
} }
double Platform_setCPUValues(Meter* this, int cpu) { 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) { static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) {
envAccum *accump = accum; envAccum *accump = accum;
(void) Phandle; (void) Phandle;
(void) addr; (void) addr;
size_t thissz = strlen(str); 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); 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)); strlcpy( accump->env + accump->size, str, (accump->capacity - accump->size));
strncpy( accump->env + accump->size + thissz + 1, "\n", 1); strncpy( accump->env + accump->size + thissz + 1, "\n", 1);
accump->size = accump->size + thissz + 1; accump->size = accump->size + thissz + 1;
return 0; return 0;
} }
char* Platform_getProcessEnv(pid_t pid) { char* Platform_getProcessEnv(pid_t pid) {
@ -240,7 +240,7 @@ char* Platform_getProcessEnv(pid_t pid) {
pid_t realpid = pid / 1024; pid_t realpid = pid / 1024;
int graberr; 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."; return "Unable to read process environment.";
@ -248,7 +248,7 @@ char* Platform_getProcessEnv(pid_t pid) {
envBuilder.size = 0; envBuilder.size = 0;
envBuilder.env = xMalloc(envBuilder.capacity); envBuilder.env = xMalloc(envBuilder.capacity);
(void) Penv_iter(Phandle,Platform_buildenv,&envBuilder); (void) Penv_iter(Phandle,Platform_buildenv,&envBuilder);
Prelease(Phandle, 0); Prelease(Phandle, 0);

View File

@ -27,7 +27,7 @@ typedef struct var kvar_t;
typedef struct envAccum_ { typedef struct envAccum_ {
size_t capacity; size_t capacity;
size_t size; size_t size;
size_t bytes; size_t bytes;
char *env; char *env;
} envAccum; } envAccum;

View File

@ -155,7 +155,7 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
idlebuf += cpuData->idlePercent; idlebuf += cpuData->idlePercent;
} }
} }
if (cpus > 1) { if (cpus > 1) {
CPUData* cpuData = &(spl->cpus[0]); CPUData* cpuData = &(spl->cpus[0]);
cpuData->userPercent = userbuf / cpus; cpuData->userPercent = userbuf / cpus;
@ -179,7 +179,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
uint64_t totalswap = 0; uint64_t totalswap = 0;
uint64_t totalfree = 0; uint64_t totalfree = 0;
int nswap = 0; int nswap = 0;
char *spath = NULL; char *spath = NULL;
char *spathbase = NULL; char *spathbase = NULL;
// Part 1 - physical memory // Part 1 - physical memory
@ -193,7 +193,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
pl->totalMem = totalmem_pgs->value.ui64 * PAGE_SIZE_KB; pl->totalMem = totalmem_pgs->value.ui64 * PAGE_SIZE_KB;
pl->usedMem = lockedmem_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! // 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 // Not really "buffers" but the best Solaris analogue that I can find to
// "memory in use but not by programs or the kernel itself" // "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) * PAGE_SIZE_KB;
@ -204,12 +204,12 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
pl->cachedMem = 0; pl->cachedMem = 0;
pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * PAGE_SIZE); pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * PAGE_SIZE);
} }
// Part 2 - swap // Part 2 - swap
nswap = swapctl(SC_GETNSWP, NULL); nswap = swapctl(SC_GETNSWP, NULL);
if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); } if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); }
if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); } if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); }
if (spathbase != NULL) { if (spathbase != NULL) {
spath = spathbase; spath = spathbase;
swapdev = sl->swt_ent; swapdev = sl->swt_ent;
for (int i = 0; i < nswap; i++, swapdev++) { for (int i = 0; i < nswap; i++, swapdev++) {
@ -219,7 +219,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
sl->swt_n = nswap; sl->swt_n = nswap;
} }
nswap = swapctl(SC_LIST, sl); nswap = swapctl(SC_LIST, sl);
if (nswap > 0) { if (nswap > 0) {
swapdev = sl->swt_ent; swapdev = sl->swt_ent;
for (int i = 0; i < nswap; i++, swapdev++) { for (int i = 0; i < nswap; i++, swapdev++) {
totalswap += swapdev->ste_pages; totalswap += swapdev->ste_pages;
@ -229,7 +229,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
free(spathbase); free(spathbase);
free(sl); free(sl);
pl->totalSwap = totalswap * PAGE_SIZE_KB; 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) { void ProcessList_delete(ProcessList* pl) {
@ -244,7 +244,7 @@ void ProcessList_delete(ProcessList* pl) {
* and MUST conform to the appropriate definition in order * and MUST conform to the appropriate definition in order
* to work. See libproc(3LIB) on a Solaris or Illumos * to work. See libproc(3LIB) on a Solaris or Illumos
* system for more info. * 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) {
struct timeval tv; struct timeval tv;
@ -264,7 +264,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *
getpid = _psinfo->pr_pid * 1024; getpid = _psinfo->pr_pid * 1024;
} else { } else {
getpid = lwpid; getpid = lwpid;
} }
Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, (Process_New) SolarisProcess_new); Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, (Process_New) SolarisProcess_new);
SolarisProcess *sproc = (SolarisProcess*) proc; SolarisProcess *sproc = (SolarisProcess*) proc;
@ -295,7 +295,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *
sproc->realpid = _psinfo->pr_pid; sproc->realpid = _psinfo->pr_pid;
sproc->lwpid = lwpid_real; sproc->lwpid = lwpid_real;
sproc->zoneid = _psinfo->pr_zoneid; 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->user = UsersTable_getRef(pl->usersTable, proc->st_uid);
proc->comm = xStrdup(_psinfo->pr_fname); proc->comm = xStrdup(_psinfo->pr_fname);
proc->commLen = strnlen(_psinfo->pr_fname,PRFNSZ); proc->commLen = strnlen(_psinfo->pr_fname,PRFNSZ);
@ -334,7 +334,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->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu/(double)32768)*(double)100.0;
proc->time = _lwpsinfo->pr_time.tv_sec; proc->time = _lwpsinfo->pr_time.tv_sec;
if (!preExisting) { // Tasks done only for NEW LWPs if (!preExisting) { // Tasks done only for NEW LWPs
sproc->is_lwp = true; sproc->is_lwp = true;
proc->basenameOffset = -1; proc->basenameOffset = -1;
proc->ppid = _psinfo->pr_pid * 1024; proc->ppid = _psinfo->pr_pid * 1024;
proc->tgid = _psinfo->pr_pid * 1024; proc->tgid = _psinfo->pr_pid * 1024;

View File

@ -56,7 +56,7 @@ void ProcessList_delete(ProcessList* pl);
* and MUST conform to the appropriate definition in order * and MUST conform to the appropriate definition in order
* to work. See libproc(3LIB) on a Solaris or Illumos * to work. See libproc(3LIB) on a Solaris or Illumos
* system for more info. * 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);

View File

@ -18,7 +18,7 @@ in the source distribution for its full text.
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
ProcessList* this = xCalloc(1, sizeof(ProcessList)); ProcessList* this = xCalloc(1, sizeof(ProcessList));
ProcessList_init(this, Class(Process), usersTable, pidWhiteList, userId); ProcessList_init(this, Class(Process), usersTable, pidWhiteList, userId);
return this; return this;
} }