ngx_process_options函数详解
来源:互联网 发布:淘宝卖家工具有哪些 编辑:程序博客网 时间:2024/05/16 16:08
ngx_process_options是初始化init_cycle中的一些如: conf_file,prefix,conf_prefix等字段的功能, 其方法的定义在src/core/nginx.c中, 以下为详细代码:
主要功能是将ngx_prefix, 配置文件的位置信息, 以及命令行参数的信息初始化到cycle对象中。
static ngx_int_tngx_process_options(ngx_cycle_t *cycle){ u_char *p; size_t len; // 配置前缀信息初始化到cycle对象中 if (ngx_prefix) { // nginx.c中定义 static u_char *ngx_prefix; len = ngx_strlen(ngx_prefix); p = ngx_prefix; if (len && !ngx_path_separator(p[len - 1])) { // 长度不为0且最后一个字符不是路径分割符 #define ngx_path_separator(c) ((c) == '/') p = ngx_pnalloc(cycle->pool, len + 1); // 在内存池中分配空间存储ngx_prefix if (p == NULL) { return NGX_ERROR; } ngx_memcpy(p, ngx_prefix, len); p[len++] = '/'; // 最后还是添加上路径分割符'/' } cycle->conf_prefix.len = len; cycle->conf_prefix.data = p; cycle->prefix.len = len; cycle->prefix.data = p; } else {#ifndef NGX_PREFIX p = ngx_pnalloc(cycle->pool, NGX_MAX_PATH); // NGX_MAX_PATH即MAX_PATH, MAX_PATH定义在linux/limits.h
.#define PATH_MAX 4096
if (p == NULL) { return NGX_ERROR; } if (ngx_getcwd(p, NGX_MAX_PATH) == 0) { // 获取当前的路径, 保存在p中。 ngx_log_stderr(ngx_errno, "[emerg]: " ngx_getcwd_n " failed"); return NGX_ERROR; } len = ngx_strlen(p); p[len++] = '/'; cycle->conf_prefix.len = len; cycle->conf_prefix.data = p; cycle->prefix.len = len; cycle->prefix.data = p;#else#ifdef NGX_CONF_PREFIX ngx_str_set(&cycle->conf_prefix, NGX_CONF_PREFIX);#else ngx_str_set(&cycle->conf_prefix, NGX_PREFIX);#endif ngx_str_set(&cycle->prefix, NGX_PREFIX);#endif } // 配置文件信息初始化到cycle对象 if (ngx_conf_file) { cycle->conf_file.len = ngx_strlen(ngx_conf_file); cycle->conf_file.data = ngx_conf_file; } else { ngx_str_set(&cycle->conf_file, NGX_CONF_PATH); } if (ngx_conf_full_name(cycle, &cycle->conf_file, 0) != NGX_OK) { return NGX_ERROR; } for (p = cycle->conf_file.data + cycle->conf_file.len - 1; p > cycle->conf_file.data; p--) { if (ngx_path_separator(*p)) { cycle->conf_prefix.len = p - ngx_cycle->conf_file.data + 1; cycle->conf_prefix.data = ngx_cycle->conf_file.data; break; } } // 命令行参数初始化到cycle对象 if (ngx_conf_params) { cycle->conf_param.len = ngx_strlen(ngx_conf_params); cycle->conf_param.data = ngx_conf_params; } if (ngx_test_config) { cycle->log->log_level = NGX_LOG_INFO; } return NGX_OK;}
- ngx_process_options函数详解
- 函数详解
- API函数详解:CreateSemaphore函数
- sql函数 group_concat函数详解
- 仿函数 ( 函数对象 ) 详解
- send函数&recv函数详解
- scan函数函数用法详解
- 【函数】register_shutdown_function函数详解【原创】
- ASP函数详解
- DateDiff 函数详解
- ASP函数详解
- ASP函数详解
- ASP的函数详解
- Window.open函数详解
- ASP函数详解
- XML系列函数详解
- ASP函数详解
- 数据库函数详解
- Ruby on rails 实战圣经:ActiveRecord
- 广州电讯-开发部管理培训生(JAVA工程师)面试
- 使用expat开发xml分析器
- Oracle字符串连接的方法
- DataBinder.Eval(Container.DataItem
- ngx_process_options函数详解
- 和大伙伴做题-gym C. Figures
- 误删的照片找回有什么好的办法吗
- 多图详解Spring框架的设计理念与设计模式
- mdss 8x26/8x74 display debug and reading notes(vsync, interface and so on)
- 用expat解析包解析XML文件
- PE文件到内存的映射
- 老生常谈IE兼容性:ie6 javascript:void(0)、IE7 input透明、IE8 jquery动态加载css
- ORA-31655: no data or metadata objects selected for job