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

Commita16a031

Browse files
committed
Make libpq thread-safe with configure --with-threads option.
Lee Kindness
1 parent62b532b commita16a031

File tree

10 files changed

+146
-71
lines changed

10 files changed

+146
-71
lines changed

‎configure

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,6 +3591,10 @@ rm -f conftest*
35913591
#
35923592
# Pthreads
35933593
#
3594+
# For each platform, we need to know about any special compile and link
3595+
# libraries, and whether the normal C function names are thread-safe.
3596+
#
3597+
NEED_REENTRANT_FUNC_NAMES=no
35943598
iftest"$with_threads" = yes;then
35953599
echo"$as_me:$LINENO: checking for ANSI C header files">&5
35963600
echo$ECHO_N"checking for ANSI C header files...$ECHO_C">&6
@@ -3902,13 +3906,19 @@ fi
39023906
case$host_osin
39033907
netbsd*|bsdi*)
39043908
# these require no special flags or libraries
3909+
NEED_REENTRANT_FUNC_NAMES=no
3910+
;;
3911+
freebsd2*|freebsd3*|freebsd4*)
3912+
THREAD_CFLAGS="-pthread"
3913+
NEED_REENTRANT_FUNC_NAMES=yes
39053914
;;
3906-
freebsd2*|freebsd3*|freebsd4*) THREAD_CFLAGS="-pthread" ;;
39073915
freebsd*)
39083916
THREAD_LIBS="-lc_r"
3917+
NEED_REENTRANT_FUNC_NAMES=yes
39093918
;;
39103919
linux*) THREAD_CFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
39113920
THREAD_LIBS="-lpthread"
3921+
NEED_REENTRANT_FUNC_NAMES=yes
39123922
;;
39133923
*)
39143924
# other operating systems might fail because they have pthread.h but need
@@ -12829,8 +12839,14 @@ fi
1282912839
#
1283012840
# Check for re-entrant versions of certain functions
1283112841
#
12832-
# Include special flags if required
12842+
# Include special flags if threads are enabled _and_ if required for
12843+
# threading on this platform. Some platforms have *_r functions but
12844+
# their natively named funcs are threadsafe, and should be used instead.
12845+
#
12846+
# One trick here is that if the don't call AC_CHECK_FUNCS, the
12847+
# functions are marked "not found", which is perfect.
1283312848
#
12849+
iftest"$NEED_REENTRANT_FUNC_NAMES" = yes;then
1283412850
_CFLAGS="$CFLAGS"
1283512851
_LIB="$LIBS"
1283612852
CFLAGS="$CFLAGS$TREAD_CFLAGS"
@@ -12915,7 +12931,7 @@ done
1291512931
1291612932
CFLAGS="$_CFLAGS"
1291712933
LIB="$_LIBS"
12918-
12934+
fi
1291912935
1292012936
1292112937
# This test makes sure that run tests work at all. Sometimes a shared

