Home Download News FAQ / Knowledge Base Screenshots Documentation Support
philosophical imaginary


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 its 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 initialisation point of your module.

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

The initialisation 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 initialised. 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 initialisation 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.

NOTE If you are using source code prior to SVN revision 5578 or release version 7.22 you must also edit Makefile.in to tell the build process how to compile your module. So for each of your *.c files you will need to add an entry to the SERV_MODULES and SOURCES macros. This has been automated sinve SVN revision 5578.

Your initialisation 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 initialisation function but you should note that the system can not complete its startup until your module has completed its initialisation.

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

Copyright © 1987-2017 Uncensored Communications Group. All rights reserved.     Login (site admin)