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/ptools/ptree/ptree.c
          +++ new/usr/src/cmd/ptools/ptree/ptree.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + * Copyright (c) 2014, Joyent, Inc.  All rights reserved.
  24   25   */
  25   26  
  26   27  /*
  27   28   * ptree -- print family tree of processes
  28   29   */
  29   30  
  30      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  31      -
  32   31  #include <assert.h>
  33   32  #include <stdio.h>
  34   33  #include <string.h>
  35   34  #include <errno.h>
  36   35  #include <fcntl.h>
  37   36  #include <sys/types.h>
  38   37  #include <sys/termios.h>
  39   38  #include <unistd.h>
  40   39  #include <stdlib.h>
  41   40  #include <dirent.h>
  42   41  #include <pwd.h>
  43   42  #include <libproc.h>
  44   43  #include <libzonecfg.h>
  45   44  #include <limits.h>
  46   45  #include <libcontract.h>
  47   46  #include <sys/contract.h>
  48   47  #include <sys/ctfs.h>
  49   48  #include <libcontract_priv.h>
  50   49  #include <sys/stat.h>
       50 +#include "ptools_common.h"
  51   51  
  52   52  #define FAKEDPID0(p)    (p->pid == 0 && p->psargs[0] == '\0')
  53   53  
  54   54  typedef struct ps {
  55   55          int     done;
  56   56          uid_t   uid;
  57   57          uid_t   gid;
  58   58          pid_t   pid;            /* pid == -1 indicates this is a contract */
  59   59          pid_t   ppid;
  60   60          pid_t   pgrp;
↓ open down ↓ 35 lines elided ↑ open up ↑
  96   96  int
  97   97  main(int argc, char **argv)
  98   98  {
  99   99          psinfo_t info;  /* process information structure from /proc */
 100  100          int opt;
 101  101          int errflg = 0;
 102  102          struct winsize winsize;
 103  103          char *s;
 104  104          int n;
 105  105          int retc = 0;
      106 +        char ppath[PATH_MAX];
 106  107  
 107  108          DIR *dirp;
 108  109          struct dirent *dentp;
 109      -        char    pname[100];
      110 +        char    pname[PATH_MAX];
 110  111          int     pdlen;
 111  112  
 112  113          ps_t *p;
 113  114  
 114  115          if ((command = strrchr(argv[0], '/')) == NULL)
 115  116                  command = argv[0];
 116  117          else
 117  118                  command++;
 118  119  
 119  120          /* options */
↓ open down ↓ 42 lines elided ↑ open up ↑
 162  163                  columns = n;
 163  164          else if (isatty(fileno(stdout)) &&
 164  165              ioctl(fileno(stdout), TIOCGWINSZ, &winsize) == 0 &&
 165  166              winsize.ws_col != 0)
 166  167                  columns = winsize.ws_col;
 167  168  
 168  169          nps = 0;
 169  170          psize = 0;
 170  171          ps = NULL;
 171  172  
      173 +        (void) proc_snprintf(ppath, sizeof (ppath), "/proc");
      174 +
 172  175          /*
 173  176           * Search the /proc directory for all processes.
 174  177           */
 175      -        if ((dirp = opendir("/proc")) == NULL) {
 176      -                (void) fprintf(stderr, "%s: cannot open /proc directory\n",
 177      -                    command);
      178 +        if ((dirp = opendir(ppath)) == NULL) {
      179 +                (void) fprintf(stderr, "%s: cannot open %s directory\n",
      180 +                    command, ppath);
 178  181                  return (1);
 179  182          }
 180  183  
 181      -        (void) strcpy(pname, "/proc");
      184 +        (void) strcpy(pname, ppath);
 182  185          pdlen = strlen(pname);
 183  186          pname[pdlen++] = '/';
 184  187  
 185  188          /* for each active process --- */
 186  189          while (dentp = readdir(dirp)) {
 187  190                  int     procfd; /* filedescriptor for /proc/nnnnn/psinfo */
 188  191  
 189  192                  if (dentp->d_name[0] == '.')            /* skip . and .. */
 190  193                          continue;
 191  194                  (void) strcpy(pname + pdlen, dentp->d_name);
↓ open down ↓ 377 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX