Split data array for file lock information into separate fields

This commit is contained in:
Benny Baumann 2020-11-13 21:34:21 +01:00
parent 18763051a2
commit d431786fca
3 changed files with 16 additions and 11 deletions

View File

@ -50,8 +50,10 @@ static void ProcessLocksScreen_draw(InfoScreen* this) {
}
static inline void FileLocks_Data_clear(FileLocks_Data* data) {
for (size_t i = 0; i < ARRAYSIZE(data->data); i++)
free(data->data[i]);
free(data->locktype);
free(data->exclusive);
free(data->readwrite);
free(data->filename);
}
static void ProcessLocksScreen_scan(InfoScreen* this) {
@ -75,18 +77,18 @@ static void ProcessLocksScreen_scan(InfoScreen* this) {
if (ULLONG_MAX == data->end) {
xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20s %s",
data->id,
data->data[0], data->data[1], data->data[2],
data->locktype, data->exclusive, data->readwrite,
data->dev[0], data->dev[1], data->inode,
data->start, "<END OF FILE>",
data->data[3] ? data->data[3] : "<N/A>"
data->filename ? data->filename : "<N/A>"
);
} else {
xSnprintf(entry, sizeof(entry), "%10d %-10s %-10s %-10s %02x:%02x:%020"PRIu64" %20"PRIu64" %20"PRIu64" %s",
data->id,
data->data[0], data->data[1], data->data[2],
data->locktype, data->exclusive, data->readwrite,
data->dev[0], data->dev[1], data->inode,
data->start, data->end,
data->data[3] ? data->data[3] : "<N/A>"
data->filename ? data->filename : "<N/A>"
);
}

View File

@ -18,7 +18,10 @@ typedef struct ProcessLocksScreen_ {
} ProcessLocksScreen;
typedef struct FileLocks_Data_ {
char* data[4];
char* locktype;
char* exclusive;
char* readwrite;
char* filename;
int id;
unsigned int dev[2];
uint64_t inode;

View File

@ -401,10 +401,10 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) {
FileLocks_LockData* ldata = xCalloc(1, sizeof(FileLocks_LockData));
FileLocks_Data* data = &ldata->data;
data->id = lock_id;
data->data[0] = xStrdup(lock_type);
data->data[1] = xStrdup(lock_excl);
data->data[2] = xStrdup(lock_rw);
data->data[3] = Platform_getInodeFilename(lock_pid, lock_inode);
data->locktype = xStrdup(lock_type);
data->exclusive = xStrdup(lock_excl);
data->readwrite = xStrdup(lock_rw);
data->filename = Platform_getInodeFilename(lock_pid, lock_inode);
data->dev[0] = lock_dev[0];
data->dev[1] = lock_dev[1];
data->inode = lock_inode;