Skip to content

Commit

Permalink
Add "bootstrap" method, and clean up module API.
Browse files Browse the repository at this point in the history
The bootstrap method is where attributes are created at run time.
This allows OTHER modules to use those attributes.

All modules in the "modules" section are now dlopen'd, their
instance data allocated, configuration is parsed, and the bootstrap
method is called.

Once all of the modules are bootstrapped, the module "instantiate"
method is called.

As part of this change, we simplify the API to:

	module_find = find a known module
	module_bootstrap = load and create a known module
	module_instantiate - call the modules instantiation routine
  • Loading branch information
alandekok committed Apr 29, 2015
1 parent 182d947 commit ff09e8f
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 141 deletions.
4 changes: 3 additions & 1 deletion src/include/modpriv.h
Expand Up @@ -49,12 +49,14 @@ typedef struct module_instance_t {
pthread_mutex_t *mutex;
#endif
CONF_SECTION *cs;
bool instantiated;
bool force;
rlm_rcode_t code;
fr_module_hup_t *mh;
} module_instance_t;

module_instance_t *find_module_instance(CONF_SECTION *modules, char const *askedname, bool do_link);
module_instance_t *module_instantiate(CONF_SECTION *modules, char const *askedname);
module_instance_t *module_find(CONF_SECTION *modules, char const *askedname);
int find_module_sibling_section(CONF_SECTION **out, CONF_SECTION *module, char const *name);
int module_hup_module(CONF_SECTION *cs, module_instance_t *node, time_t when);

Expand Down
10 changes: 2 additions & 8 deletions src/include/modules.h
Expand Up @@ -78,11 +78,6 @@ extern const section_type_value_t section_type_value[];
#define RLM_TYPE_THREAD_UNSAFE (1 << 0) //!< Module is not threadsafe.
//!< Server will protect calls
//!< with mutex.
#define RLM_TYPE_CHECK_CONFIG_UNSAFE (1 << 1) //!< Don't instantiate module on -C.
//!< Module will NOT be
//!< instantiated if the server
//!< is started in config
//!< check mode.
#define RLM_TYPE_HUP_SAFE (1 << 2) //!< Will be restarted on HUP.
//!< Server will instantiated
//!< new instance, and then
Expand Down Expand Up @@ -140,11 +135,10 @@ typedef struct module_t {
int type; //!< One or more of the RLM_TYPE_* constants.
size_t inst_size; //!< Size of the instance data
CONF_PARSER const *config; //!< Configuration information
instantiate_t bootstrap; //!< register dynamic attrs, etc.
instantiate_t instantiate; //!< Function to use for instantiation.
detach_t detach; //!< Function to use to free module instance.
packetmethod methods[MOD_COUNT]; //!< Pointers to the various section functions, ordering
//!< determines which function is mapped to.
//!< which section.
packetmethod methods[MOD_COUNT]; //!< Pointers to the various section functions.
} module_t;

int modules_init(CONF_SECTION *);
Expand Down
23 changes: 9 additions & 14 deletions src/main/command.c
Expand Up @@ -731,7 +731,7 @@ static int command_hup(rad_listen_t *listener, int argc, char *argv[])
cs = cf_section_find("modules");
if (!cs) return CMD_FAIL;

