1
0
mirror of https://github.com/openresty/openresty synced 2024-11-09 18:35:51 +01:00
openresty/patches/nginx-1.19.9-privileged_agent_process_connections.patch
Johnny Wang 7e1cf985cf
bugfix: check if the worker_connections is 0 before privileged agent spawning. (#786)
The core dump may occur during initialization

    Program terminated with signal SIGSEGV, Segmentation fault.
    #0  0x0000000000441711 in ngx_event_process_init (cycle=0x1e93cc0) at src/event/ngx_event.c:807
    801         i = cycle->connection_n;
    802         next = NULL;
    803
    804         do {
    805             i--;
    806
    807             c[i].data = next;
    #1  0x000000000044abb9 in ngx_worker_process_init (cycle=cycle@entry=0x1e93cc0, worker=worker@entry=-1) at src/os/unix/ngx_process_cycle.c:968
2021-11-09 14:23:33 +08:00

74 lines
3.0 KiB
C

diff --git a/src/core/nginx.c b/src/core/nginx.c
index 269ff84..48329bd 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -1062,6 +1062,7 @@ ngx_core_module_create_conf(ngx_cycle_t *cycle)
ccf->daemon = NGX_CONF_UNSET;
ccf->master = NGX_CONF_UNSET;
ccf->privileged_agent = NGX_CONF_UNSET;
+ ccf->privileged_agent_connections = NGX_CONF_UNSET_UINT;
ccf->timer_resolution = NGX_CONF_UNSET_MSEC;
ccf->shutdown_timeout = NGX_CONF_UNSET_MSEC;
@@ -1092,6 +1093,7 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_value(ccf->daemon, 1);
ngx_conf_init_value(ccf->master, 1);
ngx_conf_init_value(ccf->privileged_agent, 0);
+ ngx_conf_init_uint_value(ccf->privileged_agent_connections, 512);
ngx_conf_init_msec_value(ccf->timer_resolution, 0);
ngx_conf_init_msec_value(ccf->shutdown_timeout, 0);
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index 6a9583e..4469390 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -93,6 +93,7 @@ typedef struct {
ngx_flag_t daemon;
ngx_flag_t master;
ngx_flag_t privileged_agent;
+ ngx_uint_t privileged_agent_connections;
ngx_msec_t timer_resolution;
ngx_msec_t shutdown_timeout;
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index df25f9d..bd259c1 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -1179,6 +1179,7 @@ static void
ngx_privileged_agent_process_cycle(ngx_cycle_t *cycle, void *data)
{
char *name = data;
+ ngx_core_conf_t *ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
/*
* Set correct process type since closing listening Unix domain socket
@@ -1190,7 +1191,7 @@ ngx_privileged_agent_process_cycle(ngx_cycle_t *cycle, void *data)
ngx_close_listening_sockets(cycle);
/* Set a moderate number of connections for a helper process. */
- cycle->connection_n = 512;
+ cycle->connection_n = ccf->privileged_agent_connections;
ngx_worker_process_init(cycle, -1);
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index df25f9d..bd259c1 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -442,6 +442,15 @@
return;
}
+ /* 0 is an illegal value and may result in a core dump later */
+ if (ccf->privileged_agent_connections == 0) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
+ "%ui worker_connection is not enough, "
+ "privileged agent process cannot be spawned",
+ ccf->privileged_agent_connections);
+ return;
+ }
+
ngx_spawn_process(cycle, ngx_privileged_agent_process_cycle,
"privileged agent process", "privileged agent process",
respawn ? NGX_PROCESS_JUST_RESPAWN : NGX_PROCESS_RESPAWN);