PostgreSQL的initdb 源代码分析之六
继续分析
下面的是获取运行此程序的用户名称,主要还是为了防止在linux下用root来运行的情形。
effective_user = get_id();
if (strlen(username) == )
username = effective_user;
接下来,是准备好一写预备生成的文件的名称变量:
set_input(&bki_file, "postgres.bki");
set_input(&desc_file, "postgres.description");
set_input(&shdesc_file, "postgres.shdescription");
set_input(&hba_file, "pg_hba.conf.sample");
set_input(&ident_file, "pg_ident.conf.sample");
set_input(&conf_file, "postgresql.conf.sample");
set_input(&conversion_file, "conversion_create.sql");
set_input(&dictionary_file, "snowball_create.sql");
set_input(&info_schema_file, "information_schema.sql");
set_input(&features_file, "sql_features.txt");
set_input(&system_views_file, "system_views.sql");
接下来,这个函数很有趣,是为了information_schema的版本信息的:
set_info_version();
展开后可以看到:
调试其代码,可以得到 infoversion 的信息是:09.01.0002
/*
* extract the strange version of version required for information schema
* (09.08.0007abc)
*/
static void
set_info_version(void)
{
char *letterversion;
long major = ,
minor = ,
micro = ;
char *endptr;
char *vstr = xstrdup(PG_VERSION);
char *ptr; ptr = vstr + (strlen(vstr) - );
while (ptr != vstr && (*ptr < '' || *ptr > ''))
ptr--;
letterversion = ptr + ;
major = strtol(vstr, &endptr, );
if (*endptr)
minor = strtol(endptr + , &endptr, );
if (*endptr)
micro = strtol(endptr + , &endptr, );
snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s",
major, minor, micro, letterversion); }
接下来,看这个,因为没设置debug状态之类的,所以可以跳过:
if (show_setting || debug)
{
fprintf(stderr,
"VERSION=%s\n"
"PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
"POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
"POSTGRES_DESCR=%s\nPOSTGRES_SHDESCR=%s\n"
"POSTGRESQL_CONF_SAMPLE=%s\n"
"PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
PG_VERSION,
pg_data, share_path, bin_path,
username, bki_file,
desc_file, shdesc_file,
conf_file,
hba_file, ident_file);
if (show_setting)
exit();
}
再往下看:
check_input(bki_file);
check_input(desc_file);
check_input(shdesc_file);
check_input(hba_file);
check_input(ident_file);
check_input(conf_file);
check_input(conversion_file);
check_input(dictionary_file);
check_input(info_schema_file);
check_input(features_file);
check_input(system_views_file);
check_input,在这里是检查文件是否存在。
其实,postgres.bki等文件,都位于 src/backend/catalog目录下......
接下来:
setlocales();
展开后看:发现得到的 locale 变量是个空值。
/*
* set up the locale variables
*
* assumes we have called setlocale(LC_ALL,"")
*/
static void
setlocales(void)
{
/* set empty lc_* values to locale config if set */ if (strlen(locale) > )
{
if (strlen(lc_ctype) == )
lc_ctype = locale;
if (strlen(lc_collate) == )
lc_collate = locale;
if (strlen(lc_numeric) == )
lc_numeric = locale;
if (strlen(lc_time) == )
lc_time = locale;
if (strlen(lc_monetary) == )
lc_monetary = locale;
if (strlen(lc_messages) == )
lc_messages = locale;
} /*
* override absent/invalid config settings from initdb's locale settings
*/ if (strlen(lc_ctype) == || !check_locale_name(lc_ctype))
lc_ctype = xstrdup(setlocale(LC_CTYPE, NULL));
if (strlen(lc_collate) == || !check_locale_name(lc_collate))
lc_collate = xstrdup(setlocale(LC_COLLATE, NULL));
if (strlen(lc_numeric) == || !check_locale_name(lc_numeric))
lc_numeric = xstrdup(setlocale(LC_NUMERIC, NULL));
if (strlen(lc_time) == || !check_locale_name(lc_time))
lc_time = xstrdup(setlocale(LC_TIME, NULL));
if (strlen(lc_monetary) == || !check_locale_name(lc_monetary))
lc_monetary = xstrdup(setlocale(LC_MONETARY, NULL));
if (strlen(lc_messages) == || !check_locale_name(lc_messages))
#if defined(LC_MESSAGES) && !defined(WIN32)
{
/* when available get the current locale setting */
lc_messages = xstrdup(setlocale(LC_MESSAGES, NULL));
}
#else
{
/* when not available, get the CTYPE setting */
lc_messages = xstrdup(setlocale(LC_CTYPE, NULL));
}
#endif}
PostgreSQL的initdb 源代码分析之六的更多相关文章
- PostgreSQL的 initdb 源代码分析之二
继续分析 下面这一段,当 initdb --version 或者 initdb --help 才有意义. ) { ], || strcmp(argv[], ) { usage(progname); ...
- PostgreSQL的 initdb 源代码分析之二十四
继续分析: make_template0(); 展开: 无需再作解释,就是创建template0数据库 /* * copy template1 to template0 */ static void ...
- PostgreSQL的 initdb 源代码分析之十五
继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend( ...
- PostgreSQL的 initdb 源代码分析之十三
继续分析: /* Bootstrap template1 */ bootstrap_template1(); 展开: 我这里读入的文件是:/home/pgsql/project/share/postg ...
- PostgreSQL的 initdb 源代码分析之十二
继续分析 /* Now create all the text config files */ setup_config(); 将其展开: 实质就是,确定各种参数,分别写入 postgresql.co ...
- PostgreSQL的 initdb 源代码分析之十一
继续分析: /* Top level PG_VERSION is checked by bootstrapper, so make it first */ write_version_file(NUL ...
- PostgreSQL的 initdb 源代码分析之七
继续分析:由于我使用initdb的时候,没有指定 locale,所以会使用OS的缺省locale,这里是 en_US.UTF-8 printf(_("The files belonging ...
- PostgreSQL的initdb 源代码分析之五
接前面,继续分析: putenv("TZ=GMT") 设置了时区信息. find_other_exec(argv[0], "postgres", PG_BACK ...
- PostgreSQL的 initdb 源代码分析之四
继续分析: if (pwprompt && pwfilename) { fprintf(stderr, _("%s: password prompt and password ...
随机推荐
- 【 D3.js 高级系列 】 总结
高级系列的教程已经完结,特此总结. 月初的时候曾说过本月内完结高级教程,今天是最后一天,算是可以交差了.O(∩_∩)O~ 如此一来,[入门]-[进阶]-[高级]三个系列的教程算是完成了.本教程的目的在 ...
- 当ASP.NET MVC模型验证遇上CKEditor
项目需要,使用到了CKEditor编辑器.这是个很不错的富文本编辑器,但是当它绑定的字段需要进行模型验证的时候,却会出现验证失效的问题.因此本文旨在记录这个问题和给出解决办法.以下以Validatio ...
- pl/sql developer 连接本地ORACLE 11g 64位数据库
1.登录PL/SQL Developer 这里省略Oracle数据库和PL/SQL Developer的安装步骤,注意在安装PL/SQL Developer软件时,不要安装在Program Files ...
- CSS的伪元素(二)
随便聊聊CSS的伪元素,虽然它们在项目开发中用的并不多,但确实很有用,在项目中不用它,是因为大家不能了解它们,下面是一个工作场景,如有四个按钮,分别是建立,编辑,删除和修改,而我们要求这在前台显示的汉 ...
- VS2013密匙
在网上找到的,亲测有用: BWG7X-J98B3-W34RT-33B3R-JVYW9
- HDU 1387 Team Queue
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- linux中vi保存文件时的“Can't open file for writing”
今天在ubuntu 13.04环境下,使用vi新建一个文件,编辑保存时提示“Can't open file for writing”. 分析: 出现这个错误的原因可能有两个: 一是当前用户的权限不足: ...
- HDU 3333-Turing Tree(BIT好题)
题意: 给你n个数的序列a,q个询问,每个询问给l,r,求在下标i在[l,r]的区间内不含重复数的和 分析: 这类题目觉得很好,很练思维,觉得不太好做. 用BIT维护和,我们可以从前向后扫一遍序列,当 ...
- Activating Google Cloud Storage
先决条件 你需要下面的内容: 1.一个Google账户,比如来自Gmail.如果你没有,请在Google account signup site注册. 2.一个新的或已经存在的Google Devel ...
- Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...