<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7988">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">loader: Add support for built-in modules.<br><br>* Add SRC_EMBEDDED variable to main/Makefile.  Built-in module sources<br>  must be listed in this variable to ensure they get the correct CFLAGS.<br><br>Change-Id: I920852bc17513a9c2627061a4ad40511e3a20499<br>---<br>M main/Makefile<br>M main/loader.c<br>2 files changed, 49 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/Makefile b/main/Makefile<br>index c724e20..b148b6f 100644<br>--- a/main/Makefile<br>+++ b/main/Makefile<br>@@ -17,6 +17,11 @@<br> <br> include $(ASTTOPDIR)/Makefile.moddir_rules<br> <br>+# Can the MODSRC list be automated without needing built-in modules to be<br>+# in a different directory?  Would a different directory be better?<br>+MOD_SRC:=<br>+MOD_OBJS:=$(sort $(MOD_SRC:.c=.o))<br>+<br> # Must include the extra ast_expr2.c, ast_expr2f.c, in case they need to be regenerated (because to force regeneration, we delete them)<br> SRC:=$(wildcard *.c) ast_expr2.c ast_expr2f.c<br> ifeq ($(AST_ASTERISKSSL),yes)<br>@@ -25,7 +30,7 @@<br> ifeq ($(PJPROJECT_BUNDLED),yes)<br> SRC:=$(filter-out libasteriskpj.c,$(SRC))<br> endif<br>-OBJSFILTER=fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o<br>+OBJSFILTER:=$(MOD_OBJS) fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o<br> OBJS=$(filter-out $(OBJSFILTER),$(SRC:.c=.o))<br> <br> # we need to link in the objects statically, not as a library, because<br>@@ -178,6 +183,7 @@<br> endif<br> <br> $(OBJS): _ASTCFLAGS+=-DAST_MODULE=\"core\" -DAST_IN_CORE<br>+$(MOD_OBJS): _ASTCFLAGS+=$(call MOD_ASTCFLAGS,$*)<br> <br> libasteriskssl.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)<br> <br>@@ -311,10 +317,10 @@<br> <br> tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE) -Wno-deprecated-declarations<br> <br>-$(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB) $(LIBEDIT_OBJ)<br>+$(MAIN_TGT): $(OBJS) $(MOD_OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB) $(LIBEDIT_OBJ)<br>        @$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS)<br>-      $(ECHO_PREFIX) echo "   [LD] $(OBJS) $(LIBEDIT_OBJ) -> $@"<br>-      $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(ASTPJ_LDLIBS) $(LIBEDIT_OBJ) buildinfo.o $(AST_LIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)<br>+    $(ECHO_PREFIX) echo "   [LD] $(OBJS) $(MOD_OBJS) $(LIBEDIT_OBJ) -> $@"<br>+  $(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)<br> <br> ifeq ($(GNU_LD),1)<br> $(MAIN_TGT): asterisk.exports<br>diff --git a/main/loader.c b/main/loader.c<br>index ec8a184..b8e8f94 100644<br>--- a/main/loader.c<br>+++ b/main/loader.c<br>@@ -112,6 +112,9 @@<br> <br> AST_VECTOR(module_vector, struct ast_module *);<br> <br>+/* Built-in module registrations need special handling at startup */<br>+static unsigned int loader_ready;<br>+<br> /*!<br>  * \brief Internal flag to indicate all modules have been initially loaded.<br>  */<br>@@ -149,12 +152,21 @@<br>                unsigned int declined:1;<br>              /*! This module is being held open until it's time to shutdown. */<br>                unsigned int keepuntilshutdown:1;<br>+            /*! The module is built-in. */<br>+               unsigned int builtin:1;<br>       } flags;<br>      AST_DLLIST_ENTRY(ast_module) entry;<br>   char resource[0];<br> };<br> <br> static AST_DLLIST_HEAD_STATIC(module_list, ast_module);<br>+<br>+/*<br>+ * module_list is cleared by its constructor possibly after<br>+ * we start accumulating built-in modules, so we need to<br>+ * use another list (without the lock) to accumulate them.<br>+ */<br>+static struct module_list builtin_module_list;<br> <br> static int module_vector_strcasecmp(struct ast_module *a, struct ast_module *b)<br> {<br>@@ -444,6 +456,22 @@<br> void ast_module_register(const struct ast_module_info *info)<br> {<br>    struct ast_module *mod;<br>+<br>+   if (!loader_ready) {<br>+         mod = ast_calloc(1, sizeof(*mod) + strlen(info->name) + 1);<br>+               if (!mod) {<br>+                  /* We haven't even reached main() yet, if we can't<br>+                    * allocate memory at this point just give up. */<br>+                    exit(2);<br>+             }<br>+            strcpy(mod->resource, info->name); /* safe */<br>+          mod->info = info;<br>+         mod->flags.builtin = 1;<br>+           AST_DLLIST_INSERT_TAIL(&builtin_module_list, mod, entry);<br>+<br>+             /* ast_module_register for built-in modules is run again during module preload. */<br>+           return;<br>+      }<br> <br>  /*<br>     * This lock protects resource_being_loaded as well as the module<br>@@ -1729,6 +1757,17 @@<br> <br>  AST_DLLIST_LOCK(&module_list);<br> <br>+        /*<br>+    * All built-in modules have registered the first time, now it's time to complete<br>+         * the registration and add them to the priority list.<br>+        */<br>+  loader_ready = 1;<br>+<br>+ while ((resource_being_loaded = AST_DLLIST_REMOVE_HEAD(&builtin_module_list, entry))) {<br>+          /* ast_module_register doesn't finish when first run by built-in modules. */<br>+             ast_module_register(resource_being_loaded->info);<br>+ }<br>+<br>  cfg = ast_config_load2(AST_MODULE_CONFIG, "" /* core, can't reload */, config_flags);<br>   if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {<br>           ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7988">change 7988</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7988"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I920852bc17513a9c2627061a4ad40511e3a20499 </div>
<div style="display:none"> Gerrit-Change-Number: 7988 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>