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 ...
随机推荐
- C扩展Python
基本想法: 先看中文小介绍,再看英文详细文档. 1. 参考 首先参考THIS, IBM的工程师好像出了好多这样的文章啊,而且每次看到时间戳,我都想戳自己- -! 2. ERROR 可能遇到错误: fa ...
- Java Socket(2): 异常处理
1 超时 套接字底层是基于TCP的,所以socket的超时和TCP超时是相同的.下面先讨论套接字读写缓冲区,接着讨论连接建立超时.读写超时以及JAVA套接字编程的嵌套异常捕获和一个超时例子程序的抓包示 ...
- wifi详解(四)
1 IOCTL的调用逻辑 之所以要分析这个,是因为上层wpa_supplicant和WIFI驱动打交道的方式,多半是通过ioctl的方式进行的,所以看看它的调用逻辑(这里只列出其主要的调 ...
- ArcGIS AO开发高亮显示某些要素
参考代码1 ifeaturecursor pcur = ifeatureclass.search(iqueryfilter pfilter); pfilter.whereclause = strAdd ...
- ylbtech-SubwayNav(地铁线路导航)-数据库设计
ylbtech-DatabaseDesgin:ylbtech-SubwayNav(地铁线路导航)-数据库设计 DatabaseName:SubwayNav(地铁线路导航) Type:线路导航 1.A, ...
- Redis,Memcache,mongoDB的区别
从以下几个维度,对redis.memcache.mongoDB 做了对比,欢迎拍砖 1.性能 都比较高,性能对我们来说应该都不是瓶颈 总体来讲,TPS方面redis和memcache差不多,要大于mo ...
- Apache OFBiz 学习笔记 之 服务引擎 二
加载服务定义文件 ofbiz-component.xml:所有的服务定义文件在每个组件的ofbi-component.xml文件中 加载服务定义 例:framework/common/ofbi ...
- 不知道帐号密码的情况下完全重装Mac Min的OS X10.7系统
现状: 1.原系统OS X 10.7 2.老账号不知道密码 3.Mac小盒子 目的: 1.删除老账号 2.更新系统到10.9以上 尝试过程1: 1.按住option键 + 开机 2.选择“磁盘工具” ...
- ASP.NET MVC之Html.RenderAction
WEB窗体模式开发惯了,切入MVC模式,好多东西都不懂,每一步都要查资料. 初步得来的一些知识点体会是: _Layout.cshtml就相当于母版页 然后partical视图(部分视图)就是用户控件. ...
- JAVA中的异常(异常处理流程、异常处理的缺陷)
异常处理流程 1)首先由try{...}catch(Exception e){ System.out.println(e); e.printStackTrace(); }finally{...}结构 ...