aboutsummaryrefslogtreecommitdiffstats
path: root/Action.c
diff options
context:
space:
mode:
Diffstat (limited to 'Action.c')
-rw-r--r--Action.c344
1 files changed, 238 insertions, 106 deletions
diff --git a/Action.c b/Action.c
index 81432f5..4049a95 100644
--- a/Action.c
+++ b/Action.c
@@ -9,9 +9,11 @@ in the source distribution for its full text.
#include "Action.h"
+#include <assert.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
#include "CRT.h"
#include "CategoriesPanel.h"
@@ -29,9 +31,14 @@ in the source distribution for its full text.
#include "Process.h"
#include "ProcessLocksScreen.h"
#include "ProvideCurses.h"
+#include "Row.h"
+#include "RowField.h"
+#include "Scheduling.h"
#include "ScreenManager.h"
#include "SignalsPanel.h"
+#include "Table.h"
#include "TraceScreen.h"
+#include "UsersTable.h"
#include "Vector.h"
#include "XUtils.h"
@@ -41,34 +48,35 @@ in the source distribution for its full text.
#endif
-Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) {
+Object* Action_pickFromVector(State* st, Panel* list, int x, bool follow) {
MainPanel* mainPanel = st->mainPanel;
Header* header = st->header;
+ Machine* host = st->host;
int y = ((Panel*)mainPanel)->y;
- ScreenManager* scr = ScreenManager_new(header, st->settings, st, false);
+ ScreenManager* scr = ScreenManager_new(header, host, st, false);
scr->allowFocusChange = false;
ScreenManager_add(scr, list, x);
ScreenManager_add(scr, (Panel*)mainPanel, -1);
Panel* panelFocus;
int ch;
bool unfollow = false;
- int pid = followProcess ? MainPanel_selectedPid(mainPanel) : -1;
- if (followProcess && header->pl->following == -1) {
- header->pl->following = pid;
+ int row = follow ? MainPanel_selectedRow(mainPanel) : -1;
+ if (follow && host->activeTable->following == -1) {
+ host->activeTable->following = row;
unfollow = true;
}
ScreenManager_run(scr, &panelFocus, &ch, NULL);
if (unfollow) {
- header->pl->following = -1;
+ host->activeTable->following = -1;
}
ScreenManager_delete(scr);
Panel_move((Panel*)mainPanel, 0, y);
Panel_resize((Panel*)mainPanel, COLS, LINES - y - 1);
if (panelFocus == list && ch == 13) {
- if (followProcess) {
- const Process* selected = (const Process*)Panel_getSelected((Panel*)mainPanel);
- if (selected && selected->pid == pid)
+ if (follow) {
+ const Row* selected = (const Row*)Panel_getSelected((Panel*)mainPanel);
+ if (selected && selected->id == row)
return Panel_getSelected(list);
beep();
@@ -83,19 +91,20 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
// ----------------------------------------
static void Action_runSetup(State* st) {
- ScreenManager* scr = ScreenManager_new(st->header, st->settings, st, true);
- CategoriesPanel_new(scr, st->settings, st->header, st->pl);
+ const Settings* settings = st->host->settings;
+ ScreenManager* scr = ScreenManager_new(st->header, st->host, st, true);
+ CategoriesPanel_new(scr, st->header, st->host);
ScreenManager_run(scr, NULL, NULL, "Setup");
ScreenManager_delete(scr);
- if (st->settings->changed) {
- CRT_setMouse(st->settings->enableMouse);
+ if (settings->changed) {
+ CRT_setMouse(settings->enableMouse);
Header_writeBackToSettings(st->header);
}
}
static bool changePriority(MainPanel* panel, int delta) {
bool anyTagged;
- bool ok = MainPanel_foreachProcess(panel, Process_changePriorityBy, (Arg) { .i = delta }, &anyTagged);
+ bool ok = MainPanel_foreachRow(panel, Process_rowChangePriorityBy, (Arg) { .i = delta }, &anyTagged);
if (!ok)
beep();
return anyTagged;
@@ -117,36 +126,36 @@ bool Action_setUserOnly(const char* userName, uid_t* userId) {
return false;
}
-static void tagAllChildren(Panel* panel, Process* parent) {
+static void tagAllChildren(Panel* panel, Row* parent) {
parent->tag = true;
- pid_t ppid = parent->pid;
+ int parent_id = parent->id;
for (int i = 0; i < Panel_size(panel); i++) {
- Process* p = (Process*) Panel_get(panel, i);
- if (!p->tag && Process_isChildOf(p, ppid)) {
- tagAllChildren(panel, p);
+ Row* row = (Row*) Panel_get(panel, i);
+ if (!row->tag && Row_isChildOf(row, parent_id)) {
+ tagAllChildren(panel, row);
}
}
}
static bool expandCollapse(Panel* panel) {
- Process* p = (Process*) Panel_getSelected(panel);
- if (!p)
+ Row* row = (Row*) Panel_getSelected(panel);
+ if (!row)
return false;
- p->showChildren = !p->showChildren;
+ row->showChildren = !row->showChildren;
return true;
}
static bool collapseIntoParent(Panel* panel) {
- const Process* p = (Process*) Panel_getSelected(panel);
- if (!p)
+ const Row* r = (Row*) Panel_getSelected(panel);
+ if (!r)
return false;
- pid_t ppid = Process_getParentPid(p);
+ int parent_id = Row_getGroupOrParent(r);
for (int i = 0; i < Panel_size(panel); i++) {
- Process* q = (Process*) Panel_get(panel, i);
- if (q->pid == ppid) {
- q->showChildren = false;
+ Row* row = (Row*) Panel_get(panel, i);
+ if (row->id == parent_id) {
+ row->showChildren = false;
Panel_setSelected(panel, i);
return true;
}
@@ -155,22 +164,34 @@ static bool collapseIntoParent(Panel* panel) {
}
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
- ScreenSettings_setSortKey(settings->ss, sortKey);
+ ScreenSettings_setSortKey(settings->ss, (RowField) sortKey);
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR | HTOP_KEEP_FOLLOWING;
}
// ----------------------------------------
+static bool Action_writeableProcess(State* st) {
+ const Settings* settings = st->host->settings;
+ bool readonly = Settings_isReadonly() || settings->ss->dynamic;
+ return !readonly;
+}
+
+static bool Action_readableProcess(State* st) {
+ const Settings* settings = st->host->settings;
+ return !settings->ss->dynamic;
+}
+
static Htop_Reaction actionSetSortColumn(State* st) {
Htop_Reaction reaction = HTOP_OK;
Panel* sortPanel = Panel_new(0, 0, 0, 0, Class(ListItem), true, FunctionBar_newEnterEsc("Sort ", "Cancel "));
Panel_setHeader(sortPanel, "Sort by");
- const Settings* settings = st->settings;
- const ProcessField* fields = settings->ss->fields;
+ Machine* host = st->host;
+ Settings* settings = host->settings;
+ const RowField* fields = settings->ss->fields;
Hashtable* dynamicColumns = settings->dynamicColumns;
for (int i = 0; fields[i]; i++) {
char* name = NULL;
- if (fields[i] >= LAST_PROCESSFIELD) {
+ if (fields[i] >= ROW_DYNAMIC_FIELDS) {
DynamicColumn* column = Hashtable_get(dynamicColumns, fields[i]);
if (!column)
continue;
@@ -186,72 +207,85 @@ static Htop_Reaction actionSetSortColumn(State* st) {
}
const ListItem* field = (const ListItem*) Action_pickFromVector(st, sortPanel, 14, false);
if (field) {
- reaction |= Action_setSortKey(st->settings, field->key);
+ reaction |= Action_setSortKey(settings, field->key);
}
Object_delete(sortPanel);
- st->pl->needsSort = true;
+ host->activeTable->needsSort = true;
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
}
static Htop_Reaction actionSortByPID(State* st) {
- return Action_setSortKey(st->settings, PID);
+ return Action_setSortKey(st->host->settings, PID);
}
static Htop_Reaction actionSortByMemory(State* st) {
- return Action_setSortKey(st->settings, PERCENT_MEM);
+ return Action_setSortKey(st->host->settings, PERCENT_MEM);
}
static Htop_Reaction actionSortByCPU(State* st) {
- return Action_setSortKey(st->settings, PERCENT_CPU);
+ return Action_setSortKey(st->host->settings, PERCENT_CPU);
}
static Htop_Reaction actionSortByTime(State* st) {
- return Action_setSortKey(st->settings, TIME);
+ return Action_setSortKey(st->host->settings, TIME);
}
static Htop_Reaction actionToggleKernelThreads(State* st) {
- st->settings->hideKernelThreads = !st->settings->hideKernelThreads;
- st->settings->lastUpdate++;
+ Settings* settings = st->host->settings;
+ settings->hideKernelThreads = !settings->hideKernelThreads;
+ settings->lastUpdate++;
+
+ Machine_scanTables(st->host); // needed to not have a visible delay showing wrong data
return HTOP_RECALCULATE | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING;
}
static Htop_Reaction actionToggleUserlandThreads(State* st) {
- st->settings->hideUserlandThreads = !st->settings->hideUserlandThreads;
- st->settings->lastUpdate++;
+ Settings* settings = st->host->settings;
+ settings->hideUserlandThreads = !settings->hideUserlandThreads;
+ settings->lastUpdate++;
+
+ Machine_scanTables(st->host); // needed to not have a visible delay showing wrong data
return HTOP_RECALCULATE | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING;
}
static Htop_Reaction actionToggleRunningInContainer(State* st) {
- st->settings->hideRunningInContainer = !st->settings->hideRunningInContainer;
- st->settings->lastUpdate++;
+ Settings* settings = st->host->settings;
+ settings->hideRunningInContainer = !settings->hideRunningInContainer;
+ settings->lastUpdate++;
return HTOP_RECALCULATE | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING;
}
static Htop_Reaction actionToggleProgramPath(State* st) {
- st->settings->showProgramPath = !st->settings->showProgramPath;
- st->settings->lastUpdate++;
+ Settings* settings = st->host->settings;
+ settings->showProgramPath = !settings->showProgramPath;
+ settings->lastUpdate++;
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING;
}
static Htop_Reaction actionToggleMergedCommand(State* st) {
- st->settings->showMergedCommand = !st->settings->showMergedCommand;
- st->settings->lastUpdate++;
+ Settings* settings = st->host->settings;
+ settings->showMergedCommand = !settings->showMergedCommand;
+ settings->lastUpdate++;
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_UPDATE_PANELHDR;
}
static Htop_Reaction actionToggleTreeView(State* st) {
- ScreenSettings* ss = st->settings->ss;
+ Machine* host = st->host;
+ ScreenSettings* ss = host->settings->ss;
ss->treeView = !ss->treeView;
if (!ss->allBranchesCollapsed)
- ProcessList_expandTree(st->pl);
+ Table_expandTree(host->activeTable);
+
+ host->activeTable->needsSort = true;
+
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
}
@@ -261,22 +295,24 @@ static Htop_Reaction actionToggleHideMeters(State* st) {
}
static Htop_Reaction actionExpandOrCollapseAllBranches(State* st) {
- ScreenSettings* ss = st->settings->ss;
+ Machine* host = st->host;
+ ScreenSettings* ss = host->settings->ss;
if (!ss->treeView) {
return HTOP_OK;
}
ss->allBranchesCollapsed = !ss->allBranchesCollapsed;
if (ss->allBranchesCollapsed)
- ProcessList_collapseAllBranches(st->pl);
+ Table_collapseAllBranches(host->activeTable);
else
- ProcessList_expandTree(st->pl);
+ Table_expandTree(host->activeTable);
return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
}
static Htop_Reaction actionIncFilter(State* st) {
+ Machine* host = st->host;
IncSet* inc = (st->mainPanel)->inc;
IncSet_activate(inc, INC_FILTER, (Panel*)st->mainPanel);
- st->pl->incFilter = IncSet_filter(inc);
+ host->activeTable->incFilter = IncSet_filter(inc);
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
}
@@ -287,7 +323,7 @@ static Htop_Reaction actionIncSearch(State* st) {
}
static Htop_Reaction actionHigherPriority(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
bool changed = changePriority(st->mainPanel, -1);
@@ -295,7 +331,7 @@ static Htop_Reaction actionHigherPriority(State* st) {
}
static Htop_Reaction actionLowerPriority(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
bool changed = changePriority(st->mainPanel, 1);
@@ -303,13 +339,14 @@ static Htop_Reaction actionLowerPriority(State* st) {
}
static Htop_Reaction actionInvertSortOrder(State* st) {
- ScreenSettings_invertSortOrder(st->settings->ss);
- st->pl->needsSort = true;
+ Machine* host = st->host;
+ ScreenSettings_invertSortOrder(host->settings->ss);
+ host->activeTable->needsSort = true;
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_UPDATE_PANELHDR;
}
static Htop_Reaction actionExpandOrCollapse(State* st) {
- if (!st->settings->ss->treeView)
+ if (!st->host->settings->ss->treeView)
return HTOP_OK;
bool changed = expandCollapse((Panel*)st->mainPanel);
@@ -317,7 +354,7 @@ static Htop_Reaction actionExpandOrCollapse(State* st) {
}
static Htop_Reaction actionCollapseIntoParent(State* st) {
- if (!st->settings->ss->treeView) {
+ if (!st->host->settings->ss->treeView) {
return HTOP_OK;
}
bool changed = collapseIntoParent((Panel*)st->mainPanel);
@@ -325,42 +362,57 @@ static Htop_Reaction actionCollapseIntoParent(State* st) {
}
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
- return st->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
+ return st->host->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
+}
+
+static inline void setActiveScreen(Settings* settings, State* st, unsigned int ssIdx) {
+ assert(settings->ssIndex == ssIdx);
+ Machine* host = st->host;
+
+ settings->ss = settings->screens[ssIdx];
+ if (!settings->ss->table)
+ settings->ss->table = host->processTable;
+ host->activeTable = settings->ss->table;
+
+ // set correct functionBar - readonly if requested, and/or with non-process screens
+ bool readonly = Settings_isReadonly() || (host->activeTable != host->processTable);
+ MainPanel_setFunctionBar(st->mainPanel, readonly);
}
static Htop_Reaction actionNextScreen(State* st) {
- Settings* settings = st->settings;
+ Settings* settings = st->host->settings;
settings->ssIndex++;
if (settings->ssIndex == settings->nScreens) {
settings->ssIndex = 0;
}
- settings->ss = settings->screens[settings->ssIndex];
- return HTOP_UPDATE_PANELHDR | HTOP_REFRESH;
+ setActiveScreen(settings, st, settings->ssIndex);
+ return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
static Htop_Reaction actionPrevScreen(State* st) {
- Settings* settings = st->settings;
+ Settings* settings = st->host->settings;
if (settings->ssIndex == 0) {
settings->ssIndex = settings->nScreens - 1;
} else {
settings->ssIndex--;
}
- settings->ss = settings->screens[settings->ssIndex];
- return HTOP_UPDATE_PANELHDR | HTOP_REFRESH;
+ setActiveScreen(settings, st, settings->ssIndex);
+ return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
-Htop_Reaction Action_setScreenTab(Settings* settings, int x) {
+Htop_Reaction Action_setScreenTab(State* st, int x) {
+ Settings* settings = st->host->settings;
int s = 2;
for (unsigned int i = 0; i < settings->nScreens; i++) {
if (x < s) {
return 0;
}
- const char* name = settings->screens[i]->name;
- int len = strlen(name);
+ const char* tab = settings->screens[i]->heading;
+ int len = strlen(tab);
if (x <= s + len + 1) {
settings->ssIndex = i;
- settings->ss = settings->screens[i];
- return HTOP_UPDATE_PANELHDR | HTOP_REFRESH;
+ setActiveScreen(settings, st, i);
+ return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
s += len + 3;
}
@@ -372,29 +424,30 @@ static Htop_Reaction actionQuit(ATTR_UNUSED State* st) {
}
static Htop_Reaction actionSetAffinity(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
- if (st->pl->activeCPUs == 1)
+ Machine* host = st->host;
+ if (host->activeCPUs == 1)
return HTOP_OK;
#if (defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY))
- const Process* p = (const Process*) Panel_getSelected((Panel*)st->mainPanel);
- if (!p)
+ const Row* row = (const Row*) Panel_getSelected((Panel*)st->mainPanel);
+ if (!row)
return HTOP_OK;
- Affinity* affinity1 = Affinity_get(p, st->pl);
+ Affinity* affinity1 = Affinity_rowGet(row, host);
if (!affinity1)
return HTOP_OK;
int width;
- Panel* affinityPanel = AffinityPanel_new(st->pl, affinity1, &width);
+ Panel* affinityPanel = AffinityPanel_new(host, affinity1, &width);
Affinity_delete(affinity1);
const void* set = Action_pickFromVector(st, affinityPanel, width, true);
if (set) {
- Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl);
- bool ok = MainPanel_foreachProcess(st->mainPanel, Affinity_set, (Arg) { .v = affinity2 }, NULL);
+ Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, host);
+ bool ok = MainPanel_foreachRow(st->mainPanel, Affinity_rowSet, (Arg) { .v = affinity2 }, NULL);
if (!ok)
beep();
Affinity_delete(affinity2);
@@ -404,11 +457,55 @@ static Htop_Reaction actionSetAffinity(State* st) {
#else
return HTOP_OK;
#endif
+}
+
+#ifdef SCHEDULER_SUPPORT
+static Htop_Reaction actionSetSchedPolicy(State* st) {
+ if (!Action_writeableProcess(st))
+ return HTOP_KEEP_FOLLOWING;
+
+ static int preSelectedPolicy = SCHEDULINGPANEL_INITSELECTEDPOLICY;
+ static int preSelectedPriority = SCHEDULINGPANEL_INITSELECTEDPRIORITY;
+
+ Panel* schedPanel = Scheduling_newPolicyPanel(preSelectedPolicy);
+
+ const ListItem* policy;
+ for (;;) {
+ policy = (const ListItem*) Action_pickFromVector(st, schedPanel, 18, true);
+
+ if (!policy || policy->key != -1)
+ break;
+
+ Scheduling_togglePolicyPanelResetOnFork(schedPanel);
+ }
+
+ if (policy) {
+ preSelectedPolicy = policy->key;
+ Panel* prioPanel = Scheduling_newPriorityPanel(policy->key, preSelectedPriority);
+ if (prioPanel) {
+ const ListItem* prio = (const ListItem*) Action_pickFromVector(st, prioPanel, 14, true);
+ if (prio)
+ preSelectedPriority = prio->key;
+
+ Panel_delete((Object*) prioPanel);
+ }
+
+ SchedulingArg v = { .policy = preSelectedPolicy, .priority = preSelectedPriority };
+
+ bool ok = MainPanel_foreachRow(st->mainPanel, Scheduling_rowSetPolicy, (Arg) { .v = &v }, NULL);
+ if (!ok)
+ beep();
+ }
+
+ Panel_delete((Object*)schedPanel);
+
+ return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_KEEP_FOLLOWING;
}
+#endif /* SCHEDULER_SUPPORT */
static Htop_Reaction actionKill(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
static int preSelectedSignal = SIGNALSPANEL_INITSELECTEDSIGNAL;
@@ -420,26 +517,31 @@ static Htop_Reaction actionKill(State* st) {
Panel_setHeader((Panel*)st->mainPanel, "Sending...");
Panel_draw((Panel*)st->mainPanel, false, true, true, State_hideFunctionBar(st));
refresh();
- MainPanel_foreachProcess(st->mainPanel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL);
+ bool ok = MainPanel_foreachRow(st->mainPanel, Process_rowSendSignal, (Arg) { .i = sgn->key }, NULL);
+ if (!ok) {
+ beep();
+ }
napms(500);
}
Panel_delete((Object*)signalsPanel);
+
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
}
static Htop_Reaction actionFilterByUser(State* st) {
Panel* usersPanel = Panel_new(0, 0, 0, 0, Class(ListItem), true, FunctionBar_newEnterEsc("Show ", "Cancel "));
Panel_setHeader(usersPanel, "Show processes of:");
- UsersTable_foreach(st->ut, addUserToVector, usersPanel);
+ Machine* host = st->host;
+ UsersTable_foreach(host->usersTable, addUserToVector, usersPanel);
Vector_insertionSort(usersPanel->items);
ListItem* allUsers = ListItem_new("All users", -1);
Panel_insert(usersPanel, 0, (Object*) allUsers);
const ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 19, false);
if (picked) {
if (picked == allUsers) {
- st->pl->userId = (uid_t)-1;
+ host->userId = (uid_t)-1;
} else {
- Action_setUserOnly(ListItem_getRef(picked), &(st->pl->userId));
+ Action_setUserOnly(ListItem_getRef(picked), &host->userId);
}
}
Panel_delete((Object*)usersPanel);
@@ -447,7 +549,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
}
Htop_Reaction Action_follow(State* st) {
- st->pl->following = MainPanel_selectedPid(st->mainPanel);
+ st->host->activeTable->following = MainPanel_selectedRow(st->mainPanel);
Panel_setSelectionColor((Panel*)st->mainPanel, PANEL_SELECTION_FOLLOW);
return HTOP_KEEP_FOLLOWING;
}
@@ -458,13 +560,15 @@ static Htop_Reaction actionSetup(State* st) {
}
static Htop_Reaction actionLsof(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
+ assert(Object_isA((const Object*) p, (const ObjectClass*) &Process_class));
+
OpenFilesScreen* ofs = OpenFilesScreen_new(p);
InfoScreen_run((InfoScreen*)ofs);
OpenFilesScreen_delete((Object*)ofs);
@@ -474,9 +578,15 @@ static Htop_Reaction actionLsof(State* st) {
}
static Htop_Reaction actionShowLocks(State* st) {
+ if (!Action_readableProcess(st))
+ return HTOP_OK;
+
const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
+
+ assert(Object_isA((const Object*) p, (const ObjectClass*) &Process_class));
+
ProcessLocksScreen* pls = ProcessLocksScreen_new(p);
InfoScreen_run((InfoScreen*)pls);
ProcessLocksScreen_delete((Object*)pls);
@@ -486,13 +596,15 @@ static Htop_Reaction actionShowLocks(State* st) {
}
static Htop_Reaction actionStrace(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
+ assert(Object_isA((const Object*) p, (const ObjectClass*) &Process_class));
+
TraceScreen* ts = TraceScreen_new(p);
bool ok = TraceScreen_forkTracer(ts);
if (ok) {
@@ -505,22 +617,23 @@ static Htop_Reaction actionStrace(State* st) {
}
static Htop_Reaction actionTag(State* st) {
- Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
- if (!p)
+ Row* r = (Row*) Panel_getSelected((Panel*)st->mainPanel);
+ if (!r)
return HTOP_OK;
- Process_toggleTag(p);
+ Row_toggleTag(r);
Panel_onKey((Panel*)st->mainPanel, KEY_DOWN);
return HTOP_OK;
}
static Htop_Reaction actionRedraw(ATTR_UNUSED State* st) {
clear();
- return HTOP_REFRESH | HTOP_REDRAW_BAR;
+ // HTOP_RECALCULATE here to make Ctrl-L also refresh the data and not only redraw
+ return HTOP_RECALCULATE | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
-static Htop_Reaction actionTogglePauseProcessUpdate(State* st) {
- st->pauseProcessUpdate = !st->pauseProcessUpdate;
+static Htop_Reaction actionTogglePauseUpdate(State* st) {
+ st->pauseUpdate = !st->pauseUpdate;
return HTOP_REFRESH | HTOP_REDRAW_BAR;
}
@@ -542,6 +655,7 @@ static const struct {
{ .key = " u: ", .roInactive = false, .info = "show processes of a single user" },
{ .key = " H: ", .roInactive = false, .info = "hide/show user process threads" },
{ .key = " K: ", .roInactive = false, .info = "hide/show kernel threads" },
+ { .key = " O: ", .roInactive = false, .info = "hide/show processes in containers" },
{ .key = " F: ", .roInactive = false, .info = "cursor follows process" },
{ .key = " + - *: ", .roInactive = false, .info = "expand/collapse tree/toggle all" },
{ .key = "N P M T: ", .roInactive = false, .info = "sort by PID, CPU%, MEM% or TIME" },
@@ -571,6 +685,9 @@ static const struct {
{ .key = " x: ", .roInactive = false, .info = "list file locks of process" },
{ .key = " s: ", .roInactive = true, .info = "trace syscalls with strace" },
{ .key = " w: ", .roInactive = false, .info = "wrap process command in multiple lines" },
+#ifdef SCHEDULER_SUPPORT
+ { .key = " Y: ", .roInactive = true, .info = "set scheduling policy" },
+#endif
{ .key = " F2 C S: ", .roInactive = false, .info = "setup" },
{ .key = " F1 h ?: ", .roInactive = false, .info = "show this help screen" },
{ .key = " F10 q: ", .roInactive = false, .info = "quit" },
@@ -608,7 +725,7 @@ static Htop_Reaction actionHelp(State* st) {
addbartext(CRT_colors[CPU_NICE_TEXT], "", "low");
addbartext(CRT_colors[CPU_NORMAL], "/", "normal");
addbartext(CRT_colors[CPU_SYSTEM], "/", "kernel");
- if (st->settings->detailedCPUTime) {
+ if (st->host->settings->detailedCPUTime) {
addbartext(CRT_colors[CPU_IRQ], "/", "irq");
addbartext(CRT_colors[CPU_SOFTIRQ], "/", "soft-irq");
addbartext(CRT_colors[CPU_STEAL], "/", "steal");
@@ -625,10 +742,11 @@ static Htop_Reaction actionHelp(State* st) {
mvaddstr(line++, 0, "Memory bar: ");
addattrstr(CRT_colors[BAR_BORDER], "[");
addbartext(CRT_colors[MEMORY_USED], "", "used");
- addbartext(CRT_colors[MEMORY_BUFFERS_TEXT], "/", "buffers");
addbartext(CRT_colors[MEMORY_SHARED], "/", "shared");
+ addbartext(CRT_colors[MEMORY_COMPRESSED], "/", "compressed");
+ addbartext(CRT_colors[MEMORY_BUFFERS_TEXT], "/", "buffers");
addbartext(CRT_colors[MEMORY_CACHE], "/", "cache");
- addbartext(CRT_colors[BAR_SHADOW], " ", "used");
+ addbartext(CRT_colors[BAR_SHADOW], " ", "used");
addbartext(CRT_colors[BAR_SHADOW], "/", "total");
addattrstr(CRT_colors[BAR_BORDER], "]");
@@ -638,10 +756,11 @@ static Htop_Reaction actionHelp(State* st) {
addbartext(CRT_colors[SWAP], "", "used");
#ifdef HTOP_LINUX
addbartext(CRT_colors[SWAP_CACHE], "/", "cache");
+ addbartext(CRT_colors[SWAP_FRONTSWAP], "/", "frontswap");
#else
addbartext(CRT_colors[SWAP_CACHE], " ", "");
#endif
- addbartext(CRT_colors[BAR_SHADOW], " ", "used");
+ addbartext(CRT_colors[BAR_SHADOW], " ", "used");
addbartext(CRT_colors[BAR_SHADOW], "/", "total");
addattrstr(CRT_colors[BAR_BORDER], "]");
@@ -694,9 +813,9 @@ static Htop_Reaction actionHelp(State* st) {
for (item = 0; helpRight[item].key; item++) {
attrset((helpRight[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[HELP_BOLD]);
- mvaddstr(line + item, 41, helpRight[item].key);
+ mvaddstr(line + item, 43, helpRight[item].key);
attrset((helpRight[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[DEFAULT_COLOR]);
- mvaddstr(line + item, 50, helpRight[item].info);
+ mvaddstr(line + item, 52, helpRight[item].info);
}
line += MAXIMUM(leftHelpItems, item);
line++;
@@ -713,26 +832,31 @@ static Htop_Reaction actionHelp(State* st) {
static Htop_Reaction actionUntagAll(State* st) {
for (int i = 0; i < Panel_size((Panel*)st->mainPanel); i++) {
- Process* p = (Process*) Panel_get((Panel*)st->mainPanel, i);
- p->tag = false;
+ Row* row = (Row*) Panel_get((Panel*)st->mainPanel, i);
+ row->tag = false;
}
return HTOP_REFRESH;
}
static Htop_Reaction actionTagAllChildren(State* st) {
- Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
- if (!p)
+ Row* row = (Row*) Panel_getSelected((Panel*)st->mainPanel);
+ if (!row)
return HTOP_OK;
- tagAllChildren((Panel*)st->mainPanel, p);
+ tagAllChildren((Panel*)st->mainPanel, row);
return HTOP_OK;
}
static Htop_Reaction actionShowEnvScreen(State* st) {
+ if (!Action_readableProcess(st))
+ return HTOP_OK;
+
Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
+ assert(Object_isA((const Object*) p, (const ObjectClass*) &Process_class));
+
EnvScreen* es = EnvScreen_new(p);
InfoScreen_run((InfoScreen*)es);
EnvScreen_delete((Object*)es);
@@ -742,10 +866,15 @@ static Htop_Reaction actionShowEnvScreen(State* st) {
}
static Htop_Reaction actionShowCommandScreen(State* st) {
+ if (!Action_readableProcess(st))
+ return HTOP_OK;
+
Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
+ assert(Object_isA((const Object*) p, (const ObjectClass*) &Process_class));
+
CommandScreen* cmdScr = CommandScreen_new(p);
InfoScreen_run((InfoScreen*)cmdScr);
CommandScreen_delete((Object*)cmdScr);
@@ -779,7 +908,10 @@ void Action_setBindings(Htop_Action* keys) {
keys['S'] = actionSetup;
keys['T'] = actionSortByTime;
keys['U'] = actionUntagAll;
- keys['Z'] = actionTogglePauseProcessUpdate;
+#ifdef SCHEDULER_SUPPORT
+ keys['Y'] = actionSetSchedPolicy;
+#endif
+ keys['Z'] = actionTogglePauseUpdate;
keys['['] = actionLowerPriority;
keys['\014'] = actionRedraw; // Ctrl+L
keys['\177'] = actionCollapseIntoParent;

© 2014-2024 Faster IT GmbH | imprint | privacy policy