]>
Commit | Line | Data |
---|---|---|
01b54066 UD |
1 | /* Copyright (C) 2002 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
3 | Contributed by Roland McGrath <roland@redhat.com>, 2002. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, write to the Free | |
17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
18 | 02111-1307 USA. */ | |
19 | ||
20 | #include <errno.h> | |
21 | #include <pthread.h> | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <unistd.h> | |
25 | #include <sys/wait.h> | |
26 | ||
27 | ||
28 | static pid_t initial_pid; | |
29 | ||
30 | ||
31 | static void * | |
32 | tf2 (void *arg) | |
33 | { | |
34 | if (getppid () != initial_pid) | |
35 | { | |
36 | printf ("getppid in thread returned %ld, expected %ld\n", | |
37 | (long int) getppid (), (long int) initial_pid); | |
38 | return (void *) -1; | |
39 | } | |
40 | ||
41 | return NULL; | |
42 | } | |
43 | ||
44 | ||
45 | static void * | |
46 | tf1 (void *arg) | |
47 | { | |
48 | pid_t child = fork (); | |
49 | if (child == 0) | |
50 | { | |
51 | if (getppid () != initial_pid) | |
52 | { | |
53 | printf ("first getppid returned %ld, expected %ld\n", | |
54 | (long int) getppid (), (long int) initial_pid); | |
55 | exit (1); | |
56 | } | |
57 | ||
58 | pthread_t th2; | |
59 | if (pthread_create (&th2, NULL, tf2, NULL) != 0) | |
60 | { | |
61 | puts ("child: pthread_create failed"); | |
62 | exit (1); | |
63 | } | |
64 | ||
65 | void *result; | |
66 | if (pthread_join (th2, &result) != 0) | |
67 | { | |
68 | puts ("pthread_join failed"); | |
69 | exit (1); | |
70 | } | |
71 | ||
72 | exit (result == NULL ? 0 : 1); | |
73 | } | |
74 | else if (child == -1) | |
75 | { | |
76 | puts ("initial fork failed"); | |
77 | exit (1); | |
78 | } | |
79 | ||
80 | int status; | |
81 | if (TEMP_FAILURE_RETRY (waitpid (child, &status, 0)) != child) | |
82 | { | |
83 | printf ("waitpid failed: %m\n"); | |
84 | exit (1); | |
85 | } | |
86 | ||
87 | exit (status); | |
88 | } | |
89 | ||
90 | ||
91 | int | |
92 | main (void) | |
93 | { | |
94 | initial_pid = getpid (); | |
95 | ||
96 | pthread_t th1; | |
97 | if (pthread_create (&th1, NULL, tf1, NULL) != 0) | |
98 | { | |
99 | puts ("parent: pthread_create failed"); | |
100 | exit (1); | |
101 | } | |
102 | ||
103 | /* This call should never return. */ | |
104 | pthread_join (th1, NULL); | |
105 | ||
106 | return 1; | |
107 | } |