Back to index

glibc  2.9
Defines | Functions | Variables
tst-atfork1.c File Reference
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

static void prepare1 (void)
static void prepare2 (void)
static void parent1 (void)
static void parent2 (void)
static void child1 (void)
static void child2 (void)
static int do_test (void)

Variables

static int val

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 120 of file tst-atfork1.c.


Function Documentation

static void child1 ( void  ) [static]

Definition at line 56 of file tst-atfork1.c.

{
  val += 8;
}

Here is the caller graph for this function:

static void child2 ( void  ) [static]

Definition at line 62 of file tst-atfork1.c.

{
  val *= 8;
}

Here is the caller graph for this function:

static int do_test ( void  ) [static]

Definition at line 69 of file tst-atfork1.c.

{
  pid_t pid;
  int status = 0;

  if (pthread_atfork (prepare1, parent1, child1) != 0)
    {
      puts ("1st atfork failed");
      exit (1);
    }
  if (pthread_atfork (prepare2, parent2, child2) != 0)
    {
      puts ("2nd atfork failed");
      exit (1);
    }

  pid = fork ();
  if (pid == -1)
    {
      puts ("fork failed");
      exit (1);
    }

  if (pid != 0)
    {
      /* Parent.  */
      if (val != 24)
       {
         printf ("expected val=%d, got %d\n", 24, val);
         exit (1);
       }

      if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
       {
         puts ("waitpid failed");
         exit (1);
       }
    }
  else
    {
      /* Child.  */
      if (val != 80)
       {
         printf ("expected val=%d, got %d\n", 80, val);
         exit (2);
       }
    }

  return status;
}

Here is the call graph for this function:

static void parent1 ( void  ) [static]

Definition at line 44 of file tst-atfork1.c.

{
  val += 4;
}

Here is the caller graph for this function:

static void parent2 ( void  ) [static]

Definition at line 50 of file tst-atfork1.c.

{
  val *= 4;
}

Here is the caller graph for this function:

static void prepare1 ( void  ) [static]

Definition at line 32 of file tst-atfork1.c.

{
  val *= 2;
}

Here is the caller graph for this function:

static void prepare2 ( void  ) [static]

Definition at line 38 of file tst-atfork1.c.

{
  ++val;
}

Here is the caller graph for this function:


Variable Documentation

int val [static]

Definition at line 28 of file tst-atfork1.c.