Complete nginx source code annotation (9) nginx. C: ngx_get_options

Source: Internet
Author: User

This article analyzes the ngx_get_options function in ngxin. C, and its impact:

In nginx. C:

static ngx_uint_t   ngx_show_help;static ngx_uint_t   ngx_show_version;static ngx_uint_t   ngx_show_configure;static u_char      *ngx_prefix;static u_char      *ngx_conf_file;  static u_char      *ngx_conf_params;    static char        *ngx_signal;

In ngx_cycle.c:

ngx_uint_t             ngx_test_config;ngx_uint_t             ngx_quiet_mode;

In ngx_process_cycle.c (src/OS/Win32 or SRC/OS/Unix:

ngx_uint_t    ngx_process;

The scope of these variables is limited from static to nginx. c files. The ngx_get_options function is as follows:

// Input two parameters of main function: argc and argvstatic ngx_int_tngx_get_options (INT argc, char * const * argv) {u_char * P; ngx_int_t I; // For each argv (note that it starts from 1 because 0 is "nginx") for (I = 1; I <argc; I ++) {// P is the address of the I parameter P = (u_char *) argv [I]; // If (* P ++! = '-') {Ngx_log_stderr (0, "invalid option: \" % s \ "", argv [I]); Return ngx_error ;} // The reason for the while loop is that a minus sign can carry a parameter, such as-HV while (* P) {// note that P is added with 1 switch (* P ++) {// question mark and H both display help information and version information case '? ': Case 'H': ngx_show_version = 1; ngx_show_help = 1; break; // small v displays the version information case 'V': ngx_show_version = 1; break; // case 'V': ngx_show_version = 1; ngx_show_configure = 1; break; // T is used to test the configuration file case 'T ': ngx_test_config = 1; break; // Q indicates quiet mode case 'q': ngx_quiet_mode = 1; break; // P specifies prefix path case 'p': If (* P) {ngx_prefix = P; goto next;} If (argv [++ I]) {ngx_prefix = (u_char *) argv [I]; goto next;} ngx_log_stderr (0, "option \"-p \ "requires directory name"); Return ngx_error; // use the specified configuration file case 'C': If (* P) {ngx_conf_file = P; goto next;} If (argv [++ I]) {ngx_conf_file = (u_char *) argv [I]; goto next;} ngx_log_stderr (0, "option \"-C \ "requires file name"); Return ngx_error; // set the Global Command case 'G' outside the configuration file: If (* P) {ngx_conf_params = P; goto next;} If (argv [++ I]) {ngx_conf_params = (u_char *) argv [I]; goto next;} ngx_log_stderr (0, "option \"-g \ "requires parameter"); Return ngx_error; // If (* P) {// The next parameter follows-s, for example,-sstop ngx_signal = (char *) P;} else if (argv [++ I]) {// The next parameter ngx_signal = argv [I];} else {//-S does not include the ngx_log_stderr (0, "option \"-S \ "requires parameter "); return ngx_error;} // The Four signals correspond to: Stop, exit, re-open the file (log file, etc.), re-load the configuration file if (ngx_strcmp (ngx_signal, "stop ") = 0 | ngx_strcmp (ngx_signal, "quit") = 0 | ngx_strcmp (ngx_signal, "Reopen") = 0 | ngx_strcmp (ngx_signal, "reload ") = 0) {ngx_process = ngx_process_signaller; goto next;} ngx_log_stderr (0, "invalid option: \"-S % s \ "", ngx_signal); Return ngx_error; default: ngx_log_stderr (0, "invalid option: \" % C \ "", * (p-1); Return ngx_error ;}} next: continue;} return ngx_ OK ;}

The help information is as follows:

Options:  -?,-h         : this help  -v            : show version and exit  -V            : show version and configure options then exit  -t            : test configuration and exit  -q            : suppress non-error messages during configuration testing  -s signal     : send signal to a master process: stop, quit, reopen, reload  -p prefix     : set prefix path (default: /usr/local/nginx/)  -c filename   : set configuration file (default: conf/nginx.conf)  -g directives : set global directives out of configuration file

The V version information is as follows:

nginx version: nginx/1.3.5

The V version information is as follows:

nginx version: nginx/1.3.5built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) configure arguments: --with-pcre=/home/michael/packages.d/pcre-8.20 --with-zlib=/home/michael/packages.d/zlib-1.2.7

Complete nginx source code annotation (9) nginx. C: ngx_get_options

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.