开始第一段:

int
main(int argc, char *argv[])
{
/*
* options with no short version return a low integer, the rest return
* their short version value
*/
static struct option long_options[] = {
{"pgdata", required_argument, NULL, 'D'},
{"encoding", required_argument, NULL, 'E'},
{"locale", required_argument, NULL, },
{"lc-collate", required_argument, NULL, },
{"lc-ctype", required_argument, NULL, },
{"lc-monetary", required_argument, NULL, },
{"lc-numeric", required_argument, NULL, },
{"lc-time", required_argument, NULL, },
{"lc-messages", required_argument, NULL, },
{"no-locale", no_argument, NULL, },
{"text-search-config", required_argument, NULL, 'T'},
{"auth", required_argument, NULL, 'A'},
{"pwprompt", no_argument, NULL, 'W'},
{"pwfile", required_argument, NULL, },
{"username", required_argument, NULL, 'U'},
{"help", no_argument, NULL, '?'},
{"version", no_argument, NULL, 'V'},
{"debug", no_argument, NULL, 'd'},
{"show", no_argument, NULL, 's'},
{"noclean", no_argument, NULL, 'n'},
{"xlogdir", required_argument, NULL, 'X'},
{NULL, , NULL, }
}; int c,i,ret;
int option_index;
char *effective_user;
char *pgdenv; /* PGDATA value gotten from and sent to
* environment */
char bin_dir[MAXPGPATH];
char *pg_data_native;
int user_enc; #ifdef WIN32
char *restrict_env;
#endif
static const char *subdirs[] = {
"global",
"pg_xlog",
"pg_xlog/archive_status",
"pg_clog",
"pg_notify",
"pg_serial",
"pg_subtrans",
"pg_twophase",
"pg_multixact/members",
"pg_multixact/offsets",
"base",
"base/1",
"pg_tblspc",
"pg_stat_tmp"
}; progname = get_progname(argv[]); set_pglocale_pgservice(argv[], PG_TEXTDOMAIN("initdb"));
......
}

上述程序部分运行后,get_progname的返回值是:

progname ----------initdb
而我传递给 get_progname的参数 argv[0] 是 : /home/pgsql/project/bin/initdb

再来看 set_pglocale_pgservice函数:

此时传递的第一个参数是:  /home/pgsql/project/bin/initdb  传递的第二个参数是:initdb-9.1

由于  set_pglocale_pgservice 也会被postgres进程所调用,所以需要第二个参数来明确调用者。

/*
* set_pglocale_pgservice
*
* Set application-specific locale and service directory
*
* This function takes the value of argv[0] rather than a full path.
*
* (You may be wondering why this is in exec.c. It requires this module's
* services and doesn't introduce any new dependencies, so this seems as
* good as anyplace.)
*/
void
set_pglocale_pgservice(const char *argv0, const char *app)
{
char path[MAXPGPATH];
char my_exec_path[MAXPGPATH];
char env_path[MAXPGPATH + sizeof("PGSYSCONFDIR=")]; /* longer than
* PGLOCALEDIR */
/* don't set LC_ALL in the backend */
if (strcmp(app, PG_TEXTDOMAIN("postgres")) != )
setlocale(LC_ALL, ""); if (find_my_exec(argv0, my_exec_path) < )
return;
#ifdef ENABLE_NLS
get_locale_path(my_exec_path, path);
bindtextdomain(app, path);
textdomain(app); if (getenv("PGLOCALEDIR") == NULL)
{
/* set for libpq to use */
snprintf(env_path, sizeof(env_path), "PGLOCALEDIR=%s", path);
canonicalize_path(env_path + );
putenv(strdup(env_path));
}
#endif if (getenv("PGSYSCONFDIR") == NULL)
{ get_etc_path(my_exec_path, path); /* set for libpq to use */
snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path);
canonicalize_path(env_path + );
putenv(strdup(env_path)); }
}

实际上,运行时,得到的

my_exec_path :          /home/pgsql/project/bin/initdb
env_path :                  PGSYSCONFDIR=/home/pgsql/project/etc

PostgreSQL的 initdb 源代码分析之一的更多相关文章

  1. PostgreSQL的initdb 源代码分析之六

    继续分析 下面的是获取运行此程序的用户名称,主要还是为了防止在linux下用root来运行的情形. effective_user = get_id(); ) username = effective_ ...

  2. PostgreSQL的 initdb 源代码分析之二

    继续分析 下面这一段,当 initdb --version 或者  initdb --help 才有意义. ) { ], || strcmp(argv[], ) { usage(progname); ...

  3. PostgreSQL的 initdb 源代码分析之二十四

    继续分析: make_template0(); 展开: 无需再作解释,就是创建template0数据库 /* * copy template1 to template0 */ static void ...

  4. PostgreSQL的 initdb 源代码分析之十五

    继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend( ...

  5. PostgreSQL的 initdb 源代码分析之十三

    继续分析: /* Bootstrap template1 */ bootstrap_template1(); 展开: 我这里读入的文件是:/home/pgsql/project/share/postg ...

  6. PostgreSQL的 initdb 源代码分析之十二

    继续分析 /* Now create all the text config files */ setup_config(); 将其展开: 实质就是,确定各种参数,分别写入 postgresql.co ...

  7. PostgreSQL的 initdb 源代码分析之十一

    继续分析: /* Top level PG_VERSION is checked by bootstrapper, so make it first */ write_version_file(NUL ...

  8. PostgreSQL的 initdb 源代码分析之七

    继续分析:由于我使用initdb的时候,没有指定 locale,所以会使用OS的缺省locale,这里是 en_US.UTF-8 printf(_("The files belonging ...

  9. PostgreSQL的initdb 源代码分析之五

    接前面,继续分析: putenv("TZ=GMT") 设置了时区信息. find_other_exec(argv[0], "postgres", PG_BACK ...

  10. PostgreSQL的 initdb 源代码分析之四

    继续分析: if (pwprompt && pwfilename) { fprintf(stderr, _("%s: password prompt and password ...

随机推荐

  1. JS全局变量VAR和THIS

    (注意)JS全局变量VAR和THIS 很多人都觉得在javascript声明一个变量,加var和不加var没有什么区别,实际上是一个错误的观点,如果在函数外面,也就是说在window区域加不加var确 ...

  2. NALU(NAL单元)

    一 NALU类型    标识NAL单元中的RBSP数据类型,其中,nal_unit_type为1, 2, 3, 4, 5及12的NAL单元称为VCL的NAL单元,其他类型的NAL单元为非VCL的NAL ...

  3. 《C++ Primer 4th》读书笔记 第3章-标准库类型

        原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3911534.html

  4. ECshop 二次开发模板教程2

    不知道大家是学会用循环了呢,还是我的言语实在有问题,大家实在无法完成阅读哦,居然大家都没有问题,暂时心里安慰,把他当做好事情,大家都会调用了,呵呵,那我们继续循环调用商品了!好,继续在我们昨天的基础上 ...

  5. JS触发ASP.NET服务器端控件的方法

    <asp:Button ID="Button_regId" runat="server" Font-Bold="False" OnCl ...

  6. SQL Server 2012安装时如何不安装自带的Visual Studio

    不安装以下两个:

  7. 《Python核心编程》 第十章 错误和异常

    10–1. 引发异常. 以下的哪个因素会在程序执行时引发异常? 注意这里我们问的并不是异常的原因. a) 用户 b) 解释器 c) 程序 d) 以上所有 e) 只有 b) 和 c) f) 只有 a) ...

  8. jQuery常用的正则表达式

    [导读] 本文章提供了大量的jQuery正则表达式,有电话号码,密码,用户名,邮箱,哈能输入字符等,有需要的朋友可以参考一下. 代码如下复制代码 <!DOCTYPE html PUBLIC &q ...

  9. 使用Redis的理由

    Redis是一个远程内存数据库,它不仅性能强劲,而且还具有复制特性以及为解决问题而生的独一无二的数据模型.Redis提供了5种不同类型的数据结构,各式各样的问题都可以很自然地映射到这些数据结构上:Re ...

  10. 数往知来C#之面向对象准备〈一〉

    1.CLR加载编译源文件 注1.:当你点击调试或者生成解决方案的时候这就是一个编译过程首先CLR加载源文件也就是你写的代码(此代码在文件中是字符串)然后将项目中的嗲吗编译成IL代码进而生成程序集 证明 ...