openresty/patches/nginx-1.21.4-privileged_age...

74 lines
3.0 KiB
C
Raw Normal View History

2021-11-04 09:01:23 +00:00
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);