add change pipe size command

This commit is contained in:
drawing
2024-10-28 17:20:24 +08:00
parent 04baff4645
commit 583ceb1580
4 changed files with 40 additions and 1 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -428,7 +428,7 @@ ngx_open_pipe(ngx_cycle_t *cycle, ngx_open_pipe_t *op)
u_char **argv;
ngx_pid_t pid;
sigset_t set;
#ifdef T_PIPE_USE_USER
#if defined(T_PIPE_USE_USER) || defined(T_PIPE_SET_SIZE)
ngx_core_conf_t *ccf;
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
@@ -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) {