66 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77 * Portions Copyright (c) 1994, Regents of the University of California
88 *
9- *$PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.26 2004/04/2717:22:41 momjian Exp $
9+ *$PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.27 2004/04/2718:36:31 momjian Exp $
1010 *
1111 *This program tests to see if your standard libc functions use
1212 *pthread_setspecific()/pthread_getspecific() to be thread-safe.
@@ -49,6 +49,12 @@ main(int argc, char *argv[])
4949void func_call_1 (void );
5050void func_call_2 (void );
5151
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+
5258pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER ;
5359
5460volatile int thread1_done = 0 ;
@@ -90,6 +96,14 @@ main(int argc, char *argv[])
9096return 1 ;
9197}
9298
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+
93107#if !defined(HAVE_GETADDRINFO )&& !defined(HAVE_GETHOSTBYNAME_R )
94108if (gethostname (myhostname ,MAXHOSTNAMELEN )!= 0 )
95109{
@@ -195,10 +209,10 @@ func_call_1(void)
195209void * p ;
196210#endif
197211
198- unlink ("/tmp/thread_test.1" );
212+ unlink (temp_filename_1 );
199213/* 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 )
202216{
203217fprintf (stderr ,"Could not create file in /tmp or\n" );
204218fprintf (stderr ,"Could not generate failure for create file in /tmp **\nexiting\n" );
@@ -215,10 +229,10 @@ func_call_1(void)
215229if (errno != EEXIST )
216230{
217231fprintf (stderr ,"errno not thread-safe **\nexiting\n" );
218- unlink ("/tmp/thread_test.1" );
232+ unlink (temp_filename_1 );
219233exit (1 );
220234}
221- unlink ("/tmp/thread_test.1" );
235+ unlink (temp_filename_1 );
222236
223237#ifndef HAVE_STRERROR_R
224238strerror_p1 = strerror (EACCES );
@@ -266,9 +280,9 @@ func_call_2(void)
266280void * p ;
267281#endif
268282
269- unlink ("/tmp/thread_test.2" );
283+ unlink (temp_filename_2 );
270284/* 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 )
272286{
273287fprintf (stderr ,"Read-only open succeeded without create **\nexiting\n" );
274288exit (1 );
@@ -284,10 +298,10 @@ func_call_2(void)
284298if (errno != ENOENT )
285299{
286300fprintf (stderr ,"errno not thread-safe **\nexiting\n" );
287- unlink ("/tmp/thread_test.A" );
301+ unlink (temp_filename_2 );
288302exit (1 );
289303}
290- unlink ("/tmp/thread_test.2" );
304+ unlink (temp_filename_2 );
291305
292306#ifndef HAVE_STRERROR_R
293307strerror_p2 = strerror (EINVAL );