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

Commit05bb4fc

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 parent6168300 commit05bb4fc

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);
@@ -122,31 +123,31 @@ main(int argc, char *argv[])
122123
char*env_locale;
123124

124125
if ((env_locale=getenv("LC_COLLATE"))!=NULL)
125-
pg_perm_setlocale(LC_COLLATE,env_locale);
126+
init_locale(LC_COLLATE,env_locale);
126127
else
127-
pg_perm_setlocale(LC_COLLATE,"");
128+
init_locale(LC_COLLATE,"");
128129

129130
if ((env_locale=getenv("LC_CTYPE"))!=NULL)
130-
pg_perm_setlocale(LC_CTYPE,env_locale);
131+
init_locale(LC_CTYPE,env_locale);
131132
else
132-
pg_perm_setlocale(LC_CTYPE,"");
133+
init_locale(LC_CTYPE,"");
133134
}
134135
#else
135-
pg_perm_setlocale(LC_COLLATE,"");
136-
pg_perm_setlocale(LC_CTYPE,"");
136+
init_locale(LC_COLLATE,"");
137+
init_locale(LC_CTYPE,"");
137138
#endif
138139

139140
#ifdefLC_MESSAGES
140-
pg_perm_setlocale(LC_MESSAGES,"");
141+
init_locale(LC_MESSAGES,"");
141142
#endif
142143

143144
/*
144145
* We keep these set to "C" always, except transiently in pg_locale.c; see
145146
* that file for explanations.
146147
*/
147-
pg_perm_setlocale(LC_MONETARY,"C");
148-
pg_perm_setlocale(LC_NUMERIC,"C");
149-
pg_perm_setlocale(LC_TIME,"C");
148+
init_locale(LC_MONETARY,"C");
149+
init_locale(LC_NUMERIC,"C");
150+
init_locale(LC_TIME,"C");
150151

151152
/*
152153
* Now that we have absorbed as much as we wish to from the locale
@@ -278,6 +279,23 @@ startup_hacks(const char *progname)
278279
}
279280

280281

282+
/*
283+
* Make the initial permanent setting for a locale category. If that fails,
284+
* perhaps due to LC_foo=invalid in the environment, use locale C. If even
285+
* that fails, perhaps due to out-of-memory, the entire startup fails with it.
286+
* When this returns, we are guaranteed to have a setting for the given
287+
* category's environment variable.
288+
*/
289+
staticvoid
290+
init_locale(intcategory,constchar*locale)
291+
{
292+
if (pg_perm_setlocale(category,locale)==NULL&&
293+
pg_perm_setlocale(category,"C")==NULL)
294+
elog(FATAL,"could not adopt C locale");
295+
}
296+
297+
298+
281299
/*
282300
* Help display should match the options accepted by PostmasterMain()
283301
* and PostgresMain().

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp