6
6
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
- * $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.26 2004/04/27 17:22:41 momjian Exp $
9
+ * $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.27 2004/04/27 18:36:31 momjian Exp $
10
10
*
11
11
* This program tests to see if your standard libc functions use
12
12
* pthread_setspecific()/pthread_getspecific() to be thread-safe.
@@ -49,6 +49,12 @@ main(int argc, char *argv[])
49
49
void func_call_1 (void );
50
50
void func_call_2 (void );
51
51
52
+ #define TEMP_FILENAME_1 "/tmp/thread_test.1.XXXXX"
53
+ #define TEMP_FILENAME_2 "/tmp/thread_test.2.XXXXX"
54
+
55
+ char * temp_filename_1 ;
56
+ char * temp_filename_2 ;
57
+
52
58
pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER ;
53
59
54
60
volatile int thread1_done = 0 ;
@@ -90,6 +96,14 @@ main(int argc, char *argv[])
90
96
return 1 ;
91
97
}
92
98
99
+ /* Make temp filenames, might not have strdup() */
100
+ temp_filename_1 = malloc (strlen (TEMP_FILENAME_1 ) + 1 );
101
+ strcpy (temp_filename_1 , TEMP_FILENAME_1 );
102
+ mktemp (temp_filename_1 );
103
+ temp_filename_2 = malloc (strlen (TEMP_FILENAME_2 ) + 1 );
104
+ strcpy (temp_filename_2 , TEMP_FILENAME_2 );
105
+ mktemp (temp_filename_2 );
106
+
93
107
#if !defined(HAVE_GETADDRINFO ) && !defined(HAVE_GETHOSTBYNAME_R )
94
108
if (gethostname (myhostname , MAXHOSTNAMELEN ) != 0 )
95
109
{
@@ -195,10 +209,10 @@ func_call_1(void)
195
209
void * p ;
196
210
#endif
197
211
198
- unlink ("/tmp/thread_test.1" );
212
+ unlink (temp_filename_1 );
199
213
/* create, then try to fail on exclusive create open */
200
- if (open ("/tmp/thread_test.1" , O_RDWR | O_CREAT , 0600 ) < 0 ||
201
- open ("/tmp/thread_test.1" , O_RDWR | O_CREAT | O_EXCL , 0600 ) >= 0 )
214
+ if (open (temp_filename_1 , O_RDWR | O_CREAT , 0600 ) < 0 ||
215
+ open (temp_filename_1 , O_RDWR | O_CREAT | O_EXCL , 0600 ) >= 0 )
202
216
{
203
217
fprintf (stderr , "Could not create file in /tmp or\n" );
204
218
fprintf (stderr , "Could not generate failure for create file in /tmp **\nexiting\n" );
@@ -215,10 +229,10 @@ func_call_1(void)
215
229
if (errno != EEXIST )
216
230
{
217
231
fprintf (stderr , "errno not thread-safe **\nexiting\n" );
218
- unlink ("/tmp/thread_test.1" );
232
+ unlink (temp_filename_1 );
219
233
exit (1 );
220
234
}
221
- unlink ("/tmp/thread_test.1" );
235
+ unlink (temp_filename_1 );
222
236
223
237
#ifndef HAVE_STRERROR_R
224
238
strerror_p1 = strerror (EACCES );
@@ -266,9 +280,9 @@ func_call_2(void)
266
280
void * p ;
267
281
#endif
268
282
269
- unlink ("/tmp/thread_test.2" );
283
+ unlink (temp_filename_2 );
270
284
/* open non-existant file */
271
- if (open ("/tmp/thread_test.2" , O_RDONLY , 0600 ) >= 0 )
285
+ if (open (temp_filename_2 , O_RDONLY , 0600 ) >= 0 )
272
286
{
273
287
fprintf (stderr , "Read-only open succeeded without create **\nexiting\n" );
274
288
exit (1 );
@@ -284,10 +298,10 @@ func_call_2(void)
284
298
if (errno != ENOENT )
285
299
{
286
300
fprintf (stderr , "errno not thread-safe **\nexiting\n" );
287
- unlink ("/tmp/thread_test.A" );
301
+ unlink (temp_filename_2 );
288
302
exit (1 );
289
303
}
290
- unlink ("/tmp/thread_test.2" );
304
+ unlink (temp_filename_2 );
291
305
292
306
#ifndef HAVE_STRERROR_R
293
307
strerror_p2 = strerror (EINVAL );
0 commit comments