From 65e905ea032f65e7d13f3196f5feb9e07e7d68d2 Mon Sep 17 00:00:00 2001 From: drawing Date: Mon, 28 Oct 2024 17:20:24 +0800 Subject: [PATCH] add change pipe size command --- auto/modules | 1 + src/core/nginx.c | 23 +++++++++++++++++++++++ src/core/ngx_cycle.h | 5 +++++ src/os/unix/ngx_pipe.c | 10 ++++++++++ 4 files changed, 39 insertions(+) diff --git a/auto/modules b/auto/modules index 561dc49219..0ff138f58b 100644 --- a/auto/modules +++ b/auto/modules @@ -1454,6 +1454,7 @@ END have=T_NGX_DNS_RESOLVE_BACKUP . auto/have have=T_NGX_MASTER_ENV . auto/have have=T_PIPES . auto/have +have=T_PIPE_SET_SIZE . auto/have have=T_NGX_INPUT_BODY_FILTER . auto/have have=T_NGX_GZIP_CLEAR_ETAG . auto/have have=T_NGX_RESOLVER_FILE . auto/have diff --git a/src/core/nginx.c b/src/core/nginx.c index 05d1f8c1d3..0a91d23b66 100755 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -166,6 +166,15 @@ static ngx_command_t ngx_core_commands[] = { #endif +#if (T_PIPE_SET_SIZE) + { ngx_string("pipe_set_size"), + NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_size_slot, + 0, + offsetof(ngx_core_conf_t, pipe_size), + NULL }, +#endif + ngx_null_command }; @@ -1148,6 +1157,10 @@ ngx_core_module_create_conf(ngx_cycle_t *cycle) return NULL; } +#ifdef T_PIPE_SET_SIZE + ccf->pipe_size = NGX_CONF_UNSET_SIZE; +#endif + return ccf; } @@ -1282,6 +1295,16 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf) #endif +#ifdef T_PIPE_SET_SIZE + if (ccf->pipe_size != NGX_CONF_UNSET_SIZE) { + if (ccf->pipe_size < 64 * 1024) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, + "\"pipe_size\" must be at least 64K, ignored"); + return NGX_CONF_ERROR; + } + } +#endif + return NGX_CONF_OK; } diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index 2494e952b9..700c3269b9 100755 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -133,6 +133,11 @@ typedef struct { char **environment; ngx_uint_t transparent; /* unsigned transparent:1; */ + +#if (T_PIPE_SET_SIZE) + size_t pipe_size; +#endif + } ngx_core_conf_t; diff --git a/src/os/unix/ngx_pipe.c b/src/os/unix/ngx_pipe.c index c8d2b9336b..b6ec08d50d 100644 --- a/src/os/unix/ngx_pipe.c +++ b/src/os/unix/ngx_pipe.c @@ -438,6 +438,16 @@ ngx_open_pipe(ngx_cycle_t *cycle, ngx_open_pipe_t *op) return NGX_ERROR; } +#ifdef T_PIPE_SET_SIZE + if (ccf->pipe_size != NGX_CONF_UNSET_SIZE && ccf->pipe_size != 0) { + if (fcntl(op->pfd[1], F_SETPIPE_SZ, ccf->pipe_size) == -1) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + "set pipe size (%d) failed", ccf->pipe_size); + goto err; + } + } +#endif + argv = op->argv->elts; if ((pid = fork()) < 0) {