diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-01-21 20:27:37 +0100 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2021-04-14 17:21:43 +0200 |
commit | 36880cd61c52f13c6fd284aa23d42d9493d3ab2e (patch) | |
tree | 54df8a9e8ef536db034af9a3f1d6496626ad802b /Action.c | |
parent | 812cfcb94df0fc0e6f9d33e39078454842d61609 (diff) |
Add read-only option
Add command line option to disable all system and process changing
features.
Diffstat (limited to 'Action.c')
-rw-r--r-- | Action.c | 98 |
1 files changed, 60 insertions, 38 deletions
@@ -254,11 +254,17 @@ static Htop_Reaction actionIncSearch(State* st) { } static Htop_Reaction actionHigherPriority(State* st) { + if (Settings_isReadonly()) + return HTOP_OK; + bool changed = changePriority(st->mainPanel, -1); return changed ? HTOP_REFRESH : HTOP_OK; } static Htop_Reaction actionLowerPriority(State* st) { + if (Settings_isReadonly()) + return HTOP_OK; + bool changed = changePriority(st->mainPanel, 1); return changed ? HTOP_REFRESH : HTOP_OK; } @@ -292,6 +298,9 @@ static Htop_Reaction actionQuit(ATTR_UNUSED State* st) { } static Htop_Reaction actionSetAffinity(State* st) { + if (Settings_isReadonly()) + return HTOP_OK; + if (st->pl->cpuCount == 1) return HTOP_OK; @@ -323,6 +332,9 @@ static Htop_Reaction actionSetAffinity(State* st) { } static Htop_Reaction actionKill(State* st) { + if (Settings_isReadonly()) + return HTOP_OK; + Panel* signalsPanel = SignalsPanel_new(); const ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true); if (sgn && sgn->key != 0) { @@ -370,6 +382,9 @@ static Htop_Reaction actionSetup(State* st) { } static Htop_Reaction actionLsof(State* st) { + if (Settings_isReadonly()) + return HTOP_OK; + const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel); if (!p) return HTOP_OK; @@ -394,6 +409,9 @@ static Htop_Reaction actionShowLocks(State* st) { } static Htop_Reaction actionStrace(State* st) { + if (Settings_isReadonly()) + return HTOP_OK; + const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel); if (!p) return HTOP_OK; @@ -431,49 +449,51 @@ static Htop_Reaction actionTogglePauseProcessUpdate(State* st) { static const struct { const char* key; + bool roInactive; const char* info; } helpLeft[] = { - { .key = " Arrows: ", .info = "scroll process list" }, - { .key = " Digits: ", .info = "incremental PID search" }, - { .key = " F3 /: ", .info = "incremental name search" }, - { .key = " F4 \\: ",.info = "incremental name filtering" }, - { .key = " F5 t: ", .info = "tree view" }, - { .key = " p: ", .info = "toggle program path" }, - { .key = " m: ", .info = "toggle merged command" }, - { .key = " Z: ", .info = "pause/resume process updates" }, - { .key = " u: ", .info = "show processes of a single user" }, - { .key = " H: ", .info = "hide/show user process threads" }, - { .key = " K: ", .info = "hide/show kernel threads" }, - { .key = " F: ", .info = "cursor follows process" }, - { .key = " + - *: ", .info = "expand/collapse tree/toggle all" }, - { .key = "N P M T: ", .info = "sort by PID, CPU%, MEM% or TIME" }, - { .key = " I: ", .info = "invert sort order" }, - { .key = " F6 > .: ", .info = "select sort column" }, + { .key = " Arrows: ", .roInactive = false, .info = "scroll process list" }, + { .key = " Digits: ", .roInactive = false, .info = "incremental PID search" }, + { .key = " F3 /: ", .roInactive = false, .info = "incremental name search" }, + { .key = " F4 \\: ", .roInactive = false, .info = "incremental name filtering" }, + { .key = " F5 t: ", .roInactive = false, .info = "tree view" }, + { .key = " p: ", .roInactive = false, .info = "toggle program path" }, + { .key = " m: ", .roInactive = false, .info = "toggle merged command" }, + { .key = " Z: ", .roInactive = false, .info = "pause/resume process updates" }, + { .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 = " 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" }, + { .key = " I: ", .roInactive = false, .info = "invert sort order" }, + { .key = " F6 > .: ", .roInactive = false, .info = "select sort column" }, { .key = NULL, .info = NULL } }; static const struct { const char* key; + bool roInactive; const char* info; } helpRight[] = { - { .key = " Space: ", .info = "tag process" }, - { .key = " c: ", .info = "tag process and its children" }, - { .key = " U: ", .info = "untag all processes" }, - { .key = " F9 k: ", .info = "kill process/tagged processes" }, - { .key = " F7 ]: ", .info = "higher priority (root only)" }, - { .key = " F8 [: ", .info = "lower priority (+ nice)" }, + { .key = " Space: ", .roInactive = false, .info = "tag process" }, + { .key = " c: ", .roInactive = false, .info = "tag process and its children" }, + { .key = " U: ", .roInactive = false, .info = "untag all processes" }, + { .key = " F9 k: ", .roInactive = true, .info = "kill process/tagged processes" }, + { .key = " F7 ]: ", .roInactive = true, .info = "higher priority (root only)" }, + { .key = " F8 [: ", .roInactive = false, .info = "lower priority (+ nice)" }, #if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) - { .key = " a: ", .info = "set CPU affinity" }, + { .key = " a: ", .roInactive = true, .info = "set CPU affinity" }, #endif - { .key = " e: ", .info = "show process environment" }, - { .key = " i: ", .info = "set IO priority" }, - { .key = " l: ", .info = "list open files with lsof" }, - { .key = " x: ", .info = "list file locks of process" }, - { .key = " s: ", .info = "trace syscalls with strace" }, - { .key = " w: ", .info = "wrap process command in multiple lines" }, - { .key = " F2 C S: ", .info = "setup" }, - { .key = " F1 h: ", .info = "show this help screen" }, - { .key = " F10 q: ", .info = "quit" }, + { .key = " e: ", .roInactive = false, .info = "show process environment" }, + { .key = " i: ", .roInactive = true, .info = "set IO priority" }, + { .key = " l: ", .roInactive = true, .info = "list open files with lsof" }, + { .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" }, + { .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" }, { .key = NULL, .info = NULL } }; @@ -549,26 +569,28 @@ static Htop_Reaction actionHelp(State* st) { line++; + const bool readonly = Settings_isReadonly(); + int item; for (item = 0; helpLeft[item].key; item++) { - attrset(CRT_colors[DEFAULT_COLOR]); + attrset((helpLeft[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[DEFAULT_COLOR]); mvaddstr(line + item, 10, helpLeft[item].info); - attrset(CRT_colors[HELP_BOLD]); + attrset((helpLeft[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[HELP_BOLD]); mvaddstr(line + item, 1, helpLeft[item].key); if (String_eq(helpLeft[item].key, " H: ")) { - attrset(CRT_colors[PROCESS_THREAD]); + attrset((helpLeft[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[PROCESS_THREAD]); mvaddstr(line + item, 33, "threads"); } else if (String_eq(helpLeft[item].key, " K: ")) { - attrset(CRT_colors[PROCESS_THREAD]); + attrset((helpLeft[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[PROCESS_THREAD]); mvaddstr(line + item, 27, "threads"); } } int leftHelpItems = item; for (item = 0; helpRight[item].key; item++) { - attrset(CRT_colors[HELP_BOLD]); + attrset((helpRight[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[HELP_BOLD]); mvaddstr(line + item, 41, helpRight[item].key); - attrset(CRT_colors[DEFAULT_COLOR]); + attrset((helpRight[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[DEFAULT_COLOR]); mvaddstr(line + item, 50, helpRight[item].info); } line += MAXIMUM(leftHelpItems, item); |