Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asterisk-16: new package #411

Merged
merged 1 commit into from
May 1, 2019
Merged

asterisk-16: new package #411

merged 1 commit into from
May 1, 2019

Conversation

micmac1
Copy link
Contributor

@micmac1 micmac1 commented Mar 2, 2019

Maintainer: @jslachta
Compile tested: master, ath79 (musl) + arc (uclibc)
Run tested: ath79 master

Description:
Hello all,

This is not ready for merging yet. There is a problem with segmentation faults when the module loader starts. I've had help from the musl list and raised as issue for it upstream.

According to asterisk wiki Asterisk 15 will be EOL 2019-10-03, so getting Asterisk 16 in would be nice. Not to mention that 16 is an LTS release. But before this can be merged something needs to be done regarding the segmentation fault.

Kind regards,
Seb

@dhewg
Copy link
Contributor

dhewg commented Mar 5, 2019

Oh damn... just noticed this now :(

@jslachta
Copy link
Contributor

jslachta commented Mar 5, 2019

Good contributions from both of you! We should find out what is causing the segfaults. @dhewg are you experiencing the mentioned segfaults in your version of ast16 package?

@dhewg
Copy link
Contributor

dhewg commented Mar 5, 2019

I did, and I fixed the same spot, just a bit differently.

commit asterisk-16.x: hack to silence segfault in loader here relates to my patches/201-loader-fix-crash-on-arm-musl.patch

As does asterisk-16.x: fix musl compiles here with my patches/200-enforce-ASTMM_IGNORE.patch

@micmac1
Copy link
Contributor Author

micmac1 commented Mar 5, 2019

Hi @jslachta & @dhewg,

Thanks for chiming in. I was bummed out a bit by the astmm.h thing. I thought that maybe if we fix that differently then the segfault will disappear. So I asked for help again on the must list here. It was suggested to simply include sched.h before the redefinitions. So I changed the astmm.h patch to this:


--- a/include/asterisk/astmm.h
+++ b/include/asterisk/astmm.h
@@ -121,6 +121,12 @@ int __ast_repl_vasprintf(char **strp, co
 /* Don't touch the libc functions. */
 #else
 
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) && !defined(__GLIBC__)
+/* with _GNU_SOURCE defined musl also declares calloc in sched.h - and we need
+ * to define these macros _after_ including the libc headers, not before */
+#include <sched.h>
+#endif
+
 /* Undefine any macros */
 #undef malloc
 #undef calloc

That actually works fine, compile failures are gone.

But I was too optimistic thinking that this might also fix the segfault :-)

Kind regards,
Seb

@dhewg
Copy link
Contributor

dhewg commented Mar 6, 2019

The responses on the musl list reflect my own findings: code of poor quality on asterisk's side.
This whole ASTMM_LIBC thing is for debugging anyway. I recommend just enforcing ASTMM_IGNORE and be done with it.

@micmac1
Copy link
Contributor Author

micmac1 commented Mar 10, 2019 via email

@dhewg
Copy link
Contributor

dhewg commented Mar 10, 2019

Hello, I agree in so far as the patch I posted is lacking. I think the correct place the address this would be in the source files that include "asterisk.h" and <sched.h>. But this might be a bit more involved, so for the time being I think ASTMM_IGNORE is the way to go.

There are of course better ways to fix this. But I'm not going to sign any CLA to submit a proper fix upstream. So my answer was meant as a way to get this working on openwrt with a simple and future proof patch. If you're up to upstream a proper fix - I'm all for it!

Regarding the segfaults. I'm still trying to get to the bottom of this. It's fun, but time-consuming. Yesterday I made a little progress. I think I'll again post to the musl list later today, with more details, to ask for their insight. Kind regards, Seb

That alloca(dlerror()) issue? You have a similar patch than I have in my MR, both should fix the segfaults, no? At least I have asterisk running on openwrt with what I submitted.

@micmac1
Copy link
Contributor Author

micmac1 commented Mar 11, 2019

Hello again,

Don't have something off-hand for the astmm.h header. But I'm not really worried about that either as it all worked fine in the past without the redefinitions.

But the module loader issue does put the fear in me. The loader is complex and the fact that on musl dlopen will only run the constructor once doesn't fit in with the loader's inner workings.

I agree that the workaround (preventing the segfault) seems to work. But there's a good chance that something isn't working that we're not aware of.

The only other project that defaults to musl is Alpine Linux afaik. And they didn't upgrade to Asterisk 16 yet, they still run 15. I'm venturing a guess here that they've seen the breakage, too, and are being cautious for now. I'd rather wait till a proper workaround is available (and honestly/realistically it'll likely not be from me).

Just my 2 cents. :)

Kind regards,
Seb

@dhewg
Copy link
Contributor

dhewg commented Mar 11, 2019

But the module loader issue does put the fear in me. The loader is complex and the fact that on musl dlopen will only run the constructor once doesn't fit in with the loader's inner workings.

I agree that the workaround (preventing the segfault) seems to work. But there's a good chance that something isn't working that we're not aware of.

That might well be, in fact I now get these warnings at startup:

[Mar 11 16:10:57] WARNING[5672] loader.c: Some non-required modules failed to load.
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_crypto.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_format_attr_opus.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_pjproject.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_pjsip.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_pjsip_config_wizard.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_pjsip_outbound_publish.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_pjsip_pubsub.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_pjsip_session.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_smdi.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_sorcery_astdb.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_sorcery_config.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_sorcery_memory.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_sorcery_realtime.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_speech.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_statsd.so' did not register itself during load
[Mar 11 16:10:57] ERROR[5672] loader.c: Module 'res_agi.so' did not register itself during load

I didn't investigate, but to me it looks like their loader relies on a behavior that only holds on glibc. Those modules are loaded (module show) and do work. To me it looks like they got loaded as a dependency from a prior loaded module, so I ignored that issue as yet another problem with their code.

The only other project that defaults to musl is Alpine Linux afaik. And they didn't upgrade to Asterisk 16 yet, they still run 15. I'm venturing a guess here that they've seen the breakage, too, and are being cautious for now. I'd rather wait till a proper workaround is available (and honestly/realistically it'll likely not be from me).

Oh, I didn't know about alpine and musl, did you have contact with the asterisk packagers before?

I can only reiterate, but I do have asterisk16 running with these patches on openwrt for some weeks. And that's my business line, so I guess +100 calls now. I don't mind waiting to merge asterisk16 support, but we can replace our patches at any time once there's a better/proper fix. But i guess that's going to be a rewrite of parts of their loader due to their presumptions.

@micmac1
Copy link
Contributor Author

micmac1 commented Mar 19, 2019

Hi all,

I updated the astmm.h patch a bit (mostly comments). And for the loader I started on a workaround. But something is not right with it. If anybody wants to test or has any comments, please do so.

Best regards,
Seb

@micmac1
Copy link
Contributor Author

micmac1 commented Mar 24, 2019

Hello @jslachta & @dhewg

I reworked the loader patch. Now both ast_module_register() and ast_module_unregister() are always called manually when needed. This looks OK now when running asterisk.

Adding @fabled from Alpine and @jacmet, @bkuhls and @yann-morin-1998 from Buildroot in the hopes of getting some more eyes on the loader/astmm patches. Both Alpine and Buildroot use musl, too, so I think there might be a common interest here :-)

I'm not a programmer, so I probably made some mistakes. If anybody could test/review this and provide feedback that would be cool.

Kind regards,
Seb

@micmac1
Copy link
Contributor Author

micmac1 commented Mar 31, 2019

Hi all,

Updated the loader patch. For one I removed the OpenWrt Makefile part to make it easier to test if you don't use OpenWrt.

The other changes:

  • Added function ast_get_name_from_resource(). This prevents duplicate code. It also now checks if ".so" is at the end of the string. I saw that this isn't always the case, for instance when modules are manually unloaded. So this is a needed extension.
  • ast_manual_module_unregister() now checks if Asterisk is currently shutting down; if it is then it just returns because on exit the destructor is called automatically.
  • When creating module_info_list the options for ao2_container_alloc_list() is now simply set to AO2_ALLOC_OPT_LOCK_NOLOCK instead of AO2_ALLOC_OPT_LOCK_MUTEX as we're not locking (not needed as far as I'm aware).
  • In ast_module_register() the pointer comparison is removed because this can never be true as we provided the info pointer ourselves, the one we got from the first constructor run. I even checked on glibc; there as well the pointer didn't change when dlopen() called the constructor automatically.
--- /home/sk/github/telephony//net/asterisk-16.x/patches/120-loader.patch	2019-03-24 21:55:24.754642492 +0100
+++ feeds/telephony/net/asterisk-16.x/patches/120-loader.patch	2019-03-31 17:55:32.183909932 +0200
@@ -38,7 +38,7 @@
  static __attribute__((format(printf, 1, 2))) void module_load_error(const char *fmt, ...)
  {
  	char *copy = NULL;
-@@ -250,6 +281,55 @@ static void publish_unload_message(const
+@@ -250,6 +281,90 @@ static void publish_unload_message(const
   */
  static struct module_list builtin_module_list;
  
@@ -52,16 +52,47 @@
 +	return strcasecmp(entry1->name, entry_name) ? 0 : CMP_MATCH | CMP_STOP;
 +}
 +
-+static void ast_manual_module_register(const void *lib, const char *name)
++static char *ast_get_name_from_resource(const char *resource)
++{
++	int len;
++	const char *last_three;
++	char *mod_name;
++
++	if (!resource) {
++		return NULL;
++	}
++
++	len = strlen(resource);
++	if (len > 3) {
++		last_three = &resource[len-3];
++		if (!strcasecmp(last_three, ".so")) {
++			mod_name = ast_calloc(1, len - 2);
++			if (mod_name) {
++				ast_copy_string(mod_name, resource, len - 2);
++				return mod_name;
++			} else {
++				/* Unable to allocate memory. */
++				return NULL;
++			}
++		}
++	}
++	/* Resource is the name - happens when manually unloading a module. */
++	mod_name = ast_calloc(1, len + 1);
++	if (mod_name) {
++		ast_copy_string(mod_name, resource, len + 1);
++		return mod_name;
++	}
++	/* Unable to allocate memory. */
++	return NULL;
++}
++
++static void ast_manual_module_register(const void *lib, const char *resource)
 +{
 +	struct module_info_list_entry *obj_tmp;
 +	char *mod_name;
 +	if (lib) {
-+		/* info->name does not include ".so", need to remove this from name
-+		 * before comparing */
-+		mod_name = ast_calloc(1, strlen(name) - 2);
++		mod_name = ast_get_name_from_resource(resource);
 +		if (mod_name) {
-+			ast_copy_string(mod_name, name, strlen(name) - 2);
 +			obj_tmp = ao2_find(module_info_list, mod_name, OBJ_SEARCH_KEY);
 +			if (obj_tmp) {
 +				if (obj_tmp->dlopened == FIRST_DLOPEN) {
@@ -75,13 +106,17 @@
 +	}
 +}
 +
-+static void ast_manual_module_unregister(const char *name)
++static void ast_manual_module_unregister(const char *resource)
 +{
-+	struct module_info_list_entry *obj_tmp;
++	/* When Asterisk shuts down the destructor is called automatically. */
++	if (ast_shutdown_final()) {
++		return;
++	}
++
++	const struct module_info_list_entry *obj_tmp;
 +	char *mod_name;
-+	mod_name = ast_calloc(1, strlen(name) - 2);
++	mod_name = ast_get_name_from_resource(resource);
 +	if (mod_name) {
-+		ast_copy_string(mod_name, name, strlen(name) - 2);
 +		obj_tmp = ao2_find(module_info_list, mod_name, OBJ_SEARCH_KEY);
 +		if (obj_tmp) {
 +			ast_module_unregister(obj_tmp->info);
@@ -94,27 +129,20 @@
  static int module_vector_strcasecmp(struct ast_module *a, struct ast_module *b)
  {
  	return strcasecmp(a->resource, b->resource);
-@@ -597,6 +677,31 @@ void ast_module_register(const struct as
+@@ -597,6 +712,24 @@ void ast_module_register(const struct as
  
  	/* give the module a copy of its own handle, for later use in registrations and the like */
  	*((struct ast_module **) &(info->self)) = mod;
 +
 +#if defined(HAVE_PERMANENT_DLOPEN)
 +	if (!module_info_list) {
-+		module_info_list = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, info_cmp_fn);
++		module_info_list = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, info_cmp_fn);
 +	}
 +
 +	if (module_info_list && mod->flags.builtin != 1) {
 +		struct module_info_list_entry *obj_tmp = ao2_find(module_info_list, info->name, OBJ_SEARCH_KEY);
 +		if (!obj_tmp) {
 +			ao2_link(module_info_list, allocate_module_info_list_entry(info->name, info));
-+		} else {
-+			if (!(obj_tmp->info == info)) {
-+				ao2_unlink(module_info_list, obj_tmp);
-+				// This will put obj_tmp->dlopened back to
-+				// FIRST_DLOPEN. Unclear if we want that.
-+				ao2_link(module_info_list, allocate_module_info_list_entry(info->name, info));
-+			}
 +		}
 +	}
 +
@@ -126,7 +154,7 @@
  }
  
  static int module_post_register(struct ast_module *mod)
-@@ -843,6 +948,10 @@ static void logged_dlclose(const char *n
+@@ -843,6 +976,10 @@ static void logged_dlclose(const char *n
  		error = dlerror();
  		ast_log(AST_LOG_ERROR, "Failure in dlclose for module '%s': %s\n",
  			S_OR(name, "unknown"), S_OR(error, "Unknown error"));
@@ -137,7 +165,7 @@
  	}
  }
  
-@@ -949,6 +1058,9 @@ static struct ast_module *load_dlopen(co
+@@ -949,6 +1086,9 @@ static struct ast_module *load_dlopen(co
  
  	resource_being_loaded = mod;
  	mod->lib = dlopen(filename, flags);
@@ -147,7 +175,7 @@
  	if (resource_being_loaded) {
  		struct ast_str *list;
  		int c = 0;
-@@ -968,6 +1080,9 @@ static struct ast_module *load_dlopen(co
+@@ -968,6 +1108,9 @@ static struct ast_module *load_dlopen(co
  
  		resource_being_loaded = mod;
  		mod->lib = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);

@micmac1
Copy link
Contributor Author

micmac1 commented Mar 31, 2019

Oh, and I changed the name of the 2nd argument of both ast_manual_module_register() and ast_manual_module_unregister() from "name" to "resource" to make the point that this is not the name ("super_mod") but the file ("super_mod.so").

@micmac1
Copy link
Contributor Author

micmac1 commented Apr 4, 2019

Quick update, loader patch is being reviewed upstream here

Corey Farrell was nice enough to provide lots of feedback; changes were made. Will update the PR once final.

Kind regards,
Seb

@micmac1 micmac1 force-pushed the ast16 branch 2 times, most recently from c27f222 to 1490309 Compare April 11, 2019 18:42
@micmac1
Copy link
Contributor Author

micmac1 commented Apr 11, 2019

Hello Jiri, @dhewg et al,

I have updated the loader patch with the one that is now in upstream's gerrit. It was reviewed by Corey from Digium who also cherry-picked it for 16. It has not been committed yet, but that may take some more time.

I'd like to ask that you give it a test run. I have run-tested this and it looks good to me. If this gets merged I can open another pull request to add the out-of-tree modules.

As a side note I would suggests to think about removing both Asterisk 13 and 15. My arguments would be the following:

  • 16 is an LTS release (like 13)
  • 16 should have all the functionality that 13 and 15 offer, so upgrading should be no problem
  • 15 will be end of life in October 2019
  • maintaining multiple versions in different OpenWrt releases (currently 17.01, 18.06 and master; when OpenWrt cuts 19.x I expect 17.01 will be end of life) is quite laborious, also because there are often security patches to deal with

Looking forward to hear from you :)

With kind regards,
Seb

@dhewg dhewg mentioned this pull request Apr 12, 2019
@dhewg
Copy link
Contributor

dhewg commented Apr 12, 2019

Nice work! Did you sign their contributor stuff?

I updated #412 with just the additions and build with that on top of this (since I depend on those modules). Everything built just fine and seems to work with just a quick test. I'll test it a few days to make sure.

I got this message though, I think that's new?

[Apr 12 10:46:38] WARNING[2849] loader.c: Some non-required modules failed to load.
[Apr 12 10:46:38] ERROR[2849] loader.c: cdr_syslog declined to load.

@micmac1
Copy link
Contributor Author

micmac1 commented Apr 12, 2019

Hello @dhewg

I signed it some time ago for some other stuff, so no extra effort there :)

cdr_syslog only loads when you provide proper config for it (not installed by default), so that is normal I take it.

Kind regards,
Seb

Edit: I get this also on x86_64 with glibc (so without the loader patch).

@dhewg
Copy link
Contributor

dhewg commented Apr 17, 2019

It's been working fine for me, no issues at all. I'd say this can go in ;)

@micmac1
Copy link
Contributor Author

micmac1 commented Apr 17, 2019 via email

@jslachta
Copy link
Contributor

I acknowledge that asterisk works fine.

@micmac1
Copy link
Contributor Author

micmac1 commented Apr 19, 2019 via email

@fabled
Copy link

fabled commented Apr 20, 2019

Nice work!

I am looking to upgrade Alpine Asterisk soon. Seems that a simpler fix for the astmm issue might be:

--- a/include/asterisk/compat.h
+++ b/include/asterisk/compat.h
@@ -30,6 +30,7 @@
 #include <inttypes.h>
 #include <limits.h>
 #include <unistd.h>
+#include <pthread.h>
 
 #ifdef HAVE_STDDEF_H
 #include <stddef.h>

See also: alpinelinux/aports@a752e63

@micmac1
Copy link
Contributor Author

micmac1 commented Apr 20, 2019

--- a/include/asterisk/compat.h
+++ b/include/asterisk/compat.h
@@ -30,6 +30,7 @@
 #include <inttypes.h>
 #include <limits.h>
 #include <unistd.h>
+#include <pthread.h>
 
 #ifdef HAVE_STDDEF_H
 #include <stddef.h>

Hi Timo,

That seems to work fine. I understand that this way sched.h is included before astmm.h and that's why the compile does not fail. Could you tell me though why you chose to include pthread.h instead of sched.h?

Kind regards,
Seb

@fabled
Copy link

fabled commented Apr 20, 2019

I understand that this way sched.h is included before astmm.h and that's why the compile does not fail. Could you tell me though why you chose to include pthread.h instead of sched.h?

The header inclusion chain seems to be asterisk/astobj2.h -> asterisk/lock.h -> pthread.h -> sched.h. So I figured to take the top level musl header in case there ever comes additional similar indirect conflicting dependencies. Seems asterisk practically never includes sched.h directly.

@micmac1
Copy link
Contributor Author

micmac1 commented Apr 20, 2019 via email

@micmac1
Copy link
Contributor Author

micmac1 commented Apr 21, 2019

Hi Jiri,

I updated the commit with Timo's astmm fix. Compile-tested on ath79 (musl) and arc (uclibc), run-tested on ath79.

Kind regards,
Seb

@jslachta
Copy link
Contributor

Hi Sebastian,

thank you for your hard work. I have made several tests and tried Asterisk 16 in production and it seems to be stable. Would you be so kind to squash those commits into one?

Thank you.

Kind Regards,
Jiri

@micmac1
Copy link
Contributor Author

micmac1 commented Apr 27, 2019

Hi Sebastian,

thank you for your hard work. I have made several tests and tried Asterisk 16 in production and it seems to be stable. Would you be so kind to squash those commits into one?

Thank you.

Kind Regards,
Jiri

Hi Jiri,

Commits squashed.

Kind regards,
Seb

@LipkeGu
Copy link

LipkeGu commented Apr 27, 2019

Thanks for your work, is it able to adapt and cover #369

@jslachta
Copy link
Contributor

Thanks for your work, is it able to adapt and cover #369

Not within this PR. This is completely different task. It does not belong to this PR.

@micmac1
Copy link
Contributor Author

micmac1 commented May 1, 2019 via email

net/asterisk-16.x/Makefile Outdated Show resolved Hide resolved
Initial commit of Asterisk 16. Cleans up Makefile; the version number
now only occurs once in it.

Upstream removed the following modules:

  - format_jpeg
  - res_pjsip_registrar_expire (functionality was moved into
    res_pjsip_registrar.)

pjsip has a new dependency, res-http-websocket.

Notes:

  - replaced res_ninit patch

    Replaced patch with the one from Alpine. It's a bit more flexible and
    allows usage of res_ninit where available (when building against
    glibc).

  - fixed musl compiles

    astmm.h now always gets included by asterisk.h, redefining allocators.
    This causes breakage on musl:

    ccache_cc -o chan_pjsip.o -c chan_pjsip.c -MD -MT chan_pjsip.o -MF .chan_pjsip.o.d -MP -pthread -I/home/sk/tmp/openwrt/build_dir/target-mips_24kc_musl/asterisk-16.2.1/include -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -iremap/home/sk/tmp/openwrt/build_dir/target-mips_24kc_musl/asterisk-16.2.1:asterisk-16.2.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -I/home/sk/tmp/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/libiconv-stub/include -I/home/sk/tmp/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/libintl-stub/include -I/home/sk/tmp/openwrt/staging_dir/target-mips_24kc_musl/usr/include -I/home/sk/tmp/openwrt/staging_dir/target-mips_24kc_musl/include -I/home/sk/tmp/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/usr/include -I/home/sk/tmp/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/include/fortify -I/home/sk/tmp/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/include -I/home/sk/tmp/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/libiconv-stub/include -I/home/sk/tmp/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/libintl-stub/include    -I/home/sk/tmp/openwrt/staging_dir/target-mips_24kc_musl/usr/include/libxml2  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations       -fPIC -DAST_MODULE=\"chan_pjsip\" -DAST_MODULE_SELF_SYM=__internal_chan_pjsip_self  -DPJ_AUTOCONF=1 -DPJ_IS_BIG_ENDIAN=1 -DPJ_IS_LITTLE_ENDIAN=0 -fPIC -I/home/sk/tmp/openwrt/staging_dir/target-mips_24kc_musl/usr/include
    In file included from /home/sk/tmp/openwrt/build_dir/target-mips_24kc_musl/asterisk-16.2.1/include/asterisk.h:23:0,
                     from chan_pjsip.c:35:
    /home/sk/tmp/openwrt/build_dir/target-mips_24kc_musl/asterisk-16.2.1/include/asterisk/astmm.h:158:35: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
      Do_not_use_calloc__use_ast_calloc->fail(a, b)
                                       ^
    /home/sk/tmp/openwrt/build_dir/target-mips_24kc_musl/asterisk-16.2.1/include/asterisk/astmm.h:162:77: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
      Do_not_use_free__use_ast_free_or_ast_std_free_for_remotely_allocated_memory->fail(a)
                                                                                 ^
    make[4]: *** [/home/sk/tmp/openwrt/build_dir/target-mips_24kc_musl/asterisk-16.2.1/Makefile.rules:153: chan_pjsip.o] Error 1

    The problem is that with _GNU_SOURCE defined musl also declares calloc in
    <sched.h> - and when asterisk's source includes <sched.h> _after_
    "asterisk/astmm.h" the definition clashes with the macro. Timo Teräs from
    Alpine Linux fixed this by including <pthread.h> in "asterisk/compat.h". He
    chose to include <pthread.h> instead of <sched.h> because the original
    header inclusion chain seems to be "asterisk/astobj2.h" ->
    "asterisk/lock.h" -> <pthread.h> -> <sched.h>. It seems Asterisk
    practically never includes <sched.h> directly.

  - added loader workaround for musl

    When the modules are loaded, asterisk segfaults on musl.

       Asterisk Dynamic Loader Starting:
      [Mar  2 22:30:05] NOTICE[20712]: loader.c:2230 load_modules: 91 modules will be loaded.
      Segmentation fault

      [48817.544248] do_page_fault(): sending SIGSEGV to asterisk for invalid read access from 00000000
      [48817.544258] epc = 77f6b764 in libc.so[77ef8000+94000]
      [48817.544285] ra  = 0048d579 in asterisk[400000+160000]

    The real problem is that the loader expects dlopen to always run the
    constructor, which doesn't happen with musl, because its dlopen is
    permanent.

    This commit adds a new configure switch '--enable-permanent-dlopen'.
    When enabled, the loader will manually call 'ast_module_register(...)'
    and 'ast_module_unregister(...)' when needed.

  - allow eventfd detection

    Asterisk 16 wants to use eventfd, but it doesn't allow the detection
    during cross-compiling. This results in runtime warnings, for instance
    when shutting down:

      [Mar  2 22:37:41] WARNING[21593]: alertpipe.c:112 ast_alertpipe_read: read() failed: Bad file descriptor
      [Mar  2 22:37:41] WARNING[21593]: alertpipe.c:112 ast_alertpipe_read: read() failed: Bad file descriptor
      [Mar  2 22:37:41] WARNING[21593]: alertpipe.c:112 ast_alertpipe_read: read() failed: Bad file descriptor

    Relax the configure script so that eventfd can also be detected when
    cross-compiling.

Signed-off-by: Sebastian Kemper <[email protected]>
@micmac1
Copy link
Contributor Author

micmac1 commented May 1, 2019

Hi Jiri, will do tonight. Regards, Seb

Well, it's a bank holiday here, so did it already ;-)

@jslachta
Copy link
Contributor

jslachta commented May 1, 2019

Thank you, Seb. I am merging this PR.

@jslachta jslachta changed the title Asterisk 16 asterisk-16: new package May 1, 2019
@jslachta jslachta merged commit 5d9b115 into openwrt:master May 1, 2019
@jslachta
Copy link
Contributor

jslachta commented May 1, 2019

I am going to drop asterisk-15.x package first in favor of asterisk-16.x package. If asterisk-16.x package has reasonable package sizes and is stable for the production, the I would remove the ast13 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants