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

Remove need to call apteryx_init before making library calls and need to call apteryx_shutdown on program exit #290

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Commits on Sep 28, 2017

  1. Encapsulate client global data in a structure.

    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 <[email protected]>
    luukp committed Sep 28, 2017
    Configuration menu
    Copy the full SHA
    064e140 View commit details
    Browse the repository at this point in the history
  2. Refactor contents of apteryx_init

    * 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 <[email protected]>
    luukp committed Sep 28, 2017
    Configuration menu
    Copy the full SHA
    245f957 View commit details
    Browse the repository at this point in the history
  3. Gracefully handle fork

    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 <[email protected]>
    luukp committed Sep 28, 2017
    Configuration menu
    Copy the full SHA
    dd5b034 View commit details
    Browse the repository at this point in the history
  4. Automatically clean up Apteryx connections on library unload.

    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 <[email protected]>
    luukp committed Sep 28, 2017
    Configuration menu
    Copy the full SHA
    3a68db0 View commit details
    Browse the repository at this point in the history
  5. Remove the need to call apteryx_init before doing an apteryx call

    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 <[email protected]>
    luukp committed Sep 28, 2017
    Configuration menu
    Copy the full SHA
    e0086c8 View commit details
    Browse the repository at this point in the history