From 2ba0da98f81043203d1488c1dd461d722aef7440 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 7 Nov 2017 14:29:24 +0800 Subject: [PATCH 1/6] small typo fix --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index e0f4160e6..e10a5c136 100644 --- a/README.markdown +++ b/README.markdown @@ -78,7 +78,7 @@ as proper Lua modules, like [ngx.semaphore](#ngxsemaphore) and [ngx.balancer](#n The FFI-based Lua API can work with LuaJIT's JIT compiler. ngx_lua's default API is based on the standard Lua C API, which will never be JIT compiled and the user Lua code is always interpreted (slowly). -Suppor for the new [ngx_stream_lua_module](https://github.com/openresty/stream-lua-nginx-module) has also begun. +Support for the new [ngx_stream_lua_module](https://github.com/openresty/stream-lua-nginx-module) has also begun. This library is shipped with the OpenResty bundle by default. So you do not really need to worry about the dependencies and requirements. From bb7e72329e4f6a2175dcedbd84cf38be4633560e Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 27 Dec 2017 16:17:55 +0800 Subject: [PATCH 2/6] feature: new API ngx.process.master_pid --- lib/ngx/process.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ngx/process.lua b/lib/ngx/process.lua index db2d653ac..fd451f782 100644 --- a/lib/ngx/process.lua +++ b/lib/ngx/process.lua @@ -31,6 +31,7 @@ ffi.cdef[[ int ngx_http_lua_ffi_enable_privileged_agent(char **err); int ngx_http_lua_ffi_get_process_type(void); void ngx_http_lua_ffi_process_signal_graceful_exit(void); +int ngx_http_lua_ffi_master_pid(void); ]] @@ -60,4 +61,9 @@ function _M.signal_graceful_exit() end +function _M.master_pid() + return C.ngx_http_lua_ffi_master_pid() +end + + return _M From b831619aacc5775e86024d7bdf700ad8944d5412 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Wed, 27 Dec 2017 16:48:59 +0800 Subject: [PATCH 3/6] tests: ngx.process.master_pid, needs review --- t/process-master-pid.t | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 t/process-master-pid.t diff --git a/t/process-master-pid.t b/t/process-master-pid.t new file mode 100644 index 000000000..26b9560dd --- /dev/null +++ b/t/process-master-pid.t @@ -0,0 +1,68 @@ +# vim:set ft= ts=4 sw=4 et fdm=marker: +use lib 'lib'; +use Test::Nginx::Socket::Lua; +use Cwd qw(cwd); + +#worker_connections(1014); +#master_process_enabled(1); +#log_level('warn'); + +repeat_each(2); + +plan tests => repeat_each() * (blocks() * 6); + +my $pwd = cwd(); + +our $HttpConfig = <<_EOC_; + lua_shared_dict dogs 1m; + lua_package_path "$pwd/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;"; + init_by_lua_block { + local verbose = false + if verbose then + local dump = require "jit.dump" + dump.on("b", "$Test::Nginx::Util::ErrLogFile") + else + local v = require "jit.v" + v.on("$Test::Nginx::Util::ErrLogFile") + end + + require "resty.core" + -- jit.off() + } +_EOC_ + +#no_diff(); +#no_long_string(); +check_accum_error_log(); +run_tests(); + +__DATA__ + +=== TEST 1: ngx.process.master_pid +--- http_config eval: $::HttpConfig +--- config + location = /t { + content_by_lua_block { + local process = require "ngx.process" + + local v + local pid = process.master_pid + for i = 1, 400 do + v = pid() + end + ngx.say(v) + } + } +--- request +GET /t +--- response_body_like chop +\d+$ +--- error_log eval +qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/ +--- no_error_log +[error] + -- NYI: + stitch + + + From 390be5221700755b1708673c0a79b25a3e9bb988 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 2 Jan 2018 10:51:52 +0800 Subject: [PATCH 4/6] process.master_pid return nil if nginx_version < 1013008 --- lib/ngx/process.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ngx/process.lua b/lib/ngx/process.lua index fd451f782..ebdbfb23c 100644 --- a/lib/ngx/process.lua +++ b/lib/ngx/process.lua @@ -62,7 +62,12 @@ end function _M.master_pid() - return C.ngx_http_lua_ffi_master_pid() + local pid = C.ngx_http_lua_ffi_master_pid() + if pid < 0 then + return nil + end + + return pid end From 91dc99844ab4d67bc3632bc80540339af0abb9a0 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 2 Jan 2018 11:24:07 +0800 Subject: [PATCH 5/6] tests: check nginx.pid for process.master_pid --- t/process-master-pid.t | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/t/process-master-pid.t b/t/process-master-pid.t index 26b9560dd..5ec961a30 100644 --- a/t/process-master-pid.t +++ b/t/process-master-pid.t @@ -50,12 +50,22 @@ __DATA__ for i = 1, 400 do v = pid() end + + local f = io.open(ngx.config.prefix().."/logs/nginx.pid", "r") + if not f then + ngx.say(false) + else + local str = f:read("*l") + ngx.say(v == tonumber(str or "0")) + f:close() + end ngx.say(v) } } --- request GET /t --- response_body_like chop +^true \d+$ --- error_log eval qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/ From a74fdb51855586ae067f71bac65cc98fffb25e6e Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 2 Jan 2018 13:52:39 +0800 Subject: [PATCH 6/6] test case fixed in process-master-pid.t --- t/process-master-pid.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/process-master-pid.t b/t/process-master-pid.t index 5ec961a30..04f0ba2dd 100644 --- a/t/process-master-pid.t +++ b/t/process-master-pid.t @@ -68,7 +68,7 @@ GET /t ^true \d+$ --- error_log eval -qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/ +qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):\d loop\]/ --- no_error_log [error] -- NYI: