Print this page
OS-3280 need a way to specify the root of a native system in the lx brand
OS-3279 lx brand should allow delegated datasets
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/prstat/prstat.c
          +++ new/usr/src/cmd/prstat/prstat.c
↓ open down ↓ 173 lines elided ↑ open up ↑
 174  174  
 175  175  static optdesc_t opts = {
 176  176          5,                      /* interval between updates, seconds */
 177  177          15,                     /* number of lines in top part */
 178  178          5,                      /* number of lines in bottom part */
 179  179          -1,                     /* number of iterations; infinitely */
 180  180          OPT_PSINFO | OPT_FULLSCREEN | OPT_USEHOME | OPT_TERMCAP,
 181  181          -1                      /* sort in decreasing order */
 182  182  };
 183  183  
      184 +
      185 +static int
      186 +proc_snprintf(char *_RESTRICT_KYWD s, size_t n,
      187 +    const char *_RESTRICT_KYWD fmt, ...)
      188 +{
      189 +        static boolean_t ptools_zroot_valid = B_FALSE;
      190 +        static const char *ptools_zroot = NULL;
      191 +        va_list args;
      192 +        int ret, nret = 0;
      193 +
      194 +        if (ptools_zroot_valid == B_FALSE) {
      195 +                ptools_zroot_valid = B_TRUE;
      196 +                ptools_zroot = zone_get_nroot();
      197 +        }
      198 +
      199 +        if (ptools_zroot != NULL) {
      200 +                nret = snprintf(s, n, "%s", ptools_zroot);
      201 +                if (nret > n)
      202 +                        return (nret);
      203 +        }
      204 +        va_start(args, fmt);
      205 +        ret = vsnprintf(s + nret, n - nret, fmt, args);
      206 +        va_end(args);
      207 +
      208 +        return (ret + nret);
      209 +}
      210 +
 184  211  /*
 185  212   * Print timestamp as decimal reprentation of time_t value (-d u was specified)
 186  213   * or the standard date format (-d d was specified).
 187  214   */
 188  215  static void
 189  216  print_timestamp(void)
 190  217  {
 191  218          time_t t = time(NULL);
 192  219          static char *fmt = NULL;
 193  220  
↓ open down ↓ 647 lines elided ↑ open up ↑
 841  868                  lwp->li_icx = usage->pr_ictx - lwp->li_usage.pr_ictx;
 842  869                  lwp->li_scl = usage->pr_sysc - lwp->li_usage.pr_sysc;
 843  870                  lwp->li_sig = usage->pr_sigs - lwp->li_usage.pr_sigs;
 844  871                  (void) memcpy(&lwp->li_usage, usage, sizeof (prusage_t));
 845  872          }
 846  873  }
 847  874  
 848  875  static int
 849  876  read_procfile(fd_t **fd, char *pidstr, char *file, void *buf, size_t bufsize)
 850  877  {
 851      -        char procfile[MAX_PROCFS_PATH];
      878 +        char procfile[PATH_MAX];
 852  879  
 853      -        (void) snprintf(procfile, MAX_PROCFS_PATH,
      880 +        (void) proc_snprintf(procfile, PATH_MAX,
 854  881              "/proc/%s/%s", pidstr, file);
 855  882          if ((*fd = fd_open(procfile, O_RDONLY, *fd)) == NULL)
 856  883                  return (1);
 857  884          if (pread(fd_getfd(*fd), buf, bufsize, 0) != bufsize) {
 858  885                  fd_close(*fd);
 859  886                  return (1);
 860  887          }
 861  888          return (0);
 862  889  }
 863  890  
↓ open down ↓ 505 lines elided ↑ open up ↑
1369 1396  int
1370 1397  main(int argc, char **argv)
1371 1398  {
1372 1399          DIR *procdir;
1373 1400          char *p;
1374 1401          char *sortk = "cpu";    /* default sort key */
1375 1402          int opt;
1376 1403          int timeout;
1377 1404          struct pollfd pollset;
1378 1405          char key;
     1406 +        char procpath[PATH_MAX];
1379 1407  
1380 1408          (void) setlocale(LC_ALL, "");
1381 1409          (void) textdomain(TEXT_DOMAIN);
1382 1410          Progname(argv[0]);
1383 1411          lwpid_init();
1384 1412          fd_init(Setrlimit());
1385 1413  
1386 1414          pagesize = sysconf(_SC_PAGESIZE);
1387 1415  
1388 1416          while ((opt = getopt(argc, argv,
↓ open down ↓ 179 lines elided ↑ open up ↑
1568 1596          list_alloc(&zones, opts.o_nbottom);
1569 1597          list_alloc(&lgroups, opts.o_nbottom);
1570 1598          list_setkeyfunc(sortk, &opts, &lwps, LT_LWPS);
1571 1599          list_setkeyfunc(NULL, &opts, &users, LT_USERS);
1572 1600          list_setkeyfunc(NULL, &opts, &tasks, LT_TASKS);
1573 1601          list_setkeyfunc(NULL, &opts, &projects, LT_PROJECTS);
1574 1602          list_setkeyfunc(NULL, &opts, &zones, LT_ZONES);
1575 1603          list_setkeyfunc(NULL, &opts, &lgroups, LT_LGRPS);
1576 1604          if (opts.o_outpmode & OPT_TERMCAP)
1577 1605                  curses_on();
1578      -        if ((procdir = opendir("/proc")) == NULL)
     1606 +        (void) proc_snprintf(procpath, sizeof (procpath), "/proc");
     1607 +        if ((procdir = opendir(procpath)) == NULL)
1579 1608                  Die(gettext("cannot open /proc directory\n"));
1580 1609          if (opts.o_outpmode & OPT_TTY) {
1581 1610                  (void) printf(gettext("Please wait...\r"));
1582 1611                  if (!(opts.o_outpmode & OPT_TERMCAP))
1583 1612                          (void) putchar('\n');
1584 1613                  (void) fflush(stdout);
1585 1614          }
1586 1615          set_signals();
1587 1616          pollset.fd = STDIN_FILENO;
1588 1617          pollset.events = POLLIN;
↓ open down ↓ 96 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX