Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit603eb79

Browse files
committed
Always set the six locale category environment variables in main().
Typical server invocations already achieved that. Invalid localesettings in the initial postmaster environment interfered, as couldmalloc() failure. Setting "LC_MESSAGES=pt_BR.utf8 LC_ALL=invalid" inthe postmaster environment will now choose C-locale messages, notBrazilian Portuguese messages. Most localized programs, including allPostgreSQL frontend executables, do likewise. Users are unlikely toobserve changes involving locale categories other than LC_MESSAGES.CheckMyDatabase() ensures that we successfully set LC_COLLATE andLC_CTYPE; main() sets the remaining three categories to locale "C",which almost cannot fail. Back-patch to 9.0 (all supported versions).
1 parente045052 commit603eb79

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

‎src/backend/main/main.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const char *progname;
5151

5252

5353
staticvoidstartup_hacks(constchar*progname);
54+
staticvoidinit_locale(intcategory,constchar*locale);
5455
staticvoidhelp(constchar*progname);
5556
staticvoidcheck_root(constchar*progname);
5657
staticchar*get_current_username(constchar*progname);
@@ -124,31 +125,31 @@ main(int argc, char *argv[])
124125
char*env_locale;
125126

126127
if ((env_locale=getenv("LC_COLLATE"))!=NULL)
127-
pg_perm_setlocale(LC_COLLATE,env_locale);
128+
init_locale(LC_COLLATE,env_locale);
128129
else
129-
pg_perm_setlocale(LC_COLLATE,"");
130+
init_locale(LC_COLLATE,"");
130131

131132
if ((env_locale=getenv("LC_CTYPE"))!=NULL)
132-
pg_perm_setlocale(LC_CTYPE,env_locale);
133+
init_locale(LC_CTYPE,env_locale);
133134
else
134-
pg_perm_setlocale(LC_CTYPE,"");
135+
init_locale(LC_CTYPE,"");
135136
}
136137
#else
137-
pg_perm_setlocale(LC_COLLATE,"");
138-
pg_perm_setlocale(LC_CTYPE,"");
138+
init_locale(LC_COLLATE,"");
139+
init_locale(LC_CTYPE,"");
139140
#endif
140141

141142
#ifdefLC_MESSAGES
142-
pg_perm_setlocale(LC_MESSAGES,"");
143+
init_locale(LC_MESSAGES,"");
143144
#endif
144145

145146
/*
146147
* We keep these set to "C" always, except transiently in pg_locale.c; see
147148
* that file for explanations.
148149
*/
149-
pg_perm_setlocale(LC_MONETARY,"C");
150-
pg_perm_setlocale(LC_NUMERIC,"C");
151-
pg_perm_setlocale(LC_TIME,"C");
150+
init_locale(LC_MONETARY,"C");
151+
init_locale(LC_NUMERIC,"C");
152+
init_locale(LC_TIME,"C");
152153

153154
/*
154155
* Now that we have absorbed as much as we wish to from the locale
@@ -294,6 +295,23 @@ startup_hacks(const char *progname)
294295
}
295296

296297

298+
/*
299+
* Make the initial permanent setting for a locale category. If that fails,
300+
* perhaps due to LC_foo=invalid in the environment, use locale C. If even
301+
* that fails, perhaps due to out-of-memory, the entire startup fails with it.
302+
* When this returns, we are guaranteed to have a setting for the given
303+
* category's environment variable.
304+
*/
305+
staticvoid
306+
init_locale(intcategory,constchar*locale)
307+
{
308+
if (pg_perm_setlocale(category,locale)==NULL&&
309+
pg_perm_setlocale(category,"C")==NULL)
310+
elog(FATAL,"could not adopt C locale");
311+
}
312+
313+
314+
297315
/*
298316
* Help display should match the options accepted by PostmasterMain()
299317
* and PostgresMain().

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp