mirror of https://github.com/xzeldon/htop.git
Darwin: use merged command line helpers
This commit is contained in:
parent
7892ac68fb
commit
8ff4eb72ac
|
@ -96,11 +96,23 @@ static int DarwinProcess_compareByKey(const Process* v1, const Process* v2, Proc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* cmdlineBasenameEnd) {
|
static void DarwinProcess_updateExe(pid_t pid, Process* proc) {
|
||||||
|
char path[PROC_PIDPATHINFO_MAXSIZE];
|
||||||
|
|
||||||
|
int r = proc_pidpath(pid, path, sizeof(path));
|
||||||
|
if (r <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Process_updateExe(proc, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DarwinProcess_updateCmdLine(const struct kinfo_proc* k, Process* proc) {
|
||||||
|
Process_updateComm(proc, k->kp_proc.p_comm);
|
||||||
|
|
||||||
/* This function is from the old Mac version of htop. Originally from ps? */
|
/* This function is from the old Mac version of htop. Originally from ps? */
|
||||||
int mib[3], argmax, nargs, c = 0;
|
int mib[3], argmax, nargs, c = 0;
|
||||||
size_t size;
|
size_t size;
|
||||||
char *procargs, *sp, *np, *cp, *retval;
|
char *procargs, *sp, *np, *cp;
|
||||||
|
|
||||||
/* Get the maximum process arguments size. */
|
/* Get the maximum process arguments size. */
|
||||||
mib[0] = CTL_KERN;
|
mib[0] = CTL_KERN;
|
||||||
|
@ -194,7 +206,7 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* cmdlineBa
|
||||||
/* Save where the argv[0] string starts. */
|
/* Save where the argv[0] string starts. */
|
||||||
sp = cp;
|
sp = cp;
|
||||||
|
|
||||||
*cmdlineBasenameEnd = 0;
|
int end = 0;
|
||||||
for ( np = NULL; c < nargs && cp < &procargs[size]; cp++ ) {
|
for ( np = NULL; c < nargs && cp < &procargs[size]; cp++ ) {
|
||||||
if ( *cp == '\0' ) {
|
if ( *cp == '\0' ) {
|
||||||
c++;
|
c++;
|
||||||
|
@ -204,8 +216,8 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* cmdlineBa
|
||||||
}
|
}
|
||||||
/* Note location of current '\0'. */
|
/* Note location of current '\0'. */
|
||||||
np = cp;
|
np = cp;
|
||||||
if (*cmdlineBasenameEnd == 0) {
|
if (end == 0) {
|
||||||
*cmdlineBasenameEnd = cp - sp;
|
end = cp - sp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,26 +230,22 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* cmdlineBa
|
||||||
/* Empty or unterminated string. */
|
/* Empty or unterminated string. */
|
||||||
goto ERROR_B;
|
goto ERROR_B;
|
||||||
}
|
}
|
||||||
if (*cmdlineBasenameEnd == 0) {
|
if (end == 0) {
|
||||||
*cmdlineBasenameEnd = np - sp;
|
end = np - sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make a copy of the string. */
|
Process_updateCmdline(proc, sp, 0, end);
|
||||||
retval = xStrdup(sp);
|
|
||||||
|
|
||||||
/* Clean up. */
|
/* Clean up. */
|
||||||
free( procargs );
|
free( procargs );
|
||||||
|
|
||||||
return retval;
|
return;
|
||||||
|
|
||||||
ERROR_B:
|
ERROR_B:
|
||||||
free( procargs );
|
free( procargs );
|
||||||
|
|
||||||
ERROR_A:
|
ERROR_A:
|
||||||
*cmdlineBasenameEnd = -1;
|
Process_updateCmdline(proc, k->kp_proc.p_comm, 0, strlen(k->kp_proc.p_comm));
|
||||||
|
|
||||||
retval = xStrdup(k->kp_proc.p_comm);
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps, bool exists) {
|
void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps, bool exists) {
|
||||||
|
@ -284,8 +292,8 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps,
|
||||||
proc->starttime_ctime = ep->p_starttime.tv_sec;
|
proc->starttime_ctime = ep->p_starttime.tv_sec;
|
||||||
Process_fillStarttimeBuffer(proc);
|
Process_fillStarttimeBuffer(proc);
|
||||||
|
|
||||||
proc->cmdline = DarwinProcess_getCmdLine(ps, &proc->cmdlineBasenameEnd);
|
DarwinProcess_updateExe(ep->p_pid, proc);
|
||||||
proc->mergedCommand.cmdlineChanged = true;
|
DarwinProcess_updateCmdLine(ps, proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mutable information */
|
/* Mutable information */
|
||||||
|
|
Loading…
Reference in New Issue