Print this page
OS-4408 /native/usr/bin/ps should work in a lx branded zone
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ps/ps.c
          +++ new/usr/src/cmd/ps/ps.c
↓ open down ↓ 19 lines elided ↑ open up ↑
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2013 Gary Mills
  24   24   *
  25   25   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  26   26   * Use is subject to license terms.
  27   27   */
  28   28  
  29   29  /*
  30      - * Copyright (c) 2012, Joyent, Inc. All rights reserved.
       30 + * Copyright 2015 Joyent, Inc.
  31   31   */
  32   32  
  33   33  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  34   34  /*        All Rights Reserved   */
  35   35  
  36   36  /*
  37   37   * ps -- print things about processes.
  38   38   */
  39   39  #include <stdio.h>
  40   40  #include <ctype.h>
↓ open down ↓ 238 lines elided ↑ open up ↑
 279  279  static  size_t  sessidsz = 0;
 280  280  static  int     nsessid = 0;
 281  281  
 282  282  static  zoneid_t *zoneid = NULL; /* for z option */
 283  283  static  size_t  zoneidsz = 0;
 284  284  static  int     nzoneid = 0;
 285  285  
 286  286  static  int     kbytes_per_page;
 287  287  static  int     pidwidth;
 288  288  
 289      -static  char    *procdir = "/proc";     /* standard /proc directory */
      289 +static  char    procdir[MAXPATHLEN];    /* standard /proc directory */
 290  290  
 291  291  static struct ughead    euid_tbl;       /* table to store selected euid's */
 292  292  static struct ughead    ruid_tbl;       /* table to store selected real uid's */
 293  293  static struct ughead    egid_tbl;       /* table to store selected egid's */
 294  294  static struct ughead    rgid_tbl;       /* table to store selected real gid's */
 295  295  static prheader_t *lpsinfobuf;          /* buffer to contain lpsinfo */
 296  296  static size_t   lpbufsize;
 297  297  
 298  298  /*
 299  299   * This constant defines the sentinal number of process IDs below which we
↓ open down ↓ 32 lines elided ↑ open up ↑
 332  332  static  void    *Realloc(void *, size_t);
 333  333  static  int     pidcmp(const void *p1, const void *p2);
 334  334  
 335  335  extern  int     ucbmain(int, char **);
 336  336  static  int     stdmain(int, char **);
 337  337  
 338  338  int
 339  339  main(int argc, char **argv)
 340  340  {
 341  341          const char *me;
      342 +        const char *zroot = zone_get_nroot();
 342  343  
 343  344          /*
      345 +         * If this is a branded zone, the native procfs may mounted in a
      346 +         * non-standard location.  Apply such a path prefix if it exists.
      347 +         */
      348 +        (void) snprintf(procdir, sizeof (procdir), "%s/proc", zroot != NULL ?
      349 +            zroot : "");
      350 +
      351 +        /*
 344  352           * The original two ps'es are linked in a single binary;
 345  353           * their main()s are renamed to stdmain for /usr/bin/ps and
 346  354           * ucbmain for /usr/ucb/ps.
 347  355           * We try to figure out which instance of ps the user wants to run.
 348  356           * Traditionally, the UCB variant doesn't require the flag argument
 349  357           * start with a "-".  If the first argument doesn't start with a
 350  358           * "-", we call "ucbmain".
 351  359           * If there's a first argument and it starts with a "-", we check
 352  360           * whether any of the options isn't acceptable to "ucbmain"; in that
 353  361           * case we run "stdmain".
↓ open down ↓ 1716 lines elided ↑ open up ↑
2070 2078                  break;
2071 2079  
2072 2080          default:
2073 2081                  print_field(psinfo, f, ttyp);
2074 2082                  break;
2075 2083          }
2076 2084  }
2077 2085  
2078 2086  static void
2079 2087  pr_fields(psinfo_t *psinfo, const char *ttyp,
2080      -        void (*print_fld)(psinfo_t *, struct field *, const char *))
     2088 +    void (*print_fld)(psinfo_t *, struct field *, const char *))
2081 2089  {
2082 2090          struct field *f;
2083 2091  
2084 2092          for (f = fields; f != NULL; f = f->next) {
2085 2093                  print_fld(psinfo, f, ttyp);
2086 2094                  if (f->next != NULL)
2087 2095                          (void) printf(" ");
2088 2096          }
2089 2097          (void) printf("\n");
2090 2098  }
↓ open down ↓ 438 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX