Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf687c7e

Browse files
committed
Use mktemp for temporary file names, per suggestion from Peter.
1 parentb498b79 commitf687c7e

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

‎src/tools/thread/thread_test.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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[])
4949
voidfunc_call_1(void);
5050
voidfunc_call_2(void);
5151

52+
#defineTEMP_FILENAME_1"/tmp/thread_test.1.XXXXX"
53+
#defineTEMP_FILENAME_2"/tmp/thread_test.2.XXXXX"
54+
55+
char*temp_filename_1;
56+
char*temp_filename_2;
57+
5258
pthread_mutex_tinit_mutex=PTHREAD_MUTEX_INITIALIZER;
5359

5460
volatileintthread1_done=0;
@@ -90,6 +96,14 @@ main(int argc, char *argv[])
9096
return1;
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)
94108
if (gethostname(myhostname,MAXHOSTNAMELEN)!=0)
95109
{
@@ -195,10 +209,10 @@ func_call_1(void)
195209
void*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
{
203217
fprintf(stderr,"Could not create file in /tmp or\n");
204218
fprintf(stderr,"Could not generate failure for create file in /tmp **\nexiting\n");
@@ -215,10 +229,10 @@ func_call_1(void)
215229
if (errno!=EEXIST)
216230
{
217231
fprintf(stderr,"errno not thread-safe **\nexiting\n");
218-
unlink("/tmp/thread_test.1");
232+
unlink(temp_filename_1);
219233
exit(1);
220234
}
221-
unlink("/tmp/thread_test.1");
235+
unlink(temp_filename_1);
222236

223237
#ifndefHAVE_STRERROR_R
224238
strerror_p1=strerror(EACCES);
@@ -266,9 +280,9 @@ func_call_2(void)
266280
void*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
{
273287
fprintf(stderr,"Read-only open succeeded without create **\nexiting\n");
274288
exit(1);
@@ -284,10 +298,10 @@ func_call_2(void)
284298
if (errno!=ENOENT)
285299
{
286300
fprintf(stderr,"errno not thread-safe **\nexiting\n");
287-
unlink("/tmp/thread_test.A");
301+
unlink(temp_filename_2);
288302
exit(1);
289303
}
290-
unlink("/tmp/thread_test.2");
304+
unlink(temp_filename_2);
291305

292306
#ifndefHAVE_STRERROR_R
293307
strerror_p2=strerror(EINVAL);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp