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>

@@ -38,10 +38,11 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <assert.h>
+#include <zone.h>
 
 #define _POSIX_PTHREAD_SEMANTICS
 #include <dirent.h>
 #undef  _POSIX_PTHREAD_SEMANTICS
 

@@ -683,12 +684,12 @@
 { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
 { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
 { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
 };
 
-const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */
-const char *_dtrace_defld = "/usr/ccs/bin/ld";   /* default ld(1) to invoke */
+const char *_dtrace_defcpp = "/usr/lib/cpp"; /* default cpp(1) to invoke */
+const char *_dtrace_defld = "/usr/bin/ld";   /* default ld(1) to invoke */
 
 const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */
 const char *_dtrace_provdir = "/dev/dtrace/provider"; /* provider directory */
 
 int _dtrace_strbuckets = 211;   /* default number of hash buckets (prime) */

@@ -824,10 +825,12 @@
         dtrace_prog_t *pgp;
         dt_module_t *dmp;
         dt_provmod_t *provmod = NULL;
         int i, err;
         struct rlimit rl;
+        const char *zroot;
+        char *libpath = NULL;
 
         const dt_intrinsic_t *dinp;
         const dt_typedef_t *dtyp;
         const dt_ident_t *idp;
 

@@ -956,15 +959,23 @@
         dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *));
         dtp->dt_provbuckets = _dtrace_strbuckets;
         dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *));
         dt_proc_init(dtp);
         dtp->dt_vmax = DT_VERS_LATEST;
+        zroot = zone_get_nroot();
+        if (zroot != NULL) {
+                (void) asprintf(&dtp->dt_ld_path, "%s/%s", zroot,
+                    _dtrace_defld);
+                (void) asprintf(&dtp->dt_cpp_path, "%s/%s", zroot,
+                    _dtrace_defcpp);
+        } else {
+                dtp->dt_ld_path = strdup(_dtrace_defld);
         dtp->dt_cpp_path = strdup(_dtrace_defcpp);
+        }
         dtp->dt_cpp_argv = malloc(sizeof (char *));
         dtp->dt_cpp_argc = 1;
         dtp->dt_cpp_args = 1;
-        dtp->dt_ld_path = strdup(_dtrace_defld);
         dtp->dt_provmod = provmod;
         dtp->dt_vector = vector;
         dtp->dt_varg = arg;
         dt_dof_init(dtp);
         (void) uname(&dtp->dt_uts);

@@ -1305,13 +1316,19 @@
          * dt_compile() will compile all the libraries.  We intentionally defer
          * library processing to improve overhead for clients that don't ever
          * compile, and to provide better error reporting (because the full
          * reporting of compiler errors requires dtrace_open() to succeed).
          */
-        if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0)
+        if (zroot != NULL)
+                (void) asprintf(&libpath, "%s/%s", zroot, _dtrace_libdir);
+        if (dtrace_setopt(dtp, "libdir",
+            libpath != NULL ? libpath : _dtrace_libdir) != 0)
                 return (set_open_errno(dtp, errp, dtp->dt_errno));
 
+        if (libpath != NULL)
+                free(libpath);
+
         return (dtp);
 }
 
 dtrace_hdl_t *
 dtrace_open(int version, int flags, int *errp)