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; 7201e5f166STim J. Robbins int allempty; 734b88c807SRodney W. Grimes 7401e5f166STim J. Robbins allempty = 1; 7501e5f166STim J. Robbins for (vent = vhead; vent; vent = vent->next) 7678b1878aSJuli Mallett if (*vent->header != '\0') { 7701e5f166STim J. Robbins allempty = 0; 7801e5f166STim J. Robbins break; 7901e5f166STim J. Robbins } 8001e5f166STim J. Robbins if (allempty) 8101e5f166STim J. Robbins return; 824b88c807SRodney W. Grimes for (vent = vhead; vent; vent = vent->next) { 834b88c807SRodney W. Grimes v = vent->var; 844b88c807SRodney W. Grimes if (v->flag & LJUST) { 854b88c807SRodney W. Grimes if (vent->next == NULL) /* last one */ 8678b1878aSJuli Mallett (void)printf("%s", vent->header); 874b88c807SRodney W. Grimes else 8878b1878aSJuli Mallett (void)printf("%-*s", v->width, vent->header); 894b88c807SRodney W. Grimes } else 9078b1878aSJuli Mallett (void)printf("%*s", v->width, vent->header); 914b88c807SRodney W. Grimes if (vent->next != NULL) 924b88c807SRodney W. Grimes (void)putchar(' '); 934b88c807SRodney W. Grimes } 944b88c807SRodney W. Grimes (void)putchar('\n'); 954b88c807SRodney W. Grimes } 964b88c807SRodney W. Grimes 974b88c807SRodney W. Grimes void 9803334017SJuli Mallett arguments(KINFO *k, VARENT *ve) 9903334017SJuli Mallett { 10003334017SJuli Mallett VAR *v; 10103334017SJuli Mallett int left; 10203334017SJuli Mallett char *cp, *vis_args; 10303334017SJuli Mallett 10403334017SJuli Mallett v = ve->var; 10503334017SJuli Mallett if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL) 10603334017SJuli Mallett errx(1, "malloc failed"); 10703334017SJuli Mallett strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH); 10803334017SJuli Mallett if (ve->next == NULL) { 10903334017SJuli Mallett /* last field */ 11003334017SJuli Mallett if (termwidth == UNLIMITED) { 11103334017SJuli Mallett (void)printf("%s", vis_args); 11203334017SJuli Mallett } else { 11303334017SJuli Mallett left = termwidth - (totwidth - v->width); 11403334017SJuli Mallett if (left < 1) /* already wrapped, just use std width */ 11503334017SJuli Mallett left = v->width; 11603334017SJuli Mallett for (cp = vis_args; --left >= 0 && *cp != '\0';) 11703334017SJuli Mallett (void)putchar(*cp++); 11803334017SJuli Mallett } 11903334017SJuli Mallett } else { 12003334017SJuli Mallett (void)printf("%-*.*s", v->width, v->width, vis_args); 12103334017SJuli Mallett } 12203334017SJuli Mallett free(vis_args); 12303334017SJuli Mallett } 12403334017SJuli Mallett 12503334017SJuli Mallett void 12646251ddeSWarner Losh command(KINFO *k, VARENT *ve) 1274b88c807SRodney W. Grimes { 1284b88c807SRodney W. Grimes VAR *v; 1294b88c807SRodney W. Grimes int left; 1304b88c807SRodney W. Grimes char *cp, *vis_env, *vis_args; 1314b88c807SRodney W. Grimes 132db91faacSPeter Wemm v = ve->var; 133db91faacSPeter Wemm if (cflag) { 1343cc273e0SJohn Polstra if (ve->next == NULL) /* last field, don't pad */ 1351f7d2501SKirk McKusick (void)printf("%s", k->ki_p->ki_comm); 1363cc273e0SJohn Polstra else 1371f7d2501SKirk McKusick (void)printf("%-*s", v->width, k->ki_p->ki_comm); 138db91faacSPeter Wemm return; 139db91faacSPeter Wemm } 1404b88c807SRodney W. Grimes if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL) 1414fa7d788SJuli Mallett errx(1, "malloc failed"); 1424b88c807SRodney W. Grimes strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH); 1434b88c807SRodney W. Grimes if (k->ki_env) { 1444b88c807SRodney W. Grimes if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1)) == NULL) 1454fa7d788SJuli Mallett errx(1, "malloc failed"); 1464b88c807SRodney W. Grimes strvis(vis_env, k->ki_env, VIS_TAB | VIS_NL | VIS_NOSLASH); 1474b88c807SRodney W. Grimes } else 1484b88c807SRodney W. Grimes vis_env = NULL; 1494b88c807SRodney W. Grimes 1504b88c807SRodney W. Grimes if (ve->next == NULL) { 1514b88c807SRodney W. Grimes /* last field */ 1524b88c807SRodney W. Grimes if (termwidth == UNLIMITED) { 1534b88c807SRodney W. Grimes if (vis_env) 1544b88c807SRodney W. Grimes (void)printf("%s ", vis_env); 1554b88c807SRodney W. Grimes (void)printf("%s", vis_args); 1564b88c807SRodney W. Grimes } else { 1574b88c807SRodney W. Grimes left = termwidth - (totwidth - v->width); 1584b88c807SRodney W. Grimes if (left < 1) /* already wrapped, just use std width */ 1594b88c807SRodney W. Grimes left = v->width; 1604b88c807SRodney W. Grimes if ((cp = vis_env) != NULL) { 1614b88c807SRodney W. Grimes while (--left >= 0 && *cp) 1624b88c807SRodney W. Grimes (void)putchar(*cp++); 1634b88c807SRodney W. Grimes if (--left >= 0) 1644b88c807SRodney W. Grimes putchar(' '); 1654b88c807SRodney W. Grimes } 1664b88c807SRodney W. Grimes for (cp = vis_args; --left >= 0 && *cp != '\0';) 1674b88c807SRodney W. Grimes (void)putchar(*cp++); 1684b88c807SRodney W. Grimes } 1694b88c807SRodney W. Grimes } else 1704b88c807SRodney W. Grimes /* XXX env? */ 1714b88c807SRodney W. Grimes (void)printf("%-*.*s", v->width, v->width, vis_args); 1724b88c807SRodney W. Grimes free(vis_args); 1734b88c807SRodney W. Grimes if (vis_env != NULL) 1744b88c807SRodney W. Grimes free(vis_env); 1754b88c807SRodney W. Grimes } 1764b88c807SRodney W. Grimes 1774b88c807SRodney W. Grimes void 17846251ddeSWarner Losh ucomm(KINFO *k, VARENT *ve) 1794b88c807SRodney W. Grimes { 1804b88c807SRodney W. Grimes VAR *v; 1814b88c807SRodney W. Grimes 1824b88c807SRodney W. Grimes v = ve->var; 1831f7d2501SKirk McKusick (void)printf("%-*s", v->width, k->ki_p->ki_comm); 1844b88c807SRodney W. Grimes } 1854b88c807SRodney W. Grimes 1864b88c807SRodney W. Grimes void 18746251ddeSWarner Losh logname(KINFO *k, VARENT *ve) 1884b88c807SRodney W. Grimes { 1894b88c807SRodney W. Grimes VAR *v; 190ad863cacSSteve Price char *s; 1914b88c807SRodney W. Grimes 1924b88c807SRodney W. Grimes v = ve->var; 1931f7d2501SKirk McKusick (void)printf("%-*s", v->width, (s = k->ki_p->ki_login, *s) ? s : "-"); 1944b88c807SRodney W. Grimes } 1954b88c807SRodney W. Grimes 1964b88c807SRodney W. Grimes void 19746251ddeSWarner Losh state(KINFO *k, VARENT *ve) 1984b88c807SRodney W. Grimes { 199b40ce416SJulian Elischer int flag, sflag, tdflags; 2004b88c807SRodney W. Grimes char *cp; 2014b88c807SRodney W. Grimes VAR *v; 2024b88c807SRodney W. Grimes char buf[16]; 2034b88c807SRodney W. Grimes 2044b88c807SRodney W. Grimes v = ve->var; 2051f7d2501SKirk McKusick flag = k->ki_p->ki_flag; 206564efb8fSTor Egge sflag = k->ki_p->ki_sflag; 207b40ce416SJulian Elischer tdflags = k->ki_p->ki_tdflags; /* XXXKSE */ 2084b88c807SRodney W. Grimes cp = buf; 2094b88c807SRodney W. Grimes 2101f7d2501SKirk McKusick switch (k->ki_p->ki_stat) { 2114b88c807SRodney W. Grimes 2124b88c807SRodney W. Grimes case SSTOP: 2134b88c807SRodney W. Grimes *cp = 'T'; 2144b88c807SRodney W. Grimes break; 2154b88c807SRodney W. Grimes 2164b88c807SRodney W. Grimes case SSLEEP: 217b40ce416SJulian Elischer if (tdflags & TDF_SINTR) /* interruptable (long) */ 2181f7d2501SKirk McKusick *cp = k->ki_p->ki_slptime >= MAXSLP ? 'I' : 'S'; 2194b88c807SRodney W. Grimes else 2204b88c807SRodney W. Grimes *cp = 'D'; 2214b88c807SRodney W. Grimes break; 2224b88c807SRodney W. Grimes 2234b88c807SRodney W. Grimes case SRUN: 2244b88c807SRodney W. Grimes case SIDL: 2254b88c807SRodney W. Grimes *cp = 'R'; 2264b88c807SRodney W. Grimes break; 2274b88c807SRodney W. Grimes 2280384fff8SJason Evans case SWAIT: 2290384fff8SJason Evans *cp = 'W'; 2300384fff8SJason Evans break; 2310384fff8SJason Evans 2320d632649SJohn Baldwin case SLOCK: 2330d632649SJohn Baldwin *cp = 'L'; 2340384fff8SJason Evans break; 2350384fff8SJason Evans 2364b88c807SRodney W. Grimes case SZOMB: 2374b88c807SRodney W. Grimes *cp = 'Z'; 2384b88c807SRodney W. Grimes break; 2394b88c807SRodney W. Grimes 2404b88c807SRodney W. Grimes default: 2414b88c807SRodney W. Grimes *cp = '?'; 2424b88c807SRodney W. Grimes } 2434b88c807SRodney W. Grimes cp++; 244e0aa5ab7SJohn Baldwin if (!(sflag & PS_INMEM)) 2454b88c807SRodney W. Grimes *cp++ = 'W'; 2461f7d2501SKirk McKusick if (k->ki_p->ki_nice < NZERO) 2474b88c807SRodney W. Grimes *cp++ = '<'; 2481f7d2501SKirk McKusick else if (k->ki_p->ki_nice > NZERO) 2494b88c807SRodney W. Grimes *cp++ = 'N'; 2504b88c807SRodney W. Grimes if (flag & P_TRACED) 2514b88c807SRodney W. Grimes *cp++ = 'X'; 2521f7d2501SKirk McKusick if (flag & P_WEXIT && k->ki_p->ki_stat != SZOMB) 2534b88c807SRodney W. Grimes *cp++ = 'E'; 2544b88c807SRodney W. Grimes if (flag & P_PPWAIT) 2554b88c807SRodney W. Grimes *cp++ = 'V'; 2561f7d2501SKirk McKusick if ((flag & P_SYSTEM) || k->ki_p->ki_lock > 0) 2574b88c807SRodney W. Grimes *cp++ = 'L'; 2581f7d2501SKirk McKusick if (k->ki_p->ki_kiflag & KI_SLEADER) 2594b88c807SRodney W. Grimes *cp++ = 's'; 2601f7d2501SKirk McKusick if ((flag & P_CONTROLT) && k->ki_p->ki_pgid == k->ki_p->ki_tpgid) 2614b88c807SRodney W. Grimes *cp++ = '+'; 26275c13541SPoul-Henning Kamp if (flag & P_JAILED) 26375c13541SPoul-Henning Kamp *cp++ = 'J'; 2644b88c807SRodney W. Grimes *cp = '\0'; 2654b88c807SRodney W. Grimes (void)printf("%-*s", v->width, buf); 2664b88c807SRodney W. Grimes } 2674b88c807SRodney W. Grimes 2684b88c807SRodney W. Grimes void 26946251ddeSWarner Losh pri(KINFO *k, VARENT *ve) 2704b88c807SRodney W. Grimes { 2714b88c807SRodney W. Grimes VAR *v; 2724b88c807SRodney W. Grimes 2734b88c807SRodney W. Grimes v = ve->var; 2744c85452bSJake Burkholder (void)printf("%*d", v->width, k->ki_p->ki_pri.pri_level - PZERO); 2754b88c807SRodney W. Grimes } 2764b88c807SRodney W. Grimes 2774b88c807SRodney W. Grimes void 27846251ddeSWarner Losh uname(KINFO *k, VARENT *ve) 2794b88c807SRodney W. Grimes { 2804b88c807SRodney W. Grimes VAR *v; 2814b88c807SRodney W. Grimes 2824b88c807SRodney W. Grimes v = ve->var; 283e8eef4bbSJuli Mallett (void)printf("%-*s", v->width, user_from_uid(k->ki_p->ki_uid, 0)); 2844b88c807SRodney W. Grimes } 2854b88c807SRodney W. Grimes 2866a2d726bSJordan K. Hubbard int 28746251ddeSWarner Losh s_uname(KINFO *k) 2886a2d726bSJordan K. Hubbard { 2891f7d2501SKirk McKusick return (strlen(user_from_uid(k->ki_p->ki_uid, 0))); 2906a2d726bSJordan K. Hubbard } 2916a2d726bSJordan K. Hubbard 2924b88c807SRodney W. Grimes void 293e8eef4bbSJuli Mallett rgroupname(KINFO *k, VARENT *ve) 294e8eef4bbSJuli Mallett { 295e8eef4bbSJuli Mallett VAR *v; 296e8eef4bbSJuli Mallett 297e8eef4bbSJuli Mallett v = ve->var; 298e8eef4bbSJuli Mallett (void)printf("%-*s", v->width, group_from_gid(k->ki_p->ki_rgid, 0)); 299e8eef4bbSJuli Mallett } 300e8eef4bbSJuli Mallett 301e8eef4bbSJuli Mallett int 302e8eef4bbSJuli Mallett s_rgroupname(KINFO *k) 303e8eef4bbSJuli Mallett { 304e8eef4bbSJuli Mallett return (strlen(group_from_gid(k->ki_p->ki_rgid, 0))); 305e8eef4bbSJuli Mallett } 306e8eef4bbSJuli Mallett 307e8eef4bbSJuli Mallett void 30846251ddeSWarner Losh runame(KINFO *k, VARENT *ve) 3094b88c807SRodney W. Grimes { 3104b88c807SRodney W. Grimes VAR *v; 3114b88c807SRodney W. Grimes 3124b88c807SRodney W. Grimes v = ve->var; 313e8eef4bbSJuli Mallett (void)printf("%-*s", v->width, user_from_uid(k->ki_p->ki_ruid, 0)); 3144b88c807SRodney W. Grimes } 3154b88c807SRodney W. Grimes 3166a2d726bSJordan K. Hubbard int 31746251ddeSWarner Losh s_runame(KINFO *k) 3186a2d726bSJordan K. Hubbard { 3191f7d2501SKirk McKusick return (strlen(user_from_uid(k->ki_p->ki_ruid, 0))); 3206a2d726bSJordan K. Hubbard } 3216a2d726bSJordan K. Hubbard 322f3073b05SJuli Mallett 323f3073b05SJuli Mallett void 32446251ddeSWarner Losh tdev(KINFO *k, VARENT *ve) 3254b88c807SRodney W. Grimes { 3264b88c807SRodney W. Grimes VAR *v; 3274b88c807SRodney W. Grimes dev_t dev; 3284b88c807SRodney W. Grimes char buff[16]; 3294b88c807SRodney W. Grimes 3304b88c807SRodney W. Grimes v = ve->var; 3311f7d2501SKirk McKusick dev = k->ki_p->ki_tdev; 3324b88c807SRodney W. Grimes if (dev == NODEV) 3334b88c807SRodney W. Grimes (void)printf("%*s", v->width, "??"); 3344b88c807SRodney W. Grimes else { 3354b88c807SRodney W. Grimes (void)snprintf(buff, sizeof(buff), 3364b88c807SRodney W. Grimes "%d/%d", major(dev), minor(dev)); 3374b88c807SRodney W. Grimes (void)printf("%*s", v->width, buff); 3384b88c807SRodney W. Grimes } 3394b88c807SRodney W. Grimes } 3404b88c807SRodney W. Grimes 3414b88c807SRodney W. Grimes void 34246251ddeSWarner Losh tname(KINFO *k, VARENT *ve) 3434b88c807SRodney W. Grimes { 3444b88c807SRodney W. Grimes VAR *v; 3454b88c807SRodney W. Grimes dev_t dev; 3464b88c807SRodney W. Grimes char *ttname; 3474b88c807SRodney W. Grimes 3484b88c807SRodney W. Grimes v = ve->var; 3491f7d2501SKirk McKusick dev = k->ki_p->ki_tdev; 3504b88c807SRodney W. Grimes if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL) 351c55931c7SPeter Wemm (void)printf("%*s ", v->width - 1, "??"); 3524b88c807SRodney W. Grimes else { 353efc18e2cSAndrey A. Chernov if (strncmp(ttname, "tty", 3) == 0 || 354efc18e2cSAndrey A. Chernov strncmp(ttname, "cua", 3) == 0) 3554b88c807SRodney W. Grimes ttname += 3; 356c55931c7SPeter Wemm (void)printf("%*.*s%c", v->width - 1, v->width - 1, ttname, 3571f7d2501SKirk McKusick k->ki_p->ki_kiflag & KI_CTTY ? ' ' : '-'); 3584b88c807SRodney W. Grimes } 3594b88c807SRodney W. Grimes } 3604b88c807SRodney W. Grimes 3614b88c807SRodney W. Grimes void 36246251ddeSWarner Losh longtname(KINFO *k, VARENT *ve) 3634b88c807SRodney W. Grimes { 3644b88c807SRodney W. Grimes VAR *v; 3654b88c807SRodney W. Grimes dev_t dev; 3664b88c807SRodney W. Grimes char *ttname; 3674b88c807SRodney W. Grimes 3684b88c807SRodney W. Grimes v = ve->var; 3691f7d2501SKirk McKusick dev = k->ki_p->ki_tdev; 3704b88c807SRodney W. Grimes if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL) 3714b88c807SRodney W. Grimes (void)printf("%-*s", v->width, "??"); 3724b88c807SRodney W. Grimes else 3734b88c807SRodney W. Grimes (void)printf("%-*s", v->width, ttname); 3744b88c807SRodney W. Grimes } 3754b88c807SRodney W. Grimes 3764b88c807SRodney W. Grimes void 37746251ddeSWarner Losh started(KINFO *k, VARENT *ve) 3784b88c807SRodney W. Grimes { 3794b88c807SRodney W. Grimes VAR *v; 380f8ec5fe2SBruce Evans time_t then; 3814b88c807SRodney W. Grimes struct tm *tp; 382f59105eeSAndrey A. Chernov static int use_ampm = -1; 383b85add5fSPhilippe Charnier char buf[100]; 3844b88c807SRodney W. Grimes 3854b88c807SRodney W. Grimes v = ve->var; 3861f7d2501SKirk McKusick if (!k->ki_valid) { 3874b88c807SRodney W. Grimes (void)printf("%-*s", v->width, "-"); 3884b88c807SRodney W. Grimes return; 3894b88c807SRodney W. Grimes } 390f59105eeSAndrey A. Chernov if (use_ampm < 0) 391f59105eeSAndrey A. Chernov use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0'); 3921f7d2501SKirk McKusick then = k->ki_p->ki_start.tv_sec; 393f8ec5fe2SBruce Evans tp = localtime(&then); 3941f7d2501SKirk McKusick if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) { 395b85add5fSPhilippe Charnier (void)strftime(buf, sizeof(buf), 39608017519SAndrey A. Chernov use_ampm ? "%l:%M%p" : "%k:%M ", tp); 3971f7d2501SKirk McKusick } else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) { 398b85add5fSPhilippe Charnier (void)strftime(buf, sizeof(buf), 39908017519SAndrey A. Chernov use_ampm ? "%a%I%p" : "%a%H ", tp); 4004b88c807SRodney W. Grimes } else 401b85add5fSPhilippe Charnier (void)strftime(buf, sizeof(buf), "%e%b%y", tp); 4024b88c807SRodney W. Grimes (void)printf("%-*s", v->width, buf); 4034b88c807SRodney W. Grimes } 4044b88c807SRodney W. Grimes 4054b88c807SRodney W. Grimes void 40646251ddeSWarner Losh lstarted(KINFO *k, VARENT *ve) 4074b88c807SRodney W. Grimes { 4084b88c807SRodney W. Grimes VAR *v; 409f8ec5fe2SBruce Evans time_t then; 4104b88c807SRodney W. Grimes char buf[100]; 4114b88c807SRodney W. Grimes 4124b88c807SRodney W. Grimes v = ve->var; 4131f7d2501SKirk McKusick if (!k->ki_valid) { 4144b88c807SRodney W. Grimes (void)printf("%-*s", v->width, "-"); 4154b88c807SRodney W. Grimes return; 4164b88c807SRodney W. Grimes } 4171f7d2501SKirk McKusick then = k->ki_p->ki_start.tv_sec; 418b85add5fSPhilippe Charnier (void)strftime(buf, sizeof(buf), "%c", localtime(&then)); 4194b88c807SRodney W. Grimes (void)printf("%-*s", v->width, buf); 4204b88c807SRodney W. Grimes } 4214b88c807SRodney W. Grimes 4224b88c807SRodney W. Grimes void 4230d632649SJohn Baldwin lockname(KINFO *k, VARENT *ve) 424fd5f30bfSJohn Baldwin { 425fd5f30bfSJohn Baldwin VAR *v; 426fd5f30bfSJohn Baldwin 427fd5f30bfSJohn Baldwin v = ve->var; 4280d632649SJohn Baldwin if (k->ki_p->ki_kiflag & KI_LOCKBLOCK) { 4290d632649SJohn Baldwin if (k->ki_p->ki_lockname[0] != 0) 430fd5f30bfSJohn Baldwin (void)printf("%-*.*s", v->width, v->width, 4310d632649SJohn Baldwin k->ki_p->ki_lockname); 432fd5f30bfSJohn Baldwin else 433fd5f30bfSJohn Baldwin (void)printf("%-*s", v->width, "???"); 434fd5f30bfSJohn Baldwin } else 435fd5f30bfSJohn Baldwin (void)printf("%-*s", v->width, "-"); 436fd5f30bfSJohn Baldwin } 437fd5f30bfSJohn Baldwin 438fd5f30bfSJohn Baldwin void 43946251ddeSWarner Losh wchan(KINFO *k, VARENT *ve) 4404b88c807SRodney W. Grimes { 4414b88c807SRodney W. Grimes VAR *v; 4424b88c807SRodney W. Grimes 4434b88c807SRodney W. Grimes v = ve->var; 4441f7d2501SKirk McKusick if (k->ki_p->ki_wchan) { 4451f7d2501SKirk McKusick if (k->ki_p->ki_wmesg[0] != 0) 4464b88c807SRodney W. Grimes (void)printf("%-*.*s", v->width, v->width, 4471f7d2501SKirk McKusick k->ki_p->ki_wmesg); 4484b88c807SRodney W. Grimes else 4493929d518SDoug Rabson (void)printf("%-*lx", v->width, 4507d1192a7SPeter Wemm (long)k->ki_p->ki_wchan); 451b85add5fSPhilippe Charnier } else 452d9a5f890SMatthew Dillon (void)printf("%-*s", v->width, "-"); 453d9a5f890SMatthew Dillon } 454d9a5f890SMatthew Dillon 455d9a5f890SMatthew Dillon void 456de244df7SHartmut Brandt nwchan(KINFO *k, VARENT *ve) 457de244df7SHartmut Brandt { 458de244df7SHartmut Brandt VAR *v; 459de244df7SHartmut Brandt 460de244df7SHartmut Brandt v = ve->var; 461de244df7SHartmut Brandt if (k->ki_p->ki_wchan) { 462de244df7SHartmut Brandt (void)printf("%0*lx", v->width, 463de244df7SHartmut Brandt (long)k->ki_p->ki_wchan); 464de244df7SHartmut Brandt } else 465de244df7SHartmut Brandt (void)printf("%-*s", v->width, "-"); 466de244df7SHartmut Brandt } 467de244df7SHartmut Brandt 468de244df7SHartmut Brandt void 469d9a5f890SMatthew Dillon mwchan(KINFO *k, VARENT *ve) 470d9a5f890SMatthew Dillon { 471d9a5f890SMatthew Dillon VAR *v; 472d9a5f890SMatthew Dillon 473d9a5f890SMatthew Dillon v = ve->var; 474d9a5f890SMatthew Dillon if (k->ki_p->ki_wchan) { 475d9a5f890SMatthew Dillon if (k->ki_p->ki_wmesg[0] != 0) 476d9a5f890SMatthew Dillon (void)printf("%-*.*s", v->width, v->width, 477d9a5f890SMatthew Dillon k->ki_p->ki_wmesg); 478d9a5f890SMatthew Dillon else 479d9a5f890SMatthew Dillon (void)printf("%-*lx", v->width, 480d9a5f890SMatthew Dillon (long)k->ki_p->ki_wchan); 4810d632649SJohn Baldwin } else if (k->ki_p->ki_kiflag & KI_LOCKBLOCK) { 4820d632649SJohn Baldwin if (k->ki_p->ki_lockname[0]) { 483d9a5f890SMatthew Dillon (void)printf("%-*.*s", v->width, v->width, 4840d632649SJohn Baldwin k->ki_p->ki_lockname); 485b85add5fSPhilippe Charnier } else 486d9a5f890SMatthew Dillon (void)printf("%-*s", v->width, "???"); 487b85add5fSPhilippe Charnier } else 4884b88c807SRodney W. Grimes (void)printf("%-*s", v->width, "-"); 4894b88c807SRodney W. Grimes } 4904b88c807SRodney W. Grimes 4914b88c807SRodney W. Grimes void 49246251ddeSWarner Losh vsize(KINFO *k, VARENT *ve) 4934b88c807SRodney W. Grimes { 4944b88c807SRodney W. Grimes VAR *v; 4954b88c807SRodney W. Grimes 4964b88c807SRodney W. Grimes v = ve->var; 497c1f903a0SBruce Evans (void)printf("%*lu", v->width, (u_long)(k->ki_p->ki_size / 1024)); 4984b88c807SRodney W. Grimes } 4994b88c807SRodney W. Grimes 5004b88c807SRodney W. Grimes void 50146251ddeSWarner Losh cputime(KINFO *k, VARENT *ve) 5024b88c807SRodney W. Grimes { 5034b88c807SRodney W. Grimes VAR *v; 5044b88c807SRodney W. Grimes long secs; 5054b88c807SRodney W. Grimes long psecs; /* "parts" of a second. first micro, then centi */ 5064b88c807SRodney W. Grimes char obuff[128]; 507b85add5fSPhilippe Charnier static char decimal_point; 5084b88c807SRodney W. Grimes 509b85add5fSPhilippe Charnier if (decimal_point == '\0') 5108073a93cSAndrey A. Chernov decimal_point = localeconv()->decimal_point[0]; 5114b88c807SRodney W. Grimes v = ve->var; 51216ac318dSGarance A Drosehn if (!k->ki_valid) { 5135832a752SBruce Evans secs = 0; 5145832a752SBruce Evans psecs = 0; 5154b88c807SRodney W. Grimes } else { 5164b88c807SRodney W. Grimes /* 5174b88c807SRodney W. Grimes * This counts time spent handling interrupts. We could 5184b88c807SRodney W. Grimes * fix this, but it is not 100% trivial (and interrupt 5194b88c807SRodney W. Grimes * time fractions only work on the sparc anyway). XXX 5204b88c807SRodney W. Grimes */ 5211f7d2501SKirk McKusick secs = k->ki_p->ki_runtime / 1000000; 5221f7d2501SKirk McKusick psecs = k->ki_p->ki_runtime % 1000000; 5234b88c807SRodney W. Grimes if (sumrusage) { 5241f7d2501SKirk McKusick secs += k->ki_p->ki_childtime.tv_sec; 5251f7d2501SKirk McKusick psecs += k->ki_p->ki_childtime.tv_usec; 5264b88c807SRodney W. Grimes } 5274b88c807SRodney W. Grimes /* 5284b88c807SRodney W. Grimes * round and scale to 100's 5294b88c807SRodney W. Grimes */ 5305832a752SBruce Evans psecs = (psecs + 5000) / 10000; 5315832a752SBruce Evans secs += psecs / 100; 5325832a752SBruce Evans psecs = psecs % 100; 5335832a752SBruce Evans } 534b85add5fSPhilippe Charnier (void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld%c%02ld", 535b85add5fSPhilippe Charnier secs / 60, secs % 60, decimal_point, psecs); 5364b88c807SRodney W. Grimes (void)printf("%*s", v->width, obuff); 5374b88c807SRodney W. Grimes } 5384b88c807SRodney W. Grimes 53976e1a9feSJuli Mallett void 54076e1a9feSJuli Mallett elapsed(KINFO *k, VARENT *ve) 54176e1a9feSJuli Mallett { 54276e1a9feSJuli Mallett VAR *v; 543b85add5fSPhilippe Charnier time_t val; 544b85add5fSPhilippe Charnier int days, hours, mins, secs; 54576e1a9feSJuli Mallett char obuff[128]; 54676e1a9feSJuli Mallett 54776e1a9feSJuli Mallett v = ve->var; 548b85add5fSPhilippe Charnier val = now - k->ki_p->ki_start.tv_sec; 549b85add5fSPhilippe Charnier days = val / (24 * 60 * 60); 550b85add5fSPhilippe Charnier val %= 24 * 60 * 60; 551b85add5fSPhilippe Charnier hours = val / (60 * 60); 552b85add5fSPhilippe Charnier val %= 60 * 60; 553b85add5fSPhilippe Charnier mins = val / 60; 554b85add5fSPhilippe Charnier secs = val % 60; 555b85add5fSPhilippe Charnier if (days != 0) 556b85add5fSPhilippe Charnier (void)snprintf(obuff, sizeof(obuff), "%3d-%02d:%02d:%02d", 557b85add5fSPhilippe Charnier days, hours, mins, secs); 558b85add5fSPhilippe Charnier else if (hours != 0) 559b85add5fSPhilippe Charnier (void)snprintf(obuff, sizeof(obuff), "%02d:%02d:%02d", 560b85add5fSPhilippe Charnier hours, mins, secs); 561b85add5fSPhilippe Charnier else 562b85add5fSPhilippe Charnier (void)snprintf(obuff, sizeof(obuff), "%02d:%02d", mins, secs); 56376e1a9feSJuli Mallett (void)printf("%*s", v->width, obuff); 56476e1a9feSJuli Mallett } 56576e1a9feSJuli Mallett 5664b88c807SRodney W. Grimes double 567871e8d8cSMark Murray getpcpu(const KINFO *k) 5684b88c807SRodney W. Grimes { 5694b88c807SRodney W. Grimes static int failure; 5704b88c807SRodney W. Grimes 5714b88c807SRodney W. Grimes if (!nlistread) 5724b88c807SRodney W. Grimes failure = donlist(); 5734b88c807SRodney W. Grimes if (failure) 5744b88c807SRodney W. Grimes return (0.0); 5754b88c807SRodney W. Grimes 5764b88c807SRodney W. Grimes #define fxtofl(fixpt) ((double)(fixpt) / fscale) 5774b88c807SRodney W. Grimes 5784b88c807SRodney W. Grimes /* XXX - I don't like this */ 579e0aa5ab7SJohn Baldwin if (k->ki_p->ki_swtime == 0 || (k->ki_p->ki_sflag & PS_INMEM) == 0) 5804b88c807SRodney W. Grimes return (0.0); 5814b88c807SRodney W. Grimes if (rawcpu) 5821f7d2501SKirk McKusick return (100.0 * fxtofl(k->ki_p->ki_pctcpu)); 5831f7d2501SKirk McKusick return (100.0 * fxtofl(k->ki_p->ki_pctcpu) / 5841f7d2501SKirk McKusick (1.0 - exp(k->ki_p->ki_swtime * log(fxtofl(ccpu))))); 5854b88c807SRodney W. Grimes } 5864b88c807SRodney W. Grimes 5874b88c807SRodney W. Grimes void 58846251ddeSWarner Losh pcpu(KINFO *k, VARENT *ve) 5894b88c807SRodney W. Grimes { 5904b88c807SRodney W. Grimes VAR *v; 5914b88c807SRodney W. Grimes 5924b88c807SRodney W. Grimes v = ve->var; 5934b88c807SRodney W. Grimes (void)printf("%*.1f", v->width, getpcpu(k)); 5944b88c807SRodney W. Grimes } 5954b88c807SRodney W. Grimes 596871e8d8cSMark Murray static double 59746251ddeSWarner Losh getpmem(KINFO *k) 5984b88c807SRodney W. Grimes { 5994b88c807SRodney W. Grimes static int failure; 6004b88c807SRodney W. Grimes double fracmem; 6014b88c807SRodney W. Grimes 6024b88c807SRodney W. Grimes if (!nlistread) 6034b88c807SRodney W. Grimes failure = donlist(); 6044b88c807SRodney W. Grimes if (failure) 6054b88c807SRodney W. Grimes return (0.0); 6064b88c807SRodney W. Grimes 607e0aa5ab7SJohn Baldwin if ((k->ki_p->ki_sflag & PS_INMEM) == 0) 6084b88c807SRodney W. Grimes return (0.0); 6094b88c807SRodney W. Grimes /* XXX want pmap ptpages, segtab, etc. (per architecture) */ 6104b88c807SRodney W. Grimes /* XXX don't have info about shared */ 61185012e7cSPeter Wemm fracmem = ((float)k->ki_p->ki_rssize) / mempages; 6124b88c807SRodney W. Grimes return (100.0 * fracmem); 6134b88c807SRodney W. Grimes } 6144b88c807SRodney W. Grimes 6154b88c807SRodney W. Grimes void 61646251ddeSWarner Losh pmem(KINFO *k, VARENT *ve) 6174b88c807SRodney W. Grimes { 6184b88c807SRodney W. Grimes VAR *v; 6194b88c807SRodney W. Grimes 6204b88c807SRodney W. Grimes v = ve->var; 6214b88c807SRodney W. Grimes (void)printf("%*.1f", v->width, getpmem(k)); 6224b88c807SRodney W. Grimes } 6234b88c807SRodney W. Grimes 6244b88c807SRodney W. Grimes void 62546251ddeSWarner Losh pagein(KINFO *k, VARENT *ve) 6264b88c807SRodney W. Grimes { 6274b88c807SRodney W. Grimes VAR *v; 6284b88c807SRodney W. Grimes 6294b88c807SRodney W. Grimes v = ve->var; 6300fd510b7SJoerg Wunsch (void)printf("%*ld", v->width, 6311f7d2501SKirk McKusick k->ki_valid ? k->ki_p->ki_rusage.ru_majflt : 0); 6324b88c807SRodney W. Grimes } 6334b88c807SRodney W. Grimes 634871e8d8cSMark Murray /* ARGSUSED */ 6354b88c807SRodney W. Grimes void 636871e8d8cSMark Murray maxrss(KINFO *k __unused, VARENT *ve) 6374b88c807SRodney W. Grimes { 6384b88c807SRodney W. Grimes VAR *v; 6394b88c807SRodney W. Grimes 6404b88c807SRodney W. Grimes v = ve->var; 641940cca66SPeter Wemm /* XXX not yet */ 6424b88c807SRodney W. Grimes (void)printf("%*s", v->width, "-"); 6434b88c807SRodney W. Grimes } 6444b88c807SRodney W. Grimes 6454b88c807SRodney W. Grimes void 64646251ddeSWarner Losh priorityr(KINFO *k, VARENT *ve) 647ad863cacSSteve Price { 648ad863cacSSteve Price VAR *v; 649871e8d8cSMark Murray struct priority *lpri; 650ad863cacSSteve Price char str[8]; 6514c85452bSJake Burkholder unsigned class, level; 652ad863cacSSteve Price 653ad863cacSSteve Price v = ve->var; 6543998d222SGarance A Drosehn lpri = &k->ki_p->ki_pri; 655871e8d8cSMark Murray class = lpri->pri_class; 656871e8d8cSMark Murray level = lpri->pri_level; 6574c85452bSJake Burkholder switch (class) { 6584c85452bSJake Burkholder case PRI_REALTIME: 6594c85452bSJake Burkholder snprintf(str, sizeof(str), "real:%u", level); 660ad863cacSSteve Price break; 6614c85452bSJake Burkholder case PRI_TIMESHARE: 662ad863cacSSteve Price strncpy(str, "normal", sizeof(str)); 663ad863cacSSteve Price break; 6644c85452bSJake Burkholder case PRI_IDLE: 6654c85452bSJake Burkholder snprintf(str, sizeof(str), "idle:%u", level); 666ad863cacSSteve Price break; 667ad863cacSSteve Price default: 6684c85452bSJake Burkholder snprintf(str, sizeof(str), "%u:%u", class, level); 669ad863cacSSteve Price break; 670ad863cacSSteve Price } 671ad863cacSSteve Price str[sizeof(str) - 1] = '\0'; 672ad863cacSSteve Price (void)printf("%*s", v->width, str); 673ad863cacSSteve Price } 674ad863cacSSteve Price 6754b88c807SRodney W. Grimes /* 6764b88c807SRodney W. Grimes * Generic output routines. Print fields from various prototype 6774b88c807SRodney W. Grimes * structures. 6784b88c807SRodney W. Grimes */ 6794b88c807SRodney W. Grimes static void 680ffe25988SJuli Mallett printval(void *bp, VAR *v) 6814b88c807SRodney W. Grimes { 6824b88c807SRodney W. Grimes static char ofmt[32] = "%"; 683fdbec398SJuli Mallett const char *fcp; 684fdbec398SJuli Mallett char *cp; 6854b88c807SRodney W. Grimes 6864b88c807SRodney W. Grimes cp = ofmt + 1; 6874b88c807SRodney W. Grimes fcp = v->fmt; 6884b88c807SRodney W. Grimes if (v->flag & LJUST) 6894b88c807SRodney W. Grimes *cp++ = '-'; 6904b88c807SRodney W. Grimes *cp++ = '*'; 6910fd510b7SJoerg Wunsch while ((*cp++ = *fcp++)); 6924b88c807SRodney W. Grimes 693e2c9ac69STim J. Robbins #define CHKINF127(n) (((n) > 127) && (v->flag & INF127) ? 127 : (n)) 694e2c9ac69STim J. Robbins 6954b88c807SRodney W. Grimes switch (v->type) { 6964b88c807SRodney W. Grimes case CHAR: 6974b88c807SRodney W. Grimes (void)printf(ofmt, v->width, *(char *)bp); 6984b88c807SRodney W. Grimes break; 6994b88c807SRodney W. Grimes case UCHAR: 7004b88c807SRodney W. Grimes (void)printf(ofmt, v->width, *(u_char *)bp); 7014b88c807SRodney W. Grimes break; 7024b88c807SRodney W. Grimes case SHORT: 7034b88c807SRodney W. Grimes (void)printf(ofmt, v->width, *(short *)bp); 7044b88c807SRodney W. Grimes break; 7054b88c807SRodney W. Grimes case USHORT: 7064b88c807SRodney W. Grimes (void)printf(ofmt, v->width, *(u_short *)bp); 7074b88c807SRodney W. Grimes break; 7083929d518SDoug Rabson case INT: 7093929d518SDoug Rabson (void)printf(ofmt, v->width, *(int *)bp); 7103929d518SDoug Rabson break; 7113929d518SDoug Rabson case UINT: 712e2c9ac69STim J. Robbins (void)printf(ofmt, v->width, CHKINF127(*(u_int *)bp)); 7133929d518SDoug Rabson break; 7144b88c807SRodney W. Grimes case LONG: 7154b88c807SRodney W. Grimes (void)printf(ofmt, v->width, *(long *)bp); 7164b88c807SRodney W. Grimes break; 7174b88c807SRodney W. Grimes case ULONG: 7184b88c807SRodney W. Grimes (void)printf(ofmt, v->width, *(u_long *)bp); 7194b88c807SRodney W. Grimes break; 7204b88c807SRodney W. Grimes case KPTR: 7217d1192a7SPeter Wemm (void)printf(ofmt, v->width, *(u_long *)bp); 7224b88c807SRodney W. Grimes break; 723362d62baSJuli Mallett case PGTOK: 724760bbf7dSJuli Mallett (void)printf(ofmt, v->width, ps_pgtok(*(u_long *)bp)); 725760bbf7dSJuli Mallett break; 7264b88c807SRodney W. Grimes default: 7274b88c807SRodney W. Grimes errx(1, "unknown type %d", v->type); 7284b88c807SRodney W. Grimes } 7294b88c807SRodney W. Grimes } 7304b88c807SRodney W. Grimes 7314b88c807SRodney W. Grimes void 73246251ddeSWarner Losh kvar(KINFO *k, VARENT *ve) 7334b88c807SRodney W. Grimes { 7344b88c807SRodney W. Grimes VAR *v; 7354b88c807SRodney W. Grimes 7364b88c807SRodney W. Grimes v = ve->var; 7371f7d2501SKirk McKusick printval((char *)((char *)k->ki_p + v->off), v); 7384b88c807SRodney W. Grimes } 7394b88c807SRodney W. Grimes 7404b88c807SRodney W. Grimes void 74146251ddeSWarner Losh rvar(KINFO *k, VARENT *ve) 7424b88c807SRodney W. Grimes { 7434b88c807SRodney W. Grimes VAR *v; 7444b88c807SRodney W. Grimes 7454b88c807SRodney W. Grimes v = ve->var; 7461f7d2501SKirk McKusick if (k->ki_valid) 7471f7d2501SKirk McKusick printval((char *)((char *)(&k->ki_p->ki_rusage) + v->off), v); 7484b88c807SRodney W. Grimes else 7494b88c807SRodney W. Grimes (void)printf("%*s", v->width, "-"); 7504b88c807SRodney W. Grimes } 7517304f61fSBrian Feldman 7527304f61fSBrian Feldman void 75315b87b53SGarance A Drosehn emulname(KINFO *k, VARENT *ve) 75415b87b53SGarance A Drosehn { 75515b87b53SGarance A Drosehn VAR *v; 75615b87b53SGarance A Drosehn 75715b87b53SGarance A Drosehn v = ve->var; 75815b87b53SGarance A Drosehn printf("%-*s", v->width, *k->ki_p->ki_emul ? k->ki_p->ki_emul : "-"); 75915b87b53SGarance A Drosehn } 76015b87b53SGarance A Drosehn 76115b87b53SGarance A Drosehn void 7622af538ebSRobert Watson label(KINFO *k, VARENT *ve) 7637304f61fSBrian Feldman { 7642af538ebSRobert Watson char *string; 765b85add5fSPhilippe Charnier VAR *v; 766775bba9fSJuli Mallett mac_t proclabel; 7672af538ebSRobert Watson int error; 7687304f61fSBrian Feldman 7697304f61fSBrian Feldman v = ve->var; 7702af538ebSRobert Watson string = NULL; 771775bba9fSJuli Mallett if (mac_prepare_process_label(&proclabel) == -1) { 7722af538ebSRobert Watson perror("mac_prepare_process_label"); 7732af538ebSRobert Watson goto out; 7742af538ebSRobert Watson } 775775bba9fSJuli Mallett error = mac_get_pid(k->ki_p->ki_pid, proclabel); 7762af538ebSRobert Watson if (error == 0) { 777775bba9fSJuli Mallett if (mac_to_text(proclabel, &string) == -1) 7782af538ebSRobert Watson string = NULL; 7792af538ebSRobert Watson } 780775bba9fSJuli Mallett mac_free(proclabel); 7812af538ebSRobert Watson out: 7822af538ebSRobert Watson if (string != NULL) { 7832af538ebSRobert Watson (void)printf("%-*s", v->width, string); 7842af538ebSRobert Watson free(string); 7852af538ebSRobert Watson } else 786ce1affa2SGarance A Drosehn (void)printf("%-*s", v->width, " -"); 7872af538ebSRobert Watson return; 7882af538ebSRobert Watson } 7892af538ebSRobert Watson 7902af538ebSRobert Watson int 7912af538ebSRobert Watson s_label(KINFO *k) 7922af538ebSRobert Watson { 7932af538ebSRobert Watson char *string = NULL; 794775bba9fSJuli Mallett mac_t proclabel; 7952af538ebSRobert Watson int error, size = 0; 7962af538ebSRobert Watson 797775bba9fSJuli Mallett if (mac_prepare_process_label(&proclabel) == -1) { 7982af538ebSRobert Watson perror("mac_prepare_process_label"); 7992af538ebSRobert Watson return (0); 8002af538ebSRobert Watson } 801775bba9fSJuli Mallett error = mac_get_pid(k->ki_p->ki_pid, proclabel); 802775bba9fSJuli Mallett if (error == 0 && mac_to_text(proclabel, &string) == 0) { 8032af538ebSRobert Watson size = strlen(string); 8042af538ebSRobert Watson free(string); 8052af538ebSRobert Watson } 806775bba9fSJuli Mallett mac_free(proclabel); 8072af538ebSRobert Watson return (size); 8087304f61fSBrian Feldman } 809