From f0c3d75f8de08262a5c97aa610aaf115ea34c768 Mon Sep 17 00:00:00 2001 From: "hanjian.lhj" Date: Fri, 10 Nov 2023 19:59:14 +0800 Subject: [PATCH 1/2] update --- src/os/unix/ngx_pipe.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/os/unix/ngx_pipe.c b/src/os/unix/ngx_pipe.c index c8d2b9336b..a21d3a540c 100644 --- a/src/os/unix/ngx_pipe.c +++ b/src/os/unix/ngx_pipe.c @@ -250,6 +250,21 @@ ngx_open_pipes(ngx_cycle_t *cycle) ngx_pipes[i].cmd); return NGX_ERROR; } +#ifdef F_SETPIPE_SZ +#define _GNU_SOURCE + if (fcntl(ngx_pipes[i].open_fd->fd, F_SETPIPE_SZ, 10485760) == -1) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + "fcntl(F_SETPIPE_SZ) \"%s\" failed", + ngx_pipes[i].cmd); + return NGX_ERROR; + } else { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "fcntl(F_SETPIPE_SZ) 10485760 \"%s\" succeed", + ngx_pipes[i].cmd); + } +#endif + + if (fcntl(ngx_pipes[i].open_fd->fd, F_SETPIPE_SZ, 10485760) == -1) { if (ngx_nonblocking(ngx_pipes[i].open_fd->fd) == -1) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, From eb96db16895200d441e8c8ce3d53c3fbd0e7ecce Mon Sep 17 00:00:00 2001 From: lhanjian Date: Sun, 12 Nov 2023 21:25:14 +0800 Subject: [PATCH 2/2] modified: unix modified: ../src/os/unix/ngx_pipe.c modified: ../src/os/unix/ngx_pipe.h --- auto/unix | 10 ++++++ src/os/unix/ngx_pipe.c | 71 +++++++++++++++++++++++++++++++++--------- src/os/unix/ngx_pipe.h | 3 ++ 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/auto/unix b/auto/unix index 7c7d7bca69..2d8a06c3fe 100644 --- a/auto/unix +++ b/auto/unix @@ -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 " +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 diff --git a/src/os/unix/ngx_pipe.c b/src/os/unix/ngx_pipe.c index a21d3a540c..ebad5948b5 100644 --- a/src/os/unix/ngx_pipe.c +++ b/src/os/unix/ngx_pipe.c @@ -59,6 +59,11 @@ 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; @@ -66,6 +71,36 @@ ngx_conf_open_pipe(ngx_cycle_t *cycle, ngx_str_t *cmd, const char *type) (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; @@ -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]; } @@ -250,21 +289,25 @@ ngx_open_pipes(ngx_cycle_t *cycle) ngx_pipes[i].cmd); return NGX_ERROR; } -#ifdef F_SETPIPE_SZ -#define _GNU_SOURCE - if (fcntl(ngx_pipes[i].open_fd->fd, F_SETPIPE_SZ, 10485760) == -1) { - ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - "fcntl(F_SETPIPE_SZ) \"%s\" failed", - ngx_pipes[i].cmd); - return NGX_ERROR; - } else { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "fcntl(F_SETPIPE_SZ) 10485760 \"%s\" succeed", - ngx_pipes[i].cmd); - } -#endif - if (fcntl(ngx_pipes[i].open_fd->fd, F_SETPIPE_SZ, 10485760) == -1) { +#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, diff --git a/src/os/unix/ngx_pipe.h b/src/os/unix/ngx_pipe.h index 6273b551f8..0527f4d0cd 100644 --- a/src/os/unix/ngx_pipe.h +++ b/src/os/unix/ngx_pipe.h @@ -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;