FreeBSD: update Process

This commit is contained in:
Christian Göttsche 2020-10-21 19:11:26 +02:00 committed by cgzones
parent 97ea45ca9a
commit 049046c700
3 changed files with 21 additions and 22 deletions

View File

@ -19,16 +19,6 @@ in the source distribution for its full text.
const char* const nodevStr = "nodev"; const char* const nodevStr = "nodev";
const ProcessClass FreeBSDProcess_class = {
.super = {
.extends = Class(Process),
.display = Process_display,
.delete = Process_delete,
.compare = FreeBSDProcess_compare
},
.writeField = FreeBSDProcess_writeField,
};
ProcessFieldData Process_fields[] = { ProcessFieldData Process_fields[] = {
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, }, [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
@ -85,7 +75,7 @@ void Process_delete(Object* cast) {
free(this); free(this);
} }
void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { static void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) {
const FreeBSDProcess* fp = (const FreeBSDProcess*) this; const FreeBSDProcess* fp = (const FreeBSDProcess*) this;
char buffer[256]; buffer[255] = '\0'; char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR]; int attr = CRT_colors[DEFAULT_COLOR];
@ -118,7 +108,7 @@ void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessFiel
RichString_append(str, attr, buffer); RichString_append(str, attr, buffer);
} }
long FreeBSDProcess_compare(const void* v1, const void* v2) { static long FreeBSDProcess_compare(const void* v1, const void* v2) {
const FreeBSDProcess *p1, *p2; const FreeBSDProcess *p1, *p2;
const Settings *settings = ((const Process*)v1)->settings; const Settings *settings = ((const Process*)v1)->settings;
if (settings->direction == 1) { if (settings->direction == 1) {
@ -147,5 +137,15 @@ bool Process_isThread(const Process* this) {
if (fp->kernel == 1 ) if (fp->kernel == 1 )
return 1; return 1;
else else
return (Process_isUserlandThread(this)); return Process_isUserlandThread(this);
} }
const ProcessClass FreeBSDProcess_class = {
.super = {
.extends = Class(Process),
.display = Process_display,
.delete = Process_delete,
.compare = FreeBSDProcess_compare
},
.writeField = FreeBSDProcess_writeField,
};

View File

@ -34,9 +34,13 @@ typedef struct FreeBSDProcess_ {
const char* ttyPath; const char* ttyPath;
} FreeBSDProcess; } FreeBSDProcess;
#define Process_isKernelThread(_process) (_process->kernel == 1) static inline bool Process_isKernelThread(const Process* this) {
return ((const FreeBSDProcess*)this)->kernel == 1;
}
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) static inline bool Process_isUserlandThread(const Process* this) {
return this->pid != this->tgid;
}
extern const ProcessClass FreeBSDProcess_class; extern const ProcessClass FreeBSDProcess_class;
@ -48,10 +52,6 @@ Process* FreeBSDProcess_new(const Settings* settings);
void Process_delete(Object* cast); void Process_delete(Object* cast);
void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessField field);
long FreeBSDProcess_compare(const void* v1, const void* v2);
bool Process_isThread(const Process* this); bool Process_isThread(const Process* this);
#endif #endif

View File

@ -479,7 +479,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
Process* proc = ProcessList_getProcess(super, kproc->ki_pid, &preExisting, FreeBSDProcess_new); Process* proc = ProcessList_getProcess(super, kproc->ki_pid, &preExisting, FreeBSDProcess_new);
FreeBSDProcess* fp = (FreeBSDProcess*) proc; FreeBSDProcess* fp = (FreeBSDProcess*) proc;
proc->show = ! ((hideKernelThreads && Process_isKernelThread(fp)) || (hideUserlandThreads && Process_isUserlandThread(proc))); proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc)));
if (!preExisting) { if (!preExisting) {
fp->jid = kproc->ki_jid; fp->jid = kproc->ki_jid;
@ -567,9 +567,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) if (settings->flags & PROCESS_FLAG_FREEBSD_TTY)
fp->ttyPath = (kproc->ki_tdev == NODEV) ? nodevStr : Hashtable_get(fpl->ttys, kproc->ki_tdev); fp->ttyPath = (kproc->ki_tdev == NODEV) ? nodevStr : Hashtable_get(fpl->ttys, kproc->ki_tdev);
if (Process_isKernelThread(fp)) { if (Process_isKernelThread(proc))
super->kernelThreads++; super->kernelThreads++;
}
super->totalTasks++; super->totalTasks++;
if (proc->state == 'R') if (proc->state == 'R')