diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-05-23 16:04:43 +0200 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2023-02-03 09:23:25 +0100 |
commit | 623ee31cfe3a39c87e6066c3044c7c38ce676e6b (patch) | |
tree | fa81ee2673e3cce64da7100bc246c8733d661cea | |
parent | 4d40680aa04370b06e9a2acd732f0be2ee6b6eba (diff) |
Add option to shadow path prefixes
Shadow path prefixes which are used by distributions, like
/usr/bin/
/usr/sbin/
/bin/
/sbin/
/usr/libexec/
-rw-r--r-- | DisplayOptionsPanel.c | 1 | ||||
-rw-r--r-- | Process.c | 70 | ||||
-rw-r--r-- | Process.h | 1 | ||||
-rw-r--r-- | Settings.c | 4 | ||||
-rw-r--r-- | Settings.h | 1 |
5 files changed, 75 insertions, 2 deletions
diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 3b9e6cc4..f9fa9b12 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -122,6 +122,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef("Show program path", &(settings->showProgramPath))); Panel_add(super, (Object*) CheckItem_newByRef("Highlight program \"basename\"", &(settings->highlightBaseName))); Panel_add(super, (Object*) CheckItem_newByRef("Highlight out-dated/removed programs (red) / libraries (yellow)", &(settings->highlightDeletedExe))); + Panel_add(super, (Object*) CheckItem_newByRef("Shadow distribution path prefixes", &(settings->shadowDistPathPrefix))); Panel_add(super, (Object*) CheckItem_newByRef("Merge exe, comm and cmdline in Command", &(settings->showMergedCommand))); Panel_add(super, (Object*) CheckItem_newByRef("- Try to find comm in cmdline (when Command is merged)", &(settings->findCommInCmdline))); Panel_add(super, (Object*) CheckItem_newByRef("- Try to strip exe from cmdline (when Command is merged)", &(settings->stripExeFromCmdline))); @@ -413,6 +413,7 @@ void Process_makeCommandStr(Process* this) { bool searchCommInCmdline = settings->findCommInCmdline; bool stripExeFromCmdline = settings->stripExeFromCmdline; bool showThreadNames = settings->showThreadNames; + bool shadowDistPathPrefix = settings->shadowDistPathPrefix; uint64_t settingsStamp = settings->lastUpdate; @@ -472,6 +473,56 @@ void Process_makeCommandStr(Process* this) { str = stpcpy(str, SEPARATOR); \ } while (0) + #define CHECK_AND_MARK(str_, prefix_) \ + if (String_startsWith(str_, prefix_)) { \ + WRITE_HIGHLIGHT(0, strlen(prefix_), CRT_colors[PROCESS_SHADOW], CMDLINE_HIGHLIGHT_FLAG_PREFIXDIR); \ + break; \ + } else (void)0 + + #define CHECK_AND_MARK_DIST_PATH_PREFIXES(str_) \ + do { \ + if ((str_)[0] != '/') { \ + break; \ + } \ + switch ((str_)[1]) { \ + case 'b': \ + CHECK_AND_MARK(str_, "/bin/"); \ + break; \ + case 'l': \ + CHECK_AND_MARK(str_, "/lib/"); \ + CHECK_AND_MARK(str_, "/lib32/"); \ + CHECK_AND_MARK(str_, "/lib64/"); \ + CHECK_AND_MARK(str_, "/libx32/"); \ + break; \ + case 's': \ + CHECK_AND_MARK(str_, "/sbin/"); \ + break; \ + case 'u': \ + if (String_startsWith(str_, "/usr/")) { \ + switch ((str_)[5]) { \ + case 'b': \ + CHECK_AND_MARK(str_, "/usr/bin/"); \ + break; \ + case 'l': \ + CHECK_AND_MARK(str_, "/usr/libexec/"); \ + CHECK_AND_MARK(str_, "/usr/lib/"); \ + CHECK_AND_MARK(str_, "/usr/lib32/"); \ + CHECK_AND_MARK(str_, "/usr/lib64/"); \ + CHECK_AND_MARK(str_, "/usr/libx32/"); \ + \ + CHECK_AND_MARK(str_, "/usr/local/bin/"); \ + CHECK_AND_MARK(str_, "/usr/local/lib/"); \ + CHECK_AND_MARK(str_, "/usr/local/sbin/"); \ + break; \ + case 's': \ + CHECK_AND_MARK(str_, "/usr/sbin/"); \ + break; \ + } \ + } \ + break; \ + } \ + } while (0) + const int baseAttr = Process_isThread(this) ? CRT_colors[PROCESS_THREAD_BASENAME] : CRT_colors[PROCESS_BASENAME]; const int commAttr = Process_isThread(this) ? CRT_colors[PROCESS_THREAD_COMM] : CRT_colors[PROCESS_COMM]; const int delExeAttr = CRT_colors[FAILED_READ]; @@ -510,6 +561,9 @@ void Process_makeCommandStr(Process* this) { } } + if (shadowDistPathPrefix && showProgramPath) + CHECK_AND_MARK_DIST_PATH_PREFIXES(cmdline); + if (cmdlineBasenameEnd > cmdlineBasenameStart) WRITE_HIGHLIGHT(showProgramPath ? cmdlineBasenameStart : 0, cmdlineBasenameEnd - cmdlineBasenameStart, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME); @@ -537,6 +591,8 @@ void Process_makeCommandStr(Process* this) { /* Start with copying exe */ if (showProgramPath) { + if (shadowDistPathPrefix) + CHECK_AND_MARK_DIST_PATH_PREFIXES(procExe); if (haveCommInExe) WRITE_HIGHLIGHT(exeBasenameOffset, exeBasenameLen, commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); WRITE_HIGHLIGHT(exeBasenameOffset, exeBasenameLen, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME); @@ -594,6 +650,9 @@ void Process_makeCommandStr(Process* this) { WRITE_SEPARATOR; } + if (shadowDistPathPrefix) + CHECK_AND_MARK_DIST_PATH_PREFIXES(cmdline); + if (!haveCommInExe && haveCommInCmdline && !haveCommField && (!Process_isUserlandThread(this) || showThreadNames)) WRITE_HIGHLIGHT(commStart, commEnd - commStart, commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); @@ -601,6 +660,8 @@ void Process_makeCommandStr(Process* this) { if (*cmdline) (void)stpcpyWithNewlineConversion(str, cmdline); + #undef CHECK_AND_MARK_DIST_PATH_PREFIXES + #undef CHECK_AND_MARK #undef WRITE_SEPARATOR #undef WRITE_HIGHLIGHT } @@ -609,6 +670,7 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin (void)baseAttr; const ProcessMergedCommand* mc = &this->mergedCommand; + const char* mergedCommand = mc->str; int strStart = RichString_size(str); @@ -616,7 +678,7 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin const bool highlightSeparator = true; const bool highlightDeleted = this->settings->highlightDeletedExe; - if (!this->mergedCommand.str) { + if (!mergedCommand) { int len = 0; const char* cmdline = this->cmdline; @@ -649,7 +711,7 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin return; } - RichString_appendWide(str, attr, this->mergedCommand.str); + RichString_appendWide(str, attr, mergedCommand); for (size_t i = 0, hlCount = CLAMP(mc->highlightCount, 0, ARRAYSIZE(mc->highlights)); i < hlCount; i++) { const ProcessCmdlineHighlight* hl = &mc->highlights[i]; @@ -669,6 +731,10 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin if (!highlightDeleted) continue; + if (hl->flags & CMDLINE_HIGHLIGHT_FLAG_PREFIXDIR) + if (!highlightDeleted) + continue; + RichString_setAttrn(str, hl->attr, strStart + hl->offset, hl->length); } } @@ -331,6 +331,7 @@ static inline bool Process_isThread(const Process* this) { #define CMDLINE_HIGHLIGHT_FLAG_BASENAME 0x00000002 #define CMDLINE_HIGHLIGHT_FLAG_COMM 0x00000004 #define CMDLINE_HIGHLIGHT_FLAG_DELETED 0x00000008 +#define CMDLINE_HIGHLIGHT_FLAG_PREFIXDIR 0x00000010 #define ONE_K 1024UL #define ONE_M (ONE_K * ONE_K) @@ -393,6 +393,8 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini this->highlightBaseName = atoi(option[1]); } else if (String_eq(option[0], "highlight_deleted_exe")) { this->highlightDeletedExe = atoi(option[1]); + } else if (String_eq(option[0], "shadow_distribution_path_prefix")) { + this->shadowDistPathPrefix = atoi(option[1]); } else if (String_eq(option[0], "highlight_megabytes")) { this->highlightMegabytes = atoi(option[1]); } else if (String_eq(option[0], "highlight_threads")) { @@ -587,6 +589,7 @@ int Settings_write(const Settings* this, bool onCrash) { printSettingInteger("show_program_path", this->showProgramPath); printSettingInteger("highlight_base_name", this->highlightBaseName); printSettingInteger("highlight_deleted_exe", this->highlightDeletedExe); + printSettingInteger("shadow_distribution_path_prefix", this->shadowDistPathPrefix); printSettingInteger("highlight_megabytes", this->highlightMegabytes); printSettingInteger("highlight_threads", this->highlightThreads); printSettingInteger("highlight_changes", this->highlightChanges); @@ -678,6 +681,7 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns) this->hideRunningInContainer = false; this->highlightBaseName = false; this->highlightDeletedExe = true; + this->shadowDistPathPrefix = false; this->highlightMegabytes = true; this->detailedCPUTime = false; this->countCPUsFromOne = false; @@ -77,6 +77,7 @@ typedef struct Settings_ { bool hideUserlandThreads; bool highlightBaseName; bool highlightDeletedExe; + bool shadowDistPathPrefix; bool highlightMegabytes; bool highlightThreads; bool highlightChanges; |