From ca13432d600593b8eda76721118763b63746eb33 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 23 Nov 2023 00:32:48 +0900 Subject: [PATCH 1/2] locale-util: do not call setlocale() when multi-threaded Fixes #30141. --- 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 d43f91fd22..e83c7de886 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; From d54a45ad5fe520c722981146767a7a798128bb1b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 23 Nov 2023 00:34:44 +0900 Subject: [PATCH 2/2] locale-util: drop unused init_gettext() The function has not been used since 96d9117ad2db7d8c13f7898127eee8939e88daf1. --- src/basic/locale-util.c | 5 ----- src/basic/locale-util.h | 1 - 2 files changed, 6 deletions(-) diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index e83c7de886..d3fef01feb 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -281,11 +281,6 @@ int locale_is_installed(const char *name) { return true; } -void init_gettext(void) { - setlocale(LC_ALL, ""); - textdomain(GETTEXT_PACKAGE); -} - bool is_locale_utf8(void) { static int cached_answer = -1; const char *set; diff --git a/src/basic/locale-util.h b/src/basic/locale-util.h index ae2797cd2d..81fe8d1084 100644 --- a/src/basic/locale-util.h +++ b/src/basic/locale-util.h @@ -35,7 +35,6 @@ int locale_is_installed(const char *name); #define _(String) dgettext(GETTEXT_PACKAGE, String) #define N_(String) String -void init_gettext(void); bool is_locale_utf8(void);