[nginx源碼分析]主函數解析,nginx源碼

來源:互聯網
上載者:User

[nginx源碼分析]主函數解析,nginx源碼

ngx_strerror_init

         函數主要是先把錯誤資訊儲存在ngx_sys_errlist數組裡面,做一個errno->errmsg的映射數組,當系統發生錯誤時候,直接就可以通過errno找到errmsg,減少api調用。

ngx_get_options(argc, argv)

這個函數主要是根據使用者的輸入設定一些旗變數and儲存使用者輸入的參數。

Paramflag?/hngx_show_version=1/ngx_show_help=1vngx_show_version=1Vngx_show_version=1/ngx_show_configure=1tngx_test_config=1qngx_quiet_mode=1pngx_prefix=argv[index]支援-p/home/work/nginx or –p /home/work/nginxcngx_conf_file=p支援方式同上gngx_conf_param=p支援方式同上sngx_signal=p/ngx_process=NGX_PROCESS_SIGNALLER(stop、quit、reopen、reload)

ngx_time_init->ngx_time_update

         通過加鎖和解鎖,來更新如下時間

variableformatngx_cached_time = tp;ngx_cached_http_time.data = p0;“Mon, 28 Sep 1970 06:00:00 GMT”ngx_cached_err_log_time.data = p1;“1970/09/28 12:00:00”ngx_cached_http_log_time.data = p2;“28/Sep/1970:12:00:00 +0600”ngx_cached_http_log_iso8601.data = p3        “1970-09-28T12:00:00+06:00”

         ngx_regex_init()

         主要設定兩個pcre全域的分配和回收函數

         ngx_pid = getpid();//擷取主進程pid

         ngx_log_init(ngx_prefix)
#if (NGX_WIN32)     if (name[1] != ':') {#else     if (name[0] != '/') {#endif         if (prefix) {             plen = ngx_strlen(prefix);//如果使用者輸入了-p prefix         } else {#ifdef NGX_PREFIX             prefix = (u_char *) NGX_PREFIX;//使用者沒輸入,使用configure路徑             plen = ngx_strlen(prefix);#else             plen = 0;#endif         }         if (plen) {             name = malloc(plen + nlen + 2);             if (name == NULL) {                 return NULL;             }             p = ngx_cpymem(name, prefix, plen);//copy prefix             if (!ngx_path_separator(*(p - 1))) {                 *p++ = '/';             }             ngx_cpystrn(p, (u_char *) NGX_ERROR_LOG_PATH, nlen + 1);//copy path             p = name;         }     }

最後返回值和函數構造的ngx_log

ngx_log{ngx_log.file = &ngx_log_file;{ngx_fd_tfd;//開啟的錯誤記錄檔ngx_str_tname;//未設定u_char*buffer;//未設定u_char*pos;//未設定u_char*last;//未設定}log_level = NGX_LOG_NOTICE;}

init_cycle.pool = ngx_create_pool(1024, log);//分配一塊記憶體池節點,具體的記憶體池,可

詳見記憶體池分析文檔

ngx_save_argv

函數把使用者輸入的參數儲存在ngx_argv數組裡面去

ngx_process_options

這個函數主要是處理使用者輸入的參數,設定檔、測試組態檔案、

conf_file =/home/work/hunter/nginx/nginx_gdb/conf/nginx.conf

conf_prefix =/home/work/hunter/nginx/nginx_gdb/conf

prefix =/home/work/hunter/nginx/nginx_gdb

 

ngx_crc32_table_init()//初始化crc表

//設定每一個模組的模組索引

ngx_max_module = 0;for (i = 0; ngx_modules[i]; i++) {ngx_modules[i]->index = ngx_max_module++;}

然後分析配置解析

ngx_init_cycl()


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.