From: Yu Watanabe Date: Wed, 22 Nov 2023 15:32:48 +0000 (+0900) Subject: locale-util: do not call setlocale() when multi-threaded X-Git-Tag: v255-rc3~7^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ca13432d600593b8eda76721118763b63746eb33;p=thirdparty%2Fsystemd.git locale-util: do not call setlocale() when multi-threaded Fixes #30141. --- diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index d43f91fd226..e83c7de8865 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -17,6 +17,7 @@ #include "fileio.h" #include "hashmap.h" #include "locale-util.h" +#include "missing_syscall.h" #include "path-util.h" #include "set.h" #include "string-table.h" @@ -303,6 +304,12 @@ bool is_locale_utf8(void) { } else if (r != -ENXIO) log_debug_errno(r, "Failed to parse $SYSTEMD_UTF8, ignoring: %m"); + /* This function may be called from libsystemd, and setlocale() is not thread safe. Assuming yes. */ + if (gettid() != raw_getpid()) { + cached_answer = true; + goto out; + } + if (!setlocale(LC_ALL, "")) { cached_answer = true; goto out;