‎configure.in

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $Header: /cvsroot/pgsql/configure.in,v 1.262 2003/06/1414:35:42 momjian Exp $
2+
dnl $Header: /cvsroot/pgsql/configure.in,v 1.263 2003/06/1417:49:53 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -554,18 +554,28 @@ AC_SUBST(ELF_SYS)
554554
#
555555
# Pthreads
556556
#
557+
# For each platform, we need to know about any special compile and link
558+
# libraries, and whether the normal C function names are thread-safe.
559+
#
560+
NEED_REENTRANT_FUNC_NAMES=no
557561
if test "$with_threads" = yes; then
558562
AC_CHECK_HEADER(pthread.h, [], [AC_MSG_ERROR([pthread.h not found, required for --with-threads])])
559563
case $host_os in
560-
netbsd*|bsdi*)
564+
netbsd*|bsdi*)
561565
# these require no special flags or libraries
566+
NEED_REENTRANT_FUNC_NAMES=no
567+
;;
568+
freebsd2*|freebsd3*|freebsd4*)
569+
THREAD_CFLAGS="-pthread"
570+
NEED_REENTRANT_FUNC_NAMES=yes
562571
;;
563-
freebsd2*|freebsd3*|freebsd4*) THREAD_CFLAGS="-pthread" ;;
564572
freebsd*)
565573
THREAD_LIBS="-lc_r"
574+
NEED_REENTRANT_FUNC_NAMES=yes
566575
;;
567576
linux*) THREAD_CFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
568577
THREAD_LIBS="-lpthread"
578+
NEED_REENTRANT_FUNC_NAMES=yes
569579
;;
570580
*)
571581
# other operating systems might fail because they have pthread.h but need
@@ -991,16 +1001,22 @@ AC_FUNC_FSEEKO
9911001
#
9921002
# Check for re-entrant versions of certain functions
9931003
#
994-
# Include special flags if required
1004+
# Include special flags if threads are enabled _and_ if required for
1005+
# threading on this platform. Some platforms have *_r functions but
1006+
# their natively named funcs are threadsafe, and should be used instead.
1007+
#
1008+
# One trick here is that if the don't call AC_CHECK_FUNCS, the
1009+
# functions are marked "not found", which is perfect.
9951010
#
1011+
if test "$NEED_REENTRANT_FUNC_NAMES" = yes ; then
9961012
_CFLAGS="$CFLAGS"
9971013
_LIB="$LIBS"
9981014
CFLAGS="$CFLAGS $TREAD_CFLAGS"
9991015
LIBS="$LIBS $THREAD_LIBS"
10001016
AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r])
10011017
CFLAGS="$_CFLAGS"
10021018
LIB="$_LIBS"
1003-
1019+
fi
10041020

10051021

10061022
# This test makes sure that run tests work at all. Sometimes a shared

‎src/interfaces/libpq/fe-auth.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.79 2003/06/08 17:43:00 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.80 2003/06/14 17:49:53 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -391,8 +391,10 @@ pg_krb5_sendauth(char *PQerrormsg, int sock,
391391
flags=fcntl(sock,F_GETFL);
392392
if (flags<0||fcntl(sock,F_SETFL, (long) (flags& ~O_NONBLOCK)))
393393
{
394+
charsebuf[256];
395+
394396
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
395-
libpq_gettext("could not set socket to blocking mode: %s\n"),strerror(errno));
397+
libpq_gettext("could not set socket to blocking mode: %s\n"),pqStrerror(errno,sebuf,sizeof(sebuf)));
396398
krb5_free_principal(pg_krb5_context,server);
397399
returnSTATUS_ERROR;
398400
}
@@ -436,9 +438,11 @@ pg_krb5_sendauth(char *PQerrormsg, int sock,
436438

437439
if (fcntl(sock,F_SETFL, (long)flags))
438440
{
441+
charsebuf[256];
442+
439443
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
440444
libpq_gettext("could not restore non-blocking mode on socket: %s\n"),
441-
strerror(errno));
445+
pqStrerror(errno,sebuf,sizeof(sebuf)));
442446
ret=STATUS_ERROR;
443447
}
444448

@@ -495,8 +499,11 @@ pg_local_sendauth(char *PQerrormsg, PGconn *conn)
495499

496500
if (sendmsg(conn->sock,&msg,0)==-1)
497501
{
502+
charsebuf[256];
503+
498504
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
499-
"pg_local_sendauth: sendmsg: %s\n",strerror(errno));
505+
"pg_local_sendauth: sendmsg: %s\n",
506+
pqStrerror(errno,sebuf,sizeof(sebuf)));
500507
returnSTATUS_ERROR;
501508
}
502509
returnSTATUS_OK;
@@ -739,10 +746,13 @@ fe_getauthname(char *PQerrormsg)
739746
if (GetUserName(username,&namesize))
740747
name=username;
741748
#else
742-
structpasswd*pw=getpwuid(geteuid());
749+
charpwdbuf[BUFSIZ];
750+
structpasswdpwdstr;
751+
structpasswd*pw=NULL;
743752

744-
if (pw)
745-
name=pw->pw_name;
753+
if(pqGetpwuid(geteuid(),&pwdstr,
754+
pwdbuf,sizeof(pwdbuf),&pw)==0 )
755+
name=pw->pw_name;
746756
#endif
747757
}
748758

