Merge pull request #30149 from yuwata/setlocale

locale-util: do not call setlocale() when multi-threaded
This commit is contained in:
Luca Boccassi
2023-11-22 17:43:39 +00:00
committed by GitHub
2 changed files with 7 additions and 6 deletions
+7 -5
View 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"
@@ -280,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;
@@ -303,6 +299,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;
-1
View File
@@ -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);