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

Commitdb9a957

Browse files
committed
Add test for thread-safe errno to thread test program.
1 parent4f0d027 commitdb9a957

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

‎src/tools/thread/thread_test.c

Lines changed: 50 additions & 2 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.7 2004/02/11 21:44:06 momjian Exp $
9+
*$PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.8 2004/03/27 23:02:44 momjian Exp $
1010
*
1111
*This program tests to see if your standard libc functions use
1212
*pthread_setspecific()/pthread_getspecific() to be thread-safe.
@@ -29,10 +29,15 @@
2929
#include<pwd.h>
3030
#include<string.h>
3131
#include<errno.h>
32+
#include<fcntl.h>
33+
#include<errno.h>
3234

3335
voidfunc_call_1(void);
3436
voidfunc_call_2(void);
3537

38+
interrno1_set=0;
39+
interrno2_set=0;
40+
3641
char*strerror_p1;
3742
char*strerror_p2;
3843

@@ -42,6 +47,9 @@ struct passwd *passwd_p2;
4247
structhostent*hostent_p1;
4348
structhostent*hostent_p2;
4449

50+
pthread_mutex_tsinglethread_lock1=PTHREAD_MUTEX_INITIALIZER;
51+
pthread_mutex_tsinglethread_lock2=PTHREAD_MUTEX_INITIALIZER;
52+
4553
intmain(intargc,char*argv[])
4654
{
4755
pthread_tthread1,
@@ -84,7 +92,30 @@ defines to your template/$port file before compiling this program.\n\n"
8492

8593
voidfunc_call_1(void) {
8694
void*p;
87-
95+
96+
if (open("/tmp/thread_test.1",O_RDWR |O_CREAT,0600)<0)
97+
{
98+
fprintf(stderr,"Could not create file in /tmp, exiting\n");
99+
exit(1);
100+
}
101+
102+
if (open("/tmp/thread_test.1",O_RDWR |O_CREAT |O_EXCL,0600) >=0)
103+
{
104+
fprintf(stderr,"Could not generate failure for create file in /tmp, exiting\n");
105+
exit(1);
106+
}
107+
/* wait for other thread to set errno */
108+
errno1_set=1;
109+
while (errno2_set==0)
110+
/* loop */;
111+
if (errno!=EEXIST)
112+
{
113+
fprintf(stderr,"errno not thread-safe; exiting\n");
114+
unlink("/tmp/thread_test.1");
115+
exit(1);
116+
}
117+
unlink("/tmp/thread_test.1");
118+
88119
strerror_p1=strerror(EACCES);
89120
/*
90121
*If strerror() uses sys_errlist, the pointer might change for different
@@ -112,6 +143,23 @@ void func_call_1(void) {
112143
voidfunc_call_2(void) {
113144
void*p;
114145

146+
unlink("/tmp/thread_test.2");
147+
if (open("/tmp/thread_test.2",O_RDONLY,0600) >=0)
148+
{
149+
fprintf(stderr,"Read-only open succeeded without create, exiting\n");
150+
exit(1);
151+
}
152+
/* wait for other thread to set errno */
153+
errno2_set=1;
154+
while (errno1_set==0)
155+
/* loop */;
156+
if (errno!=ENOENT)
157+
{
158+
fprintf(stderr,"errno not thread-safe; exiting\n");
159+
unlink("/tmp/thread_test.A");
160+
exit(1);
161+
}
162+
115163
strerror_p2=strerror(EINVAL);
116164
/*
117165
*If strerror() uses sys_errlist, the pointer might change for different

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp