Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add change pipe size command #1965

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions auto/modules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/core/nginx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/ngx_cycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
12 changes: 11 additions & 1 deletion src/os/unix/ngx_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Loading