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

    继续分析

    下面的是获取运行此程序的用户名称,主要还是为了防止在linux下用root来运行的情形。

        effective_user = get_id();
        if (strlen(username) == 0)
            username = effective_user;

    接下来,是准备好一写预备生成的文件的名称变量:

        set_input(&bki_file, "postgres.bki");
        set_input(&desc_file, "postgres.description");
        set_input(&shdesc_file, "postgres.shdescription");
        set_input(&hba_file, "pg_hba.conf.sample");
        set_input(&ident_file, "pg_ident.conf.sample");
        set_input(&conf_file, "postgresql.conf.sample");
        set_input(&conversion_file, "conversion_create.sql");
        set_input(&dictionary_file, "snowball_create.sql");
        set_input(&info_schema_file, "information_schema.sql");
        set_input(&features_file, "sql_features.txt");
        set_input(&system_views_file, "system_views.sql");

    接下来,这个函数很有趣,是为了information_schema的版本信息的:

        set_info_version();

    展开后可以看到:

    调试其代码,可以得到  infoversion 的信息是:09.01.0002

    /*
     * extract the strange version of version required for information schema
     * (09.08.0007abc)
     */
    static void
    set_info_version(void)
    {
        char       *letterversion;
        long        major = 0,
                    minor = 0,
                    micro = 0;
        char       *endptr;
        char       *vstr = xstrdup(PG_VERSION);
        char       *ptr;
    
        ptr = vstr + (strlen(vstr) - 1);
        while (ptr != vstr && (*ptr < '0' || *ptr > '9'))
            ptr--;
        letterversion = ptr + 1;
        major = strtol(vstr, &endptr, 10);
        if (*endptr)
            minor = strtol(endptr + 1, &endptr, 10);
        if (*endptr)
            micro = strtol(endptr + 1, &endptr, 10);
        snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s",
                 major, minor, micro, letterversion);
    
    }

    接下来,看这个,因为没设置debug状态之类的,所以可以跳过:

        if (show_setting || debug)
        {
            fprintf(stderr,
                    "VERSION=%s
    "
                    "PGDATA=%s
    share_path=%s
    PGPATH=%s
    "
                    "POSTGRES_SUPERUSERNAME=%s
    POSTGRES_BKI=%s
    "
                    "POSTGRES_DESCR=%s
    POSTGRES_SHDESCR=%s
    "
                    "POSTGRESQL_CONF_SAMPLE=%s
    "
                    "PG_HBA_SAMPLE=%s
    PG_IDENT_SAMPLE=%s
    ",
                    PG_VERSION,
                    pg_data, share_path, bin_path,
                    username, bki_file,
                    desc_file, shdesc_file,
                    conf_file,
                    hba_file, ident_file);
            if (show_setting)
                exit(0);
        }

    再往下看:

        check_input(bki_file);
        check_input(desc_file);
        check_input(shdesc_file);
        check_input(hba_file);
        check_input(ident_file);
        check_input(conf_file);
        check_input(conversion_file);
        check_input(dictionary_file);
        check_input(info_schema_file);
        check_input(features_file);
        check_input(system_views_file);

    check_input,在这里是检查文件是否存在。

    其实,postgres.bki等文件,都位于 src/backend/catalog目录下......

    接下来:

        setlocales();

    展开后看:发现得到的 locale 变量是个空值。

    /*
     * set up the locale variables
     *
     * assumes we have called setlocale(LC_ALL,"")
     */
    static void
    setlocales(void)
    {
        /* set empty lc_* values to locale config if set */
    
        if (strlen(locale) > 0)
        {
            if (strlen(lc_ctype) == 0)
                lc_ctype = locale;
            if (strlen(lc_collate) == 0)
                lc_collate = locale;
            if (strlen(lc_numeric) == 0)
                lc_numeric = locale;
            if (strlen(lc_time) == 0)
                lc_time = locale;
            if (strlen(lc_monetary) == 0)
                lc_monetary = locale;
            if (strlen(lc_messages) == 0)
                lc_messages = locale;
        }
    
        /*
         * override absent/invalid config settings from initdb's locale settings
         */
    
        if (strlen(lc_ctype) == 0 || !check_locale_name(lc_ctype))
            lc_ctype = xstrdup(setlocale(LC_CTYPE, NULL));
        if (strlen(lc_collate) == 0 || !check_locale_name(lc_collate))
            lc_collate = xstrdup(setlocale(LC_COLLATE, NULL));
        if (strlen(lc_numeric) == 0 || !check_locale_name(lc_numeric))
            lc_numeric = xstrdup(setlocale(LC_NUMERIC, NULL));
        if (strlen(lc_time) == 0 || !check_locale_name(lc_time))
            lc_time = xstrdup(setlocale(LC_TIME, NULL));
        if (strlen(lc_monetary) == 0 || !check_locale_name(lc_monetary))
            lc_monetary = xstrdup(setlocale(LC_MONETARY, NULL));
        if (strlen(lc_messages) == 0 || !check_locale_name(lc_messages))
    #if defined(LC_MESSAGES) && !defined(WIN32)
        {
            /* when available get the current locale setting */
            lc_messages = xstrdup(setlocale(LC_MESSAGES, NULL));
        }
    #else
        {
            /* when not available, get the CTYPE setting */
            lc_messages = xstrdup(setlocale(LC_CTYPE, NULL));
        }
    #endif}
  • 相关阅读:
    Java面试题(3)Java new一个对象的过程中发生了什么
    spring boot(九):Spring Boot中Redis的使用
    intellij idea 2018
    springboot(八)自定义Filter、自定义Property
    springboot(六)SpringBoot问题汇总
    Java Web之路(五)JSP
    Java
    instrument(2)
    Instrumentation(1)
    Dubbo中订阅和通知解析
  • 原文地址:https://www.cnblogs.com/gaojian/p/3174072.html
Copyright © 2011-2022 走看看