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

Commit806f989

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 parent9f041b0 commit806f989

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
@@ -512,13 +512,14 @@ char *
512512
ecpg_gettext(constchar*msgid)
513513
{
514514
/*
515-
*If multiple threads come through here at about the same time, it's okay
516-
*for more than one of them tocall bindtextdomain().But it's not okay
517-
*for any of them to reach dgettext() before bindtextdomain() is
518-
*complete, so don't set the flag till that's done. Use "volatile" just
519-
*to be sure the compiler doesn't try to get cute.
515+
*At least on Windows, there are gettext implementations that fail if
516+
*multiple threadscall bindtextdomain() concurrently.Use a mutex and
517+
*flag variable to ensure that we call it just once per process. It is
518+
*not known that similar bugs exist on non-Windows platforms, but we
519+
*might as well do it the same way everywhere.
520520
*/
521521
staticvolatileboolalready_bound= false;
522+
staticpthread_mutex_tbinddomain_mutex=PTHREAD_MUTEX_INITIALIZER;
522523

523524
if (!already_bound)
524525
{
@@ -528,14 +529,26 @@ ecpg_gettext(const char *msgid)
528529
#else
529530
intsave_errno=errno;
530531
#endif
531-
constchar*ldir;
532-
533-
/* No relocatable lookup here because the binary could be anywhere */
534-
ldir=getenv("PGLOCALEDIR");
535-
if (!ldir)
536-
ldir=LOCALEDIR;
537-
bindtextdomain(PG_TEXTDOMAIN("ecpglib"),ldir);
538-
already_bound= true;
532+
533+
(void)pthread_mutex_lock(&binddomain_mutex);
534+
535+
if (!already_bound)
536+
{
537+
constchar*ldir;
538+
539+
/*
540+
* No relocatable lookup here because the calling executable could
541+
* be anywhere
542+
*/
543+
ldir=getenv("PGLOCALEDIR");
544+
if (!ldir)
545+
ldir=LOCALEDIR;
546+
bindtextdomain(PG_TEXTDOMAIN("ecpglib"),ldir);
547+
already_bound= true;
548+
}
549+
550+
(void)pthread_mutex_unlock(&binddomain_mutex);
551+
539552
#ifdefWIN32
540553
SetLastError(save_errno);
541554
#else

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

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

12441245
if (!already_bound)
12451246
{
@@ -1249,14 +1250,26 @@ libpq_binddomain(void)
12491250
#else
12501251
intsave_errno=errno;
12511252
#endif
1252-
constchar*ldir;
1253-
1254-
/* No relocatable lookup here because the binary could be anywhere */
1255-
ldir=getenv("PGLOCALEDIR");
1256-
if (!ldir)
1257-
ldir=LOCALEDIR;
1258-
bindtextdomain(PG_TEXTDOMAIN("libpq"),ldir);
1259-
already_bound= true;
1253+
1254+
(void)pthread_mutex_lock(&binddomain_mutex);
1255+
1256+
if (!already_bound)
1257+
{
1258+
constchar*ldir;
1259+
1260+
/*
1261+
* No relocatable lookup here because the calling executable could
1262+
* be anywhere
1263+
*/
1264+
ldir=getenv("PGLOCALEDIR");
1265+
if (!ldir)
1266+
ldir=LOCALEDIR;
1267+
bindtextdomain(PG_TEXTDOMAIN("libpq"),ldir);
1268+
already_bound= true;
1269+
}
1270+
1271+
(void)pthread_mutex_unlock(&binddomain_mutex);
1272+
12601273
#ifdefWIN32
12611274
SetLastError(save_errno);
12621275
#else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp