mirror of https://github.com/xzeldon/htop.git
Implements the NetBSD specific changes for makeCommandStr refactor.
Refer to #388 PR for more details.
This commit is contained in:
parent
fa65c30976
commit
9de463e756
|
@ -183,6 +183,12 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.pidColumn = true,
|
.pidColumn = true,
|
||||||
},
|
},
|
||||||
|
[PROC_COMM] = {
|
||||||
|
.name = "COMM",
|
||||||
|
.title = "COMM ",
|
||||||
|
.description = "comm string of the process",
|
||||||
|
.flags = 0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Process* NetBSDProcess_new(const Settings* settings) {
|
Process* NetBSDProcess_new(const Settings* settings) {
|
||||||
|
@ -235,7 +241,3 @@ const ProcessClass NetBSDProcess_class = {
|
||||||
.writeField = NetBSDProcess_writeField,
|
.writeField = NetBSDProcess_writeField,
|
||||||
.compareByKey = NetBSDProcess_compareByKey
|
.compareByKey = NetBSDProcess_compareByKey
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Process_isThread(const Process* this) {
|
|
||||||
return Process_isKernelThread(this) || Process_isUserlandThread(this);
|
|
||||||
}
|
|
||||||
|
|
|
@ -21,10 +21,6 @@ typedef struct NetBSDProcess_ {
|
||||||
Process super;
|
Process super;
|
||||||
} NetBSDProcess;
|
} NetBSDProcess;
|
||||||
|
|
||||||
#define Process_isKernelThread(_process) (_process->pgrp == 0)
|
|
||||||
|
|
||||||
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
|
||||||
|
|
||||||
extern const ProcessClass NetBSDProcess_class;
|
extern const ProcessClass NetBSDProcess_class;
|
||||||
|
|
||||||
extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD];
|
extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD];
|
||||||
|
@ -33,6 +29,4 @@ Process* NetBSDProcess_new(const Settings* settings);
|
||||||
|
|
||||||
void Process_delete(Object* cast);
|
void Process_delete(Object* cast);
|
||||||
|
|
||||||
bool Process_isThread(const Process* this);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -114,15 +114,17 @@ static void NetBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||||
pl->usedSwap = uvmexp.swpginuse * pageSizeKB;
|
pl->usedSwap = uvmexp.swpginuse * pageSizeKB;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* NetBSDProcessList_readProcessName(kvm_t* kd, const struct kinfo_proc2* kproc, int* basenameEnd) {
|
static void NetBSDProcessList_updateProcessName(kvm_t* kd, const struct kinfo_proc2* kproc, Process* proc) {
|
||||||
|
Process_updateComm(proc, kproc->p_comm);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Like NetBSD's top(1), we try to fall back to the command name
|
* Like NetBSD's top(1), we try to fall back to the command name
|
||||||
* (argv[0]) if we fail to construct the full command.
|
* (argv[0]) if we fail to construct the full command.
|
||||||
*/
|
*/
|
||||||
char** arg = kvm_getargv2(kd, kproc, 500);
|
char** arg = kvm_getargv2(kd, kproc, 500);
|
||||||
if (arg == NULL || *arg == NULL) {
|
if (arg == NULL || *arg == NULL) {
|
||||||
*basenameEnd = strlen(kproc->p_comm);
|
Process_updateCmdline(proc, kproc->p_comm, 0, strlen(kproc->p_comm));
|
||||||
return xStrdup(kproc->p_comm);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
@ -133,22 +135,30 @@ static char* NetBSDProcessList_readProcessName(kvm_t* kd, const struct kinfo_pro
|
||||||
/* don't use xMalloc here - we want to handle huge argv's gracefully */
|
/* don't use xMalloc here - we want to handle huge argv's gracefully */
|
||||||
char* s;
|
char* s;
|
||||||
if ((s = malloc(len)) == NULL) {
|
if ((s = malloc(len)) == NULL) {
|
||||||
*basenameEnd = strlen(kproc->p_comm);
|
Process_updateCmdline(proc, kproc->p_comm, 0, strlen(kproc->p_comm));
|
||||||
return xStrdup(kproc->p_comm);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
|
|
||||||
|
int start = 0;
|
||||||
|
int end = 0;
|
||||||
for (int i = 0; arg[i] != NULL; i++) {
|
for (int i = 0; arg[i] != NULL; i++) {
|
||||||
size_t n = strlcat(s, arg[i], len);
|
size_t n = strlcat(s, arg[i], len);
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
*basenameEnd = MINIMUM(n, len - 1);
|
end = MINIMUM(n, len - 1);
|
||||||
|
/* check if cmdline ended earlier, e.g 'kdeinit5: Running...' */
|
||||||
|
for (int j = end; j > 0; j--) {
|
||||||
|
if (arg[0][j] == ' ' && arg[0][j-1] != '\\') {
|
||||||
|
end = (arg[0][j-1] == ':') ? (j-1) : j;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* the trailing space should get truncated anyway */
|
/* the trailing space should get truncated anyway */
|
||||||
strlcat(s, " ", len);
|
strlcat(s, " ", len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
Process_updateCmdline(proc, s, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -185,16 +195,18 @@ static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) {
|
||||||
proc->session = kproc->p_sid;
|
proc->session = kproc->p_sid;
|
||||||
proc->tty_nr = kproc->p_tdev;
|
proc->tty_nr = kproc->p_tdev;
|
||||||
proc->pgrp = kproc->p__pgid;
|
proc->pgrp = kproc->p__pgid;
|
||||||
|
proc->isKernelThread = proc->pgrp == 0;
|
||||||
|
proc->isUserlandThread = proc->pid != proc->tgid;
|
||||||
proc->st_uid = kproc->p_uid;
|
proc->st_uid = kproc->p_uid;
|
||||||
proc->starttime_ctime = kproc->p_ustart_sec;
|
proc->starttime_ctime = kproc->p_ustart_sec;
|
||||||
Process_fillStarttimeBuffer(proc);
|
Process_fillStarttimeBuffer(proc);
|
||||||
proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid);
|
proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid);
|
||||||
ProcessList_add(&this->super, proc);
|
ProcessList_add(&this->super, proc);
|
||||||
proc->comm = NetBSDProcessList_readProcessName(this->kd, kproc, &proc->basenameOffset);
|
|
||||||
|
NetBSDProcessList_updateProcessName(this->kd, kproc, proc);
|
||||||
} else {
|
} else {
|
||||||
if (settings->updateProcessNames) {
|
if (settings->updateProcessNames) {
|
||||||
free(proc->comm);
|
NetBSDProcessList_updateProcessName(this->kd, kproc, proc);
|
||||||
proc->comm = NetBSDProcessList_readProcessName(this->kd, kproc, &proc->basenameOffset);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue