I'm using dlopen() in an Apache module that I am writing so that I can have a plugin system for my module. I've found that if I compile my module, compile my plugin, and start Apache, everything works peachy-keen.
If, however, after I have done all that, I recompile my plugin, (making a small change or two to the plugins code,) my next page load will cause Apache to segfault. Each subsequent request works just fine, again. Thus, it is only the first page load immediately after compiling that causes the segfault.
I've been trying to tackle this for a few days (I'm not great at C debugging) and today, I noticed this in my apache error logs:
Inconsistency detected by ld.so: dl-close.c: 719: _dl_close: Assertion `map->l_init_called' failed!
Anyone have any idea what's going on? Does this mean it's not my code and that I've been hunting a phantom bug? I am fairly confident that I call dlcose() for each call to dlopen(). However, this particular bug/segfault seems to happen when I run apache in single-process mode and start refreshing the page quickly.
Some ideas:
Probably you call dlopen()
more then once? dl
library maintains reference counters which is incremented on every dlopen()
so dlclose()
will unload the library ONLY if counter == 0.
Did you specify RTLD_NODELETE
flag for dlopen()
(assuming you are on Linux)? If yes, dlclose()
won't unload your library.
Did you try to debug syscalls with strace
? Start Apache, finds its pid and trace all syscalls Apache doesn by calling strace -p<pid>
. Probably it will give you some idea what is going on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With