diff options
author | Adam H. Leventhal <ahl@delphix.com> | 2012-07-25 19:05:31 -0400 |
---|---|---|
committer | Adam H. Leventhal <ahl@delphix.com> | 2012-07-25 19:05:31 -0400 |
commit | e5803b76927480e8f9b67b22201c484ccf4c2bcf (patch) | |
tree | b745b1558831f07bf4527082dad827ff9366393b /usr/src/lib/libdtrace/common/dt_proc.c | |
parent | ff50e8e5ae1af23788a33c5296dd2009f3b8baf7 (diff) | |
download | illumos-gate-e5803b76927480e8f9b67b22201c484ccf4c2bcf.tar.gz |
3021 option for time-ordered output from dtrace(1M)
3022 DTrace: keys should not affect the sort order when sorting by value
3023 it should be possible to dereference dynamic variables
3024 D integer narrowing needs some work
3025 register leak in D code generation
3026 libdtrace should set LD_NOLAZYLOAD=1 to help the pid provider
Reviewed by: Bryan Cantrill <bmc@joyent.com>
Reviewed by: Eric Schrock <eschrock@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Approved by: Garrett D'Amore <garrett@damore.org>
Diffstat (limited to 'usr/src/lib/libdtrace/common/dt_proc.c')
-rw-r--r-- | usr/src/lib/libdtrace/common/dt_proc.c | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/usr/src/lib/libdtrace/common/dt_proc.c b/usr/src/lib/libdtrace/common/dt_proc.c index 96e85f1bdb..03fe05f21f 100644 --- a/usr/src/lib/libdtrace/common/dt_proc.c +++ b/usr/src/lib/libdtrace/common/dt_proc.c @@ -25,6 +25,10 @@ */ /* + * Copyright (c) 2012 by Delphix. All rights reserved. + */ + +/* * DTrace Process Control * * This file provides a set of routines that permit libdtrace and its clients @@ -460,7 +464,7 @@ dt_proc_control(void *arg) dt_proc_control_data_t *datap = arg; dtrace_hdl_t *dtp = datap->dpcd_hdl; dt_proc_t *dpr = datap->dpcd_proc; - dt_proc_hash_t *dph = dpr->dpr_hdl->dt_procs; + dt_proc_hash_t *dph = dtp->dt_procs; struct ps_prochandle *P = dpr->dpr_proc; int pfd = Pctlfd(P); @@ -870,7 +874,8 @@ dt_proc_create(dtrace_hdl_t *dtp, const char *file, char *const *argv) (void) pthread_mutex_init(&dpr->dpr_lock, NULL); (void) pthread_cond_init(&dpr->dpr_cv, NULL); - if ((dpr->dpr_proc = Pcreate(file, argv, &err, NULL, 0)) == NULL) { + dpr->dpr_proc = Pxcreate(file, argv, dtp->dt_proc_env, &err, NULL, 0); + if (dpr->dpr_proc == NULL) { return (dt_proc_error(dtp, dpr, "failed to execute %s: %s\n", file, Pcreate_error(err))); } @@ -1034,30 +1039,75 @@ dt_proc_unlock(dtrace_hdl_t *dtp, struct ps_prochandle *P) } void -dt_proc_hash_create(dtrace_hdl_t *dtp) +dt_proc_init(dtrace_hdl_t *dtp) { + extern char **environ; + static char *envdef[] = { + "LD_NOLAZYLOAD=1", /* linker lazy loading hides funcs */ + NULL + }; + char **p; + int i; + if ((dtp->dt_procs = dt_zalloc(dtp, sizeof (dt_proc_hash_t) + - sizeof (dt_proc_t *) * _dtrace_pidbuckets - 1)) != NULL) { + sizeof (dt_proc_t *) * _dtrace_pidbuckets - 1)) == NULL) + return; + + (void) pthread_mutex_init(&dtp->dt_procs->dph_lock, NULL); + (void) pthread_cond_init(&dtp->dt_procs->dph_cv, NULL); + + dtp->dt_procs->dph_hashlen = _dtrace_pidbuckets; + dtp->dt_procs->dph_lrulim = _dtrace_pidlrulim; - (void) pthread_mutex_init(&dtp->dt_procs->dph_lock, NULL); - (void) pthread_cond_init(&dtp->dt_procs->dph_cv, NULL); - dtp->dt_procs->dph_hashlen = _dtrace_pidbuckets; - dtp->dt_procs->dph_lrulim = _dtrace_pidlrulim; + /* + * Count how big our environment needs to be. + */ + for (i = 1, p = environ; *p != NULL; i++, p++) + continue; + for (p = envdef; *p != NULL; i++, p++) + continue; + + if ((dtp->dt_proc_env = dt_zalloc(dtp, sizeof (char *) * i)) == NULL) + return; + + for (i = 0, p = environ; *p != NULL; i++, p++) { + if ((dtp->dt_proc_env[i] = strdup(*p)) == NULL) + goto err; } + for (p = envdef; *p != NULL; i++, p++) { + if ((dtp->dt_proc_env[i] = strdup(*p)) == NULL) + goto err; + } + + return; + +err: + while (--i != 0) { + dt_free(dtp, dtp->dt_proc_env[i]); + } + dt_free(dtp, dtp->dt_proc_env); + dtp->dt_proc_env = NULL; } void -dt_proc_hash_destroy(dtrace_hdl_t *dtp) +dt_proc_fini(dtrace_hdl_t *dtp) { dt_proc_hash_t *dph = dtp->dt_procs; dt_proc_t *dpr; + char **p; while ((dpr = dt_list_next(&dph->dph_lrulist)) != NULL) dt_proc_destroy(dtp, dpr->dpr_proc); dtp->dt_procs = NULL; dt_free(dtp, dph); + + for (p = dtp->dt_proc_env; *p != NULL; p++) + dt_free(dtp, *p); + + dt_free(dtp, dtp->dt_proc_env); + dtp->dt_proc_env = NULL; } struct ps_prochandle * |