[Asterisk-code-review] loader: Add support for built-in modules. (asterisk[master])
Jenkins2
asteriskteam at digium.com
Mon Jan 22 16:35:09 CST 2018
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/7988 )
Change subject: loader: Add support for built-in modules.
......................................................................
loader: Add support for built-in modules.
* Add SRC_EMBEDDED variable to main/Makefile. Built-in module sources
must be listed in this variable to ensure they get the correct CFLAGS.
Change-Id: I920852bc17513a9c2627061a4ad40511e3a20499
---
M main/Makefile
M main/loader.c
2 files changed, 49 insertions(+), 4 deletions(-)
Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/main/Makefile b/main/Makefile
index c724e20..b148b6f 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -17,6 +17,11 @@
include $(ASTTOPDIR)/Makefile.moddir_rules
+# Can the MODSRC list be automated without needing built-in modules to be
+# in a different directory? Would a different directory be better?
+MOD_SRC:=
+MOD_OBJS:=$(sort $(MOD_SRC:.c=.o))
+
# Must include the extra ast_expr2.c, ast_expr2f.c, in case they need to be regenerated (because to force regeneration, we delete them)
SRC:=$(wildcard *.c) ast_expr2.c ast_expr2f.c
ifeq ($(AST_ASTERISKSSL),yes)
@@ -25,7 +30,7 @@
ifeq ($(PJPROJECT_BUNDLED),yes)
SRC:=$(filter-out libasteriskpj.c,$(SRC))
endif
-OBJSFILTER=fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o
+OBJSFILTER:=$(MOD_OBJS) fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o
OBJS=$(filter-out $(OBJSFILTER),$(SRC:.c=.o))
# we need to link in the objects statically, not as a library, because
@@ -178,6 +183,7 @@
endif
$(OBJS): _ASTCFLAGS+=-DAST_MODULE=\"core\" -DAST_IN_CORE
+$(MOD_OBJS): _ASTCFLAGS+=$(call MOD_ASTCFLAGS,$*)
libasteriskssl.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
@@ -311,10 +317,10 @@
tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE) -Wno-deprecated-declarations
-$(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB) $(LIBEDIT_OBJ)
+$(MAIN_TGT): $(OBJS) $(MOD_OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB) $(LIBEDIT_OBJ)
@$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS)
- $(ECHO_PREFIX) echo " [LD] $(OBJS) $(LIBEDIT_OBJ) -> $@"
- $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(ASTPJ_LDLIBS) $(LIBEDIT_OBJ) buildinfo.o $(AST_LIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)
+ $(ECHO_PREFIX) echo " [LD] $(OBJS) $(MOD_OBJS) $(LIBEDIT_OBJ) -> $@"
+ $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(MOD_OBJS) $(ASTSSL_LDLIBS) $(ASTPJ_LDLIBS) $(LIBEDIT_OBJ) buildinfo.o $(AST_LIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)
ifeq ($(GNU_LD),1)
$(MAIN_TGT): asterisk.exports
diff --git a/main/loader.c b/main/loader.c
index ec8a184..b8e8f94 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -112,6 +112,9 @@
AST_VECTOR(module_vector, struct ast_module *);
+/* Built-in module registrations need special handling at startup */
+static unsigned int loader_ready;
+
/*!
* \brief Internal flag to indicate all modules have been initially loaded.
*/
@@ -149,12 +152,21 @@
unsigned int declined:1;
/*! This module is being held open until it's time to shutdown. */
unsigned int keepuntilshutdown:1;
+ /*! The module is built-in. */
+ unsigned int builtin:1;
} flags;
AST_DLLIST_ENTRY(ast_module) entry;
char resource[0];
};
static AST_DLLIST_HEAD_STATIC(module_list, ast_module);
+
+/*
+ * module_list is cleared by its constructor possibly after
+ * we start accumulating built-in modules, so we need to
+ * use another list (without the lock) to accumulate them.
+ */
+static struct module_list builtin_module_list;
static int module_vector_strcasecmp(struct ast_module *a, struct ast_module *b)
{
@@ -444,6 +456,22 @@
void ast_module_register(const struct ast_module_info *info)
{
struct ast_module *mod;
+
+ if (!loader_ready) {
+ mod = ast_calloc(1, sizeof(*mod) + strlen(info->name) + 1);
+ if (!mod) {
+ /* We haven't even reached main() yet, if we can't
+ * allocate memory at this point just give up. */
+ exit(2);
+ }
+ strcpy(mod->resource, info->name); /* safe */
+ mod->info = info;
+ mod->flags.builtin = 1;
+ AST_DLLIST_INSERT_TAIL(&builtin_module_list, mod, entry);
+
+ /* ast_module_register for built-in modules is run again during module preload. */
+ return;
+ }
/*
* This lock protects resource_being_loaded as well as the module
@@ -1729,6 +1757,17 @@
AST_DLLIST_LOCK(&module_list);
+ /*
+ * All built-in modules have registered the first time, now it's time to complete
+ * the registration and add them to the priority list.
+ */
+ loader_ready = 1;
+
+ while ((resource_being_loaded = AST_DLLIST_REMOVE_HEAD(&builtin_module_list, entry))) {
+ /* ast_module_register doesn't finish when first run by built-in modules. */
+ ast_module_register(resource_being_loaded->info);
+ }
+
cfg = ast_config_load2(AST_MODULE_CONFIG, "" /* core, can't reload */, config_flags);
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
--
To view, visit https://gerrit.asterisk.org/7988
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I920852bc17513a9c2627061a4ad40511e3a20499
Gerrit-Change-Number: 7988
Gerrit-PatchSet: 3
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180122/036d61ff/attachment.html>
More information about the asterisk-code-review
mailing list