stdlib/tst-secure-getenv.c (alternative_main): Only warn on SGID failures
[glibc.git] / nptl / tst-basic6.c
blob91e5fe2c7ce4fc6c18e0e7038ca1a546961384fc
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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 <pthread.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
26 static char *p;
28 static pthread_barrier_t b;
29 #define BT \
30 e = pthread_barrier_wait (&b); \
31 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) \
32 { \
33 puts ("barrier_wait failed"); \
34 exit (1); \
38 static void *
39 tf (void *a)
41 int e;
43 BT;
45 char *p2 = getcwd (NULL, 0);
46 if (p2 == NULL)
48 puts ("2nd getcwd failed");
49 exit (1);
52 if (strcmp (p, p2) != 0)
54 printf ("initial cwd mismatch: \"%s\" vs \"%s\"\n", p, p2);
55 exit (1);
58 free (p);
59 free (p2);
61 if (chdir ("..") != 0)
63 puts ("chdir failed");
64 exit (1);
67 p = getcwd (NULL, 0);
68 if (p == NULL)
70 puts ("getcwd failed");
71 exit (1);
74 return a;
78 int
79 do_test (void)
81 if (pthread_barrier_init (&b, NULL, 2) != 0)
83 puts ("barrier_init failed");
84 exit (1);
87 pthread_t th;
88 if (pthread_create (&th, NULL, tf, NULL) != 0)
90 puts ("create failed");
91 exit (1);
94 p = getcwd (NULL, 0);
95 if (p == NULL)
97 puts ("getcwd failed");
98 exit (1);
101 int e;
104 if (pthread_join (th, NULL) != 0)
106 puts ("join failed");
107 exit (1);
110 char *p2 = getcwd (NULL, 0);
111 if (p2 == NULL)
113 puts ("2nd getcwd failed");
114 exit (1);
117 if (strcmp (p, p2) != 0)
119 printf ("cwd after chdir mismatch: \"%s\" vs \"%s\"\n", p, p2);
120 exit (1);
123 free (p);
124 free (p2);
126 return 0;
130 #define TEST_FUNCTION do_test ()
131 #include "../test-skeleton.c"