]> git.ipfire.org Git - thirdparty/glibc.git/blame - malloc/tst-mallocfork.c
Sync scratch_buffer with gnulib
[thirdparty/glibc.git] / malloc / tst-mallocfork.c
CommitLineData
7dac9f3d
UD
1/* Derived from the test case in
2 http://sourceware.org/bugzilla/show_bug.cgi?id=838. */
3#include <assert.h>
4#include <errno.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <unistd.h>
8#include <sys/types.h>
9#include <sys/wait.h>
10
11static void
12sig_handler (int signum)
13{
14 pid_t child = fork ();
15 if (child == 0)
16 exit (0);
17 TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
18}
19
20static int
21do_test (void)
22{
23 pid_t parent = getpid ();
24
bd7b22b2 25 struct sigaction action = { .sa_handler = sig_handler };
7dac9f3d 26 sigemptyset (&action.sa_mask);
7dac9f3d
UD
27
28 malloc (sizeof (int));
29
30 if (sigaction (SIGALRM, &action, NULL) != 0)
31 {
32 puts ("sigaction failed");
33 return 1;
34 }
35
36 /* Create a child that sends the signal to be caught. */
37 pid_t child = fork ();
38 if (child == 0)
39 {
40 if (kill (parent, SIGALRM) == -1)
41 perror ("kill");
42 exit (0);
43 }
44
45 TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
46
47 return 0;
48}
49
50#define TEST_FUNCTION do_test ()
51#include "../test-skeleton.c"