summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2023-12-23 22:46:44 +0100
committerBenBE <BenBE@geshi.org>2023-12-29 15:20:22 +0100
commit4bcea76663008bf0c9b0b5516716702f243bc9c9 (patch)
tree94152ea99260a5670b1acace046bd6983f8646b7
parentc55401b82b1bb278947f9d2a3aed13a9f0de85a9 (diff)
OpenFilesScreen: Make column sizing dynamic for file size, offset and inode
Previously this limited the size to single-digit-gigabytes(!). Now it can be single-digit-petabytes before going out of alignment. Fixes: Debian#1059369
-rw-r--r--OpenFilesScreen.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c
index 29540247..b3f94314 100644
--- a/OpenFilesScreen.c
+++ b/OpenFilesScreen.c
@@ -34,6 +34,7 @@ typedef struct OpenFiles_Data_ {
typedef struct OpenFiles_ProcessData_ {
OpenFiles_Data data;
int error;
+ int cols[8];
struct OpenFiles_FileData_* files;
} OpenFiles_ProcessData;
@@ -92,6 +93,9 @@ static void OpenFilesScreen_draw(InfoScreen* this) {
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
+ pdata->cols[getIndexForType('s')] = 8;
+ pdata->cols[getIndexForType('o')] = 8;
+ pdata->cols[getIndexForType('i')] = 8;
int fdpair[2] = {0, 0};
if (pipe(fdpair) == -1) {
@@ -164,6 +168,10 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
{
size_t index = getIndexForType(cmd);
free_and_xStrdup(&item->data[index], line + 1);
+ size_t dlen = strlen(item->data[index]);
+ if (dlen > (size_t)pdata->cols[index]) {
+ pdata->cols[index] = (int)CLAMP(dlen, 0, INT16_MAX);
+ }
break;
}
case 'o': /* file's offset */
@@ -174,6 +182,10 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
} else {
free_and_xStrdup(&item->data[index], line + 1);
}
+ size_t dlen = strlen(item->data[index]);
+ if (dlen > (size_t)pdata->cols[index]) {
+ pdata->cols[index] = (int)CLAMP(dlen, 0, INT16_MAX);
+ }
break;
}
case 'c': /* process command name */
@@ -249,17 +261,30 @@ static void OpenFilesScreen_scan(InfoScreen* this) {
} else if (pdata->error == 1) {
InfoScreen_addLine(this, "Failed listing open files.");
} else {
+ char hdrbuf[128] = {0};
+ snprintf(hdrbuf, sizeof(hdrbuf), "%5.5s %-7.7s %-4.4s %6.6s %*s %*s %*s %s",
+ "FD", "TYPE", "MODE", "DEVICE",
+ pdata->cols[getIndexForType('s')], "SIZE",
+ pdata->cols[getIndexForType('o')], "OFFSET",
+ pdata->cols[getIndexForType('i')], "NODE",
+ "NAME"
+ );
+ Panel_setHeader(panel, hdrbuf);
+
OpenFiles_FileData* fdata = pdata->files;
while (fdata) {
OpenFiles_Data* data = &fdata->data;
char* entry = NULL;
- xAsprintf(&entry, "%5.5s %-7.7s %-4.4s %-10.10s %10.10s %10.10s %10.10s %s",
+ xAsprintf(&entry, "%5.5s %-7.7s %-4.4s %6.6s %*s %*s %*s %s",
getDataForType(data, 'f'),
getDataForType(data, 't'),
getDataForType(data, 'a'),
getDataForType(data, 'D'),
+ pdata->cols[getIndexForType('s')],
getDataForType(data, 's'),
+ pdata->cols[getIndexForType('o')],
getDataForType(data, 'o'),
+ pdata->cols[getIndexForType('i')],
getDataForType(data, 'i'),
getDataForType(data, 'n'));
InfoScreen_addLine(this, entry);

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