Index: sys/kern/kern_module.c =================================================================== --- sys/kern/kern_module.c +++ sys/kern/kern_module.c @@ -66,7 +66,7 @@ static void module_shutdown(void *, int); static int -modevent_nop(module_t mod, int what, void *arg) +modevent_no_unload(module_t mod, int what, void *arg) { switch(what) { @@ -79,6 +79,26 @@ } } +int +modevent_nop(module_t mod __unused, int type, void *unused __unused) +{ + int error; + + switch (type) { + case MOD_LOAD: + case MOD_QUIESCE: + case MOD_UNLOAD: + case MOD_SHUTDOWN: + error = 0; + break; + default: + error = EOPNOTSUPP; + break; + } + + return (error); +} + static void module_init(void *arg) { @@ -168,7 +188,7 @@ newmod->id = nextid++; newmod->name = (char *)(newmod + 1); strcpy(newmod->name, data->name); - newmod->handler = data->evhand ? data->evhand : modevent_nop; + newmod->handler = data->evhand ? data->evhand : modevent_no_unload; newmod->arg = data->priv; bzero(&newmod->data, sizeof(newmod->data)); TAILQ_INSERT_TAIL(&modules, newmod, link); Index: sys/sys/module.h =================================================================== --- sys/sys/module.h +++ sys/sys/module.h @@ -52,6 +52,13 @@ typedef struct module *module_t; typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *); +/* + * A module can use this to ignore all valid module events. (In contrast, a + * NULL eventhandler prevents module unload with EBUSY, and returns EOPNOTSUPP + * for QUIESCE and SHUTDOWN.) + */ +int modevent_nop(module_t, int, void *); + /* * Struct for registering modules statically via SYSINIT. */