mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 13:34:35 +03:00
Compare commits
436 Commits
Author | SHA1 | Date | |
---|---|---|---|
9a55efc8b5 | |||
31391b206c | |||
fed14a584d | |||
cca07e9bc9 | |||
9aa816873f | |||
0622be6ab3 | |||
54b6143cf6 | |||
5c5a599a2a | |||
e25ac8557d | |||
6b443c5da9 | |||
011125dab2 | |||
ab61ae3963 | |||
f4b0067339 | |||
1b8bed1294 | |||
a82fd262d7 | |||
cdff8aea2a | |||
b30c22d687 | |||
42c8e47cd6 | |||
0f76359e4e | |||
e833bf915f | |||
2be0992700 | |||
fb679dfb18 | |||
a7a5e356c2 | |||
dab4144f4a | |||
45ae6191c1 | |||
ed2b7791df | |||
78f4d064de | |||
e7d2f9383a | |||
97d700082c | |||
46ab1aa3bd | |||
500fb283e9 | |||
5228f5d47a | |||
74d547674d | |||
034e56b3c0 | |||
6310e5dc3a | |||
36ef4d4fb6 | |||
80ce69c44f | |||
6fbee8c1f4 | |||
00d333cc7b | |||
eef6bc447d | |||
f9625cacf0 | |||
e9947acfc6 | |||
5a17cee74d | |||
ed6f22a847 | |||
2f59798b3b | |||
9a70e43129 | |||
7ac1c709b7 | |||
579995c7c2 | |||
98e8da8bd3 | |||
7fbbf25afe | |||
e1f48c7c7c | |||
6cd1615863 | |||
c86ac5cf98 | |||
b3003f02fa | |||
dfd9279f87 | |||
b55f9320bc | |||
7fdd8d3732 | |||
f74cde982f | |||
832e77c754 | |||
8de04986cf | |||
1b4ed916b1 | |||
05c974f6cc | |||
6b5b8bab2c | |||
87c05ac136 | |||
ccf0e18414 | |||
88c9ebb8f7 | |||
37cc11253e | |||
63fbc3b517 | |||
dd33444f7e | |||
9ed47a213b | |||
12805f61d8 | |||
28840683cf | |||
18a60d668d | |||
1886117c72 | |||
a267003f2f | |||
613556faeb | |||
e450b58636 | |||
81b64691a7 | |||
909bb86f05 | |||
43728b37e7 | |||
1acfb0a752 | |||
1d5e6a27a0 | |||
9703a25d1b | |||
4b0600d8f8 | |||
7858ee6cee | |||
b0e24cd5a5 | |||
ff6914e4ad | |||
a88d2e313d | |||
fc8e9a2d3e | |||
070fe90461 | |||
a93edde1a2 | |||
92258e99e6 | |||
886eb68102 | |||
3512971084 | |||
01a1cc063f | |||
423414937b | |||
131a6c6e2b | |||
c3fadf6b69 | |||
fabe75685a | |||
078c2ddde5 | |||
fc0bf546c3 | |||
43875d94c9 | |||
08feb8585b | |||
da60309fc9 | |||
6f161e60e1 | |||
402e46bb82 | |||
90518bfc84 | |||
f49f545813 | |||
60e557868a | |||
79c939eb84 | |||
dc7d035238 | |||
6194c8dcc6 | |||
7c62db73fc | |||
a360a80d16 | |||
9139d29bbb | |||
536941fb23 | |||
ecfd6f685e | |||
f15d55c972 | |||
27fe307d22 | |||
9197adf57e | |||
41754e5632 | |||
8d7afb33e2 | |||
b7b4200f85 | |||
4cb58460e5 | |||
c39f710b52 | |||
c34be41e1c | |||
67e368914a | |||
bae27054e6 | |||
8d01ae2054 | |||
049af17be0 | |||
009837b56d | |||
bd1d719a61 | |||
ca1cce4ce7 | |||
c1fb585b6b | |||
d74b6dc8e0 | |||
060aa2b20f | |||
3d79c72e9a | |||
c005ffc3d7 | |||
48b807b0ff | |||
666e1e76b3 | |||
5f9e16b9da | |||
fd15ead51b | |||
103f1a497a | |||
08a9b051c5 | |||
e1e3791363 | |||
04cc193e3c | |||
5b38466eab | |||
34dff098c5 | |||
724aae60d1 | |||
e85b072ad0 | |||
7cfaa9dede | |||
db05ba6106 | |||
0505a7cfe1 | |||
cf04300d49 | |||
c53e384213 | |||
da4877f48c | |||
0969f83b21 | |||
155d7cbeee | |||
1ae7625c42 | |||
3c96467f7b | |||
7f40a3a5af | |||
45fad05b4a | |||
4ba06c51e5 | |||
fa18ac964c | |||
192e43c1ed | |||
75598c1389 | |||
c235b45cd6 | |||
0dbedf95a8 | |||
42c3a1fcb3 | |||
1cf8f429a5 | |||
23f96048c7 | |||
70bc51a387 | |||
442b0d2576 | |||
47cf1532b0 | |||
dc050e8088 | |||
aa3dc634dc | |||
5a75797f4d | |||
cda84fcddc | |||
69355234d0 | |||
cefbe499db | |||
76ef3682db | |||
4bd68809e4 | |||
a042cfece2 | |||
2e3c35d66d | |||
697f5bb9c1 | |||
d4ea7cd65c | |||
9ca1c993ac | |||
ccd156f8ba | |||
858af2505f | |||
655c7293d2 | |||
bc5d46982f | |||
c01f40eb3e | |||
eed18dd107 | |||
f914617508 | |||
03b2581745 | |||
8c653212c0 | |||
b064d501ae | |||
ff78a1bfce | |||
f4f35da7e0 | |||
76366be3f1 | |||
6dda8d2586 | |||
5fca258f33 | |||
70ed51a303 | |||
df9922a67e | |||
fcdff59f4c | |||
b544c22c72 | |||
f37a050d3d | |||
03f17688ad | |||
a32d7528f6 | |||
ac2dff2881 | |||
c50440f165 | |||
b0588d90ff | |||
b84ebfd4e8 | |||
b86e14d3cf | |||
b34d76cd41 | |||
87be623eac | |||
b27712181a | |||
ad99187680 | |||
b7b66b76a5 | |||
52831955c7 | |||
ef34a83c54 | |||
4c1230b03b | |||
e3f65c8ec2 | |||
b9934ffa08 | |||
65ec0bd6a6 | |||
584a9bceab | |||
9487bda330 | |||
4300a19592 | |||
60acda0bce | |||
09e241fb12 | |||
3975e9ce5c | |||
821d50f0b4 | |||
543d65c6ab | |||
f205f7004c | |||
ef7817c17a | |||
33fda93271 | |||
ce0cf3c457 | |||
d5faf64374 | |||
18b3e5d255 | |||
143a7de6b2 | |||
e940aecfb9 | |||
1a178ad581 | |||
c39f18a7be | |||
978c9e1698 | |||
e70f447d54 | |||
71785e2ded | |||
e9ecbd05bc | |||
89d15399c5 | |||
e03e45d819 | |||
45f3769887 | |||
2d8dd0b29e | |||
b1028e03c5 | |||
0c168471b6 | |||
68b8efb83f | |||
418fea33f4 | |||
975e22144e | |||
50f03f5950 | |||
cb7a06379d | |||
cba695961a | |||
49af12e7c6 | |||
b258d6e53e | |||
e0e84401e4 | |||
5570748dd2 | |||
3c09082422 | |||
53d7c66ac3 | |||
3b1260ac3d | |||
fa30938247 | |||
bb8dec1582 | |||
aa813c7561 | |||
3f6d1262c0 | |||
84bc00a275 | |||
6141edc74b | |||
2b5c1b4b13 | |||
8af4d9f453 | |||
8a147dd5b4 | |||
5df425867c | |||
46d8f2eef2 | |||
8fd6228bc1 | |||
0ce4835f95 | |||
823481ae22 | |||
96157870af | |||
5a5a7c8d6b | |||
07086fcf77 | |||
6d4df3d138 | |||
d4a8023b72 | |||
99f7ff9bd2 | |||
1f3d85b617 | |||
cceab15b9d | |||
bd5d37f297 | |||
16406ea330 | |||
d3f575264b | |||
bf35921abb | |||
b269eb24b0 | |||
3d9868833e | |||
3cd0339423 | |||
ef879b4a22 | |||
f161365d72 | |||
6b9b6db655 | |||
f80e577c59 | |||
81552d4ab5 | |||
0108117d0b | |||
a41c9b3925 | |||
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 | |||
e2ccc7b240 | |||
ef1e62d1fa | |||
453105e77a | |||
db80f202f2 | |||
98e43816a5 | |||
694addceb5 | |||
4623394456 | |||
4ad7aa6432 | |||
4b780a3499 | |||
b08cb7352e | |||
b886ecc479 | |||
63c55854e5 | |||
4f1bd232d8 | |||
84a69b1ea4 | |||
e77811e99b | |||
0a4a447d0d | |||
cc8375f9ea | |||
03af73bbc7 | |||
0cf3cfa3af | |||
797bcd0961 | |||
baec4bdcb0 | |||
a8a5e62760 | |||
f5ddb974a1 | |||
565101234a | |||
d4741d5410 | |||
9668cd11ed | |||
c23d4f12d1 | |||
34431dc7fd | |||
42c4459375 | |||
48254f92e4 | |||
5ee6715843 | |||
c18309466d | |||
fe0ad86e6d | |||
dc4f145629 | |||
d43e709364 | |||
0627a5f0e9 | |||
d10f4f615a | |||
e0c364b9cc | |||
fd216309d9 | |||
474d26cea8 | |||
471cd60635 | |||
f554f08fa9 | |||
d753996b96 | |||
b10278318b | |||
35657208d7 | |||
ae823c375a | |||
1b5025e6f5 | |||
c66ac09a66 | |||
0b70439316 | |||
e9b32eb62f | |||
3b9a4b1024 | |||
0e3cf6975f | |||
a618f477b2 | |||
cc4267cc5c | |||
d0d14da8d9 | |||
1bedac1ca2 | |||
011bf30d22 | |||
c56b1a8830 | |||
01edfcf4d4 | |||
d916f6e6f0 | |||
e46488463d | |||
8fa9da47de | |||
d408c74465 | |||
bb0333e45d | |||
b6f927bffa | |||
f1d1d6e0d6 |
@ -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
|
||||||
|
29
.github/workflows/ci.yml
vendored
Normal file
29
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-ubuntu-latest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
sudo apt-get install libncursesw5-dev
|
||||||
|
./autogen.sh
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
|
||||||
|
# build-macos-latest:
|
||||||
|
# runs-on: macos-latest
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v2
|
||||||
|
# - name: make
|
||||||
|
# run: |
|
||||||
|
# ./autogen.sh
|
||||||
|
# ./configure
|
||||||
|
# make
|
9
.gitignore
vendored
9
.gitignore
vendored
@ -4,6 +4,12 @@ htop
|
|||||||
# all object files
|
# all object files
|
||||||
*.o
|
*.o
|
||||||
|
|
||||||
|
# skip all backups
|
||||||
|
*.bak
|
||||||
|
*~
|
||||||
|
.*.sw?
|
||||||
|
|
||||||
|
# skip coverage files
|
||||||
*.gcda
|
*.gcda
|
||||||
*/*.gcda
|
*/*.gcda
|
||||||
*.gcno
|
*.gcno
|
||||||
@ -14,6 +20,7 @@ htop
|
|||||||
.deps/
|
.deps/
|
||||||
Makefile
|
Makefile
|
||||||
Makefile.in
|
Makefile.in
|
||||||
|
INSTALL
|
||||||
aclocal.m4
|
aclocal.m4
|
||||||
autom4te.cache/
|
autom4te.cache/
|
||||||
compile
|
compile
|
||||||
@ -22,6 +29,7 @@ config.h
|
|||||||
config.h.in
|
config.h.in
|
||||||
config.log
|
config.log
|
||||||
config.status
|
config.status
|
||||||
|
config.cache
|
||||||
config.sub
|
config.sub
|
||||||
configure
|
configure
|
||||||
depcomp
|
depcomp
|
||||||
@ -32,4 +40,3 @@ ltmain.sh
|
|||||||
m4/
|
m4/
|
||||||
missing
|
missing
|
||||||
stamp-h1
|
stamp-h1
|
||||||
|
|
||||||
|
106
Action.c
106
Action.c
@ -62,11 +62,11 @@ typedef struct State_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
Object* Action_pickFromVector(State* st, Panel* list, int x) {
|
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;
|
||||||
@ -75,8 +75,8 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) {
|
|||||||
Panel* panelFocus;
|
Panel* panelFocus;
|
||||||
int ch;
|
int ch;
|
||||||
bool unfollow = false;
|
bool unfollow = false;
|
||||||
int pid = MainPanel_selectedPid((MainPanel*)panel);
|
int pid = followProcess ? MainPanel_selectedPid((MainPanel*)panel) : -1;
|
||||||
if (header->pl->following == -1) {
|
if (followProcess && header->pl->following == -1) {
|
||||||
header->pl->following = pid;
|
header->pl->following = pid;
|
||||||
unfollow = true;
|
unfollow = true;
|
||||||
}
|
}
|
||||||
@ -88,11 +88,16 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) {
|
|||||||
Panel_move(panel, 0, y);
|
Panel_move(panel, 0, y);
|
||||||
Panel_resize(panel, COLS, LINES-y-1);
|
Panel_resize(panel, COLS, LINES-y-1);
|
||||||
if (panelFocus == list && ch == 13) {
|
if (panelFocus == list && ch == 13) {
|
||||||
Process* selected = (Process*)Panel_getSelected(panel);
|
if (followProcess) {
|
||||||
if (selected && selected->pid == pid)
|
Process* selected = (Process*)Panel_getSelected(panel);
|
||||||
|
if (selected && selected->pid == pid)
|
||||||
|
return Panel_getSelected(list);
|
||||||
|
else
|
||||||
|
beep();
|
||||||
|
} else {
|
||||||
return Panel_getSelected(list);
|
return Panel_getSelected(list);
|
||||||
else
|
}
|
||||||
beep();
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -115,7 +120,7 @@ static void Action_runSetup(Settings* settings, const Header* header, ProcessLis
|
|||||||
|
|
||||||
static bool changePriority(MainPanel* panel, int delta) {
|
static bool changePriority(MainPanel* panel, int delta) {
|
||||||
bool anyTagged;
|
bool anyTagged;
|
||||||
bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, delta, &anyTagged);
|
bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
beep();
|
beep();
|
||||||
return anyTagged;
|
return anyTagged;
|
||||||
@ -142,7 +147,7 @@ static void tagAllChildren(Panel* panel, Process* parent) {
|
|||||||
pid_t ppid = parent->pid;
|
pid_t ppid = parent->pid;
|
||||||
for (int i = 0; i < Panel_size(panel); i++) {
|
for (int i = 0; i < Panel_size(panel); i++) {
|
||||||
Process* p = (Process*) Panel_get(panel, i);
|
Process* p = (Process*) Panel_get(panel, i);
|
||||||
if (!p->tag && p->ppid == ppid) {
|
if (!p->tag && Process_isChildOf(p, ppid)) {
|
||||||
tagAllChildren(panel, p);
|
tagAllChildren(panel, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,6 +160,21 @@ static bool expandCollapse(Panel* panel) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool collapseIntoParent(Panel* panel) {
|
||||||
|
Process* p = (Process*) Panel_getSelected(panel);
|
||||||
|
if (!p) return false;
|
||||||
|
pid_t ppid = Process_getParentPid(p);
|
||||||
|
for (int i = 0; i < Panel_size(panel); i++) {
|
||||||
|
Process* q = (Process*) Panel_get(panel, i);
|
||||||
|
if (q->pid == ppid) {
|
||||||
|
q->showChildren = false;
|
||||||
|
Panel_setSelected(panel, i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||||
settings->sortKey = sortKey;
|
settings->sortKey = sortKey;
|
||||||
settings->direction = 1;
|
settings->direction = 1;
|
||||||
@ -174,7 +194,7 @@ static Htop_Reaction sortBy(State* st) {
|
|||||||
Panel_setSelected(sortPanel, i);
|
Panel_setSelected(sortPanel, i);
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15);
|
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false);
|
||||||
if (field) {
|
if (field) {
|
||||||
reaction |= Action_setSortKey(st->settings, field->key);
|
reaction |= Action_setSortKey(st->settings, field->key);
|
||||||
}
|
}
|
||||||
@ -185,6 +205,7 @@ static Htop_Reaction sortBy(State* st) {
|
|||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
static Htop_Reaction actionResize(State* st) {
|
static Htop_Reaction actionResize(State* st) {
|
||||||
|
clear();
|
||||||
Panel_resize(st->panel, COLS, LINES-(st->panel->y)-1);
|
Panel_resize(st->panel, COLS, LINES-(st->panel->y)-1);
|
||||||
return HTOP_REDRAW_BAR;
|
return HTOP_REDRAW_BAR;
|
||||||
}
|
}
|
||||||
@ -232,10 +253,21 @@ static Htop_Reaction actionIncFilter(State* st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionIncSearch(State* st) {
|
static Htop_Reaction actionIncSearch(State* st) {
|
||||||
|
IncSet_reset(((MainPanel*)st->panel)->inc, INC_SEARCH);
|
||||||
IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel);
|
IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel);
|
||||||
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Htop_Reaction actionIncNext(State* st) {
|
||||||
|
IncSet_next(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue);
|
||||||
|
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Htop_Reaction actionIncPrev(State* st) {
|
||||||
|
IncSet_prev(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue);
|
||||||
|
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||||
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionHigherPriority(State* st) {
|
static Htop_Reaction actionHigherPriority(State* st) {
|
||||||
bool changed = changePriority((MainPanel*)st->panel, -1);
|
bool changed = changePriority((MainPanel*)st->panel, -1);
|
||||||
return changed ? HTOP_REFRESH : HTOP_OK;
|
return changed ? HTOP_REFRESH : HTOP_OK;
|
||||||
@ -260,6 +292,14 @@ static Htop_Reaction actionExpandOrCollapse(State* st) {
|
|||||||
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Htop_Reaction actionCollapseIntoParent(State* st) {
|
||||||
|
if (!st->settings->treeView) {
|
||||||
|
return HTOP_OK;
|
||||||
|
}
|
||||||
|
bool changed = collapseIntoParent(st->panel);
|
||||||
|
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
||||||
return st->settings->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
return st->settings->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
||||||
}
|
}
|
||||||
@ -271,9 +311,9 @@ static Htop_Reaction actionQuit() {
|
|||||||
static Htop_Reaction actionSetAffinity(State* st) {
|
static Htop_Reaction actionSetAffinity(State* st) {
|
||||||
if (st->pl->cpuCount == 1)
|
if (st->pl->cpuCount == 1)
|
||||||
return HTOP_OK;
|
return HTOP_OK;
|
||||||
#if (HAVE_LIBHWLOC || HAVE_NATIVE_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);
|
||||||
@ -281,10 +321,10 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
|||||||
Panel* affinityPanel = AffinityPanel_new(st->pl, affinity);
|
Panel* affinityPanel = AffinityPanel_new(st->pl, affinity);
|
||||||
Affinity_delete(affinity);
|
Affinity_delete(affinity);
|
||||||
|
|
||||||
void* set = Action_pickFromVector(st, affinityPanel, 15);
|
void* set = Action_pickFromVector(st, affinityPanel, 15, true);
|
||||||
if (set) {
|
if (set) {
|
||||||
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
||||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (size_t) affinity, NULL);
|
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL);
|
||||||
if (!ok) beep();
|
if (!ok) beep();
|
||||||
Affinity_delete(affinity);
|
Affinity_delete(affinity);
|
||||||
}
|
}
|
||||||
@ -295,13 +335,13 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
|||||||
|
|
||||||
static Htop_Reaction actionKill(State* st) {
|
static Htop_Reaction actionKill(State* st) {
|
||||||
Panel* signalsPanel = (Panel*) SignalsPanel_new();
|
Panel* signalsPanel = (Panel*) SignalsPanel_new();
|
||||||
ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15);
|
ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true);
|
||||||
if (sgn) {
|
if (sgn) {
|
||||||
if (sgn->key != 0) {
|
if (sgn->key != 0) {
|
||||||
Panel_setHeader(st->panel, "Sending...");
|
Panel_setHeader(st->panel, "Sending...");
|
||||||
Panel_draw(st->panel, true);
|
Panel_draw(st->panel, true);
|
||||||
refresh();
|
refresh();
|
||||||
MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (size_t) sgn->key, NULL);
|
MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (Arg){ .i = sgn->key }, NULL);
|
||||||
napms(500);
|
napms(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -316,7 +356,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
|
|||||||
Vector_insertionSort(usersPanel->items);
|
Vector_insertionSort(usersPanel->items);
|
||||||
ListItem* allUsers = ListItem_new("All users", -1);
|
ListItem* allUsers = ListItem_new("All users", -1);
|
||||||
Panel_insert(usersPanel, 0, (Object*) allUsers);
|
Panel_insert(usersPanel, 0, (Object*) allUsers);
|
||||||
ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20);
|
ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, false);
|
||||||
if (picked) {
|
if (picked) {
|
||||||
if (picked == allUsers) {
|
if (picked == allUsers) {
|
||||||
st->pl->userId = -1;
|
st->pl->userId = -1;
|
||||||
@ -328,7 +368,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
|
|||||||
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
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);
|
st->pl->following = MainPanel_selectedPid((MainPanel*)st->panel);
|
||||||
Panel_setSelectionColor(st->panel, CRT_colors[PANEL_SELECTION_FOLLOW]);
|
Panel_setSelectionColor(st->panel, CRT_colors[PANEL_SELECTION_FOLLOW]);
|
||||||
return HTOP_KEEP_FOLLOWING;
|
return HTOP_KEEP_FOLLOWING;
|
||||||
@ -381,12 +421,13 @@ static Htop_Reaction actionRedraw() {
|
|||||||
return HTOP_REFRESH | HTOP_REDRAW_BAR;
|
return HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct { const char* key; const char* info; } helpLeft[] = {
|
static const struct { const char* key; const char* info; } helpLeft[] = {
|
||||||
{ .key = " Arrows: ", .info = "scroll process list" },
|
{ .key = " Arrows: ", .info = "scroll process list" },
|
||||||
{ .key = " Digits: ", .info = "incremental PID search" },
|
{ .key = " Digits: ", .info = "incremental PID search" },
|
||||||
{ .key = " F3 /: ", .info = "incremental name search" },
|
{ .key = " F3 /: ", .info = "incremental name search" },
|
||||||
{ .key = " F4 \\: ",.info = "incremental name filtering" },
|
{ .key = " F4 \\: ",.info = "incremental name filtering" },
|
||||||
{ .key = " F5 t: ", .info = "tree view" },
|
{ .key = " F5 t: ", .info = "tree view" },
|
||||||
|
{ .key = " p: ", .info = "toggle program path" },
|
||||||
{ .key = " u: ", .info = "show processes of a single user" },
|
{ .key = " u: ", .info = "show processes of a single user" },
|
||||||
{ .key = " H: ", .info = "hide/show user process threads" },
|
{ .key = " H: ", .info = "hide/show user process threads" },
|
||||||
{ .key = " K: ", .info = "hide/show kernel threads" },
|
{ .key = " K: ", .info = "hide/show kernel threads" },
|
||||||
@ -394,26 +435,26 @@ static struct { const char* key; const char* info; } helpLeft[] = {
|
|||||||
{ .key = " F6 + -: ", .info = "expand/collapse tree" },
|
{ .key = " F6 + -: ", .info = "expand/collapse tree" },
|
||||||
{ .key = " P M T: ", .info = "sort by CPU%, MEM% or TIME" },
|
{ .key = " P M T: ", .info = "sort by CPU%, MEM% or TIME" },
|
||||||
{ .key = " I: ", .info = "invert sort order" },
|
{ .key = " I: ", .info = "invert sort order" },
|
||||||
{ .key = " F6 >: ", .info = "select sort column" },
|
{ .key = " F6 > .: ", .info = "select sort column" },
|
||||||
{ .key = NULL, .info = NULL }
|
{ .key = NULL, .info = NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct { const char* key; const char* info; } helpRight[] = {
|
static const struct { const char* key; const char* info; } helpRight[] = {
|
||||||
{ .key = " Space: ", .info = "tag process" },
|
{ .key = " Space: ", .info = "tag process" },
|
||||||
{ .key = " c: ", .info = "tag process and its children" },
|
{ .key = " c: ", .info = "tag process and its children" },
|
||||||
{ .key = " U: ", .info = "untag all processes" },
|
{ .key = " U: ", .info = "untag all processes" },
|
||||||
{ .key = " F9 k: ", .info = "kill process/tagged processes" },
|
{ .key = " F9 k: ", .info = "kill process/tagged processes" },
|
||||||
{ .key = " F7 ]: ", .info = "higher priority (root only)" },
|
{ .key = " F7 ]: ", .info = "higher priority (root only)" },
|
||||||
{ .key = " F8 [: ", .info = "lower priority (+ nice)" },
|
{ .key = " F8 [: ", .info = "lower priority (+ nice)" },
|
||||||
#if (HAVE_LIBHWLOC || HAVE_NATIVE_AFFINITY)
|
#if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY)
|
||||||
{ .key = " a: ", .info = "set CPU affinity" },
|
{ .key = " a: ", .info = "set CPU affinity" },
|
||||||
#endif
|
#endif
|
||||||
{ .key = " e: ", .info = "show process environment" },
|
{ .key = " e: ", .info = "show process environment" },
|
||||||
{ .key = " i: ", .info = "set IO prority" },
|
{ .key = " i: ", .info = "set IO priority" },
|
||||||
{ .key = " l: ", .info = "list open files with lsof" },
|
{ .key = " l: ", .info = "list open files with lsof" },
|
||||||
{ .key = " s: ", .info = "trace syscalls with strace" },
|
{ .key = " s: ", .info = "trace syscalls with strace" },
|
||||||
{ .key = " ", .info = "" },
|
{ .key = " ", .info = "" },
|
||||||
{ .key = " F2 S: ", .info = "setup" },
|
{ .key = " F2 C S: ", .info = "setup" },
|
||||||
{ .key = " F1 h: ", .info = "show this help screen" },
|
{ .key = " F1 h: ", .info = "show this help screen" },
|
||||||
{ .key = " F10 q: ", .info = "quit" },
|
{ .key = " F10 q: ", .info = "quit" },
|
||||||
{ .key = NULL, .info = NULL }
|
{ .key = NULL, .info = NULL }
|
||||||
@ -438,7 +479,7 @@ static Htop_Reaction actionHelp(State* st) {
|
|||||||
if (settings->detailedCPUTime) {
|
if (settings->detailedCPUTime) {
|
||||||
addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/");
|
addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/");
|
addattrstr(CRT_colors[CPU_SYSTEM], "kernel"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/");
|
addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/");
|
addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_STEAL], "steal"); addstr("/");
|
addattrstr(CRT_colors[CPU_STEAL], "steal"); addstr("/");
|
||||||
@ -448,8 +489,8 @@ static Htop_Reaction actionHelp(State* st) {
|
|||||||
} else {
|
} else {
|
||||||
addattrstr(CRT_colors[CPU_NICE_TEXT], "low-priority"); addstr("/");
|
addattrstr(CRT_colors[CPU_NICE_TEXT], "low-priority"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/");
|
addattrstr(CRT_colors[CPU_SYSTEM], "kernel"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_STEAL], "virtualiz");
|
addattrstr(CRT_colors[CPU_GUEST], "virtualiz");
|
||||||
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
||||||
}
|
}
|
||||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||||
@ -479,8 +520,8 @@ static Htop_Reaction actionHelp(State* st) {
|
|||||||
for (int i = 0; helpLeft[i].key; i++) { mvaddstr(9+i, 0, helpLeft[i].key); }
|
for (int i = 0; helpLeft[i].key; i++) { mvaddstr(9+i, 0, helpLeft[i].key); }
|
||||||
for (int i = 0; helpRight[i].key; i++) { mvaddstr(9+i, 40, helpRight[i].key); }
|
for (int i = 0; helpRight[i].key; i++) { mvaddstr(9+i, 40, helpRight[i].key); }
|
||||||
attrset(CRT_colors[PROCESS_THREAD]);
|
attrset(CRT_colors[PROCESS_THREAD]);
|
||||||
mvaddstr(15, 32, "threads");
|
mvaddstr(16, 32, "threads");
|
||||||
mvaddstr(16, 26, "threads");
|
mvaddstr(17, 26, "threads");
|
||||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||||
|
|
||||||
attrset(CRT_colors[HELP_BOLD]);
|
attrset(CRT_colors[HELP_BOLD]);
|
||||||
@ -534,6 +575,8 @@ void Action_setBindings(Htop_Action* keys) {
|
|||||||
keys['\\'] = actionIncFilter;
|
keys['\\'] = actionIncFilter;
|
||||||
keys[KEY_F(3)] = actionIncSearch;
|
keys[KEY_F(3)] = actionIncSearch;
|
||||||
keys['/'] = actionIncSearch;
|
keys['/'] = actionIncSearch;
|
||||||
|
keys['n'] = actionIncNext;
|
||||||
|
keys['N'] = actionIncPrev;
|
||||||
|
|
||||||
keys[']'] = actionHigherPriority;
|
keys[']'] = actionHigherPriority;
|
||||||
keys[KEY_F(7)] = actionHigherPriority;
|
keys[KEY_F(7)] = actionHigherPriority;
|
||||||
@ -555,8 +598,9 @@ void Action_setBindings(Htop_Action* keys) {
|
|||||||
keys['+'] = actionExpandOrCollapse;
|
keys['+'] = actionExpandOrCollapse;
|
||||||
keys['='] = actionExpandOrCollapse;
|
keys['='] = actionExpandOrCollapse;
|
||||||
keys['-'] = actionExpandOrCollapse;
|
keys['-'] = actionExpandOrCollapse;
|
||||||
|
keys['\177'] = actionCollapseIntoParent;
|
||||||
keys['u'] = actionFilterByUser;
|
keys['u'] = actionFilterByUser;
|
||||||
keys['F'] = actionFollow;
|
keys['F'] = Action_follow;
|
||||||
keys['S'] = actionSetup;
|
keys['S'] = actionSetup;
|
||||||
keys['C'] = actionSetup;
|
keys['C'] = actionSetup;
|
||||||
keys[KEY_F(2)] = actionSetup;
|
keys[KEY_F(2)] = actionSetup;
|
||||||
|
10
Action.h
10
Action.h
@ -39,18 +39,20 @@ typedef struct State_ {
|
|||||||
} State;
|
} State;
|
||||||
|
|
||||||
|
|
||||||
Object* Action_pickFromVector(State* st, Panel* list, int x);
|
extern Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
bool Action_setUserOnly(const char* userName, uid_t* userId);
|
extern bool Action_setUserOnly(const char* userName, uid_t* userId);
|
||||||
|
|
||||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
extern Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
|
extern Htop_Reaction Action_follow(State* st);
|
||||||
|
|
||||||
void Action_setBindings(Htop_Action* keys);
|
|
||||||
|
extern void Action_setBindings(Htop_Action* keys);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
26
Affinity.c
26
Affinity.c
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - Affinity.c
|
htop - Affinity.c
|
||||||
(C) 2004-2011 Hisham H. Muhammad
|
(C) 2004-2011 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
@ -10,8 +11,13 @@ in the source distribution for its full text.
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef HAVE_LIBHWLOC
|
#ifdef HAVE_LIBHWLOC
|
||||||
#include <hwloc/linux.h>
|
#include <hwloc.h>
|
||||||
#elif HAVE_NATIVE_AFFINITY
|
#if __linux__
|
||||||
|
#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_THREAD
|
||||||
|
#else
|
||||||
|
#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS
|
||||||
|
#endif
|
||||||
|
#elif HAVE_LINUX_AFFINITY
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -55,7 +61,7 @@ void Affinity_add(Affinity* this, int id) {
|
|||||||
|
|
||||||
Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
||||||
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
||||||
bool ok = (hwloc_linux_get_tid_cpubind(pl->topology, proc->pid, cpuset) == 0);
|
bool ok = (hwloc_get_proc_cpubind(pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
|
||||||
Affinity* affinity = NULL;
|
Affinity* affinity = NULL;
|
||||||
if (ok) {
|
if (ok) {
|
||||||
affinity = Affinity_new(pl);
|
affinity = Affinity_new(pl);
|
||||||
@ -74,17 +80,18 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
|||||||
return affinity;
|
return affinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Affinity_set(Process* proc, Affinity* this) {
|
bool Affinity_set(Process* proc, Arg arg) {
|
||||||
|
Affinity *this = arg.v;
|
||||||
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
||||||
for (int i = 0; i < affinity->used; i++) {
|
for (int i = 0; i < this->used; i++) {
|
||||||
hwloc_bitmap_set(cpuset, affinity->cpus[i]);
|
hwloc_bitmap_set(cpuset, this->cpus[i]);
|
||||||
}
|
}
|
||||||
bool ok = (hwloc_linux_set_tid_cpubind(this->pl->topology, proc->pid, cpuset) == 0);
|
bool ok = (hwloc_set_proc_cpubind(this->pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
|
||||||
hwloc_bitmap_free(cpuset);
|
hwloc_bitmap_free(cpuset);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif HAVE_NATIVE_AFFINITY
|
#elif HAVE_LINUX_AFFINITY
|
||||||
|
|
||||||
Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
||||||
cpu_set_t cpuset;
|
cpu_set_t cpuset;
|
||||||
@ -98,7 +105,8 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
|||||||
return affinity;
|
return affinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Affinity_set(Process* proc, Affinity* this) {
|
bool Affinity_set(Process* proc, Arg arg) {
|
||||||
|
Affinity *this = arg.v;
|
||||||
cpu_set_t cpuset;
|
cpu_set_t cpuset;
|
||||||
CPU_ZERO(&cpuset);
|
CPU_ZERO(&cpuset);
|
||||||
for (int i = 0; i < this->used; i++) {
|
for (int i = 0; i < this->used; i++) {
|
||||||
|
24
Affinity.h
24
Affinity.h
@ -5,12 +5,18 @@
|
|||||||
/*
|
/*
|
||||||
htop - Affinity.h
|
htop - Affinity.h
|
||||||
(C) 2004-2011 Hisham H. Muhammad
|
(C) 2004-2011 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_LIBHWLOC
|
#ifdef HAVE_LIBHWLOC
|
||||||
#elif HAVE_NATIVE_AFFINITY
|
#if __linux__
|
||||||
|
#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_THREAD
|
||||||
|
#else
|
||||||
|
#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS
|
||||||
|
#endif
|
||||||
|
#elif HAVE_LINUX_AFFINITY
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
@ -24,23 +30,23 @@ typedef struct Affinity_ {
|
|||||||
} Affinity;
|
} Affinity;
|
||||||
|
|
||||||
|
|
||||||
Affinity* Affinity_new(ProcessList* pl);
|
extern Affinity* Affinity_new(ProcessList* pl);
|
||||||
|
|
||||||
void Affinity_delete(Affinity* this);
|
extern void Affinity_delete(Affinity* this);
|
||||||
|
|
||||||
void Affinity_add(Affinity* this, int id);
|
extern void Affinity_add(Affinity* this, int id);
|
||||||
|
|
||||||
#ifdef HAVE_LIBHWLOC
|
#ifdef HAVE_LIBHWLOC
|
||||||
|
|
||||||
Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
extern Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
||||||
|
|
||||||
bool Affinity_set(Process* proc, Affinity* this);
|
extern bool Affinity_set(Process* proc, Arg arg);
|
||||||
|
|
||||||
#elif HAVE_NATIVE_AFFINITY
|
#elif HAVE_LINUX_AFFINITY
|
||||||
|
|
||||||
Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
extern Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
||||||
|
|
||||||
bool Affinity_set(Process* proc, Affinity* this);
|
extern bool Affinity_set(Process* proc, Arg arg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
|
|||||||
int curCpu = 0;
|
int curCpu = 0;
|
||||||
for (int i = 0; i < pl->cpuCount; i++) {
|
for (int i = 0; i < pl->cpuCount; i++) {
|
||||||
char number[10];
|
char number[10];
|
||||||
snprintf(number, 9, "%d", Settings_cpuId(pl->settings, i));
|
xSnprintf(number, 9, "%d", Settings_cpuId(pl->settings, i));
|
||||||
bool mode;
|
bool mode;
|
||||||
if (curCpu < affinity->used && affinity->cpus[curCpu] == i) {
|
if (curCpu < affinity->used && affinity->cpus[curCpu] == i) {
|
||||||
mode = true;
|
mode = true;
|
||||||
|
@ -16,8 +16,8 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
extern PanelClass AffinityPanel_class;
|
extern PanelClass AffinityPanel_class;
|
||||||
|
|
||||||
Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity);
|
extern Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity);
|
||||||
|
|
||||||
Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl);
|
extern Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -26,7 +26,7 @@ typedef struct AvailableColumnsPanel_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
|
static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
|
||||||
|
|
||||||
static void AvailableColumnsPanel_delete(Object* object) {
|
static void AvailableColumnsPanel_delete(Object* object) {
|
||||||
Panel* super = (Panel*) object;
|
Panel* super = (Panel*) object;
|
||||||
@ -81,7 +81,7 @@ AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns) {
|
|||||||
for (int i = 1; i < Platform_numberOfFields; i++) {
|
for (int i = 1; i < Platform_numberOfFields; i++) {
|
||||||
if (i != COMM && Process_fields[i].description) {
|
if (i != COMM && Process_fields[i].description) {
|
||||||
char description[256];
|
char description[256];
|
||||||
snprintf(description, sizeof(description), "%s - %s", Process_fields[i].name, Process_fields[i].description);
|
xSnprintf(description, sizeof(description), "%s - %s", Process_fields[i].name, Process_fields[i].description);
|
||||||
Panel_add(super, (Object*) ListItem_new(description, i));
|
Panel_add(super, (Object*) ListItem_new(description, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,6 @@ typedef struct AvailableColumnsPanel_ {
|
|||||||
|
|
||||||
extern PanelClass AvailableColumnsPanel_class;
|
extern PanelClass AvailableColumnsPanel_class;
|
||||||
|
|
||||||
AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns);
|
extern AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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;
|
||||||
@ -112,20 +112,22 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade
|
|||||||
this->scr = scr;
|
this->scr = scr;
|
||||||
|
|
||||||
Panel_setHeader(super, "Available meters");
|
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++) {
|
for (int i = 1; Platform_meterTypes[i]; i++) {
|
||||||
MeterClass* type = Platform_meterTypes[i];
|
MeterClass* type = Platform_meterTypes[i];
|
||||||
if (type != &CPUMeter_class) {
|
assert(type != &CPUMeter_class);
|
||||||
const char* label = type->description ? type->description : type->uiName;
|
const char* label = type->description ? type->description : type->uiName;
|
||||||
Panel_add(super, (Object*) ListItem_new(label, i << 16));
|
Panel_add(super, (Object*) ListItem_new(label, i << 16));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Handle (&CPUMeter_class)
|
||||||
MeterClass* type = &CPUMeter_class;
|
MeterClass* type = &CPUMeter_class;
|
||||||
int cpus = pl->cpuCount;
|
int cpus = pl->cpuCount;
|
||||||
if (cpus > 1) {
|
if (cpus > 1) {
|
||||||
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
|
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
|
||||||
for (int i = 1; i <= cpus; i++) {
|
for (int i = 1; i <= cpus; i++) {
|
||||||
char buffer[50];
|
char buffer[50];
|
||||||
sprintf(buffer, "%s %d", type->uiName, i);
|
xSnprintf(buffer, 50, "%s %d", type->uiName, Settings_cpuId(this->settings, i - 1));
|
||||||
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,6 +27,6 @@ typedef struct AvailableMetersPanel_ {
|
|||||||
|
|
||||||
extern PanelClass AvailableMetersPanel_class;
|
extern PanelClass AvailableMetersPanel_class;
|
||||||
|
|
||||||
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl);
|
extern AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,15 +32,15 @@ int BatteryMeter_attributes[] = {
|
|||||||
BATTERY
|
BATTERY
|
||||||
};
|
};
|
||||||
|
|
||||||
static void BatteryMeter_setValues(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) {
|
||||||
this->values[0] = 0;
|
this->values[0] = 0;
|
||||||
snprintf(buffer, len, "n/a");
|
xSnprintf(buffer, len, "n/a");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,11 +58,11 @@ static void BatteryMeter_setValues(Meter * this, char *buffer, int len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isOnAC == AC_PRESENT) {
|
if (isOnAC == AC_PRESENT) {
|
||||||
snprintf(buffer, len, onAcText, percent);
|
xSnprintf(buffer, len, onAcText, percent);
|
||||||
} else if (isOnAC == AC_ABSENT) {
|
} else if (isOnAC == AC_ABSENT) {
|
||||||
snprintf(buffer, len, onBatteryText, percent);
|
xSnprintf(buffer, len, onBatteryText, percent);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buffer, len, unknownText, percent);
|
xSnprintf(buffer, len, unknownText, percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -73,8 +73,9 @@ MeterClass BatteryMeter_class = {
|
|||||||
.extends = Class(Meter),
|
.extends = Class(Meter),
|
||||||
.delete = Meter_delete
|
.delete = Meter_delete
|
||||||
},
|
},
|
||||||
.setValues = BatteryMeter_setValues,
|
.updateValues = BatteryMeter_updateValues,
|
||||||
.defaultMode = TEXT_METERMODE,
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 1,
|
||||||
.total = 100.0,
|
.total = 100.0,
|
||||||
.attributes = BatteryMeter_attributes,
|
.attributes = BatteryMeter_attributes,
|
||||||
.name = "Battery",
|
.name = "Battery",
|
||||||
|
56
CONTRIBUTING.md
Normal file
56
CONTRIBUTING.md
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
Contributing Guide
|
||||||
|
==================
|
||||||
|
|
||||||
|
Hello, and thank you so much for taking your time to contribute in any way to
|
||||||
|
htop! There are many ways to contribute, and I'll try to list them below. The
|
||||||
|
support from the free software community has been amazing over the years and
|
||||||
|
it is the number one thing that keeps me going, maintaining and improving
|
||||||
|
something that started as a tiny pet project back in 2004 and that nowadays is
|
||||||
|
a piece of software used all over the world, in both reality [and
|
||||||
|
fiction!](http://hisham.hm/htop/index.php?page=sightings). Cheers!
|
||||||
|
|
||||||
|
-- Hisham Muhammad
|
||||||
|
|
||||||
|
Bug Reports
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Bug reports should be posted in the [Github issue
|
||||||
|
tracker](http://github.com/hishamhm/htop/issues). (I reply to them all, but I
|
||||||
|
usually do it in batches! :) ) Bug reports are extremely important since it's
|
||||||
|
impossible for me to test htop in every possible system, distribution and
|
||||||
|
scenario. Your feedback is what keeps the tool stable and always improving!
|
||||||
|
Thank you!
|
||||||
|
|
||||||
|
Pull Requests
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Code contributions are most welcome! Just [fork the
|
||||||
|
repo](http://github.com/hishamhm/htop) and send a [pull
|
||||||
|
request](https://github.com/hishamhm/htop/pulls). Help is especially
|
||||||
|
appreciated for support of platforms other than Linux. If proposing new
|
||||||
|
features, please be mindful that htop is a system tool that needs to keep a
|
||||||
|
small footprint and perform well on systems under stress -- so unfortunately I
|
||||||
|
can't accept every new feature proposed, as I need to keep the tool slim and
|
||||||
|
maintainable. Great ideas backed by a PR are always carefully considered for
|
||||||
|
inclusion, though! Also, PRs containing bug fixes and portability tweaks are a
|
||||||
|
no-brainer, please send those in!
|
||||||
|
|
||||||
|
Feature Requests
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Back when htop was hosted in SourceForge, there used to be separate Bug
|
||||||
|
Tracker and Feature Request pages. These go all lumped together under "Issues"
|
||||||
|
in Github, which is a bit confusing. For this reason, I close Feature Requests
|
||||||
|
and file them with the [`feature
|
||||||
|
request`](https://github.com/hishamhm/htop/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22feature+request%22+)
|
||||||
|
label, where they remain accessible, but not mixed with actual bug reports.
|
||||||
|
This doesn't mean I'm dismissing or ignoring feature requests right away! It's
|
||||||
|
just an organizational issue (with Github, really!).
|
||||||
|
|
||||||
|
Donations
|
||||||
|
---------
|
||||||
|
|
||||||
|
If you like htop, feel free to [buy the author a
|
||||||
|
beer](http://hisham.hm/htop/index.php?page=donate). :-)
|
||||||
|
|
173
CPUMeter.c
173
CPUMeter.c
@ -28,13 +28,14 @@ typedef enum {
|
|||||||
CPU_METER_STEAL = 5,
|
CPU_METER_STEAL = 5,
|
||||||
CPU_METER_GUEST = 6,
|
CPU_METER_GUEST = 6,
|
||||||
CPU_METER_IOWAIT = 7,
|
CPU_METER_IOWAIT = 7,
|
||||||
CPU_METER_ITEMCOUNT = 8, // number of entries in this enum
|
CPU_METER_FREQUENCY = 8,
|
||||||
|
CPU_METER_ITEMCOUNT = 9, // number of entries in this enum
|
||||||
} CPUMeterValues;
|
} CPUMeterValues;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
int CPUMeter_attributes[] = {
|
int CPUMeter_attributes[] = {
|
||||||
CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT
|
CPU_NICE, CPU_NORMAL, CPU_SYSTEM, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
@ -48,22 +49,45 @@ static void CPUMeter_init(Meter* this) {
|
|||||||
int cpu = this->param;
|
int cpu = this->param;
|
||||||
if (this->pl->cpuCount > 1) {
|
if (this->pl->cpuCount > 1) {
|
||||||
char caption[10];
|
char caption[10];
|
||||||
sprintf(caption, "%-3d", Settings_cpuId(this->pl->settings, cpu - 1));
|
xSnprintf(caption, sizeof(caption), "%-3d", Settings_cpuId(this->pl->settings, cpu - 1));
|
||||||
Meter_setCaption(this, caption);
|
Meter_setCaption(this, caption);
|
||||||
}
|
}
|
||||||
if (this->param == 0)
|
if (this->param == 0)
|
||||||
Meter_setCaption(this, "Avg");
|
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;
|
int cpu = this->param;
|
||||||
if (cpu > this->pl->cpuCount) {
|
if (cpu > this->pl->cpuCount) {
|
||||||
snprintf(buffer, size, "absent");
|
xSnprintf(buffer, size, "absent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT);
|
memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT);
|
||||||
double percent = Platform_setCPUValues(this, cpu);
|
double percent = Platform_setCPUValues(this, cpu);
|
||||||
snprintf(buffer, size, "%5.1f%%", percent);
|
if (this->pl->settings->showCPUFrequency) {
|
||||||
|
/* Initial frequency is in MHz. Emit it as GHz if it's larger than 1000MHz */
|
||||||
|
double cpuFrequency = this->values[CPU_METER_FREQUENCY];
|
||||||
|
char unit = 'M';
|
||||||
|
char cpuFrequencyBuffer[16];
|
||||||
|
if (cpuFrequency < 0) {
|
||||||
|
xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A");
|
||||||
|
} else {
|
||||||
|
if (cpuFrequency > 1000) {
|
||||||
|
cpuFrequency /= 1000;
|
||||||
|
unit = 'G';
|
||||||
|
}
|
||||||
|
xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.3f%cHz", cpuFrequency, unit);
|
||||||
|
}
|
||||||
|
if (this->pl->settings->showCPUUsage) {
|
||||||
|
xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer);
|
||||||
|
} else {
|
||||||
|
xSnprintf(buffer, size, "%s", cpuFrequencyBuffer);
|
||||||
|
}
|
||||||
|
} else if (this->pl->settings->showCPUUsage) {
|
||||||
|
xSnprintf(buffer, size, "%5.1f%%", percent);
|
||||||
|
} else if (size > 0) {
|
||||||
|
buffer[0] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CPUMeter_display(Object* cast, RichString* out) {
|
static void CPUMeter_display(Object* cast, RichString* out) {
|
||||||
@ -74,44 +98,44 @@ static void CPUMeter_display(Object* cast, RichString* out) {
|
|||||||
RichString_append(out, CRT_colors[METER_TEXT], "absent");
|
RichString_append(out, CRT_colors[METER_TEXT], "absent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_NORMAL]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NORMAL]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], ":");
|
RichString_append(out, CRT_colors[METER_TEXT], ":");
|
||||||
RichString_append(out, CRT_colors[CPU_NORMAL], buffer);
|
RichString_append(out, CRT_colors[CPU_NORMAL], buffer);
|
||||||
if (this->pl->settings->detailedCPUTime) {
|
if (this->pl->settings->detailedCPUTime) {
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "sy:");
|
RichString_append(out, CRT_colors[METER_TEXT], "sy:");
|
||||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
RichString_append(out, CRT_colors[CPU_SYSTEM], buffer);
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_NICE]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "ni:");
|
RichString_append(out, CRT_colors[METER_TEXT], "ni:");
|
||||||
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_IRQ]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_IRQ]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "hi:");
|
RichString_append(out, CRT_colors[METER_TEXT], "hi:");
|
||||||
RichString_append(out, CRT_colors[CPU_IRQ], buffer);
|
RichString_append(out, CRT_colors[CPU_IRQ], buffer);
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_SOFTIRQ]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_SOFTIRQ]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "si:");
|
RichString_append(out, CRT_colors[METER_TEXT], "si:");
|
||||||
RichString_append(out, CRT_colors[CPU_SOFTIRQ], buffer);
|
RichString_append(out, CRT_colors[CPU_SOFTIRQ], buffer);
|
||||||
if (this->values[CPU_METER_STEAL]) {
|
if (this->values[CPU_METER_STEAL]) {
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_STEAL]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_STEAL]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "st:");
|
RichString_append(out, CRT_colors[METER_TEXT], "st:");
|
||||||
RichString_append(out, CRT_colors[CPU_STEAL], buffer);
|
RichString_append(out, CRT_colors[CPU_STEAL], buffer);
|
||||||
}
|
}
|
||||||
if (this->values[CPU_METER_GUEST]) {
|
if (this->values[CPU_METER_GUEST]) {
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_GUEST]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_GUEST]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "gu:");
|
RichString_append(out, CRT_colors[METER_TEXT], "gu:");
|
||||||
RichString_append(out, CRT_colors[CPU_GUEST], buffer);
|
RichString_append(out, CRT_colors[CPU_GUEST], buffer);
|
||||||
}
|
}
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_IOWAIT]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_IOWAIT]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "wa:");
|
RichString_append(out, CRT_colors[METER_TEXT], "wa:");
|
||||||
RichString_append(out, CRT_colors[CPU_IOWAIT], buffer);
|
RichString_append(out, CRT_colors[CPU_IOWAIT], buffer);
|
||||||
} else {
|
} else {
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
|
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
|
||||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
RichString_append(out, CRT_colors[CPU_SYSTEM], buffer);
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_NICE]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "low:");
|
RichString_append(out, CRT_colors[METER_TEXT], "low:");
|
||||||
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
||||||
if (this->values[CPU_METER_IRQ]) {
|
if (this->values[CPU_METER_IRQ]) {
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_IRQ]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_IRQ]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "vir:");
|
RichString_append(out, CRT_colors[METER_TEXT], "vir:");
|
||||||
RichString_append(out, CRT_colors[CPU_GUEST], buffer);
|
RichString_append(out, CRT_colors[CPU_GUEST], buffer);
|
||||||
}
|
}
|
||||||
@ -137,6 +161,15 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int MapClassnameToColumncount(Meter* this){
|
||||||
|
if (strchr(Meter_name(this), '4'))
|
||||||
|
return 4;
|
||||||
|
else if (strchr(Meter_name(this), '2'))
|
||||||
|
return 2;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void AllCPUsMeter_init(Meter* this) {
|
static void AllCPUsMeter_init(Meter* this) {
|
||||||
int cpus = this->pl->cpuCount;
|
int cpus = this->pl->cpuCount;
|
||||||
if (!this->drawData)
|
if (!this->drawData)
|
||||||
@ -152,10 +185,8 @@ static void AllCPUsMeter_init(Meter* this) {
|
|||||||
if (this->mode == 0)
|
if (this->mode == 0)
|
||||||
this->mode = BAR_METERMODE;
|
this->mode = BAR_METERMODE;
|
||||||
int h = Meter_modes[this->mode]->h;
|
int h = Meter_modes[this->mode]->h;
|
||||||
if (strchr(Meter_name(this), '2'))
|
int ncol = MapClassnameToColumncount(this);
|
||||||
this->h = h * ((count+1) / 2);
|
this->h = h * ((count + ncol - 1)/ ncol);
|
||||||
else
|
|
||||||
this->h = h * count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AllCPUsMeter_done(Meter* this) {
|
static void AllCPUsMeter_done(Meter* this) {
|
||||||
@ -175,10 +206,8 @@ static void AllCPUsMeter_updateMode(Meter* this, int mode) {
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Meter_setMode(meters[i], mode);
|
Meter_setMode(meters[i], mode);
|
||||||
}
|
}
|
||||||
if (strchr(Meter_name(this), '2'))
|
int ncol = MapClassnameToColumncount(this);
|
||||||
this->h = h * ((count+1) / 2);
|
this->h = h * ((count + ncol - 1)/ ncol);
|
||||||
else
|
|
||||||
this->h = h * count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
||||||
@ -209,17 +238,33 @@ static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void MultiColCPUsMeter_draw(Meter* this, int x, int y, int w){
|
||||||
|
Meter** meters = (Meter**) this->drawData;
|
||||||
|
int start, count;
|
||||||
|
AllCPUsMeter_getRange(this, &start, &count);
|
||||||
|
int ncol = MapClassnameToColumncount(this);
|
||||||
|
int colwidth = (w-ncol)/ncol + 1;
|
||||||
|
int diff = (w - (colwidth * ncol));
|
||||||
|
int nrows = (count + ncol - 1) / ncol;
|
||||||
|
for (int i = 0; i < count; i++){
|
||||||
|
int d = (i/nrows) > diff ? diff : (i / nrows) ; // dynamic spacer
|
||||||
|
int xpos = x + ((i / nrows) * colwidth) + d;
|
||||||
|
int ypos = y + ((i % nrows) * meters[0]->h);
|
||||||
|
meters[i]->draw(meters[i], xpos, ypos, colwidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MeterClass CPUMeter_class = {
|
MeterClass CPUMeter_class = {
|
||||||
.super = {
|
.super = {
|
||||||
.extends = Class(Meter),
|
.extends = Class(Meter),
|
||||||
.delete = Meter_delete,
|
.delete = Meter_delete,
|
||||||
.display = CPUMeter_display
|
.display = CPUMeter_display
|
||||||
},
|
},
|
||||||
.setValues = CPUMeter_setValues,
|
.updateValues = CPUMeter_updateValues,
|
||||||
.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 +279,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 +298,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 +317,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 +336,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,10 +355,10 @@ 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",
|
||||||
.description = "CPUs (1&2/4): first half in 2 shorter columns",
|
|
||||||
.uiName = "CPUs (1&2/4)",
|
.uiName = "CPUs (1&2/4)",
|
||||||
|
.description = "CPUs (1&2/4): first half in 2 shorter columns",
|
||||||
.caption = "CPU",
|
.caption = "CPU",
|
||||||
.draw = DualColCPUsMeter_draw,
|
.draw = DualColCPUsMeter_draw,
|
||||||
.init = AllCPUsMeter_init,
|
.init = AllCPUsMeter_init,
|
||||||
@ -329,7 +374,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",
|
||||||
@ -340,3 +385,59 @@ MeterClass RightCPUs2Meter_class = {
|
|||||||
.done = AllCPUsMeter_done
|
.done = AllCPUsMeter_done
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MeterClass AllCPUs4Meter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = CPUMeter_display
|
||||||
|
},
|
||||||
|
.defaultMode = CUSTOM_METERMODE,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = CPUMeter_attributes,
|
||||||
|
.name = "AllCPUs4",
|
||||||
|
.uiName = "CPUs (1&2&3&4/4)",
|
||||||
|
.description = "CPUs (1&2&3&4/4): all CPUs in 4 shorter columns",
|
||||||
|
.caption = "CPU",
|
||||||
|
.draw = MultiColCPUsMeter_draw,
|
||||||
|
.init = AllCPUsMeter_init,
|
||||||
|
.updateMode = AllCPUsMeter_updateMode,
|
||||||
|
.done = AllCPUsMeter_done
|
||||||
|
};
|
||||||
|
|
||||||
|
MeterClass LeftCPUs4Meter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = CPUMeter_display
|
||||||
|
},
|
||||||
|
.defaultMode = CUSTOM_METERMODE,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = CPUMeter_attributes,
|
||||||
|
.name = "LeftCPUs4",
|
||||||
|
.uiName = "CPUs (1-4/8)",
|
||||||
|
.description = "CPUs (1-4/8): first half in 4 shorter columns",
|
||||||
|
.caption = "CPU",
|
||||||
|
.draw = MultiColCPUsMeter_draw,
|
||||||
|
.init = AllCPUsMeter_init,
|
||||||
|
.updateMode = AllCPUsMeter_updateMode,
|
||||||
|
.done = AllCPUsMeter_done
|
||||||
|
};
|
||||||
|
|
||||||
|
MeterClass RightCPUs4Meter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = CPUMeter_display
|
||||||
|
},
|
||||||
|
.defaultMode = CUSTOM_METERMODE,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = CPUMeter_attributes,
|
||||||
|
.name = "RightCPUs4",
|
||||||
|
.uiName = "CPUs (5-8/8)",
|
||||||
|
.description = "CPUs (5-8/8): second half in 4 shorter columns",
|
||||||
|
.caption = "CPU",
|
||||||
|
.draw = MultiColCPUsMeter_draw,
|
||||||
|
.init = AllCPUsMeter_init,
|
||||||
|
.updateMode = AllCPUsMeter_updateMode,
|
||||||
|
.done = AllCPUsMeter_done
|
||||||
|
};
|
||||||
|
@ -20,7 +20,8 @@ typedef enum {
|
|||||||
CPU_METER_STEAL = 5,
|
CPU_METER_STEAL = 5,
|
||||||
CPU_METER_GUEST = 6,
|
CPU_METER_GUEST = 6,
|
||||||
CPU_METER_IOWAIT = 7,
|
CPU_METER_IOWAIT = 7,
|
||||||
CPU_METER_ITEMCOUNT = 8, // number of entries in this enum
|
CPU_METER_FREQUENCY = 8,
|
||||||
|
CPU_METER_ITEMCOUNT = 9, // number of entries in this enum
|
||||||
} CPUMeterValues;
|
} CPUMeterValues;
|
||||||
|
|
||||||
|
|
||||||
@ -47,5 +48,10 @@ extern MeterClass LeftCPUs2Meter_class;
|
|||||||
|
|
||||||
extern MeterClass RightCPUs2Meter_class;
|
extern MeterClass RightCPUs2Meter_class;
|
||||||
|
|
||||||
|
extern MeterClass AllCPUs4Meter_class;
|
||||||
|
|
||||||
|
extern MeterClass LeftCPUs4Meter_class;
|
||||||
|
|
||||||
|
extern MeterClass RightCPUs4Meter_class;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
200
CRT.c
200
CRT.c
@ -5,6 +5,7 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
|
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
@ -17,8 +18,14 @@ in the source distribution for its full text.
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
|
#if HAVE_SETUID_ENABLED
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
#define ColorIndex(i,j) ((7-i)*8+j)
|
||||||
|
|
||||||
|
#define ColorPair(i,j) COLOR_PAIR(ColorIndex(i,j))
|
||||||
|
|
||||||
#define Black COLOR_BLACK
|
#define Black COLOR_BLACK
|
||||||
#define Red COLOR_RED
|
#define Red COLOR_RED
|
||||||
@ -29,6 +36,9 @@ in the source distribution for its full text.
|
|||||||
#define Cyan COLOR_CYAN
|
#define Cyan COLOR_CYAN
|
||||||
#define White COLOR_WHITE
|
#define White COLOR_WHITE
|
||||||
|
|
||||||
|
#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
|
||||||
|
#define ColorIndexGrayBlack ColorIndex(Magenta,Magenta)
|
||||||
|
|
||||||
#define KEY_WHEELUP KEY_F(20)
|
#define KEY_WHEELUP KEY_F(20)
|
||||||
#define KEY_WHEELDOWN KEY_F(21)
|
#define KEY_WHEELDOWN KEY_F(21)
|
||||||
#define KEY_RECLICK KEY_F(22)
|
#define KEY_RECLICK KEY_F(22)
|
||||||
@ -112,18 +122,30 @@ typedef enum ColorElements_ {
|
|||||||
CPU_NICE,
|
CPU_NICE,
|
||||||
CPU_NICE_TEXT,
|
CPU_NICE_TEXT,
|
||||||
CPU_NORMAL,
|
CPU_NORMAL,
|
||||||
CPU_KERNEL,
|
CPU_SYSTEM,
|
||||||
CPU_IOWAIT,
|
CPU_IOWAIT,
|
||||||
CPU_IRQ,
|
CPU_IRQ,
|
||||||
CPU_SOFTIRQ,
|
CPU_SOFTIRQ,
|
||||||
CPU_STEAL,
|
CPU_STEAL,
|
||||||
CPU_GUEST,
|
CPU_GUEST,
|
||||||
|
PRESSURE_STALL_TEN,
|
||||||
|
PRESSURE_STALL_SIXTY,
|
||||||
|
PRESSURE_STALL_THREEHUNDRED,
|
||||||
|
ZFS_MFU,
|
||||||
|
ZFS_MRU,
|
||||||
|
ZFS_ANON,
|
||||||
|
ZFS_HEADER,
|
||||||
|
ZFS_OTHER,
|
||||||
|
ZFS_COMPRESSED,
|
||||||
|
ZFS_RATIO,
|
||||||
LAST_COLORELEMENT
|
LAST_COLORELEMENT
|
||||||
} ColorElements;
|
} ColorElements;
|
||||||
|
|
||||||
void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
extern void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
||||||
|
|
||||||
void CRT_handleSIGSEGV(int sgn);
|
extern void CRT_handleSIGSEGV(int sgn);
|
||||||
|
|
||||||
|
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@ -181,7 +203,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[LED_COLOR] = ColorPair(Green,Black),
|
[LED_COLOR] = ColorPair(Green,Black),
|
||||||
[TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black),
|
[TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black),
|
||||||
[PROCESS] = A_NORMAL,
|
[PROCESS] = A_NORMAL,
|
||||||
[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Black),
|
[PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack,
|
||||||
[PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
|
[PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
|
||||||
[PROCESS_MEGABYTES] = ColorPair(Cyan,Black),
|
[PROCESS_MEGABYTES] = ColorPair(Cyan,Black),
|
||||||
[PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Black),
|
[PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Black),
|
||||||
@ -193,7 +215,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[PROCESS_THREAD] = ColorPair(Green,Black),
|
[PROCESS_THREAD] = ColorPair(Green,Black),
|
||||||
[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Black),
|
[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Black),
|
||||||
[BAR_BORDER] = A_BOLD,
|
[BAR_BORDER] = A_BOLD,
|
||||||
[BAR_SHADOW] = A_BOLD | ColorPair(Black,Black),
|
[BAR_SHADOW] = A_BOLD | ColorPairGrayBlack,
|
||||||
[SWAP] = ColorPair(Red,Black),
|
[SWAP] = ColorPair(Red,Black),
|
||||||
[GRAPH_1] = A_BOLD | ColorPair(Cyan,Black),
|
[GRAPH_1] = A_BOLD | ColorPair(Cyan,Black),
|
||||||
[GRAPH_2] = ColorPair(Cyan,Black),
|
[GRAPH_2] = ColorPair(Cyan,Black),
|
||||||
@ -214,12 +236,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = ColorPair(Blue,Black),
|
[CPU_NICE] = ColorPair(Blue,Black),
|
||||||
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black),
|
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black),
|
||||||
[CPU_NORMAL] = ColorPair(Green,Black),
|
[CPU_NORMAL] = ColorPair(Green,Black),
|
||||||
[CPU_KERNEL] = ColorPair(Red,Black),
|
[CPU_SYSTEM] = ColorPair(Red,Black),
|
||||||
[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black),
|
[CPU_IOWAIT] = A_BOLD | ColorPairGrayBlack,
|
||||||
[CPU_IRQ] = ColorPair(Yellow,Black),
|
[CPU_IRQ] = ColorPair(Yellow,Black),
|
||||||
[CPU_SOFTIRQ] = ColorPair(Magenta,Black),
|
[CPU_SOFTIRQ] = ColorPair(Magenta,Black),
|
||||||
[CPU_STEAL] = ColorPair(Cyan,Black),
|
[CPU_STEAL] = ColorPair(Cyan,Black),
|
||||||
[CPU_GUEST] = ColorPair(Cyan,Black),
|
[CPU_GUEST] = ColorPair(Cyan,Black),
|
||||||
|
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan,Black),
|
||||||
|
[PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan,Black),
|
||||||
|
[PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Black),
|
||||||
|
[ZFS_MFU] = ColorPair(Blue,Black),
|
||||||
|
[ZFS_MRU] = ColorPair(Yellow,Black),
|
||||||
|
[ZFS_ANON] = ColorPair(Magenta,Black),
|
||||||
|
[ZFS_HEADER] = ColorPair(Cyan,Black),
|
||||||
|
[ZFS_OTHER] = ColorPair(Magenta,Black),
|
||||||
|
[ZFS_COMPRESSED] = ColorPair(Blue,Black),
|
||||||
|
[ZFS_RATIO] = ColorPair(Magenta,Black),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_MONOCHROME] = {
|
[COLORSCHEME_MONOCHROME] = {
|
||||||
[RESET_COLOR] = A_NORMAL,
|
[RESET_COLOR] = A_NORMAL,
|
||||||
@ -273,12 +305,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = A_NORMAL,
|
[CPU_NICE] = A_NORMAL,
|
||||||
[CPU_NICE_TEXT] = A_NORMAL,
|
[CPU_NICE_TEXT] = A_NORMAL,
|
||||||
[CPU_NORMAL] = A_BOLD,
|
[CPU_NORMAL] = A_BOLD,
|
||||||
[CPU_KERNEL] = A_BOLD,
|
[CPU_SYSTEM] = A_BOLD,
|
||||||
[CPU_IOWAIT] = A_NORMAL,
|
[CPU_IOWAIT] = A_NORMAL,
|
||||||
[CPU_IRQ] = A_BOLD,
|
[CPU_IRQ] = A_BOLD,
|
||||||
[CPU_SOFTIRQ] = A_BOLD,
|
[CPU_SOFTIRQ] = A_BOLD,
|
||||||
[CPU_STEAL] = A_REVERSE,
|
[CPU_STEAL] = A_REVERSE,
|
||||||
[CPU_GUEST] = A_REVERSE,
|
[CPU_GUEST] = A_REVERSE,
|
||||||
|
[PRESSURE_STALL_THREEHUNDRED] = A_DIM,
|
||||||
|
[PRESSURE_STALL_SIXTY] = A_NORMAL,
|
||||||
|
[PRESSURE_STALL_TEN] = A_BOLD,
|
||||||
|
[ZFS_MFU] = A_NORMAL,
|
||||||
|
[ZFS_MRU] = A_NORMAL,
|
||||||
|
[ZFS_ANON] = A_DIM,
|
||||||
|
[ZFS_HEADER] = A_BOLD,
|
||||||
|
[ZFS_OTHER] = A_DIM,
|
||||||
|
[ZFS_COMPRESSED] = A_BOLD,
|
||||||
|
[ZFS_RATIO] = A_BOLD,
|
||||||
},
|
},
|
||||||
[COLORSCHEME_BLACKONWHITE] = {
|
[COLORSCHEME_BLACKONWHITE] = {
|
||||||
[RESET_COLOR] = ColorPair(Black,White),
|
[RESET_COLOR] = ColorPair(Black,White),
|
||||||
@ -332,12 +374,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = ColorPair(Cyan,White),
|
[CPU_NICE] = ColorPair(Cyan,White),
|
||||||
[CPU_NICE_TEXT] = ColorPair(Cyan,White),
|
[CPU_NICE_TEXT] = ColorPair(Cyan,White),
|
||||||
[CPU_NORMAL] = ColorPair(Green,White),
|
[CPU_NORMAL] = ColorPair(Green,White),
|
||||||
[CPU_KERNEL] = ColorPair(Red,White),
|
[CPU_SYSTEM] = ColorPair(Red,White),
|
||||||
[CPU_IOWAIT] = A_BOLD | ColorPair(Black, White),
|
[CPU_IOWAIT] = A_BOLD | ColorPair(Black,White),
|
||||||
[CPU_IRQ] = ColorPair(Blue,White),
|
[CPU_IRQ] = ColorPair(Blue,White),
|
||||||
[CPU_SOFTIRQ] = ColorPair(Blue,White),
|
[CPU_SOFTIRQ] = ColorPair(Blue,White),
|
||||||
[CPU_STEAL] = ColorPair(Cyan,White),
|
[CPU_STEAL] = ColorPair(Cyan,White),
|
||||||
[CPU_GUEST] = ColorPair(Cyan,White),
|
[CPU_GUEST] = ColorPair(Cyan,White),
|
||||||
|
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,White),
|
||||||
|
[PRESSURE_STALL_SIXTY] = ColorPair(Black,White),
|
||||||
|
[PRESSURE_STALL_TEN] = ColorPair(Black,White),
|
||||||
|
[ZFS_MFU] = ColorPair(Cyan,White),
|
||||||
|
[ZFS_MRU] = ColorPair(Yellow,White),
|
||||||
|
[ZFS_ANON] = ColorPair(Magenta,White),
|
||||||
|
[ZFS_HEADER] = ColorPair(Yellow,White),
|
||||||
|
[ZFS_OTHER] = ColorPair(Magenta,White),
|
||||||
|
[ZFS_COMPRESSED] = ColorPair(Cyan,White),
|
||||||
|
[ZFS_RATIO] = ColorPair(Magenta,White),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_LIGHTTERMINAL] = {
|
[COLORSCHEME_LIGHTTERMINAL] = {
|
||||||
[RESET_COLOR] = ColorPair(Black,Black),
|
[RESET_COLOR] = ColorPair(Black,Black),
|
||||||
@ -358,7 +410,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[LED_COLOR] = ColorPair(Green,Black),
|
[LED_COLOR] = ColorPair(Green,Black),
|
||||||
[TASKS_RUNNING] = ColorPair(Green,Black),
|
[TASKS_RUNNING] = ColorPair(Green,Black),
|
||||||
[PROCESS] = ColorPair(Black,Black),
|
[PROCESS] = ColorPair(Black,Black),
|
||||||
[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Black),
|
[PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack,
|
||||||
[PROCESS_TAG] = ColorPair(White,Blue),
|
[PROCESS_TAG] = ColorPair(White,Blue),
|
||||||
[PROCESS_MEGABYTES] = ColorPair(Blue,Black),
|
[PROCESS_MEGABYTES] = ColorPair(Blue,Black),
|
||||||
[PROCESS_BASENAME] = ColorPair(Green,Black),
|
[PROCESS_BASENAME] = ColorPair(Green,Black),
|
||||||
@ -370,7 +422,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[PROCESS_THREAD] = ColorPair(Blue,Black),
|
[PROCESS_THREAD] = ColorPair(Blue,Black),
|
||||||
[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black),
|
[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black),
|
||||||
[BAR_BORDER] = ColorPair(Blue,Black),
|
[BAR_BORDER] = ColorPair(Blue,Black),
|
||||||
[BAR_SHADOW] = ColorPair(Black,Black),
|
[BAR_SHADOW] = ColorPairGrayBlack,
|
||||||
[SWAP] = ColorPair(Red,Black),
|
[SWAP] = ColorPair(Red,Black),
|
||||||
[GRAPH_1] = A_BOLD | ColorPair(Cyan,Black),
|
[GRAPH_1] = A_BOLD | ColorPair(Cyan,Black),
|
||||||
[GRAPH_2] = ColorPair(Cyan,Black),
|
[GRAPH_2] = ColorPair(Cyan,Black),
|
||||||
@ -391,12 +443,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = ColorPair(Cyan,Black),
|
[CPU_NICE] = ColorPair(Cyan,Black),
|
||||||
[CPU_NICE_TEXT] = ColorPair(Cyan,Black),
|
[CPU_NICE_TEXT] = ColorPair(Cyan,Black),
|
||||||
[CPU_NORMAL] = ColorPair(Green,Black),
|
[CPU_NORMAL] = ColorPair(Green,Black),
|
||||||
[CPU_KERNEL] = ColorPair(Red,Black),
|
[CPU_SYSTEM] = ColorPair(Red,Black),
|
||||||
[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black),
|
[CPU_IOWAIT] = A_BOLD | ColorPair(Black,Black),
|
||||||
[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black),
|
[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black),
|
||||||
[CPU_SOFTIRQ] = ColorPair(Blue,Black),
|
[CPU_SOFTIRQ] = ColorPair(Blue,Black),
|
||||||
[CPU_STEAL] = ColorPair(Black,Black),
|
[CPU_STEAL] = ColorPair(Black,Black),
|
||||||
[CPU_GUEST] = ColorPair(Black,Black),
|
[CPU_GUEST] = ColorPair(Black,Black),
|
||||||
|
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,Black),
|
||||||
|
[PRESSURE_STALL_SIXTY] = ColorPair(Black,Black),
|
||||||
|
[PRESSURE_STALL_TEN] = ColorPair(Black,Black),
|
||||||
|
[ZFS_MFU] = ColorPair(Cyan,Black),
|
||||||
|
[ZFS_MRU] = ColorPair(Yellow,Black),
|
||||||
|
[ZFS_ANON] = A_BOLD | ColorPair(Magenta,Black),
|
||||||
|
[ZFS_HEADER] = ColorPair(Black,Black),
|
||||||
|
[ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black),
|
||||||
|
[ZFS_COMPRESSED] = ColorPair(Cyan,Black),
|
||||||
|
[ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Black),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_MIDNIGHT] = {
|
[COLORSCHEME_MIDNIGHT] = {
|
||||||
[RESET_COLOR] = ColorPair(White,Blue),
|
[RESET_COLOR] = ColorPair(White,Blue),
|
||||||
@ -450,12 +512,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = A_BOLD | ColorPair(Cyan,Blue),
|
[CPU_NICE] = A_BOLD | ColorPair(Cyan,Blue),
|
||||||
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan,Blue),
|
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan,Blue),
|
||||||
[CPU_NORMAL] = A_BOLD | ColorPair(Green,Blue),
|
[CPU_NORMAL] = A_BOLD | ColorPair(Green,Blue),
|
||||||
[CPU_KERNEL] = A_BOLD | ColorPair(Red,Blue),
|
[CPU_SYSTEM] = A_BOLD | ColorPair(Red,Blue),
|
||||||
[CPU_IOWAIT] = A_BOLD | ColorPair(Blue,Blue),
|
[CPU_IOWAIT] = A_BOLD | ColorPair(Blue,Blue),
|
||||||
[CPU_IRQ] = A_BOLD | ColorPair(Black,Blue),
|
[CPU_IRQ] = A_BOLD | ColorPair(Black,Blue),
|
||||||
[CPU_SOFTIRQ] = ColorPair(Black,Blue),
|
[CPU_SOFTIRQ] = ColorPair(Black,Blue),
|
||||||
[CPU_STEAL] = ColorPair(White,Blue),
|
[CPU_STEAL] = ColorPair(White,Blue),
|
||||||
[CPU_GUEST] = ColorPair(White,Blue),
|
[CPU_GUEST] = ColorPair(White,Blue),
|
||||||
|
[PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black,Blue),
|
||||||
|
[PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White,Blue),
|
||||||
|
[PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Blue),
|
||||||
|
[ZFS_MFU] = A_BOLD | ColorPair(White,Blue),
|
||||||
|
[ZFS_MRU] = A_BOLD | ColorPair(Yellow,Blue),
|
||||||
|
[ZFS_ANON] = A_BOLD | ColorPair(Magenta,Blue),
|
||||||
|
[ZFS_HEADER] = A_BOLD | ColorPair(Yellow,Blue),
|
||||||
|
[ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Blue),
|
||||||
|
[ZFS_COMPRESSED] = A_BOLD | ColorPair(White,Blue),
|
||||||
|
[ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Blue),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_BLACKNIGHT] = {
|
[COLORSCHEME_BLACKNIGHT] = {
|
||||||
[RESET_COLOR] = ColorPair(Cyan,Black),
|
[RESET_COLOR] = ColorPair(Cyan,Black),
|
||||||
@ -476,7 +548,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[LED_COLOR] = ColorPair(Green,Black),
|
[LED_COLOR] = ColorPair(Green,Black),
|
||||||
[TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black),
|
[TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black),
|
||||||
[PROCESS] = ColorPair(Cyan,Black),
|
[PROCESS] = ColorPair(Cyan,Black),
|
||||||
[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Black),
|
[PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack,
|
||||||
[PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
|
[PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
|
||||||
[PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black),
|
[PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black),
|
||||||
[PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black),
|
[PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black),
|
||||||
@ -509,12 +581,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = ColorPair(Blue,Black),
|
[CPU_NICE] = ColorPair(Blue,Black),
|
||||||
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black),
|
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black),
|
||||||
[CPU_NORMAL] = ColorPair(Green,Black),
|
[CPU_NORMAL] = ColorPair(Green,Black),
|
||||||
[CPU_KERNEL] = ColorPair(Red,Black),
|
[CPU_SYSTEM] = ColorPair(Red,Black),
|
||||||
[CPU_IOWAIT] = ColorPair(Yellow,Black),
|
[CPU_IOWAIT] = ColorPair(Yellow,Black),
|
||||||
[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black),
|
[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black),
|
||||||
[CPU_SOFTIRQ] = ColorPair(Blue,Black),
|
[CPU_SOFTIRQ] = ColorPair(Blue,Black),
|
||||||
[CPU_STEAL] = ColorPair(Cyan,Black),
|
[CPU_STEAL] = ColorPair(Cyan,Black),
|
||||||
[CPU_GUEST] = ColorPair(Cyan,Black),
|
[CPU_GUEST] = ColorPair(Cyan,Black),
|
||||||
|
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green,Black),
|
||||||
|
[PRESSURE_STALL_SIXTY] = ColorPair(Green,Black),
|
||||||
|
[PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green,Black),
|
||||||
|
[ZFS_MFU] = ColorPair(Blue,Black),
|
||||||
|
[ZFS_MRU] = ColorPair(Yellow,Black),
|
||||||
|
[ZFS_ANON] = ColorPair(Magenta,Black),
|
||||||
|
[ZFS_HEADER] = ColorPair(Yellow,Black),
|
||||||
|
[ZFS_OTHER] = ColorPair(Magenta,Black),
|
||||||
|
[ZFS_COMPRESSED] = ColorPair(Blue,Black),
|
||||||
|
[ZFS_RATIO] = ColorPair(Magenta,Black),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated.
|
[COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated.
|
||||||
};
|
};
|
||||||
@ -539,6 +621,48 @@ static void CRT_handleSIGTERM(int sgn) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HAVE_SETUID_ENABLED
|
||||||
|
|
||||||
|
static int CRT_euid = -1;
|
||||||
|
|
||||||
|
static int CRT_egid = -1;
|
||||||
|
|
||||||
|
#define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0)
|
||||||
|
|
||||||
|
void CRT_dropPrivileges() {
|
||||||
|
CRT_egid = getegid();
|
||||||
|
CRT_euid = geteuid();
|
||||||
|
if (setegid(getgid()) == -1) {
|
||||||
|
DIE("Fatal error: failed dropping group privileges.\n");
|
||||||
|
}
|
||||||
|
if (seteuid(getuid()) == -1) {
|
||||||
|
DIE("Fatal error: failed dropping user privileges.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRT_restorePrivileges() {
|
||||||
|
if (CRT_egid == -1 || CRT_euid == -1) {
|
||||||
|
DIE("Fatal error: internal inconsistency.\n");
|
||||||
|
}
|
||||||
|
if (setegid(CRT_egid) == -1) {
|
||||||
|
DIE("Fatal error: failed restoring group privileges.\n");
|
||||||
|
}
|
||||||
|
if (seteuid(CRT_euid) == -1) {
|
||||||
|
DIE("Fatal error: failed restoring user privileges.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* Turn setuid operations into NOPs */
|
||||||
|
|
||||||
|
#ifndef CRT_dropPrivileges
|
||||||
|
#define CRT_dropPrivileges()
|
||||||
|
#define CRT_restorePrivileges()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: pass an instance of Settings instead.
|
// TODO: pass an instance of Settings instead.
|
||||||
|
|
||||||
void CRT_init(int delay, int colorScheme) {
|
void CRT_init(int delay, int colorScheme) {
|
||||||
@ -550,12 +674,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 | ColorPair(Black,Black)) ? 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);
|
||||||
@ -573,7 +697,7 @@ void CRT_init(int delay, int colorScheme) {
|
|||||||
CRT_scrollHAmount = 20;
|
CRT_scrollHAmount = 20;
|
||||||
else
|
else
|
||||||
CRT_scrollHAmount = 5;
|
CRT_scrollHAmount = 5;
|
||||||
if (String_eq(CRT_termType, "xterm") || String_eq(CRT_termType, "xterm-color") || String_eq(CRT_termType, "vt220")) {
|
if (String_startsWith(CRT_termType, "xterm") || String_eq(CRT_termType, "vt220")) {
|
||||||
define_key("\033[H", KEY_HOME);
|
define_key("\033[H", KEY_HOME);
|
||||||
define_key("\033[F", KEY_END);
|
define_key("\033[F", KEY_END);
|
||||||
define_key("\033[7~", KEY_HOME);
|
define_key("\033[7~", KEY_HOME);
|
||||||
@ -587,11 +711,17 @@ void CRT_init(int delay, int colorScheme) {
|
|||||||
define_key("\033[13~", KEY_F(3));
|
define_key("\033[13~", KEY_F(3));
|
||||||
define_key("\033[14~", KEY_F(4));
|
define_key("\033[14~", KEY_F(4));
|
||||||
define_key("\033[17;2~", KEY_F(18));
|
define_key("\033[17;2~", KEY_F(18));
|
||||||
|
char sequence[3] = "\033a";
|
||||||
|
for (char c = 'a'; c <= 'z'; c++) {
|
||||||
|
sequence[1] = c;
|
||||||
|
define_key(sequence, KEY_ALT('A' + (c - 'a')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
signal(11, CRT_handleSIGSEGV);
|
signal(11, CRT_handleSIGSEGV);
|
||||||
#endif
|
#endif
|
||||||
signal(SIGTERM, CRT_handleSIGTERM);
|
signal(SIGTERM, CRT_handleSIGTERM);
|
||||||
|
signal(SIGQUIT, CRT_handleSIGTERM);
|
||||||
use_default_colors();
|
use_default_colors();
|
||||||
if (!has_colors())
|
if (!has_colors())
|
||||||
CRT_colorScheme = 1;
|
CRT_colorScheme = 1;
|
||||||
@ -618,6 +748,7 @@ void CRT_init(int delay, int colorScheme) {
|
|||||||
#else
|
#else
|
||||||
mousemask(BUTTON1_RELEASED, NULL);
|
mousemask(BUTTON1_RELEASED, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRT_done() {
|
void CRT_done() {
|
||||||
@ -653,14 +784,23 @@ void CRT_enableDelay() {
|
|||||||
|
|
||||||
void CRT_setColors(int colorScheme) {
|
void CRT_setColors(int colorScheme) {
|
||||||
CRT_colorScheme = colorScheme;
|
CRT_colorScheme = colorScheme;
|
||||||
if (colorScheme == COLORSCHEME_BLACKNIGHT) {
|
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++) {
|
||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++) {
|
||||||
init_pair((7-i)*8+j, i, j);
|
if (ColorIndex(i,j) != ColorPairGrayBlack) {
|
||||||
} else {
|
int bg = (colorScheme != COLORSCHEME_BLACKNIGHT)
|
||||||
for (int i = 0; i < 8; i++)
|
? (j==0 ? -1 : j)
|
||||||
for (int j = 0; j < 8; j++)
|
: j;
|
||||||
init_pair((7-i)*8+j, i, (j==0?-1:j));
|
init_pair(ColorIndex(i,j), i, bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int grayBlackFg = COLORS > 8 ? 8 : 0;
|
||||||
|
int grayBlackBg = (colorScheme != COLORSCHEME_BLACKNIGHT)
|
||||||
|
? -1
|
||||||
|
: 0;
|
||||||
|
init_pair(ColorIndexGrayBlack, grayBlackFg, grayBlackBg);
|
||||||
|
|
||||||
CRT_colors = CRT_colorSchemes[colorScheme];
|
CRT_colors = CRT_colorSchemes[colorScheme];
|
||||||
}
|
}
|
||||||
|
67
CRT.h
67
CRT.h
@ -9,7 +9,12 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
#if HAVE_SETUID_ENABLED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ColorIndex(i,j) ((7-i)*8+j)
|
||||||
|
|
||||||
|
#define ColorPair(i,j) COLOR_PAIR(ColorIndex(i,j))
|
||||||
|
|
||||||
#define Black COLOR_BLACK
|
#define Black COLOR_BLACK
|
||||||
#define Red COLOR_RED
|
#define Red COLOR_RED
|
||||||
@ -20,6 +25,9 @@ in the source distribution for its full text.
|
|||||||
#define Cyan COLOR_CYAN
|
#define Cyan COLOR_CYAN
|
||||||
#define White COLOR_WHITE
|
#define White COLOR_WHITE
|
||||||
|
|
||||||
|
#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
|
||||||
|
#define ColorIndexGrayBlack ColorIndex(Magenta,Magenta)
|
||||||
|
|
||||||
#define KEY_WHEELUP KEY_F(20)
|
#define KEY_WHEELUP KEY_F(20)
|
||||||
#define KEY_WHEELDOWN KEY_F(21)
|
#define KEY_WHEELDOWN KEY_F(21)
|
||||||
#define KEY_RECLICK KEY_F(22)
|
#define KEY_RECLICK KEY_F(22)
|
||||||
@ -102,18 +110,30 @@ typedef enum ColorElements_ {
|
|||||||
CPU_NICE,
|
CPU_NICE,
|
||||||
CPU_NICE_TEXT,
|
CPU_NICE_TEXT,
|
||||||
CPU_NORMAL,
|
CPU_NORMAL,
|
||||||
CPU_KERNEL,
|
CPU_SYSTEM,
|
||||||
CPU_IOWAIT,
|
CPU_IOWAIT,
|
||||||
CPU_IRQ,
|
CPU_IRQ,
|
||||||
CPU_SOFTIRQ,
|
CPU_SOFTIRQ,
|
||||||
CPU_STEAL,
|
CPU_STEAL,
|
||||||
CPU_GUEST,
|
CPU_GUEST,
|
||||||
|
PRESSURE_STALL_TEN,
|
||||||
|
PRESSURE_STALL_SIXTY,
|
||||||
|
PRESSURE_STALL_THREEHUNDRED,
|
||||||
|
ZFS_MFU,
|
||||||
|
ZFS_MRU,
|
||||||
|
ZFS_ANON,
|
||||||
|
ZFS_HEADER,
|
||||||
|
ZFS_OTHER,
|
||||||
|
ZFS_COMPRESSED,
|
||||||
|
ZFS_RATIO,
|
||||||
LAST_COLORELEMENT
|
LAST_COLORELEMENT
|
||||||
} ColorElements;
|
} ColorElements;
|
||||||
|
|
||||||
void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
extern void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
||||||
|
|
||||||
void CRT_handleSIGSEGV(int sgn);
|
extern void CRT_handleSIGSEGV(int sgn);
|
||||||
|
|
||||||
|
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
||||||
|
|
||||||
|
|
||||||
extern const char *CRT_treeStrAscii[TREE_STR_COUNT];
|
extern const char *CRT_treeStrAscii[TREE_STR_COUNT];
|
||||||
@ -130,7 +150,7 @@ extern const char **CRT_treeStr;
|
|||||||
|
|
||||||
extern int CRT_delay;
|
extern int CRT_delay;
|
||||||
|
|
||||||
int* CRT_colors;
|
extern int* CRT_colors;
|
||||||
|
|
||||||
extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT];
|
extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT];
|
||||||
|
|
||||||
@ -140,28 +160,47 @@ extern int CRT_scrollHAmount;
|
|||||||
|
|
||||||
extern int CRT_scrollWheelVAmount;
|
extern int CRT_scrollWheelVAmount;
|
||||||
|
|
||||||
char* CRT_termType;
|
extern char* CRT_termType;
|
||||||
|
|
||||||
// TODO move color scheme to Settings, perhaps?
|
// TODO move color scheme to Settings, perhaps?
|
||||||
|
|
||||||
extern int CRT_colorScheme;
|
extern int CRT_colorScheme;
|
||||||
|
|
||||||
void *backtraceArray[128];
|
extern void *backtraceArray[128];
|
||||||
|
|
||||||
|
#if HAVE_SETUID_ENABLED
|
||||||
|
|
||||||
|
#define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0)
|
||||||
|
|
||||||
|
extern void CRT_dropPrivileges();
|
||||||
|
|
||||||
|
extern void CRT_restorePrivileges();
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* Turn setuid operations into NOPs */
|
||||||
|
|
||||||
|
#ifndef CRT_dropPrivileges
|
||||||
|
#define CRT_dropPrivileges()
|
||||||
|
#define CRT_restorePrivileges()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: pass an instance of Settings instead.
|
// TODO: pass an instance of Settings instead.
|
||||||
|
|
||||||
void CRT_init(int delay, int colorScheme);
|
extern void CRT_init(int delay, int colorScheme);
|
||||||
|
|
||||||
void CRT_done();
|
extern void CRT_done();
|
||||||
|
|
||||||
void CRT_fatalError(const char* note);
|
extern void CRT_fatalError(const char* note);
|
||||||
|
|
||||||
int CRT_readKey();
|
extern int CRT_readKey();
|
||||||
|
|
||||||
void CRT_disableDelay();
|
extern void CRT_disableDelay();
|
||||||
|
|
||||||
void CRT_enableDelay();
|
extern void CRT_enableDelay();
|
||||||
|
|
||||||
void CRT_setColors(int colorScheme);
|
extern void CRT_setColors(int colorScheme);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -34,7 +34,7 @@ typedef struct CategoriesPanel_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||||
|
|
||||||
static void CategoriesPanel_delete(Object* object) {
|
static void CategoriesPanel_delete(Object* object) {
|
||||||
Panel* super = (Panel*) object;
|
Panel* super = (Panel*) object;
|
||||||
@ -82,9 +82,9 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
|||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
case KEY_CTRLP:
|
case KEY_CTRL('P'):
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
case KEY_CTRLN:
|
case KEY_CTRL('N'):
|
||||||
case KEY_NPAGE:
|
case KEY_NPAGE:
|
||||||
case KEY_PPAGE:
|
case KEY_PPAGE:
|
||||||
case KEY_HOME:
|
case KEY_HOME:
|
||||||
|
@ -24,10 +24,10 @@ typedef struct CategoriesPanel_ {
|
|||||||
} CategoriesPanel;
|
} CategoriesPanel;
|
||||||
|
|
||||||
|
|
||||||
void CategoriesPanel_makeMetersPage(CategoriesPanel* this);
|
extern void CategoriesPanel_makeMetersPage(CategoriesPanel* this);
|
||||||
|
|
||||||
extern PanelClass CategoriesPanel_class;
|
extern PanelClass CategoriesPanel_class;
|
||||||
|
|
||||||
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl);
|
extern CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
99
ChangeLog
99
ChangeLog
@ -1,3 +1,102 @@
|
|||||||
|
What's new in version 2.2.0
|
||||||
|
|
||||||
|
* Solaris/Illumos/OpenIndiana support
|
||||||
|
(thanks to Guy M. Broome)
|
||||||
|
* -t/--tree flag for starting in tree-view mode
|
||||||
|
(thanks to Daniel Flanagan)
|
||||||
|
* macOS: detects High Sierra version to avoid OS bug
|
||||||
|
(thanks to Pierre Malhaire)
|
||||||
|
* OpenBSD: read battery data
|
||||||
|
(thanks to @nerd972)
|
||||||
|
* Various automake and build improvements
|
||||||
|
(thanks to Kang-Che Sung)
|
||||||
|
* Check for pkg-config when building with --enable-delayacct
|
||||||
|
(thanks to @florian2833z for the report)
|
||||||
|
* Avoid some bashisms in configure script
|
||||||
|
(thanks to Jesin)
|
||||||
|
* Use CFLAGS from ncurses*-config if present
|
||||||
|
(thanks to Michael Klein)
|
||||||
|
* Header generator supports non-UTF-8 environments
|
||||||
|
(thanks to @volkov-am)
|
||||||
|
* Linux: changed detection of kernel threads
|
||||||
|
* Collapse current subtree pressing Backspace
|
||||||
|
* BUGFIX: fix behavior of SYSCR column
|
||||||
|
(thanks to Marc Kleine-Budde)
|
||||||
|
* BUGFIX: obtain exit code of lsof correctly
|
||||||
|
(thanks to @wangqr)
|
||||||
|
* BUGFIX: fix crash with particular keycodes
|
||||||
|
(thanks to Wellington Torrejais da Silva for the report)
|
||||||
|
* BUGFIX: fix issue with small terminals
|
||||||
|
(thanks to Daniel Elf for the report)
|
||||||
|
* BUGFIX: fix terminal color issues
|
||||||
|
(thanks to Kang-Che Sung for the report)
|
||||||
|
* BUGFIX: preserve LDFLAGS when building
|
||||||
|
(thanks to Lance Frederickson for the report)
|
||||||
|
* BUGFIX: fixed overflow for systems with >= 100 signals
|
||||||
|
|
||||||
|
What's new in version 2.1.0
|
||||||
|
|
||||||
|
* Linux: Delay accounting metrics
|
||||||
|
(thanks to André Carvalho)
|
||||||
|
* DragonFlyBSD support
|
||||||
|
(thanks to Diederik de Groot)
|
||||||
|
* Support for real-time signals
|
||||||
|
(thanks to Kang-Che Sung)
|
||||||
|
* 'c' key now works with threads as well
|
||||||
|
* Session column renamed from SESN to SID
|
||||||
|
(thanks to Kamyar Rasta)
|
||||||
|
* Improved UI for meter style selection
|
||||||
|
(thanks to Kang-Che Sung)
|
||||||
|
* Improved code for constructing process tree
|
||||||
|
(thanks to wangqr)
|
||||||
|
* Compile-time option to disable setuid
|
||||||
|
* Error checking of various standard library operations
|
||||||
|
* Replacement of sprintf with snprintf
|
||||||
|
(thanks to Tomasz Kramkowski)
|
||||||
|
* Linux: performance improvements in battery meter
|
||||||
|
* Linux: update process TTY device
|
||||||
|
* Linux: add support for sorting TASK_IDLE
|
||||||
|
(thanks to Vladimir Panteleev)
|
||||||
|
* Linux: add upper-bound to running process counter
|
||||||
|
(thanks to Lucas Correia Villa Real)
|
||||||
|
* BUGFIX: avoid crash when battery is removed
|
||||||
|
(thanks to Jan Chren)
|
||||||
|
* BUGFIX: macOS: fix infinite loop in tree view
|
||||||
|
(thanks to Wataru Ashihara)
|
||||||
|
|
||||||
|
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
|
||||||
|
(thanks to Michael McConville and Juan Francisco Cantero Hurtado)
|
||||||
|
* FreeBSD: fix CPU and memory readings
|
||||||
|
(thanks to Tim Creech, Hung-Yi Chen, Bernard Spil, Greg V)
|
||||||
|
* FreeBSD: add battery support
|
||||||
|
(thanks to Greg V)
|
||||||
|
* Linux: Retain last-obtained name of a zombie process
|
||||||
|
* Mac OS X: Improve portability for OS X versions
|
||||||
|
(thanks to Michael Klein)
|
||||||
|
* Mac OS X: Fix reading command-line arguments and basename
|
||||||
|
* Mac OS X: Fix process state information
|
||||||
|
* Mac OS X: Fix tree view collapsing/expanding
|
||||||
|
* Mac OS X: Fix tree organization
|
||||||
|
* Mac OS X: Fix memory accounting
|
||||||
|
* Fix crash when emptying a column of meters
|
||||||
|
* Make Esc key more responsive
|
||||||
|
|
||||||
What's new in version 2.0.0
|
What's new in version 2.0.0
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -21,12 +21,12 @@ typedef struct CheckItem_ {
|
|||||||
|
|
||||||
extern ObjectClass CheckItem_class;
|
extern ObjectClass CheckItem_class;
|
||||||
|
|
||||||
CheckItem* CheckItem_newByRef(char* text, bool* ref);
|
extern CheckItem* CheckItem_newByRef(char* text, bool* ref);
|
||||||
|
|
||||||
CheckItem* CheckItem_newByVal(char* text, bool value);
|
extern CheckItem* CheckItem_newByVal(char* text, bool value);
|
||||||
|
|
||||||
void CheckItem_set(CheckItem* this, bool value);
|
extern void CheckItem_set(CheckItem* this, bool value);
|
||||||
|
|
||||||
bool CheckItem_get(CheckItem* this);
|
extern bool CheckItem_get(CheckItem* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,7 +19,7 @@ int ClockMeter_attributes[] = {
|
|||||||
CLOCK
|
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);
|
time_t t = time(NULL);
|
||||||
struct tm result;
|
struct tm result;
|
||||||
struct tm *lt = localtime_r(&t, &result);
|
struct tm *lt = localtime_r(&t, &result);
|
||||||
@ -32,8 +32,9 @@ MeterClass ClockMeter_class = {
|
|||||||
.extends = Class(Meter),
|
.extends = Class(Meter),
|
||||||
.delete = Meter_delete
|
.delete = Meter_delete
|
||||||
},
|
},
|
||||||
.setValues = ClockMeter_setValues,
|
.updateValues = ClockMeter_updateValues,
|
||||||
.defaultMode = TEXT_METERMODE,
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 1,
|
||||||
.total = 1440, /* 24*60 */
|
.total = 1440, /* 24*60 */
|
||||||
.attributes = ClockMeter_attributes,
|
.attributes = ClockMeter_attributes,
|
||||||
.name = "Clock",
|
.name = "Clock",
|
||||||
|
@ -34,9 +34,9 @@ typedef struct ColorsPanel_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
static const char* const ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||||
|
|
||||||
static const char* ColorSchemeNames[] = {
|
static const char* const ColorSchemeNames[] = {
|
||||||
"Default",
|
"Default",
|
||||||
"Monochromatic",
|
"Monochromatic",
|
||||||
"Black on White",
|
"Black on White",
|
||||||
@ -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);
|
||||||
|
|
||||||
@ -78,6 +78,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
|
|||||||
this->settings->changed = true;
|
this->settings->changed = true;
|
||||||
const Header* header = this->scr->header;
|
const Header* header = this->scr->header;
|
||||||
CRT_setColors(mark);
|
CRT_setColors(mark);
|
||||||
|
clear();
|
||||||
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
|
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
|
||||||
Header_draw(header);
|
Header_draw(header);
|
||||||
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
|
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
|
||||||
|
@ -29,6 +29,6 @@ typedef struct ColorsPanel_ {
|
|||||||
|
|
||||||
extern PanelClass ColorsPanel_class;
|
extern PanelClass ColorsPanel_class;
|
||||||
|
|
||||||
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr);
|
extern ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,7 +29,7 @@ typedef struct ColumnsPanel_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
|
static const char* const ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
|
||||||
|
|
||||||
static void ColumnsPanel_delete(Object* object) {
|
static void ColumnsPanel_delete(Object* object) {
|
||||||
Panel* super = (Panel*) object;
|
Panel* super = (Panel*) object;
|
||||||
@ -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);
|
||||||
@ -65,8 +65,8 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
|||||||
if (!this->moving) {
|
if (!this->moving) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* else fallthrough */
|
|
||||||
}
|
}
|
||||||
|
/* else fallthrough */
|
||||||
case KEY_F(7):
|
case KEY_F(7):
|
||||||
case '[':
|
case '[':
|
||||||
case '-':
|
case '-':
|
||||||
@ -81,13 +81,13 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
|||||||
if (!this->moving) {
|
if (!this->moving) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* else fallthrough */
|
|
||||||
}
|
}
|
||||||
|
/* else fallthrough */
|
||||||
case KEY_F(8):
|
case KEY_F(8):
|
||||||
case ']':
|
case ']':
|
||||||
case '+':
|
case '+':
|
||||||
{
|
{
|
||||||
if (selected < size - 2)
|
if (selected < size - 2)
|
||||||
Panel_moveSelectedDown(super);
|
Panel_moveSelectedDown(super);
|
||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
break;
|
break;
|
||||||
|
@ -22,11 +22,11 @@ typedef struct ColumnsPanel_ {
|
|||||||
|
|
||||||
extern PanelClass ColumnsPanel_class;
|
extern PanelClass ColumnsPanel_class;
|
||||||
|
|
||||||
ColumnsPanel* ColumnsPanel_new(Settings* settings);
|
extern ColumnsPanel* ColumnsPanel_new(Settings* settings);
|
||||||
|
|
||||||
int ColumnsPanel_fieldNameToIndex(const char* name);
|
extern int ColumnsPanel_fieldNameToIndex(const char* name);
|
||||||
|
|
||||||
void ColumnsPanel_update(Panel* super);
|
extern void ColumnsPanel_update(Panel* super);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,7 +28,7 @@ typedef struct DisplayOptionsPanel_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||||
|
|
||||||
static void DisplayOptionsPanel_delete(Object* object) {
|
static void DisplayOptionsPanel_delete(Object* object) {
|
||||||
Panel* super = (Panel*) object;
|
Panel* super = (Panel*) object;
|
||||||
@ -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);
|
||||||
|
|
||||||
@ -97,5 +97,8 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
|||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero)));
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames)));
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter)));
|
||||||
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU percentage numerically"), &(settings->showCPUUsage)));
|
||||||
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU frequency"), &(settings->showCPUFrequency)));
|
||||||
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Enable the mouse"), &(settings->enableMouse)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,6 @@ typedef struct DisplayOptionsPanel_ {
|
|||||||
|
|
||||||
extern PanelClass DisplayOptionsPanel_class;
|
extern PanelClass DisplayOptionsPanel_class;
|
||||||
|
|
||||||
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr);
|
extern DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,10 +48,9 @@ void EnvScreen_scan(InfoScreen* this) {
|
|||||||
|
|
||||||
Panel_prune(panel);
|
Panel_prune(panel);
|
||||||
|
|
||||||
uid_t euid = geteuid();
|
CRT_dropPrivileges();
|
||||||
seteuid(getuid());
|
char* env = Platform_getProcessEnv(this->process->pid);
|
||||||
char *env = Platform_getProcessEnv(this->process->pid);
|
CRT_restorePrivileges();
|
||||||
seteuid(euid);
|
|
||||||
if (env) {
|
if (env) {
|
||||||
for (char *p = env; *p; p = strrchr(p, 0)+1)
|
for (char *p = env; *p; p = strrchr(p, 0)+1)
|
||||||
InfoScreen_addLine(this, p);
|
InfoScreen_addLine(this, p);
|
||||||
|
@ -11,12 +11,12 @@ typedef struct EnvScreen_ {
|
|||||||
|
|
||||||
extern InfoScreenClass EnvScreen_class;
|
extern InfoScreenClass EnvScreen_class;
|
||||||
|
|
||||||
EnvScreen* EnvScreen_new(Process* process);
|
extern EnvScreen* EnvScreen_new(Process* process);
|
||||||
|
|
||||||
void EnvScreen_delete(Object* this);
|
extern void EnvScreen_delete(Object* this);
|
||||||
|
|
||||||
void EnvScreen_draw(InfoScreen* this);
|
extern void EnvScreen_draw(InfoScreen* this);
|
||||||
|
|
||||||
void EnvScreen_scan(InfoScreen* this);
|
extern void EnvScreen_scan(InfoScreen* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,21 +28,21 @@ typedef struct FunctionBar_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL};
|
static const char* const FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL};
|
||||||
|
|
||||||
static const char* FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL};
|
static const char* const FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL};
|
||||||
|
|
||||||
static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10)};
|
static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10)};
|
||||||
|
|
||||||
static const char* FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
|
static const char* const FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
|
||||||
static int FunctionBar_EnterEscEvents[] = {13, 27};
|
static const int FunctionBar_EnterEscEvents[] = {13, 27};
|
||||||
|
|
||||||
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) {
|
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) {
|
||||||
const char* functions[] = {enter, esc, NULL};
|
const char* functions[] = {enter, esc, NULL};
|
||||||
return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents);
|
return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events) {
|
FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events) {
|
||||||
FunctionBar* this = xCalloc(1, sizeof(FunctionBar));
|
FunctionBar* this = xCalloc(1, sizeof(FunctionBar));
|
||||||
this->functions = xCalloc(16, sizeof(char*));
|
this->functions = xCalloc(16, sizeof(char*));
|
||||||
if (!functions) {
|
if (!functions) {
|
||||||
@ -52,7 +52,7 @@ FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* eve
|
|||||||
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;
|
||||||
|
@ -22,18 +22,18 @@ typedef struct FunctionBar_ {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc);
|
extern FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc);
|
||||||
|
|
||||||
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events);
|
extern FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events);
|
||||||
|
|
||||||
void FunctionBar_delete(FunctionBar* this);
|
extern void FunctionBar_delete(FunctionBar* this);
|
||||||
|
|
||||||
void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
|
extern void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
|
||||||
|
|
||||||
void FunctionBar_draw(const FunctionBar* this, char* buffer);
|
extern void FunctionBar_draw(const FunctionBar* this, char* buffer);
|
||||||
|
|
||||||
void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
|
extern void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
|
||||||
|
|
||||||
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);
|
extern int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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;
|
||||||
|
12
Hashtable.h
12
Hashtable.h
@ -30,20 +30,20 @@ struct Hashtable_ {
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
int Hashtable_count(Hashtable* this);
|
extern int Hashtable_count(Hashtable* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Hashtable* Hashtable_new(int size, bool owner);
|
extern Hashtable* Hashtable_new(int size, bool owner);
|
||||||
|
|
||||||
void Hashtable_delete(Hashtable* this);
|
extern void Hashtable_delete(Hashtable* this);
|
||||||
|
|
||||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value);
|
extern void Hashtable_put(Hashtable* this, unsigned int key, void* value);
|
||||||
|
|
||||||
void* Hashtable_remove(Hashtable* this, unsigned int key);
|
extern void* Hashtable_remove(Hashtable* this, unsigned int key);
|
||||||
|
|
||||||
extern void* Hashtable_get(Hashtable* this, unsigned int key);
|
extern void* Hashtable_get(Hashtable* this, unsigned int key);
|
||||||
|
|
||||||
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);
|
extern void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
20
Header.c
20
Header.c
@ -37,7 +37,7 @@ typedef struct Header_ {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef Header_forEachColumn
|
#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
|
#endif
|
||||||
|
|
||||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) {
|
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) {
|
||||||
@ -76,24 +76,24 @@ 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));
|
||||||
if (meter->param) {
|
if (meter->param) {
|
||||||
snprintf(name, 63, "%s(%d)", As_Meter(meter)->name, meter->param);
|
xSnprintf(name, 63, "%s(%d)", As_Meter(meter)->name, meter->param);
|
||||||
} else {
|
} else {
|
||||||
snprintf(name, 63, "%s", As_Meter(meter)->name);
|
xSnprintf(name, 63, "%s", As_Meter(meter)->name);
|
||||||
}
|
}
|
||||||
colSettings->names[i] = name;
|
colSettings->names[i] = name;
|
||||||
colSettings->modes[i] = meter->mode;
|
colSettings->modes[i] = meter->mode;
|
||||||
@ -120,6 +120,8 @@ MeterModeId Header_addMeterByName(Header* this, char* name, int column) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (paren)
|
||||||
|
*paren = '(';
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +157,7 @@ char* Header_readMeterName(Header* this, int i, int column) {
|
|||||||
strncpy(name, Meter_name(meter), nameLen);
|
strncpy(name, Meter_name(meter), nameLen);
|
||||||
name[nameLen] = '\0';
|
name[nameLen] = '\0';
|
||||||
if (meter->param)
|
if (meter->param)
|
||||||
snprintf(name + nameLen, len - nameLen, "(%d)", meter->param);
|
xSnprintf(name + nameLen, len - nameLen, "(%d)", meter->param);
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -186,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++) {
|
||||||
|
28
Header.h
28
Header.h
@ -28,33 +28,33 @@ typedef struct Header_ {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef Header_forEachColumn
|
#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
|
#endif
|
||||||
|
|
||||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns);
|
extern Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns);
|
||||||
|
|
||||||
void Header_delete(Header* this);
|
extern void Header_delete(Header* this);
|
||||||
|
|
||||||
void Header_populateFromSettings(Header* this);
|
extern void Header_populateFromSettings(Header* this);
|
||||||
|
|
||||||
void Header_writeBackToSettings(const Header* this);
|
extern void Header_writeBackToSettings(const Header* this);
|
||||||
|
|
||||||
MeterModeId Header_addMeterByName(Header* this, char* name, int column);
|
extern MeterModeId Header_addMeterByName(Header* this, char* name, int column);
|
||||||
|
|
||||||
void Header_setMode(Header* this, int i, MeterModeId mode, int column);
|
extern void Header_setMode(Header* this, int i, MeterModeId mode, int column);
|
||||||
|
|
||||||
Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column);
|
extern Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column);
|
||||||
|
|
||||||
int Header_size(Header* this, int column);
|
extern int Header_size(Header* this, int column);
|
||||||
|
|
||||||
char* Header_readMeterName(Header* this, int i, int column);
|
extern char* Header_readMeterName(Header* this, int i, int column);
|
||||||
|
|
||||||
MeterModeId Header_readMeterMode(Header* this, int i, int column);
|
extern MeterModeId Header_readMeterMode(Header* this, int i, int column);
|
||||||
|
|
||||||
void Header_reinit(Header* this);
|
extern void Header_reinit(Header* this);
|
||||||
|
|
||||||
void Header_draw(const Header* this);
|
extern void Header_draw(const Header* this);
|
||||||
|
|
||||||
int Header_calculateHeight(Header* this);
|
extern int Header_calculateHeight(Header* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,7 +19,7 @@ int HostnameMeter_attributes[] = {
|
|||||||
HOSTNAME
|
HOSTNAME
|
||||||
};
|
};
|
||||||
|
|
||||||
static void HostnameMeter_setValues(Meter* this, char* buffer, int size) {
|
static void HostnameMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
(void) this;
|
(void) this;
|
||||||
gethostname(buffer, size-1);
|
gethostname(buffer, size-1);
|
||||||
}
|
}
|
||||||
@ -29,8 +29,9 @@ MeterClass HostnameMeter_class = {
|
|||||||
.extends = Class(Meter),
|
.extends = Class(Meter),
|
||||||
.delete = Meter_delete
|
.delete = Meter_delete
|
||||||
},
|
},
|
||||||
.setValues = HostnameMeter_setValues,
|
.updateValues = HostnameMeter_updateValues,
|
||||||
.defaultMode = TEXT_METERMODE,
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 0,
|
||||||
.total = 100.0,
|
.total = 100.0,
|
||||||
.attributes = HostnameMeter_attributes,
|
.attributes = HostnameMeter_attributes,
|
||||||
.name = "Hostname",
|
.name = "Hostname",
|
||||||
|
229
INSTALL
229
INSTALL
@ -1,229 +0,0 @@
|
|||||||
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
|
|
||||||
Foundation, Inc.
|
|
||||||
|
|
||||||
This file is free documentation; the Free Software Foundation gives
|
|
||||||
unlimited permission to copy, distribute and modify it.
|
|
||||||
|
|
||||||
Basic Installation
|
|
||||||
==================
|
|
||||||
|
|
||||||
These are generic installation instructions.
|
|
||||||
|
|
||||||
The `configure' shell script attempts to guess correct values for
|
|
||||||
various system-dependent variables used during compilation. It uses
|
|
||||||
those values to create a `Makefile' in each directory of the package.
|
|
||||||
It may also create one or more `.h' files containing system-dependent
|
|
||||||
definitions. Finally, it creates a shell script `config.status' that
|
|
||||||
you can run in the future to recreate the current configuration, and a
|
|
||||||
file `config.log' containing compiler output (useful mainly for
|
|
||||||
debugging `configure').
|
|
||||||
|
|
||||||
It can also use an optional file (typically called `config.cache'
|
|
||||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
|
||||||
the results of its tests to speed up reconfiguring. (Caching is
|
|
||||||
disabled by default to prevent problems with accidental use of stale
|
|
||||||
cache files.)
|
|
||||||
|
|
||||||
If you need to do unusual things to compile the package, please try
|
|
||||||
to figure out how `configure' could check whether to do them, and mail
|
|
||||||
diffs or instructions to the address given in the `README' so they can
|
|
||||||
be considered for the next release. If you are using the cache, and at
|
|
||||||
some point `config.cache' contains results you don't want to keep, you
|
|
||||||
may remove or edit it.
|
|
||||||
|
|
||||||
The file `configure.ac' (or `configure.in') is used to create
|
|
||||||
`configure' by a program called `autoconf'. You only need
|
|
||||||
`configure.ac' if you want to change it or regenerate `configure' using
|
|
||||||
a newer version of `autoconf'.
|
|
||||||
|
|
||||||
The simplest way to compile this package is:
|
|
||||||
|
|
||||||
1. `cd' to the directory containing the package's source code and type
|
|
||||||
`./configure' to configure the package for your system. If you're
|
|
||||||
using `csh' on an old version of System V, you might need to type
|
|
||||||
`sh ./configure' instead to prevent `csh' from trying to execute
|
|
||||||
`configure' itself.
|
|
||||||
|
|
||||||
Running `configure' takes awhile. While running, it prints some
|
|
||||||
messages telling which features it is checking for.
|
|
||||||
|
|
||||||
2. Type `make' to compile the package.
|
|
||||||
|
|
||||||
3. Optionally, type `make check' to run any self-tests that come with
|
|
||||||
the package.
|
|
||||||
|
|
||||||
4. Type `make install' to install the programs and any data files and
|
|
||||||
documentation.
|
|
||||||
|
|
||||||
5. You can remove the program binaries and object files from the
|
|
||||||
source code directory by typing `make clean'. To also remove the
|
|
||||||
files that `configure' created (so you can compile the package for
|
|
||||||
a different kind of computer), type `make distclean'. There is
|
|
||||||
also a `make maintainer-clean' target, but that is intended mainly
|
|
||||||
for the package's developers. If you use it, you may have to get
|
|
||||||
all sorts of other programs in order to regenerate files that came
|
|
||||||
with the distribution.
|
|
||||||
|
|
||||||
Compilers and Options
|
|
||||||
=====================
|
|
||||||
|
|
||||||
Some systems require unusual options for compilation or linking that
|
|
||||||
the `configure' script does not know about. Run `./configure --help'
|
|
||||||
for details on some of the pertinent environment variables.
|
|
||||||
|
|
||||||
You can give `configure' initial values for configuration parameters
|
|
||||||
by setting variables in the command line or in the environment. Here
|
|
||||||
is an example:
|
|
||||||
|
|
||||||
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
|
|
||||||
|
|
||||||
*Note Defining Variables::, for more details.
|
|
||||||
|
|
||||||
Compiling For Multiple Architectures
|
|
||||||
====================================
|
|
||||||
|
|
||||||
You can compile the package for more than one kind of computer at the
|
|
||||||
same time, by placing the object files for each architecture in their
|
|
||||||
own directory. To do this, you must use a version of `make' that
|
|
||||||
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
|
||||||
directory where you want the object files and executables to go and run
|
|
||||||
the `configure' script. `configure' automatically checks for the
|
|
||||||
source code in the directory that `configure' is in and in `..'.
|
|
||||||
|
|
||||||
If you have to use a `make' that does not support the `VPATH'
|
|
||||||
variable, you have to compile the package for one architecture at a
|
|
||||||
time in the source code directory. After you have installed the
|
|
||||||
package for one architecture, use `make distclean' before reconfiguring
|
|
||||||
for another architecture.
|
|
||||||
|
|
||||||
Installation Names
|
|
||||||
==================
|
|
||||||
|
|
||||||
By default, `make install' will install the package's files in
|
|
||||||
`/usr/local/bin', `/usr/local/man', etc. You can specify an
|
|
||||||
installation prefix other than `/usr/local' by giving `configure' the
|
|
||||||
option `--prefix=PATH'.
|
|
||||||
|
|
||||||
You can specify separate installation prefixes for
|
|
||||||
architecture-specific files and architecture-independent files. If you
|
|
||||||
give `configure' the option `--exec-prefix=PATH', the package will use
|
|
||||||
PATH as the prefix for installing programs and libraries.
|
|
||||||
Documentation and other data files will still use the regular prefix.
|
|
||||||
|
|
||||||
In addition, if you use an unusual directory layout you can give
|
|
||||||
options like `--bindir=PATH' to specify different values for particular
|
|
||||||
kinds of files. Run `configure --help' for a list of the directories
|
|
||||||
you can set and what kinds of files go in them.
|
|
||||||
|
|
||||||
If the package supports it, you can cause programs to be installed
|
|
||||||
with an extra prefix or suffix on their names by giving `configure' the
|
|
||||||
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
|
||||||
|
|
||||||
Optional Features
|
|
||||||
=================
|
|
||||||
|
|
||||||
Some packages pay attention to `--enable-FEATURE' options to
|
|
||||||
`configure', where FEATURE indicates an optional part of the package.
|
|
||||||
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
|
||||||
is something like `gnu-as' or `x' (for the X Window System). The
|
|
||||||
`README' should mention any `--enable-' and `--with-' options that the
|
|
||||||
package recognizes.
|
|
||||||
|
|
||||||
For packages that use the X Window System, `configure' can usually
|
|
||||||
find the X include and library files automatically, but if it doesn't,
|
|
||||||
you can use the `configure' options `--x-includes=DIR' and
|
|
||||||
`--x-libraries=DIR' to specify their locations.
|
|
||||||
|
|
||||||
Specifying the System Type
|
|
||||||
==========================
|
|
||||||
|
|
||||||
There may be some features `configure' cannot figure out
|
|
||||||
automatically, but needs to determine by the type of machine the package
|
|
||||||
will run on. Usually, assuming the package is built to be run on the
|
|
||||||
_same_ architectures, `configure' can figure that out, but if it prints
|
|
||||||
a message saying it cannot guess the machine type, give it the
|
|
||||||
`--build=TYPE' option. TYPE can either be a short name for the system
|
|
||||||
type, such as `sun4', or a canonical name which has the form:
|
|
||||||
|
|
||||||
CPU-COMPANY-SYSTEM
|
|
||||||
|
|
||||||
where SYSTEM can have one of these forms:
|
|
||||||
|
|
||||||
OS KERNEL-OS
|
|
||||||
|
|
||||||
See the file `config.sub' for the possible values of each field. If
|
|
||||||
`config.sub' isn't included in this package, then this package doesn't
|
|
||||||
need to know the machine type.
|
|
||||||
|
|
||||||
If you are _building_ compiler tools for cross-compiling, you should
|
|
||||||
use the `--target=TYPE' option to select the type of system they will
|
|
||||||
produce code for.
|
|
||||||
|
|
||||||
If you want to _use_ a cross compiler, that generates code for a
|
|
||||||
platform different from the build platform, you should specify the
|
|
||||||
"host" platform (i.e., that on which the generated programs will
|
|
||||||
eventually be run) with `--host=TYPE'.
|
|
||||||
|
|
||||||
Sharing Defaults
|
|
||||||
================
|
|
||||||
|
|
||||||
If you want to set default values for `configure' scripts to share,
|
|
||||||
you can create a site shell script called `config.site' that gives
|
|
||||||
default values for variables like `CC', `cache_file', and `prefix'.
|
|
||||||
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
|
||||||
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
|
||||||
`CONFIG_SITE' environment variable to the location of the site script.
|
|
||||||
A warning: not all `configure' scripts look for a site script.
|
|
||||||
|
|
||||||
Defining Variables
|
|
||||||
==================
|
|
||||||
|
|
||||||
Variables not defined in a site shell script can be set in the
|
|
||||||
environment passed to `configure'. However, some packages may run
|
|
||||||
configure again during the build, and the customized values of these
|
|
||||||
variables may be lost. In order to avoid this problem, you should set
|
|
||||||
them in the `configure' command line, using `VAR=value'. For example:
|
|
||||||
|
|
||||||
./configure CC=/usr/local2/bin/gcc
|
|
||||||
|
|
||||||
will cause the specified gcc to be used as the C compiler (unless it is
|
|
||||||
overridden in the site shell script).
|
|
||||||
|
|
||||||
`configure' Invocation
|
|
||||||
======================
|
|
||||||
|
|
||||||
`configure' recognizes the following options to control how it
|
|
||||||
operates.
|
|
||||||
|
|
||||||
`--help'
|
|
||||||
`-h'
|
|
||||||
Print a summary of the options to `configure', and exit.
|
|
||||||
|
|
||||||
`--version'
|
|
||||||
`-V'
|
|
||||||
Print the version of Autoconf used to generate the `configure'
|
|
||||||
script, and exit.
|
|
||||||
|
|
||||||
`--cache-file=FILE'
|
|
||||||
Enable the cache: use and save the results of the tests in FILE,
|
|
||||||
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
|
||||||
disable caching.
|
|
||||||
|
|
||||||
`--config-cache'
|
|
||||||
`-C'
|
|
||||||
Alias for `--cache-file=config.cache'.
|
|
||||||
|
|
||||||
`--quiet'
|
|
||||||
`--silent'
|
|
||||||
`-q'
|
|
||||||
Do not print messages saying which checks are being made. To
|
|
||||||
suppress all normal output, redirect it to `/dev/null' (any error
|
|
||||||
messages will still be shown).
|
|
||||||
|
|
||||||
`--srcdir=DIR'
|
|
||||||
Look for the package's source code in directory DIR. Usually
|
|
||||||
`configure' can determine that directory automatically.
|
|
||||||
|
|
||||||
`configure' also accepts some other, not widely useful, options. Run
|
|
||||||
`configure --help' for more details.
|
|
||||||
|
|
96
IncSet.c
96
IncSet.c
@ -40,6 +40,7 @@ typedef struct IncSet_ {
|
|||||||
IncMode* active;
|
IncMode* active;
|
||||||
FunctionBar* defaultBar;
|
FunctionBar* defaultBar;
|
||||||
bool filtering;
|
bool filtering;
|
||||||
|
bool found;
|
||||||
} IncSet;
|
} IncSet;
|
||||||
|
|
||||||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||||
@ -51,8 +52,12 @@ static void IncMode_reset(IncMode* mode) {
|
|||||||
mode->buffer[0] = 0;
|
mode->buffer[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL};
|
void IncSet_reset(IncSet* this, IncType type) {
|
||||||
static const char* searchKeys[] = {"F3", "Esc", " "};
|
IncMode_reset(&this->modes[type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* const searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL};
|
||||||
|
static const char* const searchKeys[] = {"F3", "Esc", " "};
|
||||||
static int searchEvents[] = {KEY_F(3), 27, ERR};
|
static int searchEvents[] = {KEY_F(3), 27, ERR};
|
||||||
|
|
||||||
static inline void IncMode_initSearch(IncMode* search) {
|
static inline void IncMode_initSearch(IncMode* search) {
|
||||||
@ -61,8 +66,8 @@ static inline void IncMode_initSearch(IncMode* search) {
|
|||||||
search->isFilter = false;
|
search->isFilter = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* filterFunctions[] = {"Done ", "Clear ", " Filter: ", NULL};
|
static const char* const filterFunctions[] = {"Done ", "Clear ", " Filter: ", NULL};
|
||||||
static const char* filterKeys[] = {"Enter", "Esc", " "};
|
static const char* const filterKeys[] = {"Enter", "Esc", " "};
|
||||||
static int filterEvents[] = {13, 27, ERR};
|
static int filterEvents[] = {13, 27, ERR};
|
||||||
|
|
||||||
static inline void IncMode_initFilter(IncMode* filter) {
|
static inline void IncMode_initFilter(IncMode* filter) {
|
||||||
@ -114,7 +119,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);
|
int size = Panel_size(panel);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
@ -128,6 +133,31 @@ static void search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa
|
|||||||
FunctionBar_draw(mode->bar, mode->buffer);
|
FunctionBar_draw(mode->bar, mode->buffer);
|
||||||
else
|
else
|
||||||
FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]);
|
FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]);
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) {
|
||||||
|
int size = Panel_size(panel);
|
||||||
|
int here = Panel_getSelectedIndex(panel);
|
||||||
|
int i = here;
|
||||||
|
for(;;) {
|
||||||
|
i+=step;
|
||||||
|
if (i == size) i = 0;
|
||||||
|
if (i == -1) i = size - 1;
|
||||||
|
if (i == here) return false;
|
||||||
|
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
||||||
|
Panel_setSelected(panel, i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||||
|
return IncMode_find(&this->modes[type], panel, getPanelValue, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||||
|
return IncMode_find(&this->modes[type], panel, getPanelValue, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) {
|
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) {
|
||||||
@ -139,36 +169,32 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||||||
bool doSearch = true;
|
bool doSearch = true;
|
||||||
if (ch == KEY_F(3)) {
|
if (ch == KEY_F(3)) {
|
||||||
if (size == 0) return true;
|
if (size == 0) return true;
|
||||||
int here = Panel_getSelectedIndex(panel);
|
IncMode_find(mode, panel, getPanelValue, 1);
|
||||||
int i = here;
|
|
||||||
for(;;) {
|
|
||||||
i++;
|
|
||||||
if (i == size) i = 0;
|
|
||||||
if (i == here) break;
|
|
||||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
|
||||||
Panel_setSelected(panel, i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
doSearch = false;
|
doSearch = false;
|
||||||
} else if (ch < 255 && isprint((char)ch) && (mode->index < INCMODE_MAX)) {
|
} else if (ch < 255 && isprint((char)ch)) {
|
||||||
mode->buffer[mode->index] = ch;
|
if (mode->index < INCMODE_MAX) {
|
||||||
mode->index++;
|
mode->buffer[mode->index] = ch;
|
||||||
mode->buffer[mode->index] = 0;
|
mode->index++;
|
||||||
if (mode->isFilter) {
|
mode->buffer[mode->index] = 0;
|
||||||
filterChanged = true;
|
if (mode->isFilter) {
|
||||||
if (mode->index == 1) this->filtering = true;
|
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 == 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) {
|
} else if (ch == KEY_RESIZE) {
|
||||||
Panel_resize(panel, COLS, LINES-panel->y-1);
|
Panel_resize(panel, COLS, LINES-panel->y-1);
|
||||||
} else {
|
} else {
|
||||||
@ -179,7 +205,9 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||||||
IncMode_reset(mode);
|
IncMode_reset(mode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IncMode_reset(mode);
|
if (ch == 27) {
|
||||||
|
IncMode_reset(mode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this->active = NULL;
|
this->active = NULL;
|
||||||
Panel_setDefaultBar(panel);
|
Panel_setDefaultBar(panel);
|
||||||
@ -187,7 +215,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||||||
doSearch = false;
|
doSearch = false;
|
||||||
}
|
}
|
||||||
if (doSearch) {
|
if (doSearch) {
|
||||||
search(mode, panel, getPanelValue);
|
this->found = search(mode, panel, getPanelValue);
|
||||||
}
|
}
|
||||||
if (filterChanged && lines) {
|
if (filterChanged && lines) {
|
||||||
updateWeakPanel(this, panel, lines);
|
updateWeakPanel(this, panel, lines);
|
||||||
|
21
IncSet.h
21
IncSet.h
@ -35,23 +35,30 @@ typedef struct IncSet_ {
|
|||||||
IncMode* active;
|
IncMode* active;
|
||||||
FunctionBar* defaultBar;
|
FunctionBar* defaultBar;
|
||||||
bool filtering;
|
bool filtering;
|
||||||
|
bool found;
|
||||||
} IncSet;
|
} IncSet;
|
||||||
|
|
||||||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||||
|
|
||||||
|
|
||||||
IncSet* IncSet_new(FunctionBar* bar);
|
extern void IncSet_reset(IncSet* this, IncType type);
|
||||||
|
|
||||||
void IncSet_delete(IncSet* this);
|
extern IncSet* IncSet_new(FunctionBar* bar);
|
||||||
|
|
||||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines);
|
extern void IncSet_delete(IncSet* this);
|
||||||
|
|
||||||
const char* IncSet_getListItemValue(Panel* panel, int i);
|
extern bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue);
|
||||||
|
|
||||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
extern bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue);
|
||||||
|
|
||||||
void IncSet_drawBar(IncSet* this);
|
extern bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines);
|
||||||
|
|
||||||
int IncSet_synthesizeEvent(IncSet* this, int x);
|
extern const char* IncSet_getListItemValue(Panel* panel, int i);
|
||||||
|
|
||||||
|
extern void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
||||||
|
|
||||||
|
extern void IncSet_drawBar(IncSet* this);
|
||||||
|
|
||||||
|
extern int IncSet_synthesizeEvent(IncSet* this, int x);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
21
InfoScreen.c
21
InfoScreen.c
@ -50,9 +50,9 @@ struct InfoScreen_ {
|
|||||||
};
|
};
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL};
|
static const char* const InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL};
|
||||||
|
|
||||||
static const char* InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"};
|
static const char* const InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"};
|
||||||
|
|
||||||
static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27};
|
static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27};
|
||||||
|
|
||||||
@ -83,6 +83,7 @@ void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...) {
|
|||||||
wmove(stdscr, 0, 0);
|
wmove(stdscr, 0, 0);
|
||||||
vw_printw(stdscr, fmt, ap);
|
vw_printw(stdscr, fmt, ap);
|
||||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||||
|
this->display->needsRedraw = true;
|
||||||
Panel_draw(this->display, true);
|
Panel_draw(this->display, true);
|
||||||
IncSet_drawBar(this->inc);
|
IncSet_drawBar(this->inc);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -114,10 +115,12 @@ void InfoScreen_run(InfoScreen* this) {
|
|||||||
|
|
||||||
Panel_draw(panel, true);
|
Panel_draw(panel, true);
|
||||||
|
|
||||||
if (this->inc->active)
|
if (this->inc->active) {
|
||||||
move(LINES-1, CRT_cursorX);
|
(void) move(LINES-1, CRT_cursorX);
|
||||||
|
}
|
||||||
|
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);
|
||||||
@ -128,19 +131,21 @@ void InfoScreen_run(InfoScreen* this) {
|
|||||||
if (ch == KEY_MOUSE) {
|
if (ch == KEY_MOUSE) {
|
||||||
MEVENT mevent;
|
MEVENT mevent;
|
||||||
int ok = getmouse(&mevent);
|
int ok = getmouse(&mevent);
|
||||||
if (ok == OK)
|
if (ok == OK) {
|
||||||
if (mevent.y >= panel->y && mevent.y < LINES - 1) {
|
if (mevent.y >= panel->y && mevent.y < LINES - 1) {
|
||||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV);
|
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV);
|
||||||
ch = 0;
|
ch = 0;
|
||||||
} if (mevent.y == LINES - 1)
|
} else if (mevent.y == LINES - 1) {
|
||||||
ch = IncSet_synthesizeEvent(this->inc, mevent.x);
|
ch = IncSet_synthesizeEvent(this->inc, mevent.x);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->inc->active) {
|
if (this->inc->active) {
|
||||||
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;
|
||||||
|
12
InfoScreen.h
12
InfoScreen.h
@ -38,16 +38,16 @@ struct InfoScreen_ {
|
|||||||
Vector* lines;
|
Vector* lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader);
|
extern InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader);
|
||||||
|
|
||||||
InfoScreen* InfoScreen_done(InfoScreen* this);
|
extern InfoScreen* InfoScreen_done(InfoScreen* this);
|
||||||
|
|
||||||
void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...);
|
extern void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...);
|
||||||
|
|
||||||
void InfoScreen_addLine(InfoScreen* this, const char* line);
|
extern void InfoScreen_addLine(InfoScreen* this, const char* line);
|
||||||
|
|
||||||
void InfoScreen_appendLine(InfoScreen* this, const char* line);
|
extern void InfoScreen_appendLine(InfoScreen* this, const char* line);
|
||||||
|
|
||||||
void InfoScreen_run(InfoScreen* this);
|
extern void InfoScreen_run(InfoScreen* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,7 +39,7 @@ static void ListItem_display(Object* cast, RichString* out) {
|
|||||||
/*
|
/*
|
||||||
int len = strlen(this->value)+1;
|
int len = strlen(this->value)+1;
|
||||||
char buffer[len+1];
|
char buffer[len+1];
|
||||||
snprintf(buffer, len, "%s", this->value);
|
xSnprintf(buffer, len, "%s", this->value);
|
||||||
*/
|
*/
|
||||||
if (this->moving) {
|
if (this->moving) {
|
||||||
RichString_write(out, CRT_colors[DEFAULT_COLOR],
|
RichString_write(out, CRT_colors[DEFAULT_COLOR],
|
||||||
|
@ -21,13 +21,13 @@ typedef struct ListItem_ {
|
|||||||
|
|
||||||
extern ObjectClass ListItem_class;
|
extern ObjectClass ListItem_class;
|
||||||
|
|
||||||
ListItem* ListItem_new(const char* value, int key);
|
extern ListItem* ListItem_new(const char* value, int key);
|
||||||
|
|
||||||
void ListItem_append(ListItem* this, const char* text);
|
extern void ListItem_append(ListItem* this, const char* text);
|
||||||
|
|
||||||
const char* ListItem_getRef(ListItem* this);
|
extern const char* ListItem_getRef(ListItem* this);
|
||||||
|
|
||||||
long ListItem_compare(const void* cast1, const void* cast2);
|
extern long ListItem_compare(const void* cast1, const void* cast2);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,35 +20,35 @@ int LoadAverageMeter_attributes[] = {
|
|||||||
|
|
||||||
int LoadMeter_attributes[] = { LOAD };
|
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]);
|
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]);
|
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadAverageMeter_display(Object* cast, RichString* out) {
|
static void LoadAverageMeter_display(Object* cast, RichString* out) {
|
||||||
Meter* this = (Meter*)cast;
|
Meter* this = (Meter*)cast;
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
sprintf(buffer, "%.2f ", this->values[0]);
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
|
||||||
RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
||||||
sprintf(buffer, "%.2f ", this->values[1]);
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[1]);
|
||||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
|
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
|
||||||
sprintf(buffer, "%.2f ", this->values[2]);
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[2]);
|
||||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
|
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;
|
double five, fifteen;
|
||||||
Platform_getLoadAverage(&this->values[0], &five, &fifteen);
|
Platform_getLoadAverage(&this->values[0], &five, &fifteen);
|
||||||
if (this->values[0] > this->total) {
|
if (this->values[0] > this->total) {
|
||||||
this->total = this->values[0];
|
this->total = this->values[0];
|
||||||
}
|
}
|
||||||
snprintf(buffer, size, "%.2f", this->values[0]);
|
xSnprintf(buffer, size, "%.2f", this->values[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadMeter_display(Object* cast, RichString* out) {
|
static void LoadMeter_display(Object* cast, RichString* out) {
|
||||||
Meter* this = (Meter*)cast;
|
Meter* this = (Meter*)cast;
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]);
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", ((Meter*)this)->values[0]);
|
||||||
RichString_write(out, CRT_colors[LOAD], buffer);
|
RichString_write(out, CRT_colors[LOAD], buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ MeterClass LoadAverageMeter_class = {
|
|||||||
.delete = Meter_delete,
|
.delete = Meter_delete,
|
||||||
.display = LoadAverageMeter_display,
|
.display = LoadAverageMeter_display,
|
||||||
},
|
},
|
||||||
.setValues = LoadAverageMeter_setValues,
|
.updateValues = LoadAverageMeter_updateValues,
|
||||||
.defaultMode = TEXT_METERMODE,
|
.defaultMode = TEXT_METERMODE,
|
||||||
.maxItems = 3,
|
.maxItems = 3,
|
||||||
.total = 100.0,
|
.total = 100.0,
|
||||||
@ -75,8 +75,9 @@ MeterClass LoadMeter_class = {
|
|||||||
.delete = Meter_delete,
|
.delete = Meter_delete,
|
||||||
.display = LoadMeter_display,
|
.display = LoadMeter_display,
|
||||||
},
|
},
|
||||||
.setValues = LoadMeter_setValues,
|
.updateValues = LoadMeter_updateValues,
|
||||||
.defaultMode = TEXT_METERMODE,
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 1,
|
||||||
.total = 100.0,
|
.total = 100.0,
|
||||||
.attributes = LoadMeter_attributes,
|
.attributes = LoadMeter_attributes,
|
||||||
.name = "Load",
|
.name = "Load",
|
||||||
|
32
MainPanel.c
32
MainPanel.c
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - ColumnsPanel.c
|
htop - ColumnsPanel.c
|
||||||
(C) 2004-2015 Hisham H. Muhammad
|
(C) 2004-2015 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
@ -25,13 +26,13 @@ typedef struct MainPanel_ {
|
|||||||
pid_t pidSearch;
|
pid_t pidSearch;
|
||||||
} MainPanel;
|
} MainPanel;
|
||||||
|
|
||||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
||||||
|
|
||||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL};
|
static const char* const MainFunctions[] = {"Help ", "Setup ", "Search ", "Filter ", "Tree ", "SortBy ", "Nice - ", "Nice + ", "Kill ", "Quit ", NULL};
|
||||||
|
|
||||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
|
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
|
||||||
FunctionBar* bar = MainPanel_getFunctionBar(this);
|
FunctionBar* bar = MainPanel_getFunctionBar(this);
|
||||||
@ -64,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)) {
|
||||||
@ -79,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);
|
||||||
@ -87,7 +88,10 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
|||||||
this->state->pl->incFilter = IncSet_filter(this->inc);
|
this->state->pl->incFilter = IncSet_filter(this->inc);
|
||||||
reaction = HTOP_REFRESH | HTOP_REDRAW_BAR;
|
reaction = HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||||
}
|
}
|
||||||
reaction |= HTOP_KEEP_FOLLOWING;
|
if (this->inc->found) {
|
||||||
|
reaction |= Action_follow(this->state);
|
||||||
|
reaction |= HTOP_KEEP_FOLLOWING;
|
||||||
|
}
|
||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
} else if (ch == 27) {
|
} else if (ch == 27) {
|
||||||
return HANDLED;
|
return HANDLED;
|
||||||
@ -102,20 +106,6 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
|||||||
} else {
|
} else {
|
||||||
reaction |= HTOP_KEEP_FOLLOWING;
|
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) {
|
if (reaction & HTOP_REDRAW_BAR) {
|
||||||
@ -127,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;
|
||||||
}
|
}
|
||||||
@ -159,7 +149,7 @@ const char* MainPanel_getValue(MainPanel* this, int i) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, int arg, bool* wasAnyTagged) {
|
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged) {
|
||||||
Panel* super = (Panel*) this;
|
Panel* super = (Panel*) this;
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
bool anyTagged = false;
|
bool anyTagged = false;
|
||||||
|
19
MainPanel.h
19
MainPanel.h
@ -5,6 +5,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - ColumnsPanel.h
|
htop - ColumnsPanel.h
|
||||||
(C) 2004-2015 Hisham H. Muhammad
|
(C) 2004-2015 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
@ -21,27 +22,27 @@ typedef struct MainPanel_ {
|
|||||||
pid_t pidSearch;
|
pid_t pidSearch;
|
||||||
} MainPanel;
|
} MainPanel;
|
||||||
|
|
||||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
||||||
|
|
||||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||||
|
|
||||||
|
|
||||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode);
|
extern void MainPanel_updateTreeFunctions(MainPanel* this, bool mode);
|
||||||
|
|
||||||
void MainPanel_pidSearch(MainPanel* this, int ch);
|
extern void MainPanel_pidSearch(MainPanel* this, int ch);
|
||||||
|
|
||||||
int MainPanel_selectedPid(MainPanel* this);
|
extern int MainPanel_selectedPid(MainPanel* this);
|
||||||
|
|
||||||
const char* MainPanel_getValue(MainPanel* this, int i);
|
extern const char* MainPanel_getValue(MainPanel* this, int i);
|
||||||
|
|
||||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, int arg, bool* wasAnyTagged);
|
extern bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged);
|
||||||
|
|
||||||
extern PanelClass MainPanel_class;
|
extern PanelClass MainPanel_class;
|
||||||
|
|
||||||
MainPanel* MainPanel_new();
|
extern MainPanel* MainPanel_new();
|
||||||
|
|
||||||
void MainPanel_setState(MainPanel* this, State* state);
|
extern void MainPanel_setState(MainPanel* this, State* state);
|
||||||
|
|
||||||
void MainPanel_delete(Object* object);
|
extern void MainPanel_delete(Object* object);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
176
Makefile.am
176
Makefile.am
@ -12,8 +12,8 @@ applications_DATA = htop.desktop
|
|||||||
pixmapdir = $(datadir)/pixmaps
|
pixmapdir = $(datadir)/pixmaps
|
||||||
pixmap_DATA = htop.png
|
pixmap_DATA = htop.png
|
||||||
|
|
||||||
htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
|
AM_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
|
||||||
htop_LDFLAGS =
|
AM_LDFLAGS =
|
||||||
AM_CPPFLAGS = -DNDEBUG
|
AM_CPPFLAGS = -DNDEBUG
|
||||||
|
|
||||||
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
||||||
@ -36,55 +36,182 @@ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \
|
|||||||
AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \
|
AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \
|
||||||
EnvScreen.h InfoScreen.h XAlloc.h
|
EnvScreen.h InfoScreen.h XAlloc.h
|
||||||
|
|
||||||
if HTOP_LINUX
|
all_platform_headers =
|
||||||
htop_CFLAGS += -rdynamic
|
|
||||||
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
|
||||||
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c
|
|
||||||
|
|
||||||
myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \
|
# Linux
|
||||||
linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h linux/Battery.h
|
# -----
|
||||||
|
|
||||||
|
linux_platform_headers = \
|
||||||
|
linux/Platform.h \
|
||||||
|
linux/IOPriorityPanel.h \
|
||||||
|
linux/IOPriority.h \
|
||||||
|
linux/LinuxProcess.h \
|
||||||
|
linux/LinuxProcessList.h \
|
||||||
|
linux/LinuxCRT.h \
|
||||||
|
linux/Battery.h \
|
||||||
|
linux/PressureStallMeter.h \
|
||||||
|
zfs/ZfsArcMeter.h \
|
||||||
|
zfs/ZfsCompressedArcMeter.h \
|
||||||
|
zfs/ZfsArcStats.h
|
||||||
|
|
||||||
|
all_platform_headers += $(linux_platform_headers)
|
||||||
|
|
||||||
|
if HTOP_LINUX
|
||||||
|
AM_LDFLAGS += -rdynamic
|
||||||
|
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
||||||
|
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \
|
||||||
|
linux/PressureStallMeter.c \
|
||||||
|
zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c
|
||||||
|
|
||||||
|
myhtopplatheaders = $(linux_platform_headers)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# FreeBSD
|
||||||
|
# -------
|
||||||
|
|
||||||
|
freebsd_platform_headers = \
|
||||||
|
freebsd/Platform.h \
|
||||||
|
freebsd/FreeBSDProcessList.h \
|
||||||
|
freebsd/FreeBSDProcess.h \
|
||||||
|
freebsd/FreeBSDCRT.h \
|
||||||
|
freebsd/Battery.h \
|
||||||
|
zfs/ZfsArcMeter.h \
|
||||||
|
zfs/ZfsCompressedArcMeter.h \
|
||||||
|
zfs/ZfsArcStats.h \
|
||||||
|
zfs/openzfs_sysctl.h
|
||||||
|
|
||||||
|
all_platform_headers += $(freebsd_platform_headers)
|
||||||
|
|
||||||
if HTOP_FREEBSD
|
if HTOP_FREEBSD
|
||||||
myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \
|
myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \
|
||||||
freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c
|
freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c \
|
||||||
|
zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c
|
||||||
|
|
||||||
myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \
|
myhtopplatheaders = $(freebsd_platform_headers)
|
||||||
freebsd/FreeBSDProcess.h freebsd/FreeBSDCRT.h freebsd/Battery.h
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# DragonFlyBSD
|
||||||
|
# ------------
|
||||||
|
|
||||||
|
dragonflybsd_platform_headers = \
|
||||||
|
dragonflybsd/Platform.h \
|
||||||
|
dragonflybsd/DragonFlyBSDProcessList.h \
|
||||||
|
dragonflybsd/DragonFlyBSDProcess.h \
|
||||||
|
dragonflybsd/DragonFlyBSDCRT.h \
|
||||||
|
dragonflybsd/Battery.h
|
||||||
|
|
||||||
|
all_platform_headers += $(dragonflybsd_platform_headers)
|
||||||
|
|
||||||
|
if HTOP_DRAGONFLYBSD
|
||||||
|
AM_LDFLAGS += -lkvm -lkinfo -lexecinfo
|
||||||
|
myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \
|
||||||
|
dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/DragonFlyBSDCRT.c dragonflybsd/Battery.c
|
||||||
|
|
||||||
|
myhtopplatheaders = $(dragonflybsd_platform_headers)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# OpenBSD
|
||||||
|
# -------
|
||||||
|
|
||||||
|
openbsd_platform_headers = \
|
||||||
|
openbsd/Platform.h \
|
||||||
|
openbsd/OpenBSDProcessList.h \
|
||||||
|
openbsd/OpenBSDProcess.h \
|
||||||
|
openbsd/OpenBSDCRT.h \
|
||||||
|
openbsd/Battery.h
|
||||||
|
|
||||||
|
all_platform_headers += $(openbsd_platform_headers)
|
||||||
|
|
||||||
if HTOP_OPENBSD
|
if HTOP_OPENBSD
|
||||||
myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \
|
myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \
|
||||||
openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c
|
openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = openbsd/Platform.h openbsd/OpenBSDProcessList.h \
|
myhtopplatheaders = $(openbsd_platform_headers)
|
||||||
openbsd/OpenBSDProcess.h openbsd/OpenBSDCRT.h openbsd/Battery.h
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Darwin
|
||||||
|
# ------
|
||||||
|
|
||||||
|
darwin_platform_headers = \
|
||||||
|
darwin/Platform.h \
|
||||||
|
darwin/DarwinProcess.h \
|
||||||
|
darwin/DarwinProcessList.h \
|
||||||
|
darwin/DarwinCRT.h \
|
||||||
|
darwin/Battery.h \
|
||||||
|
zfs/ZfsArcMeter.h \
|
||||||
|
zfs/ZfsCompressedArcMeter.h \
|
||||||
|
zfs/ZfsArcStats.h \
|
||||||
|
zfs/openzfs_sysctl.h
|
||||||
|
|
||||||
|
all_platform_headers += $(darwin_platform_headers)
|
||||||
|
|
||||||
if HTOP_DARWIN
|
if HTOP_DARWIN
|
||||||
htop_LDFLAGS += -framework IOKit -framework CoreFoundation
|
AM_LDFLAGS += -framework IOKit -framework CoreFoundation
|
||||||
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
||||||
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c
|
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c \
|
||||||
|
zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c
|
||||||
|
|
||||||
myhtopplatheaders = darwin/Platform.h darwin/DarwinProcess.h \
|
myhtopplatheaders = $(darwin_platform_headers)
|
||||||
darwin/DarwinProcessList.h darwin/DarwinCRT.h darwin/Battery.h
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Solaris
|
||||||
|
# -------
|
||||||
|
|
||||||
|
solaris_platform_headers = \
|
||||||
|
solaris/Platform.h \
|
||||||
|
solaris/SolarisProcess.h \
|
||||||
|
solaris/SolarisProcessList.h \
|
||||||
|
solaris/SolarisCRT.h \
|
||||||
|
solaris/Battery.h \
|
||||||
|
zfs/ZfsArcMeter.h \
|
||||||
|
zfs/ZfsCompressedArcMeter.h \
|
||||||
|
zfs/ZfsArcStats.h
|
||||||
|
|
||||||
|
all_platform_headers += $(solaris_platform_headers)
|
||||||
|
|
||||||
|
if HTOP_SOLARIS
|
||||||
|
myhtopplatsources = solaris/Platform.c \
|
||||||
|
solaris/SolarisProcess.c solaris/SolarisProcessList.c \
|
||||||
|
solaris/SolarisCRT.c solaris/Battery.c \
|
||||||
|
zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c
|
||||||
|
|
||||||
|
myhtopplatheaders = $(solaris_platform_headers)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Unsupported
|
||||||
|
# -----------
|
||||||
|
|
||||||
|
unsupported_platform_headers = \
|
||||||
|
unsupported/Platform.h \
|
||||||
|
unsupported/UnsupportedProcess.h \
|
||||||
|
unsupported/UnsupportedProcessList.h \
|
||||||
|
unsupported/UnsupportedCRT.h \
|
||||||
|
unsupported/Battery.h
|
||||||
|
|
||||||
|
all_platform_headers += $(unsupported_platform_headers)
|
||||||
|
|
||||||
if HTOP_UNSUPPORTED
|
if HTOP_UNSUPPORTED
|
||||||
myhtopplatsources = unsupported/Platform.c \
|
myhtopplatsources = unsupported/Platform.c \
|
||||||
unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \
|
unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \
|
||||||
unsupported/UnsupportedCRT.c unsupported/Battery.c
|
unsupported/UnsupportedCRT.c unsupported/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = unsupported/Platform.h \
|
myhtopplatheaders = $(unsupported_platform_headers)
|
||||||
unsupported/UnsupportedProcess.h unsupported/UnsupportedProcessList.h \
|
|
||||||
unsupported/UnsupportedCRT.h unsupported/Battery.h
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# ----
|
||||||
|
|
||||||
SUFFIXES = .h
|
SUFFIXES = .h
|
||||||
|
|
||||||
BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders)
|
BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders)
|
||||||
htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h
|
htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h
|
||||||
|
|
||||||
|
.PHONY: htop-headers clean-htop-headers
|
||||||
|
|
||||||
|
htop-headers: $(myhtopheaders) $(all_platform_headers)
|
||||||
|
|
||||||
|
clean-htop-headers:
|
||||||
|
-rm -f $(myhtopheaders) $(all_platform_headers)
|
||||||
|
|
||||||
target:
|
target:
|
||||||
echo $(htop_SOURCES)
|
echo $(htop_SOURCES)
|
||||||
|
|
||||||
@ -95,7 +222,7 @@ debug:
|
|||||||
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG"
|
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG"
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" AM_LDFLAGS="-lgcov"
|
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" LDFLAGS="-lgcov"
|
||||||
|
|
||||||
.c.h:
|
.c.h:
|
||||||
@srcdir@/scripts/MakeHeader.py $<
|
@srcdir@/scripts/MakeHeader.py $<
|
||||||
@ -103,6 +230,13 @@ coverage:
|
|||||||
cppcheck:
|
cppcheck:
|
||||||
cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS
|
cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS
|
||||||
|
|
||||||
|
dist-hook: $(top_distdir)/configure
|
||||||
|
@if grep 'pkg_m4_absent' '$(top_distdir)/configure'; then \
|
||||||
|
echo 'configure is generated without pkg.m4. Please supply pkg.m4 and run ./autogen.sh to rebuild the configure script.'>&2; \
|
||||||
|
(exit 1); \
|
||||||
|
else :; \
|
||||||
|
fi
|
||||||
|
|
||||||
.PHONY: lcov
|
.PHONY: lcov
|
||||||
|
|
||||||
lcov:
|
lcov:
|
||||||
|
@ -24,7 +24,7 @@ int MemoryMeter_attributes[] = {
|
|||||||
MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE
|
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;
|
int written;
|
||||||
Platform_setMemoryValues(this);
|
Platform_setMemoryValues(this);
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ MeterClass MemoryMeter_class = {
|
|||||||
.delete = Meter_delete,
|
.delete = Meter_delete,
|
||||||
.display = MemoryMeter_display,
|
.display = MemoryMeter_display,
|
||||||
},
|
},
|
||||||
.setValues = MemoryMeter_setValues,
|
.updateValues = MemoryMeter_updateValues,
|
||||||
.defaultMode = BAR_METERMODE,
|
.defaultMode = BAR_METERMODE,
|
||||||
.maxItems = 3,
|
.maxItems = 3,
|
||||||
.total = 100.0,
|
.total = 100.0,
|
||||||
|
90
Meter.c
90
Meter.c
@ -37,7 +37,7 @@ typedef struct Meter_ Meter;
|
|||||||
typedef void(*Meter_Init)(Meter*);
|
typedef void(*Meter_Init)(Meter*);
|
||||||
typedef void(*Meter_Done)(Meter*);
|
typedef void(*Meter_Done)(Meter*);
|
||||||
typedef void(*Meter_UpdateMode)(Meter*, int);
|
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 void(*Meter_Draw)(Meter*, int, int, int);
|
||||||
|
|
||||||
typedef struct MeterClass_ {
|
typedef struct MeterClass_ {
|
||||||
@ -46,7 +46,7 @@ typedef struct MeterClass_ {
|
|||||||
const Meter_Done done;
|
const Meter_Done done;
|
||||||
const Meter_UpdateMode updateMode;
|
const Meter_UpdateMode updateMode;
|
||||||
const Meter_Draw draw;
|
const Meter_Draw draw;
|
||||||
const Meter_SetValues setValues;
|
const Meter_UpdateValues updateValues;
|
||||||
const int defaultMode;
|
const int defaultMode;
|
||||||
const double total;
|
const double total;
|
||||||
const int* attributes;
|
const int* attributes;
|
||||||
@ -66,7 +66,8 @@ typedef struct MeterClass_ {
|
|||||||
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
|
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
|
||||||
#define Meter_drawFn(this_) As_Meter(this_)->draw
|
#define Meter_drawFn(this_) As_Meter(this_)->draw
|
||||||
#define Meter_doneFn(this_) As_Meter(this_)->done
|
#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_defaultMode(this_) As_Meter(this_)->defaultMode
|
||||||
#define Meter_getItems(this_) As_Meter(this_)->curItems
|
#define Meter_getItems(this_) As_Meter(this_)->curItems
|
||||||
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
|
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
|
||||||
@ -77,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;
|
||||||
@ -132,12 +133,8 @@ Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) {
|
|||||||
this->h = 1;
|
this->h = 1;
|
||||||
this->param = param;
|
this->param = param;
|
||||||
this->pl = pl;
|
this->pl = pl;
|
||||||
char maxItems = type->maxItems;
|
type->curItems = type->maxItems;
|
||||||
if (maxItems == 0) {
|
this->values = xCalloc(type->maxItems, sizeof(double));
|
||||||
maxItems = 1;
|
|
||||||
}
|
|
||||||
type->curItems = maxItems;
|
|
||||||
this->values = xCalloc(maxItems, sizeof(double));
|
|
||||||
this->total = type->total;
|
this->total = type->total;
|
||||||
this->caption = xStrdup(type->caption);
|
this->caption = xStrdup(type->caption);
|
||||||
if (Meter_initFn(this))
|
if (Meter_initFn(this))
|
||||||
@ -155,7 +152,7 @@ int Meter_humanUnit(char* buffer, unsigned long int value, int size) {
|
|||||||
if (value / 1024 < powi)
|
if (value / 1024 < powi)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (prefix[1] == 0)
|
if (prefix[1] == '\0')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
powi *= 1024;
|
powi *= 1024;
|
||||||
@ -184,8 +181,7 @@ void Meter_delete(Object* cast) {
|
|||||||
if (Meter_doneFn(this)) {
|
if (Meter_doneFn(this)) {
|
||||||
Meter_done(this);
|
Meter_done(this);
|
||||||
}
|
}
|
||||||
if (this->drawData)
|
free(this->drawData);
|
||||||
free(this->drawData);
|
|
||||||
free(this->caption);
|
free(this->caption);
|
||||||
free(this->values);
|
free(this->values);
|
||||||
free(this);
|
free(this);
|
||||||
@ -216,8 +212,7 @@ void Meter_setMode(Meter* this, int modeIndex) {
|
|||||||
Meter_updateMode(this, modeIndex);
|
Meter_updateMode(this, modeIndex);
|
||||||
} else {
|
} else {
|
||||||
assert(modeIndex >= 1);
|
assert(modeIndex >= 1);
|
||||||
if (this->drawData)
|
free(this->drawData);
|
||||||
free(this->drawData);
|
|
||||||
this->drawData = NULL;
|
this->drawData = NULL;
|
||||||
|
|
||||||
MeterMode* mode = Meter_modes[modeIndex];
|
MeterMode* mode = Meter_modes[modeIndex];
|
||||||
@ -230,16 +225,16 @@ void Meter_setMode(Meter* this, int modeIndex) {
|
|||||||
ListItem* Meter_toListItem(Meter* this, bool moving) {
|
ListItem* Meter_toListItem(Meter* this, bool moving) {
|
||||||
char mode[21];
|
char mode[21];
|
||||||
if (this->mode)
|
if (this->mode)
|
||||||
snprintf(mode, 20, " [%s]", Meter_modes[this->mode]->uiName);
|
xSnprintf(mode, 20, " [%s]", Meter_modes[this->mode]->uiName);
|
||||||
else
|
else
|
||||||
mode[0] = '\0';
|
mode[0] = '\0';
|
||||||
char number[11];
|
char number[11];
|
||||||
if (this->param > 0)
|
if (this->param > 0)
|
||||||
snprintf(number, 10, " %d", this->param);
|
xSnprintf(number, 10, " %d", this->param);
|
||||||
else
|
else
|
||||||
number[0] = '\0';
|
number[0] = '\0';
|
||||||
char buffer[51];
|
char buffer[51];
|
||||||
snprintf(buffer, 50, "%s%s%s", Meter_uiName(this), number, mode);
|
xSnprintf(buffer, 50, "%s%s%s", Meter_uiName(this), number, mode);
|
||||||
ListItem* li = ListItem_new(buffer, 0);
|
ListItem* li = ListItem_new(buffer, 0);
|
||||||
li->moving = moving;
|
li->moving = moving;
|
||||||
return li;
|
return li;
|
||||||
@ -249,7 +244,7 @@ ListItem* Meter_toListItem(Meter* this, bool moving) {
|
|||||||
|
|
||||||
static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||||
char buffer[METER_BUFFER_LEN];
|
char buffer[METER_BUFFER_LEN];
|
||||||
Meter_setValues(this, buffer, METER_BUFFER_LEN - 1);
|
Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||||
(void) w;
|
(void) w;
|
||||||
|
|
||||||
attrset(CRT_colors[METER_TEXT]);
|
attrset(CRT_colors[METER_TEXT]);
|
||||||
@ -265,11 +260,11 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
|||||||
|
|
||||||
/* ---------- BarMeterMode ---------- */
|
/* ---------- BarMeterMode ---------- */
|
||||||
|
|
||||||
static char BarMeterMode_characters[] = "|#*@$%&.";
|
static const char BarMeterMode_characters[] = "|#*@$%&.";
|
||||||
|
|
||||||
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||||
char buffer[METER_BUFFER_LEN];
|
char buffer[METER_BUFFER_LEN];
|
||||||
Meter_setValues(this, buffer, METER_BUFFER_LEN - 1);
|
Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||||
|
|
||||||
w -= 2;
|
w -= 2;
|
||||||
attrset(CRT_colors[METER_TEXT]);
|
attrset(CRT_colors[METER_TEXT]);
|
||||||
@ -280,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++;
|
||||||
|
|
||||||
@ -289,13 +284,10 @@ 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];
|
|
||||||
for (int i = 0; i < w; i++)
|
|
||||||
bar[i] = ' ';
|
|
||||||
|
|
||||||
const size_t barOffset = w - MIN((int)strlen(buffer), w);
|
int blockSizes[10];
|
||||||
snprintf(bar + barOffset, w - barOffset + 1, "%s", buffer);
|
|
||||||
|
xSnprintf(bar, w + 1, "%*.*s", w, w, buffer);
|
||||||
|
|
||||||
// First draw in the bar[] buffer...
|
// First draw in the bar[] buffer...
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@ -344,7 +336,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
|||||||
#ifdef HAVE_LIBNCURSESW
|
#ifdef HAVE_LIBNCURSESW
|
||||||
|
|
||||||
#define PIXPERROW_UTF8 4
|
#define PIXPERROW_UTF8 4
|
||||||
static const char* GraphMeterMode_dotsUtf8[] = {
|
static const char* const GraphMeterMode_dotsUtf8[] = {
|
||||||
/*00*/" ", /*01*/"⢀", /*02*/"⢠", /*03*/"⢰", /*04*/ "⢸",
|
/*00*/" ", /*01*/"⢀", /*02*/"⢠", /*03*/"⢰", /*04*/ "⢸",
|
||||||
/*10*/"⡀", /*11*/"⣀", /*12*/"⣠", /*13*/"⣰", /*14*/ "⣸",
|
/*10*/"⡀", /*11*/"⣀", /*12*/"⣠", /*13*/"⣰", /*14*/ "⣸",
|
||||||
/*20*/"⡄", /*21*/"⣄", /*22*/"⣤", /*23*/"⣴", /*24*/ "⣼",
|
/*20*/"⡄", /*21*/"⣄", /*22*/"⣤", /*23*/"⣴", /*24*/ "⣼",
|
||||||
@ -355,19 +347,19 @@ static const char* GraphMeterMode_dotsUtf8[] = {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PIXPERROW_ASCII 2
|
#define PIXPERROW_ASCII 2
|
||||||
static const char* GraphMeterMode_dotsAscii[] = {
|
static const char* const GraphMeterMode_dotsAscii[] = {
|
||||||
/*00*/" ", /*01*/".", /*02*/":",
|
/*00*/" ", /*01*/".", /*02*/":",
|
||||||
/*10*/".", /*11*/".", /*12*/":",
|
/*10*/".", /*11*/".", /*12*/":",
|
||||||
/*20*/":", /*21*/":", /*22*/":"
|
/*20*/":", /*21*/":", /*22*/":"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char** GraphMeterMode_dots;
|
static const char* const* GraphMeterMode_dots;
|
||||||
static int GraphMeterMode_pixPerRow;
|
static int GraphMeterMode_pixPerRow;
|
||||||
|
|
||||||
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||||
|
|
||||||
if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData));
|
if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData));
|
||||||
GraphData* data = (GraphData*) this->drawData;
|
GraphData* data = (GraphData*) this->drawData;
|
||||||
const int nValues = METER_BUFFER_LEN;
|
const int nValues = METER_BUFFER_LEN;
|
||||||
|
|
||||||
#ifdef HAVE_LIBNCURSESW
|
#ifdef HAVE_LIBNCURSESW
|
||||||
@ -386,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), <)) {
|
||||||
@ -395,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_setValues(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++)
|
||||||
@ -406,16 +398,16 @@ 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;
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
for (; i < nValues; i+=2, k++) {
|
for (; i < nValues - 1; i+=2, k++) {
|
||||||
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
|
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
|
||||||
int v1 = CLAMP(data->values[i] * pix, 1, pix);
|
int v1 = CLAMP((int) lround(data->values[i] * pix), 1, pix);
|
||||||
int v2 = CLAMP(data->values[i+1] * pix, 1, pix);
|
int v2 = CLAMP((int) lround(data->values[i+1] * pix), 1, pix);
|
||||||
|
|
||||||
int colorIdx = GRAPH_1;
|
int colorIdx = GRAPH_1;
|
||||||
for (int line = 0; line < GRAPH_HEIGHT; line++) {
|
for (int line = 0; line < GRAPH_HEIGHT; line++) {
|
||||||
@ -432,7 +424,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
|||||||
|
|
||||||
/* ---------- LEDMeterMode ---------- */
|
/* ---------- LEDMeterMode ---------- */
|
||||||
|
|
||||||
static const char* LEDMeterMode_digitsAscii[] = {
|
static const char* const LEDMeterMode_digitsAscii[] = {
|
||||||
" __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ ",
|
" __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ ",
|
||||||
"| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|",
|
"| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|",
|
||||||
"|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"
|
"|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"
|
||||||
@ -440,7 +432,7 @@ static const char* LEDMeterMode_digitsAscii[] = {
|
|||||||
|
|
||||||
#ifdef HAVE_LIBNCURSESW
|
#ifdef HAVE_LIBNCURSESW
|
||||||
|
|
||||||
static const char* LEDMeterMode_digitsUtf8[] = {
|
static const char* const LEDMeterMode_digitsUtf8[] = {
|
||||||
"┌──┐"," ┐ ","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐",
|
"┌──┐"," ┐ ","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐",
|
||||||
"│ │"," │ ","┌──┘"," ──┤","└──┤","└──┐","├──┐"," │","├──┤","└──┤",
|
"│ │"," │ ","┌──┘"," ──┤","└──┤","└──┐","├──┐"," │","├──┤","└──┤",
|
||||||
"└──┘"," ╵ ","└──╴","╶──┘"," ╵","╶──┘","└──┘"," ╵","└──┘"," ──┘"
|
"└──┘"," ╵ ","└──╴","╶──┘"," ╵","╶──┘","└──┘"," ╵","└──┘"," ──┘"
|
||||||
@ -448,7 +440,7 @@ static const char* LEDMeterMode_digitsUtf8[] = {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char** LEDMeterMode_digits;
|
static const char* const* LEDMeterMode_digits;
|
||||||
|
|
||||||
static void LEDMeterMode_drawDigit(int x, int y, int n) {
|
static void LEDMeterMode_drawDigit(int x, int y, int n) {
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
@ -466,8 +458,8 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
|
|||||||
LEDMeterMode_digits = LEDMeterMode_digitsAscii;
|
LEDMeterMode_digits = LEDMeterMode_digitsAscii;
|
||||||
|
|
||||||
char buffer[METER_BUFFER_LEN];
|
char buffer[METER_BUFFER_LEN];
|
||||||
Meter_setValues(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);
|
||||||
|
|
||||||
@ -529,8 +521,11 @@ MeterMode* Meter_modes[] = {
|
|||||||
|
|
||||||
/* Blank meter */
|
/* 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;
|
(void) this; (void) buffer; (void) size;
|
||||||
|
if (size > 0) {
|
||||||
|
*buffer = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BlankMeter_display(Object* cast, RichString* out) {
|
static void BlankMeter_display(Object* cast, RichString* out) {
|
||||||
@ -548,8 +543,9 @@ MeterClass BlankMeter_class = {
|
|||||||
.delete = Meter_delete,
|
.delete = Meter_delete,
|
||||||
.display = BlankMeter_display,
|
.display = BlankMeter_display,
|
||||||
},
|
},
|
||||||
.setValues = BlankMeter_setValues,
|
.updateValues = BlankMeter_updateValues,
|
||||||
.defaultMode = TEXT_METERMODE,
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 0,
|
||||||
.total = 100.0,
|
.total = 100.0,
|
||||||
.attributes = BlankMeter_attributes,
|
.attributes = BlankMeter_attributes,
|
||||||
.name = "Blank",
|
.name = "Blank",
|
||||||
|
21
Meter.h
21
Meter.h
@ -24,7 +24,7 @@ typedef struct Meter_ Meter;
|
|||||||
typedef void(*Meter_Init)(Meter*);
|
typedef void(*Meter_Init)(Meter*);
|
||||||
typedef void(*Meter_Done)(Meter*);
|
typedef void(*Meter_Done)(Meter*);
|
||||||
typedef void(*Meter_UpdateMode)(Meter*, int);
|
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 void(*Meter_Draw)(Meter*, int, int, int);
|
||||||
|
|
||||||
typedef struct MeterClass_ {
|
typedef struct MeterClass_ {
|
||||||
@ -33,7 +33,7 @@ typedef struct MeterClass_ {
|
|||||||
const Meter_Done done;
|
const Meter_Done done;
|
||||||
const Meter_UpdateMode updateMode;
|
const Meter_UpdateMode updateMode;
|
||||||
const Meter_Draw draw;
|
const Meter_Draw draw;
|
||||||
const Meter_SetValues setValues;
|
const Meter_UpdateValues updateValues;
|
||||||
const int defaultMode;
|
const int defaultMode;
|
||||||
const double total;
|
const double total;
|
||||||
const int* attributes;
|
const int* attributes;
|
||||||
@ -53,7 +53,8 @@ typedef struct MeterClass_ {
|
|||||||
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
|
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
|
||||||
#define Meter_drawFn(this_) As_Meter(this_)->draw
|
#define Meter_drawFn(this_) As_Meter(this_)->draw
|
||||||
#define Meter_doneFn(this_) As_Meter(this_)->done
|
#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_defaultMode(this_) As_Meter(this_)->defaultMode
|
||||||
#define Meter_getItems(this_) As_Meter(this_)->curItems
|
#define Meter_getItems(this_) As_Meter(this_)->curItems
|
||||||
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
|
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
|
||||||
@ -64,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;
|
||||||
@ -108,17 +109,17 @@ typedef struct GraphData_ {
|
|||||||
|
|
||||||
extern MeterClass Meter_class;
|
extern MeterClass Meter_class;
|
||||||
|
|
||||||
Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type);
|
extern Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type);
|
||||||
|
|
||||||
int Meter_humanUnit(char* buffer, unsigned long int value, int size);
|
extern int Meter_humanUnit(char* buffer, unsigned long int value, int size);
|
||||||
|
|
||||||
void Meter_delete(Object* cast);
|
extern void Meter_delete(Object* cast);
|
||||||
|
|
||||||
void Meter_setCaption(Meter* this, const char* caption);
|
extern void Meter_setCaption(Meter* this, const char* caption);
|
||||||
|
|
||||||
void Meter_setMode(Meter* this, int modeIndex);
|
extern void Meter_setMode(Meter* this, int modeIndex);
|
||||||
|
|
||||||
ListItem* Meter_toListItem(Meter* this, bool moving);
|
extern ListItem* Meter_toListItem(Meter* this, bool moving);
|
||||||
|
|
||||||
/* ---------- TextMeterMode ---------- */
|
/* ---------- TextMeterMode ---------- */
|
||||||
|
|
||||||
|
@ -31,13 +31,19 @@ struct MetersPanel_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* MetersFunctions[] = {"Type ", "Move ", "Delete", "Done ", NULL};
|
// Note: In code the meters are known to have bar/text/graph "Modes", but in UI
|
||||||
static const char* MetersKeys[] = {"Space", "Enter", "Del", "Esc"};
|
// we call them "Styles".
|
||||||
static int MetersEvents[] = {' ', 13, KEY_DC, 27};
|
static const char* const MetersFunctions[] = {"Style ", "Move ", " ", "Delete", "Done ", NULL};
|
||||||
|
static const char* const MetersKeys[] = {"Space", "Enter", " ", "Del", "F10"};
|
||||||
|
static int MetersEvents[] = {' ', 13, ERR, KEY_DC, KEY_F(10)};
|
||||||
|
|
||||||
static const char* MetersMovingFunctions[] = {"Up ", "Down ", "Left ", "Right ", "Confirm", "Delete", "Done ", NULL};
|
// We avoid UTF-8 arrows ← → here as they might display full-width on Chinese
|
||||||
static const char* MetersMovingKeys[] = {"Up", "Dn", "Lt", "Rt", "Enter", "Del", "Esc"};
|
// terminals, breaking our aligning.
|
||||||
static int MetersMovingEvents[] = {KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, 13, KEY_DC, 27};
|
// In <http://unicode.org/reports/tr11/>, arrows (U+2019..U+2199) are
|
||||||
|
// considered "Ambiguous characters".
|
||||||
|
static const char* const MetersMovingFunctions[] = {"Style ", "Lock ", "Up ", "Down ", "Left ", "Right ", " ", "Delete", "Done ", NULL};
|
||||||
|
static const char* const MetersMovingKeys[] = {"Space", "Enter", "Up", "Dn", "<-", "->", " ", "Del", "F10"};
|
||||||
|
static int MetersMovingEvents[] = {' ', 13, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, ERR, KEY_DC, KEY_F(10)};
|
||||||
static FunctionBar* Meters_movingBar = NULL;
|
static FunctionBar* Meters_movingBar = NULL;
|
||||||
|
|
||||||
static void MetersPanel_delete(Object* object) {
|
static void MetersPanel_delete(Object* object) {
|
||||||
@ -50,7 +56,10 @@ static void MetersPanel_delete(Object* object) {
|
|||||||
void MetersPanel_setMoving(MetersPanel* this, bool moving) {
|
void MetersPanel_setMoving(MetersPanel* this, bool moving) {
|
||||||
Panel* super = (Panel*) this;
|
Panel* super = (Panel*) this;
|
||||||
this->moving = moving;
|
this->moving = moving;
|
||||||
((ListItem*)Panel_getSelected(super))->moving = moving;
|
ListItem* selected = (ListItem*)Panel_getSelected(super);
|
||||||
|
if (selected) {
|
||||||
|
selected->moving = moving;
|
||||||
|
}
|
||||||
if (!moving) {
|
if (!moving) {
|
||||||
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOCUS]);
|
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOCUS]);
|
||||||
Panel_setDefaultBar(super);
|
Panel_setDefaultBar(super);
|
||||||
@ -58,6 +67,7 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) {
|
|||||||
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOLLOW]);
|
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOLLOW]);
|
||||||
super->currentBar = Meters_movingBar;
|
super->currentBar = Meters_movingBar;
|
||||||
}
|
}
|
||||||
|
FunctionBar_draw(this->super.currentBar, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {
|
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {
|
||||||
@ -83,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;
|
||||||
@ -96,7 +106,6 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
|||||||
if (!Vector_size(this->meters))
|
if (!Vector_size(this->meters))
|
||||||
break;
|
break;
|
||||||
MetersPanel_setMoving(this, !(this->moving));
|
MetersPanel_setMoving(this, !(this->moving));
|
||||||
FunctionBar_draw(this->super.currentBar, NULL);
|
|
||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -119,8 +128,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
|||||||
if (!this->moving) {
|
if (!this->moving) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* else fallthrough */
|
|
||||||
}
|
}
|
||||||
|
/* else fallthrough */
|
||||||
case KEY_F(7):
|
case KEY_F(7):
|
||||||
case '[':
|
case '[':
|
||||||
case '-':
|
case '-':
|
||||||
@ -135,8 +144,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
|||||||
if (!this->moving) {
|
if (!this->moving) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* else fallthrough */
|
|
||||||
}
|
}
|
||||||
|
/* else fallthrough */
|
||||||
case KEY_F(8):
|
case KEY_F(8):
|
||||||
case ']':
|
case ']':
|
||||||
case '+':
|
case '+':
|
||||||
|
@ -27,11 +27,17 @@ struct MetersPanel_ {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Note: In code the meters are known to have bar/text/graph "Modes", but in UI
|
||||||
|
// we call them "Styles".
|
||||||
|
// We avoid UTF-8 arrows ← → here as they might display full-width on Chinese
|
||||||
|
// terminals, breaking our aligning.
|
||||||
|
// In <http://unicode.org/reports/tr11/>, arrows (U+2019..U+2199) are
|
||||||
|
// considered "Ambiguous characters".
|
||||||
|
|
||||||
void MetersPanel_setMoving(MetersPanel* this, bool moving);
|
extern void MetersPanel_setMoving(MetersPanel* this, bool moving);
|
||||||
|
|
||||||
extern PanelClass MetersPanel_class;
|
extern PanelClass MetersPanel_class;
|
||||||
|
|
||||||
MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr);
|
extern MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
8
Object.c
8
Object.c
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - Object.c
|
htop - Object.c
|
||||||
(C) 2004-2012 Hisham H. Muhammad
|
(C) 2004-2012 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
@ -28,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;
|
||||||
@ -40,6 +41,11 @@ struct Object_ {
|
|||||||
ObjectClass* klass;
|
ObjectClass* klass;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
int i;
|
||||||
|
void* v;
|
||||||
|
} Arg;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
ObjectClass Object_class = {
|
ObjectClass Object_class = {
|
||||||
|
10
Object.h
10
Object.h
@ -5,6 +5,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - Object.h
|
htop - Object.h
|
||||||
(C) 2004-2012 Hisham H. Muhammad
|
(C) 2004-2012 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
@ -29,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;
|
||||||
@ -41,12 +42,17 @@ struct Object_ {
|
|||||||
ObjectClass* klass;
|
ObjectClass* klass;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
int i;
|
||||||
|
void* v;
|
||||||
|
} Arg;
|
||||||
|
|
||||||
|
|
||||||
extern ObjectClass Object_class;
|
extern ObjectClass Object_class;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
bool Object_isA(Object* o, const ObjectClass* klass);
|
extern bool Object_isA(Object* o, const ObjectClass* klass);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -76,27 +76,41 @@ void OpenFilesScreen_draw(InfoScreen* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||||
char command[1025];
|
char buffer[1025];
|
||||||
snprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid);
|
xSnprintf(buffer, 1024, "%d", pid);
|
||||||
FILE* fd = popen(command, "r");
|
|
||||||
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
|
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
|
||||||
OpenFiles_FileData* fdata = NULL;
|
OpenFiles_FileData* fdata = NULL;
|
||||||
OpenFiles_Data* item = &(pdata->data);
|
OpenFiles_Data* item = &(pdata->data);
|
||||||
if (!fd) {
|
int fdpair[2];
|
||||||
pdata->error = 127;
|
if (pipe(fdpair) == -1) {
|
||||||
|
pdata->error = 1;
|
||||||
return pdata;
|
return pdata;
|
||||||
}
|
}
|
||||||
while (!feof(fd)) {
|
pid_t child = fork();
|
||||||
int cmd = fgetc(fd);
|
if (child == -1) {
|
||||||
if (cmd == EOF)
|
pdata->error = 1;
|
||||||
break;
|
return pdata;
|
||||||
char* entry = xMalloc(1024);
|
}
|
||||||
if (!fgets(entry, 1024, fd)) {
|
if (child == 0) {
|
||||||
free(entry);
|
close(fdpair[0]);
|
||||||
|
dup2(fdpair[1], STDOUT_FILENO);
|
||||||
|
close(fdpair[1]);
|
||||||
|
int fdnull = open("/dev/null", O_WRONLY);
|
||||||
|
if (fdnull < 0)
|
||||||
|
exit(1);
|
||||||
|
dup2(fdnull, STDERR_FILENO);
|
||||||
|
close(fdnull);
|
||||||
|
execlp("lsof", "lsof", "-P", "-p", buffer, "-F", NULL);
|
||||||
|
exit(127);
|
||||||
|
}
|
||||||
|
close(fdpair[1]);
|
||||||
|
FILE* fd = fdopen(fdpair[0], "r");
|
||||||
|
for (;;) {
|
||||||
|
char* line = String_readLine(fd);
|
||||||
|
if (!line) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
char* newline = strrchr(entry, '\n');
|
unsigned char cmd = line[0];
|
||||||
*newline = '\0';
|
|
||||||
if (cmd == 'f') {
|
if (cmd == 'f') {
|
||||||
OpenFiles_FileData* nextFile = xCalloc(1, sizeof(OpenFiles_FileData));
|
OpenFiles_FileData* nextFile = xCalloc(1, sizeof(OpenFiles_FileData));
|
||||||
if (fdata == NULL) {
|
if (fdata == NULL) {
|
||||||
@ -107,10 +121,19 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
|||||||
fdata = nextFile;
|
fdata = nextFile;
|
||||||
item = &(fdata->data);
|
item = &(fdata->data);
|
||||||
}
|
}
|
||||||
assert(cmd >= 0 && cmd <= 0xff);
|
item->data[cmd] = xStrdup(line + 1);
|
||||||
item->data[cmd] = entry;
|
free(line);
|
||||||
}
|
}
|
||||||
pdata->error = pclose(fd);
|
fclose(fd);
|
||||||
|
int wstatus;
|
||||||
|
if (waitpid(child, &wstatus, 0) == -1) {
|
||||||
|
pdata->error = 1;
|
||||||
|
return pdata;
|
||||||
|
}
|
||||||
|
if (!WIFEXITED(wstatus))
|
||||||
|
pdata->error = 1;
|
||||||
|
else
|
||||||
|
pdata->error = WEXITSTATUS(wstatus);
|
||||||
return pdata;
|
return pdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,9 +155,11 @@ void OpenFilesScreen_scan(InfoScreen* this) {
|
|||||||
} else {
|
} else {
|
||||||
OpenFiles_FileData* fdata = pdata->files;
|
OpenFiles_FileData* fdata = pdata->files;
|
||||||
while (fdata) {
|
while (fdata) {
|
||||||
char entry[1024];
|
|
||||||
char** data = fdata->data.data;
|
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[sizeEntry];
|
||||||
|
xSnprintf(entry, sizeEntry, "%5.5s %7.7s %10.10s %10.10s %10.10s %s",
|
||||||
data['f'] ? data['f'] : "",
|
data['f'] ? data['f'] : "",
|
||||||
data['t'] ? data['t'] : "",
|
data['t'] ? data['t'] : "",
|
||||||
data['D'] ? data['D'] : "",
|
data['D'] ? data['D'] : "",
|
||||||
|
@ -34,12 +34,12 @@ typedef struct OpenFilesScreen_ {
|
|||||||
|
|
||||||
extern InfoScreenClass OpenFilesScreen_class;
|
extern InfoScreenClass OpenFilesScreen_class;
|
||||||
|
|
||||||
OpenFilesScreen* OpenFilesScreen_new(Process* process);
|
extern OpenFilesScreen* OpenFilesScreen_new(Process* process);
|
||||||
|
|
||||||
void OpenFilesScreen_delete(Object* this);
|
extern void OpenFilesScreen_delete(Object* this);
|
||||||
|
|
||||||
void OpenFilesScreen_draw(InfoScreen* this);
|
extern void OpenFilesScreen_draw(InfoScreen* this);
|
||||||
|
|
||||||
void OpenFilesScreen_scan(InfoScreen* this);
|
extern void OpenFilesScreen_scan(InfoScreen* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
41
Panel.c
41
Panel.c
@ -61,6 +61,7 @@ struct Panel_ {
|
|||||||
Vector* items;
|
Vector* items;
|
||||||
int selected;
|
int selected;
|
||||||
int oldSelected;
|
int oldSelected;
|
||||||
|
int selectedLen;
|
||||||
void* eventHandlerState;
|
void* eventHandlerState;
|
||||||
int scrollV;
|
int scrollV;
|
||||||
short scrollH;
|
short scrollH;
|
||||||
@ -82,10 +83,7 @@ struct Panel_ {
|
|||||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define KEY_CTRLN 0016 /* control-n key */
|
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||||
#define KEY_CTRLP 0020 /* control-p key */
|
|
||||||
#define KEY_CTRLF 0006 /* control-f key */
|
|
||||||
#define KEY_CTRLB 0002 /* control-b key */
|
|
||||||
|
|
||||||
PanelClass Panel_class = {
|
PanelClass Panel_class = {
|
||||||
.super = {
|
.super = {
|
||||||
@ -327,6 +325,7 @@ void Panel_draw(Panel* this, bool focus) {
|
|||||||
if (selected) {
|
if (selected) {
|
||||||
attrset(selectionColor);
|
attrset(selectionColor);
|
||||||
RichString_setAttr(&item, selectionColor);
|
RichString_setAttr(&item, selectionColor);
|
||||||
|
this->selectedLen = itemLen;
|
||||||
}
|
}
|
||||||
mvhline(y + line, x, ' ', this->w);
|
mvhline(y + line, x, ' ', this->w);
|
||||||
if (amt > 0)
|
if (amt > 0)
|
||||||
@ -352,6 +351,7 @@ void Panel_draw(Panel* this, bool focus) {
|
|||||||
RichString_begin(new);
|
RichString_begin(new);
|
||||||
Object_display(newObj, &new);
|
Object_display(newObj, &new);
|
||||||
int newLen = RichString_sizeVal(new);
|
int newLen = RichString_sizeVal(new);
|
||||||
|
this->selectedLen = newLen;
|
||||||
mvhline(y+ this->oldSelected - first, x+0, ' ', this->w);
|
mvhline(y+ this->oldSelected - first, x+0, ' ', this->w);
|
||||||
if (scrollH < oldLen)
|
if (scrollH < oldLen)
|
||||||
RichString_printoffnVal(old, y+this->oldSelected - first, x,
|
RichString_printoffnVal(old, y+this->oldSelected - first, x,
|
||||||
@ -372,15 +372,15 @@ 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:
|
||||||
case KEY_CTRLN:
|
case KEY_CTRL('N'):
|
||||||
this->selected++;
|
this->selected++;
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
case KEY_CTRLP:
|
case KEY_CTRL('P'):
|
||||||
this->selected--;
|
this->selected--;
|
||||||
break;
|
break;
|
||||||
#ifdef KEY_C_DOWN
|
#ifdef KEY_C_DOWN
|
||||||
@ -394,25 +394,26 @@ bool Panel_onKey(Panel* this, int key) {
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
case KEY_CTRLB:
|
case KEY_CTRL('B'):
|
||||||
if (this->scrollH > 0) {
|
if (this->scrollH > 0) {
|
||||||
this->scrollH -= CRT_scrollHAmount;
|
this->scrollH -= MAX(CRT_scrollHAmount, 0);
|
||||||
this->needsRedraw = true;
|
this->needsRedraw = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
case KEY_CTRLF:
|
case KEY_CTRL('F'):
|
||||||
this->scrollH += CRT_scrollHAmount;
|
this->scrollH += CRT_scrollHAmount;
|
||||||
this->needsRedraw = true;
|
this->needsRedraw = true;
|
||||||
break;
|
break;
|
||||||
case KEY_PPAGE:
|
case KEY_PPAGE:
|
||||||
this->selected -= (this->h - 1);
|
this->selected -= (this->h - 1);
|
||||||
this->scrollV -= (this->h - 1);
|
this->scrollV = MAX(0, this->scrollV - this->h + 1);
|
||||||
this->needsRedraw = true;
|
this->needsRedraw = true;
|
||||||
break;
|
break;
|
||||||
case KEY_NPAGE:
|
case KEY_NPAGE:
|
||||||
this->selected += (this->h - 1);
|
this->selected += (this->h - 1);
|
||||||
this->scrollV += (this->h - 1);
|
this->scrollV = MAX(0, MIN(Vector_size(this->items) - this->h,
|
||||||
|
this->scrollV + this->h - 1));
|
||||||
this->needsRedraw = true;
|
this->needsRedraw = true;
|
||||||
break;
|
break;
|
||||||
case KEY_WHEELUP:
|
case KEY_WHEELUP:
|
||||||
@ -436,15 +437,25 @@ bool Panel_onKey(Panel* this, int key) {
|
|||||||
case KEY_END:
|
case KEY_END:
|
||||||
this->selected = size - 1;
|
this->selected = size - 1;
|
||||||
break;
|
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:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure selection within bounds
|
// ensure selection within bounds
|
||||||
if (this->selected < 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;
|
||||||
}
|
}
|
||||||
@ -458,7 +469,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
|||||||
this->eventHandlerState = xCalloc(100, sizeof(char));
|
this->eventHandlerState = xCalloc(100, sizeof(char));
|
||||||
char* buffer = this->eventHandlerState;
|
char* buffer = this->eventHandlerState;
|
||||||
|
|
||||||
if (ch < 255 && isalnum(ch)) {
|
if (ch > 0 && ch < 255 && isalnum(ch)) {
|
||||||
int len = strlen(buffer);
|
int len = strlen(buffer);
|
||||||
if (len < 99) {
|
if (len < 99) {
|
||||||
buffer[len] = ch;
|
buffer[len] = ch;
|
||||||
|
52
Panel.h
52
Panel.h
@ -50,6 +50,7 @@ struct Panel_ {
|
|||||||
Vector* items;
|
Vector* items;
|
||||||
int selected;
|
int selected;
|
||||||
int oldSelected;
|
int oldSelected;
|
||||||
|
int selectedLen;
|
||||||
void* eventHandlerState;
|
void* eventHandlerState;
|
||||||
int scrollV;
|
int scrollV;
|
||||||
short scrollH;
|
short scrollH;
|
||||||
@ -70,59 +71,56 @@ struct Panel_ {
|
|||||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define KEY_CTRLN 0016 /* control-n key */
|
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||||
#define KEY_CTRLP 0020 /* control-p key */
|
|
||||||
#define KEY_CTRLF 0006 /* control-f key */
|
|
||||||
#define KEY_CTRLB 0002 /* control-b key */
|
|
||||||
|
|
||||||
extern PanelClass Panel_class;
|
extern PanelClass Panel_class;
|
||||||
|
|
||||||
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar);
|
extern Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar);
|
||||||
|
|
||||||
void Panel_delete(Object* cast);
|
extern void Panel_delete(Object* cast);
|
||||||
|
|
||||||
void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar);
|
extern void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar);
|
||||||
|
|
||||||
void Panel_done(Panel* this);
|
extern void Panel_done(Panel* this);
|
||||||
|
|
||||||
void Panel_setSelectionColor(Panel* this, int color);
|
extern void Panel_setSelectionColor(Panel* this, int color);
|
||||||
|
|
||||||
RichString* Panel_getHeader(Panel* this);
|
extern RichString* Panel_getHeader(Panel* this);
|
||||||
|
|
||||||
extern void Panel_setHeader(Panel* this, const char* header);
|
extern void Panel_setHeader(Panel* this, const char* header);
|
||||||
|
|
||||||
void Panel_move(Panel* this, int x, int y);
|
extern void Panel_move(Panel* this, int x, int y);
|
||||||
|
|
||||||
void Panel_resize(Panel* this, int w, int h);
|
extern void Panel_resize(Panel* this, int w, int h);
|
||||||
|
|
||||||
void Panel_prune(Panel* this);
|
extern void Panel_prune(Panel* this);
|
||||||
|
|
||||||
void Panel_add(Panel* this, Object* o);
|
extern void Panel_add(Panel* this, Object* o);
|
||||||
|
|
||||||
void Panel_insert(Panel* this, int i, Object* o);
|
extern void Panel_insert(Panel* this, int i, Object* o);
|
||||||
|
|
||||||
void Panel_set(Panel* this, int i, Object* o);
|
extern void Panel_set(Panel* this, int i, Object* o);
|
||||||
|
|
||||||
Object* Panel_get(Panel* this, int i);
|
extern Object* Panel_get(Panel* this, int i);
|
||||||
|
|
||||||
Object* Panel_remove(Panel* this, int i);
|
extern Object* Panel_remove(Panel* this, int i);
|
||||||
|
|
||||||
Object* Panel_getSelected(Panel* this);
|
extern Object* Panel_getSelected(Panel* this);
|
||||||
|
|
||||||
void Panel_moveSelectedUp(Panel* this);
|
extern void Panel_moveSelectedUp(Panel* this);
|
||||||
|
|
||||||
void Panel_moveSelectedDown(Panel* this);
|
extern void Panel_moveSelectedDown(Panel* this);
|
||||||
|
|
||||||
int Panel_getSelectedIndex(Panel* this);
|
extern int Panel_getSelectedIndex(Panel* this);
|
||||||
|
|
||||||
int Panel_size(Panel* this);
|
extern int Panel_size(Panel* this);
|
||||||
|
|
||||||
void Panel_setSelected(Panel* this, int selected);
|
extern void Panel_setSelected(Panel* this, int selected);
|
||||||
|
|
||||||
void Panel_draw(Panel* this, bool focus);
|
extern void Panel_draw(Panel* this, bool focus);
|
||||||
|
|
||||||
bool Panel_onKey(Panel* this, int key);
|
extern bool Panel_onKey(Panel* this, int key);
|
||||||
|
|
||||||
HandlerResult Panel_selectByTyping(Panel* this, int ch);
|
extern HandlerResult Panel_selectByTyping(Panel* this, int ch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
158
Process.c
158
Process.c
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - Process.c
|
htop - Process.c
|
||||||
(C) 2004-2015 Hisham H. Muhammad
|
(C) 2004-2015 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
@ -8,6 +9,8 @@ in the source distribution for its full text.
|
|||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "RichString.h"
|
#include "RichString.h"
|
||||||
@ -18,6 +21,7 @@ in the source distribution for its full text.
|
|||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -27,6 +31,11 @@ in the source distribution for its full text.
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#ifdef MAJOR_IN_MKDEV
|
||||||
|
#include <sys/mkdev.h>
|
||||||
|
#elif defined(MAJOR_IN_SYSMACROS)
|
||||||
|
#include <sys/sysmacros.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#define SYS_ioprio_get __NR_ioprio_get
|
#define SYS_ioprio_get __NR_ioprio_get
|
||||||
@ -48,6 +57,7 @@ in the source distribution for its full text.
|
|||||||
#define PROCESS_FLAG_IO 0x0001
|
#define PROCESS_FLAG_IO 0x0001
|
||||||
|
|
||||||
typedef enum ProcessFields {
|
typedef enum ProcessFields {
|
||||||
|
NULL_PROCESSFIELD = 0,
|
||||||
PID = 1,
|
PID = 1,
|
||||||
COMM = 2,
|
COMM = 2,
|
||||||
STATE = 3,
|
STATE = 3,
|
||||||
@ -170,6 +180,12 @@ typedef struct ProcessClass_ {
|
|||||||
|
|
||||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||||
|
|
||||||
|
#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid)
|
||||||
|
|
||||||
|
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||||
|
|
||||||
|
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static int Process_getuid = -1;
|
static int Process_getuid = -1;
|
||||||
@ -177,10 +193,12 @@ static int Process_getuid = -1;
|
|||||||
#define ONE_K 1024L
|
#define ONE_K 1024L
|
||||||
#define ONE_M (ONE_K * ONE_K)
|
#define ONE_M (ONE_K * ONE_K)
|
||||||
#define ONE_G (ONE_M * ONE_K)
|
#define ONE_G (ONE_M * ONE_K)
|
||||||
|
#define ONE_T ((long long)ONE_G * ONE_K)
|
||||||
|
|
||||||
#define ONE_DECIMAL_K 1000L
|
#define ONE_DECIMAL_K 1000L
|
||||||
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
||||||
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
||||||
|
#define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K)
|
||||||
|
|
||||||
char Process_pidFormat[20] = "%7d ";
|
char Process_pidFormat[20] = "%7d ";
|
||||||
|
|
||||||
@ -193,16 +211,16 @@ void Process_setupColumnWidths() {
|
|||||||
assert(digits < 20);
|
assert(digits < 20);
|
||||||
for (int i = 0; Process_pidColumns[i].label; i++) {
|
for (int i = 0; Process_pidColumns[i].label; i++) {
|
||||||
assert(i < 20);
|
assert(i < 20);
|
||||||
sprintf(Process_titleBuffer[i], "%*s ", digits, Process_pidColumns[i].label);
|
xSnprintf(Process_titleBuffer[i], 20, "%*s ", digits, Process_pidColumns[i].label);
|
||||||
Process_fields[Process_pidColumns[i].id].title = Process_titleBuffer[i];
|
Process_fields[Process_pidColumns[i].id].title = Process_titleBuffer[i];
|
||||||
}
|
}
|
||||||
sprintf(Process_pidFormat, "%%%dd ", digits);
|
xSnprintf(Process_pidFormat, sizeof(Process_pidFormat), "%%%dd ", digits);
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
@ -210,11 +228,11 @@ 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)) {
|
||||||
len = snprintf(buffer, 10, "%4ldT ", number / ONE_G);
|
len = snprintf(buffer, 10, "%4luT ", number / ONE_G);
|
||||||
RichString_appendn(str, largeNumberColor, buffer, len);
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
return;
|
return;
|
||||||
} else if (number >= (1000 * ONE_DECIMAL_M)) {
|
} else if (number >= (1000 * ONE_DECIMAL_M)) {
|
||||||
@ -224,7 +242,7 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(number >= (100 * ONE_DECIMAL_M)) {
|
if(number >= (100 * ONE_DECIMAL_M)) {
|
||||||
len = snprintf(buffer, 10, "%4ldG ", number / ONE_M);
|
len = snprintf(buffer, 10, "%4luG ", number / ONE_M);
|
||||||
RichString_appendn(str, largeNumberColor, buffer, len);
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -232,11 +250,11 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
|
|||||||
RichString_appendn(str, largeNumberColor, buffer, len);
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
return;
|
return;
|
||||||
} else if (number >= 100000) {
|
} else if (number >= 100000) {
|
||||||
len = snprintf(buffer, 10, "%4ldM ", number / ONE_K);
|
len = snprintf(buffer, 10, "%4luM ", number / ONE_K);
|
||||||
RichString_appendn(str, processMegabytesColor, buffer, len);
|
RichString_appendn(str, processMegabytesColor, buffer, len);
|
||||||
return;
|
return;
|
||||||
} else if (number >= 1000) {
|
} else if (number >= 1000) {
|
||||||
len = snprintf(buffer, 10, "%2ld", number/1000);
|
len = snprintf(buffer, 10, "%2lu", number/1000);
|
||||||
RichString_appendn(str, processMegabytesColor, buffer, len);
|
RichString_appendn(str, processMegabytesColor, buffer, len);
|
||||||
number %= 1000;
|
number %= 1000;
|
||||||
len = snprintf(buffer, 10, "%03lu ", number);
|
len = snprintf(buffer, 10, "%03lu ", number);
|
||||||
@ -260,13 +278,23 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori
|
|||||||
processShadowColor = CRT_colors[PROCESS];
|
processShadowColor = CRT_colors[PROCESS];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (number > 10000000000) {
|
if ((long long) number == -1LL) {
|
||||||
snprintf(buffer, 13, "%11lld ", number / 1000);
|
int len = snprintf(buffer, 13, " no perm ");
|
||||||
|
RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len);
|
||||||
|
} else if (number >= 100000LL * ONE_DECIMAL_T) {
|
||||||
|
xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_G);
|
||||||
|
RichString_appendn(str, largeNumberColor, buffer, 12);
|
||||||
|
} else if (number >= 100LL * ONE_DECIMAL_T) {
|
||||||
|
xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_M);
|
||||||
|
RichString_appendn(str, largeNumberColor, buffer, 8);
|
||||||
|
RichString_appendn(str, processMegabytesColor, buffer+8, 4);
|
||||||
|
} else if (number >= 10LL * ONE_DECIMAL_G) {
|
||||||
|
xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_K);
|
||||||
RichString_appendn(str, largeNumberColor, buffer, 5);
|
RichString_appendn(str, largeNumberColor, buffer, 5);
|
||||||
RichString_appendn(str, processMegabytesColor, buffer+5, 3);
|
RichString_appendn(str, processMegabytesColor, buffer+5, 3);
|
||||||
RichString_appendn(str, processColor, buffer+8, 4);
|
RichString_appendn(str, processColor, buffer+8, 4);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buffer, 13, "%11llu ", number);
|
xSnprintf(buffer, 13, "%11llu ", number);
|
||||||
RichString_appendn(str, largeNumberColor, buffer, 2);
|
RichString_appendn(str, largeNumberColor, buffer, 2);
|
||||||
RichString_appendn(str, processMegabytesColor, buffer+2, 3);
|
RichString_appendn(str, processMegabytesColor, buffer+2, 3);
|
||||||
RichString_appendn(str, processColor, buffer+5, 3);
|
RichString_appendn(str, processColor, buffer+5, 3);
|
||||||
@ -283,15 +311,15 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths) {
|
|||||||
int hundredths = totalHundredths - (totalSeconds * 100);
|
int hundredths = totalHundredths - (totalSeconds * 100);
|
||||||
char buffer[11];
|
char buffer[11];
|
||||||
if (hours >= 100) {
|
if (hours >= 100) {
|
||||||
snprintf(buffer, 10, "%7lluh ", hours);
|
xSnprintf(buffer, 10, "%7lluh ", hours);
|
||||||
RichString_append(str, CRT_colors[LARGE_NUMBER], buffer);
|
RichString_append(str, CRT_colors[LARGE_NUMBER], buffer);
|
||||||
} else {
|
} else {
|
||||||
if (hours) {
|
if (hours) {
|
||||||
snprintf(buffer, 10, "%2lluh", hours);
|
xSnprintf(buffer, 10, "%2lluh", hours);
|
||||||
RichString_append(str, CRT_colors[LARGE_NUMBER], buffer);
|
RichString_append(str, CRT_colors[LARGE_NUMBER], buffer);
|
||||||
snprintf(buffer, 10, "%02d:%02d ", minutes, seconds);
|
xSnprintf(buffer, 10, "%02d:%02d ", minutes, seconds);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buffer, 10, "%2d:%02d.%02d ", minutes, seconds, hundredths);
|
xSnprintf(buffer, 10, "%2d:%02d.%02d ", minutes, seconds, hundredths);
|
||||||
}
|
}
|
||||||
RichString_append(str, CRT_colors[DEFAULT_COLOR], buffer);
|
RichString_append(str, CRT_colors[DEFAULT_COLOR], buffer);
|
||||||
}
|
}
|
||||||
@ -335,17 +363,23 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c
|
|||||||
largeNumberColor = CRT_colors[PROCESS];
|
largeNumberColor = CRT_colors[PROCESS];
|
||||||
processMegabytesColor = CRT_colors[PROCESS];
|
processMegabytesColor = CRT_colors[PROCESS];
|
||||||
}
|
}
|
||||||
if (rate < ONE_K) {
|
if (rate == -1) {
|
||||||
|
int len = snprintf(buffer, n, " no perm ");
|
||||||
|
RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len);
|
||||||
|
} else if (rate < ONE_K) {
|
||||||
int len = snprintf(buffer, n, "%7.2f B/s ", rate);
|
int len = snprintf(buffer, n, "%7.2f B/s ", rate);
|
||||||
RichString_appendn(str, processColor, buffer, len);
|
RichString_appendn(str, processColor, buffer, len);
|
||||||
} else if (rate < ONE_K * ONE_K) {
|
} else if (rate < ONE_M) {
|
||||||
int len = snprintf(buffer, n, "%7.2f K/s ", rate / ONE_K);
|
int len = snprintf(buffer, n, "%7.2f K/s ", rate / ONE_K);
|
||||||
RichString_appendn(str, processColor, buffer, len);
|
RichString_appendn(str, processColor, buffer, len);
|
||||||
} else if (rate < ONE_K * ONE_K * ONE_K) {
|
} else if (rate < ONE_G) {
|
||||||
int len = snprintf(buffer, n, "%7.2f M/s ", rate / ONE_K / ONE_K);
|
int len = snprintf(buffer, n, "%7.2f M/s ", rate / ONE_M);
|
||||||
RichString_appendn(str, processMegabytesColor, buffer, len);
|
RichString_appendn(str, processMegabytesColor, buffer, len);
|
||||||
|
} else if (rate < ONE_T) {
|
||||||
|
int len = snprintf(buffer, n, "%7.2f G/s ", rate / ONE_G);
|
||||||
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
} else {
|
} else {
|
||||||
int len = snprintf(buffer, n, "%7.2f G/s ", rate / ONE_K / ONE_K / ONE_K);
|
int len = snprintf(buffer, n, "%7.2f T/s ", rate / ONE_T);
|
||||||
RichString_appendn(str, largeNumberColor, buffer, len);
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -360,19 +394,19 @@ 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) {
|
||||||
snprintf(buffer, n, "%4d ", (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) {
|
||||||
snprintf(buffer, n, "%3d. ", (unsigned int)this->percent_cpu);
|
xSnprintf(buffer, n, "%3u. ", (unsigned int)this->percent_cpu);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buffer, n, "%4.1f ", this->percent_cpu);
|
xSnprintf(buffer, n, "%4.1f ", this->percent_cpu);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PERCENT_MEM: {
|
case PERCENT_MEM: {
|
||||||
if (this->percent_mem > 99.9) {
|
if (this->percent_mem > 99.9) {
|
||||||
snprintf(buffer, n, "100. ");
|
xSnprintf(buffer, n, "100. ");
|
||||||
} else {
|
} else {
|
||||||
snprintf(buffer, n, "%4.1f ", this->percent_mem);
|
xSnprintf(buffer, n, "%4.1f ", this->percent_mem);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -391,19 +425,24 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
int indent = (this->indent < 0 ? -this->indent : this->indent);
|
int indent = (this->indent < 0 ? -this->indent : this->indent);
|
||||||
|
|
||||||
for (int i = 0; i < 32; i++)
|
for (int i = 0; i < 32; i++)
|
||||||
if (indent & (1 << i))
|
if (indent & (1U << i))
|
||||||
maxIndent = i+1;
|
maxIndent = i+1;
|
||||||
for (int i = 0; i < maxIndent - 1; i++) {
|
for (int i = 0; i < maxIndent - 1; i++) {
|
||||||
int written;
|
int written, ret;
|
||||||
if (indent & (1 << i))
|
if (indent & (1 << i))
|
||||||
written = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
|
ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
|
||||||
else
|
else
|
||||||
written = snprintf(buf, n, " ");
|
ret = snprintf(buf, n, " ");
|
||||||
|
if (ret < 0 || ret >= n) {
|
||||||
|
written = n;
|
||||||
|
} else {
|
||||||
|
written = ret;
|
||||||
|
}
|
||||||
buf += written;
|
buf += written;
|
||||||
n -= written;
|
n -= written;
|
||||||
}
|
}
|
||||||
const char* draw = CRT_treeStr[lastItem ? (this->settings->direction == 1 ? TREE_STR_BEND : TREE_STR_TEND) : TREE_STR_RTEE];
|
const char* draw = CRT_treeStr[lastItem ? (this->settings->direction == 1 ? TREE_STR_BEND : TREE_STR_TEND) : TREE_STR_RTEE];
|
||||||
snprintf(buf, n, "%s%s ", draw, this->showChildren ? CRT_treeStr[TREE_STR_SHUT] : CRT_treeStr[TREE_STR_OPEN] );
|
xSnprintf(buf, n, "%s%s ", draw, this->showChildren ? CRT_treeStr[TREE_STR_SHUT] : CRT_treeStr[TREE_STR_OPEN] );
|
||||||
RichString_append(str, CRT_colors[PROCESS_TREE], buffer);
|
RichString_append(str, CRT_colors[PROCESS_TREE], buffer);
|
||||||
Process_writeCommand(this, attr, baseattr, str);
|
Process_writeCommand(this, attr, baseattr, str);
|
||||||
return;
|
return;
|
||||||
@ -414,28 +453,28 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
case M_RESIDENT: Process_humanNumber(str, this->m_resident * PAGE_SIZE_KB, coloring); return;
|
case M_RESIDENT: Process_humanNumber(str, this->m_resident * PAGE_SIZE_KB, coloring); return;
|
||||||
case M_SIZE: Process_humanNumber(str, this->m_size * PAGE_SIZE_KB, coloring); return;
|
case M_SIZE: Process_humanNumber(str, this->m_size * PAGE_SIZE_KB, coloring); return;
|
||||||
case NICE: {
|
case NICE: {
|
||||||
snprintf(buffer, n, "%3ld ", this->nice);
|
xSnprintf(buffer, n, "%3ld ", this->nice);
|
||||||
attr = this->nice < 0 ? CRT_colors[PROCESS_HIGH_PRIORITY]
|
attr = this->nice < 0 ? CRT_colors[PROCESS_HIGH_PRIORITY]
|
||||||
: this->nice > 0 ? CRT_colors[PROCESS_LOW_PRIORITY]
|
: this->nice > 0 ? CRT_colors[PROCESS_LOW_PRIORITY]
|
||||||
: attr;
|
: attr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break;
|
case NLWP: xSnprintf(buffer, n, "%4ld ", this->nlwp); break;
|
||||||
case PGRP: snprintf(buffer, n, Process_pidFormat, this->pgrp); break;
|
case PGRP: xSnprintf(buffer, n, Process_pidFormat, this->pgrp); break;
|
||||||
case PID: snprintf(buffer, n, Process_pidFormat, this->pid); break;
|
case PID: xSnprintf(buffer, n, Process_pidFormat, this->pid); break;
|
||||||
case PPID: snprintf(buffer, n, Process_pidFormat, this->ppid); break;
|
case PPID: xSnprintf(buffer, n, Process_pidFormat, this->ppid); break;
|
||||||
case PRIORITY: {
|
case PRIORITY: {
|
||||||
if(this->priority == -100)
|
if(this->priority <= -100)
|
||||||
snprintf(buffer, n, " RT ");
|
xSnprintf(buffer, n, " RT ");
|
||||||
else
|
else
|
||||||
snprintf(buffer, n, "%3ld ", this->priority);
|
xSnprintf(buffer, n, "%3ld ", this->priority);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PROCESSOR: snprintf(buffer, n, "%3d ", Settings_cpuId(this->settings, this->processor)); break;
|
case PROCESSOR: xSnprintf(buffer, n, "%3d ", Settings_cpuId(this->settings, this->processor)); break;
|
||||||
case SESSION: snprintf(buffer, n, Process_pidFormat, this->session); break;
|
case SESSION: xSnprintf(buffer, n, Process_pidFormat, this->session); break;
|
||||||
case STARTTIME: snprintf(buffer, n, "%s", this->starttime_show); break;
|
case STARTTIME: xSnprintf(buffer, n, "%s", this->starttime_show); break;
|
||||||
case STATE: {
|
case STATE: {
|
||||||
snprintf(buffer, n, "%c ", this->state);
|
xSnprintf(buffer, n, "%c ", this->state);
|
||||||
switch(this->state) {
|
switch(this->state) {
|
||||||
case 'R':
|
case 'R':
|
||||||
attr = CRT_colors[PROCESS_R_STATE];
|
attr = CRT_colors[PROCESS_R_STATE];
|
||||||
@ -446,18 +485,18 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ST_UID: snprintf(buffer, n, "%4d ", this->st_uid); break;
|
case ST_UID: xSnprintf(buffer, n, "%5d ", this->st_uid); break;
|
||||||
case TIME: Process_printTime(str, this->time); return;
|
case TIME: Process_printTime(str, this->time); return;
|
||||||
case TGID: snprintf(buffer, n, Process_pidFormat, this->tgid); break;
|
case TGID: xSnprintf(buffer, n, Process_pidFormat, this->tgid); break;
|
||||||
case TPGID: snprintf(buffer, n, Process_pidFormat, this->tpgid); break;
|
case TPGID: xSnprintf(buffer, n, Process_pidFormat, this->tpgid); break;
|
||||||
case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break;
|
case TTY_NR: xSnprintf(buffer, n, "%3u:%3u ", major(this->tty_nr), minor(this->tty_nr)); break;
|
||||||
case USER: {
|
case USER: {
|
||||||
if (Process_getuid != (int) this->st_uid)
|
if (Process_getuid != (int) this->st_uid)
|
||||||
attr = CRT_colors[PROCESS_SHADOW];
|
attr = CRT_colors[PROCESS_SHADOW];
|
||||||
if (this->user) {
|
if (this->user) {
|
||||||
snprintf(buffer, n, "%-9s ", this->user);
|
xSnprintf(buffer, n, "%-9s ", this->user);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buffer, n, "%-9d ", this->st_uid);
|
xSnprintf(buffer, n, "%-9d ", this->st_uid);
|
||||||
}
|
}
|
||||||
if (buffer[9] != '\0') {
|
if (buffer[9] != '\0') {
|
||||||
buffer[9] = ' ';
|
buffer[9] = ' ';
|
||||||
@ -466,7 +505,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
snprintf(buffer, n, "- ");
|
xSnprintf(buffer, n, "- ");
|
||||||
}
|
}
|
||||||
RichString_append(str, attr, buffer);
|
RichString_append(str, attr, buffer);
|
||||||
}
|
}
|
||||||
@ -514,26 +553,25 @@ void Process_toggleTag(Process* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Process_setPriority(Process* this, int priority) {
|
bool Process_setPriority(Process* this, int priority) {
|
||||||
uid_t euid = geteuid();
|
CRT_dropPrivileges();
|
||||||
seteuid(getuid());
|
|
||||||
int old_prio = getpriority(PRIO_PROCESS, this->pid);
|
int old_prio = getpriority(PRIO_PROCESS, this->pid);
|
||||||
int err = setpriority(PRIO_PROCESS, this->pid, priority);
|
int err = setpriority(PRIO_PROCESS, this->pid, priority);
|
||||||
seteuid(euid);
|
CRT_restorePrivileges();
|
||||||
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
|
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
|
||||||
this->nice = priority;
|
this->nice = priority;
|
||||||
}
|
}
|
||||||
return (err == 0);
|
return (err == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Process_changePriorityBy(Process* this, size_t delta) {
|
bool Process_changePriorityBy(Process* this, Arg delta) {
|
||||||
return Process_setPriority(this, this->nice + delta);
|
return Process_setPriority(this, this->nice + delta.i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_sendSignal(Process* this, size_t sgn) {
|
bool Process_sendSignal(Process* this, Arg sgn) {
|
||||||
uid_t euid = geteuid();
|
CRT_dropPrivileges();
|
||||||
seteuid(getuid());
|
bool ok = (kill(this->pid, sgn.i) == 0);
|
||||||
kill(this->pid, (int) sgn);
|
CRT_restorePrivileges();
|
||||||
seteuid(euid);
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
long Process_pidCompare(const void* v1, const void* v2) {
|
long Process_pidCompare(const void* v1, const void* v2) {
|
||||||
@ -590,7 +628,7 @@ long Process_compare(const void* v1, const void* v2) {
|
|||||||
return (p1->starttime_ctime - p2->starttime_ctime);
|
return (p1->starttime_ctime - p2->starttime_ctime);
|
||||||
}
|
}
|
||||||
case STATE:
|
case STATE:
|
||||||
return (p1->state - p2->state);
|
return (Process_sortState(p1->state) - Process_sortState(p2->state));
|
||||||
case ST_UID:
|
case ST_UID:
|
||||||
return (p1->st_uid - p2->st_uid);
|
return (p1->st_uid - p2->st_uid);
|
||||||
case TIME:
|
case TIME:
|
||||||
|
44
Process.h
44
Process.h
@ -5,10 +5,15 @@
|
|||||||
/*
|
/*
|
||||||
htop - Process.h
|
htop - Process.h
|
||||||
(C) 2004-2015 Hisham H. Muhammad
|
(C) 2004-2015 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef MAJOR_IN_MKDEV
|
||||||
|
#elif defined(MAJOR_IN_SYSMACROS)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#define SYS_ioprio_get __NR_ioprio_get
|
#define SYS_ioprio_get __NR_ioprio_get
|
||||||
#define SYS_ioprio_set __NR_ioprio_set
|
#define SYS_ioprio_set __NR_ioprio_set
|
||||||
@ -28,6 +33,7 @@ in the source distribution for its full text.
|
|||||||
#define PROCESS_FLAG_IO 0x0001
|
#define PROCESS_FLAG_IO 0x0001
|
||||||
|
|
||||||
typedef enum ProcessFields {
|
typedef enum ProcessFields {
|
||||||
|
NULL_PROCESSFIELD = 0,
|
||||||
PID = 1,
|
PID = 1,
|
||||||
COMM = 2,
|
COMM = 2,
|
||||||
STATE = 3,
|
STATE = 3,
|
||||||
@ -150,47 +156,55 @@ typedef struct ProcessClass_ {
|
|||||||
|
|
||||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||||
|
|
||||||
|
#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid)
|
||||||
|
|
||||||
|
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||||
|
|
||||||
|
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
||||||
|
|
||||||
|
|
||||||
#define ONE_K 1024L
|
#define ONE_K 1024L
|
||||||
#define ONE_M (ONE_K * ONE_K)
|
#define ONE_M (ONE_K * ONE_K)
|
||||||
#define ONE_G (ONE_M * ONE_K)
|
#define ONE_G (ONE_M * ONE_K)
|
||||||
|
#define ONE_T ((long long)ONE_G * ONE_K)
|
||||||
|
|
||||||
#define ONE_DECIMAL_K 1000L
|
#define ONE_DECIMAL_K 1000L
|
||||||
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
||||||
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
||||||
|
#define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K)
|
||||||
|
|
||||||
extern char Process_pidFormat[20];
|
extern char Process_pidFormat[20];
|
||||||
|
|
||||||
void Process_setupColumnWidths();
|
extern void Process_setupColumnWidths();
|
||||||
|
|
||||||
void Process_humanNumber(RichString* str, unsigned long number, bool coloring);
|
extern void Process_humanNumber(RichString* str, unsigned long number, bool coloring);
|
||||||
|
|
||||||
void Process_colorNumber(RichString* str, unsigned long long number, bool coloring);
|
extern void Process_colorNumber(RichString* str, unsigned long long number, bool coloring);
|
||||||
|
|
||||||
void Process_printTime(RichString* str, unsigned long long totalHundredths);
|
extern void Process_printTime(RichString* str, unsigned long long totalHundredths);
|
||||||
|
|
||||||
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
|
extern void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
|
||||||
|
|
||||||
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
extern void Process_writeField(Process* this, RichString* str, ProcessField field);
|
||||||
|
|
||||||
void Process_display(Object* cast, RichString* out);
|
extern void Process_display(Object* cast, RichString* out);
|
||||||
|
|
||||||
void Process_done(Process* this);
|
extern void Process_done(Process* this);
|
||||||
|
|
||||||
extern ProcessClass Process_class;
|
extern ProcessClass Process_class;
|
||||||
|
|
||||||
void Process_init(Process* this, struct Settings_* settings);
|
extern void Process_init(Process* this, struct Settings_* settings);
|
||||||
|
|
||||||
void Process_toggleTag(Process* this);
|
extern void Process_toggleTag(Process* this);
|
||||||
|
|
||||||
bool Process_setPriority(Process* this, int priority);
|
extern bool Process_setPriority(Process* this, int priority);
|
||||||
|
|
||||||
bool Process_changePriorityBy(Process* this, size_t delta);
|
extern bool Process_changePriorityBy(Process* this, Arg delta);
|
||||||
|
|
||||||
void Process_sendSignal(Process* this, size_t sgn);
|
extern bool Process_sendSignal(Process* this, Arg sgn);
|
||||||
|
|
||||||
long Process_pidCompare(const void* v1, const void* v2);
|
extern long Process_pidCompare(const void* v1, const void* v2);
|
||||||
|
|
||||||
long Process_compare(const void* v1, const void* v2);
|
extern long Process_compare(const void* v1, const void* v2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,6 +22,10 @@ in the source distribution for its full text.
|
|||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBHWLOC
|
||||||
|
#include <hwloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MAX_NAME
|
#ifndef MAX_NAME
|
||||||
#define MAX_NAME 128
|
#define MAX_NAME 128
|
||||||
#endif
|
#endif
|
||||||
@ -80,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;
|
||||||
|
|
||||||
@ -104,6 +108,11 @@ ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable*
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_done(ProcessList* this) {
|
void ProcessList_done(ProcessList* this) {
|
||||||
|
#ifdef HAVE_LIBHWLOC
|
||||||
|
if (this->topologyOk) {
|
||||||
|
hwloc_topology_destroy(this->topology);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Hashtable_delete(this->processTable);
|
Hashtable_delete(this->processTable);
|
||||||
Vector_delete(this->processes);
|
Vector_delete(this->processes);
|
||||||
Vector_delete(this->processes2);
|
Vector_delete(this->processes2);
|
||||||
@ -129,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));
|
||||||
@ -164,7 +173,7 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
|
|||||||
|
|
||||||
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
|
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
|
||||||
Process* process = (Process*) (Vector_get(this->processes, i));
|
Process* process = (Process*) (Vector_get(this->processes, i));
|
||||||
if (process->show && (process->tgid == pid || (process->tgid == process->pid && process->ppid == pid))) {
|
if (process->show && Process_isChildOf(process, pid)) {
|
||||||
process = (Process*) (Vector_take(this->processes, i));
|
process = (Process*) (Vector_take(this->processes, i));
|
||||||
Vector_add(children, process);
|
Vector_add(children, process);
|
||||||
}
|
}
|
||||||
@ -204,23 +213,51 @@ void ProcessList_sort(ProcessList* this) {
|
|||||||
// Restore settings
|
// Restore settings
|
||||||
this->settings->sortKey = sortKey;
|
this->settings->sortKey = sortKey;
|
||||||
this->settings->direction = direction;
|
this->settings->direction = direction;
|
||||||
// Take PID 1 as root and add to the new listing
|
|
||||||
int vsize = Vector_size(this->processes);
|
int vsize = Vector_size(this->processes);
|
||||||
Process* init = (Process*) (Vector_take(this->processes, 0));
|
// Find all processes whose parent is not visible
|
||||||
if (!init) return;
|
int size;
|
||||||
// This assertion crashes on hardened kernels.
|
while ((size = Vector_size(this->processes))) {
|
||||||
// I wonder how well tree view works on those systems.
|
int i;
|
||||||
// assert(init->pid == 1);
|
for (i = 0; i < size; i++) {
|
||||||
init->indent = 0;
|
Process* process = (Process*)(Vector_get(this->processes, i));
|
||||||
Vector_add(this->processes2, init);
|
// Immediately consume not shown processes
|
||||||
// Recursively empty list
|
if (!process->show) {
|
||||||
ProcessList_buildTree(this, init->pid, 0, 0, direction, true);
|
process = (Process*)(Vector_take(this->processes, i));
|
||||||
// Add leftovers
|
process->indent = 0;
|
||||||
while (Vector_size(this->processes)) {
|
Vector_add(this->processes2, process);
|
||||||
Process* p = (Process*) (Vector_take(this->processes, 0));
|
ProcessList_buildTree(this, process->pid, 0, 0, direction, false);
|
||||||
p->indent = 0;
|
break;
|
||||||
Vector_add(this->processes2, p);
|
}
|
||||||
ProcessList_buildTree(this, p->pid, 0, 0, direction, p->showChildren);
|
pid_t ppid = Process_getParentPid(process);
|
||||||
|
// Bisect the process vector to find parent
|
||||||
|
int l = 0, r = size;
|
||||||
|
// If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0)
|
||||||
|
// on Mac OS X 10.11.6) cancel bisecting and regard this process as
|
||||||
|
// root.
|
||||||
|
if (process->pid == ppid)
|
||||||
|
r = 0;
|
||||||
|
while (l < r) {
|
||||||
|
int c = (l + r) / 2;
|
||||||
|
pid_t pid = ((Process*)(Vector_get(this->processes, c)))->pid;
|
||||||
|
if (ppid == pid) {
|
||||||
|
break;
|
||||||
|
} else if (ppid < pid) {
|
||||||
|
r = c;
|
||||||
|
} else {
|
||||||
|
l = c + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If parent not found, then construct the tree with this root
|
||||||
|
if (l >= r) {
|
||||||
|
process = (Process*)(Vector_take(this->processes, i));
|
||||||
|
process->indent = 0;
|
||||||
|
Vector_add(this->processes2, process);
|
||||||
|
ProcessList_buildTree(this, process->pid, 0, 0, direction, process->showChildren);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// There should be no loop in the process tree
|
||||||
|
assert(i < size);
|
||||||
}
|
}
|
||||||
assert(Vector_size(this->processes2) == vsize); (void)vsize;
|
assert(Vector_size(this->processes2) == vsize); (void)vsize;
|
||||||
assert(Vector_size(this->processes) == 0);
|
assert(Vector_size(this->processes) == 0);
|
||||||
@ -307,6 +344,7 @@ void ProcessList_scan(ProcessList* this) {
|
|||||||
for (int i = 0; i < Vector_size(this->processes); i++) {
|
for (int i = 0; i < Vector_size(this->processes); i++) {
|
||||||
Process* p = (Process*) Vector_get(this->processes, i);
|
Process* p = (Process*) Vector_get(this->processes, i);
|
||||||
p->updated = false;
|
p->updated = false;
|
||||||
|
p->show = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->totalTasks = 0;
|
this->totalTasks = 0;
|
||||||
@ -315,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)
|
||||||
|
@ -16,6 +16,10 @@ in the source distribution for its full text.
|
|||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBHWLOC
|
||||||
|
#include <hwloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MAX_NAME
|
#ifndef MAX_NAME
|
||||||
#define MAX_NAME 128
|
#define MAX_NAME 128
|
||||||
#endif
|
#endif
|
||||||
@ -67,32 +71,32 @@ void ProcessList_delete(ProcessList* pl);
|
|||||||
void ProcessList_goThroughEntries(ProcessList* pl);
|
void ProcessList_goThroughEntries(ProcessList* pl);
|
||||||
|
|
||||||
|
|
||||||
ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
extern ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||||
|
|
||||||
void ProcessList_done(ProcessList* this);
|
extern void ProcessList_done(ProcessList* this);
|
||||||
|
|
||||||
void ProcessList_setPanel(ProcessList* this, Panel* panel);
|
extern void ProcessList_setPanel(ProcessList* this, Panel* panel);
|
||||||
|
|
||||||
void ProcessList_printHeader(ProcessList* this, RichString* header);
|
extern void ProcessList_printHeader(ProcessList* this, RichString* header);
|
||||||
|
|
||||||
void ProcessList_add(ProcessList* this, Process* p);
|
extern void ProcessList_add(ProcessList* this, Process* p);
|
||||||
|
|
||||||
void ProcessList_remove(ProcessList* this, Process* p);
|
extern void ProcessList_remove(ProcessList* this, Process* p);
|
||||||
|
|
||||||
Process* ProcessList_get(ProcessList* this, int idx);
|
extern Process* ProcessList_get(ProcessList* this, int idx);
|
||||||
|
|
||||||
int ProcessList_size(ProcessList* this);
|
extern int ProcessList_size(ProcessList* this);
|
||||||
|
|
||||||
void ProcessList_sort(ProcessList* this);
|
extern void ProcessList_sort(ProcessList* this);
|
||||||
|
|
||||||
ProcessField ProcessList_keyAt(ProcessList* this, int at);
|
extern ProcessField ProcessList_keyAt(ProcessList* this, int at);
|
||||||
|
|
||||||
void ProcessList_expandTree(ProcessList* this);
|
extern void ProcessList_expandTree(ProcessList* this);
|
||||||
|
|
||||||
void ProcessList_rebuildPanel(ProcessList* this);
|
extern void ProcessList_rebuildPanel(ProcessList* this);
|
||||||
|
|
||||||
Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor);
|
extern Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor);
|
||||||
|
|
||||||
void ProcessList_scan(ProcessList* this);
|
extern void ProcessList_scan(ProcessList* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
67
README
67
README
@ -1,50 +1,41 @@
|
|||||||
htop
|

|
||||||
====
|
|
||||||
|
|
||||||
by Hisham Muhammad <hisham@gobolinux.org>
|
[](https://github.com/htop-dev/htop/actions)
|
||||||
|
[](https://scan.coverity.com/projects/21617)
|
||||||
2004 - 2015
|
[](https://groups.io/g/htop)
|
||||||
|
[](https://webchat.freenode.net/#htop)
|
||||||
|
[](https://github.com/htop-dev/htop/releases/latest)
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
This is htop, an interactive process viewer.
|
`htop` is a cross-platform interactive process viewer.
|
||||||
It requires ncurses. It is developed primarily on Linux,
|
It requires `ncurses`.
|
||||||
but we also have code for running under FreeBSD and Mac OS X
|
|
||||||
(help and testing are wanted for these platforms!)
|
|
||||||
|
|
||||||
This software has evolved considerably over the years,
|
For more information and details on how to contribute to `htop`
|
||||||
and is reasonably complete, but there is always room for improvement.
|
visit [htop.dev](https://htop.dev).
|
||||||
|
|
||||||
Comparison between 'htop' and classic 'top'
|
Build instructions
|
||||||
-------------------------------------------
|
------------------
|
||||||
|
|
||||||
* In 'htop' you can scroll the list vertically and horizontally
|
|
||||||
to see all processes and full command lines.
|
|
||||||
* In 'top' you are subject to a delay for each unassigned
|
|
||||||
key you press (especially annoying when multi-key escape
|
|
||||||
sequences are triggered by accident).
|
|
||||||
* 'htop' starts faster ('top' seems to collect data for a while
|
|
||||||
before displaying anything).
|
|
||||||
* In 'htop' you don't need to type the process number to
|
|
||||||
kill a process, in 'top' you do.
|
|
||||||
* In 'htop' you don't need to type the process number or
|
|
||||||
the priority value to renice a process, in 'top' you do.
|
|
||||||
* In 'htop' you can kill multiple processes at once.
|
|
||||||
* 'top' is older, hence, more tested.
|
|
||||||
|
|
||||||
Compilation instructions
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
This program is distributed as a standard autotools-based package.
|
This program is distributed as a standard autotools-based package.
|
||||||
See the INSTALL file for detailed instructions, but you are
|
For detailed instructions see the [INSTALL](/INSTALL) file, which
|
||||||
probably used to the common `./configure`/`make`/`make install` routine.
|
is created after `./autogen.sh` is run.
|
||||||
|
|
||||||
When fetching the code from the development repository, you need
|
When compiling from a [release tarball](https://github.com/htop-dev/htop/releases/), run:
|
||||||
to run the `./autogen.sh` script, which in turn requires autotools
|
|
||||||
to be installed.
|
|
||||||
|
|
||||||
See the manual page (man htop) or the on-line help ('F1' or 'h'
|
./configure && make
|
||||||
inside htop) for a list of supported key commands.
|
|
||||||
|
|
||||||
if not all keys work check your curses configuration.
|
For compiling sources downloaded from the Git repository, run:
|
||||||
|
|
||||||
|
./autogen.sh && ./configure && make
|
||||||
|
|
||||||
|
By default `make install` will install into `/usr/local`, for changing
|
||||||
|
the path use `./configure --prefix=/some/path`.
|
||||||
|
|
||||||
|
See the manual page (`man htop`) or the on-line help ('F1' or 'h'
|
||||||
|
inside `htop`) for a list of supported key commands.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
@ -63,7 +63,11 @@ typedef struct RichString_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
#define charBytes(n) (sizeof(CharType) * (n))
|
#ifndef CLAMP
|
||||||
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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) {
|
||||||
@ -103,6 +107,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
|
|||||||
|
|
||||||
inline void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
|
inline void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
|
||||||
cchar_t* ch = this->chptr + start;
|
cchar_t* ch = this->chptr + start;
|
||||||
|
finish = CLAMP(finish, 0, this->chlen - 1);
|
||||||
for (int i = start; i <= finish; i++) {
|
for (int i = start; i <= finish; i++) {
|
||||||
ch->attr = attrs;
|
ch->attr = attrs;
|
||||||
ch++;
|
ch++;
|
||||||
@ -132,6 +137,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
|
|||||||
|
|
||||||
void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
|
void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
|
||||||
chtype* ch = this->chptr + start;
|
chtype* ch = this->chptr + start;
|
||||||
|
finish = CLAMP(finish, 0, this->chlen - 1);
|
||||||
for (int i = start; i <= finish; i++) {
|
for (int i = start; i <= finish; i++) {
|
||||||
*ch = (*ch & 0xff) | attrs;
|
*ch = (*ch & 0xff) | attrs;
|
||||||
ch++;
|
ch++;
|
||||||
|
22
RichString.h
22
RichString.h
@ -59,7 +59,11 @@ typedef struct RichString_ {
|
|||||||
} RichString;
|
} RichString;
|
||||||
|
|
||||||
|
|
||||||
#define charBytes(n) (sizeof(CharType) * (n))
|
#ifndef CLAMP
|
||||||
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
||||||
@ -67,24 +71,24 @@ typedef struct RichString_ {
|
|||||||
|
|
||||||
extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
|
extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
|
||||||
|
|
||||||
int RichString_findChar(RichString* this, char c, int start);
|
extern int RichString_findChar(RichString* this, char c, int start);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
|
extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
|
||||||
|
|
||||||
int RichString_findChar(RichString* this, char c, int start);
|
extern int RichString_findChar(RichString* this, char c, int start);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void RichString_prune(RichString* this);
|
extern void RichString_prune(RichString* this);
|
||||||
|
|
||||||
void RichString_setAttr(RichString* this, int attrs);
|
extern void RichString_setAttr(RichString* this, int attrs);
|
||||||
|
|
||||||
void RichString_append(RichString* this, int attrs, const char* data);
|
extern void RichString_append(RichString* this, int attrs, const char* data);
|
||||||
|
|
||||||
void RichString_appendn(RichString* this, int attrs, const char* data, int len);
|
extern void RichString_appendn(RichString* this, int attrs, const char* data, int len);
|
||||||
|
|
||||||
void RichString_write(RichString* this, int attrs, const char* data);
|
extern void RichString_write(RichString* this, int attrs, const char* data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -145,14 +145,12 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
||||||
int nPanels = this->panelCount;
|
const int nPanels = this->panelCount;
|
||||||
for (int i = 0; i < nPanels; i++) {
|
for (int i = 0; i < nPanels; i++) {
|
||||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||||
Panel_draw(panel, i == focus);
|
Panel_draw(panel, i == focus);
|
||||||
if (i < nPanels) {
|
if (this->orientation == HORIZONTAL) {
|
||||||
if (this->orientation == HORIZONTAL) {
|
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1);
|
||||||
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,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;
|
||||||
@ -183,16 +181,33 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
int prevCh = ch;
|
int prevCh = ch;
|
||||||
|
set_escdelay(25);
|
||||||
ch = getch();
|
ch = getch();
|
||||||
|
|
||||||
|
if (this->settings->vimMode) {
|
||||||
|
switch (ch) {
|
||||||
|
case 'h': ch = KEY_LEFT; break;
|
||||||
|
case 'j': ch = KEY_DOWN; break;
|
||||||
|
case 'k': ch = KEY_UP; break;
|
||||||
|
case 'l': ch = KEY_RIGHT; break;
|
||||||
|
case KEY_LEFT: ch = 'h'; break;
|
||||||
|
case KEY_DOWN: ch = 'j'; break;
|
||||||
|
case KEY_UP: ch = 'k'; break;
|
||||||
|
case KEY_RIGHT: ch = 'l'; break;
|
||||||
|
case 'K': ch = 'k'; break;
|
||||||
|
case 'J': ch = 'K'; break;
|
||||||
|
case 'L': ch = 'l'; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HandlerResult result = IGNORED;
|
HandlerResult result = IGNORED;
|
||||||
if (ch == KEY_MOUSE) {
|
if (ch == KEY_MOUSE && this->settings->enableMouse) {
|
||||||
ch = ERR;
|
ch = ERR;
|
||||||
MEVENT mevent;
|
MEVENT mevent;
|
||||||
int ok = getmouse(&mevent);
|
int ok = getmouse(&mevent);
|
||||||
@ -244,28 +259,11 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||||||
redraw = false;
|
redraw = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (ch == 27) {
|
switch (ch) {
|
||||||
int ch2 = getch();
|
case KEY_ALT('H'): ch = KEY_LEFT; break;
|
||||||
if (ch2 != ERR) {
|
case KEY_ALT('J'): ch = KEY_DOWN; break;
|
||||||
switch(ch2)
|
case KEY_ALT('K'): ch = KEY_UP; break;
|
||||||
{
|
case KEY_ALT('L'): ch = KEY_RIGHT; break;
|
||||||
case 'h':
|
|
||||||
ch = KEY_LEFT;
|
|
||||||
break;
|
|
||||||
case 'j':
|
|
||||||
ch = KEY_DOWN;
|
|
||||||
break;
|
|
||||||
case 'k':
|
|
||||||
ch = KEY_UP;
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
ch = KEY_RIGHT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ungetch(ch2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
redraw = true;
|
redraw = true;
|
||||||
if (Panel_eventHandlerFn(panelFocus)) {
|
if (Panel_eventHandlerFn(panelFocus)) {
|
||||||
@ -287,7 +285,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:
|
||||||
{
|
{
|
||||||
@ -295,7 +293,10 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
case KEY_CTRLB:
|
case KEY_CTRL('B'):
|
||||||
|
if (this->panelCount < 2) {
|
||||||
|
goto defaultHandler;
|
||||||
|
}
|
||||||
if (!this->allowFocusChange)
|
if (!this->allowFocusChange)
|
||||||
break;
|
break;
|
||||||
tryLeft:
|
tryLeft:
|
||||||
@ -306,8 +307,11 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||||||
goto tryLeft;
|
goto tryLeft;
|
||||||
break;
|
break;
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
case KEY_CTRLF:
|
case KEY_CTRL('F'):
|
||||||
case 9:
|
case 9:
|
||||||
|
if (this->panelCount < 2) {
|
||||||
|
goto defaultHandler;
|
||||||
|
}
|
||||||
if (!this->allowFocusChange)
|
if (!this->allowFocusChange)
|
||||||
break;
|
break;
|
||||||
tryRight:
|
tryRight:
|
||||||
@ -323,6 +327,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||||||
quit = true;
|
quit = true;
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
|
defaultHandler:
|
||||||
sortTimeout = resetSortTimeout;
|
sortTimeout = resetSortTimeout;
|
||||||
Panel_onKey(panelFocus, ch);
|
Panel_onKey(panelFocus, ch);
|
||||||
break;
|
break;
|
||||||
|
@ -35,18 +35,18 @@ typedef struct ScreenManager_ {
|
|||||||
} ScreenManager;
|
} ScreenManager;
|
||||||
|
|
||||||
|
|
||||||
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner);
|
extern ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner);
|
||||||
|
|
||||||
void ScreenManager_delete(ScreenManager* this);
|
extern void ScreenManager_delete(ScreenManager* this);
|
||||||
|
|
||||||
extern int ScreenManager_size(ScreenManager* this);
|
extern int ScreenManager_size(ScreenManager* this);
|
||||||
|
|
||||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
extern void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
||||||
|
|
||||||
Panel* ScreenManager_remove(ScreenManager* this, int idx);
|
extern Panel* ScreenManager_remove(ScreenManager* this, int idx);
|
||||||
|
|
||||||
void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2);
|
extern void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2);
|
||||||
|
|
||||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey);
|
extern void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
124
Settings.c
124
Settings.c
@ -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;
|
||||||
@ -45,6 +45,8 @@ typedef struct Settings_ {
|
|||||||
|
|
||||||
bool countCPUsFromZero;
|
bool countCPUsFromZero;
|
||||||
bool detailedCPUTime;
|
bool detailedCPUTime;
|
||||||
|
bool showCPUUsage;
|
||||||
|
bool showCPUFrequency;
|
||||||
bool treeView;
|
bool treeView;
|
||||||
bool showProgramPath;
|
bool showProgramPath;
|
||||||
bool hideThreads;
|
bool hideThreads;
|
||||||
@ -58,6 +60,8 @@ typedef struct Settings_ {
|
|||||||
bool updateProcessNames;
|
bool updateProcessNames;
|
||||||
bool accountGuestInCPUMeter;
|
bool accountGuestInCPUMeter;
|
||||||
bool headerMargin;
|
bool headerMargin;
|
||||||
|
bool enableMouse;
|
||||||
|
bool vimMode;
|
||||||
|
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
} Settings;
|
||||||
@ -114,7 +118,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 +138,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");
|
||||||
@ -159,32 +163,36 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
|
|||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fields[j] = (ProcessField) NULL;
|
fields[j] = NULL_PROCESSFIELD;
|
||||||
String_freeArray(ids);
|
String_freeArray(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool Settings_read(Settings* this, const char* fileName) {
|
static bool Settings_read(Settings* this, const char* fileName) {
|
||||||
FILE* fd;
|
FILE* fd;
|
||||||
uid_t euid = geteuid();
|
|
||||||
|
|
||||||
seteuid(getuid());
|
CRT_dropPrivileges();
|
||||||
fd = fopen(fileName, "r");
|
fd = fopen(fileName, "r");
|
||||||
seteuid(euid);
|
CRT_restorePrivileges();
|
||||||
if (!fd)
|
if (!fd)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const int maxLine = 2048;
|
bool didReadMeters = false;
|
||||||
char buffer[maxLine];
|
bool didReadFields = false;
|
||||||
bool readMeters = false;
|
for (;;) {
|
||||||
while (fgets(buffer, maxLine, fd)) {
|
char* line = String_readLine(fd);
|
||||||
|
if (!line) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
int nOptions;
|
int nOptions;
|
||||||
char** option = String_split(buffer, '=', &nOptions);
|
char** option = String_split(line, '=', &nOptions);
|
||||||
|
free (line);
|
||||||
if (nOptions < 2) {
|
if (nOptions < 2) {
|
||||||
String_freeArray(option);
|
String_freeArray(option);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (String_eq(option[0], "fields")) {
|
if (String_eq(option[0], "fields")) {
|
||||||
readFields(this->fields, &(this->flags), option[1]);
|
readFields(this->fields, &(this->flags), option[1]);
|
||||||
|
didReadFields = true;
|
||||||
} else if (String_eq(option[0], "sort_key")) {
|
} else if (String_eq(option[0], "sort_key")) {
|
||||||
// This "+1" is for compatibility with the older enum format.
|
// This "+1" is for compatibility with the older enum format.
|
||||||
this->sortKey = atoi(option[1]) + 1;
|
this->sortKey = atoi(option[1]) + 1;
|
||||||
@ -219,6 +227,10 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
this->detailedCPUTime = atoi(option[1]);
|
this->detailedCPUTime = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "cpu_count_from_zero")) {
|
} else if (String_eq(option[0], "cpu_count_from_zero")) {
|
||||||
this->countCPUsFromZero = atoi(option[1]);
|
this->countCPUsFromZero = atoi(option[1]);
|
||||||
|
} else if (String_eq(option[0], "show_cpu_usage")) {
|
||||||
|
this->showCPUUsage = atoi(option[1]);
|
||||||
|
} else if (String_eq(option[0], "show_cpu_frequency")) {
|
||||||
|
this->showCPUFrequency = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "update_process_names")) {
|
} else if (String_eq(option[0], "update_process_names")) {
|
||||||
this->updateProcessNames = atoi(option[1]);
|
this->updateProcessNames = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "account_guest_in_cpu_meter")) {
|
} else if (String_eq(option[0], "account_guest_in_cpu_meter")) {
|
||||||
@ -228,58 +240,68 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
} else if (String_eq(option[0], "color_scheme")) {
|
} else if (String_eq(option[0], "color_scheme")) {
|
||||||
this->colorScheme = atoi(option[1]);
|
this->colorScheme = atoi(option[1]);
|
||||||
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
|
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
|
||||||
|
} else if (String_eq(option[0], "enable_mouse")) {
|
||||||
|
this->enableMouse = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "left_meters")) {
|
} else if (String_eq(option[0], "left_meters")) {
|
||||||
Settings_readMeters(this, option[1], 0);
|
Settings_readMeters(this, option[1], 0);
|
||||||
readMeters = true;
|
didReadMeters = true;
|
||||||
} else if (String_eq(option[0], "right_meters")) {
|
} else if (String_eq(option[0], "right_meters")) {
|
||||||
Settings_readMeters(this, option[1], 1);
|
Settings_readMeters(this, option[1], 1);
|
||||||
readMeters = true;
|
didReadMeters = true;
|
||||||
} else if (String_eq(option[0], "left_meter_modes")) {
|
} else if (String_eq(option[0], "left_meter_modes")) {
|
||||||
Settings_readMeterModes(this, option[1], 0);
|
Settings_readMeterModes(this, option[1], 0);
|
||||||
readMeters = true;
|
didReadMeters = true;
|
||||||
} else if (String_eq(option[0], "right_meter_modes")) {
|
} else if (String_eq(option[0], "right_meter_modes")) {
|
||||||
Settings_readMeterModes(this, option[1], 1);
|
Settings_readMeterModes(this, option[1], 1);
|
||||||
readMeters = true;
|
didReadMeters = true;
|
||||||
|
} else if (String_eq(option[0], "vim_mode")) {
|
||||||
|
this->vimMode = atoi(option[1]);
|
||||||
}
|
}
|
||||||
String_freeArray(option);
|
String_freeArray(option);
|
||||||
}
|
}
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
if (!readMeters) {
|
if (!didReadMeters) {
|
||||||
Settings_defaultMeters(this);
|
Settings_defaultMeters(this);
|
||||||
}
|
}
|
||||||
return true;
|
return didReadFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
|
static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
|
||||||
fprintf(fd, "%s=", name);
|
fprintf(fd, "%s=", name);
|
||||||
|
const char* sep = "";
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
// This "-1" is for compatibility with the older enum format.
|
// This "-1" is for compatibility with the older enum format.
|
||||||
fprintf(fd, "%d ", (int) fields[i]-1);
|
fprintf(fd, "%s%d", sep, (int) fields[i]-1);
|
||||||
|
sep = " ";
|
||||||
}
|
}
|
||||||
fprintf(fd, "\n");
|
fprintf(fd, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeMeters(Settings* this, FILE* fd, int column) {
|
static void writeMeters(Settings* this, FILE* fd, int column) {
|
||||||
|
const char* sep = "";
|
||||||
for (int i = 0; i < this->columns[column].len; i++) {
|
for (int i = 0; i < this->columns[column].len; i++) {
|
||||||
fprintf(fd, "%s ", this->columns[column].names[i]);
|
fprintf(fd, "%s%s", sep, this->columns[column].names[i]);
|
||||||
|
sep = " ";
|
||||||
}
|
}
|
||||||
fprintf(fd, "\n");
|
fprintf(fd, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeMeterModes(Settings* this, FILE* fd, int column) {
|
static void writeMeterModes(Settings* this, FILE* fd, int column) {
|
||||||
|
const char* sep = "";
|
||||||
for (int i = 0; i < this->columns[column].len; i++) {
|
for (int i = 0; i < this->columns[column].len; i++) {
|
||||||
fprintf(fd, "%d ", this->columns[column].modes[i]);
|
fprintf(fd, "%s%d", sep, this->columns[column].modes[i]);
|
||||||
|
sep = " ";
|
||||||
}
|
}
|
||||||
fprintf(fd, "\n");
|
fprintf(fd, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings_write(Settings* this) {
|
bool Settings_write(Settings* this) {
|
||||||
FILE* fd;
|
FILE* fd;
|
||||||
uid_t euid = geteuid();
|
|
||||||
|
|
||||||
seteuid(getuid());
|
CRT_dropPrivileges();
|
||||||
fd = fopen(this->filename, "w");
|
fd = fopen(this->filename, "w");
|
||||||
seteuid(euid);
|
CRT_restorePrivileges();
|
||||||
|
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -302,20 +324,24 @@ bool Settings_write(Settings* this) {
|
|||||||
fprintf(fd, "header_margin=%d\n", (int) this->headerMargin);
|
fprintf(fd, "header_margin=%d\n", (int) this->headerMargin);
|
||||||
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime);
|
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime);
|
||||||
fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->countCPUsFromZero);
|
fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->countCPUsFromZero);
|
||||||
|
fprintf(fd, "show_cpu_usage=%d\n", (int) this->showCPUUsage);
|
||||||
|
fprintf(fd, "show_cpu_frequency=%d\n", (int) this->showCPUFrequency);
|
||||||
fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames);
|
fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames);
|
||||||
fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->accountGuestInCPUMeter);
|
fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->accountGuestInCPUMeter);
|
||||||
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
|
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
|
||||||
|
fprintf(fd, "enable_mouse=%d\n", (int) this->enableMouse);
|
||||||
fprintf(fd, "delay=%d\n", (int) this->delay);
|
fprintf(fd, "delay=%d\n", (int) this->delay);
|
||||||
fprintf(fd, "left_meters="); writeMeters(this, fd, 0);
|
fprintf(fd, "left_meters="); writeMeters(this, fd, 0);
|
||||||
fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0);
|
fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0);
|
||||||
fprintf(fd, "right_meters="); writeMeters(this, fd, 1);
|
fprintf(fd, "right_meters="); writeMeters(this, fd, 1);
|
||||||
fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1);
|
fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1);
|
||||||
|
fprintf(fd, "vim_mode=%d\n", (int) this->vimMode);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -330,11 +356,13 @@ Settings* Settings_new(int cpuCount) {
|
|||||||
this->highlightMegabytes = false;
|
this->highlightMegabytes = false;
|
||||||
this->detailedCPUTime = false;
|
this->detailedCPUTime = false;
|
||||||
this->countCPUsFromZero = false;
|
this->countCPUsFromZero = false;
|
||||||
|
this->showCPUUsage = true;
|
||||||
|
this->showCPUFrequency = false;
|
||||||
this->updateProcessNames = false;
|
this->updateProcessNames = false;
|
||||||
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).
|
||||||
@ -365,47 +393,51 @@ 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");
|
||||||
uid_t euid = geteuid();
|
|
||||||
seteuid(getuid());
|
CRT_dropPrivileges();
|
||||||
(void) mkdir(configDir, 0700);
|
(void) mkdir(configDir, 0700);
|
||||||
(void) mkdir(htopDir, 0700);
|
(void) mkdir(htopDir, 0700);
|
||||||
free(htopDir);
|
free(htopDir);
|
||||||
free(configDir);
|
free(configDir);
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (lstat(legacyDotfile, &st) != 0) {
|
int err = lstat(legacyDotfile, &st);
|
||||||
st.st_mode = 0;
|
if (err || S_ISLNK(st.st_mode)) {
|
||||||
}
|
|
||||||
if (access(legacyDotfile, R_OK) != 0 || S_ISLNK(st.st_mode)) {
|
|
||||||
free(legacyDotfile);
|
free(legacyDotfile);
|
||||||
legacyDotfile = NULL;
|
legacyDotfile = NULL;
|
||||||
}
|
}
|
||||||
seteuid(euid);
|
CRT_restorePrivileges();
|
||||||
}
|
}
|
||||||
this->colorScheme = 0;
|
this->colorScheme = 0;
|
||||||
|
this->enableMouse = true;
|
||||||
this->changed = false;
|
this->changed = false;
|
||||||
this->delay = DEFAULT_DELAY;
|
this->delay = DEFAULT_DELAY;
|
||||||
bool ok = Settings_read(this, legacyDotfile ? legacyDotfile : this->filename);
|
bool ok = false;
|
||||||
if (ok) {
|
if (legacyDotfile) {
|
||||||
if (legacyDotfile) {
|
ok = Settings_read(this, legacyDotfile);
|
||||||
|
if (ok) {
|
||||||
// Transition to new location and delete old configuration file
|
// Transition to new location and delete old configuration file
|
||||||
if (Settings_write(this))
|
if (Settings_write(this))
|
||||||
unlink(legacyDotfile);
|
unlink(legacyDotfile);
|
||||||
}
|
}
|
||||||
} else {
|
free(legacyDotfile);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
ok = Settings_read(this, this->filename);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
this->changed = true;
|
this->changed = true;
|
||||||
// TODO: how to get SYSCONFDIR correctly through Autoconf?
|
// TODO: how to get SYSCONFDIR correctly through Autoconf?
|
||||||
char* systemSettings = String_cat(SYSCONFDIR, "/htoprc");
|
char* systemSettings = String_cat(SYSCONFDIR, "/htoprc");
|
||||||
ok = Settings_read(this, systemSettings);
|
ok = Settings_read(this, systemSettings);
|
||||||
free(systemSettings);
|
free(systemSettings);
|
||||||
if (!ok) {
|
|
||||||
Settings_defaultMeters(this);
|
|
||||||
this->hideKernelThreads = true;
|
|
||||||
this->highlightMegabytes = true;
|
|
||||||
this->highlightThreads = true;
|
|
||||||
this->headerMargin = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
free(legacyDotfile);
|
if (!ok) {
|
||||||
|
Settings_defaultMeters(this);
|
||||||
|
this->hideKernelThreads = true;
|
||||||
|
this->highlightMegabytes = true;
|
||||||
|
this->highlightThreads = true;
|
||||||
|
this->headerMargin = true;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
Settings.h
14
Settings.h
@ -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;
|
||||||
@ -36,6 +36,8 @@ typedef struct Settings_ {
|
|||||||
|
|
||||||
bool countCPUsFromZero;
|
bool countCPUsFromZero;
|
||||||
bool detailedCPUTime;
|
bool detailedCPUTime;
|
||||||
|
bool showCPUUsage;
|
||||||
|
bool showCPUFrequency;
|
||||||
bool treeView;
|
bool treeView;
|
||||||
bool showProgramPath;
|
bool showProgramPath;
|
||||||
bool hideThreads;
|
bool hideThreads;
|
||||||
@ -49,6 +51,8 @@ typedef struct Settings_ {
|
|||||||
bool updateProcessNames;
|
bool updateProcessNames;
|
||||||
bool accountGuestInCPUMeter;
|
bool accountGuestInCPUMeter;
|
||||||
bool headerMargin;
|
bool headerMargin;
|
||||||
|
bool enableMouse;
|
||||||
|
bool vimMode;
|
||||||
|
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
} Settings;
|
||||||
@ -58,12 +62,12 @@ typedef struct Settings_ {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void Settings_delete(Settings* this);
|
extern void Settings_delete(Settings* this);
|
||||||
|
|
||||||
bool Settings_write(Settings* this);
|
extern bool Settings_write(Settings* this);
|
||||||
|
|
||||||
Settings* Settings_new(int cpuCount);
|
extern Settings* Settings_new(int cpuCount);
|
||||||
|
|
||||||
void Settings_invertSortOrder(Settings* this);
|
extern void Settings_invertSortOrder(Settings* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,13 +31,27 @@ Panel* SignalsPanel_new() {
|
|||||||
Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Send ", "Cancel "));
|
Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Send ", "Cancel "));
|
||||||
const int defaultSignal = SIGTERM;
|
const int defaultSignal = SIGTERM;
|
||||||
int defaultPosition = 15;
|
int defaultPosition = 15;
|
||||||
for(unsigned int i = 0; i < Platform_numberOfSignals; i++) {
|
unsigned int i;
|
||||||
|
for (i = 0; i < Platform_numberOfSignals; i++) {
|
||||||
Panel_set(this, i, (Object*) ListItem_new(Platform_signals[i].name, Platform_signals[i].number));
|
Panel_set(this, i, (Object*) ListItem_new(Platform_signals[i].name, Platform_signals[i].number));
|
||||||
// signal 15 is not always the 15th signal in the table
|
// signal 15 is not always the 15th signal in the table
|
||||||
if (Platform_signals[i].number == defaultSignal) {
|
if (Platform_signals[i].number == defaultSignal) {
|
||||||
defaultPosition = i;
|
defaultPosition = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if (defined(SIGRTMIN) && defined(SIGRTMAX))
|
||||||
|
if (SIGRTMAX - SIGRTMIN <= 100) {
|
||||||
|
static char buf[16];
|
||||||
|
for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) {
|
||||||
|
int n = sig - SIGRTMIN;
|
||||||
|
xSnprintf(buf, 16, "%2d SIGRTMIN%-+3d", sig, n);
|
||||||
|
if (n == 0) {
|
||||||
|
buf[11] = '\0';
|
||||||
|
}
|
||||||
|
Panel_set(this, i, (Object*) ListItem_new(buf, sig));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Panel_setHeader(this, "Send signal:");
|
Panel_setHeader(this, "Send signal:");
|
||||||
Panel_setSelected(this, defaultPosition);
|
Panel_setSelected(this, defaultPosition);
|
||||||
return this;
|
return this;
|
||||||
|
@ -16,6 +16,6 @@ typedef struct SignalItem_ {
|
|||||||
} SignalItem;
|
} SignalItem;
|
||||||
|
|
||||||
|
|
||||||
Panel* SignalsPanel_new();
|
extern Panel* SignalsPanel_new();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,19 +13,26 @@ in the source distribution for its full text.
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0)
|
||||||
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* String_startsWith gives better performance if strlen(match) can be computed
|
||||||
|
* at compile time (e.g. when they are immutable string literals). :)
|
||||||
|
*/
|
||||||
|
|
||||||
char* String_cat(const char* s1, const char* s2) {
|
char* String_cat(const char* s1, const char* s2) {
|
||||||
int l1 = strlen(s1);
|
int l1 = strlen(s1);
|
||||||
int l2 = strlen(s2);
|
int l2 = strlen(s2);
|
||||||
char* out = xMalloc(l1 + l2 + 1);
|
char* out = xMalloc(l1 + l2 + 1);
|
||||||
strncpy(out, s1, l1);
|
memcpy(out, s1, l1);
|
||||||
strncpy(out+l1, s2, l2+1);
|
memcpy(out+l1, s2, l2+1);
|
||||||
|
out[l1 + l2] = '\0';
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,13 +76,7 @@ char** String_split(const char* s, char sep, int* n) {
|
|||||||
ctr++;
|
ctr++;
|
||||||
if (ctr == blocks) {
|
if (ctr == blocks) {
|
||||||
blocks += rate;
|
blocks += rate;
|
||||||
char** newOut = (char**) xRealloc(out, sizeof(char*) * blocks);
|
out = (char**) xRealloc(out, sizeof(char*) * blocks);
|
||||||
if (newOut) {
|
|
||||||
out = newOut;
|
|
||||||
} else {
|
|
||||||
blocks -= rate;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s += size + 1;
|
s += size + 1;
|
||||||
}
|
}
|
||||||
@ -86,16 +87,16 @@ char** String_split(const char* s, char sep, int* n) {
|
|||||||
out[ctr] = token;
|
out[ctr] = token;
|
||||||
ctr++;
|
ctr++;
|
||||||
}
|
}
|
||||||
char** newOut = xRealloc(out, sizeof(char*) * (ctr + 1));
|
out = xRealloc(out, sizeof(char*) * (ctr + 1));
|
||||||
if (newOut) {
|
|
||||||
out = newOut;
|
|
||||||
}
|
|
||||||
out[ctr] = NULL;
|
out[ctr] = NULL;
|
||||||
*n = ctr;
|
*n = ctr;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void String_freeArray(char** s) {
|
void String_freeArray(char** s) {
|
||||||
|
if (!s) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (int i = 0; s[i] != NULL; i++) {
|
for (int i = 0; s[i] != NULL; i++) {
|
||||||
free(s[i]);
|
free(s[i]);
|
||||||
}
|
}
|
||||||
@ -116,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];
|
||||||
@ -128,3 +129,29 @@ char* String_getToken(const char* line, const unsigned short int numMatch) {
|
|||||||
match[foundCount] = '\0';
|
match[foundCount] = '\0';
|
||||||
return((char*)xStrdup(match));
|
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,19 +9,28 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0)
|
||||||
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
||||||
|
|
||||||
char* String_cat(const char* s1, const char* s2);
|
/*
|
||||||
|
* String_startsWith gives better performance if strlen(match) can be computed
|
||||||
|
* at compile time (e.g. when they are immutable string literals). :)
|
||||||
|
*/
|
||||||
|
|
||||||
char* String_trim(const char* in);
|
extern char* String_cat(const char* s1, const char* s2);
|
||||||
|
|
||||||
|
extern char* String_trim(const char* in);
|
||||||
|
|
||||||
extern int String_eq(const char* s1, const char* s2);
|
extern int String_eq(const char* s1, const char* s2);
|
||||||
|
|
||||||
char** String_split(const char* s, char sep, int* n);
|
extern char** String_split(const char* s, char sep, int* n);
|
||||||
|
|
||||||
void String_freeArray(char** s);
|
extern void String_freeArray(char** s);
|
||||||
|
|
||||||
char* String_getToken(const char* line, const unsigned short int numMatch);
|
extern char* String_getToken(const char* line, const unsigned short int numMatch);
|
||||||
|
|
||||||
|
extern char* String_readLine(FILE* fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,7 +24,7 @@ int SwapMeter_attributes[] = {
|
|||||||
SWAP
|
SWAP
|
||||||
};
|
};
|
||||||
|
|
||||||
static void SwapMeter_setValues(Meter* this, char* buffer, int size) {
|
static void SwapMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
int written;
|
int written;
|
||||||
Platform_setSwapValues(this);
|
Platform_setSwapValues(this);
|
||||||
|
|
||||||
@ -54,8 +54,9 @@ MeterClass SwapMeter_class = {
|
|||||||
.delete = Meter_delete,
|
.delete = Meter_delete,
|
||||||
.display = SwapMeter_display,
|
.display = SwapMeter_display,
|
||||||
},
|
},
|
||||||
.setValues = SwapMeter_setValues,
|
.updateValues = SwapMeter_updateValues,
|
||||||
.defaultMode = BAR_METERMODE,
|
.defaultMode = BAR_METERMODE,
|
||||||
|
.maxItems = 1,
|
||||||
.total = 100.0,
|
.total = 100.0,
|
||||||
.attributes = SwapMeter_attributes,
|
.attributes = SwapMeter_attributes,
|
||||||
.name = "Swap",
|
.name = "Swap",
|
||||||
|
26
TasksMeter.c
26
TasksMeter.c
@ -15,32 +15,32 @@ in the source distribution for its full text.
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
int TasksMeter_attributes[] = {
|
int TasksMeter_attributes[] = {
|
||||||
CPU_KERNEL, PROCESS_THREAD, PROCESS, TASKS_RUNNING
|
CPU_SYSTEM, 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;
|
ProcessList* pl = this->pl;
|
||||||
this->values[0] = pl->kernelThreads;
|
this->values[0] = pl->kernelThreads;
|
||||||
this->values[1] = pl->userlandThreads;
|
this->values[1] = pl->userlandThreads;
|
||||||
this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads;
|
this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads;
|
||||||
this->values[3] = pl->runningTasks;
|
this->values[3] = MIN(pl->runningTasks, pl->cpuCount);
|
||||||
if (pl->totalTasks > this->total) {
|
if (pl->totalTasks > this->total) {
|
||||||
this->total = pl->totalTasks;
|
this->total = pl->totalTasks;
|
||||||
}
|
}
|
||||||
if (this->pl->settings->hideKernelThreads) {
|
if (this->pl->settings->hideKernelThreads) {
|
||||||
this->values[0] = 0;
|
this->values[0] = 0;
|
||||||
}
|
}
|
||||||
snprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);
|
xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TasksMeter_display(Object* cast, RichString* out) {
|
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];
|
||||||
|
|
||||||
sprintf(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];
|
||||||
int threadCaptionColor = CRT_colors[METER_TEXT];
|
int threadCaptionColor = CRT_colors[METER_TEXT];
|
||||||
@ -50,18 +50,18 @@ static void TasksMeter_display(Object* cast, RichString* out) {
|
|||||||
}
|
}
|
||||||
if (!settings->hideUserlandThreads) {
|
if (!settings->hideUserlandThreads) {
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
||||||
sprintf(buffer, "%d", (int)this->values[1]);
|
xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[1]);
|
||||||
RichString_append(out, threadValueColor, buffer);
|
RichString_append(out, threadValueColor, buffer);
|
||||||
RichString_append(out, threadCaptionColor, " thr");
|
RichString_append(out, threadCaptionColor, " thr");
|
||||||
}
|
}
|
||||||
if (!settings->hideKernelThreads) {
|
if (!settings->hideKernelThreads) {
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
||||||
sprintf(buffer, "%d", (int)this->values[0]);
|
xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[0]);
|
||||||
RichString_append(out, threadValueColor, buffer);
|
RichString_append(out, threadValueColor, buffer);
|
||||||
RichString_append(out, threadCaptionColor, " kthr");
|
RichString_append(out, threadCaptionColor, " kthr");
|
||||||
}
|
}
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "; ");
|
RichString_append(out, CRT_colors[METER_TEXT], "; ");
|
||||||
sprintf(buffer, "%d", (int)this->values[3]);
|
xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[3]);
|
||||||
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
|
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], " running");
|
RichString_append(out, CRT_colors[METER_TEXT], " running");
|
||||||
}
|
}
|
||||||
@ -72,11 +72,11 @@ MeterClass TasksMeter_class = {
|
|||||||
.delete = Meter_delete,
|
.delete = Meter_delete,
|
||||||
.display = TasksMeter_display,
|
.display = TasksMeter_display,
|
||||||
},
|
},
|
||||||
.setValues = TasksMeter_setValues,
|
.updateValues = TasksMeter_updateValues,
|
||||||
.defaultMode = TEXT_METERMODE,
|
.defaultMode = TEXT_METERMODE,
|
||||||
.total = 100.0,
|
|
||||||
.maxItems = 4,
|
.maxItems = 4,
|
||||||
.attributes = TasksMeter_attributes,
|
.total = 100.0,
|
||||||
|
.attributes = TasksMeter_attributes,
|
||||||
.name = "Tasks",
|
.name = "Tasks",
|
||||||
.uiName = "Task counter",
|
.uiName = "Task counter",
|
||||||
.caption = "Tasks: "
|
.caption = "Tasks: "
|
||||||
|
@ -22,6 +22,7 @@ in the source distribution for its full text.
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -42,9 +43,9 @@ typedef struct TraceScreen_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static const char* TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL};
|
static const char* const TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL};
|
||||||
|
|
||||||
static const char* TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"};
|
static const char* const TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"};
|
||||||
|
|
||||||
static int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
|
static int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
|
||||||
|
|
||||||
@ -90,24 +91,25 @@ void TraceScreen_draw(InfoScreen* this) {
|
|||||||
|
|
||||||
bool TraceScreen_forkTracer(TraceScreen* this) {
|
bool TraceScreen_forkTracer(TraceScreen* this) {
|
||||||
char buffer[1001];
|
char buffer[1001];
|
||||||
int err = pipe(this->fdpair);
|
int error = pipe(this->fdpair);
|
||||||
if (err == -1) return false;
|
if (error == -1) return false;
|
||||||
this->child = fork();
|
this->child = fork();
|
||||||
if (this->child == -1) return false;
|
if (this->child == -1) return false;
|
||||||
if (this->child == 0) {
|
if (this->child == 0) {
|
||||||
seteuid(getuid());
|
CRT_dropPrivileges();
|
||||||
dup2(this->fdpair[1], STDERR_FILENO);
|
dup2(this->fdpair[1], STDERR_FILENO);
|
||||||
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
||||||
if (ok != -1) {
|
if (ok != -1) {
|
||||||
sprintf(buffer, "%d", this->super.process->pid);
|
xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid);
|
||||||
execlp("strace", "strace", "-p", buffer, NULL);
|
execlp("strace", "strace", "-T", "-tt", "-s", "512", "-p", buffer, NULL);
|
||||||
}
|
}
|
||||||
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
|
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
|
||||||
ssize_t written = write(this->fdpair[1], message, strlen(message));
|
ssize_t written = write(this->fdpair[1], message, strlen(message));
|
||||||
(void) written;
|
(void) written;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK);
|
int ok = fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK);
|
||||||
|
if (ok == -1) return false;
|
||||||
this->strace = fdopen(this->fdpair[0], "r");
|
this->strace = fdopen(this->fdpair[0], "r");
|
||||||
this->fd_strace = fileno(this->strace);
|
this->fd_strace = fileno(this->strace);
|
||||||
return true;
|
return true;
|
||||||
|
@ -25,16 +25,16 @@ typedef struct TraceScreen_ {
|
|||||||
|
|
||||||
extern InfoScreenClass TraceScreen_class;
|
extern InfoScreenClass TraceScreen_class;
|
||||||
|
|
||||||
TraceScreen* TraceScreen_new(Process* process);
|
extern TraceScreen* TraceScreen_new(Process* process);
|
||||||
|
|
||||||
void TraceScreen_delete(Object* cast);
|
extern void TraceScreen_delete(Object* cast);
|
||||||
|
|
||||||
void TraceScreen_draw(InfoScreen* this);
|
extern void TraceScreen_draw(InfoScreen* this);
|
||||||
|
|
||||||
bool TraceScreen_forkTracer(TraceScreen* this);
|
extern bool TraceScreen_forkTracer(TraceScreen* this);
|
||||||
|
|
||||||
void TraceScreen_updateTrace(InfoScreen* super);
|
extern void TraceScreen_updateTrace(InfoScreen* super);
|
||||||
|
|
||||||
bool TraceScreen_onKey(InfoScreen* super, int ch);
|
extern bool TraceScreen_onKey(InfoScreen* super, int ch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,10 +17,10 @@ int UptimeMeter_attributes[] = {
|
|||||||
UPTIME
|
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();
|
int totalseconds = Platform_getUptime();
|
||||||
if (totalseconds == -1) {
|
if (totalseconds == -1) {
|
||||||
snprintf(buffer, len, "(unknown)");
|
xSnprintf(buffer, len, "(unknown)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int seconds = totalseconds % 60;
|
int seconds = totalseconds % 60;
|
||||||
@ -31,17 +31,17 @@ static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
|||||||
if (days > this->total) {
|
if (days > this->total) {
|
||||||
this->total = days;
|
this->total = days;
|
||||||
}
|
}
|
||||||
char daysbuf[15];
|
char daysbuf[32];
|
||||||
if (days > 100) {
|
if (days > 100) {
|
||||||
sprintf(daysbuf, "%d days(!), ", days);
|
xSnprintf(daysbuf, sizeof(daysbuf), "%d days(!), ", days);
|
||||||
} else if (days > 1) {
|
} else if (days > 1) {
|
||||||
sprintf(daysbuf, "%d days, ", days);
|
xSnprintf(daysbuf, sizeof(daysbuf), "%d days, ", days);
|
||||||
} else if (days == 1) {
|
} else if (days == 1) {
|
||||||
sprintf(daysbuf, "1 day, ");
|
xSnprintf(daysbuf, sizeof(daysbuf), "1 day, ");
|
||||||
} else {
|
} else {
|
||||||
daysbuf[0] = '\0';
|
daysbuf[0] = '\0';
|
||||||
}
|
}
|
||||||
snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
|
xSnprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
MeterClass UptimeMeter_class = {
|
MeterClass UptimeMeter_class = {
|
||||||
@ -49,8 +49,9 @@ MeterClass UptimeMeter_class = {
|
|||||||
.extends = Class(Meter),
|
.extends = Class(Meter),
|
||||||
.delete = Meter_delete
|
.delete = Meter_delete
|
||||||
},
|
},
|
||||||
.setValues = UptimeMeter_setValues,
|
.updateValues = UptimeMeter_updateValues,
|
||||||
.defaultMode = TEXT_METERMODE,
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 1,
|
||||||
.total = 100.0,
|
.total = 100.0,
|
||||||
.attributes = UptimeMeter_attributes,
|
.attributes = UptimeMeter_attributes,
|
||||||
.name = "Uptime",
|
.name = "Uptime",
|
||||||
|
@ -15,11 +15,11 @@ typedef struct UsersTable_ {
|
|||||||
Hashtable* users;
|
Hashtable* users;
|
||||||
} UsersTable;
|
} UsersTable;
|
||||||
|
|
||||||
UsersTable* UsersTable_new();
|
extern UsersTable* UsersTable_new();
|
||||||
|
|
||||||
void UsersTable_delete(UsersTable* this);
|
extern void UsersTable_delete(UsersTable* this);
|
||||||
|
|
||||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid);
|
extern char* UsersTable_getRef(UsersTable* this, unsigned int uid);
|
||||||
|
|
||||||
extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
|
extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
|
||||||
|
|
||||||
|
12
Vector.c
12
Vector.c
@ -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--) {
|
||||||
@ -284,17 +284,25 @@ inline Object* Vector_get(Vector* this, int idx) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
|
||||||
inline int Vector_size(Vector* this) {
|
inline int Vector_size(Vector* this) {
|
||||||
assert(Vector_isConsistent(this));
|
assert(Vector_isConsistent(this));
|
||||||
return this->items;
|
return this->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define Vector_size(v_) ((v_)->items)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
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;
|
||||||
|
34
Vector.h
34
Vector.h
@ -27,38 +27,38 @@ typedef struct Vector_ {
|
|||||||
} Vector;
|
} Vector;
|
||||||
|
|
||||||
|
|
||||||
Vector* Vector_new(ObjectClass* type, bool owner, int size);
|
extern Vector* Vector_new(ObjectClass* type, bool owner, int size);
|
||||||
|
|
||||||
void Vector_delete(Vector* this);
|
extern void Vector_delete(Vector* this);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
int Vector_count(Vector* this);
|
extern int Vector_count(Vector* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Vector_prune(Vector* this);
|
extern void Vector_prune(Vector* this);
|
||||||
|
|
||||||
// If I were to use only one sorting algorithm for both cases, it would probably be this one:
|
// If I were to use only one sorting algorithm for both cases, it would probably be this one:
|
||||||
/*
|
/*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Vector_quickSort(Vector* this);
|
extern void Vector_quickSort(Vector* this);
|
||||||
|
|
||||||
void Vector_insertionSort(Vector* this);
|
extern void Vector_insertionSort(Vector* this);
|
||||||
|
|
||||||
void Vector_insert(Vector* this, int idx, void* data_);
|
extern void Vector_insert(Vector* this, int idx, void* data_);
|
||||||
|
|
||||||
Object* Vector_take(Vector* this, int idx);
|
extern Object* Vector_take(Vector* this, int idx);
|
||||||
|
|
||||||
Object* Vector_remove(Vector* this, int idx);
|
extern Object* Vector_remove(Vector* this, int idx);
|
||||||
|
|
||||||
void Vector_moveUp(Vector* this, int idx);
|
extern void Vector_moveUp(Vector* this, int idx);
|
||||||
|
|
||||||
void Vector_moveDown(Vector* this, int idx);
|
extern void Vector_moveDown(Vector* this, int idx);
|
||||||
|
|
||||||
void Vector_set(Vector* this, int idx, void* data_);
|
extern void Vector_set(Vector* this, int idx, void* data_);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
@ -70,13 +70,21 @@ extern Object* Vector_get(Vector* this, int idx);
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
|
||||||
extern int Vector_size(Vector* this);
|
extern int Vector_size(Vector* this);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define Vector_size(v_) ((v_)->items)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Vector_add(Vector* this, void* data_);
|
extern void Vector_add(Vector* this, void* data_);
|
||||||
|
|
||||||
extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare);
|
extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare);
|
||||||
|
|
||||||
|
27
XAlloc.c
27
XAlloc.c
@ -5,11 +5,12 @@
|
|||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#endif
|
#endif
|
||||||
#include <err.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
|
#include <err.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ void* xMalloc(size_t size) {
|
|||||||
|
|
||||||
void* xCalloc(size_t nmemb, size_t size) {
|
void* xCalloc(size_t nmemb, size_t size) {
|
||||||
void* data = calloc(nmemb, size);
|
void* data = calloc(nmemb, size);
|
||||||
if (!data) {
|
if (!data && nmemb > 0 && size > 0) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
@ -43,9 +44,27 @@ void* xRealloc(void* ptr, size_t size) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* xStrdup(const char* str) {
|
#define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0)
|
||||||
|
|
||||||
|
#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);
|
char* data = strdup(str);
|
||||||
if (!data && str) {
|
if (!data) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
28
XAlloc.h
28
XAlloc.h
@ -7,14 +7,34 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void* xMalloc(size_t size);
|
extern void* xMalloc(size_t size);
|
||||||
|
|
||||||
void* xCalloc(size_t nmemb, size_t size);
|
extern void* xCalloc(size_t nmemb, size_t size);
|
||||||
|
|
||||||
void* xRealloc(void* ptr, size_t size);
|
extern void* xRealloc(void* ptr, size_t size);
|
||||||
|
|
||||||
char* xStrdup(const char* str);
|
#define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0)
|
||||||
|
|
||||||
|
#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)))
|
||||||
|
extern char* xStrdup_(const char* str) __attribute__((nonnull));
|
||||||
|
#endif // __has_attribute(nonnull) || GNU C 3.3 or later
|
||||||
|
|
||||||
|
extern char* xStrdup_(const char* str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
14
autogen.sh
14
autogen.sh
@ -1,15 +1,3 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
glibtoolize=$(which glibtoolize 2> /dev/null)
|
|
||||||
if [ ${#glibtoolize} -gt 0 ]
|
|
||||||
then libtoolize=glibtoolize
|
|
||||||
else libtoolize=libtoolize
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p m4
|
mkdir -p m4
|
||||||
aclocal -I m4
|
autoreconf --install --force
|
||||||
autoconf
|
|
||||||
autoheader
|
|
||||||
$libtoolize --copy --force
|
|
||||||
automake --add-missing --copy
|
|
||||||
|
|
||||||
|
171
configure.ac
171
configure.ac
@ -2,43 +2,47 @@
|
|||||||
# Process this file with autoconf to produce a configure script.
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
AC_PREREQ(2.65)
|
AC_PREREQ(2.65)
|
||||||
AC_INIT([htop],[2.0.0],[hisham@gobolinux.org])
|
AC_INIT([htop],[3.0.0],[htop@groups.io])
|
||||||
|
|
||||||
year=$(date +%Y)
|
AC_CONFIG_SRCDIR([htop.c])
|
||||||
|
AC_CONFIG_AUX_DIR([.])
|
||||||
|
AC_CONFIG_HEADERS([config.h])
|
||||||
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|
||||||
# The following two lines are required by hwloc scripts
|
# Required by hwloc scripts
|
||||||
AC_USE_SYSTEM_EXTENSIONS
|
|
||||||
AC_CANONICAL_TARGET
|
AC_CANONICAL_TARGET
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE([1.11])
|
AM_INIT_AUTOMAKE([1.11])
|
||||||
AC_CONFIG_SRCDIR([htop.c])
|
|
||||||
AC_CONFIG_HEADER([config.h])
|
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
|
||||||
|
|
||||||
# Checks for programs.
|
# Checks for programs.
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AM_PROG_CC_C_O
|
AM_PROG_CC_C_O
|
||||||
|
|
||||||
AC_DISABLE_SHARED
|
# Required by hwloc scripts
|
||||||
AC_ENABLE_STATIC
|
AC_USE_SYSTEM_EXTENSIONS
|
||||||
AC_PROG_LIBTOOL
|
|
||||||
|
|
||||||
# Checks for platform.
|
# Checks for platform.
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
case "$target" in
|
case "$target_os" in
|
||||||
*linux*)
|
linux*|gnu*)
|
||||||
my_htop_platform=linux
|
my_htop_platform=linux
|
||||||
;;
|
;;
|
||||||
*freebsd*)
|
freebsd*|kfreebsd*)
|
||||||
my_htop_platform=freebsd
|
my_htop_platform=freebsd
|
||||||
;;
|
;;
|
||||||
*openbsd*)
|
openbsd*)
|
||||||
my_htop_platform=openbsd
|
my_htop_platform=openbsd
|
||||||
;;
|
;;
|
||||||
*darwin*)
|
dragonfly*)
|
||||||
|
my_htop_platform=dragonflybsd
|
||||||
|
;;
|
||||||
|
darwin*)
|
||||||
my_htop_platform=darwin
|
my_htop_platform=darwin
|
||||||
;;
|
;;
|
||||||
|
solaris*)
|
||||||
|
my_htop_platform=solaris
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
my_htop_platform=unsupported
|
my_htop_platform=unsupported
|
||||||
;;
|
;;
|
||||||
@ -57,6 +61,16 @@ AC_CHECK_HEADERS([stdlib.h string.h strings.h sys/param.h sys/time.h unistd.h],[
|
|||||||
])
|
])
|
||||||
AC_CHECK_HEADERS([execinfo.h],[:],[:])
|
AC_CHECK_HEADERS([execinfo.h],[:],[:])
|
||||||
|
|
||||||
|
AC_HEADER_MAJOR
|
||||||
|
dnl glibc 2.25 deprecates 'major' and 'minor' in <sys/types.h> and requires to
|
||||||
|
dnl include <sys/sysmacros.h>. However the logic in AC_HEADER_MAJOR has not yet
|
||||||
|
dnl been updated in Autoconf 2.69, so use a workaround:
|
||||||
|
m4_version_prereq([2.70], [],
|
||||||
|
[if test "x$ac_cv_header_sys_mkdev_h" != xyes; then
|
||||||
|
AC_CHECK_HEADER(sys/sysmacros.h, [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
|
||||||
|
[Define to 1 if `major', `minor', and `makedev' are declared in <sys/sysmacros.h>.])])
|
||||||
|
fi])
|
||||||
|
|
||||||
# Checks for typedefs, structures, and compiler characteristics.
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
AC_HEADER_STDBOOL
|
AC_HEADER_STDBOOL
|
||||||
@ -74,15 +88,16 @@ AC_CHECK_FUNCS([memmove strncasecmp strstr strdup])
|
|||||||
save_cflags="${CFLAGS}"
|
save_cflags="${CFLAGS}"
|
||||||
CFLAGS="${CFLAGS} -std=c99"
|
CFLAGS="${CFLAGS} -std=c99"
|
||||||
AC_MSG_CHECKING([whether gcc -std=c99 option works])
|
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_COMPILE_IFELSE([AC_LANG_PROGRAM(
|
||||||
AC_MSG_RESULT([yes]),
|
[AC_INCLUDES_DEFAULT], [[char *a; a = strdup("foo"); int i = 0; i++; // C99]])],
|
||||||
AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.]))
|
[AC_MSG_RESULT([yes])],
|
||||||
|
[AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.])])
|
||||||
CFLAGS="$save_cflags"
|
CFLAGS="$save_cflags"
|
||||||
|
|
||||||
save_cflags="${CFLAGS}"
|
save_cflags="${CFLAGS}"
|
||||||
CFLAGS="$CFLAGS -Wextra"
|
CFLAGS="$CFLAGS -Wextra"
|
||||||
AC_MSG_CHECKING([if compiler supports -Wextra])
|
AC_MSG_CHECKING([if compiler supports -Wextra])
|
||||||
AC_TRY_COMPILE([], [], [
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],[
|
||||||
wextra_flag=-Wextra
|
wextra_flag=-Wextra
|
||||||
AC_MSG_RESULT([yes])
|
AC_MSG_RESULT([yes])
|
||||||
],[
|
],[
|
||||||
@ -96,14 +111,14 @@ AC_SUBST(wextra_flag)
|
|||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
PROCDIR=/proc
|
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
|
if test "x$enable_proc" = xyes; then
|
||||||
# An enabled proc assumes we're emulating Linux.
|
# An enabled proc assumes we're emulating Linux.
|
||||||
my_htop_platform=linux
|
my_htop_platform=linux
|
||||||
AC_DEFINE(HAVE_PROC, 1, [Define if using a Linux-compatible proc filesystem.])
|
AC_DEFINE(HAVE_PROC, 1, [Define if using a Linux-compatible proc filesystem.])
|
||||||
fi
|
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
|
if test -n "$withval"; then
|
||||||
AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem])
|
AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem])
|
||||||
@ -118,28 +133,28 @@ if test "x$cross_compiling" = xno; then
|
|||||||
fi
|
fi
|
||||||
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
|
if test "x$enable_openvz" = xyes; then
|
||||||
AC_DEFINE(HAVE_OPENVZ, 1, [Define if openvz support enabled.])
|
AC_DEFINE(HAVE_OPENVZ, 1, [Define if openvz support enabled.])
|
||||||
fi
|
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
|
if test "x$enable_cgroup" = xyes; then
|
||||||
AC_DEFINE(HAVE_CGROUP, 1, [Define if cgroup support enabled.])
|
AC_DEFINE(HAVE_CGROUP, 1, [Define if cgroup support enabled.])
|
||||||
fi
|
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
|
if test "x$enable_vserver" = xyes; then
|
||||||
AC_DEFINE(HAVE_VSERVER, 1, [Define if vserver support enabled.])
|
AC_DEFINE(HAVE_VSERVER, 1, [Define if vserver support enabled.])
|
||||||
fi
|
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
|
if test "x$enable_ancient_vserver" = xyes; then
|
||||||
AC_DEFINE(HAVE_VSERVER, 1, [Define if vserver support enabled.])
|
AC_DEFINE(HAVE_VSERVER, 1, [Define if vserver support enabled.])
|
||||||
AC_DEFINE(HAVE_ANCIENT_VSERVER, 1, [Define if ancient vserver support enabled.])
|
AC_DEFINE(HAVE_ANCIENT_VSERVER, 1, [Define if ancient vserver support enabled.])
|
||||||
fi
|
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
|
if test "x$enable_taskstats" = xyes; then
|
||||||
AC_DEFINE(HAVE_TASKSTATS, 1, [Define if taskstats support enabled.])
|
AC_DEFINE(HAVE_TASKSTATS, 1, [Define if taskstats support enabled.])
|
||||||
fi
|
fi
|
||||||
@ -147,17 +162,28 @@ fi
|
|||||||
# HTOP_CHECK_SCRIPT(LIBNAME, FUNCTION, DEFINE, CONFIG_SCRIPT, ELSE_PART)
|
# HTOP_CHECK_SCRIPT(LIBNAME, FUNCTION, DEFINE, CONFIG_SCRIPT, ELSE_PART)
|
||||||
m4_define([HTOP_CHECK_SCRIPT],
|
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_libs=$(m4_toupper($HTOP_[$1]_CONFIG_SCRIPT) --libs 2> /dev/null)
|
||||||
|
htop_config_script_cflags=$(m4_toupper($HTOP_[$1]_CONFIG_SCRIPT) --cflags 2> /dev/null)
|
||||||
|
else
|
||||||
|
htop_config_script_libs=$([$4] --libs 2> /dev/null)
|
||||||
|
htop_config_script_cflags=$([$4] --cflags 2> /dev/null)
|
||||||
|
fi
|
||||||
htop_script_success=no
|
htop_script_success=no
|
||||||
htop_save_LDFLAGS="$LDFLAGS"
|
htop_save_LDFLAGS="$LDFLAGS"
|
||||||
if test ! "x$htop_config_script" = x; then
|
htop_save_CFLAGS="$CFLAGS"
|
||||||
LDFLAGS="$htop_config_script $LDFLAGS"
|
if test ! "x$htop_config_script_libs" = x; then
|
||||||
|
LDFLAGS="$htop_config_script_libs $LDFLAGS"
|
||||||
|
CFLAGS="$htop_config_script_cflags $CFLAGS"
|
||||||
AC_CHECK_LIB([$1], [$2], [
|
AC_CHECK_LIB([$1], [$2], [
|
||||||
AC_DEFINE([$3], 1, [The library is present.])
|
AC_DEFINE([$3], 1, [The library is present.])
|
||||||
LIBS="$htop_config_script $LIBS "
|
LIBS="$htop_config_script_libs $LIBS "
|
||||||
htop_script_success=yes
|
htop_script_success=yes
|
||||||
], [])
|
], [
|
||||||
LDFLAGS="$save_LDFLAGS"
|
CFLAGS="$htop_save_CFLAGS"
|
||||||
|
])
|
||||||
|
LDFLAGS="$htop_save_LDFLAGS"
|
||||||
fi
|
fi
|
||||||
if test "x$htop_script_success" = xno; then
|
if test "x$htop_script_success" = xno; then
|
||||||
[$5]
|
[$5]
|
||||||
@ -173,17 +199,18 @@ m4_define([HTOP_CHECK_LIB],
|
|||||||
], [$4])
|
], [$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
|
if test "x$enable_unicode" = xyes; then
|
||||||
HTOP_CHECK_SCRIPT([ncursesw6], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw6-config",
|
HTOP_CHECK_SCRIPT([ncursesw6], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw6-config",
|
||||||
HTOP_CHECK_SCRIPT([ncursesw], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw5-config",
|
HTOP_CHECK_SCRIPT([ncursesw], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw6-config",
|
||||||
HTOP_CHECK_SCRIPT([ncurses], [addnwstr], [HAVE_LIBNCURSESW], "ncurses5-config",
|
HTOP_CHECK_SCRIPT([ncursesw], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw5-config",
|
||||||
HTOP_CHECK_LIB([ncursesw6], [addnwstr], [HAVE_LIBNCURSESW],
|
HTOP_CHECK_SCRIPT([ncurses], [addnwstr], [HAVE_LIBNCURSESW], "ncurses5-config",
|
||||||
HTOP_CHECK_LIB([ncursesw], [addnwstr], [HAVE_LIBNCURSESW],
|
HTOP_CHECK_LIB([ncursesw6], [addnwstr], [HAVE_LIBNCURSESW],
|
||||||
HTOP_CHECK_LIB([ncurses], [addnwstr], [HAVE_LIBNCURSESW],
|
HTOP_CHECK_LIB([ncursesw], [addnwstr], [HAVE_LIBNCURSESW],
|
||||||
missing_libraries="$missing_libraries libncursesw"
|
HTOP_CHECK_LIB([ncurses], [addnwstr], [HAVE_LIBNCURSESW],
|
||||||
AC_MSG_ERROR([You may want to use --disable-unicode or install libncursesw.])
|
missing_libraries="$missing_libraries libncursesw"
|
||||||
))))))
|
AC_MSG_ERROR([You may want to use --disable-unicode or install libncursesw.])
|
||||||
|
)))))))
|
||||||
|
|
||||||
AC_CHECK_HEADERS([ncursesw/curses.h],[:],
|
AC_CHECK_HEADERS([ncursesw/curses.h],[:],
|
||||||
[AC_CHECK_HEADERS([ncurses/ncurses.h],[:],
|
[AC_CHECK_HEADERS([ncurses/ncurses.h],[:],
|
||||||
@ -211,8 +238,14 @@ if test "$my_htop_platform" = "openbsd"; then
|
|||||||
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_ARG_ENABLE(native_affinity, [AC_HELP_STRING([--enable-native-affinity], [enable native sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_native_affinity="yes")
|
if test "$my_htop_platform" = "solaris"; then
|
||||||
if test "x$enable_native_affinity" = xyes -a "x$cross_compiling" = xno; then
|
AC_CHECK_LIB([kstat], [kstat_open], [], [missing_libraries="$missing_libraries libkstat"])
|
||||||
|
AC_CHECK_LIB([proc], [Pgrab_error], [], [missing_libraries="$missing_libraries libproc"])
|
||||||
|
AC_CHECK_LIB([malloc], [free], [], [missing_libraries="$missing_libraries libmalloc"])
|
||||||
|
fi
|
||||||
|
|
||||||
|
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_MSG_CHECKING([for usable sched_setaffinity])
|
||||||
AC_RUN_IFELSE([
|
AC_RUN_IFELSE([
|
||||||
AC_LANG_PROGRAM([[
|
AC_LANG_PROGRAM([[
|
||||||
@ -225,20 +258,44 @@ if test "x$enable_native_affinity" = xyes -a "x$cross_compiling" = xno; then
|
|||||||
if (errno == ENOSYS) return 1;
|
if (errno == ENOSYS) return 1;
|
||||||
]])],
|
]])],
|
||||||
[AC_MSG_RESULT([yes])],
|
[AC_MSG_RESULT([yes])],
|
||||||
[enable_native_affinity=no
|
[enable_linux_affinity=no
|
||||||
AC_MSG_RESULT([no])])
|
AC_MSG_RESULT([no])])
|
||||||
fi
|
fi
|
||||||
if test "x$enable_native_affinity" = xyes; then
|
if test "x$enable_linux_affinity" = xyes; then
|
||||||
AC_DEFINE(HAVE_NATIVE_AFFINITY, 1, [Define if native sched_setaffinity and sched_getaffinity are to be used.])
|
AC_DEFINE(HAVE_LINUX_AFFINITY, 1, [Define if Linux sched_setaffinity and sched_getaffinity are to be used.])
|
||||||
fi
|
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
|
if test "x$enable_hwloc" = xyes
|
||||||
then
|
then
|
||||||
AC_CHECK_LIB([hwloc], [hwloc_linux_get_tid_cpubind], [], [missing_libraries="$missing_libraries libhwloc"])
|
AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [missing_libraries="$missing_libraries libhwloc"])
|
||||||
AC_CHECK_HEADERS([hwloc.h],[:], [missing_headers="$missing_headers $ac_header"])
|
AC_CHECK_HEADERS([hwloc.h],[:], [missing_headers="$missing_headers $ac_header"])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_ARG_ENABLE(setuid, [AS_HELP_STRING([--enable-setuid], [enable setuid support for platforms that need it])],, enable_setuid="no")
|
||||||
|
if test "x$enable_setuid" = xyes
|
||||||
|
then
|
||||||
|
AC_DEFINE(HAVE_SETUID_ENABLED, 1, [Define if setuid support should be enabled.])
|
||||||
|
fi
|
||||||
|
|
||||||
|
AC_ARG_ENABLE(delayacct, [AS_HELP_STRING([--enable-delayacct], [enable Linux delay accounting])],, enable_delayacct="no")
|
||||||
|
if test "x$enable_delayacct" = xyes
|
||||||
|
then
|
||||||
|
m4_ifdef([PKG_PROG_PKG_CONFIG], [
|
||||||
|
PKG_PROG_PKG_CONFIG()
|
||||||
|
PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [missing_libraries="$missing_libraries libnl-3"])
|
||||||
|
PKG_CHECK_MODULES(LIBNL3GENL, libnl-genl-3.0, [], [missing_libraries="$missing_libraries libnl-genl-3"])
|
||||||
|
CFLAGS="$CFLAGS $LIBNL3_CFLAGS $LIBNL3GENL_CFLAGS"
|
||||||
|
LIBS="$LIBS $LIBNL3_LIBS $LIBNL3GENL_LIBS"
|
||||||
|
AC_DEFINE(HAVE_DELAYACCT, 1, [Define if delay accounting support should be enabled.])
|
||||||
|
], [
|
||||||
|
pkg_m4_absent=1
|
||||||
|
m4_warning([configure is generated without pkg.m4. 'make dist' target will be disabled.])
|
||||||
|
AC_MSG_ERROR([htop on Linux requires pkg-config for checking delayacct requirements. Please install pkg-config and run ./autogen.sh to rebuild the configure script.])
|
||||||
|
])
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Bail out on errors.
|
# Bail out on errors.
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
if test ! -z "$missing_libraries"; then
|
if test ! -z "$missing_libraries"; then
|
||||||
@ -248,15 +305,31 @@ if test ! -z "$missing_headers"; then
|
|||||||
AC_MSG_ERROR([missing headers: $missing_headers])
|
AC_MSG_ERROR([missing headers: $missing_headers])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-$year Hisham Muhammad", [Copyright message.])
|
AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-2018 Hisham Muhammad", [Copyright message.])
|
||||||
|
|
||||||
# We're done, let's go!
|
# We're done, let's go!
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
|
AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
|
||||||
AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
|
AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
|
||||||
|
AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
|
||||||
AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
|
AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
|
||||||
AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
|
AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
|
||||||
|
AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris])
|
||||||
AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
|
AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
|
||||||
AC_SUBST(my_htop_platform)
|
AC_SUBST(my_htop_platform)
|
||||||
AC_CONFIG_FILES([Makefile htop.1])
|
AC_CONFIG_FILES([Makefile htop.1])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
||||||
|
if test "$my_htop_platform" = "unsupported"
|
||||||
|
then
|
||||||
|
echo ""
|
||||||
|
echo "****************************************************************"
|
||||||
|
echo "WARNING! This platform is not currently supported by htop."
|
||||||
|
echo ""
|
||||||
|
echo "The code will build, but it will produce a dummy version of htop"
|
||||||
|
echo "which shows no processes, using the files from the unsupported/"
|
||||||
|
echo "directory. This is meant to be a skeleton, to be used as a"
|
||||||
|
echo "starting point if you are porting htop to a new platform."
|
||||||
|
echo "****************************************************************"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
@ -13,6 +13,8 @@ in the source distribution for its full text.
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <mach/mach.h>
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "DarwinProcessList.h"
|
#include "DarwinProcessList.h"
|
||||||
@ -24,6 +26,7 @@ typedef struct DarwinProcess_ {
|
|||||||
|
|
||||||
uint64_t utime;
|
uint64_t utime;
|
||||||
uint64_t stime;
|
uint64_t stime;
|
||||||
|
bool taskAccess;
|
||||||
} DarwinProcess;
|
} DarwinProcess;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
@ -45,6 +48,7 @@ DarwinProcess* DarwinProcess_new(Settings* settings) {
|
|||||||
|
|
||||||
this->utime = 0;
|
this->utime = 0;
|
||||||
this->stime = 0;
|
this->stime = 0;
|
||||||
|
this->taskAccess = true;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -69,7 +73,7 @@ void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t no
|
|||||||
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > now - 86400) ? "%R " : "%b%d "), &date);
|
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > now - 86400) ? "%R " : "%b%d "), &date);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
|
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
|
||||||
/* This function is from the old Mac version of htop. Originally from ps? */
|
/* This function is from the old Mac version of htop. Originally from ps? */
|
||||||
int mib[3], argmax, nargs, c = 0;
|
int mib[3], argmax, nargs, c = 0;
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -167,13 +171,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
|
|||||||
/* Save where the argv[0] string starts. */
|
/* Save where the argv[0] string starts. */
|
||||||
sp = cp;
|
sp = cp;
|
||||||
|
|
||||||
/*
|
*basenameOffset = 0;
|
||||||
* Iterate through the '\0'-terminated strings and convert '\0' to ' '
|
|
||||||
* until a string is found that has a '=' character in it (or there are
|
|
||||||
* no more strings in procargs). There is no way to deterministically
|
|
||||||
* know where the command arguments end and the environment strings
|
|
||||||
* start, which is why the '=' character is searched for as a heuristic.
|
|
||||||
*/
|
|
||||||
for ( np = NULL; c < nargs && cp < &procargs[size]; cp++ ) {
|
for ( np = NULL; c < nargs && cp < &procargs[size]; cp++ ) {
|
||||||
if ( *cp == '\0' ) {
|
if ( *cp == '\0' ) {
|
||||||
c++;
|
c++;
|
||||||
@ -183,49 +181,11 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
|
|||||||
}
|
}
|
||||||
/* Note location of current '\0'. */
|
/* Note location of current '\0'. */
|
||||||
np = cp;
|
np = cp;
|
||||||
|
if (*basenameOffset == 0) {
|
||||||
if ( !show_args ) {
|
*basenameOffset = cp - sp;
|
||||||
/*
|
|
||||||
* Don't convert '\0' characters to ' '.
|
|
||||||
* However, we needed to know that the
|
|
||||||
* command name was terminated, which we
|
|
||||||
* now know.
|
|
||||||
*/
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* If eflg is non-zero, continue converting '\0' characters to ' '
|
|
||||||
* characters until no more strings that look like environment settings
|
|
||||||
* follow.
|
|
||||||
*/
|
|
||||||
if ( ( eflg != 0 )
|
|
||||||
&& ( ( getuid( ) == 0 )
|
|
||||||
|| ( k->kp_eproc.e_pcred.p_ruid == getuid( ) ) ) ) {
|
|
||||||
for ( ; cp < &procargs[size]; cp++ ) {
|
|
||||||
if ( *cp == '\0' ) {
|
|
||||||
if ( np != NULL ) {
|
|
||||||
if ( &np[1] == cp ) {
|
|
||||||
/*
|
|
||||||
* Two '\0' characters in a row.
|
|
||||||
* This should normally only
|
|
||||||
* happen after all the strings
|
|
||||||
* have been seen, but in any
|
|
||||||
* case, stop parsing.
|
|
||||||
*/
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* Convert previous '\0'. */
|
|
||||||
*np = ' ';
|
|
||||||
}
|
|
||||||
/* Note location of current '\0'. */
|
|
||||||
np = cp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sp points to the beginning of the arguments/environment string, and
|
* sp points to the beginning of the arguments/environment string, and
|
||||||
@ -235,6 +195,9 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
|
|||||||
/* Empty or unterminated string. */
|
/* Empty or unterminated string. */
|
||||||
goto ERROR_B;
|
goto ERROR_B;
|
||||||
}
|
}
|
||||||
|
if (*basenameOffset == 0) {
|
||||||
|
*basenameOffset = np - sp;
|
||||||
|
}
|
||||||
|
|
||||||
/* Make a copy of the string. */
|
/* Make a copy of the string. */
|
||||||
retval = xStrdup(sp);
|
retval = xStrdup(sp);
|
||||||
@ -248,6 +211,7 @@ ERROR_B:
|
|||||||
free( procargs );
|
free( procargs );
|
||||||
ERROR_A:
|
ERROR_A:
|
||||||
retval = xStrdup(k->kp_proc.p_comm);
|
retval = xStrdup(k->kp_proc.p_comm);
|
||||||
|
*basenameOffset = strlen(retval);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -275,35 +239,22 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t
|
|||||||
proc->ppid = ps->kp_eproc.e_ppid;
|
proc->ppid = ps->kp_eproc.e_ppid;
|
||||||
proc->pgrp = ps->kp_eproc.e_pgid;
|
proc->pgrp = ps->kp_eproc.e_pgid;
|
||||||
proc->session = 0; /* TODO Get the session id */
|
proc->session = 0; /* TODO Get the session id */
|
||||||
proc->tgid = ps->kp_eproc.e_tpgid;
|
proc->tpgid = ps->kp_eproc.e_tpgid;
|
||||||
|
proc->tgid = proc->pid;
|
||||||
proc->st_uid = ps->kp_eproc.e_ucred.cr_uid;
|
proc->st_uid = ps->kp_eproc.e_ucred.cr_uid;
|
||||||
/* e_tdev = (major << 24) | (minor & 0xffffff) */
|
/* e_tdev = (major << 24) | (minor & 0xffffff) */
|
||||||
/* e_tdev == -1 for "no device" */
|
/* e_tdev == -1 for "no device" */
|
||||||
proc->tty_nr = ps->kp_eproc.e_tdev & 0xff; /* TODO tty_nr is unsigned */
|
proc->tty_nr = ps->kp_eproc.e_tdev & 0xff; /* TODO tty_nr is unsigned */
|
||||||
|
|
||||||
DarwinProcess_setStartTime(proc, ep, now);
|
DarwinProcess_setStartTime(proc, ep, now);
|
||||||
|
proc->comm = DarwinProcess_getCmdLine(ps, &(proc->basenameOffset));
|
||||||
/* The command is from the old Mac htop */
|
|
||||||
char *slash;
|
|
||||||
|
|
||||||
proc->comm = DarwinProcess_getCmdLine(ps, false);
|
|
||||||
slash = strrchr(proc->comm, '/');
|
|
||||||
proc->basenameOffset = (NULL != slash) ? (slash - proc->comm) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mutable information */
|
/* Mutable information */
|
||||||
proc->nice = ep->p_nice;
|
proc->nice = ep->p_nice;
|
||||||
proc->priority = ep->p_priority;
|
proc->priority = ep->p_priority;
|
||||||
|
|
||||||
/* Set the state */
|
proc->state = (ep->p_stat == SZOMB) ? 'Z' : '?';
|
||||||
switch(ep->p_stat) {
|
|
||||||
case SIDL: proc->state = 'I'; break;
|
|
||||||
case SRUN: proc->state = 'R'; break;
|
|
||||||
case SSLEEP: proc->state = 'S'; break;
|
|
||||||
case SSTOP: proc->state = 'T'; break;
|
|
||||||
case SZOMB: proc->state = 'Z'; break;
|
|
||||||
default: proc->state = '?'; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure the updated flag is set */
|
/* Make sure the updated flag is set */
|
||||||
proc->updated = true;
|
proc->updated = true;
|
||||||
@ -327,8 +278,8 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
|
|||||||
|
|
||||||
proc->super.time = (pti.pti_total_system + pti.pti_total_user) / 10000000;
|
proc->super.time = (pti.pti_total_system + pti.pti_total_user) / 10000000;
|
||||||
proc->super.nlwp = pti.pti_threadnum;
|
proc->super.nlwp = pti.pti_threadnum;
|
||||||
proc->super.m_size = pti.pti_virtual_size / 1024;
|
proc->super.m_size = pti.pti_virtual_size / 1024 / PAGE_SIZE_KB;
|
||||||
proc->super.m_resident = pti.pti_resident_size / 1024;
|
proc->super.m_resident = pti.pti_resident_size / 1024 / PAGE_SIZE_KB;
|
||||||
proc->super.majflt = pti.pti_faults;
|
proc->super.majflt = pti.pti_faults;
|
||||||
proc->super.percent_mem = (double)pti.pti_resident_size * 100.0
|
proc->super.percent_mem = (double)pti.pti_resident_size * 100.0
|
||||||
/ (double)dpl->host_info.max_mem;
|
/ (double)dpl->host_info.max_mem;
|
||||||
@ -342,3 +293,71 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
|
|||||||
dpl->super.runningTasks += pti.pti_numrunning;
|
dpl->super.runningTasks += pti.pti_numrunning;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Scan threads for process state information.
|
||||||
|
* Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread
|
||||||
|
* and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c
|
||||||
|
*/
|
||||||
|
void DarwinProcess_scanThreads(DarwinProcess *dp) {
|
||||||
|
Process* proc = (Process*) dp;
|
||||||
|
kern_return_t ret;
|
||||||
|
|
||||||
|
if (!dp->taskAccess) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proc->state == 'Z') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
task_t port;
|
||||||
|
ret = task_for_pid(mach_task_self(), proc->pid, &port);
|
||||||
|
if (ret != KERN_SUCCESS) {
|
||||||
|
dp->taskAccess = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
task_info_data_t tinfo;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_array_t thread_list;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
integer_t run_state = 999;
|
||||||
|
for (unsigned int i = 0; i < thread_count; i++) {
|
||||||
|
thread_info_data_t thinfo;
|
||||||
|
mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT;
|
||||||
|
ret = thread_info(thread_list[i], THREAD_BASIC_INFO, (thread_info_t)thinfo, &thread_info_count);
|
||||||
|
if (ret == KERN_SUCCESS) {
|
||||||
|
thread_basic_info_t basic_info_th = (thread_basic_info_t) thinfo;
|
||||||
|
if (basic_info_th->run_state < run_state) {
|
||||||
|
run_state = basic_info_th->run_state;
|
||||||
|
}
|
||||||
|
mach_port_deallocate(mach_task_self(), thread_list[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vm_deallocate(mach_task_self(), (vm_address_t) thread_list, sizeof(thread_port_array_t) * thread_count);
|
||||||
|
mach_port_deallocate(mach_task_self(), port);
|
||||||
|
|
||||||
|
char state = '?';
|
||||||
|
switch (run_state) {
|
||||||
|
case TH_STATE_RUNNING: state = 'R'; break;
|
||||||
|
case TH_STATE_STOPPED: state = 'S'; break;
|
||||||
|
case TH_STATE_WAITING: state = 'W'; break;
|
||||||
|
case TH_STATE_UNINTERRUPTIBLE: state = 'U'; break;
|
||||||
|
case TH_STATE_HALTED: state = 'H'; break;
|
||||||
|
}
|
||||||
|
proc->state = state;
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ typedef struct DarwinProcess_ {
|
|||||||
|
|
||||||
uint64_t utime;
|
uint64_t utime;
|
||||||
uint64_t stime;
|
uint64_t stime;
|
||||||
|
bool taskAccess;
|
||||||
} DarwinProcess;
|
} DarwinProcess;
|
||||||
|
|
||||||
|
|
||||||
@ -32,10 +33,17 @@ bool Process_isThread(Process* this);
|
|||||||
|
|
||||||
void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now);
|
void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now);
|
||||||
|
|
||||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args );
|
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset);
|
||||||
|
|
||||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists);
|
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists);
|
||||||
|
|
||||||
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl);
|
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Scan threads for process state information.
|
||||||
|
* Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread
|
||||||
|
* and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c
|
||||||
|
*/
|
||||||
|
void DarwinProcess_scanThreads(DarwinProcess *dp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,6 +9,8 @@ in the source distribution for its full text.
|
|||||||
#include "DarwinProcess.h"
|
#include "DarwinProcess.h"
|
||||||
#include "DarwinProcessList.h"
|
#include "DarwinProcessList.h"
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
|
#include "zfs/openzfs_sysctl.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -18,9 +20,43 @@ in the source distribution for its full text.
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <utmpx.h>
|
#include <utmpx.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
struct kern {
|
||||||
|
short int version[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
void GetKernelVersion(struct kern *k) {
|
||||||
|
static short int version_[3] = {0};
|
||||||
|
if (!version_[0]) {
|
||||||
|
// just in case it fails someday
|
||||||
|
version_[0] = version_[1] = version_[2] = -1;
|
||||||
|
char str[256] = {0};
|
||||||
|
size_t size = sizeof(str);
|
||||||
|
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
|
||||||
|
if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
|
||||||
|
}
|
||||||
|
memcpy(k->version, version_, sizeof(version_));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* compare the given os version with the one installed returns:
|
||||||
|
0 if equals the installed version
|
||||||
|
positive value if less than the installed version
|
||||||
|
negative value if more than the installed version
|
||||||
|
*/
|
||||||
|
int CompareKernelVersion(short int major, short int minor, short int component) {
|
||||||
|
struct kern k;
|
||||||
|
GetKernelVersion(&k);
|
||||||
|
if ( k.version[0] != major) return k.version[0] - major;
|
||||||
|
if ( k.version[1] != minor) return k.version[1] - minor;
|
||||||
|
if ( k.version[2] != component) return k.version[2] - component;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
#include <mach/mach_host.h>
|
#include <mach/mach_host.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
@ -34,6 +70,8 @@ typedef struct DarwinProcessList_ {
|
|||||||
uint64_t kernel_threads;
|
uint64_t kernel_threads;
|
||||||
uint64_t user_threads;
|
uint64_t user_threads;
|
||||||
uint64_t global_diff;
|
uint64_t global_diff;
|
||||||
|
|
||||||
|
ZfsArcStats zfs;
|
||||||
} DarwinProcessList;
|
} DarwinProcessList;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
@ -51,9 +89,8 @@ void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
|
|||||||
if(0 != munmap(*p, vm_page_size)) {
|
if(0 != munmap(*p, vm_page_size)) {
|
||||||
CRT_fatalError("Unable to free old CPU load information\n");
|
CRT_fatalError("Unable to free old CPU load information\n");
|
||||||
}
|
}
|
||||||
|
*p = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*p = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||||
@ -99,8 +136,8 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
|||||||
return processes;
|
return processes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||||
|
size_t len;
|
||||||
DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList));
|
DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList));
|
||||||
|
|
||||||
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
|
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
|
||||||
@ -113,6 +150,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
|||||||
/* Initialize the VM statistics */
|
/* Initialize the VM statistics */
|
||||||
ProcessList_getVMStats(&this->vm_stats);
|
ProcessList_getVMStats(&this->vm_stats);
|
||||||
|
|
||||||
|
/* Initialize the ZFS kstats, if zfs.kext loaded */
|
||||||
|
openzfs_sysctl_init(&this->zfs);
|
||||||
|
openzfs_sysctl_updateArcStats(&this->zfs);
|
||||||
|
|
||||||
this->super.kernelThreads = 0;
|
this->super.kernelThreads = 0;
|
||||||
this->super.userlandThreads = 0;
|
this->super.userlandThreads = 0;
|
||||||
this->super.totalTasks = 0;
|
this->super.totalTasks = 0;
|
||||||
@ -141,6 +182,7 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
|||||||
dpl->prev_load = dpl->curr_load;
|
dpl->prev_load = dpl->curr_load;
|
||||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||||
ProcessList_getVMStats(&dpl->vm_stats);
|
ProcessList_getVMStats(&dpl->vm_stats);
|
||||||
|
openzfs_sysctl_updateArcStats(&dpl->zfs);
|
||||||
|
|
||||||
/* Get the time difference */
|
/* Get the time difference */
|
||||||
dpl->global_diff = 0;
|
dpl->global_diff = 0;
|
||||||
@ -168,9 +210,16 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
|||||||
for(size_t i = 0; i < count; ++i) {
|
for(size_t i = 0; i < count; ++i) {
|
||||||
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
||||||
|
|
||||||
DarwinProcess_setFromKInfoProc(&proc->super, ps + i, tv.tv_sec, preExisting);
|
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
||||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||||
|
|
||||||
|
// Disabled for High Sierra due to bug in macOS High Sierra
|
||||||
|
bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0);
|
||||||
|
|
||||||
|
if (isScanThreadSupported){
|
||||||
|
DarwinProcess_scanThreads(proc);
|
||||||
|
}
|
||||||
|
|
||||||
super->totalTasks += 1;
|
super->totalTasks += 1;
|
||||||
|
|
||||||
if(!preExisting) {
|
if(!preExisting) {
|
||||||
|
@ -9,7 +9,19 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
struct kern;
|
||||||
|
|
||||||
|
void GetKernelVersion(struct kern *k);
|
||||||
|
|
||||||
|
/* compare the given os version with the one installed returns:
|
||||||
|
0 if equals the installed version
|
||||||
|
positive value if less than the installed version
|
||||||
|
negative value if more than the installed version
|
||||||
|
*/
|
||||||
|
int CompareKernelVersion(short int major, short int minor, short int component);
|
||||||
|
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
#include <mach/mach_host.h>
|
#include <mach/mach_host.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
@ -23,6 +35,8 @@ typedef struct DarwinProcessList_ {
|
|||||||
uint64_t kernel_threads;
|
uint64_t kernel_threads;
|
||||||
uint64_t user_threads;
|
uint64_t user_threads;
|
||||||
uint64_t global_diff;
|
uint64_t global_diff;
|
||||||
|
|
||||||
|
ZfsArcStats zfs;
|
||||||
} DarwinProcessList;
|
} DarwinProcessList;
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ in the source distribution for its full text.
|
|||||||
#include "ClockMeter.h"
|
#include "ClockMeter.h"
|
||||||
#include "HostnameMeter.h"
|
#include "HostnameMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
|
#include "zfs/ZfsArcMeter.h"
|
||||||
|
#include "zfs/ZfsCompressedArcMeter.h"
|
||||||
#include "DarwinProcessList.h"
|
#include "DarwinProcessList.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -33,7 +35,7 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
|
|
||||||
SignalItem Platform_signals[] = {
|
const SignalItem Platform_signals[] = {
|
||||||
{ .name = " 0 Cancel", .number = 0 },
|
{ .name = " 0 Cancel", .number = 0 },
|
||||||
{ .name = " 1 SIGHUP", .number = 1 },
|
{ .name = " 1 SIGHUP", .number = 1 },
|
||||||
{ .name = " 2 SIGINT", .number = 2 },
|
{ .name = " 2 SIGINT", .number = 2 },
|
||||||
@ -69,7 +71,7 @@ SignalItem Platform_signals[] = {
|
|||||||
{ .name = "31 SIGUSR2", .number = 31 },
|
{ .name = "31 SIGUSR2", .number = 31 },
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||||
|
|
||||||
ProcessFieldData Process_fields[] = {
|
ProcessFieldData Process_fields[] = {
|
||||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
@ -78,8 +80,8 @@ ProcessFieldData Process_fields[] = {
|
|||||||
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
|
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
|
||||||
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
||||||
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
||||||
[SESSION] = { .name = "SESSION", .title = " SESN ", .description = "Process's session ID", .flags = 0, },
|
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
||||||
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
||||||
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
||||||
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
||||||
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
||||||
@ -90,7 +92,7 @@ ProcessFieldData Process_fields[] = {
|
|||||||
[PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
|
[PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
|
||||||
[M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
|
[M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
|
||||||
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
||||||
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||||
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||||
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||||
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||||
@ -117,6 +119,8 @@ MeterClass* Platform_meterTypes[] = {
|
|||||||
&RightCPUsMeter_class,
|
&RightCPUsMeter_class,
|
||||||
&LeftCPUs2Meter_class,
|
&LeftCPUs2Meter_class,
|
||||||
&RightCPUs2Meter_class,
|
&RightCPUs2Meter_class,
|
||||||
|
&ZfsArcMeter_class,
|
||||||
|
&ZfsCompressedArcMeter_class,
|
||||||
&BlankMeter_class,
|
&BlankMeter_class,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
@ -166,7 +170,7 @@ ProcessPidColumn Process_pidColumns[] = {
|
|||||||
{ .id = TPGID, .label = "TPGID" },
|
{ .id = TPGID, .label = "TPGID" },
|
||||||
{ .id = TGID, .label = "TGID" },
|
{ .id = TGID, .label = "TGID" },
|
||||||
{ .id = PGRP, .label = "PGRP" },
|
{ .id = PGRP, .label = "PGRP" },
|
||||||
{ .id = SESSION, .label = "SESN" },
|
{ .id = SESSION, .label = "SID" },
|
||||||
{ .id = 0, .label = NULL },
|
{ .id = 0, .label = NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -217,6 +221,8 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
|
|||||||
/* Convert to percent and return */
|
/* Convert to percent and return */
|
||||||
total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL];
|
total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL];
|
||||||
|
|
||||||
|
mtr->values[CPU_METER_FREQUENCY] = -1;
|
||||||
|
|
||||||
return CLAMP(total, 0.0, 100.0);
|
return CLAMP(total, 0.0, 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,6 +247,18 @@ void Platform_setSwapValues(Meter* mtr) {
|
|||||||
mtr->values[0] = swapused.xsu_used / 1024;
|
mtr->values[0] = swapused.xsu_used / 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Platform_setZfsArcValues(Meter* this) {
|
||||||
|
DarwinProcessList* dpl = (DarwinProcessList*) this->pl;
|
||||||
|
|
||||||
|
ZfsArcMeter_readStats(this, &(dpl->zfs));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform_setZfsCompressedArcValues(Meter* this) {
|
||||||
|
DarwinProcessList* dpl = (DarwinProcessList*) this->pl;
|
||||||
|
|
||||||
|
ZfsCompressedArcMeter_readStats(this, &(dpl->zfs));
|
||||||
|
}
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid) {
|
char* Platform_getProcessEnv(pid_t pid) {
|
||||||
char* env = NULL;
|
char* env = NULL;
|
||||||
|
|
||||||
@ -280,11 +298,9 @@ char* Platform_getProcessEnv(pid_t pid) {
|
|||||||
|
|
||||||
size_t size = endp - p;
|
size_t size = endp - p;
|
||||||
env = xMalloc(size+2);
|
env = xMalloc(size+2);
|
||||||
if (env) {
|
memcpy(env, p, size);
|
||||||
memcpy(env, p, size);
|
env[size] = 0;
|
||||||
env[size] = 0;
|
env[size+1] = 0;
|
||||||
env[size+1] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -22,9 +22,9 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
extern ProcessField Platform_defaultFields[];
|
extern ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern SignalItem Platform_signals[];
|
extern const SignalItem Platform_signals[];
|
||||||
|
|
||||||
extern unsigned int Platform_numberOfSignals;
|
extern const unsigned int Platform_numberOfSignals;
|
||||||
|
|
||||||
extern ProcessFieldData Process_fields[];
|
extern ProcessFieldData Process_fields[];
|
||||||
|
|
||||||
@ -48,6 +48,10 @@ void Platform_setMemoryValues(Meter* mtr);
|
|||||||
|
|
||||||
void Platform_setSwapValues(Meter* mtr);
|
void Platform_setSwapValues(Meter* mtr);
|
||||||
|
|
||||||
|
void Platform_setZfsArcValues(Meter* this);
|
||||||
|
|
||||||
|
void Platform_setZfsCompressedArcValues(Meter* this);
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid);
|
char* Platform_getProcessEnv(pid_t pid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
26
dragonflybsd/Battery.c
Normal file
26
dragonflybsd/Battery.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
htop - dragonflybsd/Battery.c
|
||||||
|
(C) 2015 Hisham H. Muhammad
|
||||||
|
(C) 2017 Diederik de Groot
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "BatteryMeter.h"
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||||
|
int life;
|
||||||
|
size_t life_len = sizeof(life);
|
||||||
|
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
|
||||||
|
*level = -1;
|
||||||
|
else
|
||||||
|
*level = life;
|
||||||
|
|
||||||
|
int acline;
|
||||||
|
size_t acline_len = sizeof(acline);
|
||||||
|
if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1)
|
||||||
|
*isOnAC = AC_ERROR;
|
||||||
|
else
|
||||||
|
*isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT;
|
||||||
|
}
|
15
dragonflybsd/Battery.h
Normal file
15
dragonflybsd/Battery.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_Battery
|
||||||
|
#define HEADER_Battery
|
||||||
|
/*
|
||||||
|
htop - dragonflybsd/Battery.h
|
||||||
|
(C) 2015 Hisham H. Muhammad
|
||||||
|
(C) 2017 Diederik de Groot
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||||
|
|
||||||
|
#endif
|
35
dragonflybsd/DragonFlyBSDCRT.c
Normal file
35
dragonflybsd/DragonFlyBSDCRT.c
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
htop - dragonflybsd/DragonFlyBSDCRT.c
|
||||||
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2017 Diederik de Groot
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "CRT.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
|
#include <execinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void CRT_handleSIGSEGV(int sgn) {
|
||||||
|
(void) sgn;
|
||||||
|
CRT_done();
|
||||||
|
fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
|
size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
|
||||||
|
fprintf(stderr, "\n Please include in your report the following backtrace: \n");
|
||||||
|
backtrace_symbols_fd(backtraceArray, size, 2);
|
||||||
|
fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
|
||||||
|
fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
|
||||||
|
fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump");
|
||||||
|
fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report.");
|
||||||
|
fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "\nPlease contact your DragonFlyBSD package maintainer!\n\n");
|
||||||
|
#endif
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
19
dragonflybsd/DragonFlyBSDCRT.h
Normal file
19
dragonflybsd/DragonFlyBSDCRT.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_DragonFlyBSDCRT
|
||||||
|
#define HEADER_DragonFlyBSDCRT
|
||||||
|
/*
|
||||||
|
htop - dragonflybsd/DragonFlyBSDCRT.h
|
||||||
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2017 Diederik de Groot
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void CRT_handleSIGSEGV(int sgn);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
166
dragonflybsd/DragonFlyBSDProcess.c
Normal file
166
dragonflybsd/DragonFlyBSDProcess.c
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
htop - dragonflybsd/DragonFlyBSDProcess.c
|
||||||
|
(C) 2015 Hisham H. Muhammad
|
||||||
|
(C) 2017 Diederik de Groot
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Process.h"
|
||||||
|
#include "ProcessList.h"
|
||||||
|
#include "DragonFlyBSDProcess.h"
|
||||||
|
#include "Platform.h"
|
||||||
|
#include "CRT.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
|
||||||
|
/*{
|
||||||
|
|
||||||
|
typedef enum DragonFlyBSDProcessFields {
|
||||||
|
// Add platform-specific fields here, with ids >= 100
|
||||||
|
JID = 100,
|
||||||
|
JAIL = 101,
|
||||||
|
LAST_PROCESSFIELD = 102,
|
||||||
|
} DragonFlyBSDProcessField;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct DragonFlyBSDProcess_ {
|
||||||
|
Process super;
|
||||||
|
int kernel;
|
||||||
|
int jid;
|
||||||
|
char* jname;
|
||||||
|
} DragonFlyBSDProcess;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef Process_isKernelThread
|
||||||
|
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef Process_isUserlandThread
|
||||||
|
//#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
||||||
|
#define Process_isUserlandThread(_process) (_process->nlwp > 1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
ProcessClass DragonFlyBSDProcess_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Process),
|
||||||
|
.display = Process_display,
|
||||||
|
.delete = Process_delete,
|
||||||
|
.compare = DragonFlyBSDProcess_compare
|
||||||
|
},
|
||||||
|
.writeField = (Process_WriteField) DragonFlyBSDProcess_writeField,
|
||||||
|
};
|
||||||
|
|
||||||
|
ProcessFieldData Process_fields[] = {
|
||||||
|
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
|
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
||||||
|
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
|
||||||
|
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping (<20s), I Idle, Q Queued for Run, R running, D disk, Z zombie, T traced, W paging, B Blocked, A AskedPage, C Core, J Jailed)", .flags = 0, },
|
||||||
|
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
||||||
|
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
||||||
|
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
||||||
|
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
||||||
|
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
||||||
|
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
||||||
|
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
||||||
|
[PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
|
||||||
|
[NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
|
||||||
|
[STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
|
||||||
|
[PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
|
||||||
|
[M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
|
||||||
|
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
||||||
|
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||||
|
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||||
|
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||||
|
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||||
|
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||||
|
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
||||||
|
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
||||||
|
[JID] = { .name = "JID", .title = " JID ", .description = "Jail prison ID", .flags = 0, },
|
||||||
|
[JAIL] = { .name = "JAIL", .title = "JAIL ", .description = "Jail prison name", .flags = 0, },
|
||||||
|
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
|
};
|
||||||
|
|
||||||
|
ProcessPidColumn Process_pidColumns[] = {
|
||||||
|
{ .id = JID, .label = "JID" },
|
||||||
|
{ .id = PID, .label = "PID" },
|
||||||
|
{ .id = PPID, .label = "PPID" },
|
||||||
|
{ .id = TPGID, .label = "TPGID" },
|
||||||
|
{ .id = TGID, .label = "TGID" },
|
||||||
|
{ .id = PGRP, .label = "PGRP" },
|
||||||
|
{ .id = SESSION, .label = "SID" },
|
||||||
|
{ .id = 0, .label = NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings) {
|
||||||
|
DragonFlyBSDProcess* this = xCalloc(1, sizeof(DragonFlyBSDProcess));
|
||||||
|
Object_setClass(this, Class(DragonFlyBSDProcess));
|
||||||
|
Process_init(&this->super, settings);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Process_delete(Object* cast) {
|
||||||
|
DragonFlyBSDProcess* this = (DragonFlyBSDProcess*) cast;
|
||||||
|
Process_done((Process*)cast);
|
||||||
|
free(this->jname);
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField field) {
|
||||||
|
DragonFlyBSDProcess* fp = (DragonFlyBSDProcess*) this;
|
||||||
|
char buffer[256]; buffer[255] = '\0';
|
||||||
|
int attr = CRT_colors[DEFAULT_COLOR];
|
||||||
|
int n = sizeof(buffer) - 1;
|
||||||
|
switch ((int) field) {
|
||||||
|
// add Platform-specific fields here
|
||||||
|
case PID: xSnprintf(buffer, n, Process_pidFormat, (fp->kernel ? -1 : this->pid)); break;
|
||||||
|
case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break;
|
||||||
|
case JAIL:{
|
||||||
|
xSnprintf(buffer, n, "%-11s ", fp->jname);
|
||||||
|
if (buffer[11] != '\0') {
|
||||||
|
buffer[11] = ' ';
|
||||||
|
buffer[12] = '\0';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
Process_writeField(this, str, field);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RichString_append(str, attr, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
long DragonFlyBSDProcess_compare(const void* v1, const void* v2) {
|
||||||
|
DragonFlyBSDProcess *p1, *p2;
|
||||||
|
Settings *settings = ((Process*)v1)->settings;
|
||||||
|
if (settings->direction == 1) {
|
||||||
|
p1 = (DragonFlyBSDProcess*)v1;
|
||||||
|
p2 = (DragonFlyBSDProcess*)v2;
|
||||||
|
} else {
|
||||||
|
p2 = (DragonFlyBSDProcess*)v1;
|
||||||
|
p1 = (DragonFlyBSDProcess*)v2;
|
||||||
|
}
|
||||||
|
switch ((int) settings->sortKey) {
|
||||||
|
// add Platform-specific fields here
|
||||||
|
case JID:
|
||||||
|
return (p1->jid - p2->jid);
|
||||||
|
case JAIL:
|
||||||
|
return strcmp(p1->jname ? p1->jname : "", p2->jname ? p2->jname : "");
|
||||||
|
default:
|
||||||
|
return Process_compare(v1, v2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Process_isThread(Process* this) {
|
||||||
|
DragonFlyBSDProcess* fp = (DragonFlyBSDProcess*) this;
|
||||||
|
|
||||||
|
if (fp->kernel == 1 )
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return (Process_isUserlandThread(this));
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user