* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.7 2004/02/11 21:44:06 momjian Exp $
+ * $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.8 2004/03/27 23:02:44 momjian Exp $
*
* This program tests to see if your standard libc functions use
* pthread_setspecific()/pthread_getspecific() to be thread-safe.
#include <pwd.h>
#include <string.h>
#include <errno.h>
+#include <fcntl.h>
+#include <errno.h>
void func_call_1(void);
void func_call_2(void);
+int errno1_set = 0;
+int errno2_set = 0;
+
char *strerror_p1;
char *strerror_p2;
struct hostent *hostent_p1;
struct hostent *hostent_p2;
+pthread_mutex_t singlethread_lock1 = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t singlethread_lock2 = PTHREAD_MUTEX_INITIALIZER;
+
int main(int argc, char *argv[])
{
pthread_t thread1,
void func_call_1(void) {
void *p;
-
+
+ if (open("/tmp/thread_test.1", O_RDWR | O_CREAT, 0600) < 0)
+ {
+ fprintf(stderr, "Could not create file in /tmp, exiting\n");
+ exit(1);
+ }
+
+ if (open("/tmp/thread_test.1", O_RDWR | O_CREAT | O_EXCL, 0600) >= 0)
+ {
+ fprintf(stderr, "Could not generate failure for create file in /tmp, exiting\n");
+ exit(1);
+ }
+ /* wait for other thread to set errno */
+ errno1_set = 1;
+ while (errno2_set == 0)
+ /* loop */;
+ if (errno != EEXIST)
+ {
+ fprintf(stderr, "errno not thread-safe; exiting\n");
+ unlink("/tmp/thread_test.1");
+ exit(1);
+ }
+ unlink("/tmp/thread_test.1");
+
strerror_p1 = strerror(EACCES);
/*
* If strerror() uses sys_errlist, the pointer might change for different
void func_call_2(void) {
void *p;
+ unlink("/tmp/thread_test.2");
+ if (open("/tmp/thread_test.2", O_RDONLY, 0600) >= 0)
+ {
+ fprintf(stderr, "Read-only open succeeded without create, exiting\n");
+ exit(1);
+ }
+ /* wait for other thread to set errno */
+ errno2_set = 1;
+ while (errno1_set == 0)
+ /* loop */;
+ if (errno != ENOENT)
+ {
+ fprintf(stderr, "errno not thread-safe; exiting\n");
+ unlink("/tmp/thread_test.A");
+ exit(1);
+ }
+
strerror_p2 = strerror(EINVAL);
/*
* If strerror() uses sys_errlist, the pointer might change for different