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 ...
随机推荐
- 多个SSH key对应多个Host: Github, Bitbucket
https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-lin ...
- 我的web前端之路 分享些前端的好书(转)
WEB前端研发工程师,在国内算是一个朝阳职业,这个领域没有学校的正规教育,大多数人都是靠自己自学成才.本文主要介绍自己从事web开发以来 (从大二至今)看过的书籍和自己的成长过程,目的是给想了解Jav ...
- K2 blackpearl 流程开发(二)
转:http://blog.csdn.net/gxiangzi/article/details/8444590 本来想一篇文章把流程开发介绍完的,后来发现实在是太多了,只好分成两部分了.上一篇很简单的 ...
- MyBatis学习 之 四、MyBatis配置文件
目录(?)[-] 四MyBatis主配置文件 properties属性 settings设置 typeAliases类型别名 typeHandlers类型句柄 ObjectFactory对象工厂 pl ...
- [Papers]NSE, $\pi$, Lorentz space [Suzuki, NA, 2012]
$$\bex \sen{\pi}_{L^{s,\infty}(0,T;L^{q,\infty}(\bbR^3))} \leq \ve_*, \eex$$ with $$\bex \frac{2}{s} ...
- UITextView 不左上角显示
在Autolayout中 UITextView显示不左上角显示,修改如下 在viewDidLoad里面添加如下代码 if([[[UIDevice currentDevice] systemVersio ...
- Java连接Oracle10g
1.导入驱动包: a.找到oracle安装目录下的jdbc/lib中的文件classes12.jar: b.右击你创建的JAVA工程,找到Build path,选择Add External Archi ...
- 仿酷狗音乐播放器开发日志二十五 duilib右键事件的不足的bug修复
转载请说明原出处,谢谢~~ 虽然仿酷狗的各个菜单早就写好了,但是一直没有附加到程序里.今天把菜单和播放列表控件关联时发现了问题. 和播放列表相关的菜单有三个,分别是每个音乐项目控件相关的菜单.分组的菜 ...
- 国内外开源与 SaaS ,团队协作平台、项目管理工具整理
整理一些开源与 SaaS ,团队协作平台.项目管理工具.还有哪些比较好的工具,可以推荐下? 名称 地址 备注 asana https://asana.com/ 国外 basecamp https:// ...
- MorningSale 介绍
MorningSale是一个WEB端的收集门店销售数据,显示销售数据的简单系统,我相信该系统能够有效的提高销售公司在门店销售数据收集 汇总 分析方面的工作效率. 主要功能介绍如下: 1.查看某个店面 ...