mi = find_module_instance(cs, argv[0], false);
mi = module_find(cs, argv[0]);
if (!mi) {
cprintf_error(listener, "No such module \"%s\"\n", argv[0]);
return CMD_FAIL;
Expand Down Expand Up @@ -911,7 +911,7 @@ static int command_show_module_config(rad_listen_t *listener, int argc, char *ar
cs = cf_section_find("modules");
if (!cs) return CMD_FAIL;

mi = find_module_instance(cs, argv[0], false);
mi = module_find(cs, argv[0]);
if (!mi) {
cprintf_error(listener, "No such module \"%s\"\n", argv[0]);
return CMD_FAIL;
Expand Down Expand Up @@ -949,7 +949,7 @@ static int command_show_module_methods(rad_listen_t *listener, int argc, char *a
cs = cf_section_find("modules");
if (!cs) return CMD_FAIL;

mi = find_module_instance(cs, argv[0], false);
mi = module_find(cs, argv[0]);
if (!mi) {
cprintf_error(listener, "No such module \"%s\"\n", argv[0]);
return CMD_FAIL;
Expand Down Expand Up @@ -979,7 +979,7 @@ static int command_show_module_flags(rad_listen_t *listener, int argc, char *arg
cs = cf_section_find("modules");
if (!cs) return CMD_FAIL;

mi = find_module_instance(cs, argv[0], false);
mi = module_find(cs, argv[0]);
if (!mi) {
cprintf_error(listener, "No such module \"%s\"\n", argv[0]);
return CMD_FAIL;
Expand All @@ -990,11 +990,6 @@ static int command_show_module_flags(rad_listen_t *listener, int argc, char *arg
if ((mod->type & RLM_TYPE_THREAD_UNSAFE) != 0)
cprintf(listener, "thread-unsafe\n");


if ((mod->type & RLM_TYPE_CHECK_CONFIG_UNSAFE) != 0)
cprintf(listener, "no-check-config\n");


if ((mod->type & RLM_TYPE_HUP_SAFE) != 0)
cprintf(listener, "reload-on-hup\n");

Expand All @@ -1014,7 +1009,7 @@ static int command_show_module_status(rad_listen_t *listener, int argc, char *ar
cs = cf_section_find("modules");
if (!cs) return CMD_FAIL;

mi = find_module_instance(cs, argv[0], false);
mi = module_find(cs, argv[0]);
if (!mi) {
cprintf_error(listener, "No such module \"%s\"\n", argv[0]);
return CMD_FAIL;
Expand Down Expand Up @@ -1049,12 +1044,12 @@ static int command_show_modules(rad_listen_t *listener, UNUSED int argc, UNUSED
module_instance_t *mi;

if (name2) {
mi = find_module_instance(cs, name2, false);
mi = module_find(cs, name2);
if (!mi) continue;

cprintf(listener, "%s (%s)\n", name2, name1);
} else {
mi = find_module_instance(cs, name1, false);
mi = module_find(cs, name1);
if (!mi) continue;

cprintf(listener, "%s\n", name1);
Expand Down Expand Up @@ -1990,7 +1985,7 @@ static int command_set_module_config(rad_listen_t *listener, int argc, char *arg
cs = cf_section_find("modules");
if (!cs) return 0;

mi = find_module_instance(cs, argv[0], false);
mi = module_find(cs, argv[0]);
if (!mi) {
cprintf_error(listener, "No such module \"%s\"\n", argv[0]);
return 0;
Expand Down Expand Up @@ -2073,7 +2068,7 @@ static int command_set_module_status(rad_listen_t *listener, int argc, char *arg
cs = cf_section_find("modules");
if (!cs) return 0;

mi = find_module_instance(cs, argv[0], false);
mi = module_find(cs, argv[0]);
if (!mi) {
cprintf_error(listener, "No such module \"%s\"\n", argv[0]);
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/main/modcall.c
Expand Up @@ -2547,7 +2547,7 @@ static modcallable *do_compile_modsingle(modcallable *parent,
* which isn't loaded into the "modules" section.
*/
if (cf_section_sub_find_name2(modules, NULL, realname)) {
this = find_module_instance(modules, realname, true);
this = module_instantiate(modules, realname);
if (this) goto allocate_csingle;

/*
Expand Down Expand Up @@ -2591,7 +2591,7 @@ static modcallable *do_compile_modsingle(modcallable *parent,
buffer[p - modrefname - 1] = '\0';
component = i;

this = find_module_instance(modules, buffer, true);
this = module_instantiate(modules, buffer);
if (this) {
method = i;
goto allocate_csingle;
Expand Down

0 comments on commit ff09e8f

Please sign in to comment.