#
# Pthreads
#
+# For each platform, we need to know about any special compile and link
+# libraries, and whether the normal C function names are thread-safe.
+#
+NEED_REENTRANT_FUNC_NAMES=no
if test "$with_threads" = yes; then
echo "$as_me:$LINENO: checking for ANSI C header files" >&5
echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
case $host_os in
netbsd*|bsdi*)
# these require no special flags or libraries
+ NEED_REENTRANT_FUNC_NAMES=no
+ ;;
+ freebsd2*|freebsd3*|freebsd4*)
+ THREAD_CFLAGS="-pthread"
+ NEED_REENTRANT_FUNC_NAMES=yes
;;
- freebsd2*|freebsd3*|freebsd4*) THREAD_CFLAGS="-pthread" ;;
freebsd*)
THREAD_LIBS="-lc_r"
+ NEED_REENTRANT_FUNC_NAMES=yes
;;
linux*) THREAD_CFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
THREAD_LIBS="-lpthread"
+ NEED_REENTRANT_FUNC_NAMES=yes
;;
*)
# other operating systems might fail because they have pthread.h but need
#
# Check for re-entrant versions of certain functions
#
-# Include special flags if required
+# Include special flags if threads are enabled _and_ if required for
+# threading on this platform. Some platforms have *_r functions but
+# their natively named funcs are threadsafe, and should be used instead.
+#
+# One trick here is that if the don't call AC_CHECK_FUNCS, the
+# functions are marked "not found", which is perfect.
#
+if test "$NEED_REENTRANT_FUNC_NAMES" = yes ; then
_CFLAGS="$CFLAGS"
_LIB="$LIBS"
CFLAGS="$CFLAGS $TREAD_CFLAGS"
CFLAGS="$_CFLAGS"
LIB="$_LIBS"
-
+fi
# This test makes sure that run tests work at all. Sometimes a shared
dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.262 2003/06/14 14:35:42 momjian Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.263 2003/06/14 17:49:53 momjian Exp $
dnl
dnl Developers, please strive to achieve this order:
dnl
#
# Pthreads
#
+# For each platform, we need to know about any special compile and link
+# libraries, and whether the normal C function names are thread-safe.
+#
+NEED_REENTRANT_FUNC_NAMES=no
if test "$with_threads" = yes; then
AC_CHECK_HEADER(pthread.h, [], [AC_MSG_ERROR([pthread.h not found, required for --with-threads])])
case $host_os in
- netbsd*|bsdi*)
+ netbsd*|bsdi*)
# these require no special flags or libraries
+ NEED_REENTRANT_FUNC_NAMES=no
+ ;;
+ freebsd2*|freebsd3*|freebsd4*)
+ THREAD_CFLAGS="-pthread"
+ NEED_REENTRANT_FUNC_NAMES=yes
;;
- freebsd2*|freebsd3*|freebsd4*) THREAD_CFLAGS="-pthread" ;;
freebsd*)
THREAD_LIBS="-lc_r"
+ NEED_REENTRANT_FUNC_NAMES=yes
;;
linux*) THREAD_CFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
THREAD_LIBS="-lpthread"
+ NEED_REENTRANT_FUNC_NAMES=yes
;;
*)
# other operating systems might fail because they have pthread.h but need
#
# Check for re-entrant versions of certain functions
#
-# Include special flags if required
+# Include special flags if threads are enabled _and_ if required for
+# threading on this platform. Some platforms have *_r functions but
+# their natively named funcs are threadsafe, and should be used instead.
+#
+# One trick here is that if the don't call AC_CHECK_FUNCS, the
+# functions are marked "not found", which is perfect.
#
+if test "$NEED_REENTRANT_FUNC_NAMES" = yes ; then
_CFLAGS="$CFLAGS"
_LIB="$LIBS"
CFLAGS="$CFLAGS $TREAD_CFLAGS"
AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r])
CFLAGS="$_CFLAGS"
LIB="$_LIBS"
-
+fi
# This test makes sure that run tests work at all. Sometimes a shared
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.79 2003/06/08 17:43:00 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.80 2003/06/14 17:49:53 momjian Exp $
*
*-------------------------------------------------------------------------
*/
flags = fcntl(sock, F_GETFL);
if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK)))
{
+ char sebuf[256];
+
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
- libpq_gettext("could not set socket to blocking mode: %s\n"), strerror(errno));
+ libpq_gettext("could not set socket to blocking mode: %s\n"), pqStrerror(errno, sebuf, sizeof(sebuf)));
krb5_free_principal(pg_krb5_context, server);
return STATUS_ERROR;
}
if (fcntl(sock, F_SETFL, (long) flags))
{
+ char sebuf[256];
+
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
libpq_gettext("could not restore non-blocking mode on socket: %s\n"),
- strerror(errno));
+ pqStrerror(errno, sebuf, sizeof(sebuf)));
ret = STATUS_ERROR;
}
if (sendmsg(conn->sock, &msg, 0) == -1)
{
+ char sebuf[256];
+
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
- "pg_local_sendauth: sendmsg: %s\n", strerror(errno));
+ "pg_local_sendauth: sendmsg: %s\n",
+ pqStrerror(errno, sebuf, sizeof(sebuf)));
return STATUS_ERROR;
}
return STATUS_OK;
if (GetUserName(username, &namesize))
name = username;
#else
- struct passwd *pw = getpwuid(geteuid());
+ char pwdbuf[BUFSIZ];
+ struct passwd pwdstr;
+ struct passwd *pw = NULL;
- if (pw)
- name = pw->pw_name;
+ if( pqGetpwuid(geteuid(), &pwdstr,
+ pwdbuf, sizeof(pwdbuf), &pw) == 0 )
+ name = pw->pw_name;
#endif
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.247 2003/06/12 08:15:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.248 2003/06/14 17:49:53 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
if (FCNTL_NONBLOCK(conn->sock) < 0)
{
+ char sebuf[256];
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not set socket to non-blocking mode: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return 0;
}
(char *) &on,
sizeof(on)) < 0)
{
+ char sebuf[256];
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not set socket to TCP no delay mode: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return 0;
}
#endif
{
char hostname[NI_MAXHOST];
char service[NI_MAXHOST];
+ char sebuf[256];
getnameinfo((struct sockaddr *)&conn->raddr.addr, conn->raddr.salen,
hostname, sizeof(hostname), service, sizeof(service),
"\tIs the server running locally and accepting\n"
"\tconnections on Unix domain socket \"%s\"?\n"
),
- SOCK_STRERROR(errorno), service);
+ SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)), service);
else
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext(
"\tIs the server running on host %s and accepting\n"
"\tTCP/IP connections on port %s?\n"
),
- SOCK_STRERROR(errorno),
+ SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
conn->pghostaddr
? conn->pghostaddr
: (conn->pghost
PQconnectPoll(PGconn *conn)
{
PGresult *res;
+ char sebuf[256];
if (conn == NULL)
return PGRES_POLLING_FAILED;
}
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not create socket: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
break;
}
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not get socket error status: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
goto error_return;
}
else if (optval != 0)
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not get client address from socket: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
goto error_return;
}
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not send SSL negotiation packet: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
goto error_return;
}
/* Ok, wait for response */
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not send startup packet: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
free(startpacket);
goto error_return;
}
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive server response to SSL negotiation packet: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
goto error_return;
}
if (nread == 0)
{
int save_errno = SOCK_ERRNO;
int tmpsock = -1;
+ char sebuf[256];
struct
{
uint32 packetlen;
return TRUE;
cancel_errReturn:
- strcat(conn->errorMessage.data, SOCK_STRERROR(SOCK_ERRNO));
+ strcat(conn->errorMessage.data, SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
strcat(conn->errorMessage.data, "\n");
conn->errorMessage.len = strlen(conn->errorMessage.data);
if (tmpsock >= 0)
*val;
int found_keyword;
- key = strtok(line, "=");
- if (key == NULL)
+ key = line;
+ val = strchr(line, '=');
+ if( val == NULL )
{
printfPQExpBuffer(errorMessage,
"ERROR: syntax error in service file '%s', line %d\n",
fclose(f);
return 3;
}
+ *val++ = '\0';
/*
* If not already set, set the database name to the
}
}
- val = line + strlen(line) + 1;
-
/*
* Set the parameter --- but don't override any
* previous explicit setting.
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.41 2002/06/20 20:29:54 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.42 2003/06/14 17:49:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
fd = open(filename, O_RDONLY | PG_BINARY, 0666);
if (fd < 0)
{ /* error */
+ char sebuf[256];
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not open file \"%s\": %s\n"),
- filename, strerror(errno));
+ filename, pqStrerror(errno, sebuf, sizeof(sebuf)));
return InvalidOid;
}
fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY, 0666);
if (fd < 0)
{ /* error */
+ char sebuf[256];
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not open file \"%s\": %s\n"),
- filename, strerror(errno));
+ filename, pqStrerror(errno, sebuf, sizeof(sebuf)));
(void) lo_close(conn, lobj);
return -1;
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.95 2003/06/12 08:15:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.96 2003/06/14 17:49:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
int someread = 0;
int nread;
+ char sebuf[256];
if (conn->sock < 0)
{
#endif
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive data from server: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return -1;
}
if (nread > 0)
#endif
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive data from server: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return -1;
}
if (nread > 0)
while (len > 0)
{
int sent;
+ char sebuf[256];
sent = pqsecure_write(conn, ptr, len);
default:
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not send data to server: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
/* We don't assume it's a fatal error... */
conn->outCount = 0;
return -1;
if (result < 0)
{
+ char sebuf[256];
+
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("select() failed: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
}
return result;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.23 2003/06/08 17:43:00 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.24 2003/06/14 17:49:54 momjian Exp $
*
* NOTES
* The client *requires* a valid server certificate. Since
*/
goto rloop;
case SSL_ERROR_SYSCALL:
+ {
+ char sebuf[256];
+
if (n == -1)
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("SSL SYSCALL error: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
else
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("SSL SYSCALL error: EOF detected\n"));
+
break;
+ }
case SSL_ERROR_SSL:
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("SSL error: %s\n"), SSLerrmessage());
n = 0;
break;
case SSL_ERROR_SYSCALL:
+ {
+ char sebuf[256];
+
if (n == -1)
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("SSL SYSCALL error: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
else
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("SSL SYSCALL error: EOF detected\n"));
break;
+ }
case SSL_ERROR_SSL:
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("SSL error: %s\n"), SSLerrmessage());
#ifdef NOT_USED
/*
* Verify that common name resolves to peer.
- * This function is not thread-safe due to gethostbyname().
*/
static int
verify_peer(PGconn *conn)
len = sizeof(addr);
if (getpeername(conn->sock, &addr, &len) == -1)
{
+ char sebuf[256];
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("error querying socket: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return -1;
}
static DH *
load_dh_file(int keylength)
{
- struct passwd *pwd;
+ char pwdbuf[BUFSIZ];
+ struct passwd pwdstr;
+ struct passwd *pwd = NULL;
FILE *fp;
char fnbuf[2048];
DH *dh = NULL;
int codes;
- if ((pwd = getpwuid(getuid())) == NULL)
- return NULL;
+ if( pqGetpwuid(getuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd) == 0 )
+ return NULL;
/* attempt to open file. It's not an error if it doesn't exist. */
snprintf(fnbuf, sizeof fnbuf, "%s/.postgresql/dh%d.pem",
static int
client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
{
- struct passwd *pwd;
+ char pwdbuf[BUFSIZ];
+ struct passwd pwdstr;
+ struct passwd *pwd = NULL;
struct stat buf,
buf2;
char fnbuf[2048];
FILE *fp;
PGconn *conn = (PGconn *) SSL_get_app_data(ssl);
int (*cb) () = NULL; /* how to read user password */
+ char sebuf[256];
+
- if ((pwd = getpwuid(getuid())) == NULL)
+ if( pqGetpwuid(getuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd) == 0 )
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not get user information\n"));
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not open certificate (%s): %s\n"),
- fnbuf, strerror(errno));
+ fnbuf, pqStrerror(errno, sebuf, sizeof(sebuf)));
return -1;
}
if (PEM_read_X509(fp, x509, NULL, NULL) == NULL)
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not open private key file (%s): %s\n"),
- fnbuf, strerror(errno));
+ fnbuf, pqStrerror(errno, sebuf, sizeof(sebuf)));
X509_free(*x509);
return -1;
}
initialize_SSL(PGconn *conn)
{
struct stat buf;
- struct passwd *pwd;
+ char pwdbuf[BUFSIZ];
+ struct passwd pwdstr;
+ struct passwd *pwd = NULL;
char fnbuf[2048];
if (!SSL_context)
}
}
- if ((pwd = getpwuid(getuid())) != NULL)
+ if( pqGetpwuid(getuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd) == 0 )
{
snprintf(fnbuf, sizeof fnbuf, "%s/.postgresql/root.crt",
pwd->pw_dir);
{
return 0;
#ifdef NOT_USED
+ char sebuf[256];
/* CLIENT CERTIFICATES NOT REQUIRED bjm 2002-09-26 */
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not read root certificate list (%s): %s\n"),
- fnbuf, strerror(errno));
+ fnbuf, pqStrerror(errno, sebuf, sizeof(sebuf)));
return -1;
#endif
}
return PGRES_POLLING_WRITING;
case SSL_ERROR_SYSCALL:
+ {
+ char sebuf[256];
+
if (r == -1)
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("SSL SYSCALL error: %s\n"),
- SOCK_STRERROR(SOCK_ERRNO));
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
else
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("SSL SYSCALL error: EOF detected\n"));
close_SSL(conn);
return PGRES_POLLING_FAILED;
-
+ }
case SSL_ERROR_SSL:
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("SSL error: %s\n"), SSLerrmessage());
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-int.h,v 1.73 2003/06/12 07:36:51 momjian Exp $
+ * $Id: libpq-int.h,v 1.74 2003/06/14 17:49:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <sys/time.h>
#endif
+
#if defined(WIN32) && (!defined(ssize_t))
typedef int ssize_t; /* ssize_t doesn't exist in VC (atleast
* not VC6) */
#define SOCK_STRERROR winsock_strerror
#else
#define SOCK_ERRNO errno
-#define SOCK_STRERROR strerror
+#define SOCK_STRERROR pqStrerror
#endif
#endif /* LIBPQ_INT_H */
*/
const char *
-winsock_strerror(int err)
+winsock_strerror(int err, char *strerrbuf, size_t buflen)
{
- static char buf[512]; /* Not threadsafe */
unsigned long flags;
int offs,
i;
- int success = LookupWSErrorMessage(err, buf);
+ int success = LookupWSErrorMessage(err, strerrbuf);
for (i = 0; !success && i < DLLS_SIZE; i++)
{
flags,
dlls[i].handle, err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- buf, sizeof(buf) - 64,
+ strerrbuf, buflen - 64,
0
);
}
if (!success)
- sprintf(buf, "Unknown socket error (0x%08X/%lu)", err, err);
+ sprintf(strerrbuf, "Unknown socket error (0x%08X/%lu)", err, err);
else
{
- buf[sizeof(buf) - 1] = '\0';
- offs = strlen(buf);
- if (offs > sizeof(buf) - 64)
- offs = sizeof(buf) - 64;
- sprintf(buf + offs, " (0x%08X/%lu)", err, err);
+ strerrbuf[buflen - 1] = '\0';
+ offs = strlen(strerrbuf);
+ if (offs > buflen - 64)
+ offs = buflen - 64;
+ sprintf(strerrbuf + offs, " (0x%08X/%lu)", err, err);
}
- return buf;
+ return strerrbuf;
}
/*
* support for handling Windows Socket errors
*/
-extern const char *winsock_strerror(int eno);
-
+extern const char *winsock_strerror(int err, char *strerrbuf, size_t buflen);
#endif