summaryrefslogtreecommitdiffstats
path: root/ProcessList.c
diff options
context:
space:
mode:
authorSilke Hofstra <silke@slxh.eu>2021-08-16 22:50:36 +0200
committerBenBE <BenBE@geshi.org>2021-10-27 21:20:59 +0200
commit696f79fe5099d510fc6ecc6d1e2f0ab3ae29e04e (patch)
tree2c9fa20e121b5c4b6cb90072fa016e5a642ddb65 /ProcessList.c
parent4374a267bec655e704faaa379d1ed62eca90b71a (diff)
Dynamically scale the ST_UID size to support 32-bit UIDs
While most Unix-like systems use 16-bit user IDs, Linux supports 32-bit UIDs since version 2.6. UIDs above 65535 are used for UID namespacing of containers, where a container has its own set of 16-bit user IDs. Processes in such containers will have (much) larger UIDs than 65535. Because the current format strings for `ST_UID` and `USER` are `%5d` and `%9d` respectively, processes with such UIDs lead to misaligned columns. Dynamically scale the `ST_UID` column and increase the size of `USER` to 10 characters (length of UINT32_MAX) to ensure that the user ID always fits. Additionally: clean up how the titlebuffer size calculation and ensure the PID column has a minimum size of 5.
Diffstat (limited to 'ProcessList.c')
-rw-r--r--ProcessList.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/ProcessList.c b/ProcessList.c
index 1ce6b76d..c4c759da 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -105,13 +105,19 @@ static const char* alignedProcessFieldTitle(const ProcessList* this, ProcessFiel
if (!title)
return "- ";
- if (!Process_fields[field].pidColumn)
- return title;
+ if (Process_fields[field].pidColumn) {
+ static char titleBuffer[PROCESS_MAX_PID_DIGITS + sizeof(" ")];
+ xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_pidDigits, title);
+ return titleBuffer;
+ }
- static char titleBuffer[PROCESS_MAX_PID_DIGITS + /* space */ 1 + /* null-terminator */ + 1];
- xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_pidDigits, title);
+ if (field == ST_UID) {
+ static char titleBuffer[PROCESS_MAX_UID_DIGITS + sizeof(" ")];
+ xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_uidDigits, title);
+ return titleBuffer;
+ }
- return titleBuffer;
+ return title;
}
void ProcessList_printHeader(const ProcessList* this, RichString* header) {
@@ -626,10 +632,15 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
ProcessList_goThroughEntries(this, false);
+ uid_t maxUid = 0;
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
Process* p = (Process*) Vector_get(this->processes, i);
Process_makeCommandStr(p);
+ // keep track of the highest UID for column scaling
+ if (p->st_uid > maxUid)
+ maxUid = p->st_uid;
+
if (p->tombStampMs > 0) {
// remove tombed process
if (this->monotonicMs >= p->tombStampMs) {
@@ -647,6 +658,9 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
}
}
+ // Set UID column width based on max UID.
+ Process_setUidColumnWidth(maxUid);
+
if (this->settings->treeView) {
// Clear out the hashtable to avoid any left-over processes from previous build
//

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