apps/examples/module: Now exercises rmmod as well
This commit is contained in:
parent
d02295d1f2
commit
6c14e176d9
2
examples/module/drivers/chardev/.gitignore
vendored
2
examples/module/drivers/chardev/.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
hello
|
||||
/chardev
|
||||
|
||||
|
Binary file not shown.
@ -46,6 +46,7 @@
|
||||
#include <syslog.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/module.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
/****************************************************************************
|
||||
@ -124,6 +125,18 @@ static ssize_t chardev_write(FAR struct file *filep, FAR const char *buffer,
|
||||
return len;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: module_uninitialize
|
||||
****************************************************************************/
|
||||
|
||||
static int module_uninitialize(FAR void *arg)
|
||||
{
|
||||
/* TODO: Check if there are any open references to the driver */
|
||||
|
||||
syslog(LOG_INFO, "module_uninitialize: arg=%p\n", arg);
|
||||
return register_driver("/dev/chardev", &chardev_fops, 0666, NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -136,7 +149,14 @@ static ssize_t chardev_write(FAR struct file *filep, FAR const char *buffer,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void module_initialize(void)
|
||||
void module_initialize(mod_uninitializer_t *uninitializer, FAR void **arg)
|
||||
{
|
||||
(void)register_driver("/dev/chardev", &chardev_fops, 0666, NULL);
|
||||
int ret;
|
||||
|
||||
syslog(LOG_INFO, "module_initialize:\n");
|
||||
|
||||
*uninitializer = module_uninitialize;
|
||||
*arg = NULL;
|
||||
|
||||
return register_driver("/dev/chardev", &chardev_fops, 0666, NULL);
|
||||
}
|
||||
|
@ -205,5 +205,12 @@ int module_main(int argc, char *argv[])
|
||||
lib_dumpbuffer("Bytes read", (FAR const uint8_t *)g_write_string, nbytes);
|
||||
|
||||
close(fd);
|
||||
ret = rmmod(&module);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: rmmod failed: %d\n", ret);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user