dtrace_modevent.c revision 1.5
1/*	$NetBSD: dtrace_modevent.c,v 1.5 2015/11/28 22:41:36 pgoyette Exp $	*/
2
3/*
4 * CDDL HEADER START
5 *
6 * The contents of this file are subject to the terms of the
7 * Common Development and Distribution License (the "License").
8 * You may not use this file except in compliance with the License.
9 *
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
14 *
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
20 *
21 * CDDL HEADER END
22 *
23 * $FreeBSD: src/sys/cddl/dev/dtrace/dtrace_modevent.c,v 1.1.4.1 2009/08/03 08:13:06 kensmith Exp $
24 *
25 */
26
27/* ARGSUSED */
28static int
29dtrace_modcmd(modcmd_t cmd, void *data)
30{
31	int bmajor = -1, cmajor = -1;
32	int error;
33
34	switch (cmd) {
35	case MODULE_CMD_INIT:
36		dtrace_load(NULL);
37		error = devsw_attach("dtrace", NULL, &bmajor,
38		    &dtrace_cdevsw, &cmajor);
39		if (error != 0)
40			if (dtrace_unload() != 0)
41				panic("failed to unload dtrace");
42		return error;
43
44	case MODULE_CMD_FINI:
45		error = devsw_detach(NULL, &dtrace_cdevsw);
46		if (error != 0)
47			return error;
48
49		error = dtrace_unload();
50		if (error != 0) {
51			if (devsw_attach("dtrace", NULL, &bmajor,
52					 &dtrace_cdevsw, &cmajor) != 0)
53				panic("failed to reattach dtrace_devsw");
54		}
55		return error;
56
57	case MODULE_CMD_AUTOUNLOAD:
58		return EBUSY;
59	default:
60		return ENOTTY;
61	}
62}
63