nginx中ngx_cycle_s的conf_ctx初始化
admin
2024-05-11 19:50:12
0

ngx_cycle_t

是结构体ngx_cycle_s的别名

typedef struct ngx_cycle_s           ngx_cycle_t;

结构体ngx_cycle_s的定义

struct ngx_cycle_s {void                  ****conf_ctx;ngx_pool_t               *pool;ngx_log_t                *log;ngx_log_t                 new_log;ngx_uint_t                log_use_stderr;  /* unsigned  log_use_stderr:1; */ngx_connection_t        **files;ngx_connection_t         *free_connections;ngx_uint_t                free_connection_n;ngx_module_t            **modules;ngx_uint_t                modules_n;ngx_uint_t                modules_used;    /* unsigned  modules_used:1; */ngx_queue_t               reusable_connections_queue;ngx_uint_t                reusable_connections_n;time_t                    connections_reuse_time;ngx_array_t               listening;ngx_array_t               paths;ngx_array_t               config_dump;ngx_rbtree_t              config_dump_rbtree;ngx_rbtree_node_t         config_dump_sentinel;ngx_list_t                open_files;ngx_list_t                shared_memory;ngx_uint_t                connection_n;ngx_uint_t                files_n;ngx_connection_t         *connections;ngx_event_t              *read_events;ngx_event_t              *write_events;ngx_cycle_t              *old_cycle;ngx_str_t                 conf_file;ngx_str_t                 conf_param;ngx_str_t                 conf_prefix;ngx_str_t                 prefix;ngx_str_t                 error_log;ngx_str_t                 lock_file;ngx_str_t                 hostname;
};

conf_ctx

创建

在ngx_init_cycle中创建conf_ctx,分配内存。创建ngx_max_module个void* 内存块

cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));if (cycle->conf_ctx == NULL) {ngx_destroy_pool(pool);return NULL;}

第一次赋值

模块类型为CORE_MODULE,调用核心模块的create_conf方法来分配内存

for (i = 0; cycle->modules[i]; i++) {if (cycle->modules[i]->type != NGX_CORE_MODULE) {continue;}module = cycle->modules[i]->ctx;if (module->create_conf) {rv = module->create_conf(cycle);if (rv == NULL) {ngx_destroy_pool(pool);return NULL;}cycle->conf_ctx[cycle->modules[i]->index] = rv;}}

核心模块中有create_conf的模块有

模块

create_conf方法

ngx_core_module

ngx_core_module_create_conf

ngx_openssl_module

ngx_openssl_create_conf

ngx_google_perftools_module

ngx_google_perftools_create_conf

ngx_regex_module

ngx_regex_create_conf

ngx_thread_pool_module

ngx_thread_pool_create_conf

解析模块类型为CORE_MODULE且命令类型为NGX_MAIN_CONF

模块

命令名

命令处理

ngx_core_module

daemon

ngx_conf_set_flag_slot

master_process

ngx_conf_set_flag_slot

timer_resolution

ngx_conf_set_msec_slot

pid

ngx_conf_set_str_slot

lock_file

ngx_conf_set_str_slot

worker_processes

ngx_set_worker_processes

debug_points

ngx_conf_set_enum_slot

user

ngx_set_user

worker_priority

ngx_set_priority

worker_cpu_affinity

ngx_set_cpu_affinity

worker_rlimit_nofile

ngx_conf_set_num_slot

worker_rlimit_core

ngx_conf_set_off_slot

worker_shutdown_timeout

ngx_conf_set_msec_slot

working_directory

ngx_conf_set_str_slot

env

ngx_set_env

load_module

ngx_load_module

ngx_events_module

events

ngx_events_block

ngx_openssl_module

ssl_engine

ngx_openssl_engine

ngx_google_perftools_module

google_perftools_profiles

ngx_conf_set_str_slot

ngx_http_module

http

ngx_http_block

ngx_errlog_module

error_log

ngx_error_log

ngx_mail_module

mail

ngx_mail_block

ngx_regex_module

pcre_jit

ngx_conf_set_flag_slot

ngx_stream_module

stream

ngx_stream_block

ngx_thread_pool_module

thread_pool

ngx_thread_pool

第二次赋值

是在ngx_conf_handler中的判断命令类型是否是NGX_MAIN_CONF,此时(((void **) cf->ctx)[cf->cycle->modules[i]->index])是对应模块的配置信息的地址,其存的值是NULL。

通过命令接口的set方法来设置conf

ngx_conf_handler

if (cmd->type & NGX_DIRECT_CONF) {conf = ((void **) cf->ctx)[cf->cycle->modules[i]->index];} else if (cmd->type & NGX_MAIN_CONF) {conf = &(((void **) cf->ctx)[cf->cycle->modules[i]->index]);} else if (cf->ctx) {confp = *(void **) ((char *) cf->ctx + cmd->conf);if (confp) {conf = confp[cf->cycle->modules[i]->ctx_index];}}rv = cmd->set(cf, cmd, conf);

根据命令类型是否是NGX_DIRECT_CONF还是NGX_MAIN_CONF,模块中有命令类型是NGX_DIRECT_CONF则其子接口中都有create_conf方法。

ngx_core_module核心模块中的命令都是NGX_DIRECT_CONF类型

相关内容

热门资讯

【看表情包学Linux】进程地...   🤣 爆笑教程 👉 《看表情包学Linux》👈 猛...
育碧GDC2018程序化大世界... 1.传统手动绘制森林的问题 采用手动绘制的方法的话,每次迭代地形都要手动再绘制森林。这...
编译原理陈火旺版第三章课后题答... 下面答案仅供参考! 1.编写一个对于 Pascal 源程序的预处理程序。该程序的作用是...
MacBookPro M2芯片... MacBookPro M2芯片下如何搭建React-Native环境目录软件下载环境配置 目录 写在...
Android studio ... 解决 Android studio 出现“The emulator process for AVD ...
pyflink学习笔记(六):... 在pyflink学习笔记(一)中简单介绍了table-sql的窗口函数,下面简单介绍下...
创建deployment 创建deployment服务编排-DeploymentDeployment工作负载均衡器介绍Depl...
gma 1.1.4 (2023... 新增   1、地图工具    a. 增加【GetWorldDEMDataSet】。提供了一套 GEO...
AI专业教您保姆级在暗影精灵8... 目录 一、Stable Diffusion介绍    二、Stable Diffusion环境搭建 ...
vue笔记 第一个Vue应用 Document{{content}}{{...
Unity自带类 --- Ti... 1.在Unity中,自己写的类(脚本)的名字不能与Unit...
托福口语21天——day5 发... 目录 一、连读纠音 二、语料输入+造句输出 三、真题 一、连读纠音 英语中的连读方式有好几种...
五、排序与分页 一、排序 1、语法 ORDER BY 字段 ASC | DESC ASC(ascen...
Linux系统中如何安装软件 文章目录一、rpm包安装方式步骤:二、deb包安装方式步骤:三、tar....
开荒手册4——Related ... 0 写在前面 最早读文献的时候,每每看到related work部分都会选择性的忽略&...
实验01:吃鸡蛋问题 1.实验目的: 通过实验理解算法的概念、算法的表示、算法的时间复杂度和空间复杂度分析&...
8个免费图片/照片压缩工具帮您... 继续查看一些最好的图像压缩工具,以提升用户体验和存储空间以及网站使用支持。 无数图像压...
Spring Cloud Al... 前言 本文小新为大家带来 Sentinel控制台规则配置 相关知识,具体内容包括流控...
多项目同时进行,如何做好进度管... 多项目同时进行,如何做好进度管理? 大多数时候,面对项目进...
ATTCK红队评估实战靶场(二... 前言 第二个靶机来喽,地址:vulunstack 环境配置 大喊一声我...