[Nginx source code analysis] Main Function parsing, nginx source code

Source: Internet
Author: User

[Nginx source code analysis] Main Function parsing, nginx source code

Ngx_strerror_init

The function stores the error information in the ngx_sys_errlist array and creates a ing array of errno-> errmsg. When an error occurs in the system, you can directly find errmsg through errno, reduce api calls.

Ngx_get_options (argc, argv)

This function is mainly used to set some flag variables based on user input and save user input parameters.

Paramflag? /Hngx_show_version = 1/ngx_show_help = region = 1vngx_show_version = 1/ngx_show_configure = region = 1pngx_prefix = argv [index] supports-p/home/work/nginx or-p/home/ work/nginxcngx_conf_file = p support method same as gngx_conf_param = p support method same as sngx_signal = p/ngx_process = NGX_PROCESS_SIGNALLER (stop, quit, reopen, reload)

Ngx_time_init-> ngx_time_update

Update the following time by locking and unlocking:

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 ()

It mainly sets two pcre global allocation and revocation functions.

Ngx_pid = getpid (); // Obtain the master process pid

Ngx_log_init (ngx_prefix)
# If (NGX_WIN32) if (name [1]! = ':') {# Else if (name [0]! = '/') {# Endif if (prefix) {plen = ngx_strlen (prefix ); // if the user inputs-p prefix} else {# ifdef NGX_PREFIX prefix = (u_char *) NGX_PREFIX; // if the user does not input it, use the configure path 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 ;}}

The final return value and the ngx_log constructed by the function

Ngx_log {ngx_log.file = & ngx_log_file; {ngx_fd_tfd; // The Error Log ngx_str_tname; // u_char * buffer is not set; // u_char * pos is not set; // u_char * last is not set; // not set} log_level = NGX_LOG_NOTICE ;}

Init_cycle.pool = ngx_create_pool (1024, log); // Allocate a memory pool node. The specific memory pool can be

For details, see the memory pool analysis document.

Ngx_save_argv

The function saves user input parameters in the ngx_argv array.

Ngx_process_options

This function is mainly used to process user input parameters, configuration files, test configuration files,

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 () // initialize the crc table

// Set the module index for each module

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

Analyze Configuration Analysis

Ngx_init_cycl ()


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.