Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/top/machine.c
Show First 20 Lines • Show All 864 Lines • ▼ Show 20 Lines | format_next_process(struct handle * xhandle, char *(*get_userid)(int), int flags) | ||||
const struct kinfo_proc *oldp; | const struct kinfo_proc *oldp; | ||||
long cputime; | long cputime; | ||||
char status[22]; | char status[22]; | ||||
size_t state; | size_t state; | ||||
struct rusage ru, *rup; | struct rusage ru, *rup; | ||||
long p_tot, s_tot; | long p_tot, s_tot; | ||||
char *cmdbuf = NULL; | char *cmdbuf = NULL; | ||||
char **args; | char **args; | ||||
const int cmdlen = 256; | |||||
static struct sbuf* procbuf = NULL; | static struct sbuf* procbuf = NULL; | ||||
/* clean up from last time. */ | /* clean up from last time. */ | ||||
if (procbuf != NULL) { | if (procbuf != NULL) { | ||||
sbuf_clear(procbuf); | sbuf_clear(procbuf); | ||||
} else { | } else { | ||||
procbuf = sbuf_new_auto(); | procbuf = sbuf_new_auto(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | default: | ||||
if (state < nitems(state_abbrev)) { | if (state < nitems(state_abbrev)) { | ||||
sprintf(status, "%.6s", state_abbrev[state]); | sprintf(status, "%.6s", state_abbrev[state]); | ||||
} else { | } else { | ||||
sprintf(status, "?%5zu", state); | sprintf(status, "?%5zu", state); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
cmdbuf = calloc(cmdlen + 1, 1); | cmdbuf = calloc(screen_width + 1, 1); | ||||
if (cmdbuf == NULL) { | if (cmdbuf == NULL) { | ||||
warn("calloc(%d)", cmdlen + 1); | warn("calloc(%d)", screen_width + 1); | ||||
return NULL; | return NULL; | ||||
} | } | ||||
if (!(flags & FMT_SHOWARGS)) { | if (!(flags & FMT_SHOWARGS)) { | ||||
if (ps.thread && pp->ki_flag & P_HADTHREADS && | if (ps.thread && pp->ki_flag & P_HADTHREADS && | ||||
pp->ki_tdname[0]) { | pp->ki_tdname[0]) { | ||||
snprintf(cmdbuf, cmdlen, "%s{%s%s}", pp->ki_comm, | snprintf(cmdbuf, screen_width, "%s{%s%s}", pp->ki_comm, | ||||
pp->ki_tdname, pp->ki_moretdname); | pp->ki_tdname, pp->ki_moretdname); | ||||
} else { | } else { | ||||
snprintf(cmdbuf, cmdlen, "%s", pp->ki_comm); | snprintf(cmdbuf, screen_width, "%s", pp->ki_comm); | ||||
} | } | ||||
} else { | } else { | ||||
if (pp->ki_flag & P_SYSTEM || | if (pp->ki_flag & P_SYSTEM || | ||||
(args = kvm_getargv(kd, pp, cmdlen)) == NULL || | (args = kvm_getargv(kd, pp, screen_width)) == NULL || | ||||
!(*args)) { | !(*args)) { | ||||
if (ps.thread && pp->ki_flag & P_HADTHREADS && | if (ps.thread && pp->ki_flag & P_HADTHREADS && | ||||
pp->ki_tdname[0]) { | pp->ki_tdname[0]) { | ||||
snprintf(cmdbuf, cmdlen, | snprintf(cmdbuf, screen_width, | ||||
"[%s{%s%s}]", pp->ki_comm, pp->ki_tdname, | "[%s{%s%s}]", pp->ki_comm, pp->ki_tdname, | ||||
pp->ki_moretdname); | pp->ki_moretdname); | ||||
} else { | } else { | ||||
snprintf(cmdbuf, cmdlen, | snprintf(cmdbuf, screen_width, | ||||
"[%s]", pp->ki_comm); | "[%s]", pp->ki_comm); | ||||
} | } | ||||
} else { | } else { | ||||
const char *src; | const char *src; | ||||
char *dst, *argbuf; | char *dst, *argbuf; | ||||
const char *cmd; | const char *cmd; | ||||
size_t argbuflen; | size_t argbuflen; | ||||
size_t len; | size_t len; | ||||
argbuflen = cmdlen * 4; | argbuflen = screen_width * 4; | ||||
argbuf = calloc(argbuflen + 1, 1); | argbuf = calloc(argbuflen + 1, 1); | ||||
if (argbuf == NULL) { | if (argbuf == NULL) { | ||||
warn("calloc(%zu)", argbuflen + 1); | warn("calloc(%zu)", argbuflen + 1); | ||||
free(cmdbuf); | free(cmdbuf); | ||||
return NULL; | return NULL; | ||||
} | } | ||||
dst = argbuf; | dst = argbuf; | ||||
Show All 19 Lines | if (pp->ki_flag & P_SYSTEM || | ||||
} | } | ||||
if (dst != argbuf && dst[-1] == ' ') | if (dst != argbuf && dst[-1] == ' ') | ||||
dst--; | dst--; | ||||
*dst = '\0'; | *dst = '\0'; | ||||
if (strcmp(cmd, pp->ki_comm) != 0) { | if (strcmp(cmd, pp->ki_comm) != 0) { | ||||
if (ps.thread && pp->ki_flag & P_HADTHREADS && | if (ps.thread && pp->ki_flag & P_HADTHREADS && | ||||
pp->ki_tdname[0]) | pp->ki_tdname[0]) | ||||
snprintf(cmdbuf, cmdlen, | snprintf(cmdbuf, screen_width, | ||||
"%s (%s){%s%s}", argbuf, | "%s (%s){%s%s}", argbuf, | ||||
pp->ki_comm, pp->ki_tdname, | pp->ki_comm, pp->ki_tdname, | ||||
pp->ki_moretdname); | pp->ki_moretdname); | ||||
else | else | ||||
snprintf(cmdbuf, cmdlen, | snprintf(cmdbuf, screen_width, | ||||
"%s (%s)", argbuf, pp->ki_comm); | "%s (%s)", argbuf, pp->ki_comm); | ||||
} else { | } else { | ||||
if (ps.thread && pp->ki_flag & P_HADTHREADS && | if (ps.thread && pp->ki_flag & P_HADTHREADS && | ||||
pp->ki_tdname[0]) | pp->ki_tdname[0]) | ||||
snprintf(cmdbuf, cmdlen, | snprintf(cmdbuf, screen_width, | ||||
"%s{%s%s}", argbuf, pp->ki_tdname, | "%s{%s%s}", argbuf, pp->ki_tdname, | ||||
pp->ki_moretdname); | pp->ki_moretdname); | ||||
else | else | ||||
strlcpy(cmdbuf, argbuf, cmdlen); | strlcpy(cmdbuf, argbuf, screen_width); | ||||
} | } | ||||
free(argbuf); | free(argbuf); | ||||
} | } | ||||
} | } | ||||
if (displaymode == DISP_IO) { | if (displaymode == DISP_IO) { | ||||
oldp = get_old_proc(pp); | oldp = get_old_proc(pp); | ||||
if (oldp != NULL) { | if (oldp != NULL) { | ||||
▲ Show 20 Lines • Show All 518 Lines • Show Last 20 Lines |