From 62f712a153006d0828a172c2d3c00a266e74338b Mon Sep 17 00:00:00 2001 From: tuzhnegsong Date: Tue, 18 May 2021 16:31:13 +0800 Subject: [PATCH 1/3] feat: support the environ argument of the ngx.pipe.spawn function on macos --- .../ngx_lua-ngx_pipe_environ_on_mac.patch | 73 +++++++++++++++++++ patch/README.md | 2 + 2 files changed, 75 insertions(+) create mode 100644 patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch diff --git a/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch b/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch new file mode 100644 index 0000000..63d70ea --- /dev/null +++ b/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch @@ -0,0 +1,73 @@ +diff --git a/src/ngx_http_lua_pipe.c b/src/ngx_http_lua_pipe.c +index c555d7bc..e97fb0a8 100644 +--- a/src/ngx_http_lua_pipe.c ++++ b/src/ngx_http_lua_pipe.c +@@ -545,6 +545,21 @@ ngx_http_lua_pipe_fd_write(ngx_connection_t *c, u_char *buf, size_t size) + } + + ++#if !(NGX_HTTP_LUA_HAVE_EXECVPE) ++static int ++ngx_http_lua_execvpe(const char *program, char **argv, char **envp) ++{ ++ char **saved = environ; ++ int rc; ++ ++ environ = envp; ++ rc = execvp(program, argv); ++ environ = saved; ++ return rc; ++} ++#endif ++ ++ + int + ngx_http_lua_ffi_pipe_spawn(ngx_http_lua_ffi_pipe_proc_t *proc, + const char *file, const char **argv, int merge_stderr, size_t buffer_size, +@@ -568,15 +583,6 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua_ffi_pipe_proc_t *proc, + ngx_http_lua_pipe_signal_t *sig; + sigset_t set; + +-#if !(NGX_HTTP_LUA_HAVE_EXECVPE) +- if (environ != NULL) { +- *errbuf_size = ngx_snprintf(errbuf, *errbuf_size, +- "environ option not supported") +- - errbuf; +- return NGX_ERROR; +- } +-#endif +- + pool_size = ngx_align(NGX_MIN_POOL_SIZE + buffer_size * 2, + NGX_POOL_ALIGNMENT); + +@@ -766,9 +772,13 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua_ffi_pipe_proc_t *proc, + } + } + +-#if (NGX_HTTP_LUA_HAVE_EXECVPE) + if (environ != NULL) { +- if (execvpe(file, (char * const *) argv, (char * const *) environ) ++#if (NGX_HTTP_LUA_HAVE_EXECVPE) ++ if (execvpe(file, (char * const *) argv, (char * const *) environ) ++#else ++ if (ngx_http_lua_execvpe(file, (char * const *) argv, ++ (char * const *) environ) ++#endif + == -1) + { + ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, ngx_errno, +@@ -784,14 +794,6 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua_ffi_pipe_proc_t *proc, + } + } + +-#else +- if (execvp(file, (char * const *) argv) == -1) { +- ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, ngx_errno, +- "lua pipe child execvp() failed while executing %s", +- file); +- } +-#endif +- + exit(EXIT_FAILURE); + } + diff --git a/patch/README.md b/patch/README.md index 9c65d4b..6d62d73 100644 --- a/patch/README.md +++ b/patch/README.md @@ -5,3 +5,5 @@ We have modified them a lot and even changed the API. The `*-upstream_mtls` patches originally come from the Kong's kong-build-tools and lua-kong-nginx-module projects, which is also under Apache-2.0 License. + +The `*-ngx_pipe_environ_on_mac` patches support the environ argument of the ngx.pipe.spawn function on macos. \ No newline at end of file From 4b8abe4e10c391d451c4770faca7e25248b56f6f Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Mon, 24 May 2021 10:39:48 +0800 Subject: [PATCH 2/3] Update ngx_lua-ngx_pipe_environ_on_mac.patch update git diff format --- patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch b/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch index 63d70ea..cea9caa 100644 --- a/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch +++ b/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch @@ -1,7 +1,7 @@ diff --git a/src/ngx_http_lua_pipe.c b/src/ngx_http_lua_pipe.c index c555d7bc..e97fb0a8 100644 ---- a/src/ngx_http_lua_pipe.c -+++ b/src/ngx_http_lua_pipe.c +--- src/ngx_http_lua_pipe.c ++++ src/ngx_http_lua_pipe.c @@ -545,6 +545,21 @@ ngx_http_lua_pipe_fd_write(ngx_connection_t *c, u_char *buf, size_t size) } From e4cb8614ec47c2821bfcc697e191bb7f93357a21 Mon Sep 17 00:00:00 2001 From: tuzhnegsong Date: Mon, 24 May 2021 10:49:31 +0800 Subject: [PATCH 3/3] feat: update git diff format --- .../ngx_lua-ngx_pipe_environ_on_mac.patch | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch b/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch index cea9caa..6869bda 100644 --- a/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch +++ b/patch/1.19.3/ngx_lua-ngx_pipe_environ_on_mac.patch @@ -1,11 +1,11 @@ -diff --git a/src/ngx_http_lua_pipe.c b/src/ngx_http_lua_pipe.c -index c555d7bc..e97fb0a8 100644 +diff --git src/ngx_http_lua_pipe.c src/ngx_http_lua_pipe.c +index c555d7bc..9b50d0ae 100644 --- src/ngx_http_lua_pipe.c +++ src/ngx_http_lua_pipe.c @@ -545,6 +545,21 @@ ngx_http_lua_pipe_fd_write(ngx_connection_t *c, u_char *buf, size_t size) } - - + + +#if !(NGX_HTTP_LUA_HAVE_EXECVPE) +static int +ngx_http_lua_execvpe(const char *program, char **argv, char **envp) @@ -27,7 +27,7 @@ index c555d7bc..e97fb0a8 100644 @@ -568,15 +583,6 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua_ffi_pipe_proc_t *proc, ngx_http_lua_pipe_signal_t *sig; sigset_t set; - + -#if !(NGX_HTTP_LUA_HAVE_EXECVPE) - if (environ != NULL) { - *errbuf_size = ngx_snprintf(errbuf, *errbuf_size, @@ -39,19 +39,18 @@ index c555d7bc..e97fb0a8 100644 - pool_size = ngx_align(NGX_MIN_POOL_SIZE + buffer_size * 2, NGX_POOL_ALIGNMENT); - + @@ -766,9 +772,13 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua_ffi_pipe_proc_t *proc, } } - + -#if (NGX_HTTP_LUA_HAVE_EXECVPE) if (environ != NULL) { -- if (execvpe(file, (char * const *) argv, (char * const *) environ) +#if (NGX_HTTP_LUA_HAVE_EXECVPE) -+ if (execvpe(file, (char * const *) argv, (char * const *) environ) + if (execvpe(file, (char * const *) argv, (char * const *) environ) +#else -+ if (ngx_http_lua_execvpe(file, (char * const *) argv, -+ (char * const *) environ) ++ if (ngx_http_lua_execvpe(file, (char * const *) argv, ++ (char * const *) environ) +#endif == -1) { @@ -59,7 +58,7 @@ index c555d7bc..e97fb0a8 100644 @@ -784,14 +794,6 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua_ffi_pipe_proc_t *proc, } } - + -#else - if (execvp(file, (char * const *) argv) == -1) { - ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, ngx_errno, @@ -70,4 +69,4 @@ index c555d7bc..e97fb0a8 100644 - exit(EXIT_FAILURE); } - +