Correct style bugs. Don't skip zombies in cputime(), according to Bruce,
zombie CPU times are valid. Adjust array size in strftime(3). Submitted by: Bruce
This commit is contained in:
parent
10eeb10c63
commit
b85add5f31
@ -106,11 +106,9 @@ arguments(KINFO *k, VARENT *ve)
|
||||
char *cp, *vis_args;
|
||||
|
||||
v = ve->var;
|
||||
|
||||
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
|
||||
errx(1, "malloc failed");
|
||||
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
|
||||
|
||||
if (ve->next == NULL) {
|
||||
/* last field */
|
||||
if (termwidth == UNLIMITED) {
|
||||
@ -136,7 +134,6 @@ command(KINFO *k, VARENT *ve)
|
||||
char *cp, *vis_env, *vis_args;
|
||||
|
||||
v = ve->var;
|
||||
|
||||
if (cflag) {
|
||||
if (ve->next == NULL) /* last field, don't pad */
|
||||
(void)printf("%s", k->ki_p->ki_comm);
|
||||
@ -144,7 +141,6 @@ command(KINFO *k, VARENT *ve)
|
||||
(void)printf("%-*s", v->width, k->ki_p->ki_comm);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
|
||||
errx(1, "malloc failed");
|
||||
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
|
||||
@ -387,28 +383,26 @@ started(KINFO *k, VARENT *ve)
|
||||
VAR *v;
|
||||
time_t then;
|
||||
struct tm *tp;
|
||||
char buf[100];
|
||||
static int use_ampm = -1;
|
||||
char buf[100];
|
||||
|
||||
v = ve->var;
|
||||
if (!k->ki_valid) {
|
||||
(void)printf("%-*s", v->width, "-");
|
||||
return;
|
||||
}
|
||||
|
||||
if (use_ampm < 0)
|
||||
use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
|
||||
|
||||
then = k->ki_p->ki_start.tv_sec;
|
||||
tp = localtime(&then);
|
||||
if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
|
||||
(void)strftime(buf, sizeof(buf) - 1,
|
||||
(void)strftime(buf, sizeof(buf),
|
||||
use_ampm ? "%l:%M%p" : "%k:%M ", tp);
|
||||
} else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) {
|
||||
(void)strftime(buf, sizeof(buf) - 1,
|
||||
(void)strftime(buf, sizeof(buf),
|
||||
use_ampm ? "%a%I%p" : "%a%H ", tp);
|
||||
} else
|
||||
(void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp);
|
||||
(void)strftime(buf, sizeof(buf), "%e%b%y", tp);
|
||||
(void)printf("%-*s", v->width, buf);
|
||||
}
|
||||
|
||||
@ -425,7 +419,7 @@ lstarted(KINFO *k, VARENT *ve)
|
||||
return;
|
||||
}
|
||||
then = k->ki_p->ki_start.tv_sec;
|
||||
(void)strftime(buf, sizeof(buf) -1, "%c", localtime(&then));
|
||||
(void)strftime(buf, sizeof(buf), "%c", localtime(&then));
|
||||
(void)printf("%-*s", v->width, buf);
|
||||
}
|
||||
|
||||
@ -458,10 +452,9 @@ wchan(KINFO *k, VARENT *ve)
|
||||
else
|
||||
(void)printf("%-*lx", v->width,
|
||||
(long)k->ki_p->ki_wchan);
|
||||
} else {
|
||||
} else
|
||||
(void)printf("%-*s", v->width, "-");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mwchan(KINFO *k, VARENT *ve)
|
||||
@ -480,13 +473,11 @@ mwchan(KINFO *k, VARENT *ve)
|
||||
if (k->ki_p->ki_lockname[0]) {
|
||||
(void)printf("%-*.*s", v->width, v->width,
|
||||
k->ki_p->ki_lockname);
|
||||
} else {
|
||||
} else
|
||||
(void)printf("%-*s", v->width, "???");
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
(void)printf("%-*s", v->width, "-");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
vsize(KINFO *k, VARENT *ve)
|
||||
@ -504,12 +495,12 @@ cputime(KINFO *k, VARENT *ve)
|
||||
long secs;
|
||||
long psecs; /* "parts" of a second. first micro, then centi */
|
||||
char obuff[128];
|
||||
static char decimal_point = 0;
|
||||
static char decimal_point;
|
||||
|
||||
if (!decimal_point)
|
||||
if (decimal_point == '\0')
|
||||
decimal_point = localeconv()->decimal_point[0];
|
||||
v = ve->var;
|
||||
if (k->ki_p->ki_stat == SZOMB || !k->ki_valid) {
|
||||
if (!k->ki_valid) {
|
||||
secs = 0;
|
||||
psecs = 0;
|
||||
} else {
|
||||
@ -531,8 +522,8 @@ cputime(KINFO *k, VARENT *ve)
|
||||
secs += psecs / 100;
|
||||
psecs = psecs % 100;
|
||||
}
|
||||
(void)snprintf(obuff, sizeof(obuff),
|
||||
"%3ld:%02ld%c%02ld", secs/60, secs%60, decimal_point, psecs);
|
||||
(void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld%c%02ld",
|
||||
secs / 60, secs % 60, decimal_point, psecs);
|
||||
(void)printf("%*s", v->width, obuff);
|
||||
}
|
||||
|
||||
@ -540,30 +531,26 @@ void
|
||||
elapsed(KINFO *k, VARENT *ve)
|
||||
{
|
||||
VAR *v;
|
||||
time_t days, hours, mins, secs;
|
||||
time_t val;
|
||||
int days, hours, mins, secs;
|
||||
char obuff[128];
|
||||
|
||||
v = ve->var;
|
||||
|
||||
secs = now - k->ki_p->ki_start.tv_sec;
|
||||
days = secs/(24*60*60);
|
||||
secs %= (24*60*60);
|
||||
hours = secs/(60*60);
|
||||
secs %= (60*60);
|
||||
mins = secs/60;
|
||||
secs %= 60;
|
||||
if (days != 0) {
|
||||
(void)snprintf(obuff, sizeof(obuff), "%3ld-%02ld:%02ld:%02ld",
|
||||
(long)days, (long)hours, (long)mins, (long)secs);
|
||||
}
|
||||
else if (hours != 0) {
|
||||
(void)snprintf(obuff, sizeof(obuff), "%02ld:%02ld:%02ld",
|
||||
(long)hours, (long)mins, (long)secs);
|
||||
}
|
||||
else {
|
||||
(void)snprintf(obuff, sizeof(obuff), "%02ld:%02ld",
|
||||
(long)mins, (long)secs);
|
||||
}
|
||||
val = now - k->ki_p->ki_start.tv_sec;
|
||||
days = val / (24 * 60 * 60);
|
||||
val %= 24 * 60 * 60;
|
||||
hours = val / (60 * 60);
|
||||
val %= 60 * 60;
|
||||
mins = val / 60;
|
||||
secs = val % 60;
|
||||
if (days != 0)
|
||||
(void)snprintf(obuff, sizeof(obuff), "%3d-%02d:%02d:%02d",
|
||||
days, hours, mins, secs);
|
||||
else if (hours != 0)
|
||||
(void)snprintf(obuff, sizeof(obuff), "%02d:%02d:%02d",
|
||||
hours, mins, secs);
|
||||
else
|
||||
(void)snprintf(obuff, sizeof(obuff), "%02d:%02d", mins, secs);
|
||||
(void)printf("%*s", v->width, obuff);
|
||||
}
|
||||
|
||||
@ -757,25 +744,22 @@ void
|
||||
label(KINFO *k, VARENT *ve)
|
||||
{
|
||||
char *string;
|
||||
VAR *v;
|
||||
mac_t proclabel;
|
||||
int error;
|
||||
VAR *v;
|
||||
|
||||
v = ve->var;
|
||||
string = NULL;
|
||||
|
||||
if (mac_prepare_process_label(&proclabel) == -1) {
|
||||
perror("mac_prepare_process_label");
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = mac_get_pid(k->ki_p->ki_pid, proclabel);
|
||||
if (error == 0) {
|
||||
if (mac_to_text(proclabel, &string) == -1)
|
||||
string = NULL;
|
||||
}
|
||||
mac_free(proclabel);
|
||||
|
||||
out:
|
||||
if (string != NULL) {
|
||||
(void)printf("%-*s", v->width, string);
|
||||
|
Loading…
x
Reference in New Issue
Block a user