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>
        
*** 179,188 ****
--- 179,215 ----
          -1,                     /* number of iterations; infinitely */
          OPT_PSINFO | OPT_FULLSCREEN | OPT_USEHOME | OPT_TERMCAP,
          -1                      /* sort in decreasing order */
  };
  
+ 
+ static int
+ proc_snprintf(char *_RESTRICT_KYWD s, size_t n,
+     const char *_RESTRICT_KYWD fmt, ...)
+ {
+         static boolean_t ptools_zroot_valid = B_FALSE;
+         static const char *ptools_zroot = NULL;
+         va_list args;
+         int ret, nret = 0;
+ 
+         if (ptools_zroot_valid == B_FALSE) {
+                 ptools_zroot_valid = B_TRUE;
+                 ptools_zroot = zone_get_nroot();
+         }
+ 
+         if (ptools_zroot != NULL) {
+                 nret = snprintf(s, n, "%s", ptools_zroot);
+                 if (nret > n)
+                         return (nret);
+         }
+         va_start(args, fmt);
+         ret = vsnprintf(s + nret, n - nret, fmt, args);
+         va_end(args);
+ 
+         return (ret + nret);
+ }
+ 
  /*
   * Print timestamp as decimal reprentation of time_t value (-d u was specified)
   * or the standard date format (-d d was specified).
   */
  static void
*** 846,858 ****
  }
  
  static int
  read_procfile(fd_t **fd, char *pidstr, char *file, void *buf, size_t bufsize)
  {
!         char procfile[MAX_PROCFS_PATH];
  
!         (void) snprintf(procfile, MAX_PROCFS_PATH,
              "/proc/%s/%s", pidstr, file);
          if ((*fd = fd_open(procfile, O_RDONLY, *fd)) == NULL)
                  return (1);
          if (pread(fd_getfd(*fd), buf, bufsize, 0) != bufsize) {
                  fd_close(*fd);
--- 873,885 ----
  }
  
  static int
  read_procfile(fd_t **fd, char *pidstr, char *file, void *buf, size_t bufsize)
  {
!         char procfile[PATH_MAX];
  
!         (void) proc_snprintf(procfile, PATH_MAX,
              "/proc/%s/%s", pidstr, file);
          if ((*fd = fd_open(procfile, O_RDONLY, *fd)) == NULL)
                  return (1);
          if (pread(fd_getfd(*fd), buf, bufsize, 0) != bufsize) {
                  fd_close(*fd);
*** 1374,1383 ****
--- 1401,1411 ----
          char *sortk = "cpu";    /* default sort key */
          int opt;
          int timeout;
          struct pollfd pollset;
          char key;
+         char procpath[PATH_MAX];
  
          (void) setlocale(LC_ALL, "");
          (void) textdomain(TEXT_DOMAIN);
          Progname(argv[0]);
          lwpid_init();
*** 1573,1583 ****
          list_setkeyfunc(NULL, &opts, &projects, LT_PROJECTS);
          list_setkeyfunc(NULL, &opts, &zones, LT_ZONES);
          list_setkeyfunc(NULL, &opts, &lgroups, LT_LGRPS);
          if (opts.o_outpmode & OPT_TERMCAP)
                  curses_on();
!         if ((procdir = opendir("/proc")) == NULL)
                  Die(gettext("cannot open /proc directory\n"));
          if (opts.o_outpmode & OPT_TTY) {
                  (void) printf(gettext("Please wait...\r"));
                  if (!(opts.o_outpmode & OPT_TERMCAP))
                          (void) putchar('\n');
--- 1601,1612 ----
          list_setkeyfunc(NULL, &opts, &projects, LT_PROJECTS);
          list_setkeyfunc(NULL, &opts, &zones, LT_ZONES);
          list_setkeyfunc(NULL, &opts, &lgroups, LT_LGRPS);
          if (opts.o_outpmode & OPT_TERMCAP)
                  curses_on();
!         (void) proc_snprintf(procpath, sizeof (procpath), "/proc");
!         if ((procdir = opendir(procpath)) == NULL)
                  Die(gettext("cannot open /proc directory\n"));
          if (opts.o_outpmode & OPT_TTY) {
                  (void) printf(gettext("Please wait...\r"));
                  if (!(opts.o_outpmode & OPT_TERMCAP))
                          (void) putchar('\n');