Back to index

glibc  2.9
tst-mallocfork.c
Go to the documentation of this file.
00001 /* Derived from the test case in
00002    http://sourceware.org/bugzilla/show_bug.cgi?id=838.  */
00003 #include <assert.h>
00004 #include <errno.h>
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <unistd.h>
00008 #include <sys/types.h>
00009 #include <sys/wait.h>
00010 
00011 static void
00012 sig_handler (int signum)
00013 {
00014   pid_t child = fork ();
00015   if (child == 0)
00016     exit (0);
00017   TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
00018 }
00019 
00020 static int
00021 do_test (void)
00022 {
00023   pid_t parent = getpid ();
00024 
00025   struct sigaction action = { .sa_handler = sig_handler };
00026   sigemptyset (&action.sa_mask);
00027 
00028   malloc (sizeof (int));
00029 
00030   if (sigaction (SIGALRM, &action, NULL) != 0)
00031     {
00032       puts ("sigaction failed");
00033       return 1;
00034     }
00035 
00036   /* Create a child that sends the signal to be caught.  */
00037   pid_t child = fork ();
00038   if (child == 0)
00039     {
00040       if (kill (parent, SIGALRM) == -1)
00041        perror ("kill");
00042       exit (0);
00043     }
00044 
00045   TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
00046 
00047   return 0;
00048 }
00049 
00050 #define TEST_FUNCTION do_test ()
00051 #include "../test-skeleton.c"