Skip to content

Commit 19086f7

Browse files
yuwatamrc0mmand
authored andcommitted
locale-util: do not call setlocale() when multi-threaded
Fixes #30141. (cherry picked from commit ca13432d600593b8eda76721118763b63746eb33) Related: RHEL-93425
1 parent 0243672 commit 19086f7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/basic/locale-util.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "fd-util.h"
2121
#include "hashmap.h"
2222
#include "locale-util.h"
23+
#include "missing_syscall.h"
2324
#include "path-util.h"
2425
#include "set.h"
2526
#include "string-table.h"
@@ -234,6 +235,12 @@ bool is_locale_utf8(void) {
234235
if (cached_answer >= 0)
235236
goto out;
236237

238+
/* This function may be called from libsystemd, and setlocale() is not thread safe. Assuming yes. */
239+
if (gettid() != raw_getpid()) {
240+
cached_answer = true;
241+
goto out;
242+
}
243+
237244
if (!setlocale(LC_ALL, "")) {
238245
cached_answer = true;
239246
goto out;

0 commit comments

Comments
 (0)