PostgreSQL的 initdb 源代码分析之四
继续分析:
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 源代码分析之四的更多相关文章
- PostgreSQL的initdb 源代码分析之六
继续分析 下面的是获取运行此程序的用户名称,主要还是为了防止在linux下用root来运行的情形. effective_user = get_id(); ) username = effective_ ...
- 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 ...
随机推荐
- HDU 3844 Mining Your Own Business(割点,经典)
题意: 给出一个连通图,要求将某些点涂黑,使得无论哪个点(包括相关的边)撤掉后能够成功使得剩下的所有点能够到达任意一个涂黑的点,颜料不多,涂黑的点越少越好,并输出要涂几个点和有多少种涂法. 思路: 要 ...
- View.VISIBLE、INVISIBLE、GONE的区别
android中UI应用的开发中经常会使用view.setVisibility()来设置控件的可见性,其中该函数有3个可选值,他们有着不同的含义: View.VISIBLE--->可见View. ...
- CMake实践(2)
一,本期目标: [~@localhost t2]$ cat README this is README├── CMakeLists.txt├── COPYRIGHT├── doc│ └── hel ...
- Android中GridView滚动到底部加载数据终极版
之前在项目中有一个需求是需要GridView控件,滚动到底部自动加载.但是呢GridView控件并不提供诸如ListView监听滚动到底部的onScrollListener方法,为了实现这样一个效果, ...
- 《Python CookBook2》 第一章 文本 - 每次处理一个字符 && 字符和字符值之间的转换
文本 - 总结: 什么是文本Python 中的string 类型是不可变类型.文本,一个字符的矩阵,每一个单独的文本快可以被缩进和组织起来. 基本的文本操作①解析数据并将数据放入程序内部的结构中:②将 ...
- ARM指令集----杂项指令
ARM指令集可以分为6类,即是跳转指令,数据处理指令,程序状态传输指令,Load.Store指令,协处理器指令和异常中断指令 跳转指令: 在ARM中有两种方式可以实现程序的跳转,一种是跳转指令,另一种 ...
- [GRYZ2015]INCR
题目描述 数列 A1,A2,...,AN,修改最少的数字,使得数列严格单调递增. 输入格式 第 1 行,1 个整数 N 第 2 行,N 个整数 A1,A2,...,AN 输出格式 1 个整数,表示最少 ...
- springMVC(注解版笔记)
springMVC(注解版) 较之于非注解版本,发生一下变化: 1.配置文件需要配置的标签有: <!-- 包的扫描,此包下面的所有包都启用注解 --> <context:compon ...
- 用Python操作Mysql
平时的主要编程语言是Java,开发时也主要用Mysql,经常为了测试,调试的目的需要操作数据库,比如备份,插入测试数据,修改测试数据,有些时候不能简单的用SQL就能完成任务,或都很好的完成任务,用Ja ...
- CentOS7 mariadb 修改编码
CentOS7 mariadb 编码的修改: 网上看了不少的解决方案,要么是比较老的,要么是不正确,测试成功的方式,记录备查. 登录MySQL,使用SHOW VARIABLES LIKE 'chara ...