Home Download FAQ / Knowledge Base Screenshots Documentation Support

CTDL_MODULE_INIT

What is this call to CTDL_MODULE_INIT, why is it so important and why must you really, really, really have it in your module ONCE and ONLY ONCE!

First off, it's not a call, its a definition.

CTDL_MODULE_INIT is a macro defined in include/ctdl_module.h and it is used to define the initialization point of your module.

Every module must contain one and only one initialization point so that the core can ask the module to declare its interfaces and perform initialization tasks when the core is ready to start modules.

The initialization function is called twice at system start up. The first time, before multi threading begins and the second time, after the thread system has been initialized. You should test the variable threading to see which call is being processed. You should not attempt to start any threads until multi threading mode is reached.

The initialization function must return a const char * that will be used to make an entry in the Citadel log file.

The build process scans all of the directories under $SRC_DIR/modules and $SRC_DIR/user_modules looking for *.c files that contain this macro. Every occurance of this macro causes the generation of an entry in the auto created files $SRC_DIR/modules_init.c and $SRC_DIR/modules_init.h. This is how the core knows how to find your module.

Your initialization function should make calls to the CtdlRegister.... set of functions to register its interest in facilities and events that the core makes available. If you do not call any CtdlRgister... functions it is unlikely that your module will be able to do anything useful.

There is no time constraint on the length of your initialization function but you should note that the system can not complete its startup until your module has completed its initialization.

Take a look at modules/test/serv_test.c for a simple example of an initialization function.

There are no social media links here. Enjoy a friendly Citadel community instead. Or go outside.