继续分析:

    if (pwprompt && pwfilename)
{
fprintf(stderr, _("%s: password prompt and password file cannot be specified together\n"), progname);
exit();
} if (authmethod == NULL || !strlen(authmethod))
{
authwarning = _("\nWARNING: enabling \"trust\" authentication for local connections\n"
"You can change this by editing pg_hba.conf or using the -A option the\n"
"next time you run initdb.\n");
authmethod = "trust";
} if (strcmp(authmethod, "md5") &&
strcmp(authmethod, "peer") &&
strcmp(authmethod, "ident") &&
strcmp(authmethod, "trust") && #ifdef USE_PAM
strcmp(authmethod, "pam") &&
strncmp(authmethod, "pam ", ) && /* pam with space = param */
#endif strcmp(authmethod, "crypt") &&
strcmp(authmethod, "password")
) /*
* Kerberos methods not listed because they are not supported over
* local connections and are rejected in hba.c
*/
{
fprintf(stderr, _("%s: unrecognized authentication method \"%s\"\n"),
progname, authmethod);
exit();
} if ((!strcmp(authmethod, "md5") ||
!strcmp(authmethod, "crypt") ||
!strcmp(authmethod, "password")) &&
!(pwprompt || pwfilename))
{
fprintf(stderr, _("%s: must specify a password for the superuser to enable %s authentication\n"),
        progname, authmethod);
exit();
} /*
* When ident is specified, use peer for local connections. Mirrored, when
* peer is specified, use ident for TCP connections.
*/
if (strcmp(authmethod, "ident") == )
authmethodlocal = "peer";
else if (strcmp(authmethod, "peer") == )
{
authmethodlocal = "peer";
authmethod = "ident";
}
else
authmethodlocal = authmethod;

因为我在运行initdb的时候,未指定认证方式,所以缺省的认证方式将被设置为 trust。

接下来,因为我运行initdb是指定了 -D 参数,所以如下一段也被跳过:

    if (strlen(pg_data) == )
{
pgdenv = getenv("PGDATA");
if (pgdenv && strlen(pgdenv))
{
/* PGDATA found */
pg_data = xstrdup(pgdenv);
}
else
{
fprintf(stderr,
_("%s: no data directory specified\n"
"You must identify the directory where the data for this database system\n"
"will reside. Do this with either the invocation option -D or the\n"
"environment variable PGDATA.\n"),
progname);
exit();
}
}

接下来,canonicalize_path 是处理一些多余的/,或windows和unix平台的斜线和反斜线的统一处理。

    pg_data_native = pg_data;

    canonicalize_path(pg_data);

接下来,Win32平台相关代码也忽略:

#ifdef WIN32

    /*
* Before we execute another program, make sure that we are running with a
* restricted token. If not, re-execute ourselves with one.
*/ if ((restrict_env = getenv("PG_RESTRICT_EXEC")) == NULL
|| strcmp(restrict_env, "") != )
{
PROCESS_INFORMATION pi;
char *cmdline; ZeroMemory(&pi, sizeof(pi)); cmdline = xstrdup(GetCommandLine()); putenv("PG_RESTRICT_EXEC=1"); if (!CreateRestrictedProcess(cmdline, &pi))
{
fprintf(stderr, "Failed to re-exec with restricted token: %lu.\n", GetLastError());
}
else
{
/*
* Successfully re-execed. Now wait for child process to capture
* exitcode.
*/
DWORD x; CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE); if (!GetExitCodeProcess(pi.hProcess, &x))
{
fprintf(stderr, "Failed to get exit code from subprocess: %lu\n", GetLastError());
exit();
}
exit(x);
}
}
#endif

接下来,进行存储,也是和windows平台有点关系,加入了双引号:

    /*
* we have to set PGDATA for postgres rather than pass it on the command
* line to avoid dumb quoting problems on Windows, and we would especially
* need quotes otherwise on Windows because paths there are most likely to
* have embedded spaces.
*/
pgdenv = pg_malloc( + strlen(pg_data));
sprintf(pgdenv, "PGDATA=%s", pg_data);
putenv(pgdenv);

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 ...

随机推荐

  1. 【转】第一次使用Android Studio时你应该知道的一切配置(三):gradle项目构建

    原文网址:http://www.cnblogs.com/smyhvae/p/4456420.html [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.c ...

  2. 【转】Android Studio系列教程一--下载与安装

    原文网址:http://stormzhang.com/devtools/2014/11/25/android-studio-tutorial1/ 背景 相信大家对Android Studio已经不陌生 ...

  3. Android基于基于布局嵌套的页面导航实现

    页面如下: 主页面的布局分隔为三部分: 注意观察上面标记为红色的android:id均采用android系统默认的名称: 页面的导航组件: <?xml version="1.0&quo ...

  4. ZOJ 3329-One Person Game(概率dp,迭代处理环)

    题意: 三个色子有k1,2,k3个面每面标号(1-k1,1-k2,1-k3),一次抛三个色子,得正面向上的三个编号,若这三个标号和给定的三个编号a1,b1,c1对应则总和置零,否则总和加上三个色子标号 ...

  5. bjfu1250 模拟

    这题貌似是蓝桥杯的一题改了个题面. 就是模拟啦,应该有比我的更简洁的方法. 我的方法是把所有的人(蚂蚁)按位置排完序以后从左往右看,每次有一个向左走的,就会把最左边的t出,这个变成向右中,同时,从左端 ...

  6. The Automated Testing Handbook 自动化测试手册简介

    Learn what works, what doesn't and why. The Automated Testing Handbook is a practical blueprint for ...

  7. asp.net如何将DataSet转换成josn并输出

    public class JsonUtil { public string ToJson(DataSet dataSet) { string jsonString = "{"; f ...

  8. MVC和WebForm的优缺点对比

    1 WebForm优点 1)支持事件模型开发,得益于丰富的服务端组件,WebForm开发可以迅速的搭建Web应用 2)使用方便,入门容易 3)控件丰富的WebForm 2 WebForm缺点  1)封 ...

  9. 十字链表 Codeforces Round #367 E Working routine

    // 十字链表 Codeforces Round #367 E Working routine // 题意:给你一个矩阵,q次询问,每次交换两个子矩阵,问最后的矩阵 // 思路:暴力肯定不行.我们可以 ...

  10. leetcode@ [352] Data Stream as Disjoint Intervals (Binary Search & TreeSet)

    https://leetcode.com/problems/data-stream-as-disjoint-intervals/ Given a data stream input of non-ne ...