I have an script interpreter that is spawn by a deamon and has to be up all the time.
In other words, as soon as it goes down (crash, segfault, normal termination, whatever), the daemon spawns that again.
This interpreter opens a library dynamically using dlopen (lib1).
This library opens a lot of other libraries (lib2, lib3, …). Some of them make reference to the first library. So I’m using the RTLD_GLOBAL and RTLD_NOW flags for the dlopen call.
Up to this point, everything works well.
Problems arises when the interpreter is killed or crash and get spawned again.
I use dlopen once again, no problem… I can call lib1‘s functions normally.
In lib1‘s code, I make a call to a function from lib2.
The program just stops there.
It looks like it hasn’t crashed (no segfault or something).
There is a debug call right before the call and other in the first line of the function.
The first gets executed. The second one doesn’t.
One last detail: lib1 is actually a C++ library that returns an object instance.
I’m omitting destroyer method from lib1 and all the headers from all modules.
If anyone judge that important, I can give more information.
Does anyone have any idea on what may be happening?
To ilustrate scenario, consider the “pseudo” code:
Interpreter:
Lib1_obj *instance;
void interpreter_start() {
// dlopen lib1
// get lib1_creator symbol.
instance = lib1_creator();
}
void interpreter_on_event_X() {
int x = instance->method1();
printf("x = %d\n", x);
}
Lib1:
class Lib1_obj {
public:
int method1() {
printf("Check point 1.\n");
return lib2_do_something();
}
}
Lib1_obj * creator() {
return new Lib1_obj();
}
Lib2:
lib2_do_something() {
printf("Check point 2.\n");
return 1;
}
I suspect the problem has something to do with the fact I can’t call dlclose when the process gets killed. Is it possible that it messes up the dlopen mechanism?
Thanks very much.
There was a lib that wasn’t compiled with the -fPIC option.
Doing so solved the problem.
Thanks user315052 for the help.