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>

@@ -25,11 +25,11 @@
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 /*
- * Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ * Copyright 2015 Joyent, Inc.
  */
 
 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
 /*        All Rights Reserved   */
 

@@ -284,11 +284,11 @@
 static  int     nzoneid = 0;
 
 static  int     kbytes_per_page;
 static  int     pidwidth;
 
-static  char    *procdir = "/proc";     /* standard /proc directory */
+static  char    procdir[MAXPATHLEN];    /* standard /proc directory */
 
 static struct ughead    euid_tbl;       /* table to store selected euid's */
 static struct ughead    ruid_tbl;       /* table to store selected real uid's */
 static struct ughead    egid_tbl;       /* table to store selected egid's */
 static struct ughead    rgid_tbl;       /* table to store selected real gid's */

@@ -337,12 +337,20 @@
 
 int
 main(int argc, char **argv)
 {
         const char *me;
+        const char *zroot = zone_get_nroot();
 
         /*
+         * If this is a branded zone, the native procfs may mounted in a
+         * non-standard location.  Apply such a path prefix if it exists.
+         */
+        (void) snprintf(procdir, sizeof (procdir), "%s/proc", zroot != NULL ?
+            zroot : "");
+
+        /*
          * The original two ps'es are linked in a single binary;
          * their main()s are renamed to stdmain for /usr/bin/ps and
          * ucbmain for /usr/ucb/ps.
          * We try to figure out which instance of ps the user wants to run.
          * Traditionally, the UCB variant doesn't require the flag argument