Skip to content

Commit 53b5455

Browse files
committed
Improve thread test program to show if non-*_r functions are even called.
1 parent 37fa3b6 commit 53b5455

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

src/tools/thread/thread_test.c

Lines changed: 76 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.16 2004/04/06 13:55:17 momjian Exp $
9+
* $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.17 2004/04/21 20:51:54 momjian Exp $
1010
*
1111
* This program tests to see if your standard libc functions use
1212
* pthread_setspecific()/pthread_getspecific() to be thread-safe.
@@ -32,6 +32,8 @@
3232
#include <fcntl.h>
3333
#include <errno.h>
3434

35+
#include "postgres.h"
36+
3537
void func_call_1(void);
3638
void func_call_2(void);
3739

@@ -52,6 +54,11 @@ struct passwd *passwd_p2;
5254
struct hostent *hostent_p1;
5355
struct hostent *hostent_p2;
5456

57+
bool gethostbyname_threadsafe;
58+
bool getpwuid_threadsafe;
59+
bool strerror_threadsafe;
60+
bool platform_is_threadsafe = true;
61+
5562
pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
5663

5764
int main(int argc, char *argv[])
@@ -90,26 +97,93 @@ defines to your template/$port file before compiling this program.\n\n"
9097
printf("Add this to your template/$port file:\n\n");
9198

9299
if (strerror_p1 != strerror_p2)
100+
{
93101
printf("STRERROR_THREADSAFE=yes\n");
102+
strerror_threadsafe = true;
103+
}
94104
else
105+
{
95106
printf("STRERROR_THREADSAFE=no\n");
107+
strerror_threadsafe = false;
108+
}
96109

97110
if (passwd_p1 != passwd_p2)
111+
{
98112
printf("GETPWUID_THREADSAFE=yes\n");
113+
getpwuid_threadsafe = true;
114+
}
99115
else
116+
{
100117
printf("GETPWUID_THREADSAFE=no\n");
118+
getpwuid_threadsafe = false;
119+
}
101120

102121
if (hostent_p1 != hostent_p2)
122+
{
103123
printf("GETHOSTBYNAME_THREADSAFE=yes\n");
124+
gethostbyname_threadsafe = true;
125+
}
104126
else
127+
{
105128
printf("GETHOSTBYNAME_THREADSAFE=no\n");
129+
gethostbyname_threadsafe = false;
130+
}
106131

107132
pthread_mutex_unlock(&init_mutex); /* let children exit */
108133

109134
pthread_join(thread1, NULL); /* clean up children */
110135
pthread_join(thread2, NULL);
111136

112-
return 0;
137+
printf("\n");
138+
139+
#ifdef HAVE_STRERROR_R
140+
printf("Your system has sterror_r(), so it doesn't use strerror().\n");
141+
#else
142+
printf("Your system uses strerror().\n");
143+
if (!strerror_threadsafe)
144+
{
145+
platform_is_threadsafe = false;
146+
printf("That function is not thread-safe\n");
147+
}
148+
#endif
149+
150+
#ifdef HAVE_GETPWUID_R
151+
printf("Your system has getpwuid_r(), so it doesn't use getpwuid().\n");
152+
#else
153+
printf("Your system uses getpwuid().\n");
154+
if (!getpwuid_threadsafe)
155+
{
156+
platform_is_threadsafe = false;
157+
printf("That function is not thread-safe\n");
158+
}
159+
#endif
160+
161+
#ifdef HAVE_GETADDRINFO
162+
printf("Your system has getaddrinfo(), so it doesn't use gethostbyname()\n"
163+
"or gethostbyname_r().\n");
164+
#else
165+
#ifdef HAVE_GETHOSTBYNAME_R
166+
printf("Your system has gethostbyname_r(), so it doesn't use gethostbyname().\n");
167+
#else
168+
printf("Your system uses gethostbyname().\n");
169+
if (!gethostbyname_threadsafe)
170+
{
171+
platform_is_threadsafe = false;
172+
printf("That function is not thread-safe\n");
173+
}
174+
#endif
175+
#endif
176+
177+
if (!platform_is_threadsafe)
178+
{
179+
printf("\n** YOUR PLATFORM IS NOT THREADSAFE **\n");
180+
return 1;
181+
}
182+
else
183+
{
184+
printf("\nYOUR PLATFORM IS THREADSAFE\n");
185+
return 0;
186+
}
113187
}
114188

115189
void func_call_1(void) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy