From mdounin at mdounin.ru Thu May 3 14:32:20 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 3 May 2018 17:32:20 +0300 Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <1115169087.23375772.1524842877109.JavaMail.zimbra@redhat.com> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> <1524674456485.3120@cryptopro.ru> <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> <1524686298341.78540@cryptopro.ru> <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> <1524771096966.89645@cryptopro.ru> <20180427134017.GB32137@mdounin.ru> <1115169087.23375772.1524842877109.JavaMail.zimbra@redhat.com> Message-ID: <20180503143219.GF32137@mdounin.ru> Hello! On Fri, Apr 27, 2018 at 11:27:57AM -0400, Anderson Sasaki wrote: > Hello, > > > > > In my opinion it would be better to have nginx working with engines in > > > > both scenarios. > > > > And is not a problem to call ENGINE_init() from multiple places, since > > > > the API takes care of this case. > > > > > > I'll check these statements in your next patch, but for now it > > > seems an odd functionality to me, because we have openssl config > > > and even nginx ssl_engine directive for that. > > > > Note that the "ssl_engine" directive is not to initialize engines, > > but rather to register an engine as the default one for operations it > > supports. It is designed to make it possible to work with various > > SSL accelerators. > > I believe this patch does not affect the "ssl_engine" directive anymore. > I removed everything I could to make the patch minimal. And changed the log message to be more specific. > I will send the other changes in a new thread. > > The patch follows: > > # HG changeset patch > # User Anderson Toshiyuki Sasaki > # Date 1524841096 -7200 > # Fri Apr 27 16:58:16 2018 +0200 > # Node ID f5b0a791092224ff5d3eaf4da9a95e6018e7235f > # Parent 46c0c7ef4913011f3f1e073f9ac880b07b1a8154 > SSL: Add ENGINE_init() call before loading key. > It is necessary to call ENGINE_init() before using an OpenSSL engine > to get the engine functional reference. Without this, when > ENGINE_load_private_key() is called, the engine is still unitialized. In no particular order: - Should be "SSL: added ..." (no capital letter after a semicolon, prefer past tense). - An empty line after the summary. - Please prefer double spacing. - "uniNItialized" > diff -r 46c0c7ef4913 -r f5b0a7910922 src/event/ngx_event_openssl.c > --- a/src/event/ngx_event_openssl.c Wed Apr 25 14:57:24 2018 +0300 > +++ b/src/event/ngx_event_openssl.c Fri Apr 27 16:58:16 2018 +0200 > @@ -527,6 +527,13 @@ > return NGX_ERROR; > } > > + if (!ENGINE_init(engine)) { As previously noted at [1], this may need ENGINE_finish() to avoid leaking loaded engines. > + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > + "ENGINE_init(engine) failed"); There is no reason to log static string "engine" here. Consider using engine name here. > + ENGINE_free(engine); > + return NGX_ERROR; > + } > + > *last++ = ':'; > > pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); [1] http://mailman.nginx.org/pipermail/nginx-devel/2015-June/007081.html -- Maxim Dounin http://mdounin.ru/ From mdounin at mdounin.ru Thu May 3 14:46:03 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 3 May 2018 17:46:03 +0300 Subject: [PATCH] SSL: Set engine passed in ssl_certificate_key as default In-Reply-To: <1403375514.23673252.1525082756399.JavaMail.zimbra@redhat.com> References: <1233714625.23671766.1525081737233.JavaMail.zimbra@redhat.com> <1403375514.23673252.1525082756399.JavaMail.zimbra@redhat.com> Message-ID: <20180503144602.GG32137@mdounin.ru> Hello! On Mon, Apr 30, 2018 at 06:05:56AM -0400, Anderson Sasaki wrote: > Hello, > > Following there are two patches, one adding the call to set the engine as default for all methods and the other restricting the engine to be the default only for PKEY methods. > For me makes sense to have the engine as default only for PKEY methods. > > Best Regards, > Anderson > > # HG changeset patch > # User Anderson Toshiyuki Sasaki > # Date 1525082320 -7200 > # Mon Apr 30 11:58:40 2018 +0200 > # Node ID 07278e8f9b731a7b78b62c6f1826f71967d31fd7 > # Parent 46c0c7ef4913011f3f1e073f9ac880b07b1a8154 > SSL: Set engine passed in ssl_certificate_key as default > Set the engine as the default OpenSSL engine. > > diff -r 46c0c7ef4913 -r 07278e8f9b73 src/event/ngx_event_openssl.c > --- a/src/event/ngx_event_openssl.c Wed Apr 25 14:57:24 2018 +0300 > +++ b/src/event/ngx_event_openssl.c Mon Apr 30 11:58:40 2018 +0200 > @@ -527,6 +527,14 @@ > return NGX_ERROR; > } > > + if (ENGINE_set_default(engine, ENGINE_METHOD_ALL) == 0) { > + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > + "ENGINE_set_default(engine, ENGINE_METHOD_ALL) " > + "failed"); > + ENGINE_free(engine); > + return NGX_ERROR; > + } > + > *last++ = ':'; > > pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); There should be no need to set default engine for anything when loading private keys. Private keys as loaded from an engine are expected to work regardless of whether the engine is configured as a default one or not. If you think this change is needed for some reason, please elaborate why it is needed. [...] -- Maxim Dounin http://mdounin.ru/ From xeioex at nginx.com Thu May 3 15:29:59 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 03 May 2018 15:29:59 +0000 Subject: [njs] Public header cleanup. Message-ID: details: http://hg.nginx.org/njs/rev/4ab51298e1fe branches: changeset: 516:4ab51298e1fe user: Dmitry Volyntsev date: Thu May 03 18:29:28 2018 +0300 description: Public header cleanup. diffstat: njs/njs.h | 6 ------ njs/njs_vm.h | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diffs (32 lines): diff -r 71455987b770 -r 4ab51298e1fe njs/njs.h --- a/njs/njs.h Thu May 03 18:29:26 2018 +0300 +++ b/njs/njs.h Thu May 03 18:29:28 2018 +0300 @@ -134,12 +134,6 @@ typedef struct { } njs_vm_opt_t; -typedef struct { - nxt_str_t name; - uint32_t line; -} njs_backtrace_entry_t; - - #define NJS_OK NXT_OK #define NJS_ERROR NXT_ERROR #define NJS_AGAIN NXT_AGAIN diff -r 71455987b770 -r 4ab51298e1fe njs/njs_vm.h --- a/njs/njs_vm.h Thu May 03 18:29:26 2018 +0300 +++ b/njs/njs_vm.h Thu May 03 18:29:28 2018 +0300 @@ -347,6 +347,12 @@ typedef union { } njs_object_prototype_t; +typedef struct { + nxt_str_t name; + uint32_t line; +} njs_backtrace_entry_t; + + #define njs_value(_type, _truth, _number) { \ .data = { \ .type = _type, \ From xeioex at nginx.com Thu May 3 15:29:59 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 03 May 2018 15:29:59 +0000 Subject: [njs] Added njs_core.h Message-ID: details: http://hg.nginx.org/njs/rev/2b64817dd8f6 branches: changeset: 514:2b64817dd8f6 user: Dmitry Volyntsev date: Fri Apr 27 14:21:39 2018 +0300 description: Added njs_core.h diffstat: Makefile | 25 ++++++++++++++++++++++ nginx/ngx_http_js_module.c | 7 ------ nginx/ngx_stream_js_module.c | 7 ------ njs/njs.c | 21 ++---------------- njs/njs_array.c | 21 +------------------ njs/njs_boolean.c | 16 +------------- njs/njs_builtin.c | 27 ++--------------------- njs/njs_core.h | 45 +++++++++++++++++++++++++++++++++++++++++ njs/njs_crypto.c | 18 +--------------- njs/njs_date.c | 22 +------------------- njs/njs_disassembler.c | 15 +------------ njs/njs_error.c | 18 +--------------- njs/njs_event.c | 21 +------------------ njs/njs_extern.c | 18 +--------------- njs/njs_fs.c | 19 +---------------- njs/njs_function.c | 18 +--------------- njs/njs_generator.c | 19 +---------------- njs/njs_json.c | 21 +------------------ njs/njs_lexer.c | 16 +------------- njs/njs_lexer_keyword.c | 17 +-------------- njs/njs_math.c | 15 +------------ njs/njs_module.c | 18 +--------------- njs/njs_number.c | 19 +--------------- njs/njs_object.c | 21 +------------------ njs/njs_parser.c | 22 +------------------- njs/njs_parser_expression.c | 20 +----------------- njs/njs_regexp.c | 26 +--------------------- njs/njs_regexp_pattern.h | 3 +- njs/njs_string.c | 27 +----------------------- njs/njs_time.c | 20 +----------------- njs/njs_variable.c | 18 +--------------- njs/njs_vm.c | 25 +--------------------- njs/njs_vm.h | 2 + njs/njscript.c | 24 +-------------------- njs/njscript.h | 10 +++++++++ njs/test/njs_benchmark.c | 8 +------ njs/test/njs_interactive_test.c | 7 ------ njs/test/njs_unit_test.c | 13 +---------- 38 files changed, 122 insertions(+), 567 deletions(-) diffs (truncated from 1248 to 1000 lines): diff -r 809a919a2f5a -r 2b64817dd8f6 Makefile --- a/Makefile Fri Apr 27 14:19:45 2018 +0300 +++ b/Makefile Fri Apr 27 14:21:39 2018 +0300 @@ -125,6 +125,8 @@ dist: $(NXT_BUILDDIR)/njscript.o: \ $(NXT_BUILDDIR)/libnxt.a \ + njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ njs/njs_object.h \ @@ -140,6 +142,7 @@ dist: $(NXT_BUILDDIR)/njs_vm.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ njs/njs_string.h \ @@ -173,6 +176,7 @@ dist: $(NXT_BUILDDIR)/njs_number.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ njs/njs_string.h \ @@ -188,6 +192,7 @@ dist: $(NXT_BUILDDIR)/njs_string.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ njs/njs_string.h \ @@ -206,6 +211,7 @@ dist: $(NXT_BUILDDIR)/njs_object.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ njs/njs_object_hash.h \ @@ -219,6 +225,7 @@ dist: $(NXT_BUILDDIR)/njs_array.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ njs/njs_string.h \ @@ -235,6 +242,7 @@ dist: $(NXT_BUILDDIR)/njs_json.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ njs/njs_json.c \ @@ -247,6 +255,7 @@ dist: $(NXT_BUILDDIR)/njs_function.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ njs/njs_array.h \ @@ -260,6 +269,7 @@ dist: $(NXT_BUILDDIR)/njs_regexp.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ njs/njs_object.h \ @@ -276,6 +286,7 @@ dist: $(NXT_BUILDDIR)/njs_date.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ njs/njs_object.h \ @@ -290,6 +301,7 @@ dist: $(NXT_BUILDDIR)/njs_error.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ njs/njs_object.h \ @@ -304,6 +316,7 @@ dist: $(NXT_BUILDDIR)/njs_math.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ njs/njs_math.h \ @@ -316,6 +329,7 @@ dist: $(NXT_BUILDDIR)/njs_time.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ njs/njs_time.h \ @@ -328,6 +342,7 @@ dist: $(NXT_BUILDDIR)/njs_module.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_module.h \ njs/njs_module.c \ @@ -339,6 +354,7 @@ dist: $(NXT_BUILDDIR)/njs_event.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_event.h \ njs/njs_event.c \ @@ -361,6 +377,7 @@ dist: $(NXT_BUILDDIR)/njs_crypto.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_crypto.h \ njs/njs_crypto.c \ @@ -372,6 +389,7 @@ dist: $(NXT_BUILDDIR)/njs_extern.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_parser.h \ njs/njs_extern.h \ @@ -384,6 +402,7 @@ dist: $(NXT_BUILDDIR)/njs_variable.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_parser.h \ njs/njs_variable.h \ @@ -396,6 +415,7 @@ dist: $(NXT_BUILDDIR)/njs_builtin.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_boolean.h \ njs/njs_number.h \ @@ -415,6 +435,7 @@ dist: $(NXT_BUILDDIR)/njs_lexer.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_parser.h \ njs/njs_lexer.c \ @@ -439,6 +460,7 @@ dist: $(NXT_BUILDDIR)/njs_parser.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ njs/njs_object.h \ @@ -454,6 +476,7 @@ dist: $(NXT_BUILDDIR)/njs_parser_expression.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ njs/njs_object.h \ @@ -469,6 +492,7 @@ dist: $(NXT_BUILDDIR)/njs_generator.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ njs/njs_string.h \ @@ -485,6 +509,7 @@ dist: $(NXT_BUILDDIR)/njs_disassembler.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ + njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ njs/njs_parser.h \ diff -r 809a919a2f5a -r 2b64817dd8f6 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Fri Apr 27 14:19:45 2018 +0300 +++ b/nginx/ngx_http_js_module.c Fri Apr 27 14:21:39 2018 +0300 @@ -9,13 +9,6 @@ #include #include -#include -#include -#include -#include -#include -#include - #include diff -r 809a919a2f5a -r 2b64817dd8f6 nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Fri Apr 27 14:19:45 2018 +0300 +++ b/nginx/ngx_stream_js_module.c Fri Apr 27 14:21:39 2018 +0300 @@ -9,13 +9,6 @@ #include #include -#include -#include -#include -#include -#include -#include - #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs.c --- a/njs/njs.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,6 +4,9 @@ * Copyright (C) NGINX, Inc. */ + +#include +#include #include #include #include @@ -13,24 +16,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_array.c --- a/njs/njs_array.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_array.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,26 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_boolean.c --- a/njs/njs_boolean.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_boolean.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,21 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include njs_ret_t diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_builtin.c --- a/njs/njs_builtin.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_builtin.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,33 +4,12 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include -#include +#include #include -#include +#include #include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_core.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/njs/njs_core.h Fri Apr 27 14:21:39 2018 +0300 @@ -0,0 +1,45 @@ + +/* + * Copyright (C) Dmitry Volyntsev + * Copyright (C) NGINX, Inc. + */ + +#ifndef _NJS_CORE_H_INCLUDED_ +#define _NJS_CORE_H_INCLUDED_ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#endif /* _NJS_CORE_H_INCLUDED_ */ diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_crypto.c --- a/njs/njs_crypto.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_crypto.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,27 +4,11 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include -#include -#include -#include #include -#include -#include -#include -#include -#include #include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_date.c --- a/njs/njs_date.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_date.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,28 +4,8 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include #include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_disassembler.c --- a/njs/njs_disassembler.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_disassembler.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,20 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_error.c --- a/njs/njs_error.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_error.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,23 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_event.c --- a/njs/njs_event.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_event.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,26 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_extern.c --- a/njs/njs_extern.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_extern.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,23 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_fs.c --- a/njs/njs_fs.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_fs.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,24 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_function.c --- a/njs/njs_function.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_function.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,23 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_generator.c --- a/njs/njs_generator.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_generator.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,24 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_json.c --- a/njs/njs_json.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_json.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,26 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_lexer.c --- a/njs/njs_lexer.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_lexer.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,21 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_lexer_keyword.c --- a/njs/njs_lexer_keyword.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_lexer_keyword.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,22 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_math.c --- a/njs/njs_math.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_math.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,20 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_module.c --- a/njs/njs_module.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_module.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,23 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_number.c --- a/njs/njs_number.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_number.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,23 +4,8 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_object.c --- a/njs/njs_object.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_object.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,26 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_parser.c --- a/njs/njs_parser.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_parser.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,27 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_parser_expression.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,25 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_regexp.c --- a/njs/njs_regexp.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_regexp.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,32 +4,10 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include + #include #include diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_regexp_pattern.h --- a/njs/njs_regexp_pattern.h Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_regexp_pattern.h Fri Apr 27 14:21:39 2018 +0300 @@ -7,7 +7,8 @@ #ifndef _NJS_REGEXP_PATTERN_H_INCLUDED_ #define _NJS_REGEXP_PATTERN_H_INCLUDED_ -#include +#include +#include typedef enum { diff -r 809a919a2f5a -r 2b64817dd8f6 njs/njs_string.c --- a/njs/njs_string.c Fri Apr 27 14:19:45 2018 +0300 +++ b/njs/njs_string.c Fri Apr 27 14:21:39 2018 +0300 @@ -4,32 +4,7 @@ * Copyright (C) NGINX, Inc. */ -#include -#include -#include -#include -#include -#include From xeioex at nginx.com Thu May 3 15:29:59 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 03 May 2018 15:29:59 +0000 Subject: [njs] Renamed njscript to njs. Message-ID: details: http://hg.nginx.org/njs/rev/71455987b770 branches: changeset: 515:71455987b770 user: Dmitry Volyntsev date: Thu May 03 18:29:26 2018 +0300 description: Renamed njscript to njs. njscript.c -> njs.c njscript.h -> njs.h njs.c -> njs_shell.c diffstat: Makefile | 74 +- nginx/ngx_http_js_module.c | 2 +- nginx/ngx_stream_js_module.c | 2 +- njs/njs.c | 1137 ++++++++++++++++++++------------------ njs/njs.h | 223 +++++++ njs/njs_core.h | 2 +- njs/njs_shell.c | 651 ++++++++++++++++++++++ njs/njscript.h | 223 ------- njs/test/njs_benchmark.c | 2 +- njs/test/njs_interactive_test.c | 2 +- 10 files changed, 1512 insertions(+), 806 deletions(-) diffs (truncated from 2722 to 1000 lines): diff -r 2b64817dd8f6 -r 71455987b770 Makefile --- a/Makefile Fri Apr 27 14:21:39 2018 +0300 +++ b/Makefile Thu May 03 18:29:26 2018 +0300 @@ -7,7 +7,7 @@ NXT_BUILDDIR = build $(NXT_BUILDDIR)/libnjs.a: \ $(NXT_LIB)/nxt_auto_config.h \ - $(NXT_BUILDDIR)/njscript.o \ + $(NXT_BUILDDIR)/njs_shell.o \ $(NXT_BUILDDIR)/njs_vm.o \ $(NXT_BUILDDIR)/njs_boolean.o \ $(NXT_BUILDDIR)/njs_number.o \ @@ -49,7 +49,7 @@ NXT_BUILDDIR = build $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ ar -r -c $(NXT_BUILDDIR)/libnjs.a \ - $(NXT_BUILDDIR)/njscript.o \ + $(NXT_BUILDDIR)/njs_shell.o \ $(NXT_BUILDDIR)/njs_vm.o \ $(NXT_BUILDDIR)/njs_boolean.o \ $(NXT_BUILDDIR)/njs_number.o \ @@ -110,7 +110,7 @@ clean: rm -f $(NXT_LIB)/Makefile.conf $(NXT_LIB)/nxt_auto_config.h dist: - NJS_VER=`grep NJS_VERSION njs/njscript.h | sed -e 's/.*"\(.*\)".*/\1/'`; \ + NJS_VER=`grep NJS_VERSION njs/njs.h | sed -e 's/.*"\(.*\)".*/\1/'`; \ rm -rf njs-$${NJS_VER} \ && hg archive njs-$${NJS_VER}.tar.gz \ -p njs-$${NJS_VER} \ @@ -123,25 +123,25 @@ dist: @echo @exit 1 -$(NXT_BUILDDIR)/njscript.o: \ +$(NXT_BUILDDIR)/njs_shell.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ njs/njs_object.h \ njs/njs_function.h \ njs/njs_parser.h \ - njs/njscript.h \ - njs/njscript.c \ + njs/njs.h \ + njs/njs.c \ - $(NXT_CC) -c -o $(NXT_BUILDDIR)/njscript.o $(NXT_CFLAGS) \ + $(NXT_CC) -c -o $(NXT_BUILDDIR)/njs_shell.o $(NXT_CFLAGS) \ -I$(NXT_LIB) -Injs \ - njs/njscript.c + njs/njs.c $(NXT_BUILDDIR)/njs_vm.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ @@ -162,7 +162,7 @@ dist: $(NXT_BUILDDIR)/njs_boolean.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_vm.h \ njs/njs_boolean.h \ njs/njs_object.h \ @@ -175,7 +175,7 @@ dist: $(NXT_BUILDDIR)/njs_number.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ @@ -191,7 +191,7 @@ dist: $(NXT_BUILDDIR)/njs_string.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ @@ -210,7 +210,7 @@ dist: $(NXT_BUILDDIR)/njs_object.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ @@ -224,7 +224,7 @@ dist: $(NXT_BUILDDIR)/njs_array.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ @@ -241,7 +241,7 @@ dist: $(NXT_BUILDDIR)/njs_json.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ @@ -254,7 +254,7 @@ dist: $(NXT_BUILDDIR)/njs_function.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ @@ -268,7 +268,7 @@ dist: $(NXT_BUILDDIR)/njs_regexp.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ @@ -285,7 +285,7 @@ dist: $(NXT_BUILDDIR)/njs_date.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ @@ -300,7 +300,7 @@ dist: $(NXT_BUILDDIR)/njs_error.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ @@ -315,7 +315,7 @@ dist: $(NXT_BUILDDIR)/njs_math.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ @@ -328,7 +328,7 @@ dist: $(NXT_BUILDDIR)/njs_time.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ @@ -341,7 +341,7 @@ dist: $(NXT_BUILDDIR)/njs_module.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_module.h \ @@ -353,7 +353,7 @@ dist: $(NXT_BUILDDIR)/njs_event.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_event.h \ @@ -365,7 +365,7 @@ dist: $(NXT_BUILDDIR)/njs_fs.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_vm.h \ njs/njs_fs.h \ njs/njs_fs.c \ @@ -376,7 +376,7 @@ dist: $(NXT_BUILDDIR)/njs_crypto.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_crypto.h \ @@ -388,7 +388,7 @@ dist: $(NXT_BUILDDIR)/njs_extern.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_parser.h \ @@ -401,7 +401,7 @@ dist: $(NXT_BUILDDIR)/njs_variable.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_parser.h \ @@ -414,7 +414,7 @@ dist: $(NXT_BUILDDIR)/njs_builtin.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_boolean.h \ @@ -434,7 +434,7 @@ dist: $(NXT_BUILDDIR)/njs_lexer.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_parser.h \ @@ -446,7 +446,7 @@ dist: $(NXT_BUILDDIR)/njs_lexer_keyword.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_vm.h \ njs/njs_number.h \ njs/njs_object.h \ @@ -459,7 +459,7 @@ dist: $(NXT_BUILDDIR)/njs_parser.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_string.h \ @@ -475,7 +475,7 @@ dist: $(NXT_BUILDDIR)/njs_parser_expression.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ @@ -491,7 +491,7 @@ dist: $(NXT_BUILDDIR)/njs_generator.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_number.h \ @@ -508,7 +508,7 @@ dist: $(NXT_BUILDDIR)/njs_disassembler.o: \ $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ + njs/njs.h \ njs/njs_core.h \ njs/njs_vm.h \ njs/njs_object.h \ @@ -522,11 +522,11 @@ dist: $(NXT_BUILDDIR)/njs: \ $(NXT_BUILDDIR)/libnxt.a \ $(NXT_BUILDDIR)/libnjs.a \ - njs/njs.c \ + njs/njs_shell.c \ $(NXT_CC) -o $(NXT_BUILDDIR)/njs $(NXT_CFLAGS) \ -I$(NXT_LIB) $(NXT_EDITLINE_CFLAGS) -Injs \ - njs/njs.c \ + njs/njs_shell.c \ $(NXT_BUILDDIR)/libnjs.a \ -lm $(NXT_PCRE_LIB) $(NXT_EDITLINE_LIB) diff -r 2b64817dd8f6 -r 71455987b770 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Fri Apr 27 14:21:39 2018 +0300 +++ b/nginx/ngx_http_js_module.c Thu May 03 18:29:26 2018 +0300 @@ -9,7 +9,7 @@ #include #include -#include +#include typedef struct { diff -r 2b64817dd8f6 -r 71455987b770 nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Fri Apr 27 14:21:39 2018 +0300 +++ b/nginx/ngx_stream_js_module.c Thu May 03 18:29:26 2018 +0300 @@ -9,7 +9,7 @@ #include #include -#include +#include typedef struct { diff -r 2b64817dd8f6 -r 71455987b770 njs/njs.c --- a/njs/njs.c Fri Apr 27 14:21:39 2018 +0300 +++ b/njs/njs.c Thu May 03 18:29:26 2018 +0300 @@ -1,651 +1,706 @@ /* - * Copyright (C) Dmitry Volyntsev + * Copyright (C) Igor Sysoev * Copyright (C) NGINX, Inc. */ - #include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include + + +static nxt_int_t njs_vm_init(njs_vm_t *vm); +static nxt_int_t njs_vm_handle_events(njs_vm_t *vm); + -#include +static void * +njs_alloc(void *mem, size_t size) +{ + return nxt_malloc(size); +} -typedef enum { - NJS_COMPLETION_GLOBAL = 0, - NJS_COMPLETION_SUFFIX, -} njs_completion_phase_t; +static void * +njs_zalloc(void *mem, size_t size) +{ + void *p; + + p = nxt_malloc(size); + + if (p != NULL) { + memset(p, 0, size); + } + + return p; +} -typedef struct { - char *file; - nxt_int_t version; - nxt_int_t disassemble; - nxt_int_t interactive; -} njs_opts_t; - - -typedef struct { - size_t index; - size_t length; - njs_vm_t *vm; - nxt_array_t *completions; - nxt_array_t *suffix_completions; - nxt_lvlhsh_each_t lhe; - njs_completion_phase_t phase; -} njs_completion_t; +static void * +njs_align(void *mem, size_t alignment, size_t size) +{ + return nxt_memalign(alignment, size); +} -static nxt_int_t njs_get_options(njs_opts_t *opts, int argc, char **argv); -static nxt_int_t njs_externals_init(njs_vm_t *vm); -static nxt_int_t njs_interactive_shell(njs_opts_t *opts, - njs_vm_opt_t *vm_options); -static nxt_int_t njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options); -static nxt_int_t njs_process_script(njs_vm_t *vm, njs_opts_t *opts, - const nxt_str_t *script, nxt_str_t *out); -static nxt_int_t njs_editline_init(njs_vm_t *vm); -static char **njs_completion_handler(const char *text, int start, int end); -static char *njs_completion_generator(const char *text, int state); +static void +njs_free(void *mem, void *p) +{ + nxt_free(p); +} + -static njs_ret_t njs_ext_console_log(njs_vm_t *vm, njs_value_t *args, - nxt_uint_t nargs, njs_index_t unused); -static njs_ret_t njs_ext_console_help(njs_vm_t *vm, njs_value_t *args, - nxt_uint_t nargs, njs_index_t unused); +const nxt_mem_proto_t njs_vm_mem_cache_pool_proto = { + njs_alloc, + njs_zalloc, + njs_align, + NULL, + njs_free, + NULL, + NULL, +}; -static njs_external_t njs_ext_console[] = { +static void * +njs_array_mem_alloc(void *mem, size_t size) +{ + return nxt_mem_cache_alloc(mem, size); +} - { nxt_string("log"), - NJS_EXTERN_METHOD, - NULL, - 0, - NULL, - NULL, - NULL, - NULL, - NULL, - njs_ext_console_log, - 0 }, - { nxt_string("help"), - NJS_EXTERN_METHOD, - NULL, - 0, - NULL, - NULL, - NULL, - NULL, - NULL, - njs_ext_console_help, - 0 }, -}; +static void +njs_array_mem_free(void *mem, void *p) +{ + nxt_mem_cache_free(mem, p); +} + -static njs_external_t njs_externals[] = { - - { nxt_string("console"), - NJS_EXTERN_OBJECT, - njs_ext_console, - nxt_nitems(njs_ext_console), - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - 0 }, +const nxt_mem_proto_t njs_array_mem_proto = { + njs_array_mem_alloc, + NULL, + NULL, + NULL, + njs_array_mem_free, + NULL, + NULL, }; -static njs_completion_t njs_completion; +njs_vm_t * +njs_vm_create(njs_vm_opt_t *options) +{ + njs_vm_t *vm; + nxt_int_t ret; + nxt_array_t *debug; + nxt_mem_cache_pool_t *mcp; + njs_regexp_pattern_t *pattern; + + mcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL, + NULL, 2 * nxt_pagesize(), 128, 512, 16); + if (nxt_slow_path(mcp == NULL)) { + return NULL; + } + + vm = nxt_mem_cache_zalign(mcp, sizeof(njs_value_t), sizeof(njs_vm_t)); + + if (nxt_fast_path(vm != NULL)) { + vm->mem_cache_pool = mcp; + + ret = njs_regexp_init(vm); + if (nxt_slow_path(ret != NXT_OK)) { + return NULL; + } + + if (options->shared != NULL) { + vm->shared = options->shared; + + } else { + vm->shared = nxt_mem_cache_zalloc(mcp, sizeof(njs_vm_shared_t)); + if (nxt_slow_path(vm->shared == NULL)) { + return NULL; + } + + options->shared = vm->shared; + + nxt_lvlhsh_init(&vm->shared->keywords_hash); + + ret = njs_lexer_keywords_init(mcp, &vm->shared->keywords_hash); + if (nxt_slow_path(ret != NXT_OK)) { + return NULL; + } + + nxt_lvlhsh_init(&vm->shared->values_hash); + + pattern = njs_regexp_pattern_create(vm, (u_char *) "(?:)", + sizeof("(?:)") - 1, 0); + if (nxt_slow_path(pattern == NULL)) { + return NULL; + } + + vm->shared->empty_regexp_pattern = pattern; + + nxt_lvlhsh_init(&vm->modules_hash); + + ret = njs_builtin_objects_create(vm); + if (nxt_slow_path(ret != NXT_OK)) { + return NULL; + } + } + + nxt_lvlhsh_init(&vm->values_hash); + + vm->external = options->external; + + vm->external_objects = nxt_array_create(4, sizeof(void *), + &njs_array_mem_proto, + vm->mem_cache_pool); + if (nxt_slow_path(vm->external_objects == NULL)) { + return NULL; + } + + nxt_lvlhsh_init(&vm->externals_hash); + nxt_lvlhsh_init(&vm->external_prototypes_hash); + + vm->ops = options->ops; + + vm->trace.level = NXT_LEVEL_TRACE; + vm->trace.size = 2048; + vm->trace.handler = njs_parser_trace_handler; + vm->trace.data = vm; + + vm->trailer = options->trailer; + + if (options->backtrace) { + debug = nxt_array_create(4, sizeof(njs_function_debug_t), + &njs_array_mem_proto, + vm->mem_cache_pool); + if (nxt_slow_path(debug == NULL)) { + return NULL; + } + + vm->debug = debug; + } + + vm->accumulative = options->accumulative; + if (vm->accumulative) { + ret = njs_vm_init(vm); + if (nxt_slow_path(ret != NXT_OK)) { + return NULL; + } + + vm->retval = njs_value_void; + } + } + + return vm; +} -int -main(int argc, char **argv) +void +njs_vm_destroy(njs_vm_t *vm) { - nxt_int_t ret; - njs_opts_t opts; - njs_vm_opt_t vm_options; + njs_event_t *event; + nxt_lvlhsh_each_t lhe; + + if (njs_is_pending_events(vm)) { + nxt_lvlhsh_each_init(&lhe, &njs_event_hash_proto); - memset(&opts, 0, sizeof(njs_opts_t)); - opts.interactive = 1; + for ( ;; ) { + event = nxt_lvlhsh_each(&vm->events_hash, &lhe); - ret = njs_get_options(&opts, argc, argv); - if (ret != NXT_OK) { - return (ret == NXT_DONE) ? EXIT_SUCCESS : EXIT_FAILURE; + if (event == NULL) { + break; + } + + njs_del_event(vm, event, NJS_EVENT_RELEASE); + } } - if (opts.version != 0) { - printf("%s\n", NJS_VERSION); - return EXIT_SUCCESS; + nxt_mem_cache_pool_destroy(vm->mem_cache_pool); +} + + +nxt_int_t +njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end) +{ + nxt_int_t ret; + njs_lexer_t *lexer; + njs_parser_t *parser, *prev; + njs_parser_node_t *node; + + parser = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_parser_t)); + if (nxt_slow_path(parser == NULL)) { + return NJS_ERROR; + } + + if (vm->parser != NULL && !vm->accumulative) { + return NJS_ERROR; + } + + prev = vm->parser; + vm->parser = parser; + + lexer = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_lexer_t)); + if (nxt_slow_path(lexer == NULL)) { + return NJS_ERROR; + } + + parser->lexer = lexer; + lexer->start = *start; + lexer->end = end; + lexer->line = 1; + lexer->keywords_hash = vm->shared->keywords_hash; + + parser->code_size = sizeof(njs_vmcode_stop_t); + parser->scope_offset = NJS_INDEX_GLOBAL_OFFSET; + + if (vm->backtrace != NULL) { + nxt_array_reset(vm->backtrace); + } + + node = njs_parser(vm, parser, prev); + if (nxt_slow_path(node == NULL)) { + goto fail; + } + + ret = njs_variables_scope_reference(vm, parser->scope); + if (nxt_slow_path(ret != NXT_OK)) { + goto fail; + } + + *start = parser->lexer->start; + + /* + * Reset the code array to prevent it from being disassembled + * again in the next iteration of the accumulative mode. + */ + vm->code = NULL; + + ret = njs_generate_scope(vm, parser, node); + if (nxt_slow_path(ret != NXT_OK)) { + goto fail; } - memset(&vm_options, 0, sizeof(njs_vm_opt_t)); + vm->current = parser->code_start; + + vm->global_scope = parser->local_scope; + vm->scope_size = parser->scope_size; + vm->variables_hash = parser->scope->variables; + + return NJS_OK; - vm_options.accumulative = 1; - vm_options.backtrace = 1; +fail: + + vm->parser = prev; + + return NXT_ERROR; +} + - if (opts.interactive) { - ret = njs_interactive_shell(&opts, &vm_options); +njs_vm_t * +njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) +{ + njs_vm_t *nvm; + uint32_t items; + nxt_int_t ret; + nxt_array_t *externals; + nxt_mem_cache_pool_t *nmcp; - } else { - ret = njs_process_file(&opts, &vm_options); + nxt_thread_log_debug("CLONE:"); + + if (vm->accumulative) { + return NULL; + } + + nmcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL, + NULL, 2 * nxt_pagesize(), 128, 512, 16); + if (nxt_slow_path(nmcp == NULL)) { + return NULL; } - return (ret == NXT_OK) ? EXIT_SUCCESS : EXIT_FAILURE; + nvm = nxt_mem_cache_zalign(nmcp, sizeof(njs_value_t), sizeof(njs_vm_t)); + + if (nxt_fast_path(nvm != NULL)) { + nvm->mem_cache_pool = nmcp; + + nvm->shared = vm->shared; + + nvm->variables_hash = vm->variables_hash; + nvm->values_hash = vm->values_hash; + nvm->modules_hash = vm->modules_hash; + + nvm->externals_hash = vm->externals_hash; + nvm->external_prototypes_hash = vm->external_prototypes_hash; + + items = vm->external_objects->items; + externals = nxt_array_create(items + 4, sizeof(void *), + &njs_array_mem_proto, nvm->mem_cache_pool); + + if (nxt_slow_path(externals == NULL)) { + return NULL; + } + + if (items > 0) { + memcpy(externals->start, vm->external_objects->start, + items * sizeof(void *)); + externals->items = items; + } + + nvm->external_objects = externals; + + nvm->ops = vm->ops; + + nvm->current = vm->current; + + nvm->external = external; + + nvm->global_scope = vm->global_scope; + nvm->scope_size = vm->scope_size; + + nvm->debug = vm->debug; + + ret = njs_vm_init(nvm); + if (nxt_slow_path(ret != NXT_OK)) { + goto fail; + } + + nvm->retval = njs_value_void; + + return nvm; + } + +fail: + + nxt_mem_cache_pool_destroy(nmcp); + + return NULL; } static nxt_int_t -njs_get_options(njs_opts_t *opts, int argc, char** argv) +njs_vm_init(njs_vm_t *vm) { - char *p; - nxt_int_t i, ret; + size_t size, scope_size; + u_char *values; + nxt_int_t ret; + njs_frame_t *frame; + nxt_array_t *backtrace; + + scope_size = vm->scope_size + NJS_INDEX_GLOBAL_OFFSET; + + size = NJS_GLOBAL_FRAME_SIZE + scope_size + NJS_FRAME_SPARE_SIZE; + size = nxt_align_size(size, NJS_FRAME_SPARE_SIZE); - ret = NXT_DONE; + frame = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), size); + if (nxt_slow_path(frame == NULL)) { + return NXT_ERROR; + } + + memset(frame, 0, NJS_GLOBAL_FRAME_SIZE); + + vm->top_frame = &frame->native; + vm->active_frame = frame; + + frame->native.size = size; + frame->native.free_size = size - (NJS_GLOBAL_FRAME_SIZE + scope_size); - for (i = 1; i < argc; i++) { + values = (u_char *) frame + NJS_GLOBAL_FRAME_SIZE; + + frame->native.free = values + scope_size; - p = argv[i]; + vm->scopes[NJS_SCOPE_GLOBAL] = (njs_value_t *) values; + memcpy(values + NJS_INDEX_GLOBAL_OFFSET, vm->global_scope, + vm->scope_size); + + ret = njs_regexp_init(vm); + if (nxt_slow_path(ret != NXT_OK)) { + return NXT_ERROR; + } - if (p[0] != '-' || (p[0] == '-' && p[1] == '\0')) { - opts->interactive = 0; - opts->file = argv[i]; - continue; + ret = njs_builtin_objects_clone(vm); + if (nxt_slow_path(ret != NXT_OK)) { + return NXT_ERROR; + } + + nxt_lvlhsh_init(&vm->events_hash); + nxt_queue_init(&vm->posted_events); + + if (vm->debug != NULL) { + backtrace = nxt_array_create(4, sizeof(njs_backtrace_entry_t), + &njs_array_mem_proto, vm->mem_cache_pool); + if (nxt_slow_path(backtrace == NULL)) { + return NXT_ERROR; } - p++; - - switch (*p) { - case 'd': - opts->disassemble = 1; - break; - - case 'V': - opts->version = 1; - break; + vm->backtrace = backtrace; + } - default: - fprintf(stderr, "Unknown argument: \"%s\"\n", argv[i]); - ret = NXT_ERROR; - - /* Fall through. */ - - case 'h': - case '?': - printf("Usage: %s [|-] [-dV]\n", argv[0]); - return ret; - } - } + vm->trace.level = NXT_LEVEL_TRACE; + vm->trace.size = 2048; + vm->trace.handler = njs_parser_trace_handler; + vm->trace.data = vm; return NXT_OK; } -static nxt_int_t -njs_externals_init(njs_vm_t *vm) +nxt_int_t +njs_vm_call(njs_vm_t *vm, njs_function_t *function, njs_opaque_value_t *args, + nxt_uint_t nargs) { - nxt_uint_t ret; - const njs_extern_t *proto; - njs_opaque_value_t *value; - - static const nxt_str_t name = nxt_string_value("console"); - - proto = njs_vm_external_prototype(vm, &njs_externals[0]); - if (proto == NULL) { - fprintf(stderr, "failed to add console proto\n"); - return NXT_ERROR; - } - - value = nxt_mem_cache_zalloc(vm->mem_cache_pool, - sizeof(njs_opaque_value_t)); - if (value == NULL) { - return NXT_ERROR; - } - - ret = njs_vm_external_create(vm, value, proto, NULL); - if (ret != NXT_OK) { - return NXT_ERROR; - } - - ret = njs_vm_external_bind(vm, &name, value); - if (ret != NXT_OK) { - return NXT_ERROR; - } - - return NXT_OK; -} - - -static nxt_int_t -njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options) -{ - njs_vm_t *vm; - nxt_int_t ret; - nxt_str_t line, out; + u_char *current; + njs_ret_t ret; + njs_value_t *this; - vm = njs_vm_create(vm_options); - if (vm == NULL) { - fprintf(stderr, "failed to create vm\n"); - return NXT_ERROR; - } - - if (njs_externals_init(vm) != NXT_OK) { - fprintf(stderr, "failed to add external protos\n"); - return NXT_ERROR; - } - - if (njs_editline_init(vm) != NXT_OK) { - fprintf(stderr, "failed to init completions\n"); - return NXT_ERROR; - } - - printf("interactive njscript %s\n\n", NJS_VERSION); - - printf("v. -> the properties and prototype methods of v.\n"); - printf("type console.help() for more information\n\n"); + static const njs_vmcode_stop_t stop[] = { + { .code = { .operation = njs_vmcode_stop, + .operands = NJS_VMCODE_1OPERAND, + .retval = NJS_VMCODE_NO_RETVAL }, + .retval = NJS_INDEX_GLOBAL_RETVAL }, + }; - for ( ;; ) { - line.start = (u_char *) readline(">> "); - if (line.start == NULL) { - break; - } - - line.length = strlen((char *) line.start); - if (line.length == 0) { - continue; - } + this = (njs_value_t *) &njs_value_void; - add_history((char *) line.start); From xeioex at nginx.com Fri May 4 16:28:36 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Fri, 04 May 2018 16:28:36 +0000 Subject: [njs] Fixed crypto.createHmac() for keys with size >= alg size and < 64. Message-ID: details: http://hg.nginx.org/njs/rev/ed4721d09f60 branches: changeset: 517:ed4721d09f60 user: Dmitry Volyntsev date: Fri May 04 19:25:15 2018 +0300 description: Fixed crypto.createHmac() for keys with size >= alg size and < 64. diffstat: njs/njs_crypto.c | 6 +----- njs/test/njs_unit_test.c | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diffs (32 lines): diff -r 4ab51298e1fe -r ed4721d09f60 njs/njs_crypto.c --- a/njs/njs_crypto.c Thu May 03 18:29:28 2018 +0300 +++ b/njs/njs_crypto.c Fri May 04 19:25:15 2018 +0300 @@ -425,13 +425,9 @@ njs_crypto_create_hmac(njs_vm_t *vm, njs memcpy(key_buf, digest, alg->size); memset(key_buf + alg->size, 0, sizeof(key_buf) - alg->size); - } else if (key.length < alg->size) { - - memcpy(key_buf, key.start, key.length); - memset(key_buf + key.length, 0, sizeof(key_buf) - key.length); - } else { memcpy(key_buf, key.start, sizeof(key_buf)); + memset(key_buf + key.length, 0, sizeof(key_buf) - key.length); } for (i = 0; i < 64; i++) { diff -r 4ab51298e1fe -r ed4721d09f60 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu May 03 18:29:28 2018 +0300 +++ b/njs/test/njs_unit_test.c Fri May 04 19:25:15 2018 +0300 @@ -9256,6 +9256,10 @@ static njs_unit_test_t njs_test[] = "h.update('abc'.repeat(100)).digest('hex')"), nxt_string("b105ad6921e4c54d3fa0a9ec3f7f0ee9bd2c659d") }, + { nxt_string("var h = require('crypto').createHmac('sha1', 'A'.repeat(40));" + "h.update('AB').digest('hex')"), + nxt_string("0b84f78ca5275d76d4b7dafb5845ee2b6a79c4c2") }, + { nxt_string("var h = require('crypto').createHmac('sha1', 'A'.repeat(64));" "h.update('AB').digest('hex')"), nxt_string("400ce530816c6b3247e2959f3982a12aaf58c0c9") }, From xeioex at nginx.com Fri May 4 17:55:21 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Fri, 04 May 2018 17:55:21 +0000 Subject: [njs] Usage of njs_opaque_value_t is refactored in public API. Message-ID: details: http://hg.nginx.org/njs/rev/d0e244bc8760 branches: changeset: 518:d0e244bc8760 user: Dmitry Volyntsev date: Fri May 04 19:53:19 2018 +0300 description: Usage of njs_opaque_value_t is refactored in public API. diffstat: nginx/ngx_http_js_module.c | 23 +++++++++++++---------- nginx/ngx_stream_js_module.c | 9 +++++---- njs/njs.c | 13 ++++++------- njs/njs.h | 20 ++++++++++++++------ njs/njs_event.h | 2 +- njs/njs_extern.c | 12 +++--------- njs/njs_shell.c | 2 +- njs/test/njs_unit_test.c | 8 ++++---- 8 files changed, 47 insertions(+), 42 deletions(-) diffs (358 lines): diff -r ed4721d09f60 -r d0e244bc8760 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Fri May 04 19:25:15 2018 +0300 +++ b/nginx/ngx_http_js_module.c Fri May 04 19:53:19 2018 +0300 @@ -134,7 +134,7 @@ static void ngx_http_js_clear_timer(njs_ njs_host_event_t event); static void ngx_http_js_timer_handler(ngx_event_t *ev); static void ngx_http_js_handle_event(ngx_http_request_t *r, - njs_vm_event_t vm_event, njs_opaque_value_t *args, nxt_uint_t nargs); + njs_vm_event_t vm_event, njs_value_t *args, nxt_uint_t nargs); static char *ngx_http_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -666,7 +666,7 @@ ngx_http_js_content_event_handler(ngx_ht return; } - if (njs_vm_call(ctx->vm, func, ctx->args, 2) != NJS_OK) { + if (njs_vm_call(ctx->vm, func, njs_value_arg(ctx->args), 2) != NJS_OK) { njs_vm_retval_to_ext_string(ctx->vm, &exception); ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, @@ -776,7 +776,7 @@ ngx_http_js_variable(ngx_http_request_t pending = njs_vm_pending(ctx->vm); - if (njs_vm_call(ctx->vm, func, ctx->args, 2) != NJS_OK) { + if (njs_vm_call(ctx->vm, func, njs_value_arg(ctx->args), 2) != NJS_OK) { njs_vm_retval_to_ext_string(ctx->vm, &exception); ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, @@ -859,12 +859,14 @@ ngx_http_js_init_vm(ngx_http_request_t * return NGX_ERROR; } - rc = njs_vm_external_create(ctx->vm, &ctx->args[0], jlcf->req_proto, r); + rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->args[0]), + jlcf->req_proto, r); if (rc != NXT_OK) { return NGX_ERROR; } - rc = njs_vm_external_create(ctx->vm, &ctx->args[1], jlcf->res_proto, r); + rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->args[1]), + jlcf->res_proto, r); if (rc != NXT_OK) { return NGX_ERROR; } @@ -1670,7 +1672,7 @@ ngx_http_js_ext_get_response(njs_vm_t *v ctx = ngx_http_get_module_ctx(r, ngx_http_js_module); - njs_vm_retval_set(ctx->vm, &ctx->args[1]); + njs_vm_retval_set(ctx->vm, njs_value_arg(&ctx->args[1])); return NJS_OK; } @@ -1988,7 +1990,8 @@ ngx_http_js_subrequest_done(ngx_http_req return NGX_ERROR; } - ret = njs_vm_external_create(ctx->vm, &reply, jlcf->rep_proto, r); + ret = njs_vm_external_create(ctx->vm, njs_value_arg(&reply), + jlcf->rep_proto, r); if (ret != NXT_OK) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "js subrequest reply creation failed"); @@ -1996,7 +1999,7 @@ ngx_http_js_subrequest_done(ngx_http_req return NGX_ERROR; } - ngx_http_js_handle_event(r->parent, vm_event, &reply, 1); + ngx_http_js_handle_event(r->parent, vm_event, njs_value_arg(&reply), 1); return NGX_OK; } @@ -2019,7 +2022,7 @@ ngx_http_js_ext_get_parent(njs_vm_t *vm, return NJS_ERROR; } - njs_vm_retval_set(ctx->vm, &ctx->args[0]); + njs_vm_retval_set(ctx->vm, njs_value_arg(&ctx->args[0])); return NJS_OK; } @@ -2119,7 +2122,7 @@ ngx_http_js_timer_handler(ngx_event_t *e static void ngx_http_js_handle_event(ngx_http_request_t *r, njs_vm_event_t vm_event, - njs_opaque_value_t *args, nxt_uint_t nargs) + njs_value_t *args, nxt_uint_t nargs) { njs_ret_t rc; nxt_str_t exception; diff -r ed4721d09f60 -r d0e244bc8760 nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Fri May 04 19:25:15 2018 +0300 +++ b/nginx/ngx_stream_js_module.c Fri May 04 19:53:19 2018 +0300 @@ -400,7 +400,7 @@ ngx_stream_js_phase_handler(ngx_stream_s return NGX_ERROR; } - if (njs_vm_call(ctx->vm, func, &ctx->arg, 1) != NJS_OK) { + if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->arg), 1) != NJS_OK) { njs_vm_retval_to_ext_string(ctx->vm, &exception); ngx_log_error(NGX_LOG_ERR, c->log, 0, "js exception: %*s", @@ -487,7 +487,7 @@ ngx_stream_js_body_filter(ngx_stream_ses while (in) { ctx->buf = in->buf; - if (njs_vm_call(ctx->vm, func, &ctx->arg, 1) != NJS_OK) { + if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->arg), 1) != NJS_OK) { njs_vm_retval_to_ext_string(ctx->vm, &exception); ngx_log_error(NGX_LOG_ERR, c->log, 0, "js exception: %*s", @@ -588,7 +588,7 @@ ngx_stream_js_variable(ngx_stream_sessio pending = njs_vm_pending(ctx->vm); - if (njs_vm_call(ctx->vm, func, &ctx->arg, 1) != NJS_OK) { + if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->arg), 1) != NJS_OK) { njs_vm_retval_to_ext_string(ctx->vm, &exception); ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, @@ -671,7 +671,8 @@ ngx_stream_js_init_vm(ngx_stream_session return NGX_ERROR; } - rc = njs_vm_external_create(ctx->vm, &ctx->arg, jscf->proto, s); + rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->arg), jscf->proto, + s); if (rc != NXT_OK) { return NGX_ERROR; } diff -r ed4721d09f60 -r d0e244bc8760 njs/njs.c --- a/njs/njs.c Fri May 04 19:25:15 2018 +0300 +++ b/njs/njs.c Fri May 04 19:53:19 2018 +0300 @@ -444,7 +444,7 @@ njs_vm_init(njs_vm_t *vm) nxt_int_t -njs_vm_call(njs_vm_t *vm, njs_function_t *function, njs_opaque_value_t *args, +njs_vm_call(njs_vm_t *vm, njs_function_t *function, njs_value_t *args, nxt_uint_t nargs) { u_char *current; @@ -460,8 +460,7 @@ njs_vm_call(njs_vm_t *vm, njs_function_t this = (njs_value_t *) &njs_value_void; - ret = njs_function_frame(vm, function, this, - (njs_value_t *) args, nargs, 0); + ret = njs_function_frame(vm, function, this, args, nargs, 0); if (nxt_slow_path(ret != NXT_OK)) { return ret; } @@ -532,7 +531,7 @@ njs_vm_pending(njs_vm_t *vm) nxt_int_t njs_vm_post_event(njs_vm_t *vm, njs_vm_event_t vm_event, - njs_opaque_value_t *args, nxt_uint_t nargs) + njs_value_t *args, nxt_uint_t nargs) { njs_event_t *event; @@ -541,12 +540,12 @@ njs_vm_post_event(njs_vm_t *vm, njs_vm_e if (nargs != 0 && !event->posted) { event->nargs = nargs; event->args = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_opaque_value_t) * nargs); + sizeof(njs_value_t) * nargs); if (nxt_slow_path(event->args == NULL)) { return NJS_ERROR; } - memcpy(event->args, args, sizeof(njs_opaque_value_t) * nargs); + memcpy(event->args, args, sizeof(njs_value_t) * nargs); } if (!event->posted) { @@ -655,7 +654,7 @@ njs_vm_retval(njs_vm_t *vm) nxt_noinline void -njs_vm_retval_set(njs_vm_t *vm, njs_opaque_value_t *value) +njs_vm_retval_set(njs_vm_t *vm, njs_value_t *value) { vm->retval = *(njs_value_t *) value; } diff -r ed4721d09f60 -r d0e244bc8760 njs/njs.h --- a/njs/njs.h Fri May 04 19:25:15 2018 +0300 +++ b/njs/njs.h Fri May 04 19:53:19 2018 +0300 @@ -30,6 +30,11 @@ typedef struct njs_extern_s njs_ typedef struct njs_function_s njs_function_t; typedef struct njs_vm_shared_s njs_vm_shared_t; +/* + * njs_opaque_value_t is the external storage type for native njs_value_t type. + * sizeof(njs_opaque_value_t) == sizeof(njs_value_t). + */ + typedef struct { uint64_t filler[2]; } njs_opaque_value_t; @@ -42,6 +47,9 @@ typedef struct { #define njs_value_assign(dst, src) \ *((njs_opaque_value_t *) dst) = *((njs_opaque_value_t *) src); +#define njs_value_arg(val) ((njs_value_t *) val) + + #define njs_vm_error(vm, fmt, ...) \ njs_value_error_set(vm, njs_vm_retval(vm), fmt, ##__VA_ARGS__) @@ -147,7 +155,7 @@ NXT_EXPORT void njs_vm_destroy(njs_vm_t NXT_EXPORT nxt_int_t njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end); NXT_EXPORT njs_vm_t *njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external); NXT_EXPORT nxt_int_t njs_vm_call(njs_vm_t *vm, njs_function_t *function, - njs_opaque_value_t *args, nxt_uint_t nargs); + njs_value_t *args, nxt_uint_t nargs); NXT_EXPORT njs_vm_event_t njs_vm_add_event(njs_vm_t *vm, njs_function_t *function, njs_host_event_t host_ev, @@ -155,23 +163,23 @@ NXT_EXPORT njs_vm_event_t njs_vm_add_eve NXT_EXPORT void njs_vm_del_event(njs_vm_t *vm, njs_vm_event_t vm_event); NXT_EXPORT nxt_int_t njs_vm_pending(njs_vm_t *vm); NXT_EXPORT nxt_int_t njs_vm_post_event(njs_vm_t *vm, njs_vm_event_t vm_event, - njs_opaque_value_t *args, nxt_uint_t nargs); + njs_value_t *args, nxt_uint_t nargs); NXT_EXPORT nxt_int_t njs_vm_run(njs_vm_t *vm); NXT_EXPORT const njs_extern_t *njs_vm_external_prototype(njs_vm_t *vm, njs_external_t *external); NXT_EXPORT nxt_int_t njs_vm_external_create(njs_vm_t *vm, - njs_opaque_value_t *value, const njs_extern_t *proto, void *object); + njs_value_t *value, const njs_extern_t *proto, void *object); NXT_EXPORT nxt_int_t njs_vm_external_bind(njs_vm_t *vm, - const nxt_str_t *var_name, njs_opaque_value_t *value); + const nxt_str_t *var_name, njs_value_t *value); NXT_EXPORT void njs_disassembler(njs_vm_t *vm); NXT_EXPORT nxt_array_t *njs_vm_completions(njs_vm_t *vm, nxt_str_t *expression); NXT_EXPORT njs_function_t *njs_vm_function(njs_vm_t *vm, nxt_str_t *name); NXT_EXPORT njs_value_t *njs_vm_retval(njs_vm_t *vm); -NXT_EXPORT void njs_vm_retval_set(njs_vm_t *vm, njs_opaque_value_t *value); +NXT_EXPORT void njs_vm_retval_set(njs_vm_t *vm, njs_value_t *value); NXT_EXPORT u_char * njs_string_alloc(njs_vm_t *vm, njs_value_t *value, uint32_t size, uint32_t length); @@ -184,7 +192,7 @@ NXT_EXPORT nxt_int_t njs_value_string_co NXT_EXPORT njs_ret_t njs_vm_value_to_ext_string(njs_vm_t *vm, nxt_str_t *dst, const njs_value_t *src, nxt_uint_t handle_exception); NXT_EXPORT njs_ret_t njs_vm_retval_to_ext_string(njs_vm_t *vm, - nxt_str_t *retval); + nxt_str_t *retval); NXT_EXPORT void njs_vm_memory_error(njs_vm_t *vm); diff -r ed4721d09f60 -r d0e244bc8760 njs/njs_event.h --- a/njs/njs_event.h Fri May 04 19:25:15 2018 +0300 +++ b/njs/njs_event.h Fri May 04 19:53:19 2018 +0300 @@ -17,7 +17,7 @@ typedef struct { njs_function_t *function; - njs_opaque_value_t *args; + njs_value_t *args; nxt_uint_t nargs; njs_host_event_t host_event; njs_event_destructor destructor; diff -r ed4721d09f60 -r d0e244bc8760 njs/njs_extern.c --- a/njs/njs_extern.c Fri May 04 19:25:15 2018 +0300 +++ b/njs/njs_extern.c Fri May 04 19:53:19 2018 +0300 @@ -150,11 +150,10 @@ njs_vm_external_prototype(njs_vm_t *vm, nxt_int_t -njs_vm_external_create(njs_vm_t *vm, njs_opaque_value_t *value, +njs_vm_external_create(njs_vm_t *vm, njs_value_t *ext_val, const njs_extern_t *proto, void *object) { - void *obj; - njs_value_t *ext_val; + void *obj; if (nxt_slow_path(proto == NULL)) { return NXT_ERROR; @@ -168,8 +167,6 @@ njs_vm_external_create(njs_vm_t *vm, njs memcpy(obj, &object, sizeof(void *)); - ext_val = (njs_value_t *) value; - ext_val->type = NJS_EXTERNAL; ext_val->data.truth = 1; ext_val->external.proto = proto; @@ -181,15 +178,12 @@ njs_vm_external_create(njs_vm_t *vm, njs nxt_int_t njs_vm_external_bind(njs_vm_t *vm, const nxt_str_t *var_name, - njs_opaque_value_t *val) + njs_value_t *value) { nxt_int_t ret; - njs_value_t *value; njs_extern_value_t *ev; nxt_lvlhsh_query_t lhq; - value = (njs_value_t *) val; - if (nxt_slow_path(!njs_is_external(value))) { return NXT_ERROR; } diff -r ed4721d09f60 -r d0e244bc8760 njs/njs_shell.c --- a/njs/njs_shell.c Fri May 04 19:25:15 2018 +0300 +++ b/njs/njs_shell.c Fri May 04 19:53:19 2018 +0300 @@ -193,8 +193,8 @@ static nxt_int_t njs_externals_init(njs_vm_t *vm) { nxt_uint_t ret; + njs_value_t *value; const njs_extern_t *proto; - njs_opaque_value_t *value; static const nxt_str_t name = nxt_string_value("console"); diff -r ed4721d09f60 -r d0e244bc8760 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Fri May 04 19:25:15 2018 +0300 +++ b/njs/test/njs_unit_test.c Fri May 04 19:53:19 2018 +0300 @@ -9533,7 +9533,7 @@ njs_unit_test_create_external(njs_vm_t * { nxt_int_t ret; nxt_str_t uri; - njs_opaque_value_t *value; + njs_value_t *value; njs_unit_test_req_t *r, *sr; if (nargs > 1) { @@ -9737,15 +9737,15 @@ njs_externals_init(njs_vm_t *vm) requests[i].mem_cache_pool = vm->mem_cache_pool; requests[i].proto = proto; - ret = njs_vm_external_create(vm, &requests[i].value, proto, - &requests[i]); + ret = njs_vm_external_create(vm, njs_value_arg(&requests[i].value), + proto, &requests[i]); if (ret != NXT_OK) { printf("njs_vm_external_create() failed\n"); return NXT_ERROR; } ret = njs_vm_external_bind(vm, &nxt_test_requests[i].name, - &requests[i].value); + njs_value_arg(&requests[i].value)); if (ret != NXT_OK) { printf("njs_vm_external_bind() failed\n"); return NXT_ERROR; From xeioex at nginx.com Mon May 7 12:50:14 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Mon, 07 May 2018 12:50:14 +0000 Subject: [njs] Removed njscript.c Message-ID: details: http://hg.nginx.org/njs/rev/e33869a27515 branches: changeset: 519:e33869a27515 user: Dmitry Volyntsev date: Mon May 07 15:49:02 2018 +0300 description: Removed njscript.c The file was not deleted during renaming in 71455987b770. diffstat: njs/njscript.c | 707 --------------------------------------------------------- 1 files changed, 0 insertions(+), 707 deletions(-) diffs (711 lines): diff -r d0e244bc8760 -r e33869a27515 njs/njscript.c --- a/njs/njscript.c Fri May 04 19:53:19 2018 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,707 +0,0 @@ - -/* - * Copyright (C) Igor Sysoev - * Copyright (C) NGINX, Inc. - */ - -#include -#include - -#include - - -static nxt_int_t njs_vm_init(njs_vm_t *vm); -static nxt_int_t njs_vm_handle_events(njs_vm_t *vm); - - -static void * -njs_alloc(void *mem, size_t size) -{ - return nxt_malloc(size); -} - - -static void * -njs_zalloc(void *mem, size_t size) -{ - void *p; - - p = nxt_malloc(size); - - if (p != NULL) { - memset(p, 0, size); - } - - return p; -} - - -static void * -njs_align(void *mem, size_t alignment, size_t size) -{ - return nxt_memalign(alignment, size); -} - - -static void -njs_free(void *mem, void *p) -{ - nxt_free(p); -} - - -const nxt_mem_proto_t njs_vm_mem_cache_pool_proto = { - njs_alloc, - njs_zalloc, - njs_align, - NULL, - njs_free, - NULL, - NULL, -}; - - -static void * -njs_array_mem_alloc(void *mem, size_t size) -{ - return nxt_mem_cache_alloc(mem, size); -} - - -static void -njs_array_mem_free(void *mem, void *p) -{ - nxt_mem_cache_free(mem, p); -} - - -const nxt_mem_proto_t njs_array_mem_proto = { - njs_array_mem_alloc, - NULL, - NULL, - NULL, - njs_array_mem_free, - NULL, - NULL, -}; - - -njs_vm_t * -njs_vm_create(njs_vm_opt_t *options) -{ - njs_vm_t *vm; - nxt_int_t ret; - nxt_array_t *debug; - nxt_mem_cache_pool_t *mcp; - njs_regexp_pattern_t *pattern; - - mcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL, - NULL, 2 * nxt_pagesize(), 128, 512, 16); - if (nxt_slow_path(mcp == NULL)) { - return NULL; - } - - vm = nxt_mem_cache_zalign(mcp, sizeof(njs_value_t), sizeof(njs_vm_t)); - - if (nxt_fast_path(vm != NULL)) { - vm->mem_cache_pool = mcp; - - ret = njs_regexp_init(vm); - if (nxt_slow_path(ret != NXT_OK)) { - return NULL; - } - - if (options->shared != NULL) { - vm->shared = options->shared; - - } else { - vm->shared = nxt_mem_cache_zalloc(mcp, sizeof(njs_vm_shared_t)); - if (nxt_slow_path(vm->shared == NULL)) { - return NULL; - } - - options->shared = vm->shared; - - nxt_lvlhsh_init(&vm->shared->keywords_hash); - - ret = njs_lexer_keywords_init(mcp, &vm->shared->keywords_hash); - if (nxt_slow_path(ret != NXT_OK)) { - return NULL; - } - - nxt_lvlhsh_init(&vm->shared->values_hash); - - pattern = njs_regexp_pattern_create(vm, (u_char *) "(?:)", - sizeof("(?:)") - 1, 0); - if (nxt_slow_path(pattern == NULL)) { - return NULL; - } - - vm->shared->empty_regexp_pattern = pattern; - - nxt_lvlhsh_init(&vm->modules_hash); - - ret = njs_builtin_objects_create(vm); - if (nxt_slow_path(ret != NXT_OK)) { - return NULL; - } - } - - nxt_lvlhsh_init(&vm->values_hash); - - vm->external = options->external; - - vm->external_objects = nxt_array_create(4, sizeof(void *), - &njs_array_mem_proto, - vm->mem_cache_pool); - if (nxt_slow_path(vm->external_objects == NULL)) { - return NULL; - } - - nxt_lvlhsh_init(&vm->externals_hash); - nxt_lvlhsh_init(&vm->external_prototypes_hash); - - vm->ops = options->ops; - - vm->trace.level = NXT_LEVEL_TRACE; - vm->trace.size = 2048; - vm->trace.handler = njs_parser_trace_handler; - vm->trace.data = vm; - - vm->trailer = options->trailer; - - if (options->backtrace) { - debug = nxt_array_create(4, sizeof(njs_function_debug_t), - &njs_array_mem_proto, - vm->mem_cache_pool); - if (nxt_slow_path(debug == NULL)) { - return NULL; - } - - vm->debug = debug; - } - - vm->accumulative = options->accumulative; - if (vm->accumulative) { - ret = njs_vm_init(vm); - if (nxt_slow_path(ret != NXT_OK)) { - return NULL; - } - - vm->retval = njs_value_void; - } - } - - return vm; -} - - -void -njs_vm_destroy(njs_vm_t *vm) -{ - njs_event_t *event; - nxt_lvlhsh_each_t lhe; - - if (njs_is_pending_events(vm)) { - nxt_lvlhsh_each_init(&lhe, &njs_event_hash_proto); - - for ( ;; ) { - event = nxt_lvlhsh_each(&vm->events_hash, &lhe); - - if (event == NULL) { - break; - } - - njs_del_event(vm, event, NJS_EVENT_RELEASE); - } - } - - nxt_mem_cache_pool_destroy(vm->mem_cache_pool); -} - - -nxt_int_t -njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end) -{ - nxt_int_t ret; - njs_lexer_t *lexer; - njs_parser_t *parser, *prev; - njs_parser_node_t *node; - - parser = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_parser_t)); - if (nxt_slow_path(parser == NULL)) { - return NJS_ERROR; - } - - if (vm->parser != NULL && !vm->accumulative) { - return NJS_ERROR; - } - - prev = vm->parser; - vm->parser = parser; - - lexer = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_lexer_t)); - if (nxt_slow_path(lexer == NULL)) { - return NJS_ERROR; - } - - parser->lexer = lexer; - lexer->start = *start; - lexer->end = end; - lexer->line = 1; - lexer->keywords_hash = vm->shared->keywords_hash; - - parser->code_size = sizeof(njs_vmcode_stop_t); - parser->scope_offset = NJS_INDEX_GLOBAL_OFFSET; - - if (vm->backtrace != NULL) { - nxt_array_reset(vm->backtrace); - } - - node = njs_parser(vm, parser, prev); - if (nxt_slow_path(node == NULL)) { - goto fail; - } - - ret = njs_variables_scope_reference(vm, parser->scope); - if (nxt_slow_path(ret != NXT_OK)) { - goto fail; - } - - *start = parser->lexer->start; - - /* - * Reset the code array to prevent it from being disassembled - * again in the next iteration of the accumulative mode. - */ - vm->code = NULL; - - ret = njs_generate_scope(vm, parser, node); - if (nxt_slow_path(ret != NXT_OK)) { - goto fail; - } - - vm->current = parser->code_start; - - vm->global_scope = parser->local_scope; - vm->scope_size = parser->scope_size; - vm->variables_hash = parser->scope->variables; - - return NJS_OK; - -fail: - - vm->parser = prev; - - return NXT_ERROR; -} - - -njs_vm_t * -njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) -{ - njs_vm_t *nvm; - uint32_t items; - nxt_int_t ret; - nxt_array_t *externals; - nxt_mem_cache_pool_t *nmcp; - - nxt_thread_log_debug("CLONE:"); - - if (vm->accumulative) { - return NULL; - } - - nmcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL, - NULL, 2 * nxt_pagesize(), 128, 512, 16); - if (nxt_slow_path(nmcp == NULL)) { - return NULL; - } - - nvm = nxt_mem_cache_zalign(nmcp, sizeof(njs_value_t), sizeof(njs_vm_t)); - - if (nxt_fast_path(nvm != NULL)) { - nvm->mem_cache_pool = nmcp; - - nvm->shared = vm->shared; - - nvm->variables_hash = vm->variables_hash; - nvm->values_hash = vm->values_hash; - nvm->modules_hash = vm->modules_hash; - - nvm->externals_hash = vm->externals_hash; - nvm->external_prototypes_hash = vm->external_prototypes_hash; - - items = vm->external_objects->items; - externals = nxt_array_create(items + 4, sizeof(void *), - &njs_array_mem_proto, nvm->mem_cache_pool); - - if (nxt_slow_path(externals == NULL)) { - return NULL; - } - - if (items > 0) { - memcpy(externals->start, vm->external_objects->start, - items * sizeof(void *)); - externals->items = items; - } - - nvm->external_objects = externals; - - nvm->ops = vm->ops; - - nvm->current = vm->current; - - nvm->external = external; - - nvm->global_scope = vm->global_scope; - nvm->scope_size = vm->scope_size; - - nvm->debug = vm->debug; - - ret = njs_vm_init(nvm); - if (nxt_slow_path(ret != NXT_OK)) { - goto fail; - } - - nvm->retval = njs_value_void; - - return nvm; - } - -fail: - - nxt_mem_cache_pool_destroy(nmcp); - - return NULL; -} - - -static nxt_int_t -njs_vm_init(njs_vm_t *vm) -{ - size_t size, scope_size; - u_char *values; - nxt_int_t ret; - njs_frame_t *frame; - nxt_array_t *backtrace; - - scope_size = vm->scope_size + NJS_INDEX_GLOBAL_OFFSET; - - size = NJS_GLOBAL_FRAME_SIZE + scope_size + NJS_FRAME_SPARE_SIZE; - size = nxt_align_size(size, NJS_FRAME_SPARE_SIZE); - - frame = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), size); - if (nxt_slow_path(frame == NULL)) { - return NXT_ERROR; - } - - memset(frame, 0, NJS_GLOBAL_FRAME_SIZE); - - vm->top_frame = &frame->native; - vm->active_frame = frame; - - frame->native.size = size; - frame->native.free_size = size - (NJS_GLOBAL_FRAME_SIZE + scope_size); - - values = (u_char *) frame + NJS_GLOBAL_FRAME_SIZE; - - frame->native.free = values + scope_size; - - vm->scopes[NJS_SCOPE_GLOBAL] = (njs_value_t *) values; - memcpy(values + NJS_INDEX_GLOBAL_OFFSET, vm->global_scope, - vm->scope_size); - - ret = njs_regexp_init(vm); - if (nxt_slow_path(ret != NXT_OK)) { - return NXT_ERROR; - } - - ret = njs_builtin_objects_clone(vm); - if (nxt_slow_path(ret != NXT_OK)) { - return NXT_ERROR; - } - - nxt_lvlhsh_init(&vm->events_hash); - nxt_queue_init(&vm->posted_events); - - if (vm->debug != NULL) { - backtrace = nxt_array_create(4, sizeof(njs_backtrace_entry_t), - &njs_array_mem_proto, vm->mem_cache_pool); - if (nxt_slow_path(backtrace == NULL)) { - return NXT_ERROR; - } - - vm->backtrace = backtrace; - } - - vm->trace.level = NXT_LEVEL_TRACE; - vm->trace.size = 2048; - vm->trace.handler = njs_parser_trace_handler; - vm->trace.data = vm; - - return NXT_OK; -} - - -nxt_int_t -njs_vm_call(njs_vm_t *vm, njs_function_t *function, njs_opaque_value_t *args, - nxt_uint_t nargs) -{ - u_char *current; - njs_ret_t ret; - njs_value_t *this; - - static const njs_vmcode_stop_t stop[] = { - { .code = { .operation = njs_vmcode_stop, - .operands = NJS_VMCODE_1OPERAND, - .retval = NJS_VMCODE_NO_RETVAL }, - .retval = NJS_INDEX_GLOBAL_RETVAL }, - }; - - this = (njs_value_t *) &njs_value_void; - - ret = njs_function_frame(vm, function, this, - (njs_value_t *) args, nargs, 0); - if (nxt_slow_path(ret != NXT_OK)) { - return ret; - } - - current = vm->current; - vm->current = (u_char *) stop; - - ret = njs_function_call(vm, NJS_INDEX_GLOBAL_RETVAL, 0); - if (nxt_slow_path(ret == NXT_ERROR)) { - return ret; - } - - ret = njs_vmcode_interpreter(vm); - - vm->current = current; - - if (ret == NJS_STOP) { - ret = NXT_OK; - } - - return ret; -} - - -njs_vm_event_t -njs_vm_add_event(njs_vm_t *vm, njs_function_t *function, - njs_host_event_t host_ev, njs_event_destructor destructor) -{ - njs_event_t *event; - - event = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_event_t)); - if (nxt_slow_path(event == NULL)) { - return NULL; - } - - event->host_event = host_ev; - event->destructor = destructor; - event->function = function; - event->posted = 0; - event->nargs = 0; - event->args = NULL; - - if (njs_add_event(vm, event) != NJS_OK) { - return NULL; - } - - return event; -} - - -void -njs_vm_del_event(njs_vm_t *vm, njs_vm_event_t vm_event) -{ - njs_event_t *event; - - event = (njs_event_t *) vm_event; - - njs_del_event(vm, event, NJS_EVENT_RELEASE | NJS_EVENT_DELETE); -} - - -nxt_int_t -njs_vm_pending(njs_vm_t *vm) -{ - return njs_is_pending_events(vm); -} - - -nxt_int_t -njs_vm_post_event(njs_vm_t *vm, njs_vm_event_t vm_event, - njs_opaque_value_t *args, nxt_uint_t nargs) -{ - njs_event_t *event; - - event = (njs_event_t *) vm_event; - - if (nargs != 0 && !event->posted) { - event->nargs = nargs; - event->args = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_opaque_value_t) * nargs); - if (nxt_slow_path(event->args == NULL)) { - return NJS_ERROR; - } - - memcpy(event->args, args, sizeof(njs_opaque_value_t) * nargs); - } - - if (!event->posted) { - event->posted = 1; - nxt_queue_insert_tail(&vm->posted_events, &event->link); - } - - return NJS_OK; -} - - -nxt_int_t -njs_vm_run(njs_vm_t *vm) -{ - nxt_str_t s; - nxt_int_t ret; - - nxt_thread_log_debug("RUN:"); - - if (vm->backtrace != NULL) { - nxt_array_reset(vm->backtrace); - } - - ret = njs_vmcode_interpreter(vm); - - if (ret == NJS_STOP) { - ret = njs_vm_handle_events(vm); - } - - if (nxt_slow_path(ret == NXT_AGAIN)) { - nxt_thread_log_debug("VM: AGAIN"); - return ret; - } - - if (nxt_slow_path(ret != NJS_STOP)) { - nxt_thread_log_debug("VM: ERROR"); - return ret; - } - - if (vm->retval.type == NJS_NUMBER) { - nxt_thread_log_debug("VM: %f", vm->retval.data.u.number); - - } else if (vm->retval.type == NJS_BOOLEAN) { - nxt_thread_log_debug("VM: boolean: %d", vm->retval.data.truth); - - } else if (vm->retval.type == NJS_STRING) { - - if (njs_vm_value_to_ext_string(vm, &s, &vm->retval, 0) == NJS_OK) { - nxt_thread_log_debug("VM: '%V'", &s); - } - - } else if (vm->retval.type == NJS_FUNCTION) { - nxt_thread_log_debug("VM: function"); - - } else if (vm->retval.type == NJS_NULL) { - nxt_thread_log_debug("VM: null"); - - } else if (vm->retval.type == NJS_VOID) { - nxt_thread_log_debug("VM: void"); - - } else { - nxt_thread_log_debug("VM: unknown: %d", vm->retval.type); - } - - return NJS_OK; -} - - -static nxt_int_t -njs_vm_handle_events(njs_vm_t *vm) -{ - nxt_int_t ret; - njs_event_t *ev; - nxt_queue_t *events; - nxt_queue_link_t *link; - - events = &vm->posted_events; - - for ( ;; ) { - link = nxt_queue_first(events); - - if (link == nxt_queue_tail(events)) { - break; - } - - ev = nxt_queue_link_data(link, njs_event_t, link); - - njs_del_event(vm, ev, NJS_EVENT_DELETE); - - ret = njs_vm_call(vm, ev->function, ev->args, ev->nargs); - - if (ret == NJS_ERROR) { - return ret; - } - } - - return njs_is_pending_events(vm) ? NJS_AGAIN : NJS_STOP; -} - - -nxt_noinline njs_value_t * -njs_vm_retval(njs_vm_t *vm) -{ - return &vm->retval; -} - - -nxt_noinline void -njs_vm_retval_set(njs_vm_t *vm, njs_opaque_value_t *value) -{ - vm->retval = *(njs_value_t *) value; -} - - -nxt_noinline void -njs_vm_memory_error(njs_vm_t *vm) -{ - njs_set_memory_error(vm, &vm->retval); -} - - -njs_ret_t njs_vm_retval_to_ext_string(njs_vm_t *vm, nxt_str_t *retval) -{ - if (vm->top_frame == NULL) { - /* An exception was thrown during compilation. */ - - njs_vm_init(vm); - } - - return njs_vm_value_to_ext_string(vm, retval, &vm->retval, 1); -} - - -njs_value_t * -njs_vm_object_prop(njs_vm_t *vm, njs_value_t *value, const nxt_str_t *key) -{ - nxt_int_t ret; - njs_object_prop_t *prop; - nxt_lvlhsh_query_t lhq; - - if (nxt_slow_path(!njs_is_object(value))) { - return NULL; - } - - lhq.key = *key; - lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); - lhq.proto = &njs_object_hash_proto; - - ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq); - if (nxt_slow_path(ret != NXT_OK)) { - return NULL; - } - - prop = lhq.value; - - return &prop->value; -} From pluknet at nginx.com Tue May 8 10:42:46 2018 From: pluknet at nginx.com (Sergey Kandaurov) Date: Tue, 08 May 2018 10:42:46 +0000 Subject: [nginx] Silenced -Wcast-function-type warnings (closes #1546). Message-ID: details: http://hg.nginx.org/nginx/rev/9e25a5380a21 branches: changeset: 7271:9e25a5380a21 user: Sergey Kandaurov date: Mon May 07 09:54:37 2018 +0000 description: Silenced -Wcast-function-type warnings (closes #1546). Cast to intermediate "void *" to lose compiler knowledge about the original type and pass the warning. This is not a real fix but rather a workaround. Found by gcc8. diffstat: src/http/modules/ngx_http_fastcgi_module.c | 6 ++++-- src/http/modules/ngx_http_grpc_module.c | 3 ++- src/http/modules/ngx_http_proxy_module.c | 3 ++- src/http/modules/ngx_http_scgi_module.c | 6 ++++-- src/http/modules/ngx_http_uwsgi_module.c | 6 ++++-- src/http/ngx_http_script.c | 13 ++++++++----- src/stream/ngx_stream_script.c | 13 +++++++------ 7 files changed, 31 insertions(+), 19 deletions(-) diffs (183 lines): diff -r 46c0c7ef4913 -r 9e25a5380a21 src/http/modules/ngx_http_fastcgi_module.c --- a/src/http/modules/ngx_http_fastcgi_module.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/http/modules/ngx_http_fastcgi_module.c Mon May 07 09:54:37 2018 +0000 @@ -3264,7 +3264,8 @@ ngx_http_fastcgi_init_params(ngx_conf_t return NGX_ERROR; } - copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; + copy->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_len_code; copy->len = src[i].key.len; copy = ngx_array_push_n(params->lengths, @@ -3273,7 +3274,8 @@ ngx_http_fastcgi_init_params(ngx_conf_t return NGX_ERROR; } - copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; + copy->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_len_code; copy->len = src[i].skip_empty; diff -r 46c0c7ef4913 -r 9e25a5380a21 src/http/modules/ngx_http_grpc_module.c --- a/src/http/modules/ngx_http_grpc_module.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/http/modules/ngx_http_grpc_module.c Mon May 07 09:54:37 2018 +0000 @@ -4389,7 +4389,8 @@ ngx_http_grpc_init_headers(ngx_conf_t *c return NGX_ERROR; } - copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; + copy->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_len_code; copy->len = src[i].key.len; size = (sizeof(ngx_http_script_copy_code_t) diff -r 46c0c7ef4913 -r 9e25a5380a21 src/http/modules/ngx_http_proxy_module.c --- a/src/http/modules/ngx_http_proxy_module.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/http/modules/ngx_http_proxy_module.c Mon May 07 09:54:37 2018 +0000 @@ -3493,7 +3493,8 @@ ngx_http_proxy_init_headers(ngx_conf_t * return NGX_ERROR; } - copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; + copy->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_len_code; copy->len = src[i].key.len; size = (sizeof(ngx_http_script_copy_code_t) diff -r 46c0c7ef4913 -r 9e25a5380a21 src/http/modules/ngx_http_scgi_module.c --- a/src/http/modules/ngx_http_scgi_module.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/http/modules/ngx_http_scgi_module.c Mon May 07 09:54:37 2018 +0000 @@ -1724,7 +1724,8 @@ ngx_http_scgi_init_params(ngx_conf_t *cf return NGX_ERROR; } - copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; + copy->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_len_code; copy->len = src[i].key.len + 1; copy = ngx_array_push_n(params->lengths, @@ -1733,7 +1734,8 @@ ngx_http_scgi_init_params(ngx_conf_t *cf return NGX_ERROR; } - copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; + copy->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_len_code; copy->len = src[i].skip_empty; diff -r 46c0c7ef4913 -r 9e25a5380a21 src/http/modules/ngx_http_uwsgi_module.c --- a/src/http/modules/ngx_http_uwsgi_module.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/http/modules/ngx_http_uwsgi_module.c Mon May 07 09:54:37 2018 +0000 @@ -1987,7 +1987,8 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c return NGX_ERROR; } - copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; + copy->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_len_code; copy->len = src[i].key.len; copy = ngx_array_push_n(params->lengths, @@ -1996,7 +1997,8 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c return NGX_ERROR; } - copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; + copy->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_len_code; copy->len = src[i].skip_empty; diff -r 46c0c7ef4913 -r 9e25a5380a21 src/http/ngx_http_script.c --- a/src/http/ngx_http_script.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/http/ngx_http_script.c Mon May 07 09:54:37 2018 +0000 @@ -695,7 +695,8 @@ ngx_http_script_add_copy_code(ngx_http_s return NGX_ERROR; } - code->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; + code->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_len_code; code->len = len; size = (sizeof(ngx_http_script_copy_code_t) + len + sizeof(uintptr_t) - 1) @@ -784,7 +785,8 @@ ngx_http_script_add_var_code(ngx_http_sc return NGX_ERROR; } - code->code = (ngx_http_script_code_pt) ngx_http_script_copy_var_len_code; + code->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_var_len_code; code->index = (uintptr_t) index; code = ngx_http_script_add_code(*sc->values, @@ -1178,8 +1180,8 @@ ngx_http_script_add_capture_code(ngx_htt return NGX_ERROR; } - code->code = (ngx_http_script_code_pt) - ngx_http_script_copy_capture_len_code; + code->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_copy_capture_len_code; code->n = 2 * n; @@ -1293,7 +1295,8 @@ ngx_http_script_add_full_name_code(ngx_h return NGX_ERROR; } - code->code = (ngx_http_script_code_pt) ngx_http_script_full_name_len_code; + code->code = (ngx_http_script_code_pt) (void *) + ngx_http_script_full_name_len_code; code->conf_prefix = sc->conf_prefix; code = ngx_http_script_add_code(*sc->values, diff -r 46c0c7ef4913 -r 9e25a5380a21 src/stream/ngx_stream_script.c --- a/src/stream/ngx_stream_script.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/stream/ngx_stream_script.c Mon May 07 09:54:37 2018 +0000 @@ -587,7 +587,8 @@ ngx_stream_script_add_copy_code(ngx_stre return NGX_ERROR; } - code->code = (ngx_stream_script_code_pt) ngx_stream_script_copy_len_code; + code->code = (ngx_stream_script_code_pt) (void *) + ngx_stream_script_copy_len_code; code->len = len; size = (sizeof(ngx_stream_script_copy_code_t) + len + sizeof(uintptr_t) - 1) @@ -677,8 +678,8 @@ ngx_stream_script_add_var_code(ngx_strea return NGX_ERROR; } - code->code = (ngx_stream_script_code_pt) - ngx_stream_script_copy_var_len_code; + code->code = (ngx_stream_script_code_pt) (void *) + ngx_stream_script_copy_var_len_code; code->index = (uintptr_t) index; code = ngx_stream_script_add_code(*sc->values, @@ -767,8 +768,8 @@ ngx_stream_script_add_capture_code(ngx_s return NGX_ERROR; } - code->code = (ngx_stream_script_code_pt) - ngx_stream_script_copy_capture_len_code; + code->code = (ngx_stream_script_code_pt) (void *) + ngx_stream_script_copy_capture_len_code; code->n = 2 * n; @@ -859,7 +860,7 @@ ngx_stream_script_add_full_name_code(ngx return NGX_ERROR; } - code->code = (ngx_stream_script_code_pt) + code->code = (ngx_stream_script_code_pt) (void *) ngx_stream_script_full_name_len_code; code->conf_prefix = sc->conf_prefix; From vl at nginx.com Tue May 8 17:05:30 2018 From: vl at nginx.com (Vladimir Homutov) Date: Tue, 08 May 2018 17:05:30 +0000 Subject: [nginx] Syslog: re-open syslog udp socket on send error (ticket #1477). Message-ID: details: http://hg.nginx.org/nginx/rev/fa0e093b64d7 branches: changeset: 7272:fa0e093b64d7 user: Vladimir Homutov date: Tue May 08 19:35:56 2018 +0300 description: Syslog: re-open syslog udp socket on send error (ticket #1477). Previously, only unix domain sockets were reopened to tolerate cases when local syslog server was restarted. It makes sense to treat other cases (for example, local IP address changes) similarly. diffstat: src/core/ngx_syslog.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-) diffs (23 lines): diff -r 9e25a5380a21 -r fa0e093b64d7 src/core/ngx_syslog.c --- a/src/core/ngx_syslog.c Mon May 07 09:54:37 2018 +0000 +++ b/src/core/ngx_syslog.c Tue May 08 19:35:56 2018 +0300 @@ -289,9 +289,7 @@ ngx_syslog_send(ngx_syslog_peer_t *peer, n = ngx_os_io.send(&peer->conn, buf, len); } -#if (NGX_HAVE_UNIX_DOMAIN) - - if (n == NGX_ERROR && peer->server.sockaddr->sa_family == AF_UNIX) { + if (n == NGX_ERROR) { if (ngx_close_socket(peer->conn.fd) == -1) { ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, @@ -301,8 +299,6 @@ ngx_syslog_send(ngx_syslog_peer_t *peer, peer->conn.fd = (ngx_socket_t) -1; } -#endif - return n; } From luhliari at redhat.com Wed May 9 15:00:54 2018 From: luhliari at redhat.com (Lubos Uhliarik) Date: Wed, 9 May 2018 11:00:54 -0400 (EDT) Subject: nginx log uid/gid In-Reply-To: <406300204.552318.1525874292057.JavaMail.zimbra@redhat.com> Message-ID: <221673690.567972.1525878054108.JavaMail.zimbra@redhat.com> Hello nginx devel list, I'm experiencing following situation. When nginx is started, it creates logs in its log directory with following permissions: # ls -la /var/log/nginx total 12 drwxrwx---. 2 nginx root 4096 May 9 09:59 . drwxr-xr-x. 9 root root 4096 May 9 07:01 .. -rw-r--r--. 1 root root 0 May 9 09:59 access.log -rw-r--r--. 1 root root 374 May 9 09:59 error.log But when I send USR1 signal to nginx master process (for log rotation), it creates files with different owner (user specified in nginx configuration - in this case "nginx" user). # rm /var/log/nginx/*.log # systemctl kill --signal=USR1 nginx # ls -la /var/log/nginx total 8 drwxrwx---. 2 nginx root 4096 May 9 10:02 . drwxr-xr-x. 9 root root 4096 May 9 07:01 .. -rw-r--r--. 1 nginx root 0 May 9 10:02 access.log -rw-r--r--. 1 nginx root 0 May 9 10:02 error.log Is this behavior desired? I guess so, since in /src/os/unix/ngx_process_cycle.c is: if (ngx_reopen) { ngx_reopen = 0; ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs"); ngx_reopen_files(cycle, ccf->user); ngx_signal_worker_processes(cycle, ngx_signal_value(NGX_REOPEN_SIGNAL)); } ngx_reopen_files function call has second param set (ccf->user), which is in all other cases -1. Why do you change owner only after processing USR1 signal? This causes problem, when nginx is restarted: # systemctl restart nginx Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. # systemctl status nginx.service ? nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Wed 2018-05-09 10:12:21 EDT; 5s ago Process: 1805 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 1817 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE) Process: 1816 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 1806 (code=exited, status=0/SUCCESS) May 09 10:12:21 host-172-16-36-25 systemd[1]: Starting The nginx HTTP and reverse proxy server... May 09 10:12:21 host-172-16-36-25 nginx[1817]: nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) May 09 10:12:21 host-172-16-36-25 nginx[1817]: 2018/05/09 10:12:21 [warn] 1817#0: could not build optimal types_hash, you should increase either types_hash_max_size: 2048 o> May 09 10:12:21 host-172-16-36-25 nginx[1817]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok May 09 10:12:21 host-172-16-36-25 nginx[1817]: 2018/05/09 10:12:21 [emerg] 1817#0: open() "/var/log/nginx/error.log" failed (13: Permission denied) May 09 10:12:21 host-172-16-36-25 nginx[1817]: nginx: configuration file /etc/nginx/nginx.conf test failed May 09 10:12:21 host-172-16-36-25 systemd[1]: nginx.service: Control process exited, code=exited status=1 May 09 10:12:21 host-172-16-36-25 systemd[1]: nginx.service: Failed with result 'exit-code'. May 09 10:12:21 host-172-16-36-25 systemd[1]: Failed to start The nginx HTTP and reverse proxy server. This is a problem with SELinux (dac_override). Since master process runs as root, /var/log/nginx has ownership nginx:root, permissions 770 and NGX_FILE_DEFAULT_ACCESS is 644 for newly created logs. One possible solution is to set different permission mode for newly created logs (664 with nginx:root ownership) or do not set owner of log files to nginx user (which had probably some reason in past because of extra param in ngx_reopen_files). Thank you for your help or advice! Best, -- Lubos Uhliarik Software Engineer - EMEA ENG Developer Experience RH - Brno - TPB-C - 1D221 IRC: zero_byte at irc.freenode.net RED HAT | TRIED. TESTED. TRUSTED. Every airline in the Fortune 500 relies on Red Hat. Find out why at http://www.redhat.com/en/about/trusted Red Hat Inc. http://cz.redhat.com From teward at thomas-ward.net Wed May 9 16:29:06 2018 From: teward at thomas-ward.net (Thomas Ward) Date: Wed, 9 May 2018 12:29:06 -0400 Subject: Is there a particular reason --with-compat isn't enabled by default? Message-ID: <128a79cb-96d2-1118-fdd3-0d3a66e2bf7a@thomas-ward.net> In regards to several off-lists inquiries downstream about people trying to add additional third party modules, I've gone and started seeking justification for enabling --with-compat. Downstream in Ubuntu, I'm getting pushback in that the question of "Why do we need to enable this, what does it add?".? I'm trying to find that justification for it, and the best I can find is Maxim's statements on a 2016 email/forum thread about how it actually makes dynamic module support truly work (in a nutshell).? [1] Further, there's pushback about "Will package security updates and patches change the module ABI on security fixes or bug fixes?".? I don't have a clear answer on this, and I had this question back when dynamic module support was introduced, but never got a clear answer on this point.? It does beg consideration with regards to dynamic module support whether a simple patch applied to the same exact NGINX version will break ABI.? The way we handle security patches and such downstream is we apply patches to the existing NGINX version via `quilt`, which applies the patch at build time.? Whether this makes an ABI change or not I couldn't say, so I'm hunting a response from you, the devs, to give me a clear answer on this. So, for those who didn't read everything there's two questions here: ?(A) Other than making dynamic module support "work better", what does --with-compat actually do behind the scenes (In a nutshell)? ?(B) Will a simple patch that patches security issues or adds fixes to something later on but doesn't change the core NGINX version numbering change the module ABI in such a way that it'll break modules built against nginx without that patch (assuming that --with-compat was added, since it's apparently needed to make dynamic modules 'actually work') Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From ru at nginx.com Thu May 10 09:52:26 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Thu, 10 May 2018 09:52:26 +0000 Subject: [nginx] Configure: fixed clang version detection (closes #1539). Message-ID: details: http://hg.nginx.org/nginx/rev/ceab908790c4 branches: changeset: 7273:ceab908790c4 user: Ruslan Ermilov date: Tue Apr 24 14:04:59 2018 +0300 description: Configure: fixed clang version detection (closes #1539). While 325b3042edd6 fixed it on MINIX, it broke it on systems that output the word "version" on several lines with "cc -v". The fix is to only consider "clang version" or "LLVM version" as clang version, but this time only using sed(1). diffstat: auto/cc/clang | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diffs (13 lines): diff -r fa0e093b64d7 -r ceab908790c4 auto/cc/clang --- a/auto/cc/clang Tue May 08 19:35:56 2018 +0300 +++ b/auto/cc/clang Tue Apr 24 14:04:59 2018 +0300 @@ -6,7 +6,8 @@ NGX_CLANG_VER=`$CC -v 2>&1 | grep 'version' 2>&1 \ - | sed -e 's/^.* version \(.*\)/\1/'` + | sed -n -e 's/^.*clang version \(.*\)/\1/p' \ + -e 's/^.*LLVM version \(.*\)/\1/p'` echo " + clang version: $NGX_CLANG_VER" From ru at nginx.com Thu May 10 10:17:41 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Thu, 10 May 2018 13:17:41 +0300 Subject: Is there a particular reason --with-compat isn't enabled by default? In-Reply-To: <128a79cb-96d2-1118-fdd3-0d3a66e2bf7a@thomas-ward.net> References: <128a79cb-96d2-1118-fdd3-0d3a66e2bf7a@thomas-ward.net> Message-ID: <20180510101741.GE40212@lo0.su> On Wed, May 09, 2018 at 12:29:06PM -0400, Thomas Ward wrote: > In regards to several off-lists inquiries downstream about people trying > to add additional third party modules, I've gone and started seeking > justification for enabling --with-compat. > > Downstream in Ubuntu, I'm getting pushback in that the question of "Why > do we need to enable this, what does it add?".? I'm trying to find that > justification for it, and the best I can find is Maxim's statements on a > 2016 email/forum thread about how it actually makes dynamic module > support truly work (in a nutshell).? [1] > > Further, there's pushback about "Will package security updates and > patches change the module ABI on security fixes or bug fixes?".? I don't > have a clear answer on this, and I had this question back when dynamic > module support was introduced, but never got a clear answer on this > point.? It does beg consideration with regards to dynamic module support > whether a simple patch applied to the same exact NGINX version will > break ABI.? The way we handle security patches and such downstream is we > apply patches to the existing NGINX version via `quilt`, which applies > the patch at build time.? Whether this makes an ABI change or not I > couldn't say, so I'm hunting a response from you, the devs, to give me a > clear answer on this. > > So, for those who didn't read everything there's two questions here: > > ?(A) Other than making dynamic module support "work better", what does > --with-compat actually do behind the scenes (In a nutshell)? It enables some macros and alters some structures in a way that's compatible with NGINX Plus, built with the same option. Practically this means that checksums of module loadable objects will be identical between when using F/OSS sources and when using NGINX Plus sources. Searching for "NGX_COMPAT" throughout the F/OSS source code will give enough details. > ?(B) Will a simple patch that patches security issues or adds fixes to > something later on but doesn't change the core NGINX version numbering > change the module ABI in such a way that it'll break modules built > against nginx without that patch (assuming that --with-compat was added, > since it's apparently needed to make dynamic modules 'actually work') If a patch is simple, this is highly unlikely. For a patch to break the ABI, at least some externally visible structures should be changed in some backwards incompatible ways. From mdounin at mdounin.ru Thu May 10 12:19:12 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 10 May 2018 15:19:12 +0300 Subject: nginx log uid/gid In-Reply-To: <221673690.567972.1525878054108.JavaMail.zimbra@redhat.com> References: <406300204.552318.1525874292057.JavaMail.zimbra@redhat.com> <221673690.567972.1525878054108.JavaMail.zimbra@redhat.com> Message-ID: <20180510121912.GT32137@mdounin.ru> Hello! On Wed, May 09, 2018 at 11:00:54AM -0400, Lubos Uhliarik wrote: > Hello nginx devel list, > > I'm experiencing following situation. When nginx is started, it creates logs in its log directory with following permissions: > > # ls -la /var/log/nginx > total 12 > drwxrwx---. 2 nginx root 4096 May 9 09:59 . > drwxr-xr-x. 9 root root 4096 May 9 07:01 .. > -rw-r--r--. 1 root root 0 May 9 09:59 access.log > -rw-r--r--. 1 root root 374 May 9 09:59 error.log > > But when I send USR1 signal to nginx master process (for log rotation), it creates files with different owner (user specified > in nginx configuration - in this case "nginx" user). > > # rm /var/log/nginx/*.log > # systemctl kill --signal=USR1 nginx > # ls -la /var/log/nginx > total 8 > drwxrwx---. 2 nginx root 4096 May 9 10:02 . > drwxr-xr-x. 9 root root 4096 May 9 07:01 .. > -rw-r--r--. 1 nginx root 0 May 9 10:02 access.log > -rw-r--r--. 1 nginx root 0 May 9 10:02 error.log > > Is this behavior desired? I guess so, since in /src/os/unix/ngx_process_cycle.c is: > > if (ngx_reopen) { > ngx_reopen = 0; > ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs"); > ngx_reopen_files(cycle, ccf->user); > ngx_signal_worker_processes(cycle, > ngx_signal_value(NGX_REOPEN_SIGNAL)); > } > > ngx_reopen_files function call has second param set (ccf->user), which is in all other > cases -1. Why do you change owner only after processing USR1 signal? This causes problem, > when nginx is restarted: After the USR1 signal nginx have to ensure that already running worker processess will be able to open new log files for writing. To do so, it ensures that files are owned by the nginx user, and have at least 0600 access mode. (Note well that by using nginx:root on /var/log/nginx you are allowing privilage escalation similar to one previously seen in Debian packages, see CVE-2016-1247.) > # systemctl restart nginx > Job for nginx.service failed because the control process exited with error code. > See "systemctl status nginx.service" and "journalctl -xe" for details. > > # systemctl status nginx.service > ? nginx.service - The nginx HTTP and reverse proxy server > Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) > Active: failed (Result: exit-code) since Wed 2018-05-09 10:12:21 EDT; 5s ago > Process: 1805 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) > Process: 1817 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE) > Process: 1816 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) > Main PID: 1806 (code=exited, status=0/SUCCESS) > > May 09 10:12:21 host-172-16-36-25 systemd[1]: Starting The nginx HTTP and reverse proxy server... > May 09 10:12:21 host-172-16-36-25 nginx[1817]: nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) > May 09 10:12:21 host-172-16-36-25 nginx[1817]: 2018/05/09 10:12:21 [warn] 1817#0: could not build optimal types_hash, you should increase either types_hash_max_size: 2048 o> > May 09 10:12:21 host-172-16-36-25 nginx[1817]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok > May 09 10:12:21 host-172-16-36-25 nginx[1817]: 2018/05/09 10:12:21 [emerg] 1817#0: open() "/var/log/nginx/error.log" failed (13: Permission denied) > May 09 10:12:21 host-172-16-36-25 nginx[1817]: nginx: configuration file /etc/nginx/nginx.conf test failed > May 09 10:12:21 host-172-16-36-25 systemd[1]: nginx.service: Control process exited, code=exited status=1 > May 09 10:12:21 host-172-16-36-25 systemd[1]: nginx.service: Failed with result 'exit-code'. > May 09 10:12:21 host-172-16-36-25 systemd[1]: Failed to start The nginx HTTP and reverse proxy server. > > This is a problem with SELinux (dac_override). Since master process runs as root, /var/log/nginx has ownership nginx:root, > permissions 770 and NGX_FILE_DEFAULT_ACCESS is 644 for newly created logs. > > One possible solution is to set different permission mode for newly created logs (664 with nginx:root ownership) or do not set > owner of log files to nginx user (which had probably some reason in past because of extra param in ngx_reopen_files). If needed in a particular setup, log files can be pre-created with desired permissions before instructing nginx to reopen them via USR1. -- Maxim Dounin http://mdounin.ru/ From mdounin at mdounin.ru Thu May 10 12:47:08 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 10 May 2018 15:47:08 +0300 Subject: Is there a particular reason --with-compat isn't enabled by default? In-Reply-To: <20180510101741.GE40212@lo0.su> References: <128a79cb-96d2-1118-fdd3-0d3a66e2bf7a@thomas-ward.net> <20180510101741.GE40212@lo0.su> Message-ID: <20180510124708.GU32137@mdounin.ru> Hello! On Thu, May 10, 2018 at 01:17:41PM +0300, Ruslan Ermilov wrote: > On Wed, May 09, 2018 at 12:29:06PM -0400, Thomas Ward wrote: > > In regards to several off-lists inquiries downstream about people trying > > to add additional third party modules, I've gone and started seeking > > justification for enabling --with-compat. > > > > Downstream in Ubuntu, I'm getting pushback in that the question of "Why > > do we need to enable this, what does it add?".? I'm trying to find that > > justification for it, and the best I can find is Maxim's statements on a > > 2016 email/forum thread about how it actually makes dynamic module > > support truly work (in a nutshell).? [1] > > > > Further, there's pushback about "Will package security updates and > > patches change the module ABI on security fixes or bug fixes?".? I don't > > have a clear answer on this, and I had this question back when dynamic > > module support was introduced, but never got a clear answer on this > > point.? It does beg consideration with regards to dynamic module support > > whether a simple patch applied to the same exact NGINX version will > > break ABI.? The way we handle security patches and such downstream is we > > apply patches to the existing NGINX version via `quilt`, which applies > > the patch at build time.? Whether this makes an ABI change or not I > > couldn't say, so I'm hunting a response from you, the devs, to give me a > > clear answer on this. > > > > So, for those who didn't read everything there's two questions here: > > > > ?(A) Other than making dynamic module support "work better", what does > > --with-compat actually do behind the scenes (In a nutshell)? > > It enables some macros and alters some structures in a way that's > compatible with NGINX Plus, built with the same option. Practically > this means that checksums of module loadable objects will be identical > between when using F/OSS sources and when using NGINX Plus sources. > Searching for "NGX_COMPAT" throughout the F/OSS source code will > give enough details. While compatibily with nginx-plus is indeed provided by --with-compat as well, I doubt that this aspect is interesting to Thomas. More importantly, "--with-compat" provides compatibility between builds with different configure options. Without the "--with-compat" argument, one have to use exactly the same "./configure" line to build both nginx and a module. The "--with-compat" option relaxes this restriction, and it is more or less enough to build both nginx and a module with "--with-compat". This generally simplifies building dynamic modules, and also allows one to load the same module into different nginx variants built with different flags. > > ?(B) Will a simple patch that patches security issues or adds fixes to > > something later on but doesn't change the core NGINX version numbering > > change the module ABI in such a way that it'll break modules built > > against nginx without that patch (assuming that --with-compat was added, > > since it's apparently needed to make dynamic modules 'actually work') > > If a patch is simple, this is highly unlikely. For a patch to > break the ABI, at least some externally visible structures should > be changed in some backwards incompatible ways. While it is unlikely, it is possible. Care should be taken when applying patches without changing the version number. Whether "--with-compat" is specified or not is irrelevant. -- Maxim Dounin http://mdounin.ru/ From ansasaki at redhat.com Thu May 10 16:42:58 2018 From: ansasaki at redhat.com (Anderson Sasaki) Date: Thu, 10 May 2018 12:42:58 -0400 (EDT) Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <20180503143219.GF32137@mdounin.ru> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> <1524686298341.78540@cryptopro.ru> <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> <1524771096966.89645@cryptopro.ru> <20180427134017.GB32137@mdounin.ru> <1115169087.23375772.1524842877109.JavaMail.zimbra@redhat.com> <20180503143219.GF32137@mdounin.ru> Message-ID: <76712266.29100280.1525970578101.JavaMail.zimbra@redhat.com> Hello, Thanks again for the feedback. > In no particular order: > > - Should be "SSL: added ..." (no capital letter after a semicolon, > prefer past tense). > > - An empty line after the summary. > > - Please prefer double spacing. > > - "uniNItialized" The proposed changes were applied in the new patch version. > > diff -r 46c0c7ef4913 -r f5b0a7910922 src/event/ngx_event_openssl.c > > --- a/src/event/ngx_event_openssl.c Wed Apr 25 14:57:24 2018 +0300 > > +++ b/src/event/ngx_event_openssl.c Fri Apr 27 16:58:16 2018 +0200 > > @@ -527,6 +527,13 @@ > > return NGX_ERROR; > > } > > > > + if (!ENGINE_init(engine)) { > > As previously noted at [1], this may need ENGINE_finish() to avoid > leaking loaded engines. Added ENGINE_finish() calls. > > > + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > > + "ENGINE_init(engine) failed"); > > There is no reason to log static string "engine" here. Consider > using engine name here. Logging the engine name instead. The patch follows: # HG changeset patch # User Anderson Toshiyuki Sasaki # Date 1525954250 -7200 # Thu May 10 14:10:50 2018 +0200 # Node ID e7d0387ad229ca47514f346c8b692e6f388d72e1 # Parent ceab908790c4eb7cd01c40bd16581ef794222ca5 SSL: added ENGINE_init() call before loading key. It is necessary to call ENGINE_init() before using an OpenSSL engine to get the engine functional reference. Without this, when ENGINE_load_private_key() is called, the engine is still uninitialized. diff -r ceab908790c4 -r e7d0387ad229 src/event/ngx_event_openssl.c --- a/src/event/ngx_event_openssl.c Tue Apr 24 14:04:59 2018 +0300 +++ b/src/event/ngx_event_openssl.c Thu May 10 14:10:50 2018 +0200 @@ -527,6 +527,13 @@ return NGX_ERROR; } + if (!ENGINE_init(engine)) { + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, + "ENGINE_init(\"%s\") failed", p); + ENGINE_free(engine); + return NGX_ERROR; + } + *last++ = ':'; pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); @@ -534,10 +541,12 @@ if (pkey == NULL) { ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, "ENGINE_load_private_key(\"%s\") failed", last); + ENGINE_finish(engine); ENGINE_free(engine); return NGX_ERROR; } + ENGINE_finish(engine); ENGINE_free(engine); if (SSL_CTX_use_PrivateKey(ssl->ctx, pkey) == 0) { From xeioex at nginx.com Mon May 14 11:24:41 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Mon, 14 May 2018 11:24:41 +0000 Subject: [njs] Removed the surplus arguments of exception macros. Message-ID: details: http://hg.nginx.org/njs/rev/464d7e2905fc branches: changeset: 520:464d7e2905fc user: Dmitry Volyntsev date: Mon May 14 14:10:23 2018 +0300 description: Removed the surplus arguments of exception macros. diffstat: njs/njs_array.c | 10 +++++----- njs/njs_crypto.c | 38 +++++++++++++++++++------------------- njs/njs_date.c | 4 ++-- njs/njs_error.c | 2 +- njs/njs_error.h | 16 ++++++++-------- njs/njs_fs.c | 42 +++++++++++++++++++++--------------------- njs/njs_function.c | 12 ++++++------ njs/njs_generator.c | 8 ++++---- njs/njs_json.c | 18 +++++++++--------- njs/njs_module.c | 2 +- njs/njs_number.c | 2 +- njs/njs_object.c | 14 +++++++------- njs/njs_parser.c | 7 +++---- njs/njs_parser_expression.c | 10 ++++------ njs/njs_regexp.c | 10 +++++----- njs/njs_string.c | 12 ++++++------ njs/njs_time.c | 8 ++++---- njs/njs_variable.c | 2 +- njs/njs_vm.c | 9 ++++----- 19 files changed, 111 insertions(+), 115 deletions(-) diffs (960 lines): diff -r e33869a27515 -r 464d7e2905fc njs/njs_array.c --- a/njs/njs_array.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_array.c Mon May 14 14:10:23 2018 +0300 @@ -230,7 +230,7 @@ njs_array_constructor(njs_vm_t *vm, njs_ size = (uint32_t) num; if ((double) size != num) { - njs_range_error(vm, NULL, NULL); + njs_range_error(vm, NULL); return NXT_ERROR; } @@ -379,7 +379,7 @@ njs_array_prototype_length(njs_vm_t *vm, length = (uint32_t) num; if ((double) length != num) { - njs_range_error(vm, "Invalid array length", NULL); + njs_range_error(vm, "Invalid array length"); return NJS_ERROR; } @@ -1733,7 +1733,7 @@ njs_array_prototype_reduce(njs_vm_t *vm, n = njs_array_iterator_index(array, iter); if (n == NJS_ARRAY_INVALID_INDEX) { - njs_type_error(vm, "invalid index", NULL); + njs_type_error(vm, "invalid index"); return NXT_ERROR; } @@ -1794,7 +1794,7 @@ njs_array_iterator_args(njs_vm_t *vm, nj return NXT_OK; } - njs_type_error(vm, "unexpected iterator arguments", NULL); + njs_type_error(vm, "unexpected iterator arguments"); return NXT_ERROR; } @@ -1868,7 +1868,7 @@ njs_array_prototype_reduce_right(njs_vm_ n = njs_array_reduce_right_index(array, iter); if (n == NJS_ARRAY_INVALID_INDEX) { - njs_type_error(vm, "invalid index", NULL); + njs_type_error(vm, "invalid index"); return NXT_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_crypto.c --- a/njs/njs_crypto.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_crypto.c Mon May 14 14:10:23 2018 +0300 @@ -158,7 +158,7 @@ njs_crypto_create_hash(njs_vm_t *vm, njs njs_object_value_t *hash; if (nxt_slow_path(nargs < 2 || !njs_is_string(&args[1]))) { - njs_type_error(vm, "algorithm must be a string", NULL); + njs_type_error(vm, "algorithm must be a string"); return NJS_ERROR; } @@ -208,17 +208,17 @@ njs_hash_prototype_update(njs_vm_t *vm, njs_object_value_t *hash; if (nxt_slow_path(nargs < 2 || !njs_is_string(&args[1]))) { - njs_type_error(vm, "data must be a string", NULL); + njs_type_error(vm, "data must be a string"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_object_value(&args[0]))) { - njs_type_error(vm, "'this' is not an object_value", NULL); + njs_type_error(vm, "'this' is not an object_value"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_data(&args[0].data.u.object_value->value))) { - njs_type_error(vm, "value of 'this' is not a data type", NULL); + njs_type_error(vm, "value of 'this' is not a data type"); return NJS_ERROR; } @@ -229,7 +229,7 @@ njs_hash_prototype_update(njs_vm_t *vm, dgst = njs_value_data(&hash->value); if (nxt_slow_path(dgst->alg == NULL)) { - njs_error(vm, "Digest already called", NULL); + njs_error(vm, "Digest already called"); return NJS_ERROR; } @@ -254,17 +254,17 @@ njs_hash_prototype_digest(njs_vm_t *vm, njs_object_value_t *hash; if (nxt_slow_path(nargs > 1 && !njs_is_string(&args[1]))) { - njs_type_error(vm, "encoding must be a string", NULL); + njs_type_error(vm, "encoding must be a string"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_object_value(&args[0]))) { - njs_type_error(vm, "'this' is not an object_value", NULL); + njs_type_error(vm, "'this' is not an object_value"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_data(&args[0].data.u.object_value->value))) { - njs_type_error(vm, "value of 'this' is not a data type", NULL); + njs_type_error(vm, "value of 'this' is not a data type"); return NJS_ERROR; } @@ -284,7 +284,7 @@ njs_hash_prototype_digest(njs_vm_t *vm, dgst = njs_value_data(&hash->value); if (nxt_slow_path(dgst->alg == NULL)) { - njs_error(vm, "Digest already called", NULL); + njs_error(vm, "Digest already called"); return NJS_ERROR; } @@ -392,12 +392,12 @@ njs_crypto_create_hmac(njs_vm_t *vm, njs njs_object_value_t *hmac; if (nxt_slow_path(nargs < 2 || !njs_is_string(&args[1]))) { - njs_type_error(vm, "algorithm must be a string", NULL); + njs_type_error(vm, "algorithm must be a string"); return NJS_ERROR; } if (nxt_slow_path(nargs < 3 || !njs_is_string(&args[2]))) { - njs_type_error(vm, "key must be a string", NULL); + njs_type_error(vm, "key must be a string"); return NJS_ERROR; } @@ -471,17 +471,17 @@ njs_hmac_prototype_update(njs_vm_t *vm, njs_object_value_t *hmac; if (nxt_slow_path(nargs < 2 || !njs_is_string(&args[1]))) { - njs_type_error(vm, "data must be a string", NULL); + njs_type_error(vm, "data must be a string"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_object_value(&args[0]))) { - njs_type_error(vm, "'this' is not an object_value", NULL); + njs_type_error(vm, "'this' is not an object_value"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_data(&args[0].data.u.object_value->value))) { - njs_type_error(vm, "value of 'this' is not a data type", NULL); + njs_type_error(vm, "value of 'this' is not a data type"); return NJS_ERROR; } @@ -492,7 +492,7 @@ njs_hmac_prototype_update(njs_vm_t *vm, ctx = njs_value_data(&hmac->value); if (nxt_slow_path(ctx->alg == NULL)) { - njs_error(vm, "Digest already called", NULL); + njs_error(vm, "Digest already called"); return NJS_ERROR; } @@ -517,17 +517,17 @@ njs_hmac_prototype_digest(njs_vm_t *vm, njs_object_value_t *hmac; if (nxt_slow_path(nargs > 1 && !njs_is_string(&args[1]))) { - njs_type_error(vm, "encoding must be a string", NULL); + njs_type_error(vm, "encoding must be a string"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_object_value(&args[0]))) { - njs_type_error(vm, "'this' is not an object_value", NULL); + njs_type_error(vm, "'this' is not an object_value"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_data(&args[0].data.u.object_value->value))) { - njs_type_error(vm, "value of 'this' is not a data type", NULL); + njs_type_error(vm, "value of 'this' is not a data type"); return NJS_ERROR; } @@ -547,7 +547,7 @@ njs_hmac_prototype_digest(njs_vm_t *vm, ctx = njs_value_data(&hmac->value); if (nxt_slow_path(ctx->alg == NULL)) { - njs_error(vm, "Digest already called", NULL); + njs_error(vm, "Digest already called"); return NJS_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_date.c --- a/njs/njs_date.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_date.c Mon May 14 14:10:23 2018 +0300 @@ -1043,7 +1043,7 @@ njs_date_prototype_to_iso_string(njs_vm_ return njs_string_new(vm, &vm->retval, buf, size, size); } - njs_range_error(vm, NULL, NULL); + njs_range_error(vm, NULL); return NXT_ERROR; } @@ -1891,7 +1891,7 @@ njs_date_prototype_to_json(njs_vm_t *vm, } } - njs_type_error(vm, "'this' argument is not an object", NULL); + njs_type_error(vm, "'this' argument is not an object"); return NXT_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_error.c --- a/njs/njs_error.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_error.c Mon May 14 14:10:23 2018 +0300 @@ -596,7 +596,7 @@ njs_error_prototype_to_string(njs_vm_t * static const njs_value_t default_name = njs_string("Error"); if (nargs < 1 || !njs_is_object(&args[0])) { - njs_type_error(vm, "'this' argument is not an object", NULL); + njs_type_error(vm, "'this' argument is not an object"); return NXT_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_error.h --- a/njs/njs_error.h Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_error.h Mon May 14 14:10:23 2018 +0300 @@ -9,21 +9,21 @@ #define njs_error(vm, fmt, ...) \ - njs_exception_error_create(vm, NJS_OBJECT_ERROR, fmt, __VA_ARGS__) + njs_exception_error_create(vm, NJS_OBJECT_ERROR, fmt, ##__VA_ARGS__) #define njs_eval_error(vm, fmt, ...) \ - njs_exception_error_create(vm, NJS_OBJECT_EVAL_ERROR, fmt, __VA_ARGS__) + njs_exception_error_create(vm, NJS_OBJECT_EVAL_ERROR, fmt, ##__VA_ARGS__) #define njs_internal_error(vm, fmt, ...) \ - njs_exception_error_create(vm, NJS_OBJECT_INTERNAL_ERROR, fmt, __VA_ARGS__) + njs_exception_error_create(vm, NJS_OBJECT_INTERNAL_ERROR, fmt, ##__VA_ARGS__) #define njs_range_error(vm, fmt, ...) \ - njs_exception_error_create(vm, NJS_OBJECT_RANGE_ERROR, fmt, __VA_ARGS__) + njs_exception_error_create(vm, NJS_OBJECT_RANGE_ERROR, fmt, ##__VA_ARGS__) #define njs_reference_error(vm, fmt, ...) \ - njs_exception_error_create(vm, NJS_OBJECT_REF_ERROR, fmt, __VA_ARGS__) + njs_exception_error_create(vm, NJS_OBJECT_REF_ERROR, fmt, ##__VA_ARGS__) #define njs_syntax_error(vm, fmt, ...) \ - njs_exception_error_create(vm, NJS_OBJECT_SYNTAX_ERROR, fmt, __VA_ARGS__) + njs_exception_error_create(vm, NJS_OBJECT_SYNTAX_ERROR, fmt, ##__VA_ARGS__) #define njs_type_error(vm, fmt, ...) \ - njs_exception_error_create(vm, NJS_OBJECT_TYPE_ERROR, fmt, __VA_ARGS__) + njs_exception_error_create(vm, NJS_OBJECT_TYPE_ERROR, fmt, ##__VA_ARGS__) #define njs_uri_error(vm, fmt, ...) \ - njs_exception_error_create(vm, NJS_OBJECT_URI_ERROR, fmt, __VA_ARGS__) + njs_exception_error_create(vm, NJS_OBJECT_URI_ERROR, fmt, ##__VA_ARGS__) void njs_exception_error_create(njs_vm_t *vm, njs_value_type_t type, const char* fmt, ...); diff -r e33869a27515 -r 464d7e2905fc njs/njs_fs.c --- a/njs/njs_fs.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_fs.c Mon May 14 14:10:23 2018 +0300 @@ -99,12 +99,12 @@ njs_fs_read_file(njs_vm_t *vm, njs_value nxt_lvlhsh_query_t lhq; if (nxt_slow_path(nargs < 3)) { - njs_type_error(vm, "too few arguments", NULL); + njs_type_error(vm, "too few arguments"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_string(&args[1]))) { - njs_type_error(vm, "path must be a string", NULL); + njs_type_error(vm, "path must be a string"); return NJS_ERROR; } @@ -139,12 +139,12 @@ njs_fs_read_file(njs_vm_t *vm, njs_value } else { njs_type_error(vm, "Unknown options type " - "(a string or object required)", NULL); + "(a string or object required)"); return NJS_ERROR; } if (nxt_slow_path(nargs < 4 || !njs_is_function(&args[3]))) { - njs_type_error(vm, "callback must be a function", NULL); + njs_type_error(vm, "callback must be a function"); return NJS_ERROR; } @@ -152,7 +152,7 @@ njs_fs_read_file(njs_vm_t *vm, njs_value } else { if (nxt_slow_path(!njs_is_function(&args[2]))) { - njs_type_error(vm, "callback must be a function", NULL); + njs_type_error(vm, "callback must be a function"); return NJS_ERROR; } @@ -313,12 +313,12 @@ njs_fs_read_file_sync(njs_vm_t *vm, njs_ nxt_lvlhsh_query_t lhq; if (nxt_slow_path(nargs < 2)) { - njs_type_error(vm, "too few arguments", NULL); + njs_type_error(vm, "too few arguments"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_string(&args[1]))) { - njs_type_error(vm, "path must be a string", NULL); + njs_type_error(vm, "path must be a string"); return NJS_ERROR; } @@ -353,7 +353,7 @@ njs_fs_read_file_sync(njs_vm_t *vm, njs_ } else { njs_type_error(vm, "Unknown options type " - "(a string or object required)", NULL); + "(a string or object required)"); return NJS_ERROR; } } @@ -534,17 +534,17 @@ static njs_ret_t njs_fs_write_file_inter nxt_lvlhsh_query_t lhq; if (nxt_slow_path(nargs < 4)) { - njs_type_error(vm, "too few arguments", NULL); + njs_type_error(vm, "too few arguments"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_string(&args[1]))) { - njs_type_error(vm, "path must be a string", NULL); + njs_type_error(vm, "path must be a string"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_string(&args[2]))) { - njs_type_error(vm, "data must be a string", NULL); + njs_type_error(vm, "data must be a string"); return NJS_ERROR; } @@ -592,12 +592,12 @@ static njs_ret_t njs_fs_write_file_inter } else { njs_type_error(vm, "Unknown options type " - "(a string or object required)", NULL); + "(a string or object required)"); return NJS_ERROR; } if (nxt_slow_path(nargs < 5 || !njs_is_function(&args[4]))) { - njs_type_error(vm, "callback must be a function", NULL); + njs_type_error(vm, "callback must be a function"); return NJS_ERROR; } @@ -605,7 +605,7 @@ static njs_ret_t njs_fs_write_file_inter } else { if (nxt_slow_path(!njs_is_function(&args[3]))) { - njs_type_error(vm, "callback must be a function", NULL); + njs_type_error(vm, "callback must be a function"); return NJS_ERROR; } @@ -723,17 +723,17 @@ njs_fs_write_file_sync_internal(njs_vm_t nxt_lvlhsh_query_t lhq; if (nxt_slow_path(nargs < 3)) { - njs_type_error(vm, "too few arguments", NULL); + njs_type_error(vm, "too few arguments"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_string(&args[1]))) { - njs_type_error(vm, "path must be a string", NULL); + njs_type_error(vm, "path must be a string"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_string(&args[2]))) { - njs_type_error(vm, "data must be a string", NULL); + njs_type_error(vm, "data must be a string"); return NJS_ERROR; } @@ -781,7 +781,7 @@ njs_fs_write_file_sync_internal(njs_vm_t } else { njs_type_error(vm, "Unknown options type " - "(a string or object required)", NULL); + "(a string or object required)"); return NJS_ERROR; } } @@ -927,7 +927,7 @@ static njs_ret_t njs_fs_error(njs_vm_t * ret = nxt_lvlhsh_insert(&error->hash, &lhq); if (nxt_slow_path(ret != NXT_OK)) { - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NJS_ERROR; } } @@ -946,7 +946,7 @@ static njs_ret_t njs_fs_error(njs_vm_t * ret = nxt_lvlhsh_insert(&error->hash, &lhq); if (nxt_slow_path(ret != NXT_OK)) { - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NJS_ERROR; } } @@ -971,7 +971,7 @@ static njs_ret_t njs_fs_error(njs_vm_t * ret = nxt_lvlhsh_insert(&error->hash, &lhq); if (nxt_slow_path(ret != NXT_OK)) { - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NJS_ERROR; } } diff -r e33869a27515 -r 464d7e2905fc njs/njs_function.c --- a/njs/njs_function.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_function.c Mon May 14 14:10:23 2018 +0300 @@ -240,7 +240,7 @@ njs_function_frame_alloc(njs_vm_t *vm, s spare_size = nxt_align_size(spare_size, NJS_FRAME_SPARE_SIZE); if (vm->stack_size + spare_size > NJS_MAX_STACK_SIZE) { - njs_range_error(vm, "Maximum call stack size exceeded", NULL); + njs_range_error(vm, "Maximum call stack size exceeded"); return NULL; } @@ -501,7 +501,7 @@ njs_function_prototype_call(njs_vm_t *vm njs_function_t *function; if (!njs_is_function(&args[0])) { - njs_type_error(vm, "'this' argument is not a function", NULL); + njs_type_error(vm, "'this' argument is not a function"); return NXT_ERROR; } @@ -529,7 +529,7 @@ njs_function_prototype_apply(njs_vm_t *v njs_function_t *function; if (!njs_is_function(&args[0])) { - njs_type_error(vm, "'this' argument is not a function", NULL); + njs_type_error(vm, "'this' argument is not a function"); return NXT_ERROR; } @@ -538,7 +538,7 @@ njs_function_prototype_apply(njs_vm_t *v if (nargs > 2) { if (!njs_is_array(&args[2])) { - njs_type_error(vm, "second argument is not an array", NULL); + njs_type_error(vm, "second argument is not an array"); return NXT_ERROR; } @@ -610,7 +610,7 @@ njs_function_prototype_bind(njs_vm_t *vm njs_function_t *function; if (!njs_is_function(&args[0])) { - njs_type_error(vm, "'this' argument is not a function", NULL); + njs_type_error(vm, "'this' argument is not a function"); return NXT_ERROR; } @@ -689,7 +689,7 @@ njs_ret_t njs_eval_function(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - njs_internal_error(vm, "Not implemented", NULL); + njs_internal_error(vm, "Not implemented"); return NXT_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_generator.c --- a/njs/njs_generator.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_generator.c Mon May 14 14:10:23 2018 +0300 @@ -328,7 +328,7 @@ njs_generator(njs_vm_t *vm, njs_parser_t default: nxt_thread_log_debug("unknown token: %d", node->token); - njs_syntax_error(vm, "unknown token", NULL); + njs_syntax_error(vm, "unknown token"); return NXT_ERROR; } @@ -1137,7 +1137,7 @@ njs_generate_continue_statement(njs_vm_t } } - njs_parser_syntax_error(vm, parser, "Illegal continue statement", NULL); + njs_parser_syntax_error(vm, parser, "Illegal continue statement"); return NXT_ERROR; @@ -1180,7 +1180,7 @@ njs_generate_break_statement(njs_vm_t *v } } - njs_parser_syntax_error(vm, parser, "Illegal break statement", NULL); + njs_parser_syntax_error(vm, parser, "Illegal break statement"); return NXT_ERROR; @@ -2066,7 +2066,7 @@ njs_generate_scope(njs_vm_t *vm, njs_par parser->code_size, code_size); if (nxt_slow_path(parser->code_size < code_size)) { - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NXT_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_json.c --- a/njs/njs_json.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_json.c Mon May 14 14:10:23 2018 +0300 @@ -471,7 +471,7 @@ njs_json_parse_object(njs_json_parse_ctx ret = nxt_lvlhsh_insert(&object->hash, &lhq); if (nxt_slow_path(ret != NXT_OK)) { - njs_internal_error(ctx->vm, NULL, NULL); + njs_internal_error(ctx->vm, NULL); return NULL; } @@ -566,7 +566,7 @@ njs_json_parse_array(njs_json_parse_ctx_ ret = njs_array_add(ctx->vm, array, element); if (nxt_slow_path(ret != NXT_OK)) { - njs_internal_error(ctx->vm, NULL, NULL); + njs_internal_error(ctx->vm, NULL); return NULL; } @@ -981,7 +981,7 @@ njs_json_parse_continuation(njs_vm_t *vm } if (nxt_slow_path(ret != NXT_OK)) { - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NXT_ERROR; } @@ -1019,7 +1019,7 @@ njs_json_parse_continuation(njs_vm_t *vm break; default: - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NXT_ERROR; } } @@ -1061,7 +1061,7 @@ njs_json_parse_continuation_apply(njs_vm break; default: - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NXT_ERROR; } @@ -1488,7 +1488,7 @@ njs_json_stringify_to_json(njs_vm_t *vm, break; default: - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NXT_ERROR; } @@ -1532,7 +1532,7 @@ njs_json_stringify_replacer(njs_vm_t *vm break; default: - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NXT_ERROR; } @@ -1627,7 +1627,7 @@ njs_json_push_stringify_state(njs_vm_t * if (stringify->stack.items >= 32) { njs_type_error(stringify->vm, - "Nested too deep or a cyclic structure", NULL); + "Nested too deep or a cyclic structure"); return NULL; } @@ -1717,7 +1717,7 @@ njs_json_append_value(njs_json_stringify return njs_json_buf_append(stringify, "null", 4); default: - njs_type_error(stringify->vm, "Non-serializable object", NULL); + njs_type_error(stringify->vm, "Non-serializable object"); return NXT_DECLINED; } } diff -r e33869a27515 -r 464d7e2905fc njs/njs_module.c --- a/njs/njs_module.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_module.c Mon May 14 14:10:23 2018 +0300 @@ -43,7 +43,7 @@ njs_ret_t njs_module_require(njs_vm_t *v nxt_lvlhsh_query_t lhq; if (nargs < 2) { - njs_type_error(vm, "missing path", NULL); + njs_type_error(vm, "missing path"); return NJS_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_number.c --- a/njs/njs_number.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_number.c Mon May 14 14:10:23 2018 +0300 @@ -611,7 +611,7 @@ njs_number_prototype_to_string(njs_vm_t radix = args[1].data.u.number; if (radix < 2 || radix > 36 || radix != (int) radix) { - njs_range_error(vm, NULL, NULL); + njs_range_error(vm, NULL); return NXT_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_object.c --- a/njs/njs_object.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_object.c Mon May 14 14:10:23 2018 +0300 @@ -333,7 +333,7 @@ njs_property_query(njs_vm_t *vm, njs_pro } } - njs_type_error(vm, "cannot get property 'unknown' of undefined", NULL); + njs_type_error(vm, "cannot get property 'unknown' of undefined"); return NXT_ERROR; } @@ -727,14 +727,14 @@ njs_object_define_property(njs_vm_t *vm, } if (!value->data.u.object->extensible) { - njs_type_error(vm, "object is not extensible", NULL); + njs_type_error(vm, "object is not extensible"); return NXT_ERROR; } descriptor = njs_arg(args, nargs, 3); if (!njs_is_object(descriptor)){ - njs_type_error(vm, "descriptor is not an object", NULL); + njs_type_error(vm, "descriptor is not an object"); return NXT_ERROR; } @@ -774,14 +774,14 @@ njs_object_define_properties(njs_vm_t *v } if (!value->data.u.object->extensible) { - njs_type_error(vm, "object is not extensible", NULL); + njs_type_error(vm, "object is not extensible"); return NXT_ERROR; } descriptor = njs_arg(args, nargs, 2); if (!njs_is_object(descriptor)) { - njs_type_error(vm, "descriptor is not an object", NULL); + njs_type_error(vm, "descriptor is not an object"); return NXT_ERROR; } @@ -1395,7 +1395,7 @@ njs_property_prototype_create(njs_vm_t * } /* Memory allocation or NXT_DECLINED error. */ - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NULL; } @@ -1638,7 +1638,7 @@ njs_property_constructor_create(njs_vm_t } /* Memory allocation or NXT_DECLINED error. */ - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); return NULL; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_parser.c --- a/njs/njs_parser.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_parser.c Mon May 14 14:10:23 2018 +0300 @@ -752,8 +752,7 @@ njs_parser_return_statement(njs_vm_t *vm scope = scope->parent) { if (scope->type == NJS_SCOPE_GLOBAL) { - njs_parser_syntax_error(vm, parser, "Illegal return statement", - NULL); + njs_parser_syntax_error(vm, parser, "Illegal return statement"); return NXT_ERROR; } @@ -1037,7 +1036,7 @@ njs_parser_switch_statement(njs_vm_t *vm if (dflt != NULL) { njs_parser_syntax_error(vm, parser, "More than one default clause " - "in switch statement", NULL); + "in switch statement"); return NJS_TOKEN_ILLEGAL; } @@ -2575,7 +2574,7 @@ njs_parser_unexpected_token(njs_vm_t *vm parser->lexer->text.start); } else { - njs_parser_syntax_error(vm, parser, "Unexpected end of input", NULL); + njs_parser_syntax_error(vm, parser, "Unexpected end of input"); } return NJS_TOKEN_ILLEGAL; diff -r e33869a27515 -r 464d7e2905fc njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_parser_expression.c Mon May 14 14:10:23 2018 +0300 @@ -277,7 +277,7 @@ njs_parser_var_expression(njs_vm_t *vm, if (!njs_parser_is_lvalue(parser->node)) { njs_parser_ref_error(vm, parser, - "Invalid left-hand side in assignment", NULL); + "Invalid left-hand side in assignment"); return NJS_TOKEN_ILLEGAL; } @@ -415,7 +415,7 @@ njs_parser_assignment_expression(njs_vm_ if (!njs_parser_is_lvalue(parser->node)) { njs_parser_ref_error(vm, parser, - "Invalid left-hand side in assignment", NULL); + "Invalid left-hand side in assignment"); return NJS_TOKEN_ILLEGAL; } @@ -839,8 +839,7 @@ njs_parser_inc_dec_expression(njs_vm_t * if (!njs_parser_is_lvalue(parser->node)) { njs_parser_ref_error(vm, parser, - "Invalid left-hand side in prefix operation", - NULL); + "Invalid left-hand side in prefix operation"); return NJS_TOKEN_ILLEGAL; } @@ -894,8 +893,7 @@ njs_parser_post_inc_dec_expression(njs_v if (!njs_parser_is_lvalue(parser->node)) { njs_parser_ref_error(vm, parser, - "Invalid left-hand side in postfix operation", - NULL); + "Invalid left-hand side in postfix operation"); return NJS_TOKEN_ILLEGAL; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_regexp.c --- a/njs/njs_regexp.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_regexp.c Mon May 14 14:10:23 2018 +0300 @@ -320,7 +320,7 @@ njs_regexp_pattern_create(njs_vm_t *vm, if (nxt_fast_path(ret >= 0)) { if (nxt_slow_path((u_int) ret != pattern->ncaptures)) { - njs_internal_error(vm, NULL, NULL); + njs_internal_error(vm, NULL); nxt_mem_cache_free(vm->mem_cache_pool, pattern); return NULL; } @@ -412,7 +412,7 @@ njs_regexp_match_trace_handler(nxt_trace trace = trace->next; p = trace->handler(trace, td, start); - njs_internal_error(vm, (const char *) start, NULL); + njs_internal_error(vm, (const char *) start); return p; } @@ -545,7 +545,7 @@ njs_regexp_prototype_to_string(njs_vm_t return njs_regexp_string_create(vm, &vm->retval, source, size, length); } - njs_type_error(vm, "'this' argument is not a regexp", NULL); + njs_type_error(vm, "'this' argument is not a regexp"); return NXT_ERROR; } @@ -563,7 +563,7 @@ njs_regexp_prototype_test(njs_vm_t *vm, njs_regexp_pattern_t *pattern; if (!njs_is_regexp(&args[0])) { - njs_type_error(vm, "'this' argument is not a regexp", NULL); + njs_type_error(vm, "'this' argument is not a regexp"); return NXT_ERROR; } @@ -613,7 +613,7 @@ njs_regexp_prototype_exec(njs_vm_t *vm, nxt_regex_match_data_t *match_data; if (!njs_is_regexp(&args[0])) { - njs_type_error(vm, "'this' argument is not a regexp", NULL); + njs_type_error(vm, "'this' argument is not a regexp"); return NXT_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_string.c --- a/njs/njs_string.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_string.c Mon May 14 14:10:23 2018 +0300 @@ -732,7 +732,7 @@ njs_string_prototype_to_string(njs_vm_t } if (nxt_slow_path(!njs_is_string(&args[1]))) { - njs_type_error(vm, "encoding must be a string", NULL); + njs_type_error(vm, "encoding must be a string"); return NJS_ERROR; } @@ -741,7 +741,7 @@ njs_string_prototype_to_string(njs_vm_t (void) njs_string_prop(&string, &value); if (nxt_slow_path(string.length != 0)) { - njs_type_error(vm, "argument must be a byte string", NULL); + njs_type_error(vm, "argument must be a byte string"); return NJS_ERROR; } @@ -781,7 +781,7 @@ njs_string_prototype_concat(njs_vm_t *vm njs_string_prop_t string; if (njs_is_null_or_void(&args[0])) { - njs_type_error(vm, "'this' argument is null or undefined", NULL); + njs_type_error(vm, "'this' argument is null or undefined"); return NXT_ERROR; } @@ -1376,7 +1376,7 @@ njs_string_from_char_code(njs_vm_t *vm, range_error: - njs_range_error(vm, NULL, NULL); + njs_range_error(vm, NULL); return NXT_ERROR; } @@ -2043,7 +2043,7 @@ njs_string_prototype_repeat(njs_vm_t *vm n = args[1].data.u.number; if (nxt_slow_path(n < 0 || n >= max)) { - njs_range_error(vm, NULL, NULL); + njs_range_error(vm, NULL); return NXT_ERROR; } } @@ -3859,7 +3859,7 @@ njs_string_decode(njs_vm_t *vm, njs_valu uri_error: - njs_uri_error(vm, NULL, NULL); + njs_uri_error(vm, NULL); return NXT_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_time.c --- a/njs/njs_time.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_time.c Mon May 14 14:10:23 2018 +0300 @@ -19,18 +19,18 @@ njs_set_timeout(njs_vm_t *vm, njs_value_ njs_vm_ops_t *ops; if (nxt_slow_path(nargs < 2)) { - njs_type_error(vm, "too few arguments", NULL); + njs_type_error(vm, "too few arguments"); return NJS_ERROR; } if (nxt_slow_path(!njs_is_function(&args[1]))) { - njs_type_error(vm, "first arg must be a function", NULL); + njs_type_error(vm, "first arg must be a function"); return NJS_ERROR; } ops = vm->ops; if (nxt_slow_path(ops == NULL)) { - njs_internal_error(vm, "not supported by host environment", NULL); + njs_internal_error(vm, "not supported by host environment"); return NJS_ERROR; } @@ -62,7 +62,7 @@ njs_set_timeout(njs_vm_t *vm, njs_value_ event->host_event = ops->set_timer(vm->external, delay, event); if (event->host_event == NULL) { - njs_internal_error(vm, "set_timer() failed", NULL); + njs_internal_error(vm, "set_timer() failed"); return NJS_ERROR; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_variable.c --- a/njs/njs_variable.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_variable.c Mon May 14 14:10:23 2018 +0300 @@ -376,7 +376,7 @@ njs_variable_get(njs_vm_t *vm, njs_parse index = (index >> NJS_SCOPE_SHIFT) + 1; if (index > 255 || vs.scope->argument_closures == 0) { - njs_internal_error(vm, "too many argument closures", NULL); + njs_internal_error(vm, "too many argument closures"); return NULL; } diff -r e33869a27515 -r 464d7e2905fc njs/njs_vm.c --- a/njs/njs_vm.c Mon May 07 15:49:02 2018 +0300 +++ b/njs/njs_vm.c Mon May 14 14:10:23 2018 +0300 @@ -755,7 +755,7 @@ njs_vmcode_property_in(njs_vm_t *vm, njs case NJS_PRIMITIVE_VALUE: case NJS_STRING_VALUE: - njs_type_error(vm, "property in on a primitive value", NULL); + njs_type_error(vm, "property in on a primitive value"); return NXT_ERROR; @@ -1066,7 +1066,7 @@ njs_vmcode_instance_of(njs_vm_t *vm, njs static njs_value_t prototype_string = njs_string("prototype"); if (!njs_is_function(constructor)) { - njs_type_error(vm, "right argument is not a function", NULL); + njs_type_error(vm, "right argument is not a function"); return NXT_ERROR; } @@ -1977,7 +1977,7 @@ njs_function_frame_create(njs_vm_t *vm, } } - njs_type_error(vm, "object is not callable", NULL); + njs_type_error(vm, "object is not callable"); return NXT_ERROR; } @@ -3084,8 +3084,7 @@ njs_primitive_value(njs_vm_t *vm, njs_va } if (ret == NXT_ERROR) { - njs_type_error(vm, "cannot evaluate an object's value", - NULL); + njs_type_error(vm, "cannot evaluate an object's value"); } return ret; From arut at nginx.com Mon May 14 12:17:45 2018 From: arut at nginx.com (Roman Arutyunyan) Date: Mon, 14 May 2018 12:17:45 +0000 Subject: [njs] Style. Message-ID: details: http://hg.nginx.org/njs/rev/a994ab62d351 branches: changeset: 522:a994ab62d351 user: Roman Arutyunyan date: Mon May 14 15:03:29 2018 +0300 description: Style. diffstat: nginx/ngx_http_js_module.c | 2 +- nginx/ngx_stream_js_module.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diffs (24 lines): diff -r 5abcdd645d57 -r a994ab62d351 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Tue Apr 17 17:15:27 2018 +0300 +++ b/nginx/ngx_http_js_module.c Mon May 14 15:03:29 2018 +0300 @@ -174,7 +174,7 @@ static ngx_command_t ngx_http_js_comman 0, NULL }, - ngx_null_command + ngx_null_command }; diff -r 5abcdd645d57 -r a994ab62d351 nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Tue Apr 17 17:15:27 2018 +0300 +++ b/nginx/ngx_stream_js_module.c Mon May 14 15:03:29 2018 +0300 @@ -123,7 +123,7 @@ static ngx_command_t ngx_stream_js_comm offsetof(ngx_stream_js_srv_conf_t, filter), NULL }, - ngx_null_command + ngx_null_command }; From arut at nginx.com Mon May 14 12:17:45 2018 From: arut at nginx.com (Roman Arutyunyan) Date: Mon, 14 May 2018 12:17:45 +0000 Subject: [njs] Moved njs vm to the main configuration. Message-ID: details: http://hg.nginx.org/njs/rev/5abcdd645d57 branches: changeset: 521:5abcdd645d57 user: Roman Arutyunyan date: Tue Apr 17 17:15:27 2018 +0300 description: Moved njs vm to the main configuration. Previously, vm and proto objects were located in the location (server for stream) configuration. Since there's only one instance of these objects, they are moved to the main configuration. diffstat: nginx/ngx_http_js_module.c | 111 ++++++++++++++++++++++++------------------ nginx/ngx_stream_js_module.c | 107 ++++++++++++++++++++++++----------------- 2 files changed, 126 insertions(+), 92 deletions(-) diffs (489 lines): diff -r 464d7e2905fc -r 5abcdd645d57 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Mon May 14 14:10:23 2018 +0300 +++ b/nginx/ngx_http_js_module.c Tue Apr 17 17:15:27 2018 +0300 @@ -14,10 +14,14 @@ typedef struct { njs_vm_t *vm; - ngx_str_t content; const njs_extern_t *req_proto; const njs_extern_t *res_proto; const njs_extern_t *rep_proto; +} ngx_http_js_main_conf_t; + + +typedef struct { + ngx_str_t content; } ngx_http_js_loc_conf_t; @@ -141,6 +145,7 @@ static char *ngx_http_js_include(ngx_con static char *ngx_http_js_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_http_js_content(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static void *ngx_http_js_create_main_conf(ngx_conf_t *cf); static void *ngx_http_js_create_loc_conf(ngx_conf_t *cf); static char *ngx_http_js_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); @@ -151,7 +156,7 @@ static ngx_command_t ngx_http_js_comman { ngx_string("js_include"), NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, ngx_http_js_include, - NGX_HTTP_LOC_CONF_OFFSET, + NGX_HTTP_MAIN_CONF_OFFSET, 0, NULL }, @@ -177,7 +182,7 @@ static ngx_http_module_t ngx_http_js_mo NULL, /* preconfiguration */ NULL, /* postconfiguration */ - NULL, /* create main configuration */ + ngx_http_js_create_main_conf, /* create main configuration */ NULL, /* init main configuration */ NULL, /* create server configuration */ @@ -809,14 +814,14 @@ ngx_http_js_variable(ngx_http_request_t static ngx_int_t ngx_http_js_init_vm(ngx_http_request_t *r) { - nxt_int_t rc; - nxt_str_t exception; - ngx_http_js_ctx_t *ctx; - ngx_pool_cleanup_t *cln; - ngx_http_js_loc_conf_t *jlcf; - - jlcf = ngx_http_get_module_loc_conf(r, ngx_http_js_module); - if (jlcf->vm == NULL) { + nxt_int_t rc; + nxt_str_t exception; + ngx_http_js_ctx_t *ctx; + ngx_pool_cleanup_t *cln; + ngx_http_js_main_conf_t *jmcf; + + jmcf = ngx_http_get_module_main_conf(r, ngx_http_js_module); + if (jmcf->vm == NULL) { return NGX_DECLINED; } @@ -835,7 +840,7 @@ ngx_http_js_init_vm(ngx_http_request_t * return NGX_OK; } - ctx->vm = njs_vm_clone(jlcf->vm, r); + ctx->vm = njs_vm_clone(jmcf->vm, r); if (ctx->vm == NULL) { return NGX_ERROR; } @@ -860,13 +865,13 @@ ngx_http_js_init_vm(ngx_http_request_t * } rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->args[0]), - jlcf->req_proto, r); + jmcf->req_proto, r); if (rc != NXT_OK) { return NGX_ERROR; } rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->args[1]), - jlcf->res_proto, r); + jmcf->res_proto, r); if (rc != NXT_OK) { return NGX_ERROR; } @@ -1949,10 +1954,10 @@ ngx_http_js_subrequest_done(ngx_http_req { njs_vm_event_t vm_event = data; - nxt_int_t ret; - ngx_http_js_ctx_t *ctx; - njs_opaque_value_t reply; - ngx_http_js_loc_conf_t *jlcf; + nxt_int_t ret; + ngx_http_js_ctx_t *ctx; + njs_opaque_value_t reply; + ngx_http_js_main_conf_t *jmcf; if (rc != NGX_OK || r->connection->error || r->buffered) { return rc; @@ -1975,7 +1980,7 @@ ngx_http_js_subrequest_done(ngx_http_req ctx->done = 1; - jlcf = ngx_http_get_module_loc_conf(r->parent, ngx_http_js_module); + jmcf = ngx_http_get_module_main_conf(r, ngx_http_js_module); ctx = ngx_http_get_module_ctx(r->parent, ngx_http_js_module); @@ -1991,7 +1996,7 @@ ngx_http_js_subrequest_done(ngx_http_req } ret = njs_vm_external_create(ctx->vm, njs_value_arg(&reply), - jlcf->rep_proto, r); + jmcf->rep_proto, r); if (ret != NXT_OK) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "js subrequest reply creation failed"); @@ -2152,7 +2157,7 @@ ngx_http_js_handle_event(ngx_http_reques static char * ngx_http_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_http_js_loc_conf_t *jlcf = conf; + ngx_http_js_main_conf_t *jmcf = conf; size_t size; u_char *start, *end; @@ -2165,7 +2170,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ ngx_file_info_t fi; ngx_pool_cleanup_t *cln; - if (jlcf->vm) { + if (jmcf->vm) { return "is duplicate"; } @@ -2229,8 +2234,8 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ options.backtrace = 1; options.ops = &ngx_http_js_ops; - jlcf->vm = njs_vm_create(&options); - if (jlcf->vm == NULL) { + jmcf->vm = njs_vm_create(&options); + if (jmcf->vm == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to create JS VM"); return NGX_CONF_ERROR; } @@ -2241,34 +2246,34 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ } cln->handler = ngx_http_js_cleanup_vm; - cln->data = jlcf->vm; - - jlcf->req_proto = njs_vm_external_prototype(jlcf->vm, + cln->data = jmcf->vm; + + jmcf->req_proto = njs_vm_external_prototype(jmcf->vm, &ngx_http_js_externals[0]); - if (jlcf->req_proto == NULL) { + if (jmcf->req_proto == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to add request proto"); return NGX_CONF_ERROR; } - jlcf->res_proto = njs_vm_external_prototype(jlcf->vm, + jmcf->res_proto = njs_vm_external_prototype(jmcf->vm, &ngx_http_js_externals[1]); - if (jlcf->res_proto == NULL) { + if (jmcf->res_proto == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to add response proto"); return NGX_CONF_ERROR; } - jlcf->rep_proto = njs_vm_external_prototype(jlcf->vm, + jmcf->rep_proto = njs_vm_external_prototype(jmcf->vm, &ngx_http_js_externals[2]); - if (jlcf->rep_proto == NULL) { + if (jmcf->rep_proto == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to add reply proto"); return NGX_CONF_ERROR; } - rc = njs_vm_compile(jlcf->vm, &start, end); + rc = njs_vm_compile(jmcf->vm, &start, end); if (rc != NJS_OK) { - njs_vm_retval_to_ext_string(jlcf->vm, &text); + njs_vm_retval_to_ext_string(jmcf->vm, &text); ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%*s, included", @@ -2346,11 +2351,11 @@ ngx_http_js_content(ngx_conf_t *cf, ngx_ static void * -ngx_http_js_create_loc_conf(ngx_conf_t *cf) +ngx_http_js_create_main_conf(ngx_conf_t *cf) { - ngx_http_js_loc_conf_t *conf; - - conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_js_loc_conf_t)); + ngx_http_js_main_conf_t *conf; + + conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_js_main_conf_t)); if (conf == NULL) { return NULL; } @@ -2368,18 +2373,28 @@ ngx_http_js_create_loc_conf(ngx_conf_t * } +static void * +ngx_http_js_create_loc_conf(ngx_conf_t *cf) +{ + ngx_http_js_loc_conf_t *conf; + + conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_js_loc_conf_t)); + if (conf == NULL) { + return NULL; + } + + /* + * set by ngx_pcalloc(): + * + * conf->content = { 0, NULL }; + */ + + return conf; +} + + static char * ngx_http_js_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { - ngx_http_js_loc_conf_t *prev = parent; - ngx_http_js_loc_conf_t *conf = child; - - if (conf->vm == NULL) { - conf->vm = prev->vm; - conf->req_proto = prev->req_proto; - conf->res_proto = prev->res_proto; - conf->rep_proto = prev->rep_proto; - } - return NGX_CONF_OK; } diff -r 464d7e2905fc -r 5abcdd645d57 nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Mon May 14 14:10:23 2018 +0300 +++ b/nginx/ngx_stream_js_module.c Tue Apr 17 17:15:27 2018 +0300 @@ -14,10 +14,14 @@ typedef struct { njs_vm_t *vm; + const njs_extern_t *proto; +} ngx_stream_js_main_conf_t; + + +typedef struct { ngx_str_t access; ngx_str_t preread; ngx_str_t filter; - const njs_extern_t *proto; } ngx_stream_js_srv_conf_t; @@ -75,6 +79,7 @@ static char *ngx_stream_js_include(ngx_c void *conf); static char *ngx_stream_js_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static void *ngx_stream_js_create_main_conf(ngx_conf_t *cf); static void *ngx_stream_js_create_srv_conf(ngx_conf_t *cf); static char *ngx_stream_js_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child); @@ -86,14 +91,14 @@ static ngx_command_t ngx_stream_js_comm { ngx_string("js_include"), NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1, ngx_stream_js_include, - NGX_STREAM_SRV_CONF_OFFSET, + NGX_STREAM_MAIN_CONF_OFFSET, 0, NULL }, { ngx_string("js_set"), NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE2, ngx_stream_js_set, - NGX_STREAM_SRV_CONF_OFFSET, + 0, 0, NULL }, @@ -123,29 +128,29 @@ static ngx_command_t ngx_stream_js_comm static ngx_stream_module_t ngx_stream_js_module_ctx = { - NULL, /* preconfiguration */ - ngx_stream_js_init, /* postconfiguration */ + NULL, /* preconfiguration */ + ngx_stream_js_init, /* postconfiguration */ - NULL, /* create main configuration */ - NULL, /* init main configuration */ + ngx_stream_js_create_main_conf, /* create main configuration */ + NULL, /* init main configuration */ - ngx_stream_js_create_srv_conf, /* create server configuration */ - ngx_stream_js_merge_srv_conf, /* merge server configuration */ + ngx_stream_js_create_srv_conf, /* create server configuration */ + ngx_stream_js_merge_srv_conf, /* merge server configuration */ }; ngx_module_t ngx_stream_js_module = { NGX_MODULE_V1, - &ngx_stream_js_module_ctx, /* module context */ - ngx_stream_js_commands, /* module directives */ - NGX_STREAM_MODULE, /* module type */ - NULL, /* init master */ - NULL, /* init module */ - NULL, /* init process */ - NULL, /* init thread */ - NULL, /* exit thread */ - NULL, /* exit process */ - NULL, /* exit master */ + &ngx_stream_js_module_ctx, /* module context */ + ngx_stream_js_commands, /* module directives */ + NGX_STREAM_MODULE, /* module type */ + NULL, /* init master */ + NULL, /* init module */ + NULL, /* init process */ + NULL, /* init thread */ + NULL, /* exit thread */ + NULL, /* exit process */ + NULL, /* exit master */ NGX_MODULE_V1_PADDING }; @@ -621,14 +626,14 @@ ngx_stream_js_variable(ngx_stream_sessio static ngx_int_t ngx_stream_js_init_vm(ngx_stream_session_t *s) { - nxt_int_t rc; - nxt_str_t exception; - ngx_pool_cleanup_t *cln; - ngx_stream_js_ctx_t *ctx; - ngx_stream_js_srv_conf_t *jscf; + nxt_int_t rc; + nxt_str_t exception; + ngx_pool_cleanup_t *cln; + ngx_stream_js_ctx_t *ctx; + ngx_stream_js_main_conf_t *jmcf; - jscf = ngx_stream_get_module_srv_conf(s, ngx_stream_js_module); - if (jscf->vm == NULL) { + jmcf = ngx_stream_get_module_main_conf(s, ngx_stream_js_module); + if (jmcf->vm == NULL) { return NGX_DECLINED; } @@ -647,7 +652,7 @@ ngx_stream_js_init_vm(ngx_stream_session return NGX_OK; } - ctx->vm = njs_vm_clone(jscf->vm, s); + ctx->vm = njs_vm_clone(jmcf->vm, s); if (ctx->vm == NULL) { return NGX_ERROR; } @@ -671,7 +676,7 @@ ngx_stream_js_init_vm(ngx_stream_session return NGX_ERROR; } - rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->arg), jscf->proto, + rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->arg), jmcf->proto, s); if (rc != NXT_OK) { return NGX_ERROR; @@ -941,7 +946,7 @@ ngx_stream_js_ext_get_code(njs_vm_t *vm, static char * ngx_stream_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_stream_js_srv_conf_t *jscf = conf; + ngx_stream_js_main_conf_t *jmcf = conf; size_t size; u_char *start, *end; @@ -954,7 +959,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ng ngx_file_info_t fi; ngx_pool_cleanup_t *cln; - if (jscf->vm) { + if (jmcf->vm) { return "is duplicate"; } @@ -1017,8 +1022,8 @@ ngx_stream_js_include(ngx_conf_t *cf, ng options.backtrace = 1; - jscf->vm = njs_vm_create(&options); - if (jscf->vm == NULL) { + jmcf->vm = njs_vm_create(&options); + if (jmcf->vm == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to create JS VM"); return NGX_CONF_ERROR; } @@ -1029,20 +1034,20 @@ ngx_stream_js_include(ngx_conf_t *cf, ng } cln->handler = ngx_stream_js_cleanup_vm; - cln->data = jscf->vm; + cln->data = jmcf->vm; - jscf->proto = njs_vm_external_prototype(jscf->vm, + jmcf->proto = njs_vm_external_prototype(jmcf->vm, &ngx_stream_js_externals[0]); - if (jscf->proto == NULL) { + if (jmcf->proto == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to add stream proto"); return NGX_CONF_ERROR; } - rc = njs_vm_compile(jscf->vm, &start, end); + rc = njs_vm_compile(jmcf->vm, &start, end); if (rc != NJS_OK) { - njs_vm_retval_to_ext_string(jscf->vm, &text); + njs_vm_retval_to_ext_string(jmcf->vm, &text); ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%*s, included", @@ -1098,6 +1103,27 @@ ngx_stream_js_set(ngx_conf_t *cf, ngx_co static void * +ngx_stream_js_create_main_conf(ngx_conf_t *cf) +{ + ngx_stream_js_srv_conf_t *conf; + + conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_js_main_conf_t)); + if (conf == NULL) { + return NULL; + } + + /* + * set by ngx_pcalloc(): + * + * conf->vm = NULL; + * conf->proto = NULL; + */ + + return conf; +} + + +static void * ngx_stream_js_create_srv_conf(ngx_conf_t *cf) { ngx_stream_js_srv_conf_t *conf; @@ -1110,8 +1136,6 @@ ngx_stream_js_create_srv_conf(ngx_conf_t /* * set by ngx_pcalloc(): * - * conf->vm = NULL; - * conf->proto = NULL; * conf->access = { 0, NULL }; * conf->preread = { 0, NULL }; * conf->filter = { 0, NULL }; @@ -1127,11 +1151,6 @@ ngx_stream_js_merge_srv_conf(ngx_conf_t ngx_stream_js_srv_conf_t *prev = parent; ngx_stream_js_srv_conf_t *conf = child; - if (conf->vm == NULL) { - conf->vm = prev->vm; - conf->proto = prev->proto; - } - ngx_conf_merge_str_value(conf->access, prev->access, ""); ngx_conf_merge_str_value(conf->preread, prev->preread, ""); ngx_conf_merge_str_value(conf->filter, prev->filter, ""); From pablo at pablo.com.mx Tue May 15 03:04:22 2018 From: pablo at pablo.com.mx (Pablo Fischer) Date: Mon, 14 May 2018 20:04:22 -0700 Subject: Difference between weight, current_weight, effective_weight, etc? Message-ID: Howdy! We are looking (unless it already exists) to add load feedback functionality to our setup, this basically means to have an API (either lua or through C) that we can use to change the weight of servers "dynamically" (either async or by hitting a specific URL). However when reading the code I'm a little confused on the difference between those weight variables, seems that sometimes you compare them against each other so not sure what is the difference in them. What is the difference between weight, current_weight and effective_weight? I'm assuming that total_weight is the sum of all weights (weight?) for a given upstream. Thanks! -- Pablo From mdounin at mdounin.ru Tue May 15 03:18:19 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 15 May 2018 06:18:19 +0300 Subject: Difference between weight, current_weight, effective_weight, etc? In-Reply-To: References: Message-ID: <20180515031818.GE32137@mdounin.ru> Hello! On Mon, May 14, 2018 at 08:04:22PM -0700, Pablo Fischer wrote: > We are looking (unless it already exists) to add load feedback > functionality to our setup, this basically means to have an API > (either lua or through C) that we can use to change the weight of > servers "dynamically" (either async or by hitting a specific URL). > > However when reading the code I'm a little confused on the difference > between those weight variables, seems that sometimes you compare them > against each other so not sure what is the difference in them. > > What is the difference between weight, current_weight and > effective_weight? I'm assuming that total_weight is the sum of all > weights (weight?) for a given upstream. Try reading this commit: http://hg.nginx.org/nginx/rev/c90801720a0c -- Maxim Dounin http://mdounin.ru/ From Adam.Horvath at edgeware.tv Wed May 16 09:23:44 2018 From: Adam.Horvath at edgeware.tv (Adam Horvath) Date: Wed, 16 May 2018 09:23:44 +0000 Subject: ngx_http_upstream_round_robin.c Message-ID: <202CD3D1AF7B5C4BA5BBE6DC22A8C36E985E76@EX01.edgeware.tv> Hello, I am totally new to nginx, so please forgive me if I am wrong. I propose the following change: https://github.com/nginx/nginx/blob/master/src/http/ngx_http_upstream_round_robin.c#L615 From: if (state & NGX_PEER_FAILED) To: if (state & (NGX_PEER_FAILED || NGX_PEER_NEXT)) Note: The value causing us trouble: state = NGX_PEER_NEXT // on HTTP 404 Comes from: https://github.com/nginx/nginx/blob/master/src/http/ngx_http_upstream.c#L4097 Regular round robin seems to work fine. But with a configuration like: upstream live { server 10.16.48.227:8090; server 10.16.48.228:8090 backup; } We get a nice failover for HTTP 502. But for HTTP 404 we get a forever-loop, just like the one mentioned in Changes with nginx 1.3.0: *) Bugfix: nginx might loop infinitely over backends if the "proxy_next_upstream" directive with the "http_404" parameter was used and there were backup servers specified in an upstream block. So we get looping despite the fix. The proposed edit stops the looping for us, but I cannot see the full consequences. And of course it is possible that we can fix it by just some configuration change. What do you think? Thanks Adam -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Wed May 16 13:40:12 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 16 May 2018 16:40:12 +0300 Subject: ngx_http_upstream_round_robin.c In-Reply-To: <202CD3D1AF7B5C4BA5BBE6DC22A8C36E985E76@EX01.edgeware.tv> References: <202CD3D1AF7B5C4BA5BBE6DC22A8C36E985E76@EX01.edgeware.tv> Message-ID: <20180516134011.GK32137@mdounin.ru> Hello! On Wed, May 16, 2018 at 09:23:44AM +0000, Adam Horvath wrote: > Hello, > I am totally new to nginx, so please forgive me if I am wrong. > > I propose the following change: > https://github.com/nginx/nginx/blob/master/src/http/ngx_http_upstream_round_robin.c#L615 > From: if (state & NGX_PEER_FAILED) > To: if (state & (NGX_PEER_FAILED || NGX_PEER_NEXT)) Suggested change is wrong, as NGX_PEER_NEXT is not expected to mark the peer as failed, see documentation here: http://nginx.org/r/proxy_next_upstream Rather, it is expected to instruct nginx to try another backend, assuming the resource in question is not yet available on the particular backend. [...] > Regular round robin seems to work fine. But with a configuration like: > upstream live { > server 10.16.48.227:8090; > server 10.16.48.228:8090 backup; > } > > We get a nice failover for HTTP 502. But for HTTP 404 we get a forever-loop, just like the one mentioned in > Changes with nginx 1.3.0: > *) Bugfix: nginx might loop infinitely over backends if the > "proxy_next_upstream" directive with the "http_404" parameter was > used and there were backup servers specified in an upstream block. > > So we get looping despite the fix. The proposed edit stops the > looping for us, but I cannot see the full consequences. And of > course it is possible that we can fix it by just some > configuration change. > > What do you think? In the configuration in question and assuming "proxy_next_upstream http_404;", nginx is expected to try all backends available, and then return 404 to the user. If in your case it results in an infinite loop, you may want to share more details on your configuration. -- Maxim Dounin http://mdounin.ru/ From teward at thomas-ward.net Wed May 16 16:03:51 2018 From: teward at thomas-ward.net (Thomas Ward) Date: Wed, 16 May 2018 12:03:51 -0400 Subject: Is there a particular reason --with-compat isn't enabled by default? In-Reply-To: <20180510124708.GU32137@mdounin.ru> References: <128a79cb-96d2-1118-fdd3-0d3a66e2bf7a@thomas-ward.net> <20180510101741.GE40212@lo0.su> <20180510124708.GU32137@mdounin.ru> Message-ID: Maxim, Thanks for your reply. On 05/10/2018 08:47 AM, Maxim Dounin wrote: > More importantly, "--with-compat" provides compatibility between > builds with different configure options. > > Without the "--with-compat" argument, one have to use exactly the > same "./configure" line to build both nginx and a module. The > "--with-compat" option relaxes this restriction, and it is more or > less enough to build both nginx and a module with "--with-compat". > > This generally simplifies building dynamic modules, and also > allows one to load the same module into different nginx variants > built with different flags. Is there a reason, then, that `--with-compat` is not a default build option?? Is there a particular specific reason it was *not* set as a default compile-time option? Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Wed May 16 16:24:15 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 16 May 2018 19:24:15 +0300 Subject: Is there a particular reason --with-compat isn't enabled by default? In-Reply-To: References: <128a79cb-96d2-1118-fdd3-0d3a66e2bf7a@thomas-ward.net> <20180510101741.GE40212@lo0.su> <20180510124708.GU32137@mdounin.ru> Message-ID: <20180516162415.GM32137@mdounin.ru> Hello! On Wed, May 16, 2018 at 12:03:51PM -0400, Thomas Ward wrote: > On 05/10/2018 08:47 AM, Maxim Dounin wrote: > > More importantly, "--with-compat" provides compatibility between > > builds with different configure options. > > > > Without the "--with-compat" argument, one have to use exactly the > > same "./configure" line to build both nginx and a module. The > > "--with-compat" option relaxes this restriction, and it is more or > > less enough to build both nginx and a module with "--with-compat". > > > > This generally simplifies building dynamic modules, and also > > allows one to load the same module into different nginx variants > > built with different flags. > > Is there a reason, then, that `--with-compat` is not a default build > option?? Is there a particular specific reason it was *not* set as a > default compile-time option? The main reasons are that "--with-compat" is not needed when not using dynamic modules built separately, and compiling nginx with "--with-compat" results in slightly less optimal binaries (with various otherwise unneeded placeholder fields added to structures). We've considered making it the default when it was introduced, but decided to keep it as an explicit option then. This might worth reconsidering. -- Maxim Dounin http://mdounin.ru/ From teward at thomas-ward.net Wed May 16 16:45:11 2018 From: teward at thomas-ward.net (Thomas Ward) Date: Wed, 16 May 2018 12:45:11 -0400 Subject: Is there a particular reason --with-compat isn't enabled by default? In-Reply-To: <20180516162415.GM32137@mdounin.ru> References: <128a79cb-96d2-1118-fdd3-0d3a66e2bf7a@thomas-ward.net> <20180510101741.GE40212@lo0.su> <20180510124708.GU32137@mdounin.ru> <20180516162415.GM32137@mdounin.ru> Message-ID: Maxim, On 05/16/2018 12:24 PM, Maxim Dounin wrote: > Hello! > > On Wed, May 16, 2018 at 12:03:51PM -0400, Thomas Ward wrote: > >> On 05/10/2018 08:47 AM, Maxim Dounin wrote: >>> More importantly, "--with-compat" provides compatibility between >>> builds with different configure options. >>> >>> Without the "--with-compat" argument, one have to use exactly the >>> same "./configure" line to build both nginx and a module. The >>> "--with-compat" option relaxes this restriction, and it is more or >>> less enough to build both nginx and a module with "--with-compat". >>> >>> This generally simplifies building dynamic modules, and also >>> allows one to load the same module into different nginx variants >>> built with different flags. >> Is there a reason, then, that `--with-compat` is not a default build >> option?? Is there a particular specific reason it was *not* set as a >> default compile-time option? > The main reasons are that "--with-compat" is not needed when not > using dynamic modules built separately, and compiling nginx with > "--with-compat" results in slightly less optimal binaries (with > various otherwise unneeded placeholder fields added to > structures). > > We've considered making it the default when it was introduced, but > decided to keep it as an explicit option then. This might worth > reconsidering. > I agree it might be worth a reconsideration, in fact I am a supporter of making `--with-compat` a default option, not only to make my job as a downstream packager easy, but because this would also benefit the nginx.org open-source nginx repository as well.? With the number of third-party dynamic modules increasing, and more users wanting to utilize them, it may be detrimental to leave it disabled.? When the support was first released, and dynamic modules were 'new', it made sense to leave it disabled, but with more and more modules becoming dynamically-supported it could be detrimental to leave this 'default disabled'. With specific regard to the nginx.org repositories, at last I checked a couple weeks ago, they aren't currently built with `--with-compat` (unless I missed a recent change to the OSS packaging on hg.nginx.org), which means it's equally difficult for users to use the nginx repositories without compiling NGINX themselves with third-party modules.? If with-compat becomes the default, then this makes things easier for users using the nginx.org repos as well as other downstream distributions' packages going forward. Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From dnj0496 at gmail.com Wed May 16 17:02:02 2018 From: dnj0496 at gmail.com (Dk Jack) Date: Wed, 16 May 2018 10:02:02 -0700 Subject: error ngx_http_send_header Message-ID: Hi, I am trying to send a custom response in my module when I encounter a request for a specific location. For example, I have setup my location as follows: server { listen 9999; location /__my_module { set_mymodule_location; log_not_found off; } } In my location handler, I am trying to respond to a request for this location. I get the response I expect at the client. However, I am seeing the following error message logged in error.log: 2018/05/16 00:38:07 [alert] 225#225: *158 header already sent, client: 127.0.0.1, server: , request: "GET /__my_module HTTP/1.1", host: "localhost:9999" Can someone let me know how I can prevent this error from showing up. Also, the return value from ngx_http_send_header is always an NGX_ERROR. Not sure why... FWIW, my response buffer is always less than 512 bytes. My code is included at the end of this email. Any help is appreciated. Thanks Dk. int SendResponse(ngx_http_request_t *r, ngx_uint_t http_status, const char *data, unsigned int dlen) { ngx_buf_t *buf = ngx_create_temp_buf(r->pool, 512); if (NULL == buf) { ngx_log_error(NGX_LOG_ERR, log, 0, "allocation failure"); return NGX_HTTP_INTERNAL_SERVER_ERROR; } buf->last = ngx_copy(buf->start, (unsigned char*) data, dlen); ngx_log_t *log = r->connection->log; ngx_chain_t *out_chain = ngx_alloc_chain_link(r->pool); if (NULL == out_chain) { ngx_log_error(NGX_LOG_ERR, log, 0, "failed to alloc buffer chain"); return NGX_HTTP_INTERNAL_SERVER_ERROR; } out_chain->buf = buf; out_chain->next = NULL; buf->last_buf = 1; buf->last_in_chain = 1; ngx_int_t rc; r->headers_out.status = http_status; r->headers_out.content_length_n = buf->last - buf->start; r->headers_out.content_type.len = sizeof("text/plain") - 1; r->headers_out.content_type.data = (u_char *) "text/plain"; rc = ngx_http_send_header(r); #if 0 // send_header always returns NGX_ERROR. if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { ngx_log_error(NGX_LOG_ERR, log, 0, "send header failed. rc=%i", rc); return NGX_HTTP_INTERNAL_SERVER_ERROR; } #endif rc = ngx_http_output_filter(r, out_chain); if (rc != NGX_OK) { ngx_log_error(NGX_LOG_ERR, log, 0, "send response buffer failed. rc=%i", rc); return NGX_HTTP_INTERNAL_SERVER_ERROR; } return 0; } -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Wed May 16 17:14:43 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 16 May 2018 20:14:43 +0300 Subject: Is there a particular reason --with-compat isn't enabled by default? In-Reply-To: References: <128a79cb-96d2-1118-fdd3-0d3a66e2bf7a@thomas-ward.net> <20180510101741.GE40212@lo0.su> <20180510124708.GU32137@mdounin.ru> <20180516162415.GM32137@mdounin.ru> Message-ID: <20180516171443.GP32137@mdounin.ru> Hello! On Wed, May 16, 2018 at 12:45:11PM -0400, Thomas Ward wrote: > Maxim, > > > On 05/16/2018 12:24 PM, Maxim Dounin wrote: > > Hello! > > > > On Wed, May 16, 2018 at 12:03:51PM -0400, Thomas Ward wrote: > > > >> On 05/10/2018 08:47 AM, Maxim Dounin wrote: > >>> More importantly, "--with-compat" provides compatibility between > >>> builds with different configure options. > >>> > >>> Without the "--with-compat" argument, one have to use exactly the > >>> same "./configure" line to build both nginx and a module. The > >>> "--with-compat" option relaxes this restriction, and it is more or > >>> less enough to build both nginx and a module with "--with-compat". > >>> > >>> This generally simplifies building dynamic modules, and also > >>> allows one to load the same module into different nginx variants > >>> built with different flags. > >> Is there a reason, then, that `--with-compat` is not a default build > >> option?? Is there a particular specific reason it was *not* set as a > >> default compile-time option? > > The main reasons are that "--with-compat" is not needed when not > > using dynamic modules built separately, and compiling nginx with > > "--with-compat" results in slightly less optimal binaries (with > > various otherwise unneeded placeholder fields added to > > structures). > > > > We've considered making it the default when it was introduced, but > > decided to keep it as an explicit option then. This might worth > > reconsidering. > > > I agree it might be worth a reconsideration, in fact I am a supporter of > making `--with-compat` a default option, not only to make my job as a > downstream packager easy, but because this would also benefit the > nginx.org open-source nginx repository as well.? With the number of > third-party dynamic modules increasing, and more users wanting to > utilize them, it may be detrimental to leave it disabled.? When the > support was first released, and dynamic modules were 'new', it made > sense to leave it disabled, but with more and more modules becoming > dynamically-supported it could be detrimental to leave this 'default > disabled'. > > With specific regard to the nginx.org repositories, at last I checked a > couple weeks ago, they aren't currently built with `--with-compat` > (unless I missed a recent change to the OSS packaging on hg.nginx.org), > which means it's equally difficult for users to use the nginx > repositories without compiling NGINX themselves with third-party > modules.? If with-compat becomes the default, then this makes things > easier for users using the nginx.org repos as well as other downstream > distributions' packages going forward. Repositories as available from nginx.org are built with "--with-compat" since it was introduced in 2016: http://hg.nginx.org/pkg-oss/file/tip/rpm/SPECS/Makefile#l256 http://hg.nginx.org/pkg-oss/rev/fa656182ba2a#l3.220 -- Maxim Dounin http://mdounin.ru/ From ranier.vf at gmail.com Wed May 16 17:21:37 2018 From: ranier.vf at gmail.com (Ranier Vf) Date: Wed, 16 May 2018 14:21:37 -0300 Subject: error ngx_http_send_header In-Reply-To: References: Message-ID: Hi, I'm not sure that help. But, I suggest this: int SendResponse(ngx_http_request_t *r, ngx_uint_t http_status, const char *data, unsigned int dlen) { ngx_buf_t *buf; ngx_int_t rc; rc = ngx_http_discard_request_body(r); if (rc != NGX_OK) { return rc; } buf = ngx_create_temp_buf(r->pool, 512); /* Sure 512 is enough? */ if (NULL == buf) { ngx_log_error(NGX_LOG_ERR, log, 0, "allocation failure"); return NGX_HTTP_INTERNAL_SERVER_ERROR; } buf->last = ngx_copy(buf->start, (unsigned char*) data, dlen); ngx_log_t *log = r->connection->log; ngx_chain_t *out_chain = ngx_alloc_chain_link(r->pool); if (NULL == out_chain) { ngx_log_error(NGX_LOG_ERR, log, 0, "failed to alloc buffer chain"); return NGX_HTTP_INTERNAL_SERVER_ERROR; } out_chain->buf = buf; out_chain->next = NULL; buf->last_buf = 1; buf->last_in_chain = 1; r->headers_out.status = http_status; r->headers_out.content_length_n = buf->last - buf->pos; /* Use buf->pos */ r->headers_out.content_type.len = sizeof("text/plain") - 1; r->headers_out.content_type.data = (u_char *) "text/plain"; rc = ngx_http_send_header(r); if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { ngx_log_error(NGX_LOG_ERR, log, 0, "send header failed. rc=%i", rc); return NGX_HTTP_INTERNAL_SERVER_ERROR; } rc = ngx_http_output_filter(r, out_chain); if (rc != NGX_OK) { ngx_log_error(NGX_LOG_ERR, log, 0, "send response buffer failed. rc=%i", rc); return NGX_HTTP_INTERNAL_SERVER_ERROR; } return rc; } Livre de v?rus. www.avast.com . <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> 2018-05-16 14:02 GMT-03:00 Dk Jack : > Hi, > I am trying to send a custom response in my module when I encounter a > request for a specific location. For example, I have setup my location as > follows: > > server { > listen 9999; > location /__my_module { > set_mymodule_location; > log_not_found off; > } > } > > In my location handler, I am trying to respond to a request for this > location. I get the response I expect at the client. However, I am seeing > the following error message logged in error.log: > > 2018/05/16 00:38:07 [alert] 225#225: *158 header already sent, client: > 127.0.0.1, server: , request: "GET /__my_module HTTP/1.1", host: > "localhost:9999" > > Can someone let me know how I can prevent this error from showing up. > Also, the return value from ngx_http_send_header is always an NGX_ERROR. > Not sure why... > > FWIW, my response buffer is always less than 512 bytes. My code is > included at the end of this email. Any help is appreciated. Thanks > > Dk. > > int > SendResponse(ngx_http_request_t *r, ngx_uint_t http_status, > const char *data, unsigned int dlen) > { > ngx_buf_t *buf = ngx_create_temp_buf(r->pool, 512); > > if (NULL == buf) { > ngx_log_error(NGX_LOG_ERR, log, 0, > "allocation failure"); > return NGX_HTTP_INTERNAL_SERVER_ERROR; > } > > buf->last = ngx_copy(buf->start, (unsigned char*) data, dlen); > ngx_log_t *log = r->connection->log; > > ngx_chain_t *out_chain = ngx_alloc_chain_link(r->pool); > if (NULL == out_chain) { > ngx_log_error(NGX_LOG_ERR, log, 0, > "failed to alloc buffer chain"); > return NGX_HTTP_INTERNAL_SERVER_ERROR; > } > > out_chain->buf = buf; > out_chain->next = NULL; > buf->last_buf = 1; > buf->last_in_chain = 1; > > ngx_int_t rc; > r->headers_out.status = http_status; > r->headers_out.content_length_n = buf->last - buf->start; > r->headers_out.content_type.len = sizeof("text/plain") - 1; > r->headers_out.content_type.data = (u_char *) "text/plain"; > rc = ngx_http_send_header(r); > > #if 0 // send_header always returns NGX_ERROR. > if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { > ngx_log_error(NGX_LOG_ERR, log, 0, > "send header failed. rc=%i", rc); > return NGX_HTTP_INTERNAL_SERVER_ERROR; > } > #endif > > rc = ngx_http_output_filter(r, out_chain); > if (rc != NGX_OK) { > ngx_log_error(NGX_LOG_ERR, log, 0, > "send response buffer failed. rc=%i", rc); > return NGX_HTTP_INTERNAL_SERVER_ERROR; > } > > return 0; > } > > > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: From teward at thomas-ward.net Wed May 16 17:23:19 2018 From: teward at thomas-ward.net (Thomas Ward) Date: Wed, 16 May 2018 13:23:19 -0400 Subject: Is there a particular reason --with-compat isn't enabled by default? In-Reply-To: <20180516171443.GP32137@mdounin.ru> References: <128a79cb-96d2-1118-fdd3-0d3a66e2bf7a@thomas-ward.net> <20180510101741.GE40212@lo0.su> <20180510124708.GU32137@mdounin.ru> <20180516162415.GM32137@mdounin.ru> <20180516171443.GP32137@mdounin.ru> Message-ID: <463537d0-e4d5-1846-574f-720a9dc2582a@thomas-ward.net> Interesting, that wasn't in the specific rules when I was hunting it down. Thanks for the pointer.? In either case, it should probably be enabled globally, per my prior arguments (but with respect to downstream distros) On 05/16/2018 01:14 PM, Maxim Dounin wrote: > Hello! > > On Wed, May 16, 2018 at 12:45:11PM -0400, Thomas Ward wrote: > >> Maxim, >> >> >> On 05/16/2018 12:24 PM, Maxim Dounin wrote: >>> Hello! >>> >>> On Wed, May 16, 2018 at 12:03:51PM -0400, Thomas Ward wrote: >>> >>>> On 05/10/2018 08:47 AM, Maxim Dounin wrote: >>>>> More importantly, "--with-compat" provides compatibility between >>>>> builds with different configure options. >>>>> >>>>> Without the "--with-compat" argument, one have to use exactly the >>>>> same "./configure" line to build both nginx and a module. The >>>>> "--with-compat" option relaxes this restriction, and it is more or >>>>> less enough to build both nginx and a module with "--with-compat". >>>>> >>>>> This generally simplifies building dynamic modules, and also >>>>> allows one to load the same module into different nginx variants >>>>> built with different flags. >>>> Is there a reason, then, that `--with-compat` is not a default build >>>> option?? Is there a particular specific reason it was *not* set as a >>>> default compile-time option? >>> The main reasons are that "--with-compat" is not needed when not >>> using dynamic modules built separately, and compiling nginx with >>> "--with-compat" results in slightly less optimal binaries (with >>> various otherwise unneeded placeholder fields added to >>> structures). >>> >>> We've considered making it the default when it was introduced, but >>> decided to keep it as an explicit option then. This might worth >>> reconsidering. >>> >> I agree it might be worth a reconsideration, in fact I am a supporter of >> making `--with-compat` a default option, not only to make my job as a >> downstream packager easy, but because this would also benefit the >> nginx.org open-source nginx repository as well.? With the number of >> third-party dynamic modules increasing, and more users wanting to >> utilize them, it may be detrimental to leave it disabled.? When the >> support was first released, and dynamic modules were 'new', it made >> sense to leave it disabled, but with more and more modules becoming >> dynamically-supported it could be detrimental to leave this 'default >> disabled'. >> >> With specific regard to the nginx.org repositories, at last I checked a >> couple weeks ago, they aren't currently built with `--with-compat` >> (unless I missed a recent change to the OSS packaging on hg.nginx.org), >> which means it's equally difficult for users to use the nginx >> repositories without compiling NGINX themselves with third-party >> modules.? If with-compat becomes the default, then this makes things >> easier for users using the nginx.org repos as well as other downstream >> distributions' packages going forward. > Repositories as available from nginx.org are built with > "--with-compat" since it was introduced in 2016: > > http://hg.nginx.org/pkg-oss/file/tip/rpm/SPECS/Makefile#l256 > http://hg.nginx.org/pkg-oss/rev/fa656182ba2a#l3.220 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pablo at pablo.com.mx Wed May 16 17:50:58 2018 From: pablo at pablo.com.mx (Pablo Fischer) Date: Wed, 16 May 2018 10:50:58 -0700 Subject: Difference between weight, current_weight, effective_weight, etc? In-Reply-To: <20180515031818.GE32137@mdounin.ru> References: <20180515031818.GE32137@mdounin.ru> Message-ID: Ahh, thanks a lot for the reference and sorry for the late reply, Maxim. So reading that and assuming I?m already collecting via an OOB/async call the weights of each server (the idea is to change the weights dynamically), then when I notice a change in the weight of one of the peers the things I should update are: For round-robin: - the -> weight of the peer (I assume via get_peer): the new dynamic value. - The effective_weight: the new dynamic value. - Reset the current_weight to 0. - Update total_weights for the upstream group. As for least conn, hash and others looks like we similar changes would also be needed. Am I a bit lost or in the right path? ;-D On Mon, May 14, 2018 at 8:18 PM Maxim Dounin wrote: > Hello! > > On Mon, May 14, 2018 at 08:04:22PM -0700, Pablo Fischer wrote: > > > We are looking (unless it already exists) to add load feedback > > functionality to our setup, this basically means to have an API > > (either lua or through C) that we can use to change the weight of > > servers "dynamically" (either async or by hitting a specific URL). > > > > However when reading the code I'm a little confused on the difference > > between those weight variables, seems that sometimes you compare them > > against each other so not sure what is the difference in them. > > > > What is the difference between weight, current_weight and > > effective_weight? I'm assuming that total_weight is the sum of all > > weights (weight?) for a given upstream. > > Try reading this commit: > > http://hg.nginx.org/nginx/rev/c90801720a0c > > -- > Maxim Dounin > http://mdounin.ru/ > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Adam.Horvath at edgeware.tv Wed May 16 18:13:12 2018 From: Adam.Horvath at edgeware.tv (Adam Horvath) Date: Wed, 16 May 2018 18:13:12 +0000 Subject: ngx_http_upstream_round_robin.c Message-ID: <202CD3D1AF7B5C4BA5BBE6DC22A8C36E985F2F@EX01.edgeware.tv> Privet Max! Yes our proxy_next_upstream is set. Below is our config. >From the logging at: https://github.com/nginx/nginx/blob/master/src/http/ngx_http_upstream_round_robin.c#L594 We got maybe 50/second of these in our loop: 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 1 0 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 2 2 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 1 0 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 2 2 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 1 0 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 2 2 Etc... Which led me to speculate around: state == 2 == NGX_PEER_NEXT I must also mention that our application is deeply entangled with callbacks into http_request, so it is possible that we have messed up there but I am following this lead for the moment. I am at the moment trying to see the same error with our config and a "vanilla nginx" but I am having build problems : ( And we are actually using VERSION nginx-1.11.6... our build pipeline is not [yet] quite accommodated to changing nginx versions, sorry. Thank You Adam worker_processes auto; worker_cpu_affinity auto; #user edgeware; worker_rlimit_core 500M; working_directory /opt/cores/; error_log /var/log/edgeware/ew-repackager//error.log debug; events { worker_connections 1024; } http { access_log /var/log/edgeware/ew-repackager//access.log combined; upstream live { server 10.16.48.227:8090; server 10.16.48.227:8090 backup; } server { listen 80; server_name 0.0.0.0; #aio on; directio off; open_file_cache max=1000 inactive=5m; open_file_cache_valid 2m; open_file_cache_min_uses 1; open_file_cache_errors on; location / { root /home/adam/; } location /live/ { internal; proxy_pass http://live/; proxy_next_upstream error timeout invalid_header http_404 http_500 http_502 http_503 http_504; proxy_read_timeout 4s; } } } From mdounin at mdounin.ru Wed May 16 19:07:31 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 16 May 2018 22:07:31 +0300 Subject: ngx_http_upstream_round_robin.c In-Reply-To: <202CD3D1AF7B5C4BA5BBE6DC22A8C36E985F2F@EX01.edgeware.tv> References: <202CD3D1AF7B5C4BA5BBE6DC22A8C36E985F2F@EX01.edgeware.tv> Message-ID: <20180516190731.GS32137@mdounin.ru> Hello! On Wed, May 16, 2018 at 06:13:12PM +0000, Adam Horvath wrote: > Yes our proxy_next_upstream is set. Below is our config. > > From the logging at: > https://github.com/nginx/nginx/blob/master/src/http/ngx_http_upstream_round_robin.c#L594 > > We got maybe 50/second of these in our loop: > 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 1 0 > 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 2 2 > 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 1 0 > 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 2 2 > 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 1 0 > 2018/05/16 17:26:34 [debug] 23317#0: *452 free rr peer 2 2 > Etc... > > Which led me to speculate around: state == 2 == NGX_PEER_NEXT > > I must also mention that our application is deeply entangled > with callbacks into http_request, so it is possible that we have > messed up there but I am following this lead for the moment. I > am at the moment trying to see the same error with our config > and a "vanilla nginx" but I am having build problems : ( > > And we are actually using VERSION nginx-1.11.6... our build > pipeline is not [yet] quite accommodated to changing nginx > versions, sorry. I don't think there are any related changes since 1.11.6, so testing with nginx 1.11.6 should be enough. If you'll be able to reproduce the problem with vanilla nginx without any modifications / external modules, please share details. -- Maxim Dounin http://mdounin.ru/ From mdounin at mdounin.ru Wed May 16 19:11:28 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 16 May 2018 22:11:28 +0300 Subject: error ngx_http_send_header In-Reply-To: References: Message-ID: <20180516191128.GT32137@mdounin.ru> Hello! On Wed, May 16, 2018 at 10:02:02AM -0700, Dk Jack wrote: > Hi, > I am trying to send a custom response in my module when I encounter a > request for a specific location. For example, I have setup my location as > follows: > > server { > listen 9999; > location /__my_module { > set_mymodule_location; > log_not_found off; > } > } > > In my location handler, I am trying to respond to a request for this > location. I get the response I expect at the client. However, I am seeing > the following error message logged in error.log: > > 2018/05/16 00:38:07 [alert] 225#225: *158 header already sent, client: > 127.0.0.1, server: , request: "GET /__my_module HTTP/1.1", host: > "localhost:9999" > > Can someone let me know how I can prevent this error from showing up. Also, > the return value from ngx_http_send_header is always an NGX_ERROR. Not sure > why... The error indicate that you are trying to sent a response header at the point where it was already sent. You have to invistigate why and where it happens, and fix things. Most likely you are trying to add your code in a wrong place. -- Maxim Dounin http://mdounin.ru/ From dnj0496 at gmail.com Wed May 16 20:05:50 2018 From: dnj0496 at gmail.com (Dk Jack) Date: Wed, 16 May 2018 13:05:50 -0700 Subject: error ngx_http_send_header Message-ID: Hi Maxim, I am sending the response in the request handler which I registered for in the NGX_HTTP_SERVER_REWRITE_PHASE handler. In my handler, I have the following code to avoid responding multiple times as well. Still, I am getting the error. if (r->main->count > 1) return NGX_DECLINED; Bhasker. Hello! On Wed, May 16, 2018 at 10:02:02AM -0700, Dk Jack wrote: >* Hi, *>* I am trying to send a custom response in my module when I encounter a *>* request for a specific location. For example, I have setup my location as *>* follows: *> >* server { *>* listen 9999; *>* location /__my_module { *>* set_mymodule_location; *>* log_not_found off; *>* } *>* } *> >* In my location handler, I am trying to respond to a request for this *>* location. I get the response I expect at the client. However, I am seeing *>* the following error message logged in error.log: *> >* 2018/05/16 00:38:07 [alert] 225#225: *158 header already sent, client: *>* 127.0.0.1, server: , request: "GET /__my_module HTTP/1.1", host: *>* "localhost:9999" *> >* Can someone let me know how I can prevent this error from showing up. Also, *>* the return value from ngx_http_send_header is always an NGX_ERROR. Not sure *>* why... * The error indicate that you are trying to sent a response header at the point where it was already sent. You have to invistigate why and where it happens, and fix things. Most likely you are trying to add your code in a wrong place. -- Maxim Douninhttp://mdounin.ru/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From zchao1995 at gmail.com Thu May 17 02:29:26 2018 From: zchao1995 at gmail.com (tokers) Date: Wed, 16 May 2018 19:29:26 -0700 Subject: error ngx_http_send_header In-Reply-To: References: Message-ID: Hello! I think the handler return code is improper. You might need to learn the function ngx_http_core_rewrite_phase and decide a proper return code to this checker so that subsequent phases handler will not be invoked.Otherwise some content handlers can still can get involved. (these content handler will try to send header and flush some data to downstream). -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Thu May 17 13:11:45 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 17 May 2018 16:11:45 +0300 Subject: error ngx_http_send_header In-Reply-To: References: Message-ID: <20180517131145.GV32137@mdounin.ru> Hello! On Wed, May 16, 2018 at 01:05:50PM -0700, Dk Jack wrote: > Hi Maxim, > > I am sending the response in the request handler which I registered for > > in the NGX_HTTP_SERVER_REWRITE_PHASE handler. In my handler, I have the In a rewrite phase handler you are _not_ expected to return a response. If you do return it, you have to be careful to properly cancel additional request processing. Moreover, the server rewrite phase is _not_ executed for locations. Instead, it is a phase for rewrites affecting the whole server block. The configuration example you've provided makes no sense for a module which works in the server rewrite phase. For returning a custom response in a specifically set location it might be better idea to use the content phase, or, even simplier, to register a location-specific content handler. See empty gif module sources for a relatively simple example. > following code to avoid responding multiple times as well. Still, I am getting > > the error. > > if (r->main->count > 1) > return NGX_DECLINED; This is not expected to prevent anything from being executed multiple times. Rather, it will prevent your code from executing when there is more than one reference to the request. You may want to read some guides on writing nginx modules, as it is more or less clear you don't understand basics. In particular, Evan Miller's one might be a good start: https://www.evanmiller.org/nginx-modules-guide.html Refer to the Development Guide for more advanced subjects: http://nginx.org/en/docs/dev/development_guide.html -- Maxim Dounin http://mdounin.ru/ From mdounin at mdounin.ru Thu May 17 20:27:35 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 17 May 2018 23:27:35 +0300 Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <76712266.29100280.1525970578101.JavaMail.zimbra@redhat.com> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> <1524686298341.78540@cryptopro.ru> <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> <1524771096966.89645@cryptopro.ru> <20180427134017.GB32137@mdounin.ru> <1115169087.23375772.1524842877109.JavaMail.zimbra@redhat.com> <20180503143219.GF32137@mdounin.ru> <76712266.29100280.1525970578101.JavaMail.zimbra@redhat.com> Message-ID: <20180517202735.GX32137@mdounin.ru> Hello! On Thu, May 10, 2018 at 12:42:58PM -0400, Anderson Sasaki wrote: > Hello, > > Thanks again for the feedback. > > > In no particular order: > > > > - Should be "SSL: added ..." (no capital letter after a semicolon, > > prefer past tense). > > > > - An empty line after the summary. > > > > - Please prefer double spacing. > > > > - "uniNItialized" > > The proposed changes were applied in the new patch version. > > > > diff -r 46c0c7ef4913 -r f5b0a7910922 src/event/ngx_event_openssl.c > > > --- a/src/event/ngx_event_openssl.c Wed Apr 25 14:57:24 2018 +0300 > > > +++ b/src/event/ngx_event_openssl.c Fri Apr 27 16:58:16 2018 +0200 > > > @@ -527,6 +527,13 @@ > > > return NGX_ERROR; > > > } > > > > > > + if (!ENGINE_init(engine)) { > > > > As previously noted at [1], this may need ENGINE_finish() to avoid > > leaking loaded engines. > > Added ENGINE_finish() calls. > > > > > > + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > > > + "ENGINE_init(engine) failed"); > > > > There is no reason to log static string "engine" here. Consider > > using engine name here. > > Logging the engine name instead. > > The patch follows: > > # HG changeset patch > # User Anderson Toshiyuki Sasaki > # Date 1525954250 -7200 > # Thu May 10 14:10:50 2018 +0200 > # Node ID e7d0387ad229ca47514f346c8b692e6f388d72e1 > # Parent ceab908790c4eb7cd01c40bd16581ef794222ca5 > SSL: added ENGINE_init() call before loading key. > > It is necessary to call ENGINE_init() before using an OpenSSL engine > to get the engine functional reference. Without this, when > ENGINE_load_private_key() is called, the engine is still uninitialized. > > diff -r ceab908790c4 -r e7d0387ad229 src/event/ngx_event_openssl.c > --- a/src/event/ngx_event_openssl.c Tue Apr 24 14:04:59 2018 +0300 > +++ b/src/event/ngx_event_openssl.c Thu May 10 14:10:50 2018 +0200 > @@ -527,6 +527,13 @@ > return NGX_ERROR; > } > > + if (!ENGINE_init(engine)) { > + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > + "ENGINE_init(\"%s\") failed", p); > + ENGINE_free(engine); > + return NGX_ERROR; > + } > + > *last++ = ':'; > > pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); > @@ -534,10 +541,12 @@ > if (pkey == NULL) { > ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > "ENGINE_load_private_key(\"%s\") failed", last); > + ENGINE_finish(engine); > ENGINE_free(engine); > return NGX_ERROR; > } > > + ENGINE_finish(engine); > ENGINE_free(engine); > > if (SSL_CTX_use_PrivateKey(ssl->ctx, pkey) == 0) { The patch looks correct to me. Though it causes a segmentation faults within pkcs11 engine when using such loaded keys at least on Ubuntu 18.04 (OpenSSL 1.1.0g, pkcs11 engine from libp11 0.4.7). Segmentation faults can be reproduced with the test you've sent earlier. Using an explitic "init = 1" in openssl.conf resolves this, as well as commenting out ENGINE_finish(), so it looks like it cannot handle ENGINE_finish() while certificates loaded from the engine are still in use. Possible options might be: - avoid any changes, and require "init = 1" as we effectively do now; - add explicit lists of engines initialized, and call ENGINE_finish() once no longer needed (probably somewhere in ngx_ssl_cleanup_ctx()); - avoid calling ENGINE_finish() with appropriate explanation of the problem; - dig further into what goes on in OpenSSL / pkcs11 engine, and fix things (might be already resolved in [1]). [1] https://github.com/OpenSC/libp11/commit/da725ab727342083478150a203a3c80c4551feb4 -- Maxim Dounin http://mdounin.ru/ From ansasaki at redhat.com Fri May 18 08:36:53 2018 From: ansasaki at redhat.com (Anderson Sasaki) Date: Fri, 18 May 2018 04:36:53 -0400 (EDT) Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <20180517202735.GX32137@mdounin.ru> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> <1524771096966.89645@cryptopro.ru> <20180427134017.GB32137@mdounin.ru> <1115169087.23375772.1524842877109.JavaMail.zimbra@redhat.com> <20180503143219.GF32137@mdounin.ru> <76712266.29100280.1525970578101.JavaMail.zimbra@redhat.com> <20180517202735.GX32137@mdounin.ru> Message-ID: <892353446.31019871.1526632613226.JavaMail.zimbra@redhat.com> Hello, > The patch looks correct to me. Though it causes a segmentation > faults within pkcs11 engine when using such loaded keys at least > on Ubuntu 18.04 (OpenSSL 1.1.0g, pkcs11 engine from libp11 0.4.7). > Segmentation faults can be reproduced with the test you've sent > earlier. > > Using an explitic "init = 1" in openssl.conf resolves this, as > well as commenting out ENGINE_finish(), so it looks like it cannot > handle ENGINE_finish() while certificates loaded from the engine > are still in use. > > Possible options might be: > > - avoid any changes, and require "init = 1" as we effectively do > now; > > - add explicit lists of engines initialized, and call > ENGINE_finish() once no longer needed (probably somewhere in > ngx_ssl_cleanup_ctx()); > > - avoid calling ENGINE_finish() with appropriate explanation of > the problem; > > - dig further into what goes on in OpenSSL / pkcs11 engine, and > fix things (might be already resolved in [1]). > > [1] > https://github.com/OpenSC/libp11/commit/da725ab727342083478150a203a3c80c4551feb4 The root of the problem is solved in the patch you pointed out above. The libp11-0.4.7 release is missing this EVP_PKEY_set1_engine() call. Without this, the engine is not properly associated with the EVP_PKEY object, preventing the OpenSSL automatic re-initialization of the engine to take place when the key is used. With the inclusion of such patch, the ENGINE_finish() can be safely called. As long as the key keeps the structural reference to the engine, it will be re-initialized when needed. I've tested in Fedora, where the same problem occurs. Since I am currently a co-maintainer of the engine in Fedora, I can fix it there. But I can't fix it on Ubuntu. Best Regards, Anderson From mdounin at mdounin.ru Tue May 22 13:59:07 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 22 May 2018 13:59:07 +0000 Subject: [nginx] Core: silenced getsockopt(TCP_FASTOPEN) messages on FreeBSD. Message-ID: details: http://hg.nginx.org/nginx/rev/66aa2c1e82e6 branches: changeset: 7274:66aa2c1e82e6 user: Maxim Dounin date: Mon May 21 23:11:27 2018 +0300 description: Core: silenced getsockopt(TCP_FASTOPEN) messages on FreeBSD. FreeBSD returns EINVAL when getsockopt(TCP_FASTOPEN) is called on a unix domain socket, resulting in "getsockopt(TCP_FASTOPEN) ... failed" messages during binary upgrade when unix domain listen sockets are present in the configuration. Added EINVAL to the list of ignored error codes. diffstat: src/core/ngx_connection.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diffs (14 lines): diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -305,7 +305,9 @@ ngx_set_inherited_sockets(ngx_cycle_t *c { err = ngx_socket_errno; - if (err != NGX_EOPNOTSUPP && err != NGX_ENOPROTOOPT) { + if (err != NGX_EOPNOTSUPP && err != NGX_ENOPROTOOPT + && err != NGX_EINVAL) + { ngx_log_error(NGX_LOG_NOTICE, cycle->log, err, "getsockopt(TCP_FASTOPEN) %V failed, ignored", &ls[i].addr_text); From mdounin at mdounin.ru Tue May 22 14:17:56 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 22 May 2018 17:17:56 +0300 Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <892353446.31019871.1526632613226.JavaMail.zimbra@redhat.com> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> <1524771096966.89645@cryptopro.ru> <20180427134017.GB32137@mdounin.ru> <1115169087.23375772.1524842877109.JavaMail.zimbra@redhat.com> <20180503143219.GF32137@mdounin.ru> <76712266.29100280.1525970578101.JavaMail.zimbra@redhat.com> <20180517202735.GX32137@mdounin.ru> <892353446.31019871.1526632613226.JavaMail.zimbra@redhat.com> Message-ID: <20180522141756.GH32137@mdounin.ru> Hello! On Fri, May 18, 2018 at 04:36:53AM -0400, Anderson Sasaki wrote: > Hello, > > > The patch looks correct to me. Though it causes a segmentation > > faults within pkcs11 engine when using such loaded keys at least > > on Ubuntu 18.04 (OpenSSL 1.1.0g, pkcs11 engine from libp11 0.4.7). > > Segmentation faults can be reproduced with the test you've sent > > earlier. > > > > Using an explitic "init = 1" in openssl.conf resolves this, as > > well as commenting out ENGINE_finish(), so it looks like it cannot > > handle ENGINE_finish() while certificates loaded from the engine > > are still in use. > > > > Possible options might be: > > > > - avoid any changes, and require "init = 1" as we effectively do > > now; > > > > - add explicit lists of engines initialized, and call > > ENGINE_finish() once no longer needed (probably somewhere in > > ngx_ssl_cleanup_ctx()); > > > > - avoid calling ENGINE_finish() with appropriate explanation of > > the problem; > > > > - dig further into what goes on in OpenSSL / pkcs11 engine, and > > fix things (might be already resolved in [1]). > > > > [1] > > https://github.com/OpenSC/libp11/commit/da725ab727342083478150a203a3c80c4551feb4 > > The root of the problem is solved in the patch you pointed out > above. The libp11-0.4.7 release is missing this > EVP_PKEY_set1_engine() call. Without this, the engine is not > properly associated with the EVP_PKEY object, preventing the > OpenSSL automatic re-initialization of the engine to take place > when the key is used. > > With the inclusion of such patch, the ENGINE_finish() can be > safely called. As long as the key keeps the structural reference > to the engine, it will be re-initialized when needed. > > I've tested in Fedora, where the same problem occurs. Since I am > currently a co-maintainer of the engine in Fedora, I can fix it > there. But I can't fix it on Ubuntu. Ok, so it looks like: - With OpenSSL 1.0.x, it seems that it is not at all possible to correctly use keys loaded from an engine without this engine being referenced elsewhere. Trying to use "ENGINE_init(); ENGINE_load_private_key(); ENGINE_finish();" will result in a segmentation fault unless the engine is referenced elsewhere (and hence "ENGINE_init()" is not needed). - With OpenSSL 1.1.x, it is now possible to use EVP_PKEY_set1_engine() to preserve a reference, but neither OpenSSL 1.1.x nor fixed pkcs11 engine is available on most platforms right now. Commiting the patch as is means that we'll change an easily fixable "not initialized" error to a segmentation fault for most users affected by the patch. It doesn't look like a good solution. I don't like the idea of not calling ENGINE_finish() either, as this approach can eventually result in a reference counter overflow and another segmentation fault. A simpliest solution seems to preserve things as is, at least for now, requiring an explicit engine initialization either via openssl.conf or via (misuse of) the "ssl_engine" directive. I've also tried postponing ENGINE_finish() till ngx_ssl_cleanup_ctx(), but I can't say I like this approach. Just for the record, patch below: diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c --- a/src/event/ngx_event_openssl.c +++ b/src/event/ngx_event_openssl.c @@ -114,6 +114,7 @@ int ngx_ssl_certificate_index; int ngx_ssl_next_certificate_index; int ngx_ssl_certificate_name_index; int ngx_ssl_stapling_index; +int ngx_ssl_engine_index; ngx_int_t @@ -225,6 +226,13 @@ ngx_ssl_init(ngx_log_t *log) return NGX_ERROR; } + ngx_ssl_engine_index = X509_get_ex_new_index(0, NULL, NULL, NULL, NULL); + + if (ngx_ssl_engine_index == -1) { + ngx_ssl_error(NGX_LOG_ALERT, log, 0, "X509_get_ex_new_index() failed"); + return NGX_ERROR; + } + return NGX_OK; } @@ -534,6 +542,16 @@ ngx_ssl_certificate(ngx_conf_t *cf, ngx_ return NGX_ERROR; } + x509 = SSL_CTX_get_ex_data(ssl->ctx, ngx_ssl_certificate_index); + + if (X509_set_ex_data(x509, ngx_ssl_engine_index, engine) == 0) { + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, + "X509_set_ex_data() failed"); + ENGINE_finish(engine); + ENGINE_free(engine); + return NGX_ERROR; + } + *last++ = ':'; pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); @@ -546,7 +564,6 @@ ngx_ssl_certificate(ngx_conf_t *cf, ngx_ return NGX_ERROR; } - ENGINE_finish(engine); ENGINE_free(engine); if (SSL_CTX_use_PrivateKey(ssl->ctx, pkey) == 0) { @@ -3154,11 +3171,20 @@ ngx_ssl_cleanup_ctx(void *data) { ngx_ssl_t *ssl = data; - X509 *cert, *next; + X509 *cert, *next; +#ifndef OPENSSL_NO_ENGINE + ENGINE *engine; +#endif cert = SSL_CTX_get_ex_data(ssl->ctx, ngx_ssl_certificate_index); while (cert) { +#ifndef OPENSSL_NO_ENGINE + engine = X509_get_ex_data(cert, ngx_ssl_engine_index); + if (engine) { + ENGINE_finish(engine); + } +#endif next = X509_get_ex_data(cert, ngx_ssl_next_certificate_index); X509_free(cert); cert = next; -- Maxim Dounin http://mdounin.ru/ From ru at nginx.com Wed May 23 09:03:02 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Wed, 23 May 2018 09:03:02 +0000 Subject: [nginx] Resolver: style. Message-ID: details: http://hg.nginx.org/nginx/rev/e15bf978447e branches: changeset: 7275:e15bf978447e user: Ruslan Ermilov date: Wed May 23 10:41:29 2018 +0300 description: Resolver: style. diffstat: src/core/ngx_resolver.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (21 lines): diff -r 66aa2c1e82e6 -r e15bf978447e src/core/ngx_resolver.c --- a/src/core/ngx_resolver.c Mon May 21 23:11:27 2018 +0300 +++ b/src/core/ngx_resolver.c Wed May 23 10:41:29 2018 +0300 @@ -1299,7 +1299,7 @@ ngx_resolver_send_udp_query(ngx_resolver n = ngx_send(rec->udp, query, qlen); - if (n == -1) { + if (n == NGX_ERROR) { return NGX_ERROR; } @@ -4546,7 +4546,7 @@ ngx_tcp_connect(ngx_resolver_connection_ level = NGX_LOG_CRIT; } - ngx_log_error(level, c->log, err, "connect() to %V failed", + ngx_log_error(level, &rec->log, err, "connect() to %V failed", &rec->server); ngx_close_connection(c); From ru at nginx.com Wed May 23 09:03:04 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Wed, 23 May 2018 09:03:04 +0000 Subject: [nginx] Resolver: close UDP socket on error or incomplete send. Message-ID: details: http://hg.nginx.org/nginx/rev/a90f7812de35 branches: changeset: 7276:a90f7812de35 user: Ruslan Ermilov date: Wed May 23 10:41:38 2018 +0300 description: Resolver: close UDP socket on error or incomplete send. diffstat: src/core/ngx_resolver.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diffs (28 lines): diff -r e15bf978447e -r a90f7812de35 src/core/ngx_resolver.c --- a/src/core/ngx_resolver.c Wed May 23 10:41:29 2018 +0300 +++ b/src/core/ngx_resolver.c Wed May 23 10:41:38 2018 +0300 @@ -1300,15 +1300,22 @@ ngx_resolver_send_udp_query(ngx_resolver n = ngx_send(rec->udp, query, qlen); if (n == NGX_ERROR) { - return NGX_ERROR; + goto failed; } if ((size_t) n != (size_t) qlen) { ngx_log_error(NGX_LOG_CRIT, &rec->log, 0, "send() incomplete"); - return NGX_ERROR; + goto failed; } return NGX_OK; + +failed: + + ngx_close_connection(rec->udp); + rec->udp = NULL; + + return NGX_ERROR; } From vl at nginx.com Wed May 23 12:18:33 2018 From: vl at nginx.com (Vladimir Homutov) Date: Wed, 23 May 2018 12:18:33 +0000 Subject: [nginx] Syslog: install cleanup handler only once. Message-ID: details: http://hg.nginx.org/nginx/rev/7f9935f07fe9 branches: changeset: 7277:7f9935f07fe9 user: Vladimir Homutov date: Mon May 14 22:50:57 2018 +0300 description: Syslog: install cleanup handler only once. If a socket was re-opened due to an error (02c2352d5b01 and fa0e093b64d7), additional cleanup handler was installed each time. diffstat: src/core/ngx_syslog.c | 32 ++++++++++++++++---------------- src/core/ngx_syslog.h | 1 - 2 files changed, 16 insertions(+), 17 deletions(-) diffs (74 lines): diff -r a90f7812de35 -r 7f9935f07fe9 src/core/ngx_syslog.c --- a/src/core/ngx_syslog.c Wed May 23 10:41:38 2018 +0300 +++ b/src/core/ngx_syslog.c Mon May 14 22:50:57 2018 +0300 @@ -39,7 +39,8 @@ static ngx_event_t ngx_syslog_dummy_eve char * ngx_syslog_process_conf(ngx_conf_t *cf, ngx_syslog_peer_t *peer) { - peer->pool = cf->pool; + ngx_pool_cleanup_t *cln; + peer->facility = NGX_CONF_UNSET_UINT; peer->severity = NGX_CONF_UNSET_UINT; @@ -67,6 +68,19 @@ ngx_syslog_process_conf(ngx_conf_t *cf, peer->conn.fd = (ngx_socket_t) -1; + peer->conn.read = &ngx_syslog_dummy_event; + peer->conn.write = &ngx_syslog_dummy_event; + + ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log; + + cln = ngx_pool_cleanup_add(cf->pool, 0); + if (cln == NULL) { + return NGX_CONF_ERROR; + } + + cln->data = peer; + cln->handler = ngx_syslog_cleanup; + return NGX_CONF_OK; } @@ -306,13 +320,7 @@ ngx_syslog_send(ngx_syslog_peer_t *peer, static ngx_int_t ngx_syslog_init_peer(ngx_syslog_peer_t *peer) { - ngx_socket_t fd; - ngx_pool_cleanup_t *cln; - - peer->conn.read = &ngx_syslog_dummy_event; - peer->conn.write = &ngx_syslog_dummy_event; - - ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log; + ngx_socket_t fd; fd = ngx_socket(peer->server.sockaddr->sa_family, SOCK_DGRAM, 0); if (fd == (ngx_socket_t) -1) { @@ -333,14 +341,6 @@ ngx_syslog_init_peer(ngx_syslog_peer_t * goto failed; } - cln = ngx_pool_cleanup_add(peer->pool, 0); - if (cln == NULL) { - goto failed; - } - - cln->data = peer; - cln->handler = ngx_syslog_cleanup; - peer->conn.fd = fd; /* UDP sockets are always ready to write */ diff -r a90f7812de35 -r 7f9935f07fe9 src/core/ngx_syslog.h --- a/src/core/ngx_syslog.h Wed May 23 10:41:38 2018 +0300 +++ b/src/core/ngx_syslog.h Mon May 14 22:50:57 2018 +0300 @@ -9,7 +9,6 @@ typedef struct { - ngx_pool_t *pool; ngx_uint_t facility; ngx_uint_t severity; ngx_str_t tag; From mdounin at mdounin.ru Wed May 23 13:40:04 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 23 May 2018 13:40:04 +0000 Subject: [nginx] Removed glibc crypt_r() bug workaround (ticket #1469). Message-ID: details: http://hg.nginx.org/nginx/rev/eca3e054e978 branches: changeset: 7278:eca3e054e978 user: Maxim Dounin date: Wed May 23 16:38:16 2018 +0300 description: Removed glibc crypt_r() bug workaround (ticket #1469). The bug in question was fixed in glibc 2.3.2 and is no longer expected to manifest itself on real servers. On the other hand, the workaround causes compilation problems on various systems. Previously, we've already fixed the code to compile with musl libc (fd6fd02f6a4d), and now it is broken on Fedora 28 where glibc's crypt library was replaced by libxcrypt. So the workaround was removed. diffstat: src/os/unix/ngx_user.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-) diffs (14 lines): diff --git a/src/os/unix/ngx_user.c b/src/os/unix/ngx_user.c --- a/src/os/unix/ngx_user.c +++ b/src/os/unix/ngx_user.c @@ -21,10 +21,6 @@ ngx_libc_crypt(ngx_pool_t *pool, u_char struct crypt_data cd; cd.initialized = 0; -#ifdef __GLIBC__ - /* work around the glibc bug */ - cd.current_salt[0] = ~salt[0]; -#endif value = crypt_r((char *) key, (char *) salt, &cd); From pluknet at nginx.com Thu May 24 17:49:18 2018 From: pluknet at nginx.com (Sergey Kandaurov) Date: Thu, 24 May 2018 17:49:18 +0000 Subject: [njs] Using getrandom() libc interface. Message-ID: details: http://hg.nginx.org/njs/rev/822f975c933a branches: changeset: 523:822f975c933a user: Sergey Kandaurov date: Thu May 24 20:32:09 2018 +0300 description: Using getrandom() libc interface. Available since Glibc 2.25, and FreeBSD 12.0. diffstat: nxt/auto/getrandom | 33 ++++++++++++++++++++++++++++----- nxt/nxt_random.c | 8 +++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diffs (79 lines): diff -r a994ab62d351 -r 822f975c933a nxt/auto/getrandom --- a/nxt/auto/getrandom Mon May 14 15:03:29 2018 +0300 +++ b/nxt/auto/getrandom Thu May 24 20:32:09 2018 +0300 @@ -3,22 +3,45 @@ # Copyright (C) NGINX, Inc. -# Linux 3.17 getrandom(). +# getrandom(). nxt_feature="getrandom()" nxt_feature_name=NXT_HAVE_GETRANDOM -nxt_feature_run=no +nxt_feature_run=yes nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include - #include - #include + #include int main(void) { char buf[4]; - (void) syscall(SYS_getrandom, buf, 4, 0); + if (getrandom(buf, 4, 0) < 0) { + return 1; + } return 0; }" . ${NXT_AUTO}feature + +if [ $nxt_found = no ]; then + + # Linux 3.17 SYS_getrandom. + + nxt_feature="SYS_getrandom in Linux" + nxt_feature_name=NXT_HAVE_LINUX_SYS_GETRANDOM + nxt_feature_test="#include + #include + #include + + int main(void) { + char buf[4]; + + if (syscall(SYS_getrandom, buf, 4, 0) < 0) { + return 1; + } + + return 0; + }" + . ${NXT_AUTO}feature +fi diff -r a994ab62d351 -r 822f975c933a nxt/nxt_random.c --- a/nxt/nxt_random.c Mon May 14 15:03:29 2018 +0300 +++ b/nxt/nxt_random.c Thu May 24 20:32:09 2018 +0300 @@ -13,6 +13,8 @@ #include #include #if (NXT_HAVE_GETRANDOM) +#include +#elif (NXT_HAVE_LINUX_SYS_GETRANDOM) #include #include #endif @@ -66,7 +68,11 @@ nxt_random_stir(nxt_random_t *r, nxt_pid #if (NXT_HAVE_GETRANDOM) - /* Linux 3.17 getrandom(), it is not available in Glibc. */ + n = getrandom(&key, NXT_RANDOM_KEY_SIZE, 0); + +#elif (NXT_HAVE_LINUX_SYS_GETRANDOM) + + /* Linux 3.17 SYS_getrandom, not available in Glibc prior to 2.25. */ n = syscall(SYS_getrandom, &key, NXT_RANDOM_KEY_SIZE, 0); From xeioex at nginx.com Mon May 28 14:06:38 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Mon, 28 May 2018 14:06:38 +0000 Subject: [njs] Improved logging for js_set and js_content directives. Message-ID: details: http://hg.nginx.org/njs/rev/b65fa3d62b74 branches: changeset: 525:b65fa3d62b74 user: Dmitry Volyntsev date: Mon May 28 17:05:17 2018 +0300 description: Improved logging for js_set and js_content directives. Previously, unknown functions were reported under the debug log level which made the debugging of misconfigured directives harder. diffstat: nginx/ngx_http_js_module.c | 8 ++++---- nginx/ngx_stream_js_module.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diffs (39 lines): diff -r 481402695c87 -r b65fa3d62b74 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Mon May 28 17:05:16 2018 +0300 +++ b/nginx/ngx_http_js_module.c Mon May 28 17:05:17 2018 +0300 @@ -665,8 +665,8 @@ ngx_http_js_content_event_handler(ngx_ht func = njs_vm_function(ctx->vm, &name); if (func == NULL) { - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "js function \"%V\" not found", &jlcf->content); + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "js function \"%V\" not found", &jlcf->content); ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); return; } @@ -773,8 +773,8 @@ ngx_http_js_variable(ngx_http_request_t func = njs_vm_function(ctx->vm, &name); if (func == NULL) { - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "js function \"%V\" not found", fname); + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "js function \"%V\" not found", fname); v->not_found = 1; return NGX_OK; } diff -r 481402695c87 -r b65fa3d62b74 nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Mon May 28 17:05:16 2018 +0300 +++ b/nginx/ngx_stream_js_module.c Mon May 28 17:05:17 2018 +0300 @@ -585,8 +585,8 @@ ngx_stream_js_variable(ngx_stream_sessio func = njs_vm_function(ctx->vm, &name); if (func == NULL) { - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "js function \"%V\" not found", fname); + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + "js function \"%V\" not found", fname); v->not_found = 1; return NGX_OK; } From xeioex at nginx.com Mon May 28 14:06:38 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Mon, 28 May 2018 14:06:38 +0000 Subject: [njs] Fixed error logging in js_include. Message-ID: details: http://hg.nginx.org/njs/rev/481402695c87 branches: changeset: 524:481402695c87 user: Dmitry Volyntsev date: Mon May 28 17:05:16 2018 +0300 description: Fixed error logging in js_include. Previously, ngx_log_error() was used instead of ngx_conf_log_error() in js_include directive handler. Replacing it with ngx_conf_log_error() to report the additional information about the location of the directive in the configuration file. diffstat: nginx/ngx_http_js_module.c | 18 +++++++++--------- nginx/ngx_stream_js_module.c | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diffs (94 lines): diff -r 822f975c933a -r 481402695c87 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Thu May 24 20:32:09 2018 +0300 +++ b/nginx/ngx_http_js_module.c Mon May 28 17:05:16 2018 +0300 @@ -2189,8 +2189,8 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ } if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - ngx_fd_info_n " \"%s\" failed", file.data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, + ngx_fd_info_n " \"%s\" failed", file.data); (void) ngx_close_file(fd); return NGX_CONF_ERROR; } @@ -2206,25 +2206,25 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ n = ngx_read_fd(fd, start, size); if (n == -1) { - ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, - ngx_read_fd_n " \"%s\" failed", file.data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, + ngx_read_fd_n " \"%s\" failed", file.data); (void) ngx_close_file(fd); return NGX_CONF_ERROR; } if ((size_t) n != size) { - ngx_log_error(NGX_LOG_ALERT, cf->log, 0, - ngx_read_fd_n " has read only %z of %O from \"%s\"", - n, size, file.data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + ngx_read_fd_n " has read only %z of %O from \"%s\"", + n, size, file.data); (void) ngx_close_file(fd); return NGX_CONF_ERROR; } if (ngx_close_file(fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, - ngx_close_file_n " %s failed", file.data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, + ngx_close_file_n " %s failed", file.data); } end = start + size; diff -r 822f975c933a -r 481402695c87 nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Thu May 24 20:32:09 2018 +0300 +++ b/nginx/ngx_stream_js_module.c Mon May 28 17:05:16 2018 +0300 @@ -978,8 +978,8 @@ ngx_stream_js_include(ngx_conf_t *cf, ng } if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - ngx_fd_info_n " \"%s\" failed", file.data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, + ngx_fd_info_n " \"%s\" failed", file.data); (void) ngx_close_file(fd); return NGX_CONF_ERROR; } @@ -995,25 +995,25 @@ ngx_stream_js_include(ngx_conf_t *cf, ng n = ngx_read_fd(fd, start, size); if (n == -1) { - ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, - ngx_read_fd_n " \"%s\" failed", file.data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, + ngx_read_fd_n " \"%s\" failed", file.data); (void) ngx_close_file(fd); return NGX_CONF_ERROR; } if ((size_t) n != size) { - ngx_log_error(NGX_LOG_ALERT, cf->log, 0, - ngx_read_fd_n " has read only %z of %uz from \"%s\"", - n, size, file.data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + ngx_read_fd_n " has read only %z of %uz from \"%s\"", + n, size, file.data); (void) ngx_close_file(fd); return NGX_CONF_ERROR; } if (ngx_close_file(fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, - ngx_close_file_n " %s failed", file.data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, + ngx_close_file_n " %s failed", file.data); } end = start + size; From ru at nginx.com Tue May 29 08:48:16 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Tue, 29 May 2018 08:48:16 +0000 Subject: [nginx] Win32: fixed comment in ngx_gettimeofday() calculations. Message-ID: details: http://hg.nginx.org/nginx/rev/f95de1361039 branches: changeset: 7279:f95de1361039 user: Ruslan Ermilov date: Tue May 29 11:47:32 2018 +0300 description: Win32: fixed comment in ngx_gettimeofday() calculations. diffstat: src/os/win32/ngx_time.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r eca3e054e978 -r f95de1361039 src/os/win32/ngx_time.c --- a/src/os/win32/ngx_time.c Wed May 23 16:38:16 2018 +0300 +++ b/src/os/win32/ngx_time.c Tue May 29 11:47:32 2018 +0300 @@ -23,7 +23,7 @@ ngx_gettimeofday(struct timeval *tp) * January 1, 1601 12:00 A.M. UTC. * * Between January 1, 1970 (Epoch) and January 1, 1601 there were - * 134744 days, + * 134774 days, * 11644473600 seconds or * 11644473600,000,000,0 100-nanosecond intervals. * From ru at nginx.com Wed May 30 08:13:52 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Wed, 30 May 2018 08:13:52 +0000 Subject: [nginx] Core: fixed comment about ngx_current_msec after 81fae70d6cb8. Message-ID: details: http://hg.nginx.org/nginx/rev/76e7e20cda05 branches: changeset: 7280:76e7e20cda05 user: Ruslan Ermilov date: Tue May 29 16:15:19 2018 +0300 description: Core: fixed comment about ngx_current_msec after 81fae70d6cb8. The value is no longer guaranteed to be based on milliseconds elapsed since Epoch. diffstat: src/core/ngx_times.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (14 lines): diff -r f95de1361039 -r 76e7e20cda05 src/core/ngx_times.h --- a/src/core/ngx_times.h Tue May 29 11:47:32 2018 +0300 +++ b/src/core/ngx_times.h Tue May 29 16:15:19 2018 +0300 @@ -43,8 +43,8 @@ extern volatile ngx_str_t ngx_cached_ extern volatile ngx_str_t ngx_cached_syslog_time; /* - * milliseconds elapsed since epoch and truncated to ngx_msec_t, - * used in event timers + * milliseconds elapsed since some unspecified point in the past + * and truncated to ngx_msec_t, used in event timers */ extern volatile ngx_msec_t ngx_current_msec; From xeioex at nginx.com Wed May 30 12:07:47 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Wed, 30 May 2018 12:07:47 +0000 Subject: [njs] Setting status code to 500 by default in js_content handler. Message-ID: details: http://hg.nginx.org/njs/rev/1ac5805c9d19 branches: changeset: 526:1ac5805c9d19 user: Dmitry Volyntsev date: Wed May 30 15:07:04 2018 +0300 description: Setting status code to 500 by default in js_content handler. This helps to debug incorrectly written content handlers. diffstat: nginx/ngx_http_js_module.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diffs (36 lines): diff -r b65fa3d62b74 -r 1ac5805c9d19 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Mon May 28 17:05:17 2018 +0300 +++ b/nginx/ngx_http_js_module.c Wed May 30 15:07:04 2018 +0300 @@ -671,6 +671,13 @@ ngx_http_js_content_event_handler(ngx_ht return; } + /* + * status is expected to be overriden by finish() or return() methods, + * otherwise the content handler is considered invalid. + */ + + ctx->status = NGX_HTTP_INTERNAL_SERVER_ERROR; + if (njs_vm_call(ctx->vm, func, njs_value_arg(ctx->args), 2) != NJS_OK) { njs_vm_retval_to_ext_string(ctx->vm, &exception); @@ -1269,6 +1276,7 @@ static njs_ret_t ngx_http_js_ext_finish(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { + ngx_http_js_ctx_t *ctx; ngx_http_request_t *r; r = njs_value_data(njs_argument(args, 0)); @@ -1277,6 +1285,10 @@ ngx_http_js_ext_finish(njs_vm_t *vm, njs return NJS_ERROR; } + ctx = ngx_http_get_module_ctx(r, ngx_http_js_module); + + ctx->status = NGX_OK; + return NJS_OK; } From xeioex at nginx.com Wed May 30 12:07:47 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Wed, 30 May 2018 12:07:47 +0000 Subject: [njs] Added the debug for the returned status code in js_content. Message-ID: details: http://hg.nginx.org/njs/rev/f8c0b88d8bf7 branches: changeset: 527:f8c0b88d8bf7 user: Dmitry Volyntsev date: Wed May 30 15:07:31 2018 +0300 description: Added the debug for the returned status code in js_content. diffstat: nginx/ngx_http_js_module.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diffs (23 lines): diff -r 1ac5805c9d19 -r f8c0b88d8bf7 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Wed May 30 15:07:04 2018 +0300 +++ b/nginx/ngx_http_js_module.c Wed May 30 15:07:31 2018 +0300 @@ -693,6 +693,9 @@ ngx_http_js_content_event_handler(ngx_ht return; } + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http js content rc: %ui", ctx->status); + ngx_http_finalize_request(r, ctx->status); } @@ -711,6 +714,9 @@ ngx_http_js_content_write_event_handler( ctx = ngx_http_get_module_ctx(r, ngx_http_js_module); if (!njs_vm_pending(ctx->vm)) { + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http js content rc: %ui", ctx->status); + ngx_http_finalize_request(r, ctx->status); return; } From mdounin at mdounin.ru Wed May 30 12:42:50 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 30 May 2018 12:42:50 +0000 Subject: [nginx] Limit req: improved handling of negative times. Message-ID: details: http://hg.nginx.org/nginx/rev/bd6563e81cea branches: changeset: 7281:bd6563e81cea user: Maxim Dounin date: Wed May 30 15:40:34 2018 +0300 description: Limit req: improved handling of negative times. Negative times can appear since workers only update time on an event loop iteration start. If a worker was blocked for a long time during an event loop iteration, it is possible that another worker already updated the time stored in the node. As such, time since last update of the node (ms) will be negative. Previous code used ngx_abs(ms) in the calculations. That is, negative times were effectively treated as positive ones. As a result, it was not possible to maintain high request rates, where the same node can be updated multiple times from during an event loop iteration. In particular, this affected setups with many SSL handshakes, see http://mailman.nginx.org/pipermail/nginx/2018-May/056291.html. Fix is to only update the last update time stored in the node if the new time is larger than previously stored one. If a future time is stored in the node, we preserve this time as is. To prevent breaking things on platforms without monotonic time available if system time is updated backwards, a safety limit of 60 seconds is used. If the time stored in the node is more than 60 seconds in the future, we assume that the time was changed backwards and update lr->last to the current time. diffstat: src/http/modules/ngx_http_limit_req_module.c | 29 ++++++++++++++++++++++++--- 1 files changed, 25 insertions(+), 4 deletions(-) diffs (58 lines): diff --git a/src/http/modules/ngx_http_limit_req_module.c b/src/http/modules/ngx_http_limit_req_module.c --- a/src/http/modules/ngx_http_limit_req_module.c +++ b/src/http/modules/ngx_http_limit_req_module.c @@ -399,7 +399,14 @@ ngx_http_limit_req_lookup(ngx_http_limit ms = (ngx_msec_int_t) (now - lr->last); - excess = lr->excess - ctx->rate * ngx_abs(ms) / 1000 + 1000; + if (ms < -60000) { + ms = 1; + + } else if (ms < 0) { + ms = 0; + } + + excess = lr->excess - ctx->rate * ms / 1000 + 1000; if (excess < 0) { excess = 0; @@ -413,7 +420,11 @@ ngx_http_limit_req_lookup(ngx_http_limit if (account) { lr->excess = excess; - lr->last = now; + + if (ms) { + lr->last = now; + } + return NGX_OK; } @@ -509,13 +520,23 @@ ngx_http_limit_req_account(ngx_http_limi now = ngx_current_msec; ms = (ngx_msec_int_t) (now - lr->last); - excess = lr->excess - ctx->rate * ngx_abs(ms) / 1000 + 1000; + if (ms < -60000) { + ms = 1; + + } else if (ms < 0) { + ms = 0; + } + + excess = lr->excess - ctx->rate * ms / 1000 + 1000; if (excess < 0) { excess = 0; } - lr->last = now; + if (ms) { + lr->last = now; + } + lr->excess = excess; lr->count--; From xeioex at nginx.com Wed May 30 14:39:31 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Wed, 30 May 2018 14:39:31 +0000 Subject: [njs] Fixed the format specifier for ctx->status in debug log. Message-ID: details: http://hg.nginx.org/njs/rev/143a7f9db504 branches: changeset: 528:143a7f9db504 user: Dmitry Volyntsev date: Wed May 30 17:17:13 2018 +0300 description: Fixed the format specifier for ctx->status in debug log. diffstat: nginx/ngx_http_js_module.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (21 lines): diff -r f8c0b88d8bf7 -r 143a7f9db504 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Wed May 30 15:07:31 2018 +0300 +++ b/nginx/ngx_http_js_module.c Wed May 30 17:17:13 2018 +0300 @@ -694,7 +694,7 @@ ngx_http_js_content_event_handler(ngx_ht } ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http js content rc: %ui", ctx->status); + "http js content rc: %i", ctx->status); ngx_http_finalize_request(r, ctx->status); } @@ -715,7 +715,7 @@ ngx_http_js_content_write_event_handler( if (!njs_vm_pending(ctx->vm)) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http js content rc: %ui", ctx->status); + "http js content rc: %i", ctx->status); ngx_http_finalize_request(r, ctx->status); return; From xeioex at nginx.com Thu May 31 15:53:05 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 31 May 2018 15:53:05 +0000 Subject: [njs] Version 0.2.1. Message-ID: details: http://hg.nginx.org/njs/rev/2a0a59728b5f branches: changeset: 530:2a0a59728b5f user: Dmitry Volyntsev date: Thu May 31 18:52:02 2018 +0300 description: Version 0.2.1. diffstat: CHANGES | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-) diffs (57 lines): diff -r e38c3f59e30c -r 2a0a59728b5f CHANGES --- a/CHANGES Thu May 31 16:34:36 2018 +0300 +++ b/CHANGES Thu May 31 18:52:02 2018 +0300 @@ -1,3 +1,53 @@ + +Changes with njs 0.2.1 31 May 2018 + + Nginx modules: + + *) Feature: HTTP request body getter. + + *) Improvement: moved njs vm to the main configuration. + + *) Improvement: improved logging for js_set and js_content directives. + + *) Improvement: setting status code to 500 by default in + js_content handler. + + *) Improvement: added the debug for the returned status code in + js_content. + + *) Bugfix: fixed error logging in js_include. + + Core: + + *) Feature: added array length setter. + + *) Improvement: public header cleanup. njscript.h is renamed to njs.h. + + *) Bugfix: fixed crypto update() method after digest() is called. + + *) Bugfix: fixed crypto.createHmac() for keys with size >= alg size + and < 64. + + *) Bugfix: fixed JSON.stringify() for arrays with empty cells. + + *) Bugfix: fixed exception type for unsupported types in + JSON.stringify(). + + *) Bugfix: fixed handling of undefined arguments of functions. + + *) Bugfix: fixed handling of missing arg of + Object.getOwnPropertyDescriptor(). + + *) Bugfix: fixed handling of properties in + Object.getOwnPropertyDescriptor(). + + *) Bugfix: fixed the writeable flag of Array.length property. + + *) Bugfix: fixed return value type of clearTimeout(). + + *) Bugfix: fixed njs_vm_external_bind(). + + *) Bugfix: miscellaneous additional bugs have been fixed. Changes with njs 0.2.0 3 Apr 2018 From xeioex at nginx.com Thu May 31 15:53:05 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 31 May 2018 15:53:05 +0000 Subject: [njs] Renaming remnants of "nJScript" and "njscript" to "njs". Message-ID: details: http://hg.nginx.org/njs/rev/e38c3f59e30c branches: changeset: 529:e38c3f59e30c user: Dmitry Volyntsev date: Thu May 31 16:34:36 2018 +0300 description: Renaming remnants of "nJScript" and "njscript" to "njs". diffstat: CHANGES | 24 ++++++++++++------------ njs/njs_shell.c | 2 +- njs/test/njs_expect_test.exp | 2 +- njs/test/njs_unit_test.c | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diffs (134 lines): diff -r 143a7f9db504 -r e38c3f59e30c CHANGES --- a/CHANGES Wed May 30 17:17:13 2018 +0300 +++ b/CHANGES Thu May 31 16:34:36 2018 +0300 @@ -1,5 +1,5 @@ -Changes with nJScript 0.2.0 3 Apr 2018 +Changes with njs 0.2.0 3 Apr 2018 *) Feature: reporting njs version by CLI. @@ -20,7 +20,7 @@ Changes with nJScript 0.2.0 *) Bugfix: miscellaneous bugs have been fixed in the core and interactive shell. -Changes with nJScript 0.1.15 20 Nov 2017 +Changes with njs 0.1.15 20 Nov 2017 *) Feature: Error, EvalError, InternalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError objects. @@ -35,7 +35,7 @@ Changes with nJScript 0.1.15 *) Bugfix: miscellaneous bugs have been fixed. -Changes with nJScript 0.1.14 09 Oct 2017 +Changes with njs 0.1.14 09 Oct 2017 *) Feature: JSON object. @@ -46,7 +46,7 @@ Changes with nJScript 0.1.14 *) Bugfix: miscellaneous bugs have been fixed in the core and interactive shell. -Changes with nJScript 0.1.13 31 Aug 2017 +Changes with njs 0.1.13 31 Aug 2017 *) Feature: console.log() and console.help() methods in interactive shell. @@ -59,13 +59,13 @@ Changes with nJScript 0.1.13 *) Bugfix: improved editline detection. -Changes with nJScript 0.1.12 08 Aug 2017 +Changes with njs 0.1.12 08 Aug 2017 *) Feature: Interactive shell. *) Bugfix: in Object.isSealed(). -Changes with nJScript 0.1.11 27 Jun 2017 +Changes with njs 0.1.11 27 Jun 2017 *) Feature: Object.keys(), Object.prototype.hasOwnProperty() methods. @@ -87,7 +87,7 @@ Changes with nJScript 0.1.11 *) Bugfix: in parseInt() and Date.parse(). -Changes with nJScript 0.1.10 04 Apr 2017 +Changes with njs 0.1.10 04 Apr 2017 *) Feature: nested functions and function closures. @@ -96,12 +96,12 @@ Changes with nJScript 0.1.10 *) Bugfix: miscellaneous bugs and segmentation faults have been fixed. -Changes with nJScript 0.1.9 01 Feb 2017 +Changes with njs 0.1.9 01 Feb 2017 - *) Bugfix: global variables were not initialized when nJScript was used + *) Bugfix: global variables were not initialized when njs was used in nginx. -Changes with nJScript 0.1.8 24 Jan 2017 +Changes with njs 0.1.8 24 Jan 2017 *) Change: the "strict" mode is enforced, variables must be explicitly declared. @@ -115,7 +115,7 @@ Changes with nJScript 0.1.8 *) Bugfix: miscellaneous bugs and segmentation faults have been fixed. -Changes with nJScript 0.1.7 27 Dec 2016 +Changes with njs 0.1.7 27 Dec 2016 *) Change: the "js_include" directive has been disabled at server and location levels. @@ -124,7 +124,7 @@ Changes with nJScript 0.1.7 *) Bugfix: miscellaneous bugs and segmentation faults have been fixed. -Changes with nJScript 0.1.6 13 Dec 2016 +Changes with njs 0.1.6 13 Dec 2016 *) Change: the "js_set" directive has been disabled at server and location levels. diff -r 143a7f9db504 -r e38c3f59e30c njs/njs_shell.c --- a/njs/njs_shell.c Wed May 30 17:17:13 2018 +0300 +++ b/njs/njs_shell.c Thu May 31 16:34:36 2018 +0300 @@ -247,7 +247,7 @@ njs_interactive_shell(njs_opts_t *opts, return NXT_ERROR; } - printf("interactive njscript %s\n\n", NJS_VERSION); + printf("interactive njs %s\n\n", NJS_VERSION); printf("v. -> the properties and prototype methods of v.\n"); printf("type console.help() for more information\n\n"); diff -r 143a7f9db504 -r e38c3f59e30c njs/test/njs_expect_test.exp --- a/njs/test/njs_expect_test.exp Wed May 30 17:17:13 2018 +0300 +++ b/njs/test/njs_expect_test.exp Thu May 31 16:34:36 2018 +0300 @@ -5,7 +5,7 @@ proc njs_test {body} { spawn -nottycopy njs - expect -re "interactive njscript \\d+\.\\d+\.\\d+\r\n\r" + expect -re "interactive njs \\d+\.\\d+\.\\d+\r\n\r" expect "v. -> the properties and prototype methods of v.\r type console.help() for more information\r \r diff -r 143a7f9db504 -r e38c3f59e30c njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Wed May 30 17:17:13 2018 +0300 +++ b/njs/test/njs_unit_test.c Thu May 31 16:34:36 2018 +0300 @@ -287,8 +287,8 @@ static njs_unit_test_t njs_test[] = { nxt_string("0xffff.toString(16)"), nxt_string("ffff") }, - { nxt_string("1845449130881..toString(36)"), - nxt_string("njscript") }, + { nxt_string("30520..toString(36)"), + nxt_string("njs") }, { nxt_string("Infinity.toString()"), nxt_string("Infinity") }, From xeioex at nginx.com Thu May 31 15:53:05 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 31 May 2018 15:53:05 +0000 Subject: [njs] Added tag 0.2.1 for changeset 2a0a59728b5f Message-ID: details: http://hg.nginx.org/njs/rev/ca28263e2787 branches: changeset: 531:ca28263e2787 user: Dmitry Volyntsev date: Thu May 31 18:52:45 2018 +0300 description: Added tag 0.2.1 for changeset 2a0a59728b5f diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff -r 2a0a59728b5f -r ca28263e2787 .hgtags --- a/.hgtags Thu May 31 18:52:02 2018 +0300 +++ b/.hgtags Thu May 31 18:52:45 2018 +0300 @@ -15,3 +15,4 @@ d548b78eb881ca799aa6fc8ba459d076f7db5ac8 d89d06dc638e78f8635c0bfbcd02469ac1a08748 0.1.14 215ca47b9167d513fd58ac88de97659377e45275 0.1.15 ddd1b2c9c64b2d459e9c399554dfaadcaabcc364 0.2.0 +2a0a59728b5f197379ca62a334a516fabd4ea392 0.2.1 From xeioex at nginx.com Thu May 31 15:57:27 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 31 May 2018 15:57:27 +0000 Subject: [njs] Version bump. Message-ID: details: http://hg.nginx.org/njs/rev/c56687caf3a5 branches: changeset: 532:c56687caf3a5 user: Dmitry Volyntsev date: Thu May 31 18:55:35 2018 +0300 description: Version bump. diffstat: njs/njs.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r ca28263e2787 -r c56687caf3a5 njs/njs.h --- a/njs/njs.h Thu May 31 18:52:45 2018 +0300 +++ b/njs/njs.h Thu May 31 18:55:35 2018 +0300 @@ -11,7 +11,7 @@ #include -#define NJS_VERSION "0.2.1" +#define NJS_VERSION "0.2.2" #include