Remove need to call apteryx_init before making library calls and need to call apteryx_shutdown on program exit#290
Open
luukp wants to merge 5 commits into
Open
Remove need to call apteryx_init before making library calls and need to call apteryx_shutdown on program exit#290luukp wants to merge 5 commits into
luukp wants to merge 5 commits into
Conversation
This is preparatory to cleaning up correctly after a fork, and not requiring apteryx_init to be called. * Some unreachable code in apteryx_dump is removed. (prior ASSERT performs this check) * apteryx_shutdown_force is changed to just keep calling apteryx_shutdown until it returns false, rather than relying on refcount. This means that technically it will be called once more than necessary. Signed-off-by: Luuk Paulussen <luuk.paulussen@alliedtelesis.co.nz>
* Move the client init code done inside the lock to _apteryx_init_internal * Split the code to start the callback server into a separate function and call from _apteryx_init_internal and from add_callback Signed-off-by: Luuk Paulussen <luuk.paulussen@alliedtelesis.co.nz>
When a process linked to an initialized apteryx client library forks, one of the threads and all of the internal data and socket handles are copied to the new process. All locks are left in their current state. This means that in the child process, the state of the client is indeterminate. Register pthread_atfork handlers to take the global lock and release it, so that we at least have one lock we know is safe in the child process. Also, set client data to NULL in the child process, so that it can no longer interfere with any sockets, etc. created by the parent. Currently, if the child calls apteryx_shutdown, the parent process loses its callback socket. This breaks the test_double_fork unit test. That test expects to be able to set/get after a fork without reinitialising. Signed-off-by: Luuk Paulussen <luuk.paulussen@alliedtelesis.co.nz>
This will cause any RPC connections and Unix socket descriptors to be cleaned up. This will also be called when a forked process unloads the library, but as we have set the client_data to NULL in _apteryx_atfork_child, this will have no negative effect. Signed-off-by: Luuk Paulussen <luuk.paulussen@alliedtelesis.co.nz>
Add a function that gets the apteryx client data if it exists and initialises it if it does not. Use this function in the apteryx client APIs. The test_init function is removed as its assertions are no longer valid. The test_double_fork test now passes again. Signed-off-by: Luuk Paulussen <luuk.paulussen@alliedtelesis.co.nz>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.