/* confdefs.h. */ #define PACKAGE_NAME "PostgreSQL" #define PACKAGE_TARNAME "postgresql" #define PACKAGE_VERSION "9.0.5" #define PACKAGE_STRING "PostgreSQL 9.0.5" #define PACKAGE_BUGREPORT "address@hidden" #define PG_VERSION "9.0.5" #define PG_MAJORVERSION "9.0" #define USE_INTEGER_DATETIMES 1 #define DEF_PGPORT 5432 #define DEF_PGPORT_STR "5432" #define BLCKSZ 8192 #define RELSEG_SIZE 131072 #define XLOG_BLCKSZ 8192 #define XLOG_SEG_SIZE (16 * 1024 * 1024) #define ENABLE_THREAD_SAFETY 1 #define PG_KRB_SRVNAM "postgres" #define HAVE_LIBM 1 #define HAVE_SPINLOCKS 1 #define STDC_HEADERS 1 #define HAVE_SYS_TYPES_H 1 #define HAVE_SYS_STAT_H 1 #define HAVE_STDLIB_H 1 #define HAVE_STRING_H 1 #define HAVE_MEMORY_H 1 #define HAVE_STRINGS_H 1 #define HAVE_INTTYPES_H 1 #define HAVE_STDINT_H 1 #define HAVE_UNISTD_H 1 #define HAVE_CRYPT_H 1 #define HAVE_GETOPT_H 1 #define HAVE_IFADDRS_H 1 #define HAVE_LANGINFO_H 1 #define HAVE_POLL_H 1 #define HAVE_PWD_H 1 #define HAVE_SYS_IOCTL_H 1 #define HAVE_SYS_IPC_H 1 #define HAVE_SYS_POLL_H 1 #define HAVE_SYS_RESOURCE_H 1 #define HAVE_SYS_SELECT_H 1 #define HAVE_SYS_SEM_H 1 #define HAVE_SYS_SHM_H 1 #define HAVE_SYS_SOCKET_H 1 #define HAVE_SYS_TIME_H 1 #define HAVE_SYS_UN_H 1 #define HAVE_TERMIOS_H 1 #define HAVE_UTIME_H 1 #define HAVE_WCHAR_H 1 #define HAVE_WCTYPE_H 1 #define HAVE_NET_IF_H 1 #define HAVE_NETINET_IN_H 1 #define HAVE_NETINET_TCP_H 1 #define WORDS_BIGENDIAN 1 #define USE_INLINE 1 #define HAVE_STRINGIZE 1 #define HAVE_FUNCNAME__FUNC 1 #define HAVE_STRUCT_TM_TM_ZONE 1 #define HAVE_TM_ZONE 1 #define HAVE_TZNAME 1 #define HAVE_STRUCT_SOCKADDR_UN 1 #define HAVE_UNIX_SOCKETS 1 #define HAVE_STRUCT_SOCKADDR_STORAGE 1 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 #define HAVE_STRUCT_ADDRINFO 1 #define HAVE_INTPTR_T 1 #define HAVE_UINTPTR_T 1 #define HAVE_LONG_LONG_INT 1 #define HAVE_STRUCT_OPTION 1 #define _FILE_OFFSET_BITS 64 #define SIZEOF_OFF_T 8 #define HAVE_INT_TIMEZONE /**/ #define ACCEPT_TYPE_RETURN int #define ACCEPT_TYPE_ARG1 int #define ACCEPT_TYPE_ARG2 struct sockaddr * #define ACCEPT_TYPE_ARG3 size_t #define HAVE_CBRT 1 #define HAVE_DLOPEN 1 #define HAVE_FCVT 1 #define HAVE_FDATASYNC 1 #define HAVE_GETIFADDRS 1 #define HAVE_GETRLIMIT 1 #define HAVE_MEMMOVE 1 #define HAVE_POLL 1 #define HAVE_READLINK 1 #define HAVE_SCANDIR 1 #define HAVE_SETSID 1 #define HAVE_SIGPROCMASK 1 #define HAVE_SYMLINK 1 #define HAVE_SYSCONF 1 #define HAVE_TOWLOWER 1 #define HAVE_UTIME 1 #define HAVE_UTIMES 1 #define HAVE_WAITPID 1 #define HAVE_WCSTOMBS 1 #define HAVE_FSEEKO 1 #define HAVE_FSEEKO 1 #define HAVE_POSIX_FADVISE 1 #define HAVE_DECL_POSIX_FADVISE 1 #define HAVE_DECL_FDATASYNC 1 #define HAVE_DECL_STRLCAT 0 #define HAVE_DECL_STRLCPY 0 #define HAVE_DECL_F_FULLFSYNC 0 #define HAVE_IPV6 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 #define HAVE_DECL_SNPRINTF 1 #define HAVE_DECL_VSNPRINTF 1 #define HAVE_ISINF 1 #define HAVE_CRYPT 1 #define HAVE_ERAND48 1 #define HAVE_GETOPT 1 #define HAVE_GETRUSAGE 1 #define HAVE_INET_ATON 1 #define HAVE_RANDOM 1 #define HAVE_RINT 1 #define HAVE_SRANDOM 1 #define HAVE_STRDUP 1 #define HAVE_STRERROR 1 #define HAVE_STRTOL 1 #define HAVE_STRTOUL 1 #define HAVE_UNSETENV 1 #define HAVE_GETADDRINFO 1 #define HAVE_GETOPT_LONG 1 #define HAVE_SIGSETJMP 1 #define HAVE_DECL_SYS_SIGLIST 1 #define HAVE_SYSLOG 1 #define HAVE_INT_OPTERR 1 #define HAVE_STRTOLL 1 #define HAVE_STRTOULL 1 #define HAVE_ATEXIT 1 #define HAVE_STRERROR_R 1 #define HAVE_GETPWUID_R 1 #define HAVE_GETHOSTBYNAME_R 1 #define GETPWUID_R_5ARG /**/ #define HAVE_LONG_LONG_INT_64 1 #define HAVE_LL_CONSTANTS 1 #define INT64_FORMAT "%lld" #define UINT64_FORMAT "%llu" #define SIZEOF_VOID_P 4 #define SIZEOF_SIZE_T 4 #define SIZEOF_LONG 4 #define USE_FLOAT4_BYVAL 1 #define FLOAT4PASSBYVAL true #define FLOAT8PASSBYVAL false #define ALIGNOF_SHORT 2 #define ALIGNOF_INT 4 #define ALIGNOF_LONG 4 #define ALIGNOF_LONG_LONG_INT 8 #define ALIGNOF_DOUBLE 8 #define MAXIMUM_ALIGNOF 8 #define HAVE_SIG_ATOMIC_T 1 #define HAVE_POSIX_SIGNALS /**/ #define USE_SYSV_SEMAPHORES 1 #define USE_SYSV_SHARED_MEMORY 1 #define MEMSET_LOOP_LIMIT 1024 /* end confdefs.h. */ /*------------------------------------------------------------------------- * * test_thread_funcs.c * libc thread test program * * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * $PostgreSQL: pgsql/src/test/thread/thread_test.c,v 1.8 2010/01/02 16:58:16 momjian Exp $ * * This program tests to see if your standard libc functions use * pthread_setspecific()/pthread_getspecific() to be thread-safe. * See src/port/thread.c for more details. * * This program first tests to see if each function returns a constant * memory pointer within the same thread, then, assuming it does, tests * to see if the pointers are different for different threads. If they * are, the function is thread-safe. * *------------------------------------------------------------------------- */ #if !defined(IN_CONFIGURE) && !defined(WIN32) #include "postgres.h" #else /* From src/include/c.h" */ #ifndef bool typedef char bool; #endif #ifndef true #define true ((bool) 1) #endif #ifndef false #define false ((bool) 0) #endif #endif #include #include #include #include #include #include #include #include #include /* CYGWIN requires this for MAXHOSTNAMELEN */ #ifdef __CYGWIN__ #include #endif /****************************************************************** * Windows Hacks *****************************************************************/ #ifdef WIN32 #define MAXHOSTNAMELEN 63 #include int mkstemp(char *template); int mkstemp(char *template) { FILE *foo; mktemp(template); foo = fopen(template, "rw"); if (!foo) return -1; else return (int) foo; } #endif /****************************************************************** * End Windows Hacks *****************************************************************/ /* Test for POSIX.1c 2-arg sigwait() and fail on single-arg version */ #include int sigwait(const sigset_t *set, int *sig); #if !defined(ENABLE_THREAD_SAFETY) && !defined(IN_CONFIGURE) && !(defined(WIN32)) int main(int argc, char *argv[]) { fprintf(stderr, "This PostgreSQL build does not support threads.\n"); fprintf(stderr, "Perhaps rerun 'configure' using '--enable-thread-safety'.\n"); return 1; } #else /* This must be down here because this is the code that uses threads. */ #include static void func_call_1(void); static void func_call_2(void); #ifdef WIN32 #define TEMP_FILENAME_1 "thread_test.1.XXXXXX" #define TEMP_FILENAME_2 "thread_test.2.XXXXXX" #else #define TEMP_FILENAME_1 "/tmp/thread_test.1.XXXXXX" #define TEMP_FILENAME_2 "/tmp/thread_test.2.XXXXXX" #endif static char *temp_filename_1; static char *temp_filename_2; static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER; static volatile int thread1_done = 0; static volatile int thread2_done = 0; static volatile int errno1_set = 0; static volatile int errno2_set = 0; #ifndef HAVE_STRERROR_R static char *strerror_p1; static char *strerror_p2; static bool strerror_threadsafe = false; #endif #ifndef WIN32 #ifndef HAVE_GETPWUID_R static struct passwd *passwd_p1; static struct passwd *passwd_p2; static bool getpwuid_threadsafe = false; #endif #endif #if !defined(HAVE_GETADDRINFO) && !defined(HAVE_GETHOSTBYNAME_R) static struct hostent *hostent_p1; static struct hostent *hostent_p2; static char myhostname[MAXHOSTNAMELEN]; static bool gethostbyname_threadsafe = false; #endif static bool platform_is_threadsafe = true; int main(int argc, char *argv[]) { pthread_t thread1, thread2; int fd; #ifdef WIN32 WSADATA wsaData; int err; #endif if (argc > 1) { fprintf(stderr, "Usage: %s\n", argv[0]); return 1; } #ifdef IN_CONFIGURE /* Send stdout to 'config.log' */ close(1); dup(5); #endif #ifdef WIN32 err = WSAStartup(MAKEWORD(1, 1), &wsaData); if (err != 0) { fprintf(stderr, "Cannot start the network subsystem - %d**\nexiting\n", err); exit(1); } #endif /* Make temp filenames, might not have strdup() */ temp_filename_1 = malloc(strlen(TEMP_FILENAME_1) + 1); strcpy(temp_filename_1, TEMP_FILENAME_1); fd = mkstemp(temp_filename_1); close(fd); temp_filename_2 = malloc(strlen(TEMP_FILENAME_2) + 1); strcpy(temp_filename_2, TEMP_FILENAME_2); fd = mkstemp(temp_filename_2); close(fd); #if !defined(HAVE_GETADDRINFO) && !defined(HAVE_GETHOSTBYNAME_R) if (gethostname(myhostname, MAXHOSTNAMELEN) != 0) { fprintf(stderr, "Cannot get local hostname **\nexiting\n"); exit(1); } #endif /* Hold lock until we are ready for the child threads to exit. */ pthread_mutex_lock(&init_mutex); pthread_create(&thread1, NULL, (void *(*) (void *)) func_call_1, NULL); pthread_create(&thread2, NULL, (void *(*) (void *)) func_call_2, NULL); while (thread1_done == 0 || thread2_done == 0) sched_yield(); /* if this is a portability problem, remove it */ #ifdef WIN32 printf("Your GetLastError() is thread-safe.\n"); #else printf("Your errno is thread-safe.\n"); #endif #ifndef HAVE_STRERROR_R if (strerror_p1 != strerror_p2) strerror_threadsafe = true; #endif #ifndef WIN32 #ifndef HAVE_GETPWUID_R if (passwd_p1 != passwd_p2) getpwuid_threadsafe = true; #endif #endif #if !defined(HAVE_GETADDRINFO) && !defined(HAVE_GETHOSTBYNAME_R) if (hostent_p1 != hostent_p2) gethostbyname_threadsafe = true; #endif pthread_mutex_unlock(&init_mutex); /* let children exit */ pthread_join(thread1, NULL); /* clean up children */ pthread_join(thread2, NULL); #ifdef HAVE_STRERROR_R printf("Your system has sterror_r(); it does not need strerror().\n"); #else printf("Your system uses strerror() which is "); if (strerror_threadsafe) printf("thread-safe.\n"); else { printf("not thread-safe. **\n"); platform_is_threadsafe = false; } #endif #ifndef WIN32 #ifdef HAVE_GETPWUID_R printf("Your system has getpwuid_r(); it does not need getpwuid().\n"); #else printf("Your system uses getpwuid() which is "); if (getpwuid_threadsafe) printf("thread-safe.\n"); else { printf("not thread-safe. **\n"); platform_is_threadsafe = false; } #endif #else printf("getpwuid_r()/getpwuid() are not applicable to Win32 platforms.\n"); #endif #ifdef HAVE_GETADDRINFO printf("Your system has getaddrinfo(); it does not need gethostbyname()\n" " or gethostbyname_r().\n"); #else #ifdef HAVE_GETHOSTBYNAME_R printf("Your system has gethostbyname_r(); it does not need gethostbyname().\n"); #else printf("Your system uses gethostbyname which is "); if (gethostbyname_threadsafe) printf("thread-safe.\n"); else { printf("not thread-safe. **\n"); platform_is_threadsafe = false; } #endif #endif if (platform_is_threadsafe) { printf("\nYour platform is thread-safe.\n"); return 0; } else { printf("\n** YOUR PLATFORM IS NOT THREAD-SAFE. **\n"); return 1; } } static void func_call_1(void) { #if !defined(HAVE_GETPWUID_R) || \ (!defined(HAVE_GETADDRINFO) && \ !defined(HAVE_GETHOSTBYNAME_R)) void *p; #endif #ifdef WIN32 HANDLE h1; HANDLE h2; #endif unlink(temp_filename_1); /* create, then try to fail on exclusive create open */ #ifdef WIN32 h1 = CreateFile(temp_filename_1, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL); h2 = CreateFile(temp_filename_1, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL); if (h1 == INVALID_HANDLE_VALUE || GetLastError() != ERROR_FILE_EXISTS) #else if (open(temp_filename_1, O_RDWR | O_CREAT, 0600) < 0 || open(temp_filename_1, O_RDWR | O_CREAT | O_EXCL, 0600) >= 0) #endif { #ifdef WIN32 fprintf(stderr, "Could not create file in current directory or\n"); fprintf(stderr, "Could not generate failure for create file in current directory **\nexiting\n"); #else fprintf(stderr, "Could not create file in /tmp or\n"); fprintf(stderr, "Could not generate failure for create file in /tmp **\nexiting\n"); #endif exit(1); } /* * Wait for other thread to set errno. We can't use thread-specific * locking here because it might affect errno. */ errno1_set = 1; while (errno2_set == 0) sched_yield(); #ifdef WIN32 if (GetLastError() != ERROR_FILE_EXISTS) #else if (errno != EEXIST) #endif { #ifdef WIN32 fprintf(stderr, "GetLastError() not thread-safe **\nexiting\n"); #else fprintf(stderr, "errno not thread-safe **\nexiting\n"); #endif unlink(temp_filename_1); exit(1); } unlink(temp_filename_1); #ifndef HAVE_STRERROR_R strerror_p1 = strerror(EACCES); /* * If strerror() uses sys_errlist, the pointer might change for different * errno values, so we don't check to see if it varies within the thread. */ #endif #ifndef WIN32 #ifndef HAVE_GETPWUID_R passwd_p1 = getpwuid(0); p = getpwuid(1); if (passwd_p1 != p) { printf("Your getpwuid() changes the static memory area between calls\n"); passwd_p1 = NULL; /* force thread-safe failure report */ } #endif #endif #if !defined(HAVE_GETADDRINFO) && !defined(HAVE_GETHOSTBYNAME_R) /* threads do this in opposite order */ hostent_p1 = gethostbyname(myhostname); p = gethostbyname("localhost"); if (hostent_p1 != p) { printf("Your gethostbyname() changes the static memory area between calls\n"); hostent_p1 = NULL; /* force thread-safe failure report */ } #endif thread1_done = 1; pthread_mutex_lock(&init_mutex); /* wait for parent to test */ pthread_mutex_unlock(&init_mutex); } static void func_call_2(void) { #if !defined(HAVE_GETPWUID_R) || \ (!defined(HAVE_GETADDRINFO) && \ !defined(HAVE_GETHOSTBYNAME_R)) void *p; #endif unlink(temp_filename_2); /* open non-existant file */ #ifdef WIN32 CreateFile(temp_filename_2, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (GetLastError() != ERROR_FILE_NOT_FOUND) #else if (open(temp_filename_2, O_RDONLY, 0600) >= 0) #endif { fprintf(stderr, "Read-only open succeeded without create **\nexiting\n"); exit(1); } /* * Wait for other thread to set errno. We can't use thread-specific * locking here because it might affect errno. */ errno2_set = 1; while (errno1_set == 0) sched_yield(); #ifdef WIN32 if (GetLastError() != ENOENT) #else if (errno != ENOENT) #endif { #ifdef WIN32 fprintf(stderr, "GetLastError() not thread-safe **\nexiting\n"); #else fprintf(stderr, "errno not thread-safe **\nexiting\n"); #endif unlink(temp_filename_2); exit(1); } unlink(temp_filename_2); #ifndef HAVE_STRERROR_R strerror_p2 = strerror(EINVAL); /* * If strerror() uses sys_errlist, the pointer might change for different * errno values, so we don't check to see if it varies within the thread. */ #endif #ifndef WIN32 #ifndef HAVE_GETPWUID_R passwd_p2 = getpwuid(2); p = getpwuid(3); if (passwd_p2 != p) { printf("Your getpwuid() changes the static memory area between calls\n"); passwd_p2 = NULL; /* force thread-safe failure report */ } #endif #endif #if !defined(HAVE_GETADDRINFO) && !defined(HAVE_GETHOSTBYNAME_R) /* threads do this in opposite order */ hostent_p2 = gethostbyname("localhost"); p = gethostbyname(myhostname); if (hostent_p2 != p) { printf("Your gethostbyname() changes the static memory area between calls\n"); hostent_p2 = NULL; /* force thread-safe failure report */ } #endif thread2_done = 1; pthread_mutex_lock(&init_mutex); /* wait for parent to test */ pthread_mutex_unlock(&init_mutex); } #endif /* !ENABLE_THREAD_SAFETY && !IN_CONFIGURE */