]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale-util: do not call setlocale() when multi-threaded
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 22 Nov 2023 15:32:48 +0000 (00:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 22 Nov 2023 15:50:42 +0000 (00:50 +0900)
Fixes #30141.

src/basic/locale-util.c

index d43f91fd226b96bc633dd6f5fb453cd27156a60b..e83c7de88653d49b7d7b20d2fd99f90c070e875e 100644 (file)
@@ -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;