I am trying to figure out how to cleany handle error conditions with module loading/unloading, especially when trying to load a module which is already statically compiled in the kernel. I have browsed through the source a bit but haven't found a good example that I could understand.
Basically, i see a problem in the way module_register_init() is implemented. This function ends like this: void module_register_init(const void *arg) { ... error = MOD_EVENT(mod, MOD_LOAD); if (error) { MOD_EVENT(mod, MOD_UNLOAD); module_release(mod); } } and I have a problem understanding the reason of the call to MOD_UNLOAD in case of failure. To me the most obvious way to handle a LOAD failure was that the called function should take care to do the necessary cleanup, without deferring this task to a further call to MOD_UNLOAD. Furthermore, the latter is indistinguishable from a regular call to MOD_UNLOAD generated by kldunload unless the module that failed to register stores some state to record the failure itself. Finally, perhaps there ought to be some automatic way (such as in the DECLARE_MODULE macro) to make sure that when a module is statically compiled in, kldload fails with EEXIST without even attempting to call MOD_LOAD ? I can easily implement some conditional code in modevent, such as static int foo_modevent(module_t mod, int type, void *unused) { switch (type) { case MOD_LOAD: err = foo_init(); break ; case MOD_UNLOAD: #if !defined(KLD_MODULE) printf("cannot unload module foo, it is statically compiled\n"); err = EINVAL #else err = foo_unload(); #endif break; default: err = EINVAL ; break; } but it would be much more convenient if the check were done in some automatic way with some trick in DECLARE_MODULE. cheers luigi ----------------------------------+----------------------------------------- Luigi RIZZO, [EMAIL PROTECTED] . ACIRI/ICSI (on leave from Univ. di Pisa) http://www.iet.unipi.it/~luigi/ . 1947 Center St, Berkeley CA 94704 Phone: (510) 666 2927 ----------------------------------+----------------------------------------- To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message