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

sdjournal: don't close libsystemd on Close() #170

Merged
merged 1 commit into from
Jun 7, 2016

Conversation

iaguis
Copy link
Contributor

@iaguis iaguis commented Jun 7, 2016

There is a symbol cache (map from function names to their addresses) so
we don't need to call dlsym everytime we call a function from libsystemd
if it was already called before.

Every time we open a new Journal, we call dlopen(), and every time we
close it, we call dlclose(). Since the map was global and we weren't
clearing it up after closing Journal, we were reusing the addresses from
the previous invocation. This is wrong because libsystemd can end up in
a different address the second time we dlopen() it.

Instead, just don't call dlclose() when we close the Journal so
libsystemd remains in the process address space for the whole life of
it. This means the symbol cache will be shared between different Journal
instances.

According to dlopen(3):

If the same shared object is loaded again with dlopen(), the
same object handle is returned. The dynamic linker maintains reference
counts for object handles, so a dynamically loaded shared object is
not deallocated until dlclose() has been called on it as many times
as dlopen() has succeeded on it.

So we don't worry about calling dlopen() on an already opened library.

This is an alternative fix to #169

There is a symbol cache (map from function names to their addresses) so
we don't need to call dlsym everytime we call a function from libsystemd
if it was already called before.

Every time we open a new Journal, we call dlopen(), and every time we
close it, we call dlclose(). Since the map was global and we weren't
clearing it up after closing Journal, we were reusing the addresses from
the previous invocation. This is wrong because libsystemd can end up in
a different address the second time we dlopen() it.

Instead, just don't call dlclose() when we close the Journal so
libsystemd remains in the process address space for the whole life of
it. This means the symbol cache will be shared between different Journal
instances.

According to dlopen(3):

 If the same shared object is loaded again with dlopen(), the
 same object handle is returned. The dynamic linker maintains reference
 counts for object handles, so a dynamically loaded shared object is
 not deallocated until dlclose() has been called on it as many times
 as dlopen() has succeeded on it.

So we don't worry about calling dlopen() on an already opened library.
@iaguis iaguis force-pushed the iaguis/libsystemd-map-dont-close branch from 0ad9571 to fdff22c Compare June 7, 2016 14:57
@alban
Copy link
Contributor

alban commented Jun 7, 2016

LGTM

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

Successfully merging this pull request may close these issues.

None yet

3 participants