Skip to content

Commit ca13432

Browse files
committed
locale-util: do not call setlocale() when multi-threaded
Fixes #30141.
1 parent 3197d77 commit ca13432

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
@@ -17,6 +17,7 @@
1717
#include "fileio.h"
1818
#include "hashmap.h"
1919
#include "locale-util.h"
20+
#include "missing_syscall.h"
2021
#include "path-util.h"
2122
#include "set.h"
2223
#include "string-table.h"
@@ -303,6 +304,12 @@ bool is_locale_utf8(void) {
303304
} else if (r != -ENXIO)
304305
log_debug_errno(r, "Failed to parse $SYSTEMD_UTF8, ignoring: %m");
305306

307+
/* This function may be called from libsystemd, and setlocale() is not thread safe. Assuming yes. */
308+
if (gettid() != raw_getpid()) {
309+
cached_answer = true;
310+
goto out;
311+
}
312+
306313
if (!setlocale(LC_ALL, "")) {
307314
cached_answer = true;
308315
goto out;

0 commit comments

Comments
 (0)