‎src/interfaces/libpq/fe-connect.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.247 2003/06/12 08:15:29 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.248 2003/06/14 17:49:53 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -713,9 +713,11 @@ connectMakeNonblocking(PGconn *conn)
713713
{
714714
if (FCNTL_NONBLOCK(conn->sock)<0)
715715
{
716+
charsebuf[256];
717+
716718
printfPQExpBuffer(&conn->errorMessage,
717719
libpq_gettext("could not set socket to non-blocking mode: %s\n"),
718-
SOCK_STRERROR(SOCK_ERRNO));
720+
SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
719721
return0;
720722
}
721723

@@ -738,9 +740,11 @@ connectNoDelay(PGconn *conn)
738740
(char*)&on,
739741
sizeof(on))<0)
740742
{
743+
charsebuf[256];
744+
741745
printfPQExpBuffer(&conn->errorMessage,
742746
libpq_gettext("could not set socket to TCP no delay mode: %s\n"),
743-
SOCK_STRERROR(SOCK_ERRNO));
747+
SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
744748
return0;
745749
}
746750
#endif
@@ -759,6 +763,7 @@ connectFailureMessage(PGconn *conn, int errorno)
759763
{
760764
charhostname[NI_MAXHOST];
761765
charservice[NI_MAXHOST];
766+
charsebuf[256];
762767

763768
getnameinfo((structsockaddr*)&conn->raddr.addr,conn->raddr.salen,
764769
hostname,sizeof(hostname),service,sizeof(service),
@@ -770,15 +775,15 @@ connectFailureMessage(PGconn *conn, int errorno)
770775
"\tIs the server running locally and accepting\n"
771776
"\tconnections on Unix domain socket \"%s\"?\n"
772777
),
773-
SOCK_STRERROR(errorno),service);
778+
SOCK_STRERROR(errorno,sebuf,sizeof(sebuf)),service);
774779
else
775780
printfPQExpBuffer(&conn->errorMessage,
776781
libpq_gettext(
777782
"could not connect to server: %s\n"
778783
"\tIs the server running on host %s and accepting\n"
779784
"\tTCP/IP connections on port %s?\n"
780785
),
781-
SOCK_STRERROR(errorno),
786+
SOCK_STRERROR(errorno,sebuf,sizeof(sebuf)),
782787
conn->pghostaddr
783788
?conn->pghostaddr
784789
: (conn->pghost
@@ -1001,6 +1006,7 @@ PostgresPollingStatusType
10011006
PQconnectPoll(PGconn*conn)
10021007
{
10031008
PGresult*res;
1009+
charsebuf[256];
10041010

10051011
if (conn==NULL)
10061012
returnPGRES_POLLING_FAILED;
@@ -1094,7 +1100,7 @@ PQconnectPoll(PGconn *conn)
10941100
}
10951101
printfPQExpBuffer(&conn->errorMessage,
10961102
libpq_gettext("could not create socket: %s\n"),
1097-
SOCK_STRERROR(SOCK_ERRNO));
1103+
SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
10981104
break;
10991105
}
11001106

@@ -1200,7 +1206,7 @@ PQconnectPoll(PGconn *conn)
12001206
{
12011207
printfPQExpBuffer(&conn->errorMessage,
12021208
libpq_gettext("could not get socket error status: %s\n"),
1203-
SOCK_STRERROR(SOCK_ERRNO));
1209+
SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
12041210
gotoerror_return;
12051211
}
12061212
elseif (optval!=0)
@@ -1237,7 +1243,7 @@ PQconnectPoll(PGconn *conn)
12371243
{
12381244
printfPQExpBuffer(&conn->errorMessage,
12391245
libpq_gettext("could not get client address from socket: %s\n"),
1240-
SOCK_STRERROR(SOCK_ERRNO));
1246+
SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
12411247
gotoerror_return;
12421248
}
12431249

@@ -1282,7 +1288,7 @@ PQconnectPoll(PGconn *conn)
12821288
{
12831289
printfPQExpBuffer(&conn->errorMessage,
12841290
libpq_gettext("could not send SSL negotiation packet: %s\n"),
1285-
SOCK_STRERROR(SOCK_ERRNO));
1291+
SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
12861292
gotoerror_return;
12871293
}
12881294
/* Ok, wait for response */
@@ -1317,7 +1323,7 @@ PQconnectPoll(PGconn *conn)
13171323
{
13181324
printfPQExpBuffer(&conn->errorMessage,
13191325
libpq_gettext("could not send startup packet: %s\n"),
1320-
SOCK_STRERROR(SOCK_ERRNO));
1326+
SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
13211327
free(startpacket);
13221328
gotoerror_return;
13231329
}
@@ -1357,7 +1363,7 @@ PQconnectPoll(PGconn *conn)
13571363

13581364
printfPQExpBuffer(&conn->errorMessage,
13591365
libpq_gettext("could not receive server response to SSL negotiation packet: %s\n"),
1360-
SOCK_STRERROR(SOCK_ERRNO));
1366+
SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
13611367
gotoerror_return;
13621368
}
13631369
if (nread==0)
@@ -2037,6 +2043,7 @@ PQrequestCancel(PGconn *conn)
20372043
{
20382044
intsave_errno=SOCK_ERRNO;
20392045
inttmpsock=-1;
2046+
charsebuf[256];
20402047
struct
20412048
{
20422049
uint32packetlen;
@@ -2115,7 +2122,7 @@ PQrequestCancel(PGconn *conn)
21152122
return TRUE;
21162123

21172124
cancel_errReturn:
2118-
strcat(conn->errorMessage.data,SOCK_STRERROR(SOCK_ERRNO));
2125+
strcat(conn->errorMessage.data,SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
21192126
strcat(conn->errorMessage.data,"\n");
21202127
conn->errorMessage.len=strlen(conn->errorMessage.data);
21212128
if (tmpsock >=0)
@@ -2262,8 +2269,9 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
22622269
*val;
22632270
intfound_keyword;
22642271

2265-
key=strtok(line,"=");
2266-
if (key==NULL)
2272+
key=line;
2273+
val=strchr(line,'=');
2274+
if(val==NULL )
22672275
{
22682276
printfPQExpBuffer(errorMessage,
22692277
"ERROR: syntax error in service file '%s', line %d\n",
@@ -2272,6 +2280,7 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
22722280
fclose(f);
22732281
return3;
22742282
}
2283+
*val++='\0';
22752284

22762285
/*
22772286
*If not already set, set the database name to the
@@ -2287,8 +2296,6 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
22872296
}
22882297
}
22892298

2290-
val=line+strlen(line)+1;
2291-
22922299
/*
22932300
* Set the parameter --- but don't override any
22942301
* previous explicit setting.

‎src/interfaces/libpq/fe-lobj.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.41 2002/06/20 20:29:54 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.42 2003/06/14 17:49:54 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -396,9 +396,10 @@ lo_import(PGconn *conn, const char *filename)
396396
fd=open(filename,O_RDONLY |PG_BINARY,0666);
397397
if (fd<0)
398398
{/* error */
399+
charsebuf[256];
399400
printfPQExpBuffer(&conn->errorMessage,
400401
libpq_gettext("could not open file \"%s\": %s\n"),
401-
filename,strerror(errno));
402+
filename,pqStrerror(errno,sebuf,sizeof(sebuf)));
402403
returnInvalidOid;
403404
}
404405

@@ -479,9 +480,10 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
479480
fd=open(filename,O_CREAT |O_WRONLY |O_TRUNC |PG_BINARY,0666);
480481
if (fd<0)
481482
{/* error */
483+
charsebuf[256];
482484
printfPQExpBuffer(&conn->errorMessage,
483485
libpq_gettext("could not open file \"%s\": %s\n"),
484-
filename,strerror(errno));
486+
filename,pqStrerror(errno,sebuf,sizeof(sebuf)));
485487
(void)lo_close(conn,lobj);
486488
return-1;
487489
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp