From owner-freebsd-bugs@FreeBSD.ORG Sat Dec 15 06:40:01 2012 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6F89D991 for ; Sat, 15 Dec 2012 06:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 52C378FC0C for ; Sat, 15 Dec 2012 06:40:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id qBF6e0kS072843 for ; Sat, 15 Dec 2012 06:40:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id qBF6e0f8072842; Sat, 15 Dec 2012 06:40:00 GMT (envelope-from gnats) Date: Sat, 15 Dec 2012 06:40:00 GMT Message-Id: <201212150640.qBF6e0f8072842@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Mark Johnston Subject: Re: bin/171678: [dtrace] dtrace -h doesn't work when io.d is installed X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Mark Johnston List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Dec 2012 06:40:01 -0000 The following reply was made to PR bin/171678; it has been noted by GNATS. From: Mark Johnston To: bug-followup@FreeBSD.org Cc: Subject: Re: bin/171678: [dtrace] dtrace -h doesn't work when io.d is installed Date: Sat, 15 Dec 2012 01:34:08 -0500 --jTMWTj4UTAEmbWeb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I've attached a patch with an actual fix. Specific, this changes libdtrace to first look for providers from the debug.dtrace.providers sysctl. This doesn't require the user to be root, so dtrace -h works as expected. Here's an easy test case (for CURRENT) to reproduce the original problem: $ cat probe.d provider test { probe testprobe(); }; $ dtrace -h -s probe.d dtrace: failed to compile script probe.d: "/usr/lib/dtrace/regs_x86.d", line 2: type redeclared: struct devinfo $ As I mentioned, this is caused by the depends_on pragma in io.d. The same problem comes up if a "depends_on provider" pragma is added to probe.d. Thanks, -Mark --jTMWTj4UTAEmbWeb Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="dtrace_depends_on_sysctl.patch" diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c index 00578f4..8d64d8d 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c @@ -241,6 +241,8 @@ dt_pragma_depends(const char *prname, dt_node_t *cnp) int found; dt_lib_depend_t *dld; char lib[MAXPATHLEN]; + size_t plen; + char *provs, *cpy, *tok; if (cnp == NULL || nnp == NULL || cnp->dn_kind != DT_NODE_IDENT || nnp->dn_kind != DT_NODE_IDENT) { @@ -248,9 +250,28 @@ dt_pragma_depends(const char *prname, dt_node_t *cnp) " \n", prname); } - if (strcmp(cnp->dn_string, "provider") == 0) - found = dt_provider_lookup(dtp, nnp->dn_string) != NULL; - else if (strcmp(cnp->dn_string, "module") == 0) { + if (strcmp(cnp->dn_string, "provider") == 0) { + /* + * First try to get the provider list using the + * debug.dtrace.providers sysctl, since that'll work even if + * we're not running as root. + */ + provs = NULL; + if (sysctlbyname("debug.dtrace.providers", NULL, &plen, NULL, 0) || + ((provs = dt_alloc(dtp, plen)) == NULL) || + sysctlbyname("debug.dtrace.providers", provs, &plen, NULL, 0)) + found = dt_provider_lookup(dtp, nnp->dn_string) != NULL; + else { + found = B_FALSE; + for (cpy = provs; (tok = strsep(&cpy, " ")) != NULL; ) + if (strcmp(tok, nnp->dn_string) == 0) { + found = B_TRUE; + break; + } + } + if (provs != NULL) + dt_free(dtp, provs); + } else if (strcmp(cnp->dn_string, "module") == 0) { dt_module_t *mp = dt_module_lookup_by_name(dtp, nnp->dn_string); found = mp != NULL && dt_module_getctf(dtp, mp) != NULL; } else if (strcmp(cnp->dn_string, "library") == 0) { --jTMWTj4UTAEmbWeb--