systemd/1069-locale-util-do-not-call-setlocale-when-multi-threade.patch
Jan Macku 6a6e696970 systemd-239-82.15
Resolves: RHEL-93425
2026-01-30 08:55:59 +01:00

40 lines
1.2 KiB
Diff

From e4279cad64211a364e8a45edcc7e9dfa93546f2e Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Thu, 23 Nov 2023 00:32:48 +0900
Subject: [PATCH] locale-util: do not call setlocale() when multi-threaded
Fixes #30141.
(cherry picked from commit ca13432d600593b8eda76721118763b63746eb33)
Related: RHEL-93425
---
src/basic/locale-util.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c
index 42ef309ebd..99cc7b5ef5 100644
--- a/src/basic/locale-util.c
+++ b/src/basic/locale-util.c
@@ -20,6 +20,7 @@
#include "fd-util.h"
#include "hashmap.h"
#include "locale-util.h"
+#include "missing_syscall.h"
#include "path-util.h"
#include "set.h"
#include "string-table.h"
@@ -234,6 +235,12 @@ bool is_locale_utf8(void) {
if (cached_answer >= 0)
goto out;
+ /* 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;