Add more tests of csqrt, lgamma, log10, sinh.
[glibc.git] / nptl / tst-atfork1.c
blob4b956e253a4bef6e2c5ce59ae7a21f8bffdd8556
1 /* Copyright (C) 2002-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <pthread.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <sys/wait.h>
27 static int val;
30 static void
31 prepare1 (void)
33 val *= 2;
36 static void
37 prepare2 (void)
39 ++val;
42 static void
43 parent1 (void)
45 val += 4;
48 static void
49 parent2 (void)
51 val *= 4;
54 static void
55 child1 (void)
57 val += 8;
60 static void
61 child2 (void)
63 val *= 8;
67 static int
68 do_test (void)
70 pid_t pid;
71 int status = 0;
73 if (pthread_atfork (prepare1, parent1, child1) != 0)
75 puts ("1st atfork failed");
76 exit (1);
78 if (pthread_atfork (prepare2, parent2, child2) != 0)
80 puts ("2nd atfork failed");
81 exit (1);
84 pid = fork ();
85 if (pid == -1)
87 puts ("fork failed");
88 exit (1);
91 if (pid != 0)
93 /* Parent. */
94 if (val != 24)
96 printf ("expected val=%d, got %d\n", 24, val);
97 exit (1);
100 if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
102 puts ("waitpid failed");
103 exit (1);
106 else
108 /* Child. */
109 if (val != 80)
111 printf ("expected val=%d, got %d\n", 80, val);
112 exit (2);
116 return status;
119 #define TEST_FUNCTION do_test ()
120 #include "../test-skeleton.c"