继续:下面的是定义信号处理函数。

    /*
* 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 源代码分析之九的更多相关文章

  1. PostgreSQL的 initdb 源代码分析之十九

    继续分析: setup_dictionary(); 展开: 其中: cmd 是:"/home/pgsql/project/bin/postgres" --single -F -O ...

  2. PostgreSQL的initdb 源代码分析之六

    继续分析 下面的是获取运行此程序的用户名称,主要还是为了防止在linux下用root来运行的情形. effective_user = get_id(); ) username = effective_ ...

  3. PostgreSQL的 initdb 源代码分析之二

    继续分析 下面这一段,当 initdb --version 或者  initdb --help 才有意义. ) { ], || strcmp(argv[], ) { usage(progname); ...

  4. PostgreSQL的 initdb 源代码分析之二十四

    继续分析: make_template0(); 展开: 无需再作解释,就是创建template0数据库 /* * copy template1 to template0 */ static void ...

  5. PostgreSQL的 initdb 源代码分析之十五

    继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend( ...

  6. PostgreSQL的 initdb 源代码分析之十三

    继续分析: /* Bootstrap template1 */ bootstrap_template1(); 展开: 我这里读入的文件是:/home/pgsql/project/share/postg ...

  7. PostgreSQL的 initdb 源代码分析之十二

    继续分析 /* Now create all the text config files */ setup_config(); 将其展开: 实质就是,确定各种参数,分别写入 postgresql.co ...

  8. PostgreSQL的 initdb 源代码分析之十一

    继续分析: /* Top level PG_VERSION is checked by bootstrapper, so make it first */ write_version_file(NUL ...

  9. PostgreSQL的 initdb 源代码分析之七

    继续分析:由于我使用initdb的时候,没有指定 locale,所以会使用OS的缺省locale,这里是 en_US.UTF-8 printf(_("The files belonging ...

随机推荐

  1. HDU 3844 Mining Your Own Business(割点,经典)

    题意: 给出一个连通图,要求将某些点涂黑,使得无论哪个点(包括相关的边)撤掉后能够成功使得剩下的所有点能够到达任意一个涂黑的点,颜料不多,涂黑的点越少越好,并输出要涂几个点和有多少种涂法. 思路: 要 ...

  2. c& c++ enum

    1.为什么要用enum       写程序时,我们常常需要为某个对象关联一组可选alternative属性.例如,学生的成绩分A,B,C,D等,天气分sunny, cloudy, rainy等等.   ...

  3. 【Mac】Mac键盘实现Home, End, Page UP, Page DOWN

     * Home键=Fn+左方向    * End键=Fn+右方向    * PageUP=Fn+上方向    * PageDOWN=Fn+下方向    * 向后删除=Fn+delete  * Find ...

  4. Struts2中通配符

    1.Struts2中通配符可通过请求的url路径来确定包.类.方法.返回值名. 如 <action name="*_*_*_*" class="cn.javass. ...

  5. oracle 统计语句 与常见函数的归纳(未完待续)

    一.统计语句 1. count count(*)与count(0)语句的区别: count(*)统计所有数量 count(0)统计第一列不为空的 2. 两个统计量的减法 select (select ...

  6. C# Adding Hyperlink to Windows Form z

    When creating a Windows form in C#, we would like to create a hyperlink so that when the user click ...

  7. Python--类使用

    类使用的几个注意点: 1. 类的语法结构:2. __init__(self),3. __metaclass__=type, (新式类)4. super(subclassname, self).__in ...

  8. bzoj 3143 [Hnoi2013]游走(贪心,高斯消元,期望方程)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3143 [题意] 给定一个无向图,从1走到n,走过一条边得到的分数为边的标号,问一个边的 ...

  9. [Hive-Tutorial] What Is Hive

    What Is Hive Hive is a data warehousing infrastructure based on Hadoop. Hadoop provides massive scal ...

  10. MLE MAP EM

    1.最大似然估计 (MLE):  什么是最大似然估计?     问题:给定一组观察数据还有一个参数待定的模型,如何来估计这个未知参数呢? 观察数据(x1,y1)......(xn,yn)   待定模型 ...