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

Commita584d03

Browse files
committed
Avoid concurrent calls to bindtextdomain().
We previously supposed that it was okay for different threads tocall bindtextdomain() concurrently (cf. commit1f655fd).It now emerges that there's at least one gettext implementationin which that triggers an abort() crash, so let's stop doing that.Add mutexes guarding libpq's and ecpglib's calls, which are theonly ones that need worry about multithreaded callers.Note: in libpq, we could perhaps have piggybacked ondefault_threadlock() to avoid defining a new mutex variable.I judge that not terribly safe though, since libpq_gettext couldbe called from code that is holding the default mutex. If thatwere the first such call in the process, it'd fail. An extramutex is cheap insurance against unforeseen interactions.Per bug #18312 from Christian Maurer. Back-patch to allsupported versions.Discussion:https://postgr.es/m/18312-bbbabc8113592b78@postgresql.orgDiscussion:https://postgr.es/m/264860.1707163416@sss.pgh.pa.us
1 parent0028b55 commita584d03

File tree

2 files changed

+52
-26
lines changed

2 files changed

+52
-26
lines changed

‎src/interfaces/ecpg/ecpglib/misc.c‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,14 @@ char *
465465
ecpg_gettext(constchar*msgid)
466466
{
467467
/*
468-
*If multiple threads come through here at about the same time, it's okay
469-
*for more than one of them tocall bindtextdomain().But it's not okay
470-
*for any of them to reach dgettext() before bindtextdomain() is
471-
*complete, so don't set the flag till that's done. Use "volatile" just
472-
*to be sure the compiler doesn't try to get cute.
468+
*At least on Windows, there are gettext implementations that fail if
469+
*multiple threadscall bindtextdomain() concurrently.Use a mutex and
470+
*flag variable to ensure that we call it just once per process. It is
471+
*not known that similar bugs exist on non-Windows platforms, but we
472+
*might as well do it the same way everywhere.
473473
*/
474474
staticvolatileboolalready_bound= false;
475+
staticpthread_mutex_tbinddomain_mutex=PTHREAD_MUTEX_INITIALIZER;
475476

476477
if (!already_bound)
477478
{
@@ -481,14 +482,26 @@ ecpg_gettext(const char *msgid)
481482
#else
482483
intsave_errno=errno;
483484
#endif
484-
constchar*ldir;
485-
486-
/* No relocatable lookup here because the binary could be anywhere */
487-
ldir=getenv("PGLOCALEDIR");
488-
if (!ldir)
489-
ldir=LOCALEDIR;
490-
bindtextdomain(PG_TEXTDOMAIN("ecpglib"),ldir);
491-
already_bound= true;
485+
486+
(void)pthread_mutex_lock(&binddomain_mutex);
487+
488+
if (!already_bound)
489+
{
490+
constchar*ldir;
491+
492+
/*
493+
* No relocatable lookup here because the calling executable could
494+
* be anywhere
495+
*/
496+
ldir=getenv("PGLOCALEDIR");
497+
if (!ldir)
498+
ldir=LOCALEDIR;
499+
bindtextdomain(PG_TEXTDOMAIN("ecpglib"),ldir);
500+
already_bound= true;
501+
}
502+
503+
(void)pthread_mutex_unlock(&binddomain_mutex);
504+
492505
#ifdefWIN32
493506
SetLastError(save_errno);
494507
#else

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,13 +1225,14 @@ static void
12251225
libpq_binddomain(void)
12261226
{
12271227
/*
1228-
*If multiple threads come through here at about the same time, it's okay
1229-
*for more than one of them tocall bindtextdomain().But it's not okay
1230-
*for any of them to return to caller before bindtextdomain() is
1231-
*complete, so don't set the flag till that's done. Use "volatile" just
1232-
*to be sure the compiler doesn't try to get cute.
1228+
*At least on Windows, there are gettext implementations that fail if
1229+
*multiple threadscall bindtextdomain() concurrently.Use a mutex and
1230+
*flag variable to ensure that we call it just once per process. It is
1231+
*not known that similar bugs exist on non-Windows platforms, but we
1232+
*might as well do it the same way everywhere.
12331233
*/
12341234
staticvolatileboolalready_bound= false;
1235+
staticpthread_mutex_tbinddomain_mutex=PTHREAD_MUTEX_INITIALIZER;
12351236

12361237
if (!already_bound)
12371238
{
@@ -1241,14 +1242,26 @@ libpq_binddomain(void)
12411242
#else
12421243
intsave_errno=errno;
12431244
#endif
1244-
constchar*ldir;
1245-
1246-
/* No relocatable lookup here because the binary could be anywhere */
1247-
ldir=getenv("PGLOCALEDIR");
1248-
if (!ldir)
1249-
ldir=LOCALEDIR;
1250-
bindtextdomain(PG_TEXTDOMAIN("libpq"),ldir);
1251-
already_bound= true;
1245+
1246+
(void)pthread_mutex_lock(&binddomain_mutex);
1247+
1248+
if (!already_bound)
1249+
{
1250+
constchar*ldir;
1251+
1252+
/*
1253+
* No relocatable lookup here because the calling executable could
1254+
* be anywhere
1255+
*/
1256+
ldir=getenv("PGLOCALEDIR");
1257+
if (!ldir)
1258+
ldir=LOCALEDIR;
1259+
bindtextdomain(PG_TEXTDOMAIN("libpq"),ldir);
1260+
already_bound= true;
1261+
}
1262+
1263+
(void)pthread_mutex_unlock(&binddomain_mutex);
1264+
12521265
#ifdefWIN32
12531266
SetLastError(save_errno);
12541267
#else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp