xref: /freebsd/sys/cddl/dev/dtrace/dtrace_sysctl.c (revision 9a14aa017b21c292740c00ee098195cd46642730)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * $FreeBSD$
22  *
23  */
24 
25 int	dtrace_debug = 0;
26 TUNABLE_INT("debug.dtrace.debug", &dtrace_debug);
27 SYSCTL_INT(_debug_dtrace, OID_AUTO, debug, CTLFLAG_RW, &dtrace_debug, 0, "");
28 
29 /* Report registered DTrace providers. */
30 static int
31 sysctl_dtrace_providers(SYSCTL_HANDLER_ARGS)
32 {
33 	char	*p_name	= NULL;
34 	dtrace_provider_t
35 		*prov	= dtrace_provider;
36 	int	error	= 0;
37 	size_t	len	= 0;
38 
39 	mutex_enter(&dtrace_provider_lock);
40 	mutex_enter(&dtrace_lock);
41 
42 	/* Compute the length of the space-separated provider name string. */
43 	while (prov != NULL) {
44 		len += strlen(prov->dtpv_name) + 1;
45 		prov = prov->dtpv_next;
46 	}
47 
48 	if ((p_name = kmem_alloc(len, KM_SLEEP)) == NULL)
49 		error = ENOMEM;
50 	else {
51 		/* Start with an empty string. */
52 		*p_name = '\0';
53 
54 		/* Point to the first provider again. */
55 		prov = dtrace_provider;
56 
57 		/* Loop through the providers, appending the names. */
58 		while (prov != NULL) {
59 			if (prov != dtrace_provider)
60 				(void) strlcat(p_name, " ", len);
61 
62 			(void) strlcat(p_name, prov->dtpv_name, len);
63 
64 			prov = prov->dtpv_next;
65 		}
66 	}
67 
68 	mutex_exit(&dtrace_lock);
69 	mutex_exit(&dtrace_provider_lock);
70 
71 	if (p_name != NULL) {
72 		error = sysctl_handle_string(oidp, p_name, len, req);
73 
74 		kmem_free(p_name, 0);
75 	}
76 
77 	return (error);
78 }
79 
80 SYSCTL_PROC(_debug_dtrace, OID_AUTO, providers, CTLTYPE_STRING | CTLFLAG_RD,
81     0, 0, sysctl_dtrace_providers, "A", "");
82 
83