xref: /freebsd/bin/ps/print.c (revision 7bd5296d2908712067ff0b689a27c928a9b75128)
14b88c807SRodney W. Grimes /*-
24b88c807SRodney W. Grimes  * Copyright (c) 1990, 1993, 1994
34b88c807SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
44b88c807SRodney W. Grimes  *
54b88c807SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
64b88c807SRodney W. Grimes  * modification, are permitted provided that the following conditions
74b88c807SRodney W. Grimes  * are met:
84b88c807SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
94b88c807SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
104b88c807SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
114b88c807SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
124b88c807SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
134b88c807SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
144b88c807SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
154b88c807SRodney W. Grimes  *    without specific prior written permission.
164b88c807SRodney W. Grimes  *
174b88c807SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
184b88c807SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
194b88c807SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
204b88c807SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
214b88c807SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
224b88c807SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
234b88c807SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
244b88c807SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
254b88c807SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
264b88c807SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
274b88c807SRodney W. Grimes  * SUCH DAMAGE.
284b88c807SRodney W. Grimes  */
294b88c807SRodney W. Grimes 
30c9a8d1f4SPhilippe Charnier #if 0
31871e8d8cSMark Murray #ifndef lint
32c9a8d1f4SPhilippe Charnier static char sccsid[] = "@(#)print.c	8.6 (Berkeley) 4/16/94";
334b88c807SRodney W. Grimes #endif /* not lint */
34871e8d8cSMark Murray #endif
35eaed5652SPhilippe Charnier 
362749b141SDavid E. O'Brien #include <sys/cdefs.h>
372749b141SDavid E. O'Brien __FBSDID("$FreeBSD$");
384b88c807SRodney W. Grimes 
394b88c807SRodney W. Grimes #include <sys/param.h>
404b88c807SRodney W. Grimes #include <sys/time.h>
414b88c807SRodney W. Grimes #include <sys/resource.h>
424b88c807SRodney W. Grimes #include <sys/proc.h>
434b88c807SRodney W. Grimes #include <sys/stat.h>
444b88c807SRodney W. Grimes 
452af538ebSRobert Watson #include <sys/mac.h>
468b9b0e39SPoul-Henning Kamp #include <sys/user.h>
474b88c807SRodney W. Grimes #include <sys/sysctl.h>
484b88c807SRodney W. Grimes 
494b88c807SRodney W. Grimes #include <err.h>
50576541a9SWarner Losh #include <grp.h>
51f59105eeSAndrey A. Chernov #include <langinfo.h>
528073a93cSAndrey A. Chernov #include <locale.h>
534b88c807SRodney W. Grimes #include <math.h>
544b88c807SRodney W. Grimes #include <nlist.h>
55576541a9SWarner Losh #include <pwd.h>
564b88c807SRodney W. Grimes #include <stddef.h>
574b88c807SRodney W. Grimes #include <stdio.h>
584b88c807SRodney W. Grimes #include <stdlib.h>
594b88c807SRodney W. Grimes #include <string.h>
60871e8d8cSMark Murray #include <unistd.h>
614b88c807SRodney W. Grimes #include <vis.h>
624b88c807SRodney W. Grimes 
634b88c807SRodney W. Grimes #include "ps.h"
644b88c807SRodney W. Grimes 
656327ab9cSPeter Wemm #define	ps_pgtok(a)	(((a) * getpagesize()) / 1024)
66871e8d8cSMark Murray 
674b88c807SRodney W. Grimes void
6846251ddeSWarner Losh printheader(void)
694b88c807SRodney W. Grimes {
704b88c807SRodney W. Grimes 	VAR *v;
714b88c807SRodney W. Grimes 	struct varent *vent;
724b88c807SRodney W. Grimes 
73bdf8ab46SGarance A Drosehn 	STAILQ_FOREACH(vent, &varlist, next_ve)
74bdf8ab46SGarance A Drosehn 		if (*vent->header != '\0')
7501e5f166STim J. Robbins 			break;
76bdf8ab46SGarance A Drosehn 	if (!vent)
7701e5f166STim J. Robbins 		return;
78bdf8ab46SGarance A Drosehn 
79bdf8ab46SGarance A Drosehn 	STAILQ_FOREACH(vent, &varlist, next_ve) {
804b88c807SRodney W. Grimes 		v = vent->var;
814b88c807SRodney W. Grimes 		if (v->flag & LJUST) {
82bdf8ab46SGarance A Drosehn 			if (STAILQ_NEXT(vent, next_ve) == NULL)	/* last one */
8378b1878aSJuli Mallett 				(void)printf("%s", vent->header);
844b88c807SRodney W. Grimes 			else
8578b1878aSJuli Mallett 				(void)printf("%-*s", v->width, vent->header);
864b88c807SRodney W. Grimes 		} else
8778b1878aSJuli Mallett 			(void)printf("%*s", v->width, vent->header);
88bdf8ab46SGarance A Drosehn 		if (STAILQ_NEXT(vent, next_ve) != NULL)
894b88c807SRodney W. Grimes 			(void)putchar(' ');
904b88c807SRodney W. Grimes 	}
914b88c807SRodney W. Grimes 	(void)putchar('\n');
924b88c807SRodney W. Grimes }
934b88c807SRodney W. Grimes 
944b88c807SRodney W. Grimes void
9503334017SJuli Mallett arguments(KINFO *k, VARENT *ve)
9603334017SJuli Mallett {
9703334017SJuli Mallett 	VAR *v;
9803334017SJuli Mallett 	int left;
9903334017SJuli Mallett 	char *cp, *vis_args;
10003334017SJuli Mallett 
10103334017SJuli Mallett 	v = ve->var;
10203334017SJuli Mallett 	if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
10303334017SJuli Mallett 		errx(1, "malloc failed");
10403334017SJuli Mallett 	strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
105bdf8ab46SGarance A Drosehn 	if (STAILQ_NEXT(ve, next_ve) == NULL) {
10603334017SJuli Mallett 		/* last field */
10703334017SJuli Mallett 		if (termwidth == UNLIMITED) {
10803334017SJuli Mallett 			(void)printf("%s", vis_args);
10903334017SJuli Mallett 		} else {
11003334017SJuli Mallett 			left = termwidth - (totwidth - v->width);
11103334017SJuli Mallett 			if (left < 1) /* already wrapped, just use std width */
11203334017SJuli Mallett 				left = v->width;
11303334017SJuli Mallett 			for (cp = vis_args; --left >= 0 && *cp != '\0';)
11403334017SJuli Mallett 				(void)putchar(*cp++);
11503334017SJuli Mallett 		}
11603334017SJuli Mallett 	} else {
11703334017SJuli Mallett 		(void)printf("%-*.*s", v->width, v->width, vis_args);
11803334017SJuli Mallett 	}
11903334017SJuli Mallett 	free(vis_args);
12003334017SJuli Mallett }
12103334017SJuli Mallett 
12203334017SJuli Mallett void
12346251ddeSWarner Losh command(KINFO *k, VARENT *ve)
1244b88c807SRodney W. Grimes {
1254b88c807SRodney W. Grimes 	VAR *v;
1264b88c807SRodney W. Grimes 	int left;
1274b88c807SRodney W. Grimes 	char *cp, *vis_env, *vis_args;
1284b88c807SRodney W. Grimes 
129db91faacSPeter Wemm 	v = ve->var;
130db91faacSPeter Wemm 	if (cflag) {
131bdf8ab46SGarance A Drosehn 		/* If it is the last field, then don't pad */
132bdf8ab46SGarance A Drosehn 		if (STAILQ_NEXT(ve, next_ve) == NULL)
1331f7d2501SKirk McKusick 			(void)printf("%s", k->ki_p->ki_comm);
1343cc273e0SJohn Polstra 		else
1351f7d2501SKirk McKusick 			(void)printf("%-*s", v->width, k->ki_p->ki_comm);
136db91faacSPeter Wemm 		return;
137db91faacSPeter Wemm 	}
1384b88c807SRodney W. Grimes 	if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
1394fa7d788SJuli Mallett 		errx(1, "malloc failed");
1404b88c807SRodney W. Grimes 	strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
1414b88c807SRodney W. Grimes 	if (k->ki_env) {
1424b88c807SRodney W. Grimes 		if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1)) == NULL)
1434fa7d788SJuli Mallett 			errx(1, "malloc failed");
1444b88c807SRodney W. Grimes 		strvis(vis_env, k->ki_env, VIS_TAB | VIS_NL | VIS_NOSLASH);
1454b88c807SRodney W. Grimes 	} else
1464b88c807SRodney W. Grimes 		vis_env = NULL;
1474b88c807SRodney W. Grimes 
148bdf8ab46SGarance A Drosehn 	if (STAILQ_NEXT(ve, next_ve) == NULL) {
1494b88c807SRodney W. Grimes 		/* last field */
1504b88c807SRodney W. Grimes 		if (termwidth == UNLIMITED) {
1514b88c807SRodney W. Grimes 			if (vis_env)
1524b88c807SRodney W. Grimes 				(void)printf("%s ", vis_env);
1534b88c807SRodney W. Grimes 			(void)printf("%s", vis_args);
1544b88c807SRodney W. Grimes 		} else {
1554b88c807SRodney W. Grimes 			left = termwidth - (totwidth - v->width);
1564b88c807SRodney W. Grimes 			if (left < 1) /* already wrapped, just use std width */
1574b88c807SRodney W. Grimes 				left = v->width;
1584b88c807SRodney W. Grimes 			if ((cp = vis_env) != NULL) {
1594b88c807SRodney W. Grimes 				while (--left >= 0 && *cp)
1604b88c807SRodney W. Grimes 					(void)putchar(*cp++);
1614b88c807SRodney W. Grimes 				if (--left >= 0)
1624b88c807SRodney W. Grimes 					putchar(' ');
1634b88c807SRodney W. Grimes 			}
1644b88c807SRodney W. Grimes 			for (cp = vis_args; --left >= 0 && *cp != '\0';)
1654b88c807SRodney W. Grimes 				(void)putchar(*cp++);
1664b88c807SRodney W. Grimes 		}
1674b88c807SRodney W. Grimes 	} else
1684b88c807SRodney W. Grimes 		/* XXX env? */
1694b88c807SRodney W. Grimes 		(void)printf("%-*.*s", v->width, v->width, vis_args);
1704b88c807SRodney W. Grimes 	free(vis_args);
1714b88c807SRodney W. Grimes 	if (vis_env != NULL)
1724b88c807SRodney W. Grimes 		free(vis_env);
1734b88c807SRodney W. Grimes }
1744b88c807SRodney W. Grimes 
1754b88c807SRodney W. Grimes void
17646251ddeSWarner Losh ucomm(KINFO *k, VARENT *ve)
1774b88c807SRodney W. Grimes {
1784b88c807SRodney W. Grimes 	VAR *v;
1794b88c807SRodney W. Grimes 
1804b88c807SRodney W. Grimes 	v = ve->var;
181bdf8ab46SGarance A Drosehn 	if (STAILQ_NEXT(ve, next_ve) == NULL)	/* last field, don't pad */
1824e8a8d9fSGarance A Drosehn 		(void)printf("%s", k->ki_p->ki_comm);
1834e8a8d9fSGarance A Drosehn 	else
1841f7d2501SKirk McKusick 		(void)printf("%-*s", v->width, k->ki_p->ki_comm);
1854b88c807SRodney W. Grimes }
1864b88c807SRodney W. Grimes 
1874b88c807SRodney W. Grimes void
18846251ddeSWarner Losh logname(KINFO *k, VARENT *ve)
1894b88c807SRodney W. Grimes {
1904b88c807SRodney W. Grimes 	VAR *v;
191ad863cacSSteve Price 	char *s;
1924b88c807SRodney W. Grimes 
1934b88c807SRodney W. Grimes 	v = ve->var;
1941f7d2501SKirk McKusick 	(void)printf("%-*s", v->width, (s = k->ki_p->ki_login, *s) ? s : "-");
1954b88c807SRodney W. Grimes }
1964b88c807SRodney W. Grimes 
1974b88c807SRodney W. Grimes void
19846251ddeSWarner Losh state(KINFO *k, VARENT *ve)
1994b88c807SRodney W. Grimes {
200b40ce416SJulian Elischer 	int flag, sflag, tdflags;
2014b88c807SRodney W. Grimes 	char *cp;
2024b88c807SRodney W. Grimes 	VAR *v;
2034b88c807SRodney W. Grimes 	char buf[16];
2044b88c807SRodney W. Grimes 
2054b88c807SRodney W. Grimes 	v = ve->var;
2061f7d2501SKirk McKusick 	flag = k->ki_p->ki_flag;
207564efb8fSTor Egge 	sflag = k->ki_p->ki_sflag;
208b40ce416SJulian Elischer 	tdflags = k->ki_p->ki_tdflags;	/* XXXKSE */
2094b88c807SRodney W. Grimes 	cp = buf;
2104b88c807SRodney W. Grimes 
2111f7d2501SKirk McKusick 	switch (k->ki_p->ki_stat) {
2124b88c807SRodney W. Grimes 
2134b88c807SRodney W. Grimes 	case SSTOP:
2144b88c807SRodney W. Grimes 		*cp = 'T';
2154b88c807SRodney W. Grimes 		break;
2164b88c807SRodney W. Grimes 
2174b88c807SRodney W. Grimes 	case SSLEEP:
218b40ce416SJulian Elischer 		if (tdflags & TDF_SINTR)	/* interruptable (long) */
2191f7d2501SKirk McKusick 			*cp = k->ki_p->ki_slptime >= MAXSLP ? 'I' : 'S';
2204b88c807SRodney W. Grimes 		else
2214b88c807SRodney W. Grimes 			*cp = 'D';
2224b88c807SRodney W. Grimes 		break;
2234b88c807SRodney W. Grimes 
2244b88c807SRodney W. Grimes 	case SRUN:
2254b88c807SRodney W. Grimes 	case SIDL:
2264b88c807SRodney W. Grimes 		*cp = 'R';
2274b88c807SRodney W. Grimes 		break;
2284b88c807SRodney W. Grimes 
2290384fff8SJason Evans 	case SWAIT:
2300384fff8SJason Evans 		*cp = 'W';
2310384fff8SJason Evans 		break;
2320384fff8SJason Evans 
2330d632649SJohn Baldwin 	case SLOCK:
2340d632649SJohn Baldwin 		*cp = 'L';
2350384fff8SJason Evans 		break;
2360384fff8SJason Evans 
2374b88c807SRodney W. Grimes 	case SZOMB:
2384b88c807SRodney W. Grimes 		*cp = 'Z';
2394b88c807SRodney W. Grimes 		break;
2404b88c807SRodney W. Grimes 
2414b88c807SRodney W. Grimes 	default:
2424b88c807SRodney W. Grimes 		*cp = '?';
2434b88c807SRodney W. Grimes 	}
2444b88c807SRodney W. Grimes 	cp++;
245e0aa5ab7SJohn Baldwin 	if (!(sflag & PS_INMEM))
2464b88c807SRodney W. Grimes 		*cp++ = 'W';
2471f7d2501SKirk McKusick 	if (k->ki_p->ki_nice < NZERO)
2484b88c807SRodney W. Grimes 		*cp++ = '<';
2491f7d2501SKirk McKusick 	else if (k->ki_p->ki_nice > NZERO)
2504b88c807SRodney W. Grimes 		*cp++ = 'N';
2514b88c807SRodney W. Grimes 	if (flag & P_TRACED)
2524b88c807SRodney W. Grimes 		*cp++ = 'X';
2531f7d2501SKirk McKusick 	if (flag & P_WEXIT && k->ki_p->ki_stat != SZOMB)
2544b88c807SRodney W. Grimes 		*cp++ = 'E';
2554b88c807SRodney W. Grimes 	if (flag & P_PPWAIT)
2564b88c807SRodney W. Grimes 		*cp++ = 'V';
2571f7d2501SKirk McKusick 	if ((flag & P_SYSTEM) || k->ki_p->ki_lock > 0)
2584b88c807SRodney W. Grimes 		*cp++ = 'L';
2591f7d2501SKirk McKusick 	if (k->ki_p->ki_kiflag & KI_SLEADER)
2604b88c807SRodney W. Grimes 		*cp++ = 's';
2611f7d2501SKirk McKusick 	if ((flag & P_CONTROLT) && k->ki_p->ki_pgid == k->ki_p->ki_tpgid)
2624b88c807SRodney W. Grimes 		*cp++ = '+';
26375c13541SPoul-Henning Kamp 	if (flag & P_JAILED)
26475c13541SPoul-Henning Kamp 		*cp++ = 'J';
2654b88c807SRodney W. Grimes 	*cp = '\0';
2664b88c807SRodney W. Grimes 	(void)printf("%-*s", v->width, buf);
2674b88c807SRodney W. Grimes }
2684b88c807SRodney W. Grimes 
269820434b2SGarance A Drosehn #define	scalepri(x)	((x) - PZERO)
270820434b2SGarance A Drosehn 
2714b88c807SRodney W. Grimes void
27246251ddeSWarner Losh pri(KINFO *k, VARENT *ve)
2734b88c807SRodney W. Grimes {
2744b88c807SRodney W. Grimes 	VAR *v;
2754b88c807SRodney W. Grimes 
2764b88c807SRodney W. Grimes 	v = ve->var;
277820434b2SGarance A Drosehn 	(void)printf("%*d", v->width, scalepri(k->ki_p->ki_pri.pri_level));
2784b88c807SRodney W. Grimes }
2794b88c807SRodney W. Grimes 
2804b88c807SRodney W. Grimes void
281820434b2SGarance A Drosehn upr(KINFO *k, VARENT *ve)
282820434b2SGarance A Drosehn {
283820434b2SGarance A Drosehn 	VAR *v;
284820434b2SGarance A Drosehn 
285820434b2SGarance A Drosehn 	v = ve->var;
286820434b2SGarance A Drosehn 	(void)printf("%*d", v->width, scalepri(k->ki_p->ki_pri.pri_user));
287820434b2SGarance A Drosehn }
288820434b2SGarance A Drosehn #undef scalepri
289820434b2SGarance A Drosehn 
290820434b2SGarance A Drosehn void
29146251ddeSWarner Losh uname(KINFO *k, VARENT *ve)
2924b88c807SRodney W. Grimes {
2934b88c807SRodney W. Grimes 	VAR *v;
2944b88c807SRodney W. Grimes 
2954b88c807SRodney W. Grimes 	v = ve->var;
296e8eef4bbSJuli Mallett 	(void)printf("%-*s", v->width, user_from_uid(k->ki_p->ki_uid, 0));
2974b88c807SRodney W. Grimes }
2984b88c807SRodney W. Grimes 
2996a2d726bSJordan K. Hubbard int
30046251ddeSWarner Losh s_uname(KINFO *k)
3016a2d726bSJordan K. Hubbard {
3021f7d2501SKirk McKusick 	return (strlen(user_from_uid(k->ki_p->ki_uid, 0)));
3036a2d726bSJordan K. Hubbard }
3046a2d726bSJordan K. Hubbard 
3054b88c807SRodney W. Grimes void
306e8eef4bbSJuli Mallett rgroupname(KINFO *k, VARENT *ve)
307e8eef4bbSJuli Mallett {
308e8eef4bbSJuli Mallett 	VAR *v;
309e8eef4bbSJuli Mallett 
310e8eef4bbSJuli Mallett 	v = ve->var;
311e8eef4bbSJuli Mallett 	(void)printf("%-*s", v->width, group_from_gid(k->ki_p->ki_rgid, 0));
312e8eef4bbSJuli Mallett }
313e8eef4bbSJuli Mallett 
314e8eef4bbSJuli Mallett int
315e8eef4bbSJuli Mallett s_rgroupname(KINFO *k)
316e8eef4bbSJuli Mallett {
317e8eef4bbSJuli Mallett 	return (strlen(group_from_gid(k->ki_p->ki_rgid, 0)));
318e8eef4bbSJuli Mallett }
319e8eef4bbSJuli Mallett 
320e8eef4bbSJuli Mallett void
32146251ddeSWarner Losh runame(KINFO *k, VARENT *ve)
3224b88c807SRodney W. Grimes {
3234b88c807SRodney W. Grimes 	VAR *v;
3244b88c807SRodney W. Grimes 
3254b88c807SRodney W. Grimes 	v = ve->var;
326e8eef4bbSJuli Mallett 	(void)printf("%-*s", v->width, user_from_uid(k->ki_p->ki_ruid, 0));
3274b88c807SRodney W. Grimes }
3284b88c807SRodney W. Grimes 
3296a2d726bSJordan K. Hubbard int
33046251ddeSWarner Losh s_runame(KINFO *k)
3316a2d726bSJordan K. Hubbard {
3321f7d2501SKirk McKusick 	return (strlen(user_from_uid(k->ki_p->ki_ruid, 0)));
3336a2d726bSJordan K. Hubbard }
3346a2d726bSJordan K. Hubbard 
335f3073b05SJuli Mallett 
336f3073b05SJuli Mallett void
33746251ddeSWarner Losh tdev(KINFO *k, VARENT *ve)
3384b88c807SRodney W. Grimes {
3394b88c807SRodney W. Grimes 	VAR *v;
3404b88c807SRodney W. Grimes 	dev_t dev;
3414b88c807SRodney W. Grimes 	char buff[16];
3424b88c807SRodney W. Grimes 
3434b88c807SRodney W. Grimes 	v = ve->var;
3441f7d2501SKirk McKusick 	dev = k->ki_p->ki_tdev;
3454b88c807SRodney W. Grimes 	if (dev == NODEV)
3464b88c807SRodney W. Grimes 		(void)printf("%*s", v->width, "??");
3474b88c807SRodney W. Grimes 	else {
3484b88c807SRodney W. Grimes 		(void)snprintf(buff, sizeof(buff),
3494b88c807SRodney W. Grimes 		    "%d/%d", major(dev), minor(dev));
3504b88c807SRodney W. Grimes 		(void)printf("%*s", v->width, buff);
3514b88c807SRodney W. Grimes 	}
3524b88c807SRodney W. Grimes }
3534b88c807SRodney W. Grimes 
3544b88c807SRodney W. Grimes void
35546251ddeSWarner Losh tname(KINFO *k, VARENT *ve)
3564b88c807SRodney W. Grimes {
3574b88c807SRodney W. Grimes 	VAR *v;
3584b88c807SRodney W. Grimes 	dev_t dev;
3594b88c807SRodney W. Grimes 	char *ttname;
3604b88c807SRodney W. Grimes 
3614b88c807SRodney W. Grimes 	v = ve->var;
3621f7d2501SKirk McKusick 	dev = k->ki_p->ki_tdev;
3634b88c807SRodney W. Grimes 	if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
364c55931c7SPeter Wemm 		(void)printf("%*s ", v->width - 1, "??");
3654b88c807SRodney W. Grimes 	else {
366efc18e2cSAndrey A. Chernov 		if (strncmp(ttname, "tty", 3) == 0 ||
367efc18e2cSAndrey A. Chernov 		    strncmp(ttname, "cua", 3) == 0)
3684b88c807SRodney W. Grimes 			ttname += 3;
3697bd5296dSOlivier Houchard 		if (strncmp(ttname, "pts/", 4) == 0)
3707bd5296dSOlivier Houchard 			ttname += 4;
371c55931c7SPeter Wemm 		(void)printf("%*.*s%c", v->width - 1, v->width - 1, ttname,
3721f7d2501SKirk McKusick 		    k->ki_p->ki_kiflag & KI_CTTY ? ' ' : '-');
3734b88c807SRodney W. Grimes 	}
3744b88c807SRodney W. Grimes }
3754b88c807SRodney W. Grimes 
3764b88c807SRodney W. Grimes void
37746251ddeSWarner Losh longtname(KINFO *k, VARENT *ve)
3784b88c807SRodney W. Grimes {
3794b88c807SRodney W. Grimes 	VAR *v;
3804b88c807SRodney W. Grimes 	dev_t dev;
3814b88c807SRodney W. Grimes 	char *ttname;
3824b88c807SRodney W. Grimes 
3834b88c807SRodney W. Grimes 	v = ve->var;
3841f7d2501SKirk McKusick 	dev = k->ki_p->ki_tdev;
3854b88c807SRodney W. Grimes 	if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
3864b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, "??");
3874b88c807SRodney W. Grimes 	else
3884b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, ttname);
3894b88c807SRodney W. Grimes }
3904b88c807SRodney W. Grimes 
3914b88c807SRodney W. Grimes void
39246251ddeSWarner Losh started(KINFO *k, VARENT *ve)
3934b88c807SRodney W. Grimes {
3944b88c807SRodney W. Grimes 	VAR *v;
395f8ec5fe2SBruce Evans 	time_t then;
3964b88c807SRodney W. Grimes 	struct tm *tp;
397f59105eeSAndrey A. Chernov 	static int use_ampm = -1;
398b85add5fSPhilippe Charnier 	char buf[100];
3994b88c807SRodney W. Grimes 
4004b88c807SRodney W. Grimes 	v = ve->var;
4011f7d2501SKirk McKusick 	if (!k->ki_valid) {
4024b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, "-");
4034b88c807SRodney W. Grimes 		return;
4044b88c807SRodney W. Grimes 	}
405f59105eeSAndrey A. Chernov 	if (use_ampm < 0)
406f59105eeSAndrey A. Chernov 		use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
4071f7d2501SKirk McKusick 	then = k->ki_p->ki_start.tv_sec;
408f8ec5fe2SBruce Evans 	tp = localtime(&then);
4091f7d2501SKirk McKusick 	if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
410b85add5fSPhilippe Charnier 		(void)strftime(buf, sizeof(buf),
41108017519SAndrey A. Chernov 		    use_ampm ? "%l:%M%p" : "%k:%M  ", tp);
4121f7d2501SKirk McKusick 	} else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) {
413b85add5fSPhilippe Charnier 		(void)strftime(buf, sizeof(buf),
41408017519SAndrey A. Chernov 		    use_ampm ? "%a%I%p" : "%a%H  ", tp);
4154b88c807SRodney W. Grimes 	} else
416b85add5fSPhilippe Charnier 		(void)strftime(buf, sizeof(buf), "%e%b%y", tp);
4174b88c807SRodney W. Grimes 	(void)printf("%-*s", v->width, buf);
4184b88c807SRodney W. Grimes }
4194b88c807SRodney W. Grimes 
4204b88c807SRodney W. Grimes void
42146251ddeSWarner Losh lstarted(KINFO *k, VARENT *ve)
4224b88c807SRodney W. Grimes {
4234b88c807SRodney W. Grimes 	VAR *v;
424f8ec5fe2SBruce Evans 	time_t then;
4254b88c807SRodney W. Grimes 	char buf[100];
4264b88c807SRodney W. Grimes 
4274b88c807SRodney W. Grimes 	v = ve->var;
4281f7d2501SKirk McKusick 	if (!k->ki_valid) {
4294b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, "-");
4304b88c807SRodney W. Grimes 		return;
4314b88c807SRodney W. Grimes 	}
4321f7d2501SKirk McKusick 	then = k->ki_p->ki_start.tv_sec;
433b85add5fSPhilippe Charnier 	(void)strftime(buf, sizeof(buf), "%c", localtime(&then));
4344b88c807SRodney W. Grimes 	(void)printf("%-*s", v->width, buf);
4354b88c807SRodney W. Grimes }
4364b88c807SRodney W. Grimes 
4374b88c807SRodney W. Grimes void
4380d632649SJohn Baldwin lockname(KINFO *k, VARENT *ve)
439fd5f30bfSJohn Baldwin {
440fd5f30bfSJohn Baldwin 	VAR *v;
441fd5f30bfSJohn Baldwin 
442fd5f30bfSJohn Baldwin 	v = ve->var;
4430d632649SJohn Baldwin 	if (k->ki_p->ki_kiflag & KI_LOCKBLOCK) {
4440d632649SJohn Baldwin 		if (k->ki_p->ki_lockname[0] != 0)
445fd5f30bfSJohn Baldwin 			(void)printf("%-*.*s", v->width, v->width,
4460d632649SJohn Baldwin 			    k->ki_p->ki_lockname);
447fd5f30bfSJohn Baldwin 		else
448fd5f30bfSJohn Baldwin 			(void)printf("%-*s", v->width, "???");
449fd5f30bfSJohn Baldwin 	} else
450fd5f30bfSJohn Baldwin 		(void)printf("%-*s", v->width, "-");
451fd5f30bfSJohn Baldwin }
452fd5f30bfSJohn Baldwin 
453fd5f30bfSJohn Baldwin void
45446251ddeSWarner Losh wchan(KINFO *k, VARENT *ve)
4554b88c807SRodney W. Grimes {
4564b88c807SRodney W. Grimes 	VAR *v;
4574b88c807SRodney W. Grimes 
4584b88c807SRodney W. Grimes 	v = ve->var;
4591f7d2501SKirk McKusick 	if (k->ki_p->ki_wchan) {
4601f7d2501SKirk McKusick 		if (k->ki_p->ki_wmesg[0] != 0)
4614b88c807SRodney W. Grimes 			(void)printf("%-*.*s", v->width, v->width,
4621f7d2501SKirk McKusick 			    k->ki_p->ki_wmesg);
4634b88c807SRodney W. Grimes 		else
4643929d518SDoug Rabson 			(void)printf("%-*lx", v->width,
4657d1192a7SPeter Wemm 			    (long)k->ki_p->ki_wchan);
466b85add5fSPhilippe Charnier 	} else
467d9a5f890SMatthew Dillon 		(void)printf("%-*s", v->width, "-");
468d9a5f890SMatthew Dillon }
469d9a5f890SMatthew Dillon 
470d9a5f890SMatthew Dillon void
471de244df7SHartmut Brandt nwchan(KINFO *k, VARENT *ve)
472de244df7SHartmut Brandt {
473de244df7SHartmut Brandt 	VAR *v;
474de244df7SHartmut Brandt 
475de244df7SHartmut Brandt 	v = ve->var;
476de244df7SHartmut Brandt 	if (k->ki_p->ki_wchan) {
477de244df7SHartmut Brandt 		(void)printf("%0*lx", v->width,
478de244df7SHartmut Brandt 		    (long)k->ki_p->ki_wchan);
479de244df7SHartmut Brandt 	} else
480de244df7SHartmut Brandt 		(void)printf("%-*s", v->width, "-");
481de244df7SHartmut Brandt }
482de244df7SHartmut Brandt 
483de244df7SHartmut Brandt void
484d9a5f890SMatthew Dillon mwchan(KINFO *k, VARENT *ve)
485d9a5f890SMatthew Dillon {
486d9a5f890SMatthew Dillon 	VAR *v;
487d9a5f890SMatthew Dillon 
488d9a5f890SMatthew Dillon 	v = ve->var;
489d9a5f890SMatthew Dillon 	if (k->ki_p->ki_wchan) {
490d9a5f890SMatthew Dillon 		if (k->ki_p->ki_wmesg[0] != 0)
491d9a5f890SMatthew Dillon 			(void)printf("%-*.*s", v->width, v->width,
492d9a5f890SMatthew Dillon 			    k->ki_p->ki_wmesg);
493d9a5f890SMatthew Dillon 		else
494d9a5f890SMatthew Dillon 			(void)printf("%-*lx", v->width,
495d9a5f890SMatthew Dillon 			    (long)k->ki_p->ki_wchan);
4960d632649SJohn Baldwin 	} else if (k->ki_p->ki_kiflag & KI_LOCKBLOCK) {
4970d632649SJohn Baldwin 		if (k->ki_p->ki_lockname[0]) {
498d9a5f890SMatthew Dillon 			(void)printf("%-*.*s", v->width, v->width,
4990d632649SJohn Baldwin 			    k->ki_p->ki_lockname);
500b85add5fSPhilippe Charnier 		} else
501d9a5f890SMatthew Dillon 			(void)printf("%-*s", v->width, "???");
502b85add5fSPhilippe Charnier 	} else
5034b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, "-");
5044b88c807SRodney W. Grimes }
5054b88c807SRodney W. Grimes 
5064b88c807SRodney W. Grimes void
50746251ddeSWarner Losh vsize(KINFO *k, VARENT *ve)
5084b88c807SRodney W. Grimes {
5094b88c807SRodney W. Grimes 	VAR *v;
5104b88c807SRodney W. Grimes 
5114b88c807SRodney W. Grimes 	v = ve->var;
512c1f903a0SBruce Evans 	(void)printf("%*lu", v->width, (u_long)(k->ki_p->ki_size / 1024));
5134b88c807SRodney W. Grimes }
5144b88c807SRodney W. Grimes 
5154b88c807SRodney W. Grimes void
51646251ddeSWarner Losh cputime(KINFO *k, VARENT *ve)
5174b88c807SRodney W. Grimes {
5184b88c807SRodney W. Grimes 	VAR *v;
5194b88c807SRodney W. Grimes 	long secs;
5204b88c807SRodney W. Grimes 	long psecs;	/* "parts" of a second. first micro, then centi */
5214b88c807SRodney W. Grimes 	char obuff[128];
522b85add5fSPhilippe Charnier 	static char decimal_point;
5234b88c807SRodney W. Grimes 
524b85add5fSPhilippe Charnier 	if (decimal_point == '\0')
5258073a93cSAndrey A. Chernov 		decimal_point = localeconv()->decimal_point[0];
5264b88c807SRodney W. Grimes 	v = ve->var;
52716ac318dSGarance A Drosehn 	if (!k->ki_valid) {
5285832a752SBruce Evans 		secs = 0;
5295832a752SBruce Evans 		psecs = 0;
5304b88c807SRodney W. Grimes 	} else {
5314b88c807SRodney W. Grimes 		/*
5324b88c807SRodney W. Grimes 		 * This counts time spent handling interrupts.  We could
5334b88c807SRodney W. Grimes 		 * fix this, but it is not 100% trivial (and interrupt
5344b88c807SRodney W. Grimes 		 * time fractions only work on the sparc anyway).	XXX
5354b88c807SRodney W. Grimes 		 */
5361f7d2501SKirk McKusick 		secs = k->ki_p->ki_runtime / 1000000;
5371f7d2501SKirk McKusick 		psecs = k->ki_p->ki_runtime % 1000000;
5384b88c807SRodney W. Grimes 		if (sumrusage) {
5391f7d2501SKirk McKusick 			secs += k->ki_p->ki_childtime.tv_sec;
5401f7d2501SKirk McKusick 			psecs += k->ki_p->ki_childtime.tv_usec;
5414b88c807SRodney W. Grimes 		}
5424b88c807SRodney W. Grimes 		/*
5434b88c807SRodney W. Grimes 		 * round and scale to 100's
5444b88c807SRodney W. Grimes 		 */
5455832a752SBruce Evans 		psecs = (psecs + 5000) / 10000;
5465832a752SBruce Evans 		secs += psecs / 100;
5475832a752SBruce Evans 		psecs = psecs % 100;
5485832a752SBruce Evans 	}
549b85add5fSPhilippe Charnier 	(void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld%c%02ld",
550b85add5fSPhilippe Charnier 	    secs / 60, secs % 60, decimal_point, psecs);
5514b88c807SRodney W. Grimes 	(void)printf("%*s", v->width, obuff);
5524b88c807SRodney W. Grimes }
5534b88c807SRodney W. Grimes 
55476e1a9feSJuli Mallett void
55576e1a9feSJuli Mallett elapsed(KINFO *k, VARENT *ve)
55676e1a9feSJuli Mallett {
55776e1a9feSJuli Mallett 	VAR *v;
558b85add5fSPhilippe Charnier 	time_t val;
559b85add5fSPhilippe Charnier 	int days, hours, mins, secs;
56076e1a9feSJuli Mallett 	char obuff[128];
56176e1a9feSJuli Mallett 
56276e1a9feSJuli Mallett 	v = ve->var;
563b85add5fSPhilippe Charnier 	val = now - k->ki_p->ki_start.tv_sec;
564b85add5fSPhilippe Charnier 	days = val / (24 * 60 * 60);
565b85add5fSPhilippe Charnier 	val %= 24 * 60 * 60;
566b85add5fSPhilippe Charnier 	hours = val / (60 * 60);
567b85add5fSPhilippe Charnier 	val %= 60 * 60;
568b85add5fSPhilippe Charnier 	mins = val / 60;
569b85add5fSPhilippe Charnier 	secs = val % 60;
570b85add5fSPhilippe Charnier 	if (days != 0)
571b85add5fSPhilippe Charnier 		(void)snprintf(obuff, sizeof(obuff), "%3d-%02d:%02d:%02d",
572b85add5fSPhilippe Charnier 		    days, hours, mins, secs);
573b85add5fSPhilippe Charnier 	else if (hours != 0)
574b85add5fSPhilippe Charnier 		(void)snprintf(obuff, sizeof(obuff), "%02d:%02d:%02d",
575b85add5fSPhilippe Charnier 		    hours, mins, secs);
576b85add5fSPhilippe Charnier 	else
577b85add5fSPhilippe Charnier 		(void)snprintf(obuff, sizeof(obuff), "%02d:%02d", mins, secs);
57876e1a9feSJuli Mallett 	(void)printf("%*s", v->width, obuff);
57976e1a9feSJuli Mallett }
58076e1a9feSJuli Mallett 
5814b88c807SRodney W. Grimes double
582871e8d8cSMark Murray getpcpu(const KINFO *k)
5834b88c807SRodney W. Grimes {
5844b88c807SRodney W. Grimes 	static int failure;
5854b88c807SRodney W. Grimes 
5864b88c807SRodney W. Grimes 	if (!nlistread)
5874b88c807SRodney W. Grimes 		failure = donlist();
5884b88c807SRodney W. Grimes 	if (failure)
5894b88c807SRodney W. Grimes 		return (0.0);
5904b88c807SRodney W. Grimes 
5914b88c807SRodney W. Grimes #define	fxtofl(fixpt)	((double)(fixpt) / fscale)
5924b88c807SRodney W. Grimes 
5934b88c807SRodney W. Grimes 	/* XXX - I don't like this */
594e0aa5ab7SJohn Baldwin 	if (k->ki_p->ki_swtime == 0 || (k->ki_p->ki_sflag & PS_INMEM) == 0)
5954b88c807SRodney W. Grimes 		return (0.0);
5964b88c807SRodney W. Grimes 	if (rawcpu)
5971f7d2501SKirk McKusick 		return (100.0 * fxtofl(k->ki_p->ki_pctcpu));
5981f7d2501SKirk McKusick 	return (100.0 * fxtofl(k->ki_p->ki_pctcpu) /
5991f7d2501SKirk McKusick 		(1.0 - exp(k->ki_p->ki_swtime * log(fxtofl(ccpu)))));
6004b88c807SRodney W. Grimes }
6014b88c807SRodney W. Grimes 
6024b88c807SRodney W. Grimes void
60346251ddeSWarner Losh pcpu(KINFO *k, VARENT *ve)
6044b88c807SRodney W. Grimes {
6054b88c807SRodney W. Grimes 	VAR *v;
6064b88c807SRodney W. Grimes 
6074b88c807SRodney W. Grimes 	v = ve->var;
6084b88c807SRodney W. Grimes 	(void)printf("%*.1f", v->width, getpcpu(k));
6094b88c807SRodney W. Grimes }
6104b88c807SRodney W. Grimes 
611871e8d8cSMark Murray static double
61246251ddeSWarner Losh getpmem(KINFO *k)
6134b88c807SRodney W. Grimes {
6144b88c807SRodney W. Grimes 	static int failure;
6154b88c807SRodney W. Grimes 	double fracmem;
6164b88c807SRodney W. Grimes 
6174b88c807SRodney W. Grimes 	if (!nlistread)
6184b88c807SRodney W. Grimes 		failure = donlist();
6194b88c807SRodney W. Grimes 	if (failure)
6204b88c807SRodney W. Grimes 		return (0.0);
6214b88c807SRodney W. Grimes 
622e0aa5ab7SJohn Baldwin 	if ((k->ki_p->ki_sflag & PS_INMEM) == 0)
6234b88c807SRodney W. Grimes 		return (0.0);
6244b88c807SRodney W. Grimes 	/* XXX want pmap ptpages, segtab, etc. (per architecture) */
6254b88c807SRodney W. Grimes 	/* XXX don't have info about shared */
62685012e7cSPeter Wemm 	fracmem = ((float)k->ki_p->ki_rssize) / mempages;
6274b88c807SRodney W. Grimes 	return (100.0 * fracmem);
6284b88c807SRodney W. Grimes }
6294b88c807SRodney W. Grimes 
6304b88c807SRodney W. Grimes void
63146251ddeSWarner Losh pmem(KINFO *k, VARENT *ve)
6324b88c807SRodney W. Grimes {
6334b88c807SRodney W. Grimes 	VAR *v;
6344b88c807SRodney W. Grimes 
6354b88c807SRodney W. Grimes 	v = ve->var;
6364b88c807SRodney W. Grimes 	(void)printf("%*.1f", v->width, getpmem(k));
6374b88c807SRodney W. Grimes }
6384b88c807SRodney W. Grimes 
6394b88c807SRodney W. Grimes void
64046251ddeSWarner Losh pagein(KINFO *k, VARENT *ve)
6414b88c807SRodney W. Grimes {
6424b88c807SRodney W. Grimes 	VAR *v;
6434b88c807SRodney W. Grimes 
6444b88c807SRodney W. Grimes 	v = ve->var;
6450fd510b7SJoerg Wunsch 	(void)printf("%*ld", v->width,
6461f7d2501SKirk McKusick 	    k->ki_valid ? k->ki_p->ki_rusage.ru_majflt : 0);
6474b88c807SRodney W. Grimes }
6484b88c807SRodney W. Grimes 
649871e8d8cSMark Murray /* ARGSUSED */
6504b88c807SRodney W. Grimes void
651871e8d8cSMark Murray maxrss(KINFO *k __unused, VARENT *ve)
6524b88c807SRodney W. Grimes {
6534b88c807SRodney W. Grimes 	VAR *v;
6544b88c807SRodney W. Grimes 
6554b88c807SRodney W. Grimes 	v = ve->var;
656940cca66SPeter Wemm 	/* XXX not yet */
6574b88c807SRodney W. Grimes 	(void)printf("%*s", v->width, "-");
6584b88c807SRodney W. Grimes }
6594b88c807SRodney W. Grimes 
6604b88c807SRodney W. Grimes void
66146251ddeSWarner Losh priorityr(KINFO *k, VARENT *ve)
662ad863cacSSteve Price {
663ad863cacSSteve Price 	VAR *v;
664871e8d8cSMark Murray 	struct priority *lpri;
665ad863cacSSteve Price 	char str[8];
6664c85452bSJake Burkholder 	unsigned class, level;
667ad863cacSSteve Price 
668ad863cacSSteve Price 	v = ve->var;
6693998d222SGarance A Drosehn 	lpri = &k->ki_p->ki_pri;
670871e8d8cSMark Murray 	class = lpri->pri_class;
671871e8d8cSMark Murray 	level = lpri->pri_level;
6724c85452bSJake Burkholder 	switch (class) {
67370548f64SGarance A Drosehn 	case PRI_ITHD:
67470548f64SGarance A Drosehn 		snprintf(str, sizeof(str), "intr:%u", level);
67570548f64SGarance A Drosehn 		break;
6764c85452bSJake Burkholder 	case PRI_REALTIME:
6774c85452bSJake Burkholder 		snprintf(str, sizeof(str), "real:%u", level);
678ad863cacSSteve Price 		break;
6794c85452bSJake Burkholder 	case PRI_TIMESHARE:
680ad863cacSSteve Price 		strncpy(str, "normal", sizeof(str));
681ad863cacSSteve Price 		break;
6824c85452bSJake Burkholder 	case PRI_IDLE:
6834c85452bSJake Burkholder 		snprintf(str, sizeof(str), "idle:%u", level);
684ad863cacSSteve Price 		break;
685ad863cacSSteve Price 	default:
6864c85452bSJake Burkholder 		snprintf(str, sizeof(str), "%u:%u", class, level);
687ad863cacSSteve Price 		break;
688ad863cacSSteve Price 	}
689ad863cacSSteve Price 	str[sizeof(str) - 1] = '\0';
690ad863cacSSteve Price 	(void)printf("%*s", v->width, str);
691ad863cacSSteve Price }
692ad863cacSSteve Price 
6934b88c807SRodney W. Grimes /*
6944b88c807SRodney W. Grimes  * Generic output routines.  Print fields from various prototype
6954b88c807SRodney W. Grimes  * structures.
6964b88c807SRodney W. Grimes  */
6974b88c807SRodney W. Grimes static void
698ffe25988SJuli Mallett printval(void *bp, VAR *v)
6994b88c807SRodney W. Grimes {
7004b88c807SRodney W. Grimes 	static char ofmt[32] = "%";
701fdbec398SJuli Mallett 	const char *fcp;
702fdbec398SJuli Mallett 	char *cp;
7034b88c807SRodney W. Grimes 
7044b88c807SRodney W. Grimes 	cp = ofmt + 1;
7054b88c807SRodney W. Grimes 	fcp = v->fmt;
7064b88c807SRodney W. Grimes 	if (v->flag & LJUST)
7074b88c807SRodney W. Grimes 		*cp++ = '-';
7084b88c807SRodney W. Grimes 	*cp++ = '*';
7090fd510b7SJoerg Wunsch 	while ((*cp++ = *fcp++));
7104b88c807SRodney W. Grimes 
711e2c9ac69STim J. Robbins #define	CHKINF127(n)	(((n) > 127) && (v->flag & INF127) ? 127 : (n))
712e2c9ac69STim J. Robbins 
7134b88c807SRodney W. Grimes 	switch (v->type) {
7144b88c807SRodney W. Grimes 	case CHAR:
7154b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(char *)bp);
7164b88c807SRodney W. Grimes 		break;
7174b88c807SRodney W. Grimes 	case UCHAR:
7184b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(u_char *)bp);
7194b88c807SRodney W. Grimes 		break;
7204b88c807SRodney W. Grimes 	case SHORT:
7214b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(short *)bp);
7224b88c807SRodney W. Grimes 		break;
7234b88c807SRodney W. Grimes 	case USHORT:
7244b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(u_short *)bp);
7254b88c807SRodney W. Grimes 		break;
7263929d518SDoug Rabson 	case INT:
7273929d518SDoug Rabson 		(void)printf(ofmt, v->width, *(int *)bp);
7283929d518SDoug Rabson 		break;
7293929d518SDoug Rabson 	case UINT:
730e2c9ac69STim J. Robbins 		(void)printf(ofmt, v->width, CHKINF127(*(u_int *)bp));
7313929d518SDoug Rabson 		break;
7324b88c807SRodney W. Grimes 	case LONG:
7334b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(long *)bp);
7344b88c807SRodney W. Grimes 		break;
7354b88c807SRodney W. Grimes 	case ULONG:
7364b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(u_long *)bp);
7374b88c807SRodney W. Grimes 		break;
7384b88c807SRodney W. Grimes 	case KPTR:
7397d1192a7SPeter Wemm 		(void)printf(ofmt, v->width, *(u_long *)bp);
7404b88c807SRodney W. Grimes 		break;
741362d62baSJuli Mallett 	case PGTOK:
742760bbf7dSJuli Mallett 		(void)printf(ofmt, v->width, ps_pgtok(*(u_long *)bp));
743760bbf7dSJuli Mallett 		break;
7444b88c807SRodney W. Grimes 	default:
7454b88c807SRodney W. Grimes 		errx(1, "unknown type %d", v->type);
7464b88c807SRodney W. Grimes 	}
7474b88c807SRodney W. Grimes }
7484b88c807SRodney W. Grimes 
7494b88c807SRodney W. Grimes void
75046251ddeSWarner Losh kvar(KINFO *k, VARENT *ve)
7514b88c807SRodney W. Grimes {
7524b88c807SRodney W. Grimes 	VAR *v;
7534b88c807SRodney W. Grimes 
7544b88c807SRodney W. Grimes 	v = ve->var;
7551f7d2501SKirk McKusick 	printval((char *)((char *)k->ki_p + v->off), v);
7564b88c807SRodney W. Grimes }
7574b88c807SRodney W. Grimes 
7584b88c807SRodney W. Grimes void
75946251ddeSWarner Losh rvar(KINFO *k, VARENT *ve)
7604b88c807SRodney W. Grimes {
7614b88c807SRodney W. Grimes 	VAR *v;
7624b88c807SRodney W. Grimes 
7634b88c807SRodney W. Grimes 	v = ve->var;
7641f7d2501SKirk McKusick 	if (k->ki_valid)
7651f7d2501SKirk McKusick 		printval((char *)((char *)(&k->ki_p->ki_rusage) + v->off), v);
7664b88c807SRodney W. Grimes 	else
7674b88c807SRodney W. Grimes 		(void)printf("%*s", v->width, "-");
7684b88c807SRodney W. Grimes }
7697304f61fSBrian Feldman 
7707304f61fSBrian Feldman void
77115b87b53SGarance A Drosehn emulname(KINFO *k, VARENT *ve)
77215b87b53SGarance A Drosehn {
77315b87b53SGarance A Drosehn 	VAR *v;
77415b87b53SGarance A Drosehn 
77515b87b53SGarance A Drosehn 	v = ve->var;
77615b87b53SGarance A Drosehn 	printf("%-*s", v->width, *k->ki_p->ki_emul ? k->ki_p->ki_emul : "-");
77715b87b53SGarance A Drosehn }
77815b87b53SGarance A Drosehn 
77915b87b53SGarance A Drosehn void
7802af538ebSRobert Watson label(KINFO *k, VARENT *ve)
7817304f61fSBrian Feldman {
7822af538ebSRobert Watson 	char *string;
783b85add5fSPhilippe Charnier 	VAR *v;
784775bba9fSJuli Mallett 	mac_t proclabel;
7852af538ebSRobert Watson 	int error;
7867304f61fSBrian Feldman 
7877304f61fSBrian Feldman 	v = ve->var;
7882af538ebSRobert Watson 	string = NULL;
789775bba9fSJuli Mallett 	if (mac_prepare_process_label(&proclabel) == -1) {
7902c61418dSTim J. Robbins 		warn("mac_prepare_process_label");
7912af538ebSRobert Watson 		goto out;
7922af538ebSRobert Watson 	}
793775bba9fSJuli Mallett 	error = mac_get_pid(k->ki_p->ki_pid, proclabel);
7942af538ebSRobert Watson 	if (error == 0) {
795775bba9fSJuli Mallett 		if (mac_to_text(proclabel, &string) == -1)
7962af538ebSRobert Watson 			string = NULL;
7972af538ebSRobert Watson 	}
798775bba9fSJuli Mallett 	mac_free(proclabel);
7992af538ebSRobert Watson out:
8002af538ebSRobert Watson 	if (string != NULL) {
8012af538ebSRobert Watson 		(void)printf("%-*s", v->width, string);
8022af538ebSRobert Watson 		free(string);
8032af538ebSRobert Watson 	} else
804ce1affa2SGarance A Drosehn 		(void)printf("%-*s", v->width, "  -");
8052af538ebSRobert Watson 	return;
8062af538ebSRobert Watson }
8072af538ebSRobert Watson 
8082af538ebSRobert Watson int
8092af538ebSRobert Watson s_label(KINFO *k)
8102af538ebSRobert Watson {
8112af538ebSRobert Watson 	char *string = NULL;
812775bba9fSJuli Mallett 	mac_t proclabel;
8132af538ebSRobert Watson 	int error, size = 0;
8142af538ebSRobert Watson 
815775bba9fSJuli Mallett 	if (mac_prepare_process_label(&proclabel) == -1) {
8162c61418dSTim J. Robbins 		warn("mac_prepare_process_label");
8172af538ebSRobert Watson 		return (0);
8182af538ebSRobert Watson 	}
819775bba9fSJuli Mallett 	error = mac_get_pid(k->ki_p->ki_pid, proclabel);
820775bba9fSJuli Mallett 	if (error == 0 && mac_to_text(proclabel, &string) == 0) {
8212af538ebSRobert Watson 		size = strlen(string);
8222af538ebSRobert Watson 		free(string);
8232af538ebSRobert Watson 	}
824775bba9fSJuli Mallett 	mac_free(proclabel);
8252af538ebSRobert Watson 	return (size);
8267304f61fSBrian Feldman }
827