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

    /*
* 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. 【周期串】NYOJ-1121 周期串

    [题目链接:NYOJ-1121] 例如:abcabcabc 该字符串的长度为9,那么周期串的长度len只可能为{1,3,9},否则就不可能构成周期串. 接下来,就是要在各周期间进行比较.描述不清... ...

  2. js一些平时会用到的

    如何屏蔽页面js错误    <script language="javascript">    function killErrors()    {        re ...

  3. 漂亮灵活设置的jquery通知提示插件toastr

    toastr是一款非常棒的基于jquery库的非阻塞通知提示插件,toastr可设定四种通知模式:成功,出错,警告,提示,而提示窗口的位置,动画效果都可以通过能数来设置,在官方站可以通过勾选参数来生成 ...

  4. iOS 7 自定义Back按钮 与 Pop interactive gesture 问题

    1.自定义Back按钮 iOS中很多时候我们都会自定义返回按钮,也是一件easy的事,类似如下: // 返回按钮 1 - (void)showNavBackButton { UIButton *bac ...

  5. Visual Studio 2010中创建ASP.Net Web Service

    转自:http://blog.csdn.net/xinyaping/article/details/7331375 很多人在论坛里说,在Visual Studio 2010中不能创建“ASP.Net ...

  6. SQL注入中利用XP_cmdshell提权的用法(转)

    先来介绍一下子服务器的基本情况,windows 2000 adv server 中文版,据称 打过了sp3,asp+iis+mssql .首先扫描了一下子端口,呵呵,开始的一般步骤. 端口21开放: ...

  7. Perfect Service

    题意: n个节点树,在一个节点放上一台服务器可以给相邻的其他各点提供服务且一个节点只能接受一台服务器,求使n个节点都被服务放的服务器的最小数量. 分析: 不算太难,状态想的差不多,但是考虑不全面状态方 ...

  8. HDU5715 XOR 游戏 二分+字典树+dp

    当时Astar复赛的时候只做出1题,赛后补题(很长时间后才补,懒真是要命),发现这是第二简单的 分析: 这个题,可以每次二分区间的最小异或和 进行check的时候用dp进行判断,dp[i][j]代表前 ...

  9. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 list_selection_should_be(self, locator, *items)

    def list_selection_should_be(self, locator, *items): """Verifies the selection of sel ...

  10. 【软件多国语言】一个demo

    之前上学的时候做过一个东西,需要中英文软件界面,并且需要随时可以切换,当时是师妹来做的,用的最直接也是最笨的办法, what? if(中文) { button1.Text = "花姑娘&qu ...