zoukankan      html  css  js  c++  java
  • PostgreSQL的 initdb 源代码分析之十

    继续分析,

    如下这段,因为条件不成立,被跳过:

        /* Create transaction log symlink, if required */
        if (strcmp(xlog_dir, "") != 0)
        {
    
            fprintf(stderr,"In main function -----------------190
    ");
    
            char       *linkloc;
    
            /* clean up xlog directory name, check it's absolute */
            canonicalize_path(xlog_dir);
            if (!is_absolute_path(xlog_dir))
            {
                fprintf(stderr, _("%s: transaction log directory location must be an absolute path
    "), progname);
                exit_nicely();
            }
    
            /* check if the specified xlog directory exists/is empty */
            switch (pg_check_dir(xlog_dir))
            {
                case 0:
                    /* xlog directory not there, must create it */
                    printf(_("creating directory %s ... "),
                           xlog_dir);
                    fflush(stdout);
    
                    if (pg_mkdir_p(xlog_dir, S_IRWXU) != 0)
                    {
                        fprintf(stderr, _("%s: could not create directory "%s": %s
    "),
                                progname, xlog_dir, strerror(errno));
                        exit_nicely();
                    }
                    else
                        check_ok();
    
                    made_new_xlogdir = true;
                    break;
    
                case 1:
                    /* Present but empty, fix permissions and use it */
                    printf(_("fixing permissions on existing directory %s ... "),
                           xlog_dir);
                    fflush(stdout);
    
                    if (chmod(xlog_dir, S_IRWXU) != 0)
                    {
                        fprintf(stderr, _("%s: could not change permissions of directory "%s": %s
    "),
                                progname, xlog_dir, strerror(errno));
                        exit_nicely();
                    }
                    else
                        check_ok();
    
                    found_existing_xlogdir = true;
                    break;
    
                case 2:
                    /* Present and not empty */
                    fprintf(stderr,
                            _("%s: directory "%s" exists but is not empty
    "),
                            progname, xlog_dir);
                    fprintf(stderr,
                     _("If you want to store the transaction log there, either
    "
                       "remove or empty the directory "%s".
    "),
                            xlog_dir);
                    exit_nicely();
    
                default:
                    /* Trouble accessing directory */
                    fprintf(stderr, _("%s: could not access directory "%s": %s
    "),
                            progname, xlog_dir, strerror(errno));
                    exit_nicely();
            }
    
            /* form name of the place where the symlink must go */
            linkloc = (char *) pg_malloc(strlen(pg_data) + 8 + 1);
            sprintf(linkloc, "%s/pg_xlog", pg_data);
    
    #ifdef HAVE_SYMLINK
            if (symlink(xlog_dir, linkloc) != 0)
            {
                fprintf(stderr, _("%s: could not create symbolic link "%s": %s
    "),
                        progname, linkloc, strerror(errno));
                exit_nicely();
            }
    #else
            fprintf(stderr, _("%s: symlinks are not supported on this platform"));
            exit_nicely();
    #endif
        }

    接下来:

    开始创建各个子目录

        /* Create required subdirectories */
        printf(_("creating subdirectories ... "));
        fflush(stdout);
    
        for (i = 0; i < (sizeof(subdirs) / sizeof(char *)); i++)
        {
            if (!mkdatadir(subdirs[i]))
                exit_nicely();
        }

    加入调试代码后,可以看到,上述建立的各子目录分别是:

    subdirs[0] is: global

    subdirs[1] is: pg_xlog

    subdirs[2] is: pg_xlog/archive_status

    subdirs[3] is: pg_clog

    subdirs[4] is: pg_notify

    subdirs[5] is: pg_serial

    subdirs[6] is: pg_subtrans

    subdirs[7] is: pg_twophase

    subdirs[8] is: pg_multixact/members

    subdirs[9] is: pg_multixact/offsets

    subdirs[10] is: base

    subdirs[11] is: base/1

    subdirs[12] is: pg_tblspc

    subdirs[13] is: pg_stat_tmp

    想起来了,前面有过定义的:

        static const char *subdirs[] = {
            "global",
            "pg_xlog",
            "pg_xlog/archive_status",
            "pg_clog",
            "pg_notify",
            "pg_serial",
            "pg_subtrans",
            "pg_twophase",
            "pg_multixact/members",
            "pg_multixact/offsets",
            "base",
            "base/1",
            "pg_tblspc",
            "pg_stat_tmp"
        };

    而接下来,就是:

        check_ok();

    这个check_ok ,其注释就说得很清楚:

    /*
     * call exit_nicely() if we got a signal, or else output "ok".
     */
    static void
    check_ok(void)
    {
        if (caught_signal)
        {
            printf(_("caught signal
    "));
            fflush(stdout);
            exit_nicely();
        }
        else if (output_failed)
        {
            printf(_("could not write to child process: %s
    "),
                   strerror(output_errno));
            fflush(stdout);
            exit_nicely();
        }
        else
        {
            /* all seems well */
            printf(_("ok
    "));
            fflush(stdout);
        }
    }
  • 相关阅读:
    Oracle的列操作(增加列,修改列,删除列),包括操作多列
    txt文本怎么去除重复项
    Javascript去掉字符串前后空格
    Js作用域链及变量作用域
    js变量以及其作用域详解
    如何在sqlserver 的函数或存储过程中抛出异常。
    存储过程如何处理异常
    设置VS2010和IE8 调试ATL控件<转>
    YUV图像合成原理<转>
    VS2013 查看程序各个函数的CPU利用率<转>
  • 原文地址:https://www.cnblogs.com/gaojian/p/3177146.html
Copyright © 2011-2022 走看看