I'm making a program that uses a .so library (also being developed by me). I want to be able to update and re-deploy the .so as I develop it, without restarting the program that uses it. I've demonstrated on my system (Ubuntu 15.04) that dlopen, dlsym, and dlclose can make this happen for me, if I replace the file, close the old library, open the new version via the same file path, and reload the symbol(s) I need. But what if I want to keep the old version open too?
I imagine I could achieve this by using N different file paths for N versions of the library, though I haven't tried it yet. But I'd prefer to use the same path. I can't get this to work though. If I do like this:
- dlopen the old .so
- from outside the program, rm the .so and replace it with a newer version
- dlopen the .so (this time wanting to get a handle to the new version)
...then I appear to end up with two copies of the same library handle, which presumably now has to be dlclose'd twice because its reference count has been increased. And I get the old versions of things from dlsym in step 5. So dlopen is not seeing my new file. I guess its reference-counting mechanism indexes files by path or something, and not by their contents? It'd be pretty weird for it to try to recognize libraries by examining their contents, I suppose.
Can I do what I want, or do I need to just use two different file paths? It's not a big deal in this case, but I'm curious. And the dlopen man pages don't seem to specify what logic dlopen uses to decide whether the library you're opening is one that you already have open.