home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / crh / freebsd / rootkit / ps / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-27  |  14.3 KB  |  755 lines

  1. /*-
  2.  * Copyright (c) 1990, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    $Id: print.c,v 1.16.2.2 1997/08/03 08:33:17 peter Exp $
  34.  */
  35.  
  36. #ifndef lint
  37. static char sccsid[] = "@(#)print.c    8.6 (Berkeley) 4/16/94";
  38. #endif /* not lint */
  39.  
  40. #include <sys/param.h>
  41. #include <sys/time.h>
  42. #include <sys/resource.h>
  43. #include <sys/proc.h>
  44. #include <sys/stat.h>
  45.  
  46. #ifdef P_PPWAIT
  47. #define NEWVM
  48. #endif
  49.  
  50. #ifdef NEWVM
  51. #include <sys/ucred.h>
  52. #include <sys/user.h>
  53. #include <sys/sysctl.h>
  54. #include <vm/vm.h>
  55. #else
  56. #include <machine/pte.h>
  57. #include <sys/vmparam.h>
  58. #include <sys/vm.h>
  59. #endif
  60.  
  61. #include <err.h>
  62. #include <math.h>
  63. #include <nlist.h>
  64. #include <stddef.h>
  65. #include <stdio.h>
  66. #include <stdlib.h>
  67. #include <unistd.h>
  68. #include <string.h>
  69. #include <vis.h>
  70.  
  71. #include "ps.h"
  72.  
  73. void
  74. printheader()
  75. {
  76.     VAR *v;
  77.     struct varent *vent;
  78.  
  79.     for (vent = vhead; vent; vent = vent->next) {
  80.         v = vent->var;
  81.         if (v->flag & LJUST) {
  82.             if (vent->next == NULL)    /* last one */
  83.                 (void)printf("%s", v->header);
  84.             else
  85.                 (void)printf("%-*s", v->width, v->header);
  86.         } else
  87.             (void)printf("%*s", v->width, v->header);
  88.         if (vent->next != NULL)
  89.             (void)putchar(' ');
  90.     }
  91.     (void)putchar('\n');
  92. }
  93.  
  94. void
  95. command(k, ve)
  96.     KINFO *k;
  97.     VARENT *ve;
  98. {
  99.     VAR *v;
  100.     int left;
  101.     char *cp, *vis_env, *vis_args;
  102.  
  103.     v = ve->var;
  104.  
  105.     if (cflag) {
  106.         if (ve->next == NULL)    /* last field, don't pad */
  107.             (void)printf("%s", KI_PROC(k)->p_comm);
  108.         else
  109.             (void)printf("%-*s", v->width, KI_PROC(k)->p_comm);
  110.         return;
  111.     }
  112.  
  113.     if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
  114.         err(1, NULL);
  115.     strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
  116.     if (k->ki_env) {
  117.         if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1)) == NULL)
  118.             err(1, NULL);
  119.         strvis(vis_env, k->ki_env, VIS_TAB | VIS_NL | VIS_NOSLASH);
  120.     } else
  121.         vis_env = NULL;
  122.  
  123.     if (ve->next == NULL) {
  124.         /* last field */
  125.         if (termwidth == UNLIMITED) {
  126.             if (vis_env)
  127.                 (void)printf("%s ", vis_env);
  128.             (void)printf("%s", vis_args);
  129.         } else {
  130.             left = termwidth - (totwidth - v->width);
  131.             if (left < 1) /* already wrapped, just use std width */
  132.                 left = v->width;
  133.             if ((cp = vis_env) != NULL) {
  134.                 while (--left >= 0 && *cp)
  135.                     (void)putchar(*cp++);
  136.                 if (--left >= 0)
  137.                     putchar(' ');
  138.             }
  139.             for (cp = vis_args; --left >= 0 && *cp != '\0';)
  140.                 (void)putchar(*cp++);
  141.         }
  142.     } else
  143.         /* XXX env? */
  144.         (void)printf("%-*.*s", v->width, v->width, vis_args);
  145.     free(vis_args);
  146.     if (vis_env != NULL)
  147.         free(vis_env);
  148. }
  149.  
  150. void
  151. ucomm(k, ve)
  152.     KINFO *k;
  153.     VARENT *ve;
  154. {
  155.     VAR *v;
  156.  
  157.     v = ve->var;
  158.     (void)printf("%-*s", v->width, KI_PROC(k)->p_comm);
  159. }
  160.  
  161. void
  162. logname(k, ve)
  163.     KINFO *k;
  164.     VARENT *ve;
  165. {
  166.     VAR *v;
  167.  
  168.     v = ve->var;
  169. #ifndef NEWVM
  170.     (void)printf("%-*s", v->width, KI_PROC(k)->p_logname);
  171. #else
  172.     (void)printf("%-*s", v->width, KI_EPROC(k)->e_login);
  173. #endif
  174. }
  175.  
  176. void
  177. state(k, ve)
  178.     KINFO *k;
  179.     VARENT *ve;
  180. {
  181.     struct proc *p;
  182.     int flag;
  183.     char *cp;
  184.     VAR *v;
  185.     char buf[16];
  186.  
  187.     v = ve->var;
  188.     p = KI_PROC(k);
  189.     flag = p->p_flag;
  190.     cp = buf;
  191.  
  192.     switch (p->p_stat) {
  193.  
  194.     case SSTOP:
  195.         *cp = 'T';
  196.         break;
  197.  
  198.     case SSLEEP:
  199.         if (flag & P_SINTR)    /* interuptable (long) */
  200.             *cp = p->p_slptime >= MAXSLP ? 'I' : 'S';
  201.         else
  202.             *cp = 'D';
  203.         break;
  204.  
  205.     case SRUN:
  206.     case SIDL:
  207.         *cp = 'R';
  208.         break;
  209.  
  210.     case SZOMB:
  211.         *cp = 'Z';
  212.         break;
  213.  
  214.     default:
  215.         *cp = '?';
  216.     }
  217.     cp++;
  218.     if (flag & P_INMEM) {
  219. #ifndef NEWVM
  220.         if (p->p_rssize > p->p_maxrss)
  221.             *cp++ = '>';
  222. #endif
  223.     } else
  224.         *cp++ = 'W';
  225.     if (p->p_nice < NZERO)
  226.         *cp++ = '<';
  227.     else if (p->p_nice > NZERO)
  228.         *cp++ = 'N';
  229. #ifndef NEWVM
  230.     if (flag & SUANOM)
  231.         *cp++ = 'A';
  232.     else if (flag & SSEQL)
  233.         *cp++ = 'S';
  234. #endif
  235.     if (flag & P_TRACED)
  236.         *cp++ = 'X';
  237.     if (flag & P_WEXIT && p->p_stat != SZOMB)
  238.         *cp++ = 'E';
  239. #ifdef NEWVM
  240.     if (flag & P_PPWAIT)
  241. #else
  242.     if (flag & SVFORK)
  243. #endif
  244.         *cp++ = 'V';
  245. #ifdef NEWVM
  246.     if (flag & (P_SYSTEM | P_NOSWAP | P_PHYSIO))
  247. #else
  248.     if (flag & (SSYS|SLOCK|SULOCK|SKEEP|SPHYSIO))
  249. #endif
  250.         *cp++ = 'L';
  251.     if (KI_EPROC(k)->e_flag & EPROC_SLEADER)
  252.         *cp++ = 's';
  253.     if ((flag & P_CONTROLT) && KI_EPROC(k)->e_pgid == KI_EPROC(k)->e_tpgid)
  254.         *cp++ = '+';
  255.     *cp = '\0';
  256.     (void)printf("%-*s", v->width, buf);
  257. }
  258.  
  259. void
  260. pri(k, ve)
  261.     KINFO *k;
  262.     VARENT *ve;
  263. {
  264.     VAR *v;
  265.  
  266.     v = ve->var;
  267.     (void)printf("%*d", v->width, KI_PROC(k)->p_priority - PZERO);
  268. }
  269.  
  270. void
  271. uname(k, ve)
  272.     KINFO *k;
  273.     VARENT *ve;
  274. {
  275.     VAR *v;
  276.  
  277.     v = ve->var;
  278. #ifndef NEWVM
  279.     (void)printf("%-*s",
  280.         (int)v->width, user_from_uid(KI_PROC(k)->p_uid, 0));
  281. #else
  282.     (void)printf("%-*s",
  283.         (int)v->width, user_from_uid(KI_EPROC(k)->e_ucred.cr_uid, 0));
  284. #endif
  285. }
  286.  
  287. void
  288. runame(k, ve)
  289.     KINFO *k;
  290.     VARENT *ve;
  291. {
  292.     VAR *v;
  293.  
  294.     v = ve->var;
  295. #ifndef NEWVM
  296.     (void)printf("%-*s",
  297.         (int)v->width, user_from_uid(KI_PROC(k)->p_ruid, 0));
  298. #else
  299.     (void)printf("%-*s",
  300.         (int)v->width, user_from_uid(KI_EPROC(k)->e_pcred.p_ruid, 0));
  301. #endif
  302. }
  303.  
  304. void
  305. tdev(k, ve)
  306.     KINFO *k;
  307.     VARENT *ve;
  308. {
  309.     VAR *v;
  310.     dev_t dev;
  311.     char buff[16];
  312.  
  313.     v = ve->var;
  314.     dev = KI_EPROC(k)->e_tdev;
  315.     if (dev == NODEV)
  316.         (void)printf("%*s", v->width, "??");
  317.     else {
  318.         (void)snprintf(buff, sizeof(buff),
  319.             "%d/%d", major(dev), minor(dev));
  320.         (void)printf("%*s", v->width, buff);
  321.     }
  322. }
  323.  
  324. void
  325. tname(k, ve)
  326.     KINFO *k;
  327.     VARENT *ve;
  328. {
  329.     VAR *v;
  330.     dev_t dev;
  331.     char *ttname;
  332.  
  333.     v = ve->var;
  334.     dev = KI_EPROC(k)->e_tdev;
  335.     if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
  336.         (void)printf("%*s ", v->width-1, "??");
  337.     else {
  338.         if (strncmp(ttname, "tty", 3) == 0 ||
  339.             strncmp(ttname, "cua", 3) == 0)
  340.             ttname += 3;
  341.         (void)printf("%*.*s%c", v->width-1, v->width-1, ttname,
  342.             KI_EPROC(k)->e_flag & EPROC_CTTY ? ' ' : '-');
  343.     }
  344. }
  345.  
  346. void
  347. longtname(k, ve)
  348.     KINFO *k;
  349.     VARENT *ve;
  350. {
  351.     VAR *v;
  352.     dev_t dev;
  353.     char *ttname;
  354.  
  355.     v = ve->var;
  356.     dev = KI_EPROC(k)->e_tdev;
  357.     if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
  358.         (void)printf("%-*s", v->width, "??");
  359.     else
  360.         (void)printf("%-*s", v->width, ttname);
  361. }
  362.  
  363. void
  364. started(k, ve)
  365.     KINFO *k;
  366.     VARENT *ve;
  367. {
  368.     VAR *v;
  369.     static time_t now;
  370.     struct tm *tp;
  371.     char buf[100];
  372.  
  373.     v = ve->var;
  374.     if (!k->ki_u.u_valid) {
  375.         (void)printf("%-*s", v->width, "-");
  376.         return;
  377.     }
  378.  
  379.     tp = localtime(&k->ki_u.u_start.tv_sec);
  380.     if (!now)
  381.         (void)time(&now);
  382.     if (now - k->ki_u.u_start.tv_sec < 24 * 3600) {
  383.         /* I *hate* SCCS... */
  384.         static char fmt[] = __CONCAT("%l:%", "M%p");
  385.         (void)strftime(buf, sizeof(buf) - 1, fmt, tp);
  386.     } else if (now - k->ki_u.u_start.tv_sec < 7 * 86400) {
  387.         /* I *hate* SCCS... */
  388.         static char fmt[] = __CONCAT("%a%", "I%p");
  389.         (void)strftime(buf, sizeof(buf) - 1, fmt, tp);
  390.     } else
  391.         (void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp);
  392.     (void)printf("%-*s", v->width, buf);
  393. }
  394.  
  395. void
  396. lstarted(k, ve)
  397.     KINFO *k;
  398.     VARENT *ve;
  399. {
  400.     VAR *v;
  401.     char buf[100];
  402.  
  403.     v = ve->var;
  404.     if (!k->ki_u.u_valid) {
  405.         (void)printf("%-*s", v->width, "-");
  406.         return;
  407.     }
  408.     (void)strftime(buf, sizeof(buf) -1, "%c",
  409.         localtime(&k->ki_u.u_start.tv_sec));
  410.     (void)printf("%-*s", v->width, buf);
  411. }
  412.  
  413. void
  414. wchan(k, ve)
  415.     KINFO *k;
  416.     VARENT *ve;
  417. {
  418.     VAR *v;
  419.  
  420.     v = ve->var;
  421.     if (KI_PROC(k)->p_wchan) {
  422.         if (KI_PROC(k)->p_wmesg)
  423.             (void)printf("%-*.*s", v->width, v->width,
  424.                       KI_EPROC(k)->e_wmesg);
  425.         else
  426.             (void)printf("%-*x", v->width,
  427.                 (int)KI_PROC(k)->p_wchan &~ KERNBASE);
  428.     } else
  429.         (void)printf("%-*s", v->width, "-");
  430. }
  431.  
  432. #define pgtok(a)        (((a)*getpagesize())/1024)
  433.  
  434. void
  435. vsize(k, ve)
  436.     KINFO *k;
  437.     VARENT *ve;
  438. {
  439.     VAR *v;
  440.  
  441.     v = ve->var;
  442.     (void)printf("%*d", v->width,
  443. #ifndef NEWVM
  444.         pgtok(KI_PROC(k)->p_dsize +
  445.             KI_PROC(k)->p_ssize + KI_EPROC(k)->e_xsize));
  446. #else
  447.         pgtok(KI_EPROC(k)->e_vm.vm_dsize + KI_EPROC(k)->e_vm.vm_ssize +
  448.         KI_EPROC(k)->e_vm.vm_tsize));
  449. #endif
  450. }
  451.  
  452. void
  453. rssize(k, ve)
  454.     KINFO *k;
  455.     VARENT *ve;
  456. {
  457.     VAR *v;
  458.  
  459.     v = ve->var;
  460. #ifndef NEWVM
  461.     (void)printf("%*d", v->width,
  462.         pgtok(KI_PROC(k)->p_rssize + (KI_EPROC(k)->e_xccount ?
  463.         (KI_EPROC(k)->e_xrssize / KI_EPROC(k)->e_xccount) : 0)));
  464. #else
  465.     /* XXX don't have info about shared */
  466.     (void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_rssize));
  467. #endif
  468. }
  469.  
  470. void
  471. p_rssize(k, ve)        /* doesn't account for text */
  472.     KINFO *k;
  473.     VARENT *ve;
  474. {
  475.     VAR *v;
  476.  
  477.     v = ve->var;
  478. #ifndef NEWVM
  479.     (void)printf("%*d", v->width, pgtok(KI_PROC(k)->p_rssize));
  480. #else
  481.     (void)printf("%*ld", v->width, pgtok(KI_EPROC(k)->e_vm.vm_rssize));
  482. #endif
  483. }
  484.  
  485. void
  486. cputime(k, ve)
  487.     KINFO *k;
  488.     VARENT *ve;
  489. {
  490.     VAR *v;
  491.     long secs;
  492.     long psecs;    /* "parts" of a second. first micro, then centi */
  493.     char obuff[128];
  494.  
  495.     v = ve->var;
  496.     if (KI_PROC(k)->p_stat == SZOMB || !k->ki_u.u_valid) {
  497.         secs = 0;
  498.         psecs = 0;
  499.     } else {
  500.         /*
  501.          * This counts time spent handling interrupts.  We could
  502.          * fix this, but it is not 100% trivial (and interrupt
  503.          * time fractions only work on the sparc anyway).    XXX
  504.          */
  505.         secs = KI_PROC(k)->p_rtime.tv_sec;
  506.         psecs = KI_PROC(k)->p_rtime.tv_usec;
  507.         if (sumrusage) {
  508.             secs += k->ki_u.u_cru.ru_utime.tv_sec +
  509.                 k->ki_u.u_cru.ru_stime.tv_sec;
  510.             psecs += k->ki_u.u_cru.ru_utime.tv_usec +
  511.                 k->ki_u.u_cru.ru_stime.tv_usec;
  512.         }
  513.         /*
  514.          * round and scale to 100's
  515.          */
  516.         psecs = (psecs + 5000) / 10000;
  517.         secs += psecs / 100;
  518.         psecs = psecs % 100;
  519.     }
  520.     (void)snprintf(obuff, sizeof(obuff),
  521.         "%3ld:%02ld.%02ld", secs/60, secs%60, psecs);
  522.     (void)printf("%*s", v->width, obuff);
  523. }
  524.  
  525. double
  526. getpcpu(k)
  527.     KINFO *k;
  528. {
  529.     struct proc *p;
  530.     static int failure;
  531.  
  532.     if (!nlistread)
  533.         failure = donlist();
  534.     if (failure)
  535.         return (0.0);
  536.  
  537.     p = KI_PROC(k);
  538. #define    fxtofl(fixpt)    ((double)(fixpt) / fscale)
  539.  
  540.     /* XXX - I don't like this */
  541.     if (p->p_swtime == 0 || (p->p_flag & P_INMEM) == 0)
  542.         return (0.0);
  543.     if (rawcpu)
  544.         return (10000.0 / sysconf(_SC_CLK_TCK) * fxtofl(p->p_pctcpu));
  545.     return (10000.0 / sysconf(_SC_CLK_TCK) * fxtofl(p->p_pctcpu) /
  546.         (1.0 - exp(p->p_swtime * log(fxtofl(ccpu)))));
  547. }
  548.  
  549. void
  550. pcpu(k, ve)
  551.     KINFO *k;
  552.     VARENT *ve;
  553. {
  554.     VAR *v;
  555.  
  556.     v = ve->var;
  557.     (void)printf("%*.1f", v->width, getpcpu(k));
  558. }
  559.  
  560. double
  561. getpmem(k)
  562.     KINFO *k;
  563. {
  564.     static int failure;
  565.     struct proc *p;
  566.     struct eproc *e;
  567.     double fracmem;
  568.     int szptudot;
  569.  
  570.     if (!nlistread)
  571.         failure = donlist();
  572.     if (failure)
  573.         return (0.0);
  574.  
  575.     p = KI_PROC(k);
  576.     e = KI_EPROC(k);
  577.     if ((p->p_flag & P_INMEM) == 0)
  578.         return (0.0);
  579. #ifndef NEWVM
  580.     szptudot = UPAGES + clrnd(ctopt(p->p_dsize + p->p_ssize + e->e_xsize));
  581.     fracmem = ((float)p->p_rssize + szptudot)/CLSIZE/mempages;
  582.     if (p->p_textp && e->e_xccount)
  583.         fracmem += ((float)e->e_xrssize)/CLSIZE/e->e_xccount/mempages;
  584. #else
  585.     /* XXX want pmap ptpages, segtab, etc. (per architecture) */
  586.     szptudot = UPAGES;
  587.     /* XXX don't have info about shared */
  588.     fracmem = ((float)e->e_vm.vm_rssize + szptudot)/mempages;
  589. #endif
  590.     return (100.0 * fracmem);
  591. }
  592.  
  593. void
  594. pmem(k, ve)
  595.     KINFO *k;
  596.     VARENT *ve;
  597. {
  598.     VAR *v;
  599.  
  600.     v = ve->var;
  601.     (void)printf("%*.1f", v->width, getpmem(k));
  602. }
  603.  
  604. void
  605. pagein(k, ve)
  606.     KINFO *k;
  607.     VARENT *ve;
  608. {
  609.     VAR *v;
  610.  
  611.     v = ve->var;
  612.     (void)printf("%*ld", v->width,
  613.         k->ki_u.u_valid ? k->ki_u.u_ru.ru_majflt : 0);
  614. }
  615.  
  616. void
  617. maxrss(k, ve)
  618.     KINFO *k;
  619.     VARENT *ve;
  620. {
  621.     VAR *v;
  622.  
  623.     v = ve->var;
  624. #ifndef NEWVM    /* not yet */
  625.     if (KI_PROC(k)->p_maxrss != (RLIM_INFINITY/PAGE_SIZE))
  626.         (void)printf("%*d", v->width, pgtok(KI_PROC(k)->p_maxrss));
  627.     else
  628. #endif
  629.         (void)printf("%*s", v->width, "-");
  630. }
  631.  
  632. void
  633. tsize(k, ve)
  634.     KINFO *k;
  635.     VARENT *ve;
  636. {
  637.     VAR *v;
  638.  
  639.     v = ve->var;
  640. #ifndef NEWVM
  641.     (void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_xsize));
  642. #else
  643.     (void)printf("%*ld", v->width, pgtok(KI_EPROC(k)->e_vm.vm_tsize));
  644. #endif
  645. }
  646.  
  647. #ifndef NEWVM
  648. void
  649. trss(k, ve)
  650.     KINFO *k;
  651.     VARENT *ve;
  652. {
  653.     VAR *v;
  654.  
  655.     v = ve->var;
  656.     (void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_xrssize));
  657. }
  658. #endif
  659.  
  660. /*
  661.  * Generic output routines.  Print fields from various prototype
  662.  * structures.
  663.  */
  664. static void
  665. printval(bp, v)
  666.     char *bp;
  667.     VAR *v;
  668. {
  669.     static char ofmt[32] = "%";
  670.     char *fcp, *cp;
  671.  
  672.     cp = ofmt + 1;
  673.     fcp = v->fmt;
  674.     if (v->flag & LJUST)
  675.         *cp++ = '-';
  676.     *cp++ = '*';
  677.     while ((*cp++ = *fcp++));
  678.  
  679.     switch (v->type) {
  680.     case CHAR:
  681.         (void)printf(ofmt, v->width, *(char *)bp);
  682.         break;
  683.     case UCHAR:
  684.         (void)printf(ofmt, v->width, *(u_char *)bp);
  685.         break;
  686.     case SHORT:
  687.         (void)printf(ofmt, v->width, *(short *)bp);
  688.         break;
  689.     case USHORT:
  690.         (void)printf(ofmt, v->width, *(u_short *)bp);
  691.         break;
  692.     case LONG:
  693.         (void)printf(ofmt, v->width, *(long *)bp);
  694.         break;
  695.     case ULONG:
  696.         (void)printf(ofmt, v->width, *(u_long *)bp);
  697.         break;
  698.     case KPTR:
  699.         (void)printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE);
  700.         break;
  701.     default:
  702.         errx(1, "unknown type %d", v->type);
  703.     }
  704. }
  705.  
  706. void
  707. pvar(k, ve)
  708.     KINFO *k;
  709.     VARENT *ve;
  710. {
  711.     VAR *v;
  712.  
  713.     v = ve->var;
  714.     printval((char *)((char *)KI_PROC(k) + v->off), v);
  715. }
  716.  
  717. void
  718. evar(k, ve)
  719.     KINFO *k;
  720.     VARENT *ve;
  721. {
  722.     VAR *v;
  723.  
  724.     v = ve->var;
  725.     printval((char *)((char *)KI_EPROC(k) + v->off), v);
  726. }
  727.  
  728. void
  729. uvar(k, ve)
  730.     KINFO *k;
  731.     VARENT *ve;
  732. {
  733.     VAR *v;
  734.  
  735.     v = ve->var;
  736.     if (k->ki_u.u_valid)
  737.         printval((char *)((char *)&k->ki_u + v->off), v);
  738.     else
  739.         (void)printf("%*s", v->width, "-");
  740. }
  741.  
  742. void
  743. rvar(k, ve)
  744.     KINFO *k;
  745.     VARENT *ve;
  746. {
  747.     VAR *v;
  748.  
  749.     v = ve->var;
  750.     if (k->ki_u.u_valid)
  751.         printval((char *)((char *)(&k->ki_u.u_ru) + v->off), v);
  752.     else
  753.         (void)printf("%*s", v->width, "-");
  754. }
  755.