Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(2)

详解(2)


1. 复制配置前缀(conf_prefix

c 复制代码
    cycle->conf_prefix.len = old_cycle->conf_prefix.len;
    cycle->conf_prefix.data = ngx_pstrdup(pool, &old_cycle->conf_prefix);
    if (cycle->conf_prefix.data == NULL) {
        ngx_destroy_pool(pool);
        return NULL;
    }

从旧周期复制 conf_prefix,用于定位配置文件
平滑重启:保持配置路径一致,避免重新解析路径导致的延迟。

ngx_pstrdup


2. 复制安装前缀(prefix

c 复制代码
cycle->prefix.len = old_cycle->prefix.len;
cycle->prefix.data = ngx_pstrdup(pool, &old_cycle->prefix);
if (cycle->prefix.data == NULL) {
    ngx_destroy_pool(pool);
    return NULL;
}

从旧周期复制 prefix(如 /usr/local/nginx/),用于解析相对路径。

路径一致性:确保模块或日志路径的正确解析,避免配置更新时路径失效。


3. 复制错误日志路径(error_log

c 复制代码
cycle->error_log.len = old_cycle->error_log.len;
cycle->error_log.data = ngx_pnalloc(pool, old_cycle->error_log.len + 1);
if (cycle->error_log.data == NULL) {
    ngx_destroy_pool(pool);
    return NULL;
}
ngx_cpystrn(cycle->error_log.data, old_cycle->error_log.data,
            old_cycle->error_log.len + 1);

继承错误日志路径 :复制旧周期的错误日志文件路径
日志连续性 :初始化阶段使用旧日志配置,避免日志记录中断。
字符串安全性 :通过 ngx_cpystrn 确保字符串以 \0 结尾,防止溢出。


4. 复制配置文件路径(conf_file

c 复制代码
cycle->conf_file.len = old_cycle->conf_file.len;
cycle->conf_file.data = ngx_pnalloc(pool, old_cycle->conf_file.len + 1);
if (cycle->conf_file.data == NULL) {
    ngx_destroy_pool(pool);
    return NULL;
}
ngx_cpystrn(cycle->conf_file.data, old_cycle->conf_file.data,
            old_cycle->conf_file.len + 1);

继承配置文件路径:复制旧周期的配置文件路径


5. 复制配置参数(conf_param

c 复制代码
cycle->conf_param.len = old_cycle->conf_param.len;
cycle->conf_param.data = ngx_pstrdup(pool, &old_cycle->conf_param);
if (cycle->conf_param.data == NULL) {
    ngx_destroy_pool(pool);
    return NULL;
}

继承命令行配置参数 :复制通过 -g 参数传递的配置
参数保留:确保新周期保留启动时的动态配置,避免参数丢失。


相关推荐
HIT_Weston1 天前
18、【Ubuntu】【远程开发】技术方案分析:私网ip掩码
linux·tcp/ip·ubuntu
韩立学长1 天前
基于Springboot的旧时月历史论坛4099k6s9(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·后端
TDengine (老段)1 天前
TDengine 字符串函数 CONCAT_WS 用户手册
android·大数据·数据库·时序数据库·tdengine·涛思数据
IT 小阿姨(数据库)1 天前
PostgreSQL 之上的开源时序数据库 TimescaleDB 详解
运维·数据库·sql·postgresql·开源·centos·时序数据库
熊文豪1 天前
openEuler 云原生实战:部署高性能 Redis 集群与压测分析
数据库·redis·云原生·openeuler
GTgiantech1 天前
科普SFP 封装光模块教程
服务器·网络·数据库
深圳市恒讯科技1 天前
如何在服务器上安装和配置数据库(如MySQL)?
服务器·数据库·mysql
天一生水water1 天前
ubuntu使用毫秒镜像方式安装docker mysql
ubuntu·阿里云·docker
言之。1 天前
TiDB分布式数据库技术架构概述
数据库·分布式·tidb
万事大吉CC1 天前
SQL表设计与约束教程
数据库·sql