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 ...
随机推荐
- HDU 3844 Mining Your Own Business(割点,经典)
题意: 给出一个连通图,要求将某些点涂黑,使得无论哪个点(包括相关的边)撤掉后能够成功使得剩下的所有点能够到达任意一个涂黑的点,颜料不多,涂黑的点越少越好,并输出要涂几个点和有多少种涂法. 思路: 要 ...
- atoi&itoa
char* itoa(int num,char*str,int radix) {/*索引表*/ char index[]="0123456789ABCDEFGHIJKLMNOPQRSTUVW ...
- SVN版本管理提示信息
1. FAQ 1.路径或权限不足时将出现错误信息提示: http://192.134.4.251/svn/svnproject(路径不对)Error * PROPFIND request failed ...
- delphi 当月的第一天, 当月的最后一天
//取当月的第一天function TDealWithXML.FDOM(Date: TDateTime): TDateTime;var Year, Month, Day: Word;begin Dec ...
- HDU 5122 K.Bro Sorting
K.Bro Sorting Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Tot ...
- Eclipse中设置在创建新类时自动生成注释的方法
windows–>preference Java–>Code Style–>Code Templates code–>new Java files 编辑它 ${filecom ...
- 将spfile存储在ASM中
数据库的spfile开始是存储在普通的文件系统中,如下所示: SQL> show parameter spfile NAME TYPE VALUE ----------------------- ...
- Vim小知识
在退出vim编辑的时候,强制退出是q! 感叹号在前,即!q,表示执行外部shell命令,感叹号在后,即q!,表示强制执行vi命令.
- 数往知来C#之面向对象准备〈一〉
1.CLR加载编译源文件 注1.:当你点击调试或者生成解决方案的时候这就是一个编译过程首先CLR加载源文件也就是你写的代码(此代码在文件中是字符串)然后将项目中的嗲吗编译成IL代码进而生成程序集 证明 ...
- bzoj 1798 [Ahoi2009]Seq 维护序列seq(线段树+传标)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1798 [题意] 给定一个序列,要求提供区间乘/加,以及区间求和的操作 [思路] 线段树 ...