mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 05:24:36 +03:00
Compare commits
71 Commits
Author | SHA1 | Date | |
---|---|---|---|
f80e577c59 | |||
81552d4ab5 | |||
265d04821a | |||
78b82d0fdc | |||
7f9c82f28d | |||
7d5ef246f1 | |||
0fa03322a9 | |||
52f814481c | |||
b139671cbd | |||
adcc944e35 | |||
a5ef374bb8 | |||
6dd32d3604 | |||
8cd045cc79 | |||
0128d222b9 | |||
1a13b4d0f4 | |||
9ec41d1b65 | |||
c0e37bc5f5 | |||
f9c1db514d | |||
3297616efa | |||
e288f690af | |||
ea9dc4ab74 | |||
112db9a609 | |||
5db1b0e9a0 | |||
4674b4a732 | |||
7ededce9b5 | |||
3126cfce6c | |||
313b3d3752 | |||
fa0c637c55 | |||
b7ac416634 | |||
6cc0a8c820 | |||
645057d81a | |||
6c1be63291 | |||
642ccb49ca | |||
6028e1b4c4 | |||
95d1984339 | |||
c0df404701 | |||
b71b07f5e0 | |||
f0df28a470 | |||
7d72715a6b | |||
54621e8b8f | |||
572546f806 | |||
d464be13db | |||
759caf0f8f | |||
cdc91b0b33 | |||
1754a1cd48 | |||
8e6ffdb0ab | |||
c37be409a9 | |||
fa1b5d1e2e | |||
19f0f4db27 | |||
9dea20e068 | |||
2ea4bee66d | |||
1809f4be98 | |||
5776cb56b4 | |||
74f8b31040 | |||
4d3f483b96 | |||
2de52862a6 | |||
a9508275cc | |||
306c5443ae | |||
d15555ed2c | |||
d64f2bdd56 | |||
6c2f698a47 | |||
7b3c8bc77a | |||
3a4c0fa2d6 | |||
328de35623 | |||
c8a735e471 | |||
99fb3070a2 | |||
7d3f67e822 | |||
3283c6d23c | |||
8a928c8b89 | |||
f295a52ed9 | |||
cc8375f9ea |
4
Action.c
4
Action.c
@ -328,7 +328,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionFollow(State* st) {
|
||||
Htop_Reaction Action_follow(State* st) {
|
||||
st->pl->following = MainPanel_selectedPid((MainPanel*)st->panel);
|
||||
Panel_setSelectionColor(st->panel, CRT_colors[PANEL_SELECTION_FOLLOW]);
|
||||
return HTOP_KEEP_FOLLOWING;
|
||||
@ -557,7 +557,7 @@ void Action_setBindings(Htop_Action* keys) {
|
||||
keys['='] = actionExpandOrCollapse;
|
||||
keys['-'] = actionExpandOrCollapse;
|
||||
keys['u'] = actionFilterByUser;
|
||||
keys['F'] = actionFollow;
|
||||
keys['F'] = Action_follow;
|
||||
keys['S'] = actionSetup;
|
||||
keys['C'] = actionSetup;
|
||||
keys[KEY_F(2)] = actionSetup;
|
||||
|
2
Action.h
2
Action.h
@ -49,6 +49,8 @@ Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
Htop_Reaction Action_follow(State* st);
|
||||
|
||||
|
||||
void Action_setBindings(Htop_Action* keys);
|
||||
|
||||
|
@ -112,20 +112,22 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade
|
||||
this->scr = scr;
|
||||
|
||||
Panel_setHeader(super, "Available meters");
|
||||
// Platform_meterTypes[0] should be always (&CPUMeter_class), which we will
|
||||
// handle separately in the code below.
|
||||
for (int i = 1; Platform_meterTypes[i]; i++) {
|
||||
MeterClass* type = Platform_meterTypes[i];
|
||||
if (type != &CPUMeter_class) {
|
||||
const char* label = type->description ? type->description : type->uiName;
|
||||
Panel_add(super, (Object*) ListItem_new(label, i << 16));
|
||||
}
|
||||
assert(type != &CPUMeter_class);
|
||||
const char* label = type->description ? type->description : type->uiName;
|
||||
Panel_add(super, (Object*) ListItem_new(label, i << 16));
|
||||
}
|
||||
// Handle (&CPUMeter_class)
|
||||
MeterClass* type = &CPUMeter_class;
|
||||
int cpus = pl->cpuCount;
|
||||
if (cpus > 1) {
|
||||
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
|
||||
for (int i = 1; i <= cpus; i++) {
|
||||
char buffer[50];
|
||||
sprintf(buffer, "%s %d", type->uiName, i);
|
||||
snprintf(buffer, 50, "%s %d", type->uiName, i);
|
||||
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
||||
}
|
||||
} else {
|
||||
|
@ -32,7 +32,7 @@ int BatteryMeter_attributes[] = {
|
||||
BATTERY
|
||||
};
|
||||
|
||||
static void BatteryMeter_setValues(Meter * this, char *buffer, int len) {
|
||||
static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) {
|
||||
ACPresence isOnAC;
|
||||
double percent;
|
||||
|
||||
@ -73,8 +73,9 @@ MeterClass BatteryMeter_class = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete
|
||||
},
|
||||
.setValues = BatteryMeter_setValues,
|
||||
.updateValues = BatteryMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = BatteryMeter_attributes,
|
||||
.name = "Battery",
|
||||
|
@ -55,7 +55,7 @@ static void CPUMeter_init(Meter* this) {
|
||||
Meter_setCaption(this, "Avg");
|
||||
}
|
||||
|
||||
static void CPUMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
int cpu = this->param;
|
||||
if (cpu > this->pl->cpuCount) {
|
||||
snprintf(buffer, size, "absent");
|
||||
@ -215,7 +215,7 @@ MeterClass CPUMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = CPUMeter_display
|
||||
},
|
||||
.setValues = CPUMeter_setValues,
|
||||
.updateValues = CPUMeter_updateValues,
|
||||
.defaultMode = BAR_METERMODE,
|
||||
.maxItems = CPU_METER_ITEMCOUNT,
|
||||
.total = 100.0,
|
||||
@ -312,8 +312,8 @@ MeterClass LeftCPUs2Meter_class = {
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "LeftCPUs2",
|
||||
.description = "CPUs (1&2/4): first half in 2 shorter columns",
|
||||
.uiName = "CPUs (1&2/4)",
|
||||
.description = "CPUs (1&2/4): first half in 2 shorter columns",
|
||||
.caption = "CPU",
|
||||
.draw = DualColCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
|
3
CRT.c
3
CRT.c
@ -125,7 +125,7 @@ void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn);
|
||||
|
||||
#define KEY_ALT(x) KEY_F(60) + (x - 'A')
|
||||
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
||||
|
||||
}*/
|
||||
|
||||
@ -599,6 +599,7 @@ void CRT_init(int delay, int colorScheme) {
|
||||
signal(11, CRT_handleSIGSEGV);
|
||||
#endif
|
||||
signal(SIGTERM, CRT_handleSIGTERM);
|
||||
signal(SIGQUIT, CRT_handleSIGTERM);
|
||||
use_default_colors();
|
||||
if (!has_colors())
|
||||
CRT_colorScheme = 1;
|
||||
|
2
CRT.h
2
CRT.h
@ -115,7 +115,7 @@ void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn);
|
||||
|
||||
#define KEY_ALT(x) KEY_F(60) + (x - 'A')
|
||||
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
||||
|
||||
|
||||
extern const char *CRT_treeStrAscii[TREE_STR_COUNT];
|
||||
|
@ -82,9 +82,9 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||
result = HANDLED;
|
||||
break;
|
||||
case KEY_UP:
|
||||
case KEY_CTRLP:
|
||||
case KEY_CTRL('P'):
|
||||
case KEY_DOWN:
|
||||
case KEY_CTRLN:
|
||||
case KEY_CTRL('N'):
|
||||
case KEY_NPAGE:
|
||||
case KEY_PPAGE:
|
||||
case KEY_HOME:
|
||||
|
15
ChangeLog
15
ChangeLog
@ -1,4 +1,19 @@
|
||||
|
||||
What's new in version 2.0.2
|
||||
|
||||
* Mac OS X: stop trying when task_for_pid fails for a process,
|
||||
stops spamming logs with errors.
|
||||
* Add Ctrl+A and Ctrl+E to go to beginning and end of line
|
||||
* FreeBSD: fixes for CPU calculation
|
||||
(thanks to Tim Creech, Andy Pilate)
|
||||
* Usability: auto-follow process after a search.
|
||||
* Use Linux backend on GNU Hurd
|
||||
* Improvement for reproducible builds.
|
||||
* BUGFIX: Fix behavior of Alt-key combinations
|
||||
(thanks to Kang-Che Sung)
|
||||
* Various code tweaks and cleanups
|
||||
(thanks to Kang-Che Sung)
|
||||
|
||||
What's new in version 2.0.1
|
||||
|
||||
* OpenBSD: Various fixes and improvements
|
||||
|
@ -19,7 +19,7 @@ int ClockMeter_attributes[] = {
|
||||
CLOCK
|
||||
};
|
||||
|
||||
static void ClockMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void ClockMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
time_t t = time(NULL);
|
||||
struct tm result;
|
||||
struct tm *lt = localtime_r(&t, &result);
|
||||
@ -32,8 +32,9 @@ MeterClass ClockMeter_class = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete
|
||||
},
|
||||
.setValues = ClockMeter_setValues,
|
||||
.updateValues = ClockMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 1440, /* 24*60 */
|
||||
.attributes = ClockMeter_attributes,
|
||||
.name = "Clock",
|
||||
|
@ -49,9 +49,9 @@ void EnvScreen_scan(InfoScreen* this) {
|
||||
Panel_prune(panel);
|
||||
|
||||
uid_t euid = geteuid();
|
||||
seteuid(getuid());
|
||||
(void) seteuid(getuid());
|
||||
char *env = Platform_getProcessEnv(this->process->pid);
|
||||
seteuid(euid);
|
||||
(void) seteuid(euid);
|
||||
if (env) {
|
||||
for (char *p = env; *p; p = strrchr(p, 0)+1)
|
||||
InfoScreen_addLine(this, p);
|
||||
|
2
Header.c
2
Header.c
@ -37,7 +37,7 @@ typedef struct Header_ {
|
||||
#endif
|
||||
|
||||
#ifndef Header_forEachColumn
|
||||
#define Header_forEachColumn(this_, i_) for (int i_=0; i_ < this->nrColumns; i_++)
|
||||
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
||||
#endif
|
||||
|
||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) {
|
||||
|
2
Header.h
2
Header.h
@ -28,7 +28,7 @@ typedef struct Header_ {
|
||||
#endif
|
||||
|
||||
#ifndef Header_forEachColumn
|
||||
#define Header_forEachColumn(this_, i_) for (int i_=0; i_ < this->nrColumns; i_++)
|
||||
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
||||
#endif
|
||||
|
||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns);
|
||||
|
@ -19,7 +19,7 @@ int HostnameMeter_attributes[] = {
|
||||
HOSTNAME
|
||||
};
|
||||
|
||||
static void HostnameMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void HostnameMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
(void) this;
|
||||
gethostname(buffer, size-1);
|
||||
}
|
||||
@ -29,8 +29,9 @@ MeterClass HostnameMeter_class = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete
|
||||
},
|
||||
.setValues = HostnameMeter_setValues,
|
||||
.updateValues = HostnameMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 0,
|
||||
.total = 100.0,
|
||||
.attributes = HostnameMeter_attributes,
|
||||
.name = "Hostname",
|
||||
|
4
INSTALL
4
INSTALL
@ -12,8 +12,8 @@ without warranty of any kind.
|
||||
Basic Installation
|
||||
==================
|
||||
|
||||
Briefly, the shell commands `./configure; make; make install' should
|
||||
configure, build, and install this package. The following
|
||||
Briefly, the shell command `./configure && make && make install'
|
||||
should configure, build, and install this package. The following
|
||||
more-detailed instructions are generic; see the `README' file for
|
||||
instructions specific to this package. Some packages provide this
|
||||
`INSTALL' file but do not implement all of the features documented
|
||||
|
44
IncSet.c
44
IncSet.c
@ -40,6 +40,7 @@ typedef struct IncSet_ {
|
||||
IncMode* active;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
bool found;
|
||||
} IncSet;
|
||||
|
||||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||
@ -114,7 +115,7 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
|
||||
}
|
||||
}
|
||||
|
||||
static void search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
int size = Panel_size(panel);
|
||||
bool found = false;
|
||||
for (int i = 0; i < size; i++) {
|
||||
@ -128,6 +129,7 @@ static void search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa
|
||||
FunctionBar_draw(mode->bar, mode->buffer);
|
||||
else
|
||||
FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) {
|
||||
@ -151,24 +153,30 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
}
|
||||
}
|
||||
doSearch = false;
|
||||
} else if (ch < 255 && isprint((char)ch) && (mode->index < INCMODE_MAX)) {
|
||||
mode->buffer[mode->index] = ch;
|
||||
mode->index++;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
filterChanged = true;
|
||||
if (mode->index == 1) this->filtering = true;
|
||||
}
|
||||
} else if ((ch == KEY_BACKSPACE || ch == 127) && (mode->index > 0)) {
|
||||
mode->index--;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
filterChanged = true;
|
||||
if (mode->index == 0) {
|
||||
this->filtering = false;
|
||||
IncMode_reset(mode);
|
||||
} else if (ch < 255 && isprint((char)ch)) {
|
||||
if (mode->index < INCMODE_MAX) {
|
||||
mode->buffer[mode->index] = ch;
|
||||
mode->index++;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
filterChanged = true;
|
||||
if (mode->index == 1) this->filtering = true;
|
||||
}
|
||||
}
|
||||
} else if ((ch == KEY_BACKSPACE || ch == 127)) {
|
||||
if (mode->index > 0) {
|
||||
mode->index--;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
filterChanged = true;
|
||||
if (mode->index == 0) {
|
||||
this->filtering = false;
|
||||
IncMode_reset(mode);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doSearch = false;
|
||||
}
|
||||
} else if (ch == KEY_RESIZE) {
|
||||
Panel_resize(panel, COLS, LINES-panel->y-1);
|
||||
} else {
|
||||
@ -187,7 +195,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
doSearch = false;
|
||||
}
|
||||
if (doSearch) {
|
||||
search(mode, panel, getPanelValue);
|
||||
this->found = search(mode, panel, getPanelValue);
|
||||
}
|
||||
if (filterChanged && lines) {
|
||||
updateWeakPanel(this, panel, lines);
|
||||
|
1
IncSet.h
1
IncSet.h
@ -35,6 +35,7 @@ typedef struct IncSet_ {
|
||||
IncMode* active;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
bool found;
|
||||
} IncSet;
|
||||
|
||||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||
|
@ -83,6 +83,7 @@ void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...) {
|
||||
wmove(stdscr, 0, 0);
|
||||
vw_printw(stdscr, fmt, ap);
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
this->display->needsRedraw = true;
|
||||
Panel_draw(this->display, true);
|
||||
IncSet_drawBar(this->inc);
|
||||
va_end(ap);
|
||||
@ -116,7 +117,7 @@ void InfoScreen_run(InfoScreen* this) {
|
||||
|
||||
if (this->inc->active)
|
||||
move(LINES-1, CRT_cursorX);
|
||||
ESCDELAY = 25;
|
||||
set_escdelay(25);
|
||||
int ch = getch();
|
||||
|
||||
if (ch == ERR) {
|
||||
|
@ -20,7 +20,7 @@ int LoadAverageMeter_attributes[] = {
|
||||
|
||||
int LoadMeter_attributes[] = { LOAD };
|
||||
|
||||
static void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]);
|
||||
snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
|
||||
}
|
||||
@ -36,7 +36,7 @@ static void LoadAverageMeter_display(Object* cast, RichString* out) {
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
|
||||
}
|
||||
|
||||
static void LoadMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void LoadMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
double five, fifteen;
|
||||
Platform_getLoadAverage(&this->values[0], &five, &fifteen);
|
||||
if (this->values[0] > this->total) {
|
||||
@ -58,7 +58,7 @@ MeterClass LoadAverageMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = LoadAverageMeter_display,
|
||||
},
|
||||
.setValues = LoadAverageMeter_setValues,
|
||||
.updateValues = LoadAverageMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 3,
|
||||
.total = 100.0,
|
||||
@ -75,8 +75,9 @@ MeterClass LoadMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = LoadMeter_display,
|
||||
},
|
||||
.setValues = LoadMeter_setValues,
|
||||
.updateValues = LoadMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = LoadMeter_attributes,
|
||||
.name = "Load",
|
||||
|
19
MainPanel.c
19
MainPanel.c
@ -83,6 +83,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||
result = HANDLED;
|
||||
} else if (ch != ERR && this->inc->active) {
|
||||
bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
|
||||
if (this->inc->found) {
|
||||
reaction |= Action_follow(this->state);
|
||||
}
|
||||
if (filterChanged) {
|
||||
this->state->pl->incFilter = IncSet_filter(this->inc);
|
||||
reaction = HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||
@ -102,20 +105,6 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||
} else {
|
||||
reaction |= HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
switch (ch) {
|
||||
case KEY_LEFT:
|
||||
case KEY_CTRLB:
|
||||
if (super->scrollH > 0) {
|
||||
super->scrollH -= CRT_scrollHAmount;
|
||||
super->needsRedraw = true;
|
||||
}
|
||||
return HANDLED;
|
||||
case KEY_RIGHT:
|
||||
case KEY_CTRLF:
|
||||
super->scrollH += CRT_scrollHAmount;
|
||||
super->needsRedraw = true;
|
||||
return HANDLED;
|
||||
}
|
||||
}
|
||||
|
||||
if (reaction & HTOP_REDRAW_BAR) {
|
||||
@ -159,7 +148,7 @@ const char* MainPanel_getValue(MainPanel* this, int i) {
|
||||
return "";
|
||||
}
|
||||
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, int arg, bool* wasAnyTagged) {
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged) {
|
||||
Panel* super = (Panel*) this;
|
||||
bool ok = true;
|
||||
bool anyTagged = false;
|
||||
|
@ -34,7 +34,7 @@ int MainPanel_selectedPid(MainPanel* this);
|
||||
|
||||
const char* MainPanel_getValue(MainPanel* this, int i);
|
||||
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, int arg, bool* wasAnyTagged);
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged);
|
||||
|
||||
extern PanelClass MainPanel_class;
|
||||
|
||||
|
@ -24,7 +24,7 @@ int MemoryMeter_attributes[] = {
|
||||
MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE
|
||||
};
|
||||
|
||||
static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
int written;
|
||||
Platform_setMemoryValues(this);
|
||||
|
||||
@ -60,7 +60,7 @@ MeterClass MemoryMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = MemoryMeter_display,
|
||||
},
|
||||
.setValues = MemoryMeter_setValues,
|
||||
.updateValues = MemoryMeter_updateValues,
|
||||
.defaultMode = BAR_METERMODE,
|
||||
.maxItems = 3,
|
||||
.total = 100.0,
|
||||
|
39
Meter.c
39
Meter.c
@ -37,7 +37,7 @@ typedef struct Meter_ Meter;
|
||||
typedef void(*Meter_Init)(Meter*);
|
||||
typedef void(*Meter_Done)(Meter*);
|
||||
typedef void(*Meter_UpdateMode)(Meter*, int);
|
||||
typedef void(*Meter_SetValues)(Meter*, char*, int);
|
||||
typedef void(*Meter_UpdateValues)(Meter*, char*, int);
|
||||
typedef void(*Meter_Draw)(Meter*, int, int, int);
|
||||
|
||||
typedef struct MeterClass_ {
|
||||
@ -46,7 +46,7 @@ typedef struct MeterClass_ {
|
||||
const Meter_Done done;
|
||||
const Meter_UpdateMode updateMode;
|
||||
const Meter_Draw draw;
|
||||
const Meter_SetValues setValues;
|
||||
const Meter_UpdateValues updateValues;
|
||||
const int defaultMode;
|
||||
const double total;
|
||||
const int* attributes;
|
||||
@ -66,7 +66,8 @@ typedef struct MeterClass_ {
|
||||
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
|
||||
#define Meter_drawFn(this_) As_Meter(this_)->draw
|
||||
#define Meter_doneFn(this_) As_Meter(this_)->done
|
||||
#define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_)
|
||||
#define Meter_updateValues(this_, buf_, sz_) \
|
||||
As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_)
|
||||
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
|
||||
#define Meter_getItems(this_) As_Meter(this_)->curItems
|
||||
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
|
||||
@ -132,12 +133,8 @@ Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) {
|
||||
this->h = 1;
|
||||
this->param = param;
|
||||
this->pl = pl;
|
||||
char maxItems = type->maxItems;
|
||||
if (maxItems == 0) {
|
||||
maxItems = 1;
|
||||
}
|
||||
type->curItems = maxItems;
|
||||
this->values = xCalloc(maxItems, sizeof(double));
|
||||
type->curItems = type->maxItems;
|
||||
this->values = xCalloc(type->maxItems, sizeof(double));
|
||||
this->total = type->total;
|
||||
this->caption = xStrdup(type->caption);
|
||||
if (Meter_initFn(this))
|
||||
@ -184,8 +181,7 @@ void Meter_delete(Object* cast) {
|
||||
if (Meter_doneFn(this)) {
|
||||
Meter_done(this);
|
||||
}
|
||||
if (this->drawData)
|
||||
free(this->drawData);
|
||||
free(this->drawData);
|
||||
free(this->caption);
|
||||
free(this->values);
|
||||
free(this);
|
||||
@ -216,8 +212,7 @@ void Meter_setMode(Meter* this, int modeIndex) {
|
||||
Meter_updateMode(this, modeIndex);
|
||||
} else {
|
||||
assert(modeIndex >= 1);
|
||||
if (this->drawData)
|
||||
free(this->drawData);
|
||||
free(this->drawData);
|
||||
this->drawData = NULL;
|
||||
|
||||
MeterMode* mode = Meter_modes[modeIndex];
|
||||
@ -249,7 +244,7 @@ ListItem* Meter_toListItem(Meter* this, bool moving) {
|
||||
|
||||
static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
char buffer[METER_BUFFER_LEN];
|
||||
Meter_setValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
(void) w;
|
||||
|
||||
attrset(CRT_colors[METER_TEXT]);
|
||||
@ -269,7 +264,7 @@ static char BarMeterMode_characters[] = "|#*@$%&.";
|
||||
|
||||
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
char buffer[METER_BUFFER_LEN];
|
||||
Meter_setValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
|
||||
w -= 2;
|
||||
attrset(CRT_colors[METER_TEXT]);
|
||||
@ -291,11 +286,8 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
char bar[w + 1];
|
||||
|
||||
int blockSizes[10];
|
||||
for (int i = 0; i < w; i++)
|
||||
bar[i] = ' ';
|
||||
|
||||
const size_t barOffset = w - MIN((int)strlen(buffer), w);
|
||||
snprintf(bar + barOffset, w - barOffset + 1, "%s", buffer);
|
||||
snprintf(bar, w + 1, "%*s", w, buffer);
|
||||
|
||||
// First draw in the bar[] buffer...
|
||||
int offset = 0;
|
||||
@ -397,7 +389,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
data->values[i] = data->values[i+1];
|
||||
|
||||
char buffer[nValues];
|
||||
Meter_setValues(this, buffer, nValues - 1);
|
||||
Meter_updateValues(this, buffer, nValues - 1);
|
||||
|
||||
double value = 0.0;
|
||||
int items = Meter_getItems(this);
|
||||
@ -466,7 +458,7 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
LEDMeterMode_digits = LEDMeterMode_digitsAscii;
|
||||
|
||||
char buffer[METER_BUFFER_LEN];
|
||||
Meter_setValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
|
||||
RichString_begin(out);
|
||||
Meter_displayBuffer(this, buffer, &out);
|
||||
@ -529,7 +521,7 @@ MeterMode* Meter_modes[] = {
|
||||
|
||||
/* Blank meter */
|
||||
|
||||
static void BlankMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void BlankMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
(void) this; (void) buffer; (void) size;
|
||||
}
|
||||
|
||||
@ -548,8 +540,9 @@ MeterClass BlankMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = BlankMeter_display,
|
||||
},
|
||||
.setValues = BlankMeter_setValues,
|
||||
.updateValues = BlankMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 0,
|
||||
.total = 100.0,
|
||||
.attributes = BlankMeter_attributes,
|
||||
.name = "Blank",
|
||||
|
7
Meter.h
7
Meter.h
@ -24,7 +24,7 @@ typedef struct Meter_ Meter;
|
||||
typedef void(*Meter_Init)(Meter*);
|
||||
typedef void(*Meter_Done)(Meter*);
|
||||
typedef void(*Meter_UpdateMode)(Meter*, int);
|
||||
typedef void(*Meter_SetValues)(Meter*, char*, int);
|
||||
typedef void(*Meter_UpdateValues)(Meter*, char*, int);
|
||||
typedef void(*Meter_Draw)(Meter*, int, int, int);
|
||||
|
||||
typedef struct MeterClass_ {
|
||||
@ -33,7 +33,7 @@ typedef struct MeterClass_ {
|
||||
const Meter_Done done;
|
||||
const Meter_UpdateMode updateMode;
|
||||
const Meter_Draw draw;
|
||||
const Meter_SetValues setValues;
|
||||
const Meter_UpdateValues updateValues;
|
||||
const int defaultMode;
|
||||
const double total;
|
||||
const int* attributes;
|
||||
@ -53,7 +53,8 @@ typedef struct MeterClass_ {
|
||||
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
|
||||
#define Meter_drawFn(this_) As_Meter(this_)->draw
|
||||
#define Meter_doneFn(this_) As_Meter(this_)->done
|
||||
#define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_)
|
||||
#define Meter_updateValues(this_, buf_, sz_) \
|
||||
As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_)
|
||||
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
|
||||
#define Meter_getItems(this_) As_Meter(this_)->curItems
|
||||
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
|
||||
|
@ -61,6 +61,7 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) {
|
||||
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOLLOW]);
|
||||
super->currentBar = Meters_movingBar;
|
||||
}
|
||||
FunctionBar_draw(this->super.currentBar, NULL);
|
||||
}
|
||||
|
||||
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {
|
||||
@ -99,7 +100,6 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
||||
if (!Vector_size(this->meters))
|
||||
break;
|
||||
MetersPanel_setMoving(this, !(this->moving));
|
||||
FunctionBar_draw(this->super.currentBar, NULL);
|
||||
result = HANDLED;
|
||||
break;
|
||||
}
|
||||
|
@ -86,17 +86,12 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
pdata->error = 127;
|
||||
return pdata;
|
||||
}
|
||||
while (!feof(fd)) {
|
||||
int cmd = fgetc(fd);
|
||||
if (cmd == EOF)
|
||||
break;
|
||||
char* entry = xMalloc(1024);
|
||||
if (!fgets(entry, 1024, fd)) {
|
||||
free(entry);
|
||||
for (;;) {
|
||||
char* line = String_readLine(fd);
|
||||
if (!line) {
|
||||
break;
|
||||
}
|
||||
char* newline = strrchr(entry, '\n');
|
||||
*newline = '\0';
|
||||
unsigned char cmd = line[0];
|
||||
if (cmd == 'f') {
|
||||
OpenFiles_FileData* nextFile = xCalloc(1, sizeof(OpenFiles_FileData));
|
||||
if (fdata == NULL) {
|
||||
@ -108,7 +103,8 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
item = &(fdata->data);
|
||||
}
|
||||
assert(cmd >= 0 && cmd <= 0xff);
|
||||
item->data[cmd] = entry;
|
||||
item->data[cmd] = xStrdup(line + 1);
|
||||
free(line);
|
||||
}
|
||||
pdata->error = pclose(fd);
|
||||
return pdata;
|
||||
@ -132,9 +128,11 @@ void OpenFilesScreen_scan(InfoScreen* this) {
|
||||
} else {
|
||||
OpenFiles_FileData* fdata = pdata->files;
|
||||
while (fdata) {
|
||||
char entry[1024];
|
||||
char** data = fdata->data.data;
|
||||
sprintf(entry, "%5s %4s %10s %10s %10s %s",
|
||||
int lenN = data['n'] ? strlen(data['n']) : 0;
|
||||
int sizeEntry = 5 + 7 + 10 + 10 + 10 + lenN + 5 /*spaces*/ + 1 /*null*/;
|
||||
char* entry = xMalloc(sizeEntry);
|
||||
snprintf(entry, sizeEntry, "%5.5s %7.7s %10.10s %10.10s %10.10s %s",
|
||||
data['f'] ? data['f'] : "",
|
||||
data['t'] ? data['t'] : "",
|
||||
data['D'] ? data['D'] : "",
|
||||
|
30
Panel.c
30
Panel.c
@ -61,6 +61,7 @@ struct Panel_ {
|
||||
Vector* items;
|
||||
int selected;
|
||||
int oldSelected;
|
||||
int selectedLen;
|
||||
void* eventHandlerState;
|
||||
int scrollV;
|
||||
short scrollH;
|
||||
@ -82,10 +83,7 @@ struct Panel_ {
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#define KEY_CTRLN 0016 /* control-n key */
|
||||
#define KEY_CTRLP 0020 /* control-p key */
|
||||
#define KEY_CTRLF 0006 /* control-f key */
|
||||
#define KEY_CTRLB 0002 /* control-b key */
|
||||
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||
|
||||
PanelClass Panel_class = {
|
||||
.super = {
|
||||
@ -327,6 +325,7 @@ void Panel_draw(Panel* this, bool focus) {
|
||||
if (selected) {
|
||||
attrset(selectionColor);
|
||||
RichString_setAttr(&item, selectionColor);
|
||||
this->selectedLen = itemLen;
|
||||
}
|
||||
mvhline(y + line, x, ' ', this->w);
|
||||
if (amt > 0)
|
||||
@ -352,6 +351,7 @@ void Panel_draw(Panel* this, bool focus) {
|
||||
RichString_begin(new);
|
||||
Object_display(newObj, &new);
|
||||
int newLen = RichString_sizeVal(new);
|
||||
this->selectedLen = newLen;
|
||||
mvhline(y+ this->oldSelected - first, x+0, ' ', this->w);
|
||||
if (scrollH < oldLen)
|
||||
RichString_printoffnVal(old, y+this->oldSelected - first, x,
|
||||
@ -376,11 +376,11 @@ bool Panel_onKey(Panel* this, int key) {
|
||||
int size = Vector_size(this->items);
|
||||
switch (key) {
|
||||
case KEY_DOWN:
|
||||
case KEY_CTRLN:
|
||||
case KEY_CTRL('N'):
|
||||
this->selected++;
|
||||
break;
|
||||
case KEY_UP:
|
||||
case KEY_CTRLP:
|
||||
case KEY_CTRL('P'):
|
||||
this->selected--;
|
||||
break;
|
||||
#ifdef KEY_C_DOWN
|
||||
@ -394,14 +394,14 @@ bool Panel_onKey(Panel* this, int key) {
|
||||
break;
|
||||
#endif
|
||||
case KEY_LEFT:
|
||||
case KEY_CTRLB:
|
||||
case KEY_CTRL('B'):
|
||||
if (this->scrollH > 0) {
|
||||
this->scrollH -= CRT_scrollHAmount;
|
||||
this->scrollH -= MAX(CRT_scrollHAmount, 0);
|
||||
this->needsRedraw = true;
|
||||
}
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
case KEY_CTRLF:
|
||||
case KEY_CTRL('F'):
|
||||
this->scrollH += CRT_scrollHAmount;
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
@ -412,7 +412,7 @@ bool Panel_onKey(Panel* this, int key) {
|
||||
break;
|
||||
case KEY_NPAGE:
|
||||
this->selected += (this->h - 1);
|
||||
this->scrollV += (this->h - 1);
|
||||
this->scrollV = MIN(MAX(0, Vector_size(this->items) - this->h), this->selected - this->h);
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
case KEY_WHEELUP:
|
||||
@ -436,6 +436,16 @@ bool Panel_onKey(Panel* this, int key) {
|
||||
case KEY_END:
|
||||
this->selected = size - 1;
|
||||
break;
|
||||
case KEY_CTRL('A'):
|
||||
case '^':
|
||||
this->scrollH = 0;
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
case KEY_CTRL('E'):
|
||||
case '$':
|
||||
this->scrollH = MAX(this->selectedLen - this->w, 0);
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
6
Panel.h
6
Panel.h
@ -50,6 +50,7 @@ struct Panel_ {
|
||||
Vector* items;
|
||||
int selected;
|
||||
int oldSelected;
|
||||
int selectedLen;
|
||||
void* eventHandlerState;
|
||||
int scrollV;
|
||||
short scrollH;
|
||||
@ -70,10 +71,7 @@ struct Panel_ {
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#define KEY_CTRLN 0016 /* control-n key */
|
||||
#define KEY_CTRLP 0020 /* control-p key */
|
||||
#define KEY_CTRLF 0006 /* control-f key */
|
||||
#define KEY_CTRLB 0002 /* control-b key */
|
||||
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||
|
||||
extern PanelClass Panel_class;
|
||||
|
||||
|
13
Process.c
13
Process.c
@ -48,6 +48,7 @@ in the source distribution for its full text.
|
||||
#define PROCESS_FLAG_IO 0x0001
|
||||
|
||||
typedef enum ProcessFields {
|
||||
NULL_PROCESSFIELD = 0,
|
||||
PID = 1,
|
||||
COMM = 2,
|
||||
STATE = 3,
|
||||
@ -193,7 +194,7 @@ void Process_setupColumnWidths() {
|
||||
assert(digits < 20);
|
||||
for (int i = 0; Process_pidColumns[i].label; i++) {
|
||||
assert(i < 20);
|
||||
sprintf(Process_titleBuffer[i], "%*s ", digits, Process_pidColumns[i].label);
|
||||
snprintf(Process_titleBuffer[i], 20, "%*s ", digits, Process_pidColumns[i].label);
|
||||
Process_fields[Process_pidColumns[i].id].title = Process_titleBuffer[i];
|
||||
}
|
||||
sprintf(Process_pidFormat, "%%%dd ", digits);
|
||||
@ -394,7 +395,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
int indent = (this->indent < 0 ? -this->indent : this->indent);
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
if (indent & (1 << i))
|
||||
if (indent & (1U << i))
|
||||
maxIndent = i+1;
|
||||
for (int i = 0; i < maxIndent - 1; i++) {
|
||||
int written;
|
||||
@ -518,10 +519,10 @@ void Process_toggleTag(Process* this) {
|
||||
|
||||
bool Process_setPriority(Process* this, int priority) {
|
||||
uid_t euid = geteuid();
|
||||
seteuid(getuid());
|
||||
(void) seteuid(getuid());
|
||||
int old_prio = getpriority(PRIO_PROCESS, this->pid);
|
||||
int err = setpriority(PRIO_PROCESS, this->pid, priority);
|
||||
seteuid(euid);
|
||||
(void) seteuid(euid);
|
||||
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
|
||||
this->nice = priority;
|
||||
}
|
||||
@ -534,9 +535,9 @@ bool Process_changePriorityBy(Process* this, size_t delta) {
|
||||
|
||||
void Process_sendSignal(Process* this, size_t sgn) {
|
||||
uid_t euid = geteuid();
|
||||
seteuid(getuid());
|
||||
(void) seteuid(getuid());
|
||||
kill(this->pid, (int) sgn);
|
||||
seteuid(euid);
|
||||
(void) seteuid(euid);
|
||||
}
|
||||
|
||||
long Process_pidCompare(const void* v1, const void* v2) {
|
||||
|
@ -28,6 +28,7 @@ in the source distribution for its full text.
|
||||
#define PROCESS_FLAG_IO 0x0001
|
||||
|
||||
typedef enum ProcessFields {
|
||||
NULL_PROCESSFIELD = 0,
|
||||
PID = 1,
|
||||
COMM = 2,
|
||||
STATE = 3,
|
||||
|
@ -189,7 +189,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
}
|
||||
|
||||
int prevCh = ch;
|
||||
ESCDELAY = 25;
|
||||
set_escdelay(25);
|
||||
ch = getch();
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
@ -279,7 +279,10 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
continue;
|
||||
}
|
||||
case KEY_LEFT:
|
||||
case KEY_CTRLB:
|
||||
case KEY_CTRL('B'):
|
||||
if (this->panelCount < 2) {
|
||||
goto defaultHandler;
|
||||
}
|
||||
if (!this->allowFocusChange)
|
||||
break;
|
||||
tryLeft:
|
||||
@ -290,8 +293,11 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
goto tryLeft;
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
case KEY_CTRLF:
|
||||
case KEY_CTRL('F'):
|
||||
case 9:
|
||||
if (this->panelCount < 2) {
|
||||
goto defaultHandler;
|
||||
}
|
||||
if (!this->allowFocusChange)
|
||||
break;
|
||||
tryRight:
|
||||
@ -307,6 +313,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
quit = true;
|
||||
continue;
|
||||
default:
|
||||
defaultHandler:
|
||||
sortTimeout = resetSortTimeout;
|
||||
Panel_onKey(panelFocus, ch);
|
||||
break;
|
||||
|
25
Settings.c
25
Settings.c
@ -159,7 +159,7 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
fields[j] = (ProcessField) NULL;
|
||||
fields[j] = NULL_PROCESSFIELD;
|
||||
String_freeArray(ids);
|
||||
}
|
||||
|
||||
@ -167,18 +167,21 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
||||
FILE* fd;
|
||||
uid_t euid = geteuid();
|
||||
|
||||
seteuid(getuid());
|
||||
(void) seteuid(getuid());
|
||||
fd = fopen(fileName, "r");
|
||||
seteuid(euid);
|
||||
(void) seteuid(euid);
|
||||
if (!fd)
|
||||
return false;
|
||||
|
||||
const int maxLine = 2048;
|
||||
char buffer[maxLine];
|
||||
bool readMeters = false;
|
||||
while (fgets(buffer, maxLine, fd)) {
|
||||
for (;;) {
|
||||
char* line = String_readLine(fd);
|
||||
if (!line) {
|
||||
break;
|
||||
}
|
||||
int nOptions;
|
||||
char** option = String_split(buffer, '=', &nOptions);
|
||||
char** option = String_split(line, '=', &nOptions);
|
||||
free (line);
|
||||
if (nOptions < 2) {
|
||||
String_freeArray(option);
|
||||
continue;
|
||||
@ -277,9 +280,9 @@ bool Settings_write(Settings* this) {
|
||||
FILE* fd;
|
||||
uid_t euid = geteuid();
|
||||
|
||||
seteuid(getuid());
|
||||
(void) seteuid(getuid());
|
||||
fd = fopen(this->filename, "w");
|
||||
seteuid(euid);
|
||||
(void) seteuid(euid);
|
||||
if (fd == NULL) {
|
||||
return false;
|
||||
}
|
||||
@ -366,7 +369,7 @@ Settings* Settings_new(int cpuCount) {
|
||||
}
|
||||
legacyDotfile = String_cat(home, "/.htoprc");
|
||||
uid_t euid = geteuid();
|
||||
seteuid(getuid());
|
||||
(void) seteuid(getuid());
|
||||
(void) mkdir(configDir, 0700);
|
||||
(void) mkdir(htopDir, 0700);
|
||||
free(htopDir);
|
||||
@ -379,7 +382,7 @@ Settings* Settings_new(int cpuCount) {
|
||||
free(legacyDotfile);
|
||||
legacyDotfile = NULL;
|
||||
}
|
||||
seteuid(euid);
|
||||
(void) seteuid(euid);
|
||||
}
|
||||
this->colorScheme = 0;
|
||||
this->changed = false;
|
||||
|
@ -13,9 +13,10 @@ in the source distribution for its full text.
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*{
|
||||
#include <stdio.h>
|
||||
|
||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
||||
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
||||
}*/
|
||||
@ -69,13 +70,7 @@ char** String_split(const char* s, char sep, int* n) {
|
||||
ctr++;
|
||||
if (ctr == blocks) {
|
||||
blocks += rate;
|
||||
char** newOut = (char**) xRealloc(out, sizeof(char*) * blocks);
|
||||
if (newOut) {
|
||||
out = newOut;
|
||||
} else {
|
||||
blocks -= rate;
|
||||
break;
|
||||
}
|
||||
out = (char**) xRealloc(out, sizeof(char*) * blocks);
|
||||
}
|
||||
s += size + 1;
|
||||
}
|
||||
@ -86,10 +81,7 @@ char** String_split(const char* s, char sep, int* n) {
|
||||
out[ctr] = token;
|
||||
ctr++;
|
||||
}
|
||||
char** newOut = xRealloc(out, sizeof(char*) * (ctr + 1));
|
||||
if (newOut) {
|
||||
out = newOut;
|
||||
}
|
||||
out = xRealloc(out, sizeof(char*) * (ctr + 1));
|
||||
out[ctr] = NULL;
|
||||
*n = ctr;
|
||||
return out;
|
||||
@ -128,3 +120,29 @@ char* String_getToken(const char* line, const unsigned short int numMatch) {
|
||||
match[foundCount] = '\0';
|
||||
return((char*)xStrdup(match));
|
||||
}
|
||||
|
||||
char* String_readLine(FILE* fd) {
|
||||
const int step = 1024;
|
||||
int bufSize = step;
|
||||
char* buffer = xMalloc(step + 1);
|
||||
char* at = buffer;
|
||||
for (;;) {
|
||||
char* ok = fgets(at, step + 1, fd);
|
||||
if (!ok) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
char* newLine = strrchr(at, '\n');
|
||||
if (newLine) {
|
||||
*newLine = '\0';
|
||||
return buffer;
|
||||
} else {
|
||||
if (feof(fd)) {
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
bufSize += step;
|
||||
buffer = xRealloc(buffer, bufSize + 1);
|
||||
at = buffer + bufSize - step;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
||||
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
||||
|
||||
@ -24,4 +26,6 @@ void String_freeArray(char** s);
|
||||
|
||||
char* String_getToken(const char* line, const unsigned short int numMatch);
|
||||
|
||||
char* String_readLine(FILE* fd);
|
||||
|
||||
#endif
|
||||
|
@ -24,7 +24,7 @@ int SwapMeter_attributes[] = {
|
||||
SWAP
|
||||
};
|
||||
|
||||
static void SwapMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void SwapMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
int written;
|
||||
Platform_setSwapValues(this);
|
||||
|
||||
@ -54,8 +54,9 @@ MeterClass SwapMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = SwapMeter_display,
|
||||
},
|
||||
.setValues = SwapMeter_setValues,
|
||||
.updateValues = SwapMeter_updateValues,
|
||||
.defaultMode = BAR_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = SwapMeter_attributes,
|
||||
.name = "Swap",
|
||||
|
@ -18,7 +18,7 @@ int TasksMeter_attributes[] = {
|
||||
CPU_KERNEL, PROCESS_THREAD, PROCESS, TASKS_RUNNING
|
||||
};
|
||||
|
||||
static void TasksMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
|
||||
ProcessList* pl = this->pl;
|
||||
this->values[0] = pl->kernelThreads;
|
||||
this->values[1] = pl->userlandThreads;
|
||||
@ -72,10 +72,10 @@ MeterClass TasksMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = TasksMeter_display,
|
||||
},
|
||||
.setValues = TasksMeter_setValues,
|
||||
.updateValues = TasksMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.total = 100.0,
|
||||
.maxItems = 4,
|
||||
.total = 100.0,
|
||||
.attributes = TasksMeter_attributes,
|
||||
.name = "Tasks",
|
||||
.uiName = "Task counter",
|
||||
|
@ -95,7 +95,7 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
|
||||
this->child = fork();
|
||||
if (this->child == -1) return false;
|
||||
if (this->child == 0) {
|
||||
seteuid(getuid());
|
||||
(void) seteuid(getuid());
|
||||
dup2(this->fdpair[1], STDERR_FILENO);
|
||||
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
||||
if (ok != -1) {
|
||||
|
@ -17,7 +17,7 @@ int UptimeMeter_attributes[] = {
|
||||
UPTIME
|
||||
};
|
||||
|
||||
static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) {
|
||||
int totalseconds = Platform_getUptime();
|
||||
if (totalseconds == -1) {
|
||||
snprintf(buffer, len, "(unknown)");
|
||||
@ -49,8 +49,9 @@ MeterClass UptimeMeter_class = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete
|
||||
},
|
||||
.setValues = UptimeMeter_setValues,
|
||||
.updateValues = UptimeMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = UptimeMeter_attributes,
|
||||
.name = "Uptime",
|
||||
|
23
XAlloc.c
23
XAlloc.c
@ -10,6 +10,7 @@
|
||||
#include <string.h>
|
||||
|
||||
/*{
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
}*/
|
||||
|
||||
@ -29,7 +30,7 @@ void* xMalloc(size_t size) {
|
||||
|
||||
void* xCalloc(size_t nmemb, size_t size) {
|
||||
void* data = calloc(nmemb, size);
|
||||
if (!data) {
|
||||
if (!data && nmemb > 0 && size > 0) {
|
||||
fail();
|
||||
}
|
||||
return data;
|
||||
@ -43,9 +44,25 @@ void* xRealloc(void* ptr, size_t size) {
|
||||
return data;
|
||||
}
|
||||
|
||||
char* xStrdup(const char* str) {
|
||||
#undef xStrdup
|
||||
#undef xStrdup_
|
||||
#ifdef NDEBUG
|
||||
# define xStrdup_ xStrdup
|
||||
#else
|
||||
# define xStrdup(str_) (assert(str_), xStrdup_(str_))
|
||||
#endif
|
||||
|
||||
#ifndef __has_attribute // Clang's macro
|
||||
# define __has_attribute(x) 0
|
||||
#endif
|
||||
#if (__has_attribute(nonnull) || \
|
||||
((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)))
|
||||
char* xStrdup_(const char* str) __attribute__((nonnull));
|
||||
#endif // __has_attribute(nonnull) || GNU C 3.3 or later
|
||||
|
||||
char* xStrdup_(const char* str) {
|
||||
char* data = strdup(str);
|
||||
if (!data && str) {
|
||||
if (!data) {
|
||||
fail();
|
||||
}
|
||||
return data;
|
||||
|
19
XAlloc.h
19
XAlloc.h
@ -7,6 +7,7 @@
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void* xMalloc(size_t size);
|
||||
@ -15,6 +16,22 @@ void* xCalloc(size_t nmemb, size_t size);
|
||||
|
||||
void* xRealloc(void* ptr, size_t size);
|
||||
|
||||
char* xStrdup(const char* str);
|
||||
#undef xStrdup
|
||||
#undef xStrdup_
|
||||
#ifdef NDEBUG
|
||||
# define xStrdup_ xStrdup
|
||||
#else
|
||||
# define xStrdup(str_) (assert(str_), xStrdup_(str_))
|
||||
#endif
|
||||
|
||||
#ifndef __has_attribute // Clang's macro
|
||||
# define __has_attribute(x) 0
|
||||
#endif
|
||||
#if (__has_attribute(nonnull) || \
|
||||
((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)))
|
||||
char* xStrdup_(const char* str) __attribute__((nonnull));
|
||||
#endif // __has_attribute(nonnull) || GNU C 3.3 or later
|
||||
|
||||
char* xStrdup_(const char* str);
|
||||
|
||||
#endif
|
||||
|
70
configure.ac
70
configure.ac
@ -2,41 +2,45 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.65)
|
||||
AC_INIT([htop],[2.0.1],[hisham@gobolinux.org])
|
||||
LT_PREREQ([2.4.2])
|
||||
AC_INIT([htop],[2.0.2],[hisham@gobolinux.org])
|
||||
|
||||
year=$(date +%Y)
|
||||
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}"
|
||||
year=$(date -u -d "@$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u "+%Y")
|
||||
|
||||
# The following two lines are required by hwloc scripts
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
AC_CONFIG_SRCDIR([htop.c])
|
||||
AC_CONFIG_AUX_DIR([.])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
# Required by hwloc scripts
|
||||
AC_CANONICAL_TARGET
|
||||
|
||||
AM_INIT_AUTOMAKE([1.11])
|
||||
AC_CONFIG_SRCDIR([htop.c])
|
||||
AC_CONFIG_HEADER([config.h])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
# Checks for programs.
|
||||
# ----------------------------------------------------------------------
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_C_O
|
||||
|
||||
AC_DISABLE_SHARED
|
||||
AC_ENABLE_STATIC
|
||||
AC_PROG_LIBTOOL
|
||||
# Required by hwloc scripts
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
|
||||
LT_INIT([disable-shared static])
|
||||
|
||||
# Checks for platform.
|
||||
# ----------------------------------------------------------------------
|
||||
case "$target" in
|
||||
*linux*)
|
||||
case "$target_os" in
|
||||
linux*|gnu*)
|
||||
my_htop_platform=linux
|
||||
;;
|
||||
*freebsd*)
|
||||
freebsd*|kfreebsd*)
|
||||
my_htop_platform=freebsd
|
||||
;;
|
||||
*openbsd*)
|
||||
openbsd*)
|
||||
my_htop_platform=openbsd
|
||||
;;
|
||||
*darwin*)
|
||||
darwin*)
|
||||
my_htop_platform=darwin
|
||||
;;
|
||||
*)
|
||||
@ -74,15 +78,16 @@ AC_CHECK_FUNCS([memmove strncasecmp strstr strdup])
|
||||
save_cflags="${CFLAGS}"
|
||||
CFLAGS="${CFLAGS} -std=c99"
|
||||
AC_MSG_CHECKING([whether gcc -std=c99 option works])
|
||||
AC_TRY_COMPILE(AC_INCLUDES_DEFAULT, [char *a; a = strdup("foo"); int i = 0; i++; // C99],
|
||||
AC_MSG_RESULT([yes]),
|
||||
AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.]))
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
|
||||
[AC_INCLUDES_DEFAULT], [[char *a; a = strdup("foo"); int i = 0; i++; // C99]])],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.])])
|
||||
CFLAGS="$save_cflags"
|
||||
|
||||
save_cflags="${CFLAGS}"
|
||||
CFLAGS="$CFLAGS -Wextra"
|
||||
AC_MSG_CHECKING([if compiler supports -Wextra])
|
||||
AC_TRY_COMPILE([], [], [
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],[
|
||||
wextra_flag=-Wextra
|
||||
AC_MSG_RESULT([yes])
|
||||
],[
|
||||
@ -96,14 +101,14 @@ AC_SUBST(wextra_flag)
|
||||
# ----------------------------------------------------------------------
|
||||
PROCDIR=/proc
|
||||
|
||||
AC_ARG_ENABLE(proc, [AC_HELP_STRING([--enable-proc], [use Linux-compatible proc filesystem])], enable_proc="yes", enable_proc="no")
|
||||
AC_ARG_ENABLE(proc, [AS_HELP_STRING([--enable-proc], [use Linux-compatible proc filesystem])], enable_proc="yes", enable_proc="no")
|
||||
if test "x$enable_proc" = xyes; then
|
||||
# An enabled proc assumes we're emulating Linux.
|
||||
my_htop_platform=linux
|
||||
AC_DEFINE(HAVE_PROC, 1, [Define if using a Linux-compatible proc filesystem.])
|
||||
fi
|
||||
|
||||
AC_ARG_WITH(proc, [AC_HELP_STRING([--with-proc=DIR], [Location of a Linux-compatible proc filesystem (default=/proc).])],
|
||||
AC_ARG_WITH(proc, [AS_HELP_STRING([--with-proc=DIR], [Location of a Linux-compatible proc filesystem (default=/proc).])],
|
||||
|
||||
if test -n "$withval"; then
|
||||
AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem])
|
||||
@ -118,28 +123,28 @@ if test "x$cross_compiling" = xno; then
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(openvz, [AC_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no")
|
||||
AC_ARG_ENABLE(openvz, [AS_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no")
|
||||
if test "x$enable_openvz" = xyes; then
|
||||
AC_DEFINE(HAVE_OPENVZ, 1, [Define if openvz support enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(cgroup, [AC_HELP_STRING([--enable-cgroup], [enable cgroups support])], ,enable_cgroup="no")
|
||||
AC_ARG_ENABLE(cgroup, [AS_HELP_STRING([--enable-cgroup], [enable cgroups support])], ,enable_cgroup="no")
|
||||
if test "x$enable_cgroup" = xyes; then
|
||||
AC_DEFINE(HAVE_CGROUP, 1, [Define if cgroup support enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(vserver, [AC_HELP_STRING([--enable-vserver], [enable VServer support])], ,enable_vserver="no")
|
||||
AC_ARG_ENABLE(vserver, [AS_HELP_STRING([--enable-vserver], [enable VServer support])], ,enable_vserver="no")
|
||||
if test "x$enable_vserver" = xyes; then
|
||||
AC_DEFINE(HAVE_VSERVER, 1, [Define if vserver support enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(ancient_vserver, [AC_HELP_STRING([--enable-ancient-vserver], [enable ancient VServer support (implies --enable-vserver)])], ,enable_ancient_vserver="no")
|
||||
AC_ARG_ENABLE(ancient_vserver, [AS_HELP_STRING([--enable-ancient-vserver], [enable ancient VServer support (implies --enable-vserver)])], ,enable_ancient_vserver="no")
|
||||
if test "x$enable_ancient_vserver" = xyes; then
|
||||
AC_DEFINE(HAVE_VSERVER, 1, [Define if vserver support enabled.])
|
||||
AC_DEFINE(HAVE_ANCIENT_VSERVER, 1, [Define if ancient vserver support enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(taskstats, [AC_HELP_STRING([--enable-taskstats], [enable per-task IO Stats (taskstats kernel sup required)])], ,enable_taskstats="yes")
|
||||
AC_ARG_ENABLE(taskstats, [AS_HELP_STRING([--enable-taskstats], [enable per-task IO Stats (taskstats kernel sup required)])], ,enable_taskstats="yes")
|
||||
if test "x$enable_taskstats" = xyes; then
|
||||
AC_DEFINE(HAVE_TASKSTATS, 1, [Define if taskstats support enabled.])
|
||||
fi
|
||||
@ -147,7 +152,12 @@ fi
|
||||
# HTOP_CHECK_SCRIPT(LIBNAME, FUNCTION, DEFINE, CONFIG_SCRIPT, ELSE_PART)
|
||||
m4_define([HTOP_CHECK_SCRIPT],
|
||||
[
|
||||
htop_config_script=$([$4] --libs 2> /dev/null)
|
||||
if test ! -z "m4_toupper($HTOP_[$1]_CONFIG_SCRIPT)"; then
|
||||
# to be used to set the path to ncurses*-config when cross-compiling
|
||||
htop_config_script=$(m4_toupper($HTOP_[$1]_CONFIG_SCRIPT) --libs 2> /dev/null)
|
||||
else
|
||||
htop_config_script=$([$4] --libs 2> /dev/null)
|
||||
fi
|
||||
htop_script_success=no
|
||||
htop_save_LDFLAGS="$LDFLAGS"
|
||||
if test ! "x$htop_config_script" = x; then
|
||||
@ -173,7 +183,7 @@ m4_define([HTOP_CHECK_LIB],
|
||||
], [$4])
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(unicode, [AC_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes")
|
||||
AC_ARG_ENABLE(unicode, [AS_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes")
|
||||
if test "x$enable_unicode" = xyes; then
|
||||
HTOP_CHECK_SCRIPT([ncursesw6], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw6-config",
|
||||
HTOP_CHECK_SCRIPT([ncursesw], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw5-config",
|
||||
@ -211,7 +221,7 @@ if test "$my_htop_platform" = "openbsd"; then
|
||||
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(linux_affinity, [AC_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes")
|
||||
AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes")
|
||||
if test "x$enable_linux_affinity" = xyes -a "x$cross_compiling" = xno; then
|
||||
AC_MSG_CHECKING([for usable sched_setaffinity])
|
||||
AC_RUN_IFELSE([
|
||||
@ -232,7 +242,7 @@ if test "x$enable_linux_affinity" = xyes; then
|
||||
AC_DEFINE(HAVE_LINUX_AFFINITY, 1, [Define if Linux sched_setaffinity and sched_getaffinity are to be used.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(hwloc, [AC_HELP_STRING([--enable-hwloc], [enable hwloc support for CPU affinity])],, enable_hwloc="no")
|
||||
AC_ARG_ENABLE(hwloc, [AS_HELP_STRING([--enable-hwloc], [enable hwloc support for CPU affinity])],, enable_hwloc="no")
|
||||
if test "x$enable_hwloc" = xyes
|
||||
then
|
||||
AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [missing_libraries="$missing_libraries libhwloc"])
|
||||
|
@ -26,6 +26,7 @@ typedef struct DarwinProcess_ {
|
||||
|
||||
uint64_t utime;
|
||||
uint64_t stime;
|
||||
bool taskAccess;
|
||||
} DarwinProcess;
|
||||
|
||||
}*/
|
||||
@ -47,6 +48,7 @@ DarwinProcess* DarwinProcess_new(Settings* settings) {
|
||||
|
||||
this->utime = 0;
|
||||
this->stime = 0;
|
||||
this->taskAccess = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -301,6 +303,10 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) {
|
||||
Process* proc = (Process*) dp;
|
||||
kern_return_t ret;
|
||||
|
||||
if (!dp->taskAccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (proc->state == 'Z') {
|
||||
return;
|
||||
}
|
||||
@ -308,6 +314,7 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) {
|
||||
task_t port;
|
||||
ret = task_for_pid(mach_task_self(), proc->pid, &port);
|
||||
if (ret != KERN_SUCCESS) {
|
||||
dp->taskAccess = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -315,6 +322,7 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) {
|
||||
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);
|
||||
if (ret != KERN_SUCCESS) {
|
||||
dp->taskAccess = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -322,6 +330,7 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) {
|
||||
mach_msg_type_number_t thread_count;
|
||||
ret = task_threads(port, &thread_list, &thread_count);
|
||||
if (ret != KERN_SUCCESS) {
|
||||
dp->taskAccess = false;
|
||||
mach_port_deallocate(mach_task_self(), port);
|
||||
return;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ typedef struct DarwinProcess_ {
|
||||
|
||||
uint64_t utime;
|
||||
uint64_t stime;
|
||||
bool taskAccess;
|
||||
} DarwinProcess;
|
||||
|
||||
|
||||
|
@ -280,11 +280,9 @@ char* Platform_getProcessEnv(pid_t pid) {
|
||||
|
||||
size_t size = endp - p;
|
||||
env = xMalloc(size+2);
|
||||
if (env) {
|
||||
memcpy(env, p, size);
|
||||
env[size] = 0;
|
||||
env[size+1] = 0;
|
||||
}
|
||||
memcpy(env, p, size);
|
||||
env[size] = 0;
|
||||
env[size+1] = 0;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
|
@ -427,7 +427,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
||||
|
||||
int cpus = this->cpuCount;
|
||||
int count = 0;
|
||||
struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_ALL, 0, &count);
|
||||
struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
struct kinfo_proc* kproc = &kprocs[i];
|
||||
@ -495,10 +495,6 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
||||
isIdleProcess = true;
|
||||
}
|
||||
}
|
||||
if (isIdleProcess == false && proc->percent_cpu >= 99.8) {
|
||||
// don't break formatting
|
||||
proc->percent_cpu = 99.8;
|
||||
}
|
||||
|
||||
proc->priority = kproc->ki_pri.pri_level - PZERO;
|
||||
|
||||
|
@ -163,15 +163,15 @@ double Platform_setCPUValues(Meter* this, int cpu) {
|
||||
double percent;
|
||||
double* v = this->values;
|
||||
|
||||
v[CPU_METER_NICE] = cpuData->nicePercent * cpus;
|
||||
v[CPU_METER_NORMAL] = cpuData->userPercent * cpus;
|
||||
v[CPU_METER_NICE] = cpuData->nicePercent;
|
||||
v[CPU_METER_NORMAL] = cpuData->userPercent;
|
||||
if (this->pl->settings->detailedCPUTime) {
|
||||
v[CPU_METER_KERNEL] = cpuData->systemPercent * cpus;
|
||||
v[CPU_METER_IRQ] = cpuData->irqPercent * cpus;
|
||||
v[CPU_METER_KERNEL] = cpuData->systemPercent;
|
||||
v[CPU_METER_IRQ] = cpuData->irqPercent;
|
||||
Meter_setItems(this, 4);
|
||||
percent = v[0]+v[1]+v[2]+v[3];
|
||||
} else {
|
||||
v[2] = cpuData->systemAllPercent * cpus;
|
||||
v[2] = cpuData->systemAllPercent;
|
||||
Meter_setItems(this, 3);
|
||||
percent = v[0]+v[1]+v[2];
|
||||
}
|
||||
|
32
htop.1.in
32
htop.1.in
@ -10,7 +10,7 @@ Htop is a free (GPL) ncurses-based process viewer for Linux.
|
||||
.LP
|
||||
It is similar to top, but allows you to scroll vertically and horizontally,
|
||||
so you can see all the processes running on the system, along with their full
|
||||
command lines, as well as viewing them as a process tree, selecting mutiple
|
||||
command lines, as well as viewing them as a process tree, selecting multiple
|
||||
processes and acting on them all at once.
|
||||
.LP
|
||||
Tasks related to processes (killing, renicing) can be done without
|
||||
@ -48,8 +48,34 @@ Output version information and exit
|
||||
The following commands are supported while in htop:
|
||||
.LP
|
||||
.TP 5
|
||||
.B Arrows, PgUP, PgDn, Home, End
|
||||
Scroll the process list.
|
||||
.B Up, Alt-k
|
||||
Select (hightlight) the previous process in the process list. Scroll the list
|
||||
if necessary.
|
||||
.TP
|
||||
.B Down, Alt-j
|
||||
Select (hightlight) the next process in the process list. Scroll the list if
|
||||
necessary.
|
||||
.TP
|
||||
.B Left, Alt-h
|
||||
Scroll the process list left.
|
||||
.TP
|
||||
.B Right, Alt-l
|
||||
Scroll the process list right.
|
||||
.TP
|
||||
.B PgUp, PgDn
|
||||
Scroll the process list up or down one window.
|
||||
.TP
|
||||
.B Home
|
||||
Scroll to the top of the process list and select the first process.
|
||||
.TP
|
||||
.B End
|
||||
Scroll to the bottom of the process list and select the last process.
|
||||
.TP
|
||||
.B Ctrl-A, ^
|
||||
Scroll left to the beginning of the process entry (i.e. beginning of line).
|
||||
.TP
|
||||
.B Ctrl-E, $
|
||||
Scroll right to the end of the process entry (i.e. end of line).
|
||||
.TP
|
||||
.B Space
|
||||
Tag or untag a process. Commands that can operate on multiple processes,
|
||||
|
@ -60,3 +60,4 @@ GenericName[sv]=Processvisning
|
||||
GenericName[tr]=Süreç Görüntüleyici
|
||||
GenericName[uk]=Перегляд процесів
|
||||
GenericName[zh_TW]=行程檢視器
|
||||
Keywords=system;process;task
|
||||
|
@ -65,10 +65,11 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
|
||||
break;
|
||||
}
|
||||
|
||||
char line[50] = "";
|
||||
char* line = NULL;
|
||||
for (unsigned short int i = 0; i < lineNum; i++) {
|
||||
char* ok = fgets(line, sizeof line, file);
|
||||
if (!ok) break;
|
||||
free(line);
|
||||
line = String_readLine(file);
|
||||
if (!line) break;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
@ -76,7 +77,8 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
|
||||
char *foundNumStr = String_getToken(line, wordNum);
|
||||
const unsigned long int foundNum = atoi(foundNumStr);
|
||||
free(foundNumStr);
|
||||
|
||||
free(line);
|
||||
|
||||
total += foundNum;
|
||||
}
|
||||
|
||||
@ -116,14 +118,13 @@ static ACPresence procAcpiCheck() {
|
||||
continue;
|
||||
}
|
||||
|
||||
char line[100];
|
||||
char* ok = fgets(line, sizeof line, file);
|
||||
if (!ok) continue;
|
||||
line[sizeof(line) - 1] = '\0';
|
||||
char* line = String_readLine(file);
|
||||
if (!line) continue;
|
||||
|
||||
fclose(file);
|
||||
|
||||
const char *isOnline = String_getToken(line, 2);
|
||||
free(line);
|
||||
|
||||
if (strcmp(isOnline, "on-line") == 0) {
|
||||
isOn = AC_PRESENT;
|
||||
|
@ -470,6 +470,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
||||
int amtRead = xread(fd, command, sizeof(command) - 1);
|
||||
close(fd);
|
||||
int tokenEnd = 0;
|
||||
int lastChar = 0;
|
||||
if (amtRead > 0) {
|
||||
for (int i = 0; i < amtRead; i++)
|
||||
if (command[i] == '\0' || command[i] == '\n') {
|
||||
@ -477,14 +478,16 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
||||
tokenEnd = i;
|
||||
}
|
||||
command[i] = ' ';
|
||||
} else {
|
||||
lastChar = i;
|
||||
}
|
||||
}
|
||||
if (tokenEnd == 0) {
|
||||
tokenEnd = amtRead;
|
||||
}
|
||||
command[amtRead] = '\0';
|
||||
command[lastChar + 1] = '\0';
|
||||
process->basenameOffset = tokenEnd;
|
||||
setCommand(process, command, amtRead);
|
||||
setCommand(process, command, lastChar + 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -265,9 +265,6 @@ void Platform_setSwapValues(Meter* this) {
|
||||
}
|
||||
|
||||
swdev = xCalloc(nswap, sizeof(*swdev));
|
||||
if (swdev == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
rnswap = swapctl(SWAP_STATS, swdev, nswap);
|
||||
if (rnswap == -1) {
|
||||
|
Reference in New Issue
Block a user