static int __init mod_init(void) { major = register_chrdev(0, DEVICE_NAME, &fops); if(major < 0) { printk(KERN_ALERT "hellodev: register_chrdev failed\n"); mod_exit(); return major; } printk(KERN_INFO "hellodev: register_chrdev: %d\n", major); dev_class = class_create(THIS_MODULE, CLASS_NAME); if (IS_ERR(dev_class)) { printk(KERN_ALERT "hellodev: class_create failed\n"); mod_exit(); return PTR_ERR(dev_class); } printk(KERN_INFO "hellodev: class_create: OK\n"); dev_device = device_create(dev_class, NULL, MKDEV(major, 0), NULL, DEVICE_NAME); if (IS_ERR(dev_device)) { printk(KERN_ALERT "hellodev: device_create failed\n"); mod_exit(); return PTR_ERR(dev_device); } printk(KERN_INFO "hellodev: device_create: OK\n"); return 0; }
void destroy_output_modules(void) { int i, ret; void (*mod_exit)(void); for (i = 0; i < nr_outputs; i++) { mod_exit = dlsym(output_dlhandles[i], "netconsd_output_exit"); if (mod_exit) mod_exit(); ret = dlclose(output_dlhandles[i]); if (ret) warn("dlclose() failed: %s\n", dlerror()); } }
void vsf_module_unload(char *name) { struct vsf_module_t *module = vsf_module_get(name); vsf_err_t (*mod_exit)(struct vsf_module_t *); if ((module != NULL) && (module->code_buff != NULL)) { if (module->flash->exit) { mod_exit = (vsf_err_t (*)(struct vsf_module_t *)) (module->code_buff + module->flash->exit); mod_exit(module); } #ifdef VSFCFG_MODULE_ALLOC_RAM if (module->flash->size > 0) { vsf_bufmgr_free(module->code_buff); } #endif module->code_buff = NULL; } }
int main(int argc, char *argv[]) { opt_t opt; int retval = 0; const char *m; /* * Initialize. */ err_init(xbasename(argv[0])); /* init err package */ /* * If running setuid, fork a child to handle * all privileged operations and drop privs in this process. */ privsep_init(); /* * Seed options with default values: */ opt_default(&opt, argv[0]); /* * Override defaults with environment */ opt_env(&opt); /* * Process any options that need to be handled early: */ opt_args_early(&opt, argc, argv); /* * Load static or dynamic pdsh modules */ mod_init(); /* * Allow module directory to be overridden, but not when * running as root or setuid. (This is mainly for testing...) */ if (!(m = getenv ("PDSH_MODULE_DIR")) || getuid() == 0 || getuid() != geteuid()) m = pdsh_module_dir; if (mod_load_modules(m, &opt) < 0) errx("%p: Couldn't load any pdsh modules\n"); /* * Handle options. */ opt_args(&opt, argc, argv); /* override with command line */ if (opt_verify(&opt)) { /* verify options, print errors */ /* * Do the work. */ if (opt.info_only) /* display info only */ opt_list(&opt); else if (pdsh_personality() == PCP && opt.pcp_server) retval = (_pcp_remote_server (&opt) < 0); else if (pdsh_personality() == PCP && opt.pcp_client) retval = (_pcp_remote_client (&opt) < 0); else if (pdsh_personality() == PCP || opt.cmd != NULL) retval = dsh(&opt); /* single dsh/pcp command */ else /* prompt loop */ _interactive_dsh(&opt); } else { retval = 1; } mod_exit(); /* * Clean up. */ privsep_fini(); opt_free(&opt); /* free heap storage in opt struct */ err_cleanup(); return retval; }