From nobody@FreeBSD.org  Sun Sep 16 05:56:16 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 041B8106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 16 Sep 2012 05:56:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id E32098FC29
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 16 Sep 2012 05:56:15 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q8G5uFPd019079
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 16 Sep 2012 05:56:15 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q8G5uFwJ019076;
	Sun, 16 Sep 2012 05:56:15 GMT
	(envelope-from nobody)
Message-Id: <201209160556.q8G5uFwJ019076@red.freebsd.org>
Date: Sun, 16 Sep 2012 05:56:15 GMT
From: Mark Johnston <markjdb@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [dtrace] dtrace -h doesn't work when io.d is installed
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         171678
>Category:       bin
>Synopsis:       [dtrace] dtrace -h doesn't work when io.d is installed
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnn
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 16 06:00:27 UTC 2012
>Closed-Date:    Sun Dec 29 17:13:05 UTC 2013
>Last-Modified:  Sun Dec 29 17:13:05 UTC 2013
>Originator:     Mark Johnston
>Release:        CURRENT
>Organization:
>Environment:
FreeBSD oddish.laptop 10.0-CURRENT FreeBSD 10.0-CURRENT #13 r240519+3cc2dea-dirty: Sat Sep 15 22:29:45 EDT 2012     mark@oddish.laptop:/usr/obj/usr/home/mark/src/freebsd/sys/GENERIC  amd64
>Description:
When running dtrace -h, I get the following unintuitive error message:

$ dtrace -h -s perldtrace.d
dtrace: failed to compile script perldtrace.d: "/usr/lib/dtrace/regs_x86.d", line 2: type redeclared: struct devinfo

This error doesn't occur if I run it without -h, which doesn't make much sense since the scripts in /usr/lib/dtrace/ are processed regardless.
>How-To-Repeat:

>Fix:
The root of the problem is the "#pragma D depends_on provider" in /usr/lib/dtrace/io.d. When dtrace sees that directive, it calls a DTRACEIOC_PROVIDER ioctl on /dev/dtrace/dtrace with the appropriate provider argument ("io" in this case) to verify that that provider really is available.

Turns out that the -h (and -G) option sets the DTRACE_O_NODEV flag, which basically means "don't open /dev/dtrace/dtrace or /dev/dtrace/fasttrap." This allows dtrace -h to be used without needing root privileges. But obviously we need to open /dev/dtrace/dtrace for the reason mentioned above, and dtrace aborts because it can't call the ioctl.

For now, I'm working around this by just removing /usr/lib/dtrace/io.d - I don't need it at the moment. I'm not sure what the right fix is. Probably the error message could also be improved in this case, but I haven't really looked into that.

>Release-Note:
>Audit-Trail:

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/171678: [dtrace] dtrace -h doesn&#39;t work when io.d is
 installed
Date: Sun, 16 Sep 2012 02:20:46 -0400

 I should also point out that simply removing the depends_on directive in
 io.d is a sufficient workaround. Just make sure dtio.ko is loaded I
 guess. :)
 
 -Mark

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/171678: [dtrace] dtrace -h doesn&#39;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)
  		    "<class> <name>\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--

From: Kenji Rikitake <kenji.rikitake@acm.org>
To: bug-followup@FreeBSD.org, markjdb@gmail.com
Cc: Kenji Rikitake <kenji.rikitake@acm.org>, olgeni@freebsd.org
Subject: Re: bin/171678: [dtrace] dtrace -h doesn&#39;t work when io.d is installed
Date: Sun, 13 Jan 2013 09:16:27 +0900

 This patch (dtrace_depends_on_sysctl.patch)
 was required when I built the Port lang/erlang
 (Erlang/OTP R15B03-1) with the dtrace option enabled.
 I suggest this patch should be merged
 into the STABLE branch ASAP.
 
 My test environment:
 FreeBSD minimax.priv.k2r.org 9.1-STABLE FreeBSD 9.1-STABLE #14
 r245019: Fri Jan  4 11:08:18 JST 2013
 root@minimax.priv.k2r.org:/usr/obj/usr/src/sys/MINIMAX  amd64
 
 And the Ports tree svn revision was r310207.
 
 Regards,
 Kenji Rikitake
State-Changed-From-To: open->analyzed 
State-Changed-By: markj 
State-Changed-When: Thu Jan 24 18:34:11 UTC 2013 
State-Changed-Why:  
I believe gnn@ is taking a look at this. 


Responsible-Changed-From-To: freebsd-bugs->gnn 
Responsible-Changed-By: markj 
Responsible-Changed-When: Thu Jan 24 18:34:11 UTC 2013 
Responsible-Changed-Why:  
I believe gnn@ is taking a look at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171678 

From: Mark Johnston <markj@freebsd.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/171678: [dtrace] dtrace -h doesn&#39;t work when io.d is
 installed
Date: Thu, 24 Jan 2013 11:35:59 -0800

 --2oS5YaxWCcQjTEyO
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Here's a slightly updated version of the last patch - this changes the
 new code so that dt_lookup_provider() is still called if we can't find
 the provider in the debug.dtrace.providers sysctl.
 
 Thanks,
 -Mark
 
 --2oS5YaxWCcQjTEyO
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=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..760c2f6 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,31 @@ dt_pragma_depends(const char *prname, dt_node_t *cnp)
  		    "<class> <name>\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 (found == B_FALSE)
 +				found = dt_provider_lookup(dtp,
 +				    nnp->dn_string) != NULL;
 +		}
 +		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) {
 
 --2oS5YaxWCcQjTEyO--
State-Changed-From-To: analyzed->patched 
State-Changed-By: gnn 
State-Changed-When: Thu Mar 28 20:15:27 UTC 2013 
State-Changed-Why:  
I have committed what I think is a fix to HEAD, in the form of an 
updated io.d.  Please test aand let me know. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171678 
State-Changed-From-To: patched->analyzed 
State-Changed-By: gnn 
State-Changed-When: Thu Mar 28 20:23:18 UTC 2013 
State-Changed-Why:  
Need to apply a different patch moving back to analyzed for the moment. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171678 
State-Changed-From-To: analyzed->patched 
State-Changed-By: gnn 
State-Changed-When: Thu Mar 28 20:26:55 UTC 2013 
State-Changed-Why:  
Apply the latest patch to address this from the reporter. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171678 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/171678: commit references a PR
Date: Thu, 28 Mar 2013 20:31:16 +0000 (UTC)

 Author: gnn
 Date: Thu Mar 28 20:31:03 2013
 New Revision: 248848
 URL: http://svnweb.freebsd.org/changeset/base/248848
 
 Log:
   Commit a patch that fixes a problem in the #pragma statement when searching
   for and loading dependent modules.  This addresses a bug seen with
   io.d where it was being doubly included.
   
   PR:		171678
   Submitted by:	 Mark Johnston
   MFC after:	2 weeks
 
 Modified:
   head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c
 
 Modified: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c
 ==============================================================================
 --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c	Thu Mar 28 20:27:01 2013	(r248847)
 +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c	Thu Mar 28 20:31:03 2013	(r248848)
 @@ -241,6 +241,8 @@ dt_pragma_depends(const char *prname, dt
  	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,31 @@ dt_pragma_depends(const char *prname, dt
  		    "<class> <name>\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 (found == B_FALSE)
 +				found = dt_provider_lookup(dtp,
 +				    nnp->dn_string) != NULL;
 +		}
 +		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) {
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/171678: commit references a PR
Date: Mon, 17 Jun 2013 15:42:39 +0000 (UTC)

 Author: gnn
 Date: Mon Jun 17 15:42:21 2013
 New Revision: 251857
 URL: http://svnweb.freebsd.org/changeset/base/251857
 
 Log:
   MFC: 248848
   
   Commit a patch that fixes a problem in the #pragma statement when searching
   for and loading dependent modules.  This addresses a bug seen with
   io.d where it was being doubly included.
   
   PR:		171678
   Submitted by:	 Mark Johnston
 
 Modified:
   stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c
 Directory Properties:
   stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/   (props changed)
 
 Modified: stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c
 ==============================================================================
 --- stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c	Mon Jun 17 15:34:22 2013	(r251856)
 +++ stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c	Mon Jun 17 15:42:21 2013	(r251857)
 @@ -241,6 +241,8 @@ dt_pragma_depends(const char *prname, dt
  	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,31 @@ dt_pragma_depends(const char *prname, dt
  		    "<class> <name>\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 (found == B_FALSE)
 +				found = dt_provider_lookup(dtp,
 +				    nnp->dn_string) != NULL;
 +		}
 +		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) {
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: markj 
State-Changed-When: Sun Dec 29 17:13:04 UTC 2013 
State-Changed-Why:  
The fix for this PR has been committed and MFCed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171678 
>Unformatted:
