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

Commit3580397

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 parentaae12e4 commit3580397

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
@@ -50,6 +50,7 @@ const char *progname;
5050

5151

5252
staticvoidstartup_hacks(constchar*progname);
53+
staticvoidinit_locale(intcategory,constchar*locale);
5354
staticvoidhelp(constchar*progname);
5455
staticvoidcheck_root(constchar*progname);
5556
staticchar*get_current_username(constchar*progname);
@@ -111,31 +112,31 @@ main(int argc, char *argv[])
111112
char*env_locale;
112113

113114
if ((env_locale=getenv("LC_COLLATE"))!=NULL)
114-
pg_perm_setlocale(LC_COLLATE,env_locale);
115+
init_locale(LC_COLLATE,env_locale);
115116
else
116-
pg_perm_setlocale(LC_COLLATE,"");
117+
init_locale(LC_COLLATE,"");
117118

118119
if ((env_locale=getenv("LC_CTYPE"))!=NULL)
119-
pg_perm_setlocale(LC_CTYPE,env_locale);
120+
init_locale(LC_CTYPE,env_locale);
120121
else
121-
pg_perm_setlocale(LC_CTYPE,"");
122+
init_locale(LC_CTYPE,"");
122123
}
123124
#else
124-
pg_perm_setlocale(LC_COLLATE,"");
125-
pg_perm_setlocale(LC_CTYPE,"");
125+
init_locale(LC_COLLATE,"");
126+
init_locale(LC_CTYPE,"");
126127
#endif
127128

128129
#ifdefLC_MESSAGES
129-
pg_perm_setlocale(LC_MESSAGES,"");
130+
init_locale(LC_MESSAGES,"");
130131
#endif
131132

132133
/*
133134
* We keep these set to "C" always, except transiently in pg_locale.c; see
134135
* that file for explanations.
135136
*/
136-
pg_perm_setlocale(LC_MONETARY,"C");
137-
pg_perm_setlocale(LC_NUMERIC,"C");
138-
pg_perm_setlocale(LC_TIME,"C");
137+
init_locale(LC_MONETARY,"C");
138+
init_locale(LC_NUMERIC,"C");
139+
init_locale(LC_TIME,"C");
139140

140141
/*
141142
* Now that we have absorbed as much as we wish to from the locale
@@ -268,6 +269,23 @@ startup_hacks(const char *progname)
268269
}
269270

270271

272+
/*
273+
* Make the initial permanent setting for a locale category. If that fails,
274+
* perhaps due to LC_foo=invalid in the environment, use locale C. If even
275+
* that fails, perhaps due to out-of-memory, the entire startup fails with it.
276+
* When this returns, we are guaranteed to have a setting for the given
277+
* category's environment variable.
278+
*/
279+
staticvoid
280+
init_locale(intcategory,constchar*locale)
281+
{
282+
if (pg_perm_setlocale(category,locale)==NULL&&
283+
pg_perm_setlocale(category,"C")==NULL)
284+
elog(FATAL,"could not adopt C locale");
285+
}
286+
287+
288+
271289
/*
272290
* Help display should match the options accepted by PostmasterMain()
273291
* and PostgresMain().

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp