PostgreSQL的 initdb 源代码分析之九
继续:下面的是定义信号处理函数。
/*
* now we are starting to do real work, trap signals so we can clean up
*/ /* some of these are not valid on Windows */
#ifdef SIGHUP
pqsignal(SIGHUP, trapsig);
#endif
#ifdef SIGINT
pqsignal(SIGINT, trapsig);
#endif
#ifdef SIGQUIT
pqsignal(SIGQUIT, trapsig);
#endif
#ifdef SIGTERM
pqsignal(SIGTERM, trapsig);
#endif
#ifdef SIGPIPE
pqsignal(SIGPIPE, SIG_IGN);
#endif
SIGHUP: 我用 kill -HUP initdb的进程号,trapsig函数会收到 SIGHUP 信号,这是退出时候会收到的信号。
SIGINT: 我用 kill -INT initdb的进程号,trapsig函数会收到 SIGINT 信号,这是ctrl+c时会收到的信号。
SIGQUIT: ctrl+\ 时会受到的信号。
SIGTERM:
接下来:
switch (pg_check_dir(pg_data))
{
case :
/* PGDATA not there, must create it */
printf(_("creating directory %s ... "),
pg_data);
fflush(stdout); if (!mkdatadir(NULL))
exit_nicely();
else
check_ok(); made_new_pgdata = true;
break; case :
/* Present but empty, fix permissions and use it */
printf(_("fixing permissions on existing directory %s ... "),
pg_data);
fflush(stdout); if (chmod(pg_data, S_IRWXU) != )
{
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
progname, pg_data, strerror(errno));
exit_nicely();
}
else
check_ok(); found_existing_pgdata = true;
break; case :
/* Present and not empty */
fprintf(stderr,
_("%s: directory \"%s\" exists but is not empty\n"),
progname, pg_data);
fprintf(stderr,
_("If you want to create a new database system, either remove or empty\n"
"the directory \"%s\" or run %s\n"
"with an argument other than \"%s\".\n"),
pg_data, progname, pg_data);
exit(); /* no further message needed */ default:
/* Trouble accessing directory */
fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
progname, pg_data, strerror(errno));
exit_nicely();
}
此时,要看这个函数的效果:
/*
* Test to see if a directory exists and is empty or not.
*
* Returns:
* 0 if nonexistent
* 1 if exists and empty
* 2 if exists and not empty
* -1 if trouble accessing directory (errno reflects the error)
*/
int
pg_check_dir(const char *dir)
{
int result = ;
DIR *chkdir;
struct dirent *file; errno = ; chkdir = opendir(dir); if (chkdir == NULL)
return (errno == ENOENT) ? : -; while ((file = readdir(chkdir)) != NULL)
{
if (strcmp(".", file->d_name) == ||
strcmp("..", file->d_name) == )
{
/* skip this and parent directory */
continue;
}
else
{
result = ; /* not empty */
break;
}
} #ifdef WIN32 /*
* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
* released version
*/
if (GetLastError() == ERROR_NO_MORE_FILES)
errno = ;
#endif closedir(chkdir); if (errno != )
result = -; /* some kind of I/O error? */ return result;
}
按最正常的情况,我的目录存在而且为空,则 check_ok() 得到执行,而 found_existing_pgdata = true...
PostgreSQL的 initdb 源代码分析之九的更多相关文章
- PostgreSQL的 initdb 源代码分析之十九
继续分析: setup_dictionary(); 展开: 其中: cmd 是:"/home/pgsql/project/bin/postgres" --single -F -O ...
- 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 ...
随机推荐
- 【MySQL for Mac】终极解决——MySQL在Mac的字符集设置
这个问题烦恼一天了,现在终于得以解决.分享给大家 首先贴出来,亲测不可行的博客连接: http://www.2cto.com/database/201305/215563.html http://bl ...
- 【Mysql】初学命令行指南
MYSQL初学者使用指南与介绍 一.连接MYSQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1.例1:连接到本机上的MYSQL. 首先在打开DOS窗口,然后进入目录 mysqlbi ...
- PostgreSQL 8.4.1
PHP100资讯:PostgreSQL 是一种对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大.特性最丰富和最复杂的自由软件数据库系统.它起源于伯克利(BSD)的数据库研究计划,目前是最 ...
- c# 进行AE开发时,如何在地图上定位出一个点
一.文本形式的气泡提示框 由于本人是初学,所以具体的含义尚未弄清楚,直接给出代码吧!
- IOS 本地通知UILocalNotification
//发送通知 UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notificati ...
- mysql EF
使用 mysql-installer-community-5.6.26.0.msi visual studio 2013 update 4版 Install-Package EntityFramewo ...
- SOA和NS区别
SOA是起始权威服务器,在该服务器上可以新增和删除记录; NS服务器是笔试哪些DNS服务器可以解析该域名; 对于一个域(如baidu.com)SOA只有一个NS可以有多个. NS服务器包含SOA,SO ...
- JQuery WEB前段开发
JQuery WEB前段开发 Jquery是继prototype之后又一个优秀的Javascript框架.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, S ...
- mybatis系列-13-resultMap总结
resultType: 作用: 将查询结果按照sql列名pojo属性名一致性映射到pojo中. 场合: 常见一些明细记录的展示,比如用户购买商品明细,将关联查询信息全部展示在页面时,此时可直接使用re ...
- Ubuntu 软件包管理详解
原文转载自:http://www.cppblog.com/jb8164/archive/2009/01/09/71583.html Ubuntu 方便宜用,最值得让人称道的便是其安装软件的方式, 一条 ...