Skip to content

Commit 7d4b61d

Browse files
authored
Merge pull request #30149 from yuwata/setlocale
locale-util: do not call setlocale() when multi-threaded
2 parents c1fd45d + d54a45a commit 7d4b61d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/basic/locale-util.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "fileio.h"
1818
#include "hashmap.h"
1919
#include "locale-util.h"
20+
#include "missing_syscall.h"
2021
#include "path-util.h"
2122
#include "set.h"
2223
#include "string-table.h"
@@ -280,11 +281,6 @@ int locale_is_installed(const char *name) {
280281
return true;
281282
}
282283

283-
void init_gettext(void) {
284-
setlocale(LC_ALL, "");
285-
textdomain(GETTEXT_PACKAGE);
286-
}
287-
288284
bool is_locale_utf8(void) {
289285
static int cached_answer = -1;
290286
const char *set;
@@ -303,6 +299,12 @@ bool is_locale_utf8(void) {
303299
} else if (r != -ENXIO)
304300
log_debug_errno(r, "Failed to parse $SYSTEMD_UTF8, ignoring: %m");
305301

302+
/* This function may be called from libsystemd, and setlocale() is not thread safe. Assuming yes. */
303+
if (gettid() != raw_getpid()) {
304+
cached_answer = true;
305+
goto out;
306+
}
307+
306308
if (!setlocale(LC_ALL, "")) {
307309
cached_answer = true;
308310
goto out;

src/basic/locale-util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ int locale_is_installed(const char *name);
3535

3636
#define _(String) dgettext(GETTEXT_PACKAGE, String)
3737
#define N_(String) String
38-
void init_gettext(void);
3938

4039
bool is_locale_utf8(void);
4140

0 commit comments

Comments
 (0)