Blame malloc/tst-mallocfork.c

Packit 6c4009
/* Derived from the test case in
Packit 6c4009
   https://sourceware.org/bugzilla/show_bug.cgi?id=838.  */
Packit 6c4009
#include <assert.h>
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <sys/types.h>
Packit 6c4009
#include <sys/wait.h>
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
sig_handler (int signum)
Packit 6c4009
{
Packit 6c4009
  pid_t child = fork ();
Packit 6c4009
  if (child == 0)
Packit 6c4009
    exit (0);
Packit 6c4009
  TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  pid_t parent = getpid ();
Packit 6c4009
Packit 6c4009
  struct sigaction action = { .sa_handler = sig_handler };
Packit 6c4009
  sigemptyset (&action.sa_mask);
Packit 6c4009
Packit 6c4009
  malloc (sizeof (int));
Packit 6c4009
Packit 6c4009
  if (sigaction (SIGALRM, &action, NULL) != 0)
Packit 6c4009
    {
Packit 6c4009
      puts ("sigaction failed");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Create a child that sends the signal to be caught.  */
Packit 6c4009
  pid_t child = fork ();
Packit 6c4009
  if (child == 0)
Packit 6c4009
    {
Packit 6c4009
      if (kill (parent, SIGALRM) == -1)
Packit 6c4009
	perror ("kill");
Packit 6c4009
      exit (0);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"