Back to index

glibc  2.9
Classes | Defines | Functions
fork.h File Reference
#include <list.h>
#include <bits/libc-lock.h>
#include <sysdep.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  fork_block
struct  fork_handler

Defines

#define UNREGISTER_ATFORK(dso_handle)   __unregister_atfork (dso_handle)
#define ARCH_FORK()   INLINE_SYSCALL (fork, 0)

Functions

void __unregister_atfork (void *dso_handle) attribute_hidden
int __register_atfork (void(*__prepare)(void), void(*__parent)(void), void(*__child)(void), void *dso_handle)

Define Documentation

#define ARCH_FORK ( )    INLINE_SYSCALL (fork, 0)
#define UNREGISTER_ATFORK (   dso_handle)    __unregister_atfork (dso_handle)

Definition at line 48 of file fork.h.


Function Documentation

int __register_atfork ( void(*)(void)  __prepare,
void(*)(void)  __parent,
void(*)(void)  __child,
void *  dso_handle 
)

Definition at line 26 of file register-atfork.c.

{
  struct fork_handler *new_prepare = NULL;
  struct fork_handler *new_parent = NULL;
  struct fork_handler *new_child = NULL;

  if (prepare != NULL)
    {
      new_prepare = (struct fork_handler *) malloc (sizeof (*new_prepare));
      if (new_prepare == NULL)
       goto out1;

      new_prepare->handler = prepare;
      new_prepare->dso_handle = dso_handle;
    }

  if (parent != NULL)
    {
      new_parent = (struct fork_handler *) malloc (sizeof (*new_parent));
      if (new_parent == NULL)
       goto out2;

      new_parent->handler = parent;
      new_parent->dso_handle = dso_handle;
    }

  if (child != NULL)
    {
      new_child = (struct fork_handler *) malloc (sizeof (*new_child));
      if (new_child == NULL)
       {
         free (new_parent);
       out2:
         free (new_prepare);
       out1:
         return errno;
       }

      new_child->handler = child;
      new_child->dso_handle = dso_handle;
    }

  /* Get the lock to not conflict with running forks.  */
  __libc_lock_lock (__fork_block.lock);

  /* Now that we have all the handlers allocate enqueue them.  */
  if (new_prepare != NULL)
    list_add_tail (&new_prepare->list, &__fork_block.prepare_list);
  if (new_parent != NULL)
    list_add_tail (&new_parent->list, &__fork_block.parent_list);
  if (new_child != NULL)
    list_add_tail (&new_child->list, &__fork_block.child_list);

  /* Release the lock.  */
  __libc_lock_unlock (__fork_block.lock);

  return 0;
}

Here is the caller graph for this function:

void __unregister_atfork ( void *  dso_handle)

Definition at line 26 of file unregister-atfork.c.

{
  /* Get the lock to not conflict with running forks.  */
  __libc_lock_lock (__fork_block.lock);

  list_t *runp;
  list_t *prevp;

  list_for_each_prev_safe (runp, prevp, &__fork_block.prepare_list)
    if (list_entry (runp, struct fork_handler, list)->dso_handle == dso_handle)
      list_del (runp);

  list_for_each_prev_safe (runp, prevp, &__fork_block.parent_list)
    if (list_entry (runp, struct fork_handler, list)->dso_handle == dso_handle)
      list_del (runp);

  list_for_each_prev_safe (runp, prevp, &__fork_block.child_list)
    if (list_entry (runp, struct fork_handler, list)->dso_handle == dso_handle)
      list_del (runp);

  /* Release the lock.  */
  __libc_lock_unlock (__fork_block.lock);
}