dtrace_modevent.c revision 1.7
1/* $NetBSD: dtrace_modevent.c,v 1.7 2022/03/28 12:33:20 riastradh 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: head/sys/cddl/dev/dtrace/dtrace_load.c 309069 2016-11-23 22:50:20Z gnn $ 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 devsw_detach(NULL, &dtrace_cdevsw); 46 47 error = dtrace_unload(); 48 if (error != 0) { 49 if (devsw_attach("dtrace", NULL, &bmajor, 50 &dtrace_cdevsw, &cmajor) != 0) 51 panic("failed to reattach dtrace_devsw"); 52 } 53 return error; 54 55 case MODULE_CMD_AUTOUNLOAD: 56 return EBUSY; 57 default: 58 return ENOTTY; 59 } 60} 61