summaryrefslogtreecommitdiffstats
path: root/Process.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2021-05-23 16:04:43 +0200
committerBenBE <BenBE@geshi.org>2023-02-03 09:23:25 +0100
commit623ee31cfe3a39c87e6066c3044c7c38ce676e6b (patch)
treefa81ee2673e3cce64da7100bc246c8733d661cea /Process.c
parent4d40680aa04370b06e9a2acd732f0be2ee6b6eba (diff)
Add option to shadow path prefixes
Shadow path prefixes which are used by distributions, like /usr/bin/ /usr/sbin/ /bin/ /sbin/ /usr/libexec/
Diffstat (limited to 'Process.c')
-rw-r--r--Process.c70
1 files changed, 68 insertions, 2 deletions
diff --git a/Process.c b/Process.c
index ee7a5b39..fcaa3d54 100644
--- a/Process.c
+++ b/Process.c
@@ -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);
}
}

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