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

WIP: set log pipe size #1893

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions auto/unix
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ if [ $ngx_found = no ]; then
fi


ngx_feature="F_SETPIPE_SZ"
ngx_feature_name="T_NGX_HAVE_F_SETPIPE_SZ"
ngx_feature_run=no
ngx_feature_incs="#define _GNU_SOURCE
#include <fcntl.h>"
ngx_feature_path=
ngx_feature_libs=
ngx_feature_test="fcntl(0, F_SETPIPE_SZ, 65536)"
. auto/feature

ngx_feature="F_READAHEAD"
ngx_feature_name="NGX_HAVE_F_READAHEAD"
ngx_feature_run=no
Expand Down
58 changes: 58 additions & 0 deletions src/os/unix/ngx_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,48 @@ ngx_conf_open_pipe(ngx_cycle_t *cycle, ngx_str_t *cmd, const char *type)
ngx_uint_t i, j, numargs = 0;
ngx_array_t *argv_out;

#if (T_NGX_HAVE_F_SETPIPE_SZ)
u_char *sp;
ngx_int_t pipe_size = 0;
#endif

dup = ngx_pnalloc(cycle->pool, cmd->len + 1);
if (dup == NULL) {
return NULL;
}

(void) ngx_cpystrn(dup, cmd->data, cmd->len + 1);

#if (T_NGX_HAVE_F_SETPIPE_SZ)
if (ngx_strncmp(cmd->data, "size:", 5) == 0) {
cmd->len -= sizeof("size:") - 1;
cmd->data += sizeof("size:") - 1;

if (cmd->len <= 0) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"The size configuration of log pipe is incorrect");
return NULL;
}

for (sp = cmd->data; *sp != ':'; sp++) {}

pipe_size = ngx_atoi(cmd->data, sp - cmd->data);
if (pipe_size <= 0) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"The size configuration of log pipe is incorrect, size:%d",
pipe_size);
return NULL;
}

cmd->data = sp;
cmd->len -= pipe_size;

if (cmd->len <= 0) {
return NULL;
}
}
#endif

for (cp = cmd->data; *cp == ' ' || *cp == '\t'; cp++);
ct = cp;

Expand Down Expand Up @@ -180,6 +215,10 @@ ngx_conf_open_pipe(ngx_cycle_t *cycle, ngx_str_t *cmd, const char *type)
ngx_pipes[use].type = ti;
ngx_pipes[use].generation = ngx_pipe_generation;
ngx_pipes[use].configured = 1;
#if (T_NGX_HAVE_F_SETPIPE_SZ)
ngx_pipes[use].pipe_size = pipe_size;
#endif


return &ngx_pipes[use];
}
Expand Down Expand Up @@ -251,6 +290,25 @@ ngx_open_pipes(ngx_cycle_t *cycle)
return NGX_ERROR;
}

#if (T_NGX_HAVE_F_SETPIPE_SZ)
if (ngx_pipes[i].pipe_size > 0) {
if (fcntl(ngx_pipes[i].open_fd->fd, F_SETPIPE_SZ, ngx_pipes[i].pipe_size) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"fcntl(F_SETPIPE_SZ) %d failed",
ngx_pipes[i].pipe_size);
return NGX_ERROR;
} else {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"fcntl(F_SETPIPE_SZ) %d succeed",
ngx_pipes[i].pipe_size);
}
} else if (ngx_pipes[i].pipe_size < 0) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"fcntl(F_SETPIPE_SZ) %d failed, unexpected < 0",
ngx_pipes[i].pipe_size);
} /* else, pipe_size == 0, pipe_size no change*/
#endif

if (ngx_nonblocking(ngx_pipes[i].open_fd->fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"nonblock \"%s\" failed",
Expand Down
3 changes: 3 additions & 0 deletions src/os/unix/ngx_pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ typedef struct {
ngx_uint_t generation;
ngx_array_t *argv;
ngx_open_file_t *open_fd; /* the fd of pipe left open in master */
#if (T_NGX_HAVE_F_SETPIPE_SZ)
ngx_int_t pipe_size; /* fcntl can adjust size of pipe*/
#endif

unsigned type:1; /* 1: write, 0: read */
unsigned configured:1;
Expand Down