From alx.manpages at gmail.com Wed Jun 1 23:49:01 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 01:49:01 +0200 Subject: inline Message-ID: Hi, We define `nxt_inline` as: $ grepc nxt_inline ./src/nxt_clang.h:11: #define nxt_inline static inline __attribute__((always_inline)) I'm concerned that we may be inlining too much. See for example the following function calls: $ grep -rnA1 nxt_slow_path | grep -B1 nxt_thread_get_tid src/nxt_thread.c:247: if (nxt_slow_path(thr->tid == 0)) { src/nxt_thread.c-248- thr->tid = nxt_thread_get_tid(); -- src/nxt_thread.c:257: if (nxt_slow_path(thr->tid == 0)) { src/nxt_thread.c-258- thr->tid = nxt_thread_get_tid(); Looks good, but then see the definition of nxt_thread_get_tid() (it has several difinitions, one for each system, but I'll copy here one that is pretty big (NXT_AIX)): $ grepc nxt_thread_get_tid [...] ./src/nxt_thread_id.h:107: nxt_inline nxt_tid_t nxt_thread_get_tid(void) { int err, size; pthread_t pt; struct __pthrdsinfo ti; size = 0; pt = pthread_self(); err = pthread_getthrds_np(&pt, PTHRDSINFO_QUERY_TID, &ti, sizeof(struct __pthrdsinfo), NULL, size); if (nxt_fast_path(err == 0)) { return ti.__pi_tid; } nxt_main_log_alert("pthread_getthrds_np(PTHRDSINFO_QUERY_TID) failed %E", err); return 0; } [...] We're inlining a *huge* function in some cases where we know it's a slow path. We could do better by marking the function as inline (without [[gnu::always_inline]]), and let the compiler decide that it doesn't want to inline when it's in an `nxt_slow_path()`. My proposal is to split the inlining to two cases: `static inline` (for .c files) and C99 `inline` (for .h files), and have `nxt_always_inline` as a separate attribute that we can add selectively depending on each function (i.e., not adding it blindly to all functions). For a deep explanation of the different `inline` models there are, see . Let me summarize: `static inline`: This should only be used in .c files. Basically, `static` should only be applied to functions local to a translation unit, as in non-inline static functions. The problem of using `static inline` in headers is that the compiler emits duplicated function code in every translation unit (code bloat), for when the function is not inlined. There's an exception, which is when it is used together with `[[gnu::always_inline]]`, which we do (I guess for this reason), but in that case `static` is redundant (`inline [[gnu::always_inline]]` does the same thing). `inline`: We should use the C99 model. The GNU `inline` model is broken, and anyway, compilers default to C99 inline if the C version required in the command line is >= C99. We should use the `-fno-gnu89-inline` compiler flag if available to make sure the compiler doesn't fallback to GNU inline mode. Anyway, sine we use other C99 features, this should be fine. So, following the C99 inline model, we should put inline functions in headers, and then one `extern` declaration for each inline function in a .c file. `[[gnu::always_inline]]` (aka `__attribute__((__always_inline__))`): We should use this only when we are very sure that we want to *always* inline (i.e., oneliners; nxt_var_is_const() would be a great candidate). I'd also like to have some benchmark to test that none of these changes reduce performance, since changes to the inlining could trigger important performance changes (for good or for bad, we'll see). Do we have such a thing? Cheers, Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From t.stark at f5.com Thu Jun 2 14:33:43 2022 From: t.stark at f5.com (Timo Stark) Date: Thu, 2 Jun 2022 14:33:43 +0000 Subject: Unit 1.27. release Message-ID: Hi, We are pleased to announce NGINX Unit 1.27. This release brings a new level of maturity to Unit for serving static assets. We love using Unit as a cloud-native web server, and this release brings some missing features to this use case. - Redirecting HTTP requests to HTTPS - Configurable filename for path-only URIs ** Redirecting HTTP Requests to HTTPS ** Since we added TLS support and certificate management to Unit, we’ve been asked to simplify redirecting plaintext HTTP requests to the TLS-enabled listener. This is now possible by configuring the location value of a route action to contain variables. Indeed, a new variable, $request_uri, is now available that contains the path-and-query parts of the original URI, preserving any encoding needed by the browser. A full example is provided below. ``` { "listeners": { "*:443": { "tls": { "certificate": "example.com" }, "pass": "routes" }, "*:80": { "pass": "routes" } }, "routes": [ { "match": { "scheme": "http" }, "action": { "return": 301, "location": "https://${host}${request_uri}" } }, ... ``` This configuration enables Unit to listen on plaintext and TLS-enabled ports, ensuring that any requests received on the plaintext port notify the browser to resubmit on the TLS-enabled port. ** Configurable Filename for Path-Only URIs ** While it is conventional for index.html to represent the resource to be served when a path-only URI is requested, i. e. one without a filename suffix, this convention is rooted in history. It comes from a time in the early 1990s when HTTP was used exclusively to index and navigate HTML pages. You can now use a different default filename by specifying the index for a route action. A full example is provided below. ``` "routes": [ { "match": { "uri": "/cms/*" }, "action": { "share": "/var/cms$uri", "index": "default.html" } }, { "action": { "share": "/var/www$uri" } } ] ``` This configuration enables Unit to serve default.html for path-only URIs made to /cms/* and the default index.html filename for all other path-only URIs. ** Full Changelog ** This release also includes a number of bug fixes. The full changelog can be seen below. Changes with Unit 1.27.0 02 Jun 2022 *) Feature: ability to specify a custom index file name when serving static files. *) Feature: variables support in the "location" option of the "return" action. *) Feature: support empty strings in the "location" option of the "return" action. *) Feature: added a new variable, $request_uri, that includes both the path and the query parts as per RFC 3986, sections 3-4. *) Feature: Ruby Rack environment parameter "SCRIPT_NAME" support. *) Feature: compatibility with GCC 12. *) Bugfix: Ruby Sinatra applications don't work without custom logging. *) Bugfix: the controller process could crash when a chain of more than four certificates was uploaded. *) Bugfix: some Perl applications failed to process the request body, notably with Plack. *) Bugfix: some Spring Boot applications failed to start, notably with Grails. *) Bugfix: incorrect Python protocol auto detection (ASGI or WSGI) for native callable object, notably with Falcon. ** Platform Updates ** Official packages are now available for the following Linux distributions: - Fedora 36 (https://unit.nginx.org/installation/#fedora) - RHEL 9 (https://unit.nginx.org/installation/#rhel) - Ubuntu 22.04 (https://unit.nginx.org/installation/#ubuntu) Docker images (https://unit.nginx.org/installation/#docker-images) have been updated to use the latest language versions: - Go 1.18 - PHP 8.1 - Ruby 3.1 Community, Roadmap and Open Issues We continue to receive valuable bug reports and feature requests to our GitHub issues page(https://github.com/nginx/unit/issues). Although we are a small team, every issue is reviewed, and we aim to respond within 2-3 days. Since the last release, we refreshed our GitHub README (https://github.com/nginx/unit#readme) with a super-quick-start guide and added contribution guidelines(https://github.com/nginx/unit/blob/master/CONTRIBUTING.md) to help you get involved. For other discussions, please join us at the #unit-users channel on the NGINX Community Slack(https://join.slack.com/t/nginxcommunity/shared_invite/zt-1aaa22w80-~_~wSMNyPxLPLp5xunOC7w). Although this release focuses on bug fixes and web server features, we have advanced in several other projects that you can expect to see in forthcoming releases this year: - Custom logging (which brings lots of new variables and places you can use them) - JavaScript-in-the-configuration (already available as an experimental patch) (https://github.com/nginx/unit/issues/652) - Statistics API to provide true observability for Unit - CLI tool for easier command-line management of Unit Finally, you may have noticed our new mascot, the “tribot” - we hope you like it too! If you’re lucky, you can even find a T-shirt (https://swag-nginx.com/collections/tees/products/unit-tee-straight-fit) at NGINX events this year! Wbr, Timo & the Unit Team From alx.manpages at gmail.com Thu Jun 2 15:12:06 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 17:12:06 +0200 Subject: inline In-Reply-To: References: Message-ID: <504bdb4c-c50f-a469-37c9-0c44019e05de@gmail.com> On 6/2/22 01:49, Alejandro Colomar wrote: > I'm concerned that we may be inlining too much. > > > See for example the following function calls: > > $ grep -rnA1 nxt_slow_path | grep -B1 nxt_thread_get_tid > src/nxt_thread.c:247:    if (nxt_slow_path(thr->tid == 0)) { > src/nxt_thread.c-248-        thr->tid = nxt_thread_get_tid(); > -- > src/nxt_thread.c:257:        if (nxt_slow_path(thr->tid == 0)) { > src/nxt_thread.c-258-            thr->tid = nxt_thread_get_tid(); > > > Looks good, but then see the definition of nxt_thread_get_tid() (it has > several difinitions, one for each system, but I'll copy here one that is > pretty big (NXT_AIX)): > > [...] > > > We're inlining a *huge* function in some cases where we know it's a slow > path.  We could do better by marking the function as inline (without > [[gnu::always_inline]]), and let the compiler decide that it doesn't > want to inline when it's in an `nxt_slow_path()`. > I found the following functions that are being inlined within nxt_slow_path(), which seems wrong: $ find src \ | grep '\.[ch]$' \ | xargs pcregrep -M '(?s)nxt(_always)?_inline[\s\w\*]*\s\*?\w+\(' \ | grep -o '\w\+(' \ | sed 's/(//' \ | while read f; do find src \ | grep '\.[ch]$' \ | xargs pcregrep -Mn '(?s)^(\s+)[^\n]*nxt_slow_path(?:(?!^\1?}).)*?\b'"$f"'\b(?:(?!\1}).)*?^\1}' \ | sed -E 's/^[^:]+:[0-9]+:/\n\n&\n/' \ | grep -o "\b$f\b"; # You can filter with the following instead of `grep -o ...` # to view the code (remember to remove |sort|uniq): # | perl -pe 's/('"$f"')/\033[32m\1\033[0m/'; done \ | sort \ | uniq; nxt_array_init nxt_array_remove_last nxt_buf_cpystr nxt_buf_dummy_completion nxt_cpymem nxt_fastcgi_param_length nxt_h1p_request_error nxt_http_date nxt_mp_chunk_pages_index nxt_next_highest_power_of_two nxt_perl_psgi_add_sptr nxt_perl_psgi_add_str nxt_perl_psgi_add_value nxt_perl_psgi_cb_request_done nxt_pivot_root nxt_port_close_fds nxt_port_mmap_chunk_id nxt_port_mmap_chunk_start nxt_port_mmap_set_chunk_free nxt_port_rpc_lhq_peer nxt_port_socket_write nxt_thread_event_engine nxt_thread_get_tid nxt_unit_close nxt_unit_mmap_buf_insert nxt_unit_process_release These functions should not be forced to be inline (except oneliners). Cheers, Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 2 15:25:07 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 17:25:07 +0200 Subject: inline In-Reply-To: <504bdb4c-c50f-a469-37c9-0c44019e05de@gmail.com> References: <504bdb4c-c50f-a469-37c9-0c44019e05de@gmail.com> Message-ID: On 6/2/22 17:12, Alejandro Colomar wrote: > find src \ >   | grep '\.[ch]$' \ >   | xargs pcregrep -M '(?s)nxt(_always)?_inline[\s\w\*]*\s\*?\w+\(' \ >   | grep -o '\w\+(' \ >   | sed 's/(//' \ >   | while read f; do >     find src \ >     | grep '\.[ch]$' \ >     | xargs pcregrep -Mn > '(?s)^(\s+)[^\n]*nxt_slow_path(?:(?!^\1?}).)*?\b'"$f"'\b(?:(?!\1}).)*?^\1}' > \ >     | sed -E 's/^[^:]+:[0-9]+:/\n\n&\n/' \ >     | grep -o "\b$f\b"; >     # You can filter with the following instead of `grep -o ...` >     # to view the code (remember to remove |sort|uniq): >     # | perl -pe 's/('"$f"')/\033[32m\1\033[0m/'; >   done \ >   | sort \ >   | uniq; There were a few typos in that regex. The list is slightly smaller, but still too big: $ find src \ | grep '\.[ch]$' \ | xargs pcregrep -M '(?s)nxt(_always)?_inline[\s\w\*]*\s\*?\w+\(' \ | grep -o '\w\+(' \ | sed 's/(//' \ | while read f; do find src \ | grep '\.[ch]$' \ | xargs pcregrep -Mn '(?s)^( +)[^\s][^\n]*nxt_slow_path(?:(?!^\1?}).)*?\b'"$f"'\b(?:(?!\1}).)*?^\1}' \ | sed -E 's/^[^:]+:[0-9]+:/\n\n&\n/' \ | grep -o "\b$f\b"; # You can filter with the following instead of `grep -o ...` # to view the code (remember to remove |sort|uniq): # | perl -pe 's/('"$f"')/\033[32m\1\033[0m/'; done \ | sort \ | uniq; nxt_array_remove_last nxt_cpymem nxt_h1p_request_error nxt_perl_psgi_add_sptr nxt_perl_psgi_add_str nxt_perl_psgi_add_value nxt_perl_psgi_cb_request_done nxt_pivot_root nxt_port_close_fds nxt_port_socket_write nxt_thread_get_tid nxt_unit_close nxt_unit_process_release -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 2 18:04:54 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:04:54 +0200 Subject: [PATCH 00/18] Improve use of 'inline' In-Reply-To: References: Message-ID: <20220602180512.56110-1-alx.manpages@gmail.com> Hi! As I explained the previous emails, I was concerned about the use of inline in Unit. This patch set attempts to fix that (and a few other related minor issues that make sense together in this patch set). Performance should be kept the same, or even improved in some cases, but that's just a guess, and no performance tests have been done. The only tests I've run are the normal pytests to check I didn't break anything. Cheers! Alex Alejandro Colomar (18): Put function attributes where C2x specifies. Added nxt_always_inline attribute. Replaced nxt_inline in .c files by static inline. Removed superfluous 'static' keyword from always_inline functions. Added auto/cflags, with a test for -fno-gnu89-inline. Requiring C99 inline. Replaced nxt_inline in .h files by inline. Removed nxt_always_inline from nxt_array_remove_last(). Removed nxt_always_inline from nxt_h1p_request_error(). Removed nxt_always_inline from nxt_perl_psgi_cb_request_done(). Removed nxt_always_inline from nxt_port_close_fds(). Removed nxt_always_inline from (NXT_AIX) nxt_thread_get_tid(). Removed nxt_always_inline from nxt_unit_close(). Removed nxt_always_inline from nxt_unit_process_release(). Fixed static and static inline in a header to be C99 inline. Fixed static and static inline in a header to be C99 inline. Added const to a constant variable. Added extern version of C99 inline function. auto/cflags | 23 +++++++++++ auto/clang | 26 +++++++++++- auto/sources | 3 ++ configure | 1 + src/nxt_app_nncq.c | 29 +++++++++++++ src/nxt_app_nncq.h | 24 +++++------ src/nxt_app_queue.h | 15 ++++--- src/nxt_application.c | 3 +- src/nxt_array.c | 3 ++ src/nxt_array.h | 5 ++- src/nxt_atomic.h | 9 ++-- src/nxt_buf.c | 3 ++ src/nxt_buf.h | 12 ++++-- src/nxt_buf_filter.c | 4 +- src/nxt_cache.c | 6 ++- src/nxt_clang.h | 5 ++- src/nxt_conf.c | 3 +- src/nxt_conf_validation.c | 8 ++-- src/nxt_event_engine.h | 3 +- src/nxt_external.c | 3 +- src/nxt_fastcgi_source.c | 3 +- src/nxt_h1proto.c | 4 +- src/nxt_hash.h | 9 ++-- src/nxt_http.h | 12 +++--- src/nxt_http_parse.c | 3 +- src/nxt_http_parse.h | 3 +- src/nxt_http_source.c | 3 +- src/nxt_isolation.c | 5 ++- src/nxt_list.h | 6 ++- src/nxt_malloc.h | 12 ++---- src/nxt_mem_zone.c | 3 +- src/nxt_mem_zone.h | 9 ++-- src/nxt_mp.c | 9 ++-- src/nxt_mp.h | 28 +++++-------- src/nxt_nncq.c | 23 +++++++++++ src/nxt_nncq.h | 24 +++++------ src/nxt_openssl.c | 3 +- src/nxt_php_sapi.c | 16 ++++---- src/nxt_port.c | 3 +- src/nxt_port.h | 6 ++- src/nxt_port_hash.c | 3 +- src/nxt_port_memory.c | 3 +- src/nxt_port_memory_int.h | 30 +++++++++----- src/nxt_port_queue.h | 9 ++-- src/nxt_port_rpc.c | 6 ++- src/nxt_port_socket.c | 9 ++-- src/nxt_random.c | 8 ++-- src/nxt_rbtree.c | 14 ++++--- src/nxt_rbtree.h | 6 ++- src/nxt_router.c | 21 ++++++---- src/nxt_runtime.c | 3 +- src/nxt_sockaddr.h | 19 ++++----- src/nxt_socket_msg.h | 9 ++-- src/nxt_string.h | 3 +- src/nxt_thread_id.c | 5 +++ src/nxt_thread_id.h | 23 +++++++---- src/nxt_thread_log.h | 3 +- src/nxt_timer.h | 3 +- src/nxt_unit.c | 77 +++++++++++++++++++---------------- src/nxt_unit.h | 8 ++-- src/nxt_utf8.h | 3 +- src/nxt_var.h | 3 +- src/nxt_vector.h | 3 +- src/nxt_websocket.c | 12 ++++-- src/nxt_work_queue.c | 3 +- src/perl/nxt_perl_psgi.c | 23 ++++++----- src/ruby/nxt_ruby.c | 6 +-- src/ruby/nxt_ruby_stream_io.c | 5 ++- src/test/nxt_rbtree1.c | 14 ++++--- src/test/nxt_rbtree1.h | 3 +- src/test/nxt_rbtree1_test.c | 6 ++- src/test/nxt_tests.h | 3 +- 72 files changed, 463 insertions(+), 255 deletions(-) create mode 100644 auto/cflags create mode 100644 src/nxt_app_nncq.c create mode 100644 src/nxt_nncq.c create mode 100644 src/nxt_thread_id.c -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:04:55 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:04:55 +0200 Subject: [PATCH 01/18] Put function attributes where C2x specifies. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-2-alx.manpages@gmail.com> GCC is very generous in where attributes can be placed. C2x, the first ISO C standard that standardizes attributes, in order to be less ambiguous, decided to only allow attributes to be placed in very specific places. Function attributes go at the very beginning of a function prototype (it also allows them to go after the function identifier and just before the parameter list's opening parenthesis, but that was a bad decission that I expect to be dropped before the standard is released, and anyway I don't like it for many reasons, including that it breaks the ability to grep for functions using a regex). See the following test that helps understand this: $ cat inline.c [[gnu::always_inline]] static inline void a(void); static [[gnu::always_inline]] inline void b(void); static inline [[gnu::always_inline]] void c(void); static inline void [[gnu::always_inline]] d(void); static inline void e [[gnu::always_inline]] (void); static inline void f(void)[[gnu::always_inline]]; static inline void g(void); static inline void a(void) { return; } static inline void b(void) { return; } static inline void c(void) { return; } static inline void d(void) { return; } static inline void e(void) { return; } static inline void f(void) { return; } static inline void g(void) { return; } $ clang -Wall -Wextra -Werror -std=c2x inline.c -c inline.c:2:8: error: an attribute list cannot appear here static [[gnu::always_inline]] inline void b(void); ^~~~~~~~~~~~~~~~~~~~~~ inline.c:3:15: error: an attribute list cannot appear here static inline [[gnu::always_inline]] void c(void); ^~~~~~~~~~~~~~~~~~~~~~ inline.c:4:22: error: 'always_inline' attribute cannot be applied to types static inline void [[gnu::always_inline]] d(void); ^ inline.c:6:29: error: attribute 'always_inline' ignored, because it cannot be applied to a type [-Werror,-Wignored-attributes] static inline void f(void)[[gnu::always_inline]]; ^ 4 errors generated. $ cc -Wall -Wextra -Werror -std=c2x inline.c -c inline.c:2:1: error: ‘always_inline’ attribute does not apply to types [-Werror=attributes] 2 | static [[gnu::always_inline]] inline void b(void); | ^~~~~~ inline.c:2:31: error: expected identifier or ‘(’ before ‘inline’ 2 | static [[gnu::always_inline]] inline void b(void); | ^~~~~~ inline.c:3:1: error: ‘always_inline’ attribute does not apply to types [-Werror=attributes] 3 | static inline [[gnu::always_inline]] void c(void); | ^~~~~~ inline.c:3:38: error: expected identifier or ‘(’ before ‘void’ 3 | static inline [[gnu::always_inline]] void c(void); | ^~~~ inline.c:4:1: error: ‘always_inline’ attribute does not apply to types [-Werror=attributes] 4 | static inline void [[gnu::always_inline]] d(void); | ^~~~~~ inline.c:6:1: error: ‘always_inline’ attribute does not apply to types [-Werror=attributes] 6 | static inline void f(void)[[gnu::always_inline]]; | ^~~~~~ cc1: all warnings being treated as errors --- auto/clang | 4 ++-- src/nxt_clang.h | 2 +- src/nxt_conf_validation.c | 5 ++--- src/nxt_malloc.h | 12 ++++-------- src/nxt_mem_zone.h | 9 ++++----- src/nxt_mp.h | 28 +++++++++++----------------- src/nxt_sockaddr.h | 19 ++++++++----------- src/nxt_unit.h | 8 ++++---- 8 files changed, 36 insertions(+), 51 deletions(-) diff --git a/auto/clang b/auto/clang index 1a05b5a..3ea5f65 100644 --- a/auto/clang +++ b/auto/clang @@ -147,7 +147,7 @@ nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include - void *f(void) __attribute__ ((__malloc__)); + __attribute__ ((__malloc__)) void *f(void); void *f(void) { return malloc(1); @@ -183,7 +183,7 @@ nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_UNUSED nxt_feature_run= nxt_feature_incs= nxt_feature_libs= -nxt_feature_test="static void f(void) __attribute__ ((__unused__)); +nxt_feature_test="__attribute__ ((__unused__)) static void f(void); static void f(void) { diff --git a/src/nxt_clang.h b/src/nxt_clang.h index 9463834..eff3cd5 100644 --- a/src/nxt_clang.h +++ b/src/nxt_clang.h @@ -8,7 +8,7 @@ #define _NXT_CLANG_H_INCLUDED_ -#define nxt_inline static inline __attribute__((always_inline)) +#define nxt_inline __attribute__((always_inline)) static inline #define nxt_noinline __attribute__((noinline)) #define nxt_cdecl diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index ee7ebe4..60b9610 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -76,9 +76,8 @@ static nxt_int_t nxt_conf_vldt_error(nxt_conf_validation_t *vldt, const char *fmt, ...); static nxt_int_t nxt_conf_vldt_var(nxt_conf_validation_t *vldt, nxt_str_t *name, nxt_str_t *value); -nxt_inline nxt_int_t nxt_conf_vldt_unsupported(nxt_conf_validation_t *vldt, - nxt_conf_value_t *value, void *data) - NXT_MAYBE_UNUSED; +NXT_MAYBE_UNUSED nxt_inline nxt_int_t nxt_conf_vldt_unsupported( + nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); static nxt_int_t nxt_conf_vldt_mtypes(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); diff --git a/src/nxt_malloc.h b/src/nxt_malloc.h index fd5493a..fa5a7b7 100644 --- a/src/nxt_malloc.h +++ b/src/nxt_malloc.h @@ -8,14 +8,10 @@ #define _NXT_UNIX_MALLOC_H_INCLUDED_ -NXT_EXPORT void *nxt_malloc(size_t size) - NXT_MALLOC_LIKE; -NXT_EXPORT void *nxt_zalloc(size_t size) - NXT_MALLOC_LIKE; -NXT_EXPORT void *nxt_realloc(void *p, size_t size) - NXT_MALLOC_LIKE; -NXT_EXPORT void *nxt_memalign(size_t alignment, size_t size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_malloc(size_t size); +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_zalloc(size_t size); +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_realloc(void *p, size_t size); +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_memalign(size_t alignment, size_t size); #if (NXT_DEBUG) diff --git a/src/nxt_mem_zone.h b/src/nxt_mem_zone.h index 89d73ca..e15ea42 100644 --- a/src/nxt_mem_zone.h +++ b/src/nxt_mem_zone.h @@ -17,11 +17,10 @@ NXT_EXPORT nxt_mem_zone_t *nxt_mem_zone_init(u_char *start, size_t zone_size, #define nxt_mem_zone_alloc(zone, size) \ nxt_mem_zone_align((zone), 1, (size)) -NXT_EXPORT void *nxt_mem_zone_align(nxt_mem_zone_t *zone, size_t alignment, - size_t size) - NXT_MALLOC_LIKE; -NXT_EXPORT void *nxt_mem_zone_zalloc(nxt_mem_zone_t *zone, size_t size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_mem_zone_align(nxt_mem_zone_t *zone, + size_t alignment, size_t size); +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_mem_zone_zalloc(nxt_mem_zone_t *zone, + size_t size); NXT_EXPORT void nxt_mem_zone_free(nxt_mem_zone_t *zone, void *p); diff --git a/src/nxt_mp.h b/src/nxt_mp.h index a5aaabd..a38d3df 100644 --- a/src/nxt_mp.h +++ b/src/nxt_mp.h @@ -31,9 +31,8 @@ typedef struct nxt_mp_s nxt_mp_t; * nxt_mp_create() creates a memory pool and sets the pool's retention * counter to 1. */ -NXT_EXPORT nxt_mp_t *nxt_mp_create(size_t cluster_size, size_t page_alignment, - size_t page_size, size_t min_chunk_size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE nxt_mp_t *nxt_mp_create(size_t cluster_size, + size_t page_alignment, size_t page_size, size_t min_chunk_size); /* * nxt_mp_destroy() destroys memory pool in spite of the pool's retention @@ -64,46 +63,41 @@ NXT_EXPORT nxt_bool_t nxt_mp_is_empty(nxt_mp_t *mp); * nxt_mp_alloc() returns aligned freeable memory. * The alignment is sutiable to allocate structures. */ -NXT_EXPORT void *nxt_mp_alloc(nxt_mp_t *mp, size_t size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_mp_alloc(nxt_mp_t *mp, size_t size); /* * nxt_mp_zalloc() returns zeroed aligned freeable memory. * The alignment is sutiable to allocate structures. */ -NXT_EXPORT void *nxt_mp_zalloc(nxt_mp_t *mp, size_t size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_mp_zalloc(nxt_mp_t *mp, size_t size); /* nxt_mp_align() returns aligned freeable memory. */ -NXT_EXPORT void *nxt_mp_align(nxt_mp_t *mp, size_t alignment, size_t size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_mp_align(nxt_mp_t *mp, size_t alignment, + size_t size); /* nxt_mp_zalign() returns zeroed aligned freeable memory. */ -NXT_EXPORT void *nxt_mp_zalign(nxt_mp_t *mp, size_t alignment, size_t size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_mp_zalign(nxt_mp_t *mp, size_t alignment, + size_t size); /* nxt_mp_free() frees freeable memory. */ NXT_EXPORT void nxt_mp_free(nxt_mp_t *mp, void *p); /* nxt_mp_nget() returns non-aligned non-freeable memory. */ -NXT_EXPORT void *nxt_mp_nget(nxt_mp_t *mp, size_t size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_mp_nget(nxt_mp_t *mp, size_t size); /* * nxt_mp_get() returns aligned non-freeable memory. * The alignment is sutiable to allocate structures. */ -NXT_EXPORT void *nxt_mp_get(nxt_mp_t *mp, size_t size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_mp_get(nxt_mp_t *mp, size_t size); /* * nxt_mp_zget() returns zeroed aligned non-freeable memory. * The alignment is sutiable to allocate structures. */ -NXT_EXPORT void *nxt_mp_zget(nxt_mp_t *mp, size_t size) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE void *nxt_mp_zget(nxt_mp_t *mp, size_t size); NXT_EXPORT nxt_int_t nxt_mp_cleanup(nxt_mp_t *mp, nxt_work_handler_t handler, diff --git a/src/nxt_sockaddr.h b/src/nxt_sockaddr.h index a8f1b39..4da193b 100644 --- a/src/nxt_sockaddr.h +++ b/src/nxt_sockaddr.h @@ -71,17 +71,14 @@ nxt_sockaddr_t *nxt_sockaddr_cache_alloc(nxt_event_engine_t *engine, nxt_listen_socket_t *ls); void nxt_sockaddr_cache_free(nxt_event_engine_t *engine, nxt_conn_t *c); -NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_alloc(nxt_mp_t *mp, socklen_t socklen, - size_t address_length) - NXT_MALLOC_LIKE; -NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_create(nxt_mp_t *mp, - struct sockaddr *sockaddr, socklen_t socklen, size_t address_length) - NXT_MALLOC_LIKE; -NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_copy(nxt_mp_t *mp, nxt_sockaddr_t *src) - NXT_MALLOC_LIKE; -NXT_EXPORT nxt_sockaddr_t *nxt_getsockname(nxt_task_t *task, nxt_mp_t *mp, - nxt_socket_t s) - NXT_MALLOC_LIKE; +NXT_EXPORT NXT_MALLOC_LIKE nxt_sockaddr_t *nxt_sockaddr_alloc(nxt_mp_t *mp, + socklen_t socklen, size_t address_length); +NXT_EXPORT NXT_MALLOC_LIKE nxt_sockaddr_t *nxt_sockaddr_create(nxt_mp_t *mp, + struct sockaddr *sockaddr, socklen_t socklen, size_t address_length); +NXT_EXPORT NXT_MALLOC_LIKE nxt_sockaddr_t *nxt_sockaddr_copy(nxt_mp_t *mp, + nxt_sockaddr_t *src); +NXT_EXPORT NXT_MALLOC_LIKE nxt_sockaddr_t *nxt_getsockname(nxt_task_t *task, + nxt_mp_t *mp, nxt_socket_t s); NXT_EXPORT void nxt_sockaddr_text(nxt_sockaddr_t *sa); diff --git a/src/nxt_unit.h b/src/nxt_unit.h index 35f9fa5..4826d66 100644 --- a/src/nxt_unit.h +++ b/src/nxt_unit.h @@ -355,11 +355,11 @@ void nxt_unit_free(nxt_unit_ctx_t *ctx, void *p); #endif -void nxt_unit_log(nxt_unit_ctx_t *ctx, int level, const char* fmt, ...) - NXT_ATTR_FORMAT; +NXT_ATTR_FORMAT void nxt_unit_log(nxt_unit_ctx_t *ctx, int level, + const char* fmt, ...); -void nxt_unit_req_log(nxt_unit_request_info_t *req, int level, - const char* fmt, ...) NXT_ATTR_FORMAT; +NXT_ATTR_FORMAT void nxt_unit_req_log(nxt_unit_request_info_t *req, int level, + const char* fmt, ...); #if (NXT_DEBUG) -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:04:56 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:04:56 +0200 Subject: [PATCH 02/18] Added nxt_always_inline attribute. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-3-alx.manpages@gmail.com> Wrap __attribute__((always_inline)) in our own macro, to be able to use it selectively in function declarations. --- src/nxt_clang.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nxt_clang.h b/src/nxt_clang.h index eff3cd5..b8fa08a 100644 --- a/src/nxt_clang.h +++ b/src/nxt_clang.h @@ -8,8 +8,9 @@ #define _NXT_CLANG_H_INCLUDED_ -#define nxt_inline __attribute__((always_inline)) static inline -#define nxt_noinline __attribute__((noinline)) +#define nxt_always_inline __attribute__((__always_inline__)) +#define nxt_inline nxt_always_inline static inline +#define nxt_noinline __attribute__((noinline)) #define nxt_cdecl -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:04:58 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:04:58 +0200 Subject: [PATCH 04/18] Removed superfluous 'static' keyword from always_inline functions. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-5-alx.manpages@gmail.com> 'static' is completely redundant with '__attribute__((__always_inline__))'. Also, it's unnatural (and wrong) to have 'static' functions that aren't local to a translation unit. It is wrong because either it means nothing (when paired with always_inline) or it produces code bloat (when it's not paired with always_inline). --- src/nxt_clang.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nxt_clang.h b/src/nxt_clang.h index b8fa08a..c0513f0 100644 --- a/src/nxt_clang.h +++ b/src/nxt_clang.h @@ -9,7 +9,7 @@ #define nxt_always_inline __attribute__((__always_inline__)) -#define nxt_inline nxt_always_inline static inline +#define nxt_inline nxt_always_inline inline #define nxt_noinline __attribute__((noinline)) #define nxt_cdecl -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:04:59 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:04:59 +0200 Subject: [PATCH 05/18] Added auto/cflags, with a test for -fno-gnu89-inline. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-6-alx.manpages@gmail.com> Add -fno-gnu89-inline, to make sure we don't use the broken GNU inline. The default is C99 inline nowadays, which is the desired one, but this flags helps make sure we don't use it accidentally. See also: --- auto/cflags | 23 +++++++++++++++++++++++ configure | 1 + 2 files changed, 24 insertions(+) create mode 100644 auto/cflags diff --git a/auto/cflags b/auto/cflags new file mode 100644 index 00000000..b192ba4 --- /dev/null +++ b/auto/cflags @@ -0,0 +1,23 @@ + + +# C compiler flags + + +nxt_feature='-fno-gnu89-inline' +nxt_feature_name= +nxt_feature_run= +nxt_feature_incs='-fno-gnu89-inline' +nxt_feature_libs= +nxt_feature_test='inline void f(void) { + return; + } + + int main(void) { + f(); + }' + +. auto/feature + +if [ $nxt_found = yes ]; then + NXT_CFLAGS="$NXT_CFLAGS -fno-gnu89-inline" +fi diff --git a/configure b/configure index bc21e57..4a12a6f 100755 --- a/configure +++ b/configure @@ -114,6 +114,7 @@ fi NXT_LIBRT= +. auto/cflags . auto/types . auto/clang . auto/atomic -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:01 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:01 +0200 Subject: [PATCH 07/18] Replaced nxt_inline in .h files by inline. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-8-alx.manpages@gmail.com> Keep the nxt_always_inline to avoid changing behavior. I put the attributes in a line preceeding the return type of the function, since it seems to me a bit more readable. --- src/nxt_app_queue.h | 15 ++++++++++----- src/nxt_array.h | 6 ++++-- src/nxt_atomic.h | 9 ++++++--- src/nxt_buf.h | 12 ++++++++---- src/nxt_event_engine.h | 3 ++- src/nxt_hash.h | 9 ++++++--- src/nxt_http.h | 3 ++- src/nxt_http_parse.h | 3 ++- src/nxt_list.h | 6 ++++-- src/nxt_port.h | 6 ++++-- src/nxt_port_memory_int.h | 30 ++++++++++++++++++++---------- src/nxt_port_queue.h | 9 ++++++--- src/nxt_rbtree.h | 6 ++++-- src/nxt_socket_msg.h | 9 ++++++--- src/nxt_string.h | 3 ++- src/nxt_thread_id.h | 24 ++++++++++++++++-------- src/nxt_thread_log.h | 3 ++- src/nxt_timer.h | 3 ++- src/nxt_utf8.h | 3 ++- src/nxt_var.h | 3 ++- src/nxt_vector.h | 3 ++- src/test/nxt_rbtree1.h | 3 ++- src/test/nxt_tests.h | 3 ++- 23 files changed, 116 insertions(+), 58 deletions(-) diff --git a/src/nxt_app_queue.h b/src/nxt_app_queue.h index a1cc2f1..22aa1a1 100644 --- a/src/nxt_app_queue.h +++ b/src/nxt_app_queue.h @@ -30,7 +30,8 @@ typedef struct { } nxt_app_queue_t; -nxt_inline void +nxt_always_inline +inline void nxt_app_queue_init(nxt_app_queue_t volatile *q) { nxt_app_nncq_atomic_t i; @@ -46,7 +47,8 @@ nxt_app_queue_init(nxt_app_queue_t volatile *q) } -nxt_inline nxt_int_t +nxt_always_inline +inline nxt_int_t nxt_app_queue_send(nxt_app_queue_t volatile *q, const void *p, uint8_t size, uint32_t tracking, int *notify, uint32_t *cookie) { @@ -78,14 +80,16 @@ nxt_app_queue_send(nxt_app_queue_t volatile *q, const void *p, } -nxt_inline void +nxt_always_inline +inline void nxt_app_queue_notification_received(nxt_app_queue_t volatile *q) { q->notified = 0; } -nxt_inline nxt_bool_t +nxt_always_inline +inline nxt_bool_t nxt_app_queue_cancel(nxt_app_queue_t volatile *q, uint32_t cookie, uint32_t tracking) { @@ -97,7 +101,8 @@ nxt_app_queue_cancel(nxt_app_queue_t volatile *q, uint32_t cookie, } -nxt_inline ssize_t +nxt_always_inline +inline ssize_t nxt_app_queue_recv(nxt_app_queue_t volatile *q, void *p, uint32_t *cookie) { ssize_t res; diff --git a/src/nxt_array.h b/src/nxt_array.h index f06ff14..548548f 100644 --- a/src/nxt_array.h +++ b/src/nxt_array.h @@ -18,7 +18,8 @@ typedef struct { } nxt_array_t; -nxt_inline void +nxt_always_inline +inline void nxt_array_init(nxt_array_t *array, nxt_mp_t *mp, size_t size) { array->elts = nxt_pointer_to(array, sizeof(nxt_array_t)); @@ -47,7 +48,8 @@ NXT_EXPORT nxt_array_t *nxt_array_copy(nxt_mp_t *mp, nxt_array_t *dst, ((array)->nelts == 0) -nxt_inline void * +nxt_always_inline +inline void * nxt_array_remove_last(nxt_array_t *array) { array->nelts--; diff --git a/src/nxt_atomic.h b/src/nxt_atomic.h index cd2e725..7d13aad 100644 --- a/src/nxt_atomic.h +++ b/src/nxt_atomic.h @@ -166,7 +166,8 @@ typedef unsigned long nxt_atomic_uint_t; typedef volatile nxt_atomic_int_t nxt_atomic_t; -nxt_inline nxt_bool_t +nxt_always_inline +inline nxt_bool_t nxt_atomic_cmp_set(nxt_atomic_t *lock, nxt_atomic_int_t cmp, nxt_atomic_int_t set) { @@ -193,7 +194,8 @@ typedef unsigned int nxt_atomic_uint_t; typedef volatile nxt_atomic_int_t nxt_atomic_t; -nxt_inline nxt_bool_t +nxt_always_inline +inline nxt_bool_t nxt_atomic_cmp_set(nxt_atomic_t *lock, nxt_atomic_int_t cmp, nxt_atomic_int_t set) { @@ -240,7 +242,8 @@ nxt_atomic_cmp_set(nxt_atomic_t *lock, nxt_atomic_int_t cmp, * the lock is granted. */ -nxt_inline nxt_bool_t +nxt_always_inline +inline nxt_bool_t nxt_atomic_try_lock(nxt_atomic_t *lock) { if (nxt_atomic_cmp_set(lock, 0, 1)) { diff --git a/src/nxt_buf.h b/src/nxt_buf.h index f1e2879..65769d9 100644 --- a/src/nxt_buf.h +++ b/src/nxt_buf.h @@ -227,7 +227,8 @@ NXT_EXPORT void nxt_buf_parent_completion(nxt_task_t *task, nxt_buf_t *parent); NXT_EXPORT nxt_buf_t *nxt_buf_make_plain(nxt_mp_t *mp, nxt_buf_t *src, size_t size); -nxt_inline nxt_buf_t * +nxt_always_inline +inline nxt_buf_t * nxt_buf_chk_make_plain(nxt_mp_t *mp, nxt_buf_t *src, size_t size) { if (nxt_slow_path(src != NULL && src->next != NULL)) { @@ -244,7 +245,8 @@ nxt_buf_chk_make_plain(nxt_mp_t *mp, nxt_buf_t *src, size_t size) NXT_EXPORT void nxt_buf_chain_add(nxt_buf_t **head, nxt_buf_t *in); NXT_EXPORT size_t nxt_buf_chain_length(nxt_buf_t *b); -nxt_inline nxt_buf_t * +nxt_always_inline +inline nxt_buf_t * nxt_buf_cpy(nxt_buf_t *b, const void *src, size_t length) { nxt_memcpy(b->mem.free, src, length); @@ -253,14 +255,16 @@ nxt_buf_cpy(nxt_buf_t *b, const void *src, size_t length) return b; } -nxt_inline nxt_buf_t * +nxt_always_inline +inline nxt_buf_t * nxt_buf_cpystr(nxt_buf_t *b, const nxt_str_t *str) { return nxt_buf_cpy(b, str->start, str->length); } -nxt_inline void +nxt_always_inline +inline void nxt_buf_dummy_completion(nxt_task_t *task, void *obj, void *data) { } diff --git a/src/nxt_event_engine.h b/src/nxt_event_engine.h index 91cfc0a..1a55ae1 100644 --- a/src/nxt_event_engine.h +++ b/src/nxt_event_engine.h @@ -514,7 +514,8 @@ void nxt_event_engine_buf_mem_completion(nxt_task_t *task, void *obj, void *data); -nxt_inline nxt_event_engine_t * +nxt_always_inline +inline nxt_event_engine_t * nxt_thread_event_engine(void) { nxt_thread_t *thr; diff --git a/src/nxt_hash.h b/src/nxt_hash.h index 01c727d..aea6a5b 100644 --- a/src/nxt_hash.h +++ b/src/nxt_hash.h @@ -15,7 +15,8 @@ typedef struct { } nxt_hash_t; -nxt_inline nxt_int_t +nxt_always_inline +inline nxt_int_t nxt_hash_find(nxt_hash_t *h, nxt_lvlhsh_query_t *lhq) { lhq->proto = h->proto; @@ -24,7 +25,8 @@ nxt_hash_find(nxt_hash_t *h, nxt_lvlhsh_query_t *lhq) } -nxt_inline nxt_int_t +nxt_always_inline +inline nxt_int_t nxt_hash_insert(nxt_hash_t *h, nxt_lvlhsh_query_t *lhq) { lhq->proto = h->proto; @@ -34,7 +36,8 @@ nxt_hash_insert(nxt_hash_t *h, nxt_lvlhsh_query_t *lhq) } -nxt_inline nxt_int_t +nxt_always_inline +inline nxt_int_t nxt_hash_delete(nxt_hash_t *h, nxt_lvlhsh_query_t *lhq) { lhq->proto = h->proto; diff --git a/src/nxt_http.h b/src/nxt_http.h index d299fdd..c916ae5 100644 --- a/src/nxt_http.h +++ b/src/nxt_http.h @@ -276,7 +276,8 @@ struct nxt_http_client_ip_s { #define NXT_HTTP_DATE_LEN nxt_length("Wed, 31 Dec 1986 16:40:00 GMT") -nxt_inline u_char * +nxt_always_inline +inline u_char * nxt_http_date(u_char *buf, struct tm *tm) { static const char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", diff --git a/src/nxt_http_parse.h b/src/nxt_http_parse.h index 3cd9bd1..4a2894d 100644 --- a/src/nxt_http_parse.h +++ b/src/nxt_http_parse.h @@ -132,7 +132,8 @@ nxt_buf_t *nxt_http_chunk_parse(nxt_task_t *task, nxt_http_chunk_parse_t *hcp, extern const nxt_lvlhsh_proto_t nxt_http_fields_hash_proto; -nxt_inline nxt_int_t +nxt_always_inline +inline nxt_int_t nxt_http_field_process(nxt_http_field_t *field, nxt_lvlhsh_t *hash, void *ctx) { nxt_lvlhsh_query_t lhq; diff --git a/src/nxt_list.h b/src/nxt_list.h index dc948e0..32f8e49 100644 --- a/src/nxt_list.h +++ b/src/nxt_list.h @@ -49,7 +49,8 @@ typedef struct { nxt_list_data(nxt_list_part(list)) -nxt_inline void * +nxt_always_inline +inline void * nxt_list_elt(nxt_list_t *list, nxt_uint_t n) { nxt_list_part_t *part; @@ -103,7 +104,8 @@ NXT_EXPORT void *nxt_list_next(nxt_list_t *list, nxt_list_next_t *next); (nxt_pointer_to(nxt_list_data((next)->part), (next)->elt * (list)->size)) -nxt_inline nxt_uint_t +nxt_always_inline +inline nxt_uint_t nxt_list_nelts(nxt_list_t *list) { nxt_uint_t n; diff --git a/src/nxt_port.h b/src/nxt_port.h index 3b66edf..6ee8db7 100644 --- a/src/nxt_port.h +++ b/src/nxt_port.h @@ -327,7 +327,8 @@ nxt_int_t nxt_port_socket_write2(nxt_task_t *task, nxt_port_t *port, nxt_uint_t type, nxt_fd_t fd, nxt_fd_t fd2, uint32_t stream, nxt_port_id_t reply_port, nxt_buf_t *b); -nxt_inline nxt_int_t +nxt_always_inline +inline nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port, nxt_buf_t *b) @@ -358,7 +359,8 @@ nxt_int_t nxt_port_post(nxt_task_t *task, nxt_port_t *port, nxt_port_post_handler_t handler, void *data); void nxt_port_use(nxt_task_t *task, nxt_port_t *port, int i); -nxt_inline void nxt_port_inc_use(nxt_port_t *port) +nxt_always_inline +inline void nxt_port_inc_use(nxt_port_t *port) { nxt_atomic_fetch_add(&port->use_count, 1); } diff --git a/src/nxt_port_memory_int.h b/src/nxt_port_memory_int.h index d2524ee..c9ba0a7 100644 --- a/src/nxt_port_memory_int.h +++ b/src/nxt_port_memory_int.h @@ -91,22 +91,27 @@ struct nxt_port_mmap_tracking_msg_s { nxt_chunk_id_t tracking_id; /* Tracking index. */ }; -nxt_inline nxt_bool_t +nxt_always_inline +inline nxt_bool_t nxt_port_mmap_get_free_chunk(nxt_free_map_t *m, nxt_chunk_id_t *c); #define nxt_port_mmap_get_chunk_busy(m, c) \ ((m[FREE_IDX(c)] & FREE_MASK(c)) == 0) -nxt_inline void +nxt_always_inline +inline void nxt_port_mmap_set_chunk_busy(nxt_free_map_t *m, nxt_chunk_id_t c); -nxt_inline nxt_bool_t +nxt_always_inline +inline nxt_bool_t nxt_port_mmap_chk_set_chunk_busy(nxt_free_map_t *m, nxt_chunk_id_t c); -nxt_inline void +nxt_always_inline +inline void nxt_port_mmap_set_chunk_free(nxt_free_map_t *m, nxt_chunk_id_t c); -nxt_inline nxt_chunk_id_t +nxt_always_inline +inline nxt_chunk_id_t nxt_port_mmap_chunk_id(nxt_port_mmap_header_t *hdr, u_char *p) { u_char *mm_start; @@ -117,7 +122,8 @@ nxt_port_mmap_chunk_id(nxt_port_mmap_header_t *hdr, u_char *p) } -nxt_inline u_char * +nxt_always_inline +inline u_char * nxt_port_mmap_chunk_start(nxt_port_mmap_header_t *hdr, nxt_chunk_id_t c) { u_char *mm_start; @@ -128,7 +134,8 @@ nxt_port_mmap_chunk_start(nxt_port_mmap_header_t *hdr, nxt_chunk_id_t c) } -nxt_inline nxt_bool_t +nxt_always_inline +inline nxt_bool_t nxt_port_mmap_get_free_chunk(nxt_free_map_t *m, nxt_chunk_id_t *c) { const nxt_free_map_t default_mask = (nxt_free_map_t) -1; @@ -164,14 +171,16 @@ nxt_port_mmap_get_free_chunk(nxt_free_map_t *m, nxt_chunk_id_t *c) } -nxt_inline void +nxt_always_inline +inline void nxt_port_mmap_set_chunk_busy(nxt_free_map_t *m, nxt_chunk_id_t c) { nxt_atomic_and_fetch(m + FREE_IDX(c), ~FREE_MASK(c)); } -nxt_inline nxt_bool_t +nxt_always_inline +inline nxt_bool_t nxt_port_mmap_chk_set_chunk_busy(nxt_free_map_t *m, nxt_chunk_id_t c) { nxt_free_map_t *f; @@ -193,7 +202,8 @@ nxt_port_mmap_chk_set_chunk_busy(nxt_free_map_t *m, nxt_chunk_id_t c) } -nxt_inline void +nxt_always_inline +inline void nxt_port_mmap_set_chunk_free(nxt_free_map_t *m, nxt_chunk_id_t c) { nxt_atomic_or_fetch(m + FREE_IDX(c), FREE_MASK(c)); diff --git a/src/nxt_port_queue.h b/src/nxt_port_queue.h index d2b2326..2ff7a3f 100644 --- a/src/nxt_port_queue.h +++ b/src/nxt_port_queue.h @@ -30,7 +30,8 @@ typedef struct { } nxt_port_queue_t; -nxt_inline void +nxt_always_inline +inline void nxt_port_queue_init(nxt_port_queue_t volatile *q) { nxt_nncq_atomic_t i; @@ -46,7 +47,8 @@ nxt_port_queue_init(nxt_port_queue_t volatile *q) } -nxt_inline nxt_int_t +nxt_always_inline +inline nxt_int_t nxt_port_queue_send(nxt_port_queue_t volatile *q, const void *p, uint8_t size, int *notify) { @@ -74,7 +76,8 @@ nxt_port_queue_send(nxt_port_queue_t volatile *q, const void *p, uint8_t size, } -nxt_inline ssize_t +nxt_always_inline +inline ssize_t nxt_port_queue_recv(nxt_port_queue_t volatile *q, void *p) { ssize_t res; diff --git a/src/nxt_rbtree.h b/src/nxt_rbtree.h index 4bf479e..54ba12e 100644 --- a/src/nxt_rbtree.h +++ b/src/nxt_rbtree.h @@ -64,7 +64,8 @@ typedef intptr_t (*nxt_rbtree_compare_t)(nxt_rbtree_node_t *node1, nxt_rbtree_branch_min(tree, &(tree)->sentinel) -nxt_inline nxt_rbtree_node_t * +nxt_always_inline +inline nxt_rbtree_node_t * nxt_rbtree_branch_min(nxt_rbtree_t *tree, nxt_rbtree_node_t *node) { while (node->left != nxt_rbtree_sentinel(tree)) { @@ -79,7 +80,8 @@ nxt_rbtree_branch_min(nxt_rbtree_t *tree, nxt_rbtree_node_t *node) ((node) != nxt_rbtree_sentinel(tree)) -nxt_inline nxt_rbtree_node_t * +nxt_always_inline +inline nxt_rbtree_node_t * nxt_rbtree_node_successor(nxt_rbtree_t *tree, nxt_rbtree_node_t *node) { nxt_rbtree_node_t *parent; diff --git a/src/nxt_socket_msg.h b/src/nxt_socket_msg.h index 04de176..2ed208a 100644 --- a/src/nxt_socket_msg.h +++ b/src/nxt_socket_msg.h @@ -69,7 +69,8 @@ NXT_EXPORT ssize_t nxt_recvmsg(nxt_socket_t s, nxt_iobuf_t *iob, nxt_uint_t niob, nxt_recv_oob_t *oob); -nxt_inline void +nxt_always_inline +inline void nxt_socket_msg_oob_init(nxt_send_oob_t *oob, int *fds) { int nfds; @@ -123,7 +124,8 @@ nxt_socket_msg_oob_init(nxt_send_oob_t *oob, int *fds) } -nxt_inline nxt_int_t +nxt_always_inline +inline nxt_int_t nxt_socket_msg_oob_get_fds(nxt_recv_oob_t *oob, nxt_fd_t *fd) { size_t size; @@ -154,7 +156,8 @@ nxt_socket_msg_oob_get_fds(nxt_recv_oob_t *oob, nxt_fd_t *fd) } -nxt_inline nxt_int_t +nxt_always_inline +inline nxt_int_t nxt_socket_msg_oob_get(nxt_recv_oob_t *oob, nxt_fd_t *fd, nxt_pid_t *pid) { size_t size; diff --git a/src/nxt_string.h b/src/nxt_string.h index 80cdbb5..4021dae 100644 --- a/src/nxt_string.h +++ b/src/nxt_string.h @@ -55,7 +55,8 @@ NXT_EXPORT void nxt_memcpy_upcase(u_char *dst, const u_char *src, * nxt_cpymem() is an inline function but not a macro to * eliminate possible double evaluation of length "length". */ -nxt_inline void * +nxt_always_inline +inline void * nxt_cpymem(void *dst, const void *src, size_t length) { return ((u_char *) memcpy(dst, src, length)) + length; diff --git a/src/nxt_thread_id.h b/src/nxt_thread_id.h index 764c993..5f70987 100644 --- a/src/nxt_thread_id.h +++ b/src/nxt_thread_id.h @@ -17,7 +17,8 @@ typedef pid_t nxt_tid_t; -nxt_inline nxt_tid_t +nxt_always_inline +inline nxt_tid_t nxt_thread_get_tid(void) { return syscall(SYS_gettid); @@ -34,7 +35,8 @@ nxt_thread_get_tid(void) typedef uint32_t nxt_tid_t; -nxt_inline nxt_tid_t +nxt_always_inline +inline nxt_tid_t nxt_thread_get_tid(void) { return (uint32_t) (*(long *) pthread_self()); @@ -46,7 +48,8 @@ nxt_thread_get_tid(void) typedef pthread_t nxt_tid_t; -nxt_inline nxt_tid_t +nxt_always_inline +inline nxt_tid_t nxt_thread_get_tid(void) { return pthread_self(); @@ -64,7 +67,8 @@ nxt_thread_get_tid(void) typedef uint64_t nxt_tid_t; -nxt_inline nxt_tid_t +nxt_always_inline +inline nxt_tid_t nxt_thread_get_tid(void) { uint64_t tid; @@ -86,7 +90,8 @@ typedef pid_t nxt_tid_t; /* OpenBSD 3.9 getthrid(). */ -nxt_inline nxt_tid_t +nxt_always_inline +inline nxt_tid_t nxt_thread_get_tid(void) { return getthrid(); @@ -104,7 +109,8 @@ nxt_thread_get_tid(void) typedef tid_t nxt_tid_t; -nxt_inline nxt_tid_t +nxt_always_inline +inline nxt_tid_t nxt_thread_get_tid(void) { int err, size; @@ -146,7 +152,8 @@ nxt_thread_get_tid(void) typedef pthread_t nxt_tid_t; -nxt_inline nxt_tid_t +nxt_always_inline +inline nxt_tid_t nxt_thread_get_tid(void) { return pthread_self(); @@ -156,7 +163,8 @@ nxt_thread_get_tid(void) typedef pthread_t nxt_tid_t; -nxt_inline nxt_tid_t +nxt_always_inline +inline nxt_tid_t nxt_thread_get_tid(void) { return pthread_self(); diff --git a/src/nxt_thread_log.h b/src/nxt_thread_log.h index 214098f..67466af 100644 --- a/src/nxt_thread_log.h +++ b/src/nxt_thread_log.h @@ -48,7 +48,8 @@ #endif -nxt_inline nxt_log_t * +nxt_always_inline +inline nxt_log_t * nxt_thread_log(void) { nxt_thread_t *thr; diff --git a/src/nxt_timer.h b/src/nxt_timer.h index 3ccff84..161825b 100644 --- a/src/nxt_timer.h +++ b/src/nxt_timer.h @@ -101,7 +101,8 @@ NXT_EXPORT void nxt_timer_add(nxt_event_engine_t *engine, nxt_timer_t *timer, NXT_EXPORT nxt_bool_t nxt_timer_delete(nxt_event_engine_t *engine, nxt_timer_t *timer); -nxt_inline void +nxt_always_inline +inline void nxt_timer_disable(nxt_event_engine_t *engine, nxt_timer_t *timer) { nxt_debug(timer->task, "timer disable: %M", timer->time); diff --git a/src/nxt_utf8.h b/src/nxt_utf8.h index 13f42e1..cd5e508 100644 --- a/src/nxt_utf8.h +++ b/src/nxt_utf8.h @@ -28,7 +28,8 @@ NXT_EXPORT nxt_bool_t nxt_utf8_is_valid(const u_char *p, size_t len); /* nxt_utf8_next() expects a valid UTF-8 string. */ -nxt_inline const u_char * +nxt_always_inline +inline const u_char * nxt_utf8_next(const u_char *p, const u_char *end) { u_char c; diff --git a/src/nxt_var.h b/src/nxt_var.h index 3b7d0c2..32fa453 100644 --- a/src/nxt_var.h +++ b/src/nxt_var.h @@ -23,7 +23,8 @@ typedef struct { } nxt_var_decl_t; -nxt_inline nxt_bool_t +nxt_always_inline +inline nxt_bool_t nxt_is_var(nxt_str_t *str) { return (nxt_memchr(str->start, '$', str->length) != NULL); diff --git a/src/nxt_vector.h b/src/nxt_vector.h index dcac53d..281bb45 100644 --- a/src/nxt_vector.h +++ b/src/nxt_vector.h @@ -54,7 +54,8 @@ NXT_EXPORT void nxt_vector_remove(nxt_vector_t *vector, void *item); ((vector)->items == 0) -nxt_inline void * +nxt_always_inline +inline void * nxt_vector_remove_last(nxt_vector_t *vector) { vector->items--; diff --git a/src/test/nxt_rbtree1.h b/src/test/nxt_rbtree1.h index 60048da..b322bf8 100644 --- a/src/test/nxt_rbtree1.h +++ b/src/test/nxt_rbtree1.h @@ -62,7 +62,8 @@ NXT_EXPORT void nxt_rbtree1_insert_timer_value(nxt_rbtree1_node_t *root, #define nxt_rbtree1_sentinel_init(node) nxt_rbtree1_black(node) -nxt_inline nxt_rbtree1_node_t * +nxt_always_inline +inline nxt_rbtree1_node_t * nxt_rbtree1_min(nxt_rbtree1_node_t *node, nxt_rbtree1_node_t *sentinel) { while (node->left != sentinel) { diff --git a/src/test/nxt_tests.h b/src/test/nxt_tests.h index 463dc85..6a59ca9 100644 --- a/src/test/nxt_tests.h +++ b/src/test/nxt_tests.h @@ -19,7 +19,8 @@ typedef nxt_bool_t (*nxt_msec_less_t)(nxt_msec_t first, nxt_msec_t second); #define NXT_TEST_RTDTSC 1 -nxt_inline uint64_t +nxt_always_inline +inline uint64_t nxt_rdtsc(void) { uint32_t eax, edx; -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:05 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:05 +0200 Subject: [PATCH 11/18] Removed nxt_always_inline from nxt_port_close_fds(). In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-12-alx.manpages@gmail.com> We shouldn't be forcing the inline of a function used in error cases (slow path). --- src/nxt_port_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nxt_port_socket.c b/src/nxt_port_socket.c index 30ec449..96988c8 100644 --- a/src/nxt_port_socket.c +++ b/src/nxt_port_socket.c @@ -24,7 +24,7 @@ static void nxt_port_write_handler(nxt_task_t *task, void *obj, void *data); static nxt_port_send_msg_t *nxt_port_msg_first(nxt_port_t *port); nxt_always_inline static inline void nxt_port_msg_close_fd( nxt_port_send_msg_t *msg); -nxt_always_inline static inline void nxt_port_close_fds(nxt_fd_t *fd); +static inline void nxt_port_close_fds(nxt_fd_t *fd); static nxt_buf_t *nxt_port_buf_completion(nxt_task_t *task, nxt_work_queue_t *wq, nxt_buf_t *b, size_t sent, nxt_bool_t mmap_mode); static nxt_port_send_msg_t *nxt_port_msg_insert_tail(nxt_port_t *port, -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:04:57 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:04:57 +0200 Subject: [PATCH 03/18] Replaced nxt_inline in .c files by static inline. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-4-alx.manpages@gmail.com> Keep the nxt_always_inline to avoid changing behavior. But don't repeat it in function definitions when it has already been specified in the corresponding function prototype. I put the attributes in a line preceeding the return type of the function, since it seems to me a bit more readable. --- src/nxt_application.c | 3 +- src/nxt_buf_filter.c | 4 +- src/nxt_cache.c | 6 ++- src/nxt_conf.c | 3 +- src/nxt_conf_validation.c | 7 ++-- src/nxt_external.c | 3 +- src/nxt_fastcgi_source.c | 3 +- src/nxt_h1proto.c | 6 +-- src/nxt_http_parse.c | 3 +- src/nxt_http_source.c | 3 +- src/nxt_isolation.c | 5 ++- src/nxt_mem_zone.c | 3 +- src/nxt_mp.c | 9 ++-- src/nxt_openssl.c | 3 +- src/nxt_php_sapi.c | 16 +++---- src/nxt_port.c | 3 +- src/nxt_port_hash.c | 3 +- src/nxt_port_memory.c | 3 +- src/nxt_port_rpc.c | 6 ++- src/nxt_port_socket.c | 9 ++-- src/nxt_random.c | 8 ++-- src/nxt_rbtree.c | 14 ++++--- src/nxt_router.c | 21 ++++++---- src/nxt_runtime.c | 3 +- src/nxt_unit.c | 78 +++++++++++++++++++---------------- src/nxt_websocket.c | 12 ++++-- src/nxt_work_queue.c | 3 +- src/perl/nxt_perl_psgi.c | 24 ++++++----- src/ruby/nxt_ruby.c | 6 +-- src/ruby/nxt_ruby_stream_io.c | 5 ++- src/test/nxt_rbtree1.c | 14 ++++--- src/test/nxt_rbtree1_test.c | 6 ++- 32 files changed, 175 insertions(+), 120 deletions(-) diff --git a/src/nxt_application.c b/src/nxt_application.c index 594574b..32295fd 100644 --- a/src/nxt_application.c +++ b/src/nxt_application.c @@ -1089,7 +1089,8 @@ static const nxt_lvlhsh_proto_t lvlhsh_processes_proto nxt_aligned(64) = { }; -nxt_inline void +nxt_always_inline +static inline void nxt_proto_process_lhq_pid(nxt_lvlhsh_query_t *lhq, nxt_pid_t *pid) { lhq->key_hash = nxt_murmur_hash2(pid, sizeof(nxt_pid_t)); diff --git a/src/nxt_buf_filter.c b/src/nxt_buf_filter.c index 83e5baa..c59c875 100644 --- a/src/nxt_buf_filter.c +++ b/src/nxt_buf_filter.c @@ -8,7 +8,7 @@ static nxt_int_t nxt_buf_filter_nobuf(nxt_buf_filter_t *f); -nxt_inline void nxt_buf_filter_next(nxt_buf_filter_t *f); +nxt_always_inline static inline void nxt_buf_filter_next(nxt_buf_filter_t *f); static void nxt_buf_filter_file_read_start(nxt_task_t *task, nxt_buf_filter_t *f); static void nxt_buf_filter_file_read(nxt_task_t *task, nxt_buf_filter_t *f); @@ -195,7 +195,7 @@ nxt_buf_filter_nobuf(nxt_buf_filter_t *f) } -nxt_inline void +static inline void nxt_buf_filter_next(nxt_buf_filter_t *f) { if (f->output != NULL) { diff --git a/src/nxt_cache.c b/src/nxt_cache.c index e81d63d..1bfb8ea 100644 --- a/src/nxt_cache.c +++ b/src/nxt_cache.c @@ -108,7 +108,8 @@ nxt_cache_lvlhsh_test(nxt_lvlhsh_query_t *lhq, void *data) } -nxt_inline void +nxt_always_inline +static inline void nxt_cache_lock(nxt_cache_t *cache) { if (cache->shared) { @@ -117,7 +118,8 @@ nxt_cache_lock(nxt_cache_t *cache) } -nxt_inline void +nxt_always_inline +static inline void nxt_cache_unlock(nxt_cache_t *cache) { if (cache->shared) { diff --git a/src/nxt_conf.c b/src/nxt_conf.c index 79e776a..692a263 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -148,7 +148,8 @@ static u_char *nxt_conf_json_escape(u_char *dst, u_char *src, size_t size); ((p)[0] = '\r', (p)[1] = '\n', (p) + 2) -nxt_inline u_char * +nxt_always_inline +static inline u_char * nxt_conf_json_indentation(u_char *p, uint32_t level) { while (level) { diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 60b9610..b2c8d46 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -76,8 +76,9 @@ static nxt_int_t nxt_conf_vldt_error(nxt_conf_validation_t *vldt, const char *fmt, ...); static nxt_int_t nxt_conf_vldt_var(nxt_conf_validation_t *vldt, nxt_str_t *name, nxt_str_t *value); -NXT_MAYBE_UNUSED nxt_inline nxt_int_t nxt_conf_vldt_unsupported( - nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); +NXT_MAYBE_UNUSED nxt_always_inline static inline nxt_int_t + nxt_conf_vldt_unsupported(nxt_conf_validation_t *vldt, + nxt_conf_value_t *value, void *data); static nxt_int_t nxt_conf_vldt_mtypes(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); @@ -1298,7 +1299,7 @@ nxt_conf_vldt_error(nxt_conf_validation_t *vldt, const char *fmt, ...) } -nxt_inline nxt_int_t +static inline nxt_int_t nxt_conf_vldt_unsupported(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data) { diff --git a/src/nxt_external.c b/src/nxt_external.c index c724b9b..19854d7 100644 --- a/src/nxt_external.c +++ b/src/nxt_external.c @@ -27,7 +27,8 @@ nxt_app_module_t nxt_external_module = { extern char **environ; -nxt_inline nxt_int_t +nxt_always_inline +static inline nxt_int_t nxt_external_fd_no_cloexec(nxt_task_t *task, nxt_socket_t fd) { int res, flags; diff --git a/src/nxt_fastcgi_source.c b/src/nxt_fastcgi_source.c index b242429..849dc89 100644 --- a/src/nxt_fastcgi_source.c +++ b/src/nxt_fastcgi_source.c @@ -27,7 +27,8 @@ typedef struct { } while (0) -nxt_inline size_t +nxt_always_inline +static inline size_t nxt_fastcgi_param_length(u_char *p, uint32_t length) { if (nxt_fast_path(length < 128)) { diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c index d334077..e4a12a3 100644 --- a/src/nxt_h1proto.c +++ b/src/nxt_h1proto.c @@ -60,8 +60,8 @@ static void nxt_h1p_conn_request_timeout(nxt_task_t *task, void *obj, void *data); static void nxt_h1p_conn_request_send_timeout(nxt_task_t *task, void *obj, void *data); -nxt_inline void nxt_h1p_request_error(nxt_task_t *task, nxt_h1proto_t *h1p, - nxt_http_request_t *r); +nxt_always_inline static inline void nxt_h1p_request_error(nxt_task_t *task, + nxt_h1proto_t *h1p, nxt_http_request_t *r); static void nxt_h1p_request_close(nxt_task_t *task, nxt_http_proto_t proto, nxt_socket_conf_joint_t *joint); static void nxt_h1p_conn_sent(nxt_task_t *task, void *obj, void *data); @@ -1670,7 +1670,7 @@ nxt_h1p_conn_request_timer_value(nxt_conn_t *c, uintptr_t data) } -nxt_inline void +static inline void nxt_h1p_request_error(nxt_task_t *task, nxt_h1proto_t *h1p, nxt_http_request_t *r) { diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c index 1ab6cc9..748423c 100644 --- a/src/nxt_http_parse.c +++ b/src/nxt_http_parse.c @@ -61,7 +61,8 @@ static const uint8_t nxt_http_target_chars[256] nxt_aligned(64) = { }; -nxt_inline nxt_http_target_traps_e +nxt_always_inline +static inline nxt_http_target_traps_e nxt_http_parse_target(u_char **pos, u_char *end) { u_char *p; diff --git a/src/nxt_http_source.c b/src/nxt_http_source.c index 889dcd0..f4d258d 100644 --- a/src/nxt_http_source.c +++ b/src/nxt_http_source.c @@ -109,7 +109,8 @@ fail: } -nxt_inline u_char * +nxt_always_inline +static inline u_char * nxt_http_source_copy(u_char *p, nxt_str_t *src, size_t len) { u_char *s; diff --git a/src/nxt_isolation.c b/src/nxt_isolation.c index e3cb1f2..767327d 100644 --- a/src/nxt_isolation.c +++ b/src/nxt_isolation.c @@ -49,7 +49,8 @@ static void nxt_isolation_unmount_all(nxt_task_t *task, nxt_process_t *process); static nxt_int_t nxt_isolation_pivot_root(nxt_task_t *task, const char *rootfs); static nxt_int_t nxt_isolation_make_private_mount(nxt_task_t *task, const char *rootfs); -nxt_inline int nxt_pivot_root(const char *new_root, const char *old_root); +nxt_always_inline static inline int nxt_pivot_root(const char *new_root, + const char *old_root); #endif static nxt_int_t nxt_isolation_chroot(nxt_task_t *task, const char *path); @@ -1000,7 +1001,7 @@ fail: } -nxt_inline int +static inline int nxt_pivot_root(const char *new_root, const char *old_root) { return syscall(__NR_pivot_root, new_root, old_root); diff --git a/src/nxt_mem_zone.c b/src/nxt_mem_zone.c index f8ab09d..f5de448 100644 --- a/src/nxt_mem_zone.c +++ b/src/nxt_mem_zone.c @@ -367,7 +367,8 @@ nxt_mem_zone_slot_init(nxt_mem_zone_slot_t *slot, nxt_uint_t page_size) * described in "Bit Twiddling Hacks" by Sean Eron Anderson. */ -nxt_inline uint32_t +nxt_always_inline +static inline uint32_t nxt_next_highest_power_of_two(uint32_t n) { n--; diff --git a/src/nxt_mp.c b/src/nxt_mp.c index d0de2c0..0bcae6d 100644 --- a/src/nxt_mp.c +++ b/src/nxt_mp.c @@ -197,7 +197,8 @@ nxt_lg2(uint64_t v) #if (NXT_DEBUG) -nxt_inline void +nxt_always_inline +static inline void nxt_mp_thread_assert(nxt_mp_t *mp) { nxt_tid_t tid; @@ -480,7 +481,8 @@ nxt_mp_zalign(nxt_mp_t *mp, size_t alignment, size_t size) } -nxt_inline nxt_uint_t +nxt_always_inline +static inline nxt_uint_t nxt_mp_chunk_pages_index(nxt_mp_t *mp, size_t size) { nxt_int_t n, index; @@ -501,7 +503,8 @@ nxt_mp_chunk_pages_index(nxt_mp_t *mp, size_t size) #if !(NXT_DEBUG_MEMORY) -nxt_inline u_char * +nxt_always_inline +static inline u_char * nxt_mp_page_addr(nxt_mp_t *mp, nxt_mp_page_t *page) { size_t page_offset; diff --git a/src/nxt_openssl.c b/src/nxt_openssl.c index e19b138..29fcbcb 100644 --- a/src/nxt_openssl.c +++ b/src/nxt_openssl.c @@ -1217,7 +1217,8 @@ fail: } -nxt_inline void +nxt_always_inline +static inline void nxt_openssl_conn_free(nxt_task_t *task, nxt_conn_t *c) { nxt_openssl_conn_t *tls; diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c index 68ef07e..9190833 100644 --- a/src/nxt_php_sapi.c +++ b/src/nxt_php_sapi.c @@ -98,13 +98,14 @@ static void nxt_php_disable(nxt_task_t *task, const char *type, static nxt_int_t nxt_php_dirname(const nxt_str_t *file, nxt_str_t *dir); static void nxt_php_str_trim_trail(nxt_str_t *str, u_char t); static void nxt_php_str_trim_lead(nxt_str_t *str, u_char t); -nxt_inline u_char *nxt_realpath(const void *c); +nxt_always_inline static inline u_char *nxt_realpath(const void *c); static void nxt_php_request_handler(nxt_unit_request_info_t *req); static void nxt_php_dynamic_request(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r); static void nxt_php_execute(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r); -nxt_inline void nxt_php_vcwd_chdir(nxt_unit_request_info_t *req, u_char *dir); +nxt_always_inline static inline void nxt_php_vcwd_chdir( + nxt_unit_request_info_t *req, u_char *dir); static int nxt_php_startup(sapi_module_struct *sapi_module); static int nxt_php_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC); @@ -113,8 +114,9 @@ static void *nxt_php_hash_str_find_ptr(const HashTable *ht, static char *nxt_php_read_cookies(TSRMLS_D); static void nxt_php_set_sptr(nxt_unit_request_info_t *req, const char *name, nxt_unit_sptr_t *v, uint32_t len, zval *track_vars_array TSRMLS_DC); -nxt_inline void nxt_php_set_str(nxt_unit_request_info_t *req, const char *name, - nxt_str_t *s, zval *track_vars_array TSRMLS_DC); +nxt_always_inline static inline void nxt_php_set_str( + nxt_unit_request_info_t *req, const char *name, nxt_str_t *s, + zval *track_vars_array TSRMLS_DC); static void nxt_php_set_cstr(nxt_unit_request_info_t *req, const char *name, const char *str, uint32_t len, zval *track_vars_array TSRMLS_DC); static void nxt_php_register_variables(zval *track_vars_array TSRMLS_DC); @@ -913,7 +915,7 @@ nxt_php_str_trim_lead(nxt_str_t *str, u_char t) } -nxt_inline u_char * +static inline u_char * nxt_realpath(const void *c) { return (u_char *) realpath(c, NULL); @@ -1137,7 +1139,7 @@ nxt_php_execute(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r) } -nxt_inline void +static inline void nxt_php_vcwd_chdir(nxt_unit_request_info_t *req, u_char *dir) { if (nxt_slow_path(VCWD_CHDIR((char *) dir) != 0)) { @@ -1415,7 +1417,7 @@ nxt_php_set_sptr(nxt_unit_request_info_t *req, const char *name, } -nxt_inline void +static inline void nxt_php_set_str(nxt_unit_request_info_t *req, const char *name, nxt_str_t *s, zval *track_vars_array TSRMLS_DC) { diff --git a/src/nxt_port.c b/src/nxt_port.c index ed7050f..81eb5db 100644 --- a/src/nxt_port.c +++ b/src/nxt_port.c @@ -199,7 +199,8 @@ nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) /* TODO join with process_ready and move to nxt_main_process.c */ -nxt_inline void +nxt_always_inline +static inline void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, nxt_port_t *new_port, uint32_t stream) { diff --git a/src/nxt_port_hash.c b/src/nxt_port_hash.c index b23acfb..2102826 100644 --- a/src/nxt_port_hash.c +++ b/src/nxt_port_hash.c @@ -48,7 +48,8 @@ nxt_port_hash_retrieve(nxt_lvlhsh_t *port_hash) } -nxt_inline void +nxt_always_inline +static inline void nxt_port_hash_lhq(nxt_lvlhsh_query_t *lhq, nxt_pid_port_id_t *pid_port) { lhq->key_hash = nxt_murmur_hash2(pid_port, sizeof(nxt_pid_port_id_t)); diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c index e799f86..333592f 100644 --- a/src/nxt_port_memory.c +++ b/src/nxt_port_memory.c @@ -21,7 +21,8 @@ static void nxt_port_broadcast_shm_ack(nxt_task_t *task, nxt_port_t *port, void *data); -nxt_inline void +nxt_always_inline +static inline void nxt_port_mmap_handler_use(nxt_port_mmap_handler_t *mmap_handler, int i) { int c; diff --git a/src/nxt_port_rpc.c b/src/nxt_port_rpc.c index 0cac5cb..0443059 100644 --- a/src/nxt_port_rpc.c +++ b/src/nxt_port_rpc.c @@ -68,7 +68,8 @@ static const nxt_lvlhsh_proto_t lvlhsh_rpc_reg_proto nxt_aligned(64) = { }; -nxt_inline void +nxt_always_inline +static inline void nxt_port_rpc_lhq_stream(nxt_lvlhsh_query_t *lhq, uint32_t *stream) { lhq->key_hash = nxt_murmur_hash2(stream, sizeof(*stream)); @@ -78,7 +79,8 @@ nxt_port_rpc_lhq_stream(nxt_lvlhsh_query_t *lhq, uint32_t *stream) } -nxt_inline void +nxt_always_inline +static inline void nxt_port_rpc_lhq_peer(nxt_lvlhsh_query_t *lhq, nxt_pid_t *peer) { lhq->key_hash = nxt_murmur_hash2(peer, sizeof(*peer)); diff --git a/src/nxt_port_socket.c b/src/nxt_port_socket.c index 2a51dfb..30ec449 100644 --- a/src/nxt_port_socket.c +++ b/src/nxt_port_socket.c @@ -22,8 +22,9 @@ static nxt_int_t nxt_port_msg_chk_insert(nxt_task_t *task, nxt_port_t *port, static nxt_port_send_msg_t *nxt_port_msg_alloc(nxt_port_send_msg_t *m); static void nxt_port_write_handler(nxt_task_t *task, void *obj, void *data); static nxt_port_send_msg_t *nxt_port_msg_first(nxt_port_t *port); -nxt_inline void nxt_port_msg_close_fd(nxt_port_send_msg_t *msg); -nxt_inline void nxt_port_close_fds(nxt_fd_t *fd); +nxt_always_inline static inline void nxt_port_msg_close_fd( + nxt_port_send_msg_t *msg); +nxt_always_inline static inline void nxt_port_close_fds(nxt_fd_t *fd); static nxt_buf_t *nxt_port_buf_completion(nxt_task_t *task, nxt_work_queue_t *wq, nxt_buf_t *b, size_t sent, nxt_bool_t mmap_mode); static nxt_port_send_msg_t *nxt_port_msg_insert_tail(nxt_port_t *port, @@ -588,7 +589,7 @@ nxt_port_msg_first(nxt_port_t *port) } -nxt_inline void +static inline void nxt_port_msg_close_fd(nxt_port_send_msg_t *msg) { if (!msg->close_fd) { @@ -599,7 +600,7 @@ nxt_port_msg_close_fd(nxt_port_send_msg_t *msg) } -nxt_inline void +static inline void nxt_port_close_fds(nxt_fd_t *fd) { if (fd[0] != -1) { diff --git a/src/nxt_random.c b/src/nxt_random.c index 1211896..d2385f5 100644 --- a/src/nxt_random.c +++ b/src/nxt_random.c @@ -18,10 +18,10 @@ #define NXT_RANDOM_KEY_SIZE 128 -nxt_inline void nxt_random_start_schedule(nxt_random_t *r); +nxt_always_inline static inline void nxt_random_start_schedule(nxt_random_t *r); static void nxt_random_stir(nxt_random_t *r); static void nxt_random_add(nxt_random_t *r, const u_char *key, uint32_t len); -nxt_inline uint8_t nxt_random_byte(nxt_random_t *r); +nxt_always_inline static inline uint8_t nxt_random_byte(nxt_random_t *r); void @@ -33,7 +33,7 @@ nxt_random_init(nxt_random_t *r) } -nxt_inline void +static inline void nxt_random_start_schedule(nxt_random_t *r) { nxt_uint_t i; @@ -157,7 +157,7 @@ nxt_random(nxt_random_t *r) } -nxt_inline uint8_t +static inline uint8_t nxt_random_byte(nxt_random_t *r) { uint8_t si, sj; diff --git a/src/nxt_rbtree.c b/src/nxt_rbtree.c index 4a0f9c2..337638d 100644 --- a/src/nxt_rbtree.c +++ b/src/nxt_rbtree.c @@ -16,10 +16,12 @@ static void nxt_rbtree_insert_fixup(nxt_rbtree_node_t *node); static void nxt_rbtree_delete_fixup(nxt_rbtree_t *tree, nxt_rbtree_node_t *node); -nxt_inline void nxt_rbtree_left_rotate(nxt_rbtree_node_t *node); -nxt_inline void nxt_rbtree_right_rotate(nxt_rbtree_node_t *node); -nxt_inline void nxt_rbtree_parent_relink(nxt_rbtree_node_t *subst, +nxt_always_inline static inline void nxt_rbtree_left_rotate( nxt_rbtree_node_t *node); +nxt_always_inline static inline void nxt_rbtree_right_rotate( + nxt_rbtree_node_t *node); +nxt_always_inline static inline void nxt_rbtree_parent_relink( + nxt_rbtree_node_t *subst, nxt_rbtree_node_t *node); #define NXT_RBTREE_BLACK 0 @@ -445,7 +447,7 @@ nxt_rbtree_delete_fixup(nxt_rbtree_t *tree, nxt_rbtree_node_t *node) } -nxt_inline void +static inline void nxt_rbtree_left_rotate(nxt_rbtree_node_t *node) { nxt_rbtree_node_t *child; @@ -461,7 +463,7 @@ nxt_rbtree_left_rotate(nxt_rbtree_node_t *node) } -nxt_inline void +static inline void nxt_rbtree_right_rotate(nxt_rbtree_node_t *node) { nxt_rbtree_node_t *child; @@ -479,7 +481,7 @@ nxt_rbtree_right_rotate(nxt_rbtree_node_t *node) /* Relink a parent from the node to the subst node. */ -nxt_inline void +static inline void nxt_rbtree_parent_relink(nxt_rbtree_node_t *subst, nxt_rbtree_node_t *node) { nxt_rbtree_node_t *parent, **link; diff --git a/src/nxt_router.c b/src/nxt_router.c index 3a32a36..a89bad6 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -535,7 +535,8 @@ nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app) } -nxt_inline nxt_bool_t +nxt_always_inline +static inline nxt_bool_t nxt_router_msg_cancel(nxt_task_t *task, nxt_request_rpc_data_t *req_rpc_data) { nxt_buf_t *b, *next; @@ -582,7 +583,8 @@ nxt_router_msg_cancel(nxt_task_t *task, nxt_request_rpc_data_t *req_rpc_data) } -nxt_inline nxt_bool_t +nxt_always_inline +static inline nxt_bool_t nxt_queue_chk_remove(nxt_queue_link_t *lnk) { if (lnk->next != NULL) { @@ -597,7 +599,8 @@ nxt_queue_chk_remove(nxt_queue_link_t *lnk) } -nxt_inline void +nxt_always_inline +static inline void nxt_request_rpc_data_unlink(nxt_task_t *task, nxt_request_rpc_data_t *req_rpc_data) { @@ -1051,7 +1054,8 @@ fail: } -nxt_inline nxt_bool_t +nxt_always_inline +static inline nxt_bool_t nxt_router_app_can_start(nxt_app_t *app) { return app->processes + app->pending_processes < app->max_processes @@ -1059,7 +1063,8 @@ nxt_router_app_can_start(nxt_app_t *app) } -nxt_inline nxt_bool_t +nxt_always_inline +static inline nxt_bool_t nxt_router_app_need_start(nxt_app_t *app) { return (app->active_requests @@ -3455,7 +3460,8 @@ nxt_router_listen_socket_create(nxt_task_t *task, void *obj, void *data) } -nxt_inline nxt_listen_event_t * +nxt_always_inline +static inline nxt_listen_event_t * nxt_router_listen_event(nxt_queue_t *listen_connections, nxt_socket_conf_t *skcf) { @@ -4692,7 +4698,8 @@ nxt_router_app_port_error(nxt_task_t *task, nxt_port_recv_msg_t *msg, } -nxt_inline nxt_port_t * +nxt_always_inline +static inline nxt_port_t * nxt_router_app_get_port_for_quit(nxt_task_t *task, nxt_app_t *app) { nxt_port_t *port; diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c index 46955f1..6046a1b 100644 --- a/src/nxt_runtime.c +++ b/src/nxt_runtime.c @@ -1446,7 +1446,8 @@ static const nxt_lvlhsh_proto_t lvlhsh_processes_proto nxt_aligned(64) = { }; -nxt_inline void +nxt_always_inline +static inline void nxt_runtime_process_lhq_pid(nxt_lvlhsh_query_t *lhq, nxt_pid_t *pid) { lhq->key_hash = nxt_murmur_hash2(pid, sizeof(*pid)); diff --git a/src/nxt_unit.c b/src/nxt_unit.c index 32bb07a..f3f8bb9 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -44,15 +44,16 @@ typedef struct nxt_unit_websocket_frame_impl_s nxt_unit_websocket_frame_impl_t; static nxt_unit_impl_t *nxt_unit_create(nxt_unit_init_t *init); static int nxt_unit_ctx_init(nxt_unit_impl_t *lib, nxt_unit_ctx_impl_t *ctx_impl, void *data); -nxt_inline void nxt_unit_ctx_use(nxt_unit_ctx_t *ctx); -nxt_inline void nxt_unit_ctx_release(nxt_unit_ctx_t *ctx); -nxt_inline void nxt_unit_lib_use(nxt_unit_impl_t *lib); -nxt_inline void nxt_unit_lib_release(nxt_unit_impl_t *lib); -nxt_inline void nxt_unit_mmap_buf_insert(nxt_unit_mmap_buf_t **head, +nxt_always_inline static inline void nxt_unit_ctx_use(nxt_unit_ctx_t *ctx); +nxt_always_inline static inline void nxt_unit_ctx_release(nxt_unit_ctx_t *ctx); +nxt_always_inline static inline void nxt_unit_lib_use(nxt_unit_impl_t *lib); +nxt_always_inline static inline void nxt_unit_lib_release(nxt_unit_impl_t *lib); +nxt_always_inline static inline void nxt_unit_mmap_buf_insert( + nxt_unit_mmap_buf_t **head, nxt_unit_mmap_buf_t *mmap_buf); +nxt_always_inline static inline void nxt_unit_mmap_buf_insert_tail( + nxt_unit_mmap_buf_t **prev, nxt_unit_mmap_buf_t *mmap_buf); +nxt_always_inline static inline void nxt_unit_mmap_buf_unlink( nxt_unit_mmap_buf_t *mmap_buf); -nxt_inline void nxt_unit_mmap_buf_insert_tail(nxt_unit_mmap_buf_t **prev, - nxt_unit_mmap_buf_t *mmap_buf); -nxt_inline void nxt_unit_mmap_buf_unlink(nxt_unit_mmap_buf_t *mmap_buf); static int nxt_unit_read_env(nxt_unit_port_t *ready_port, nxt_unit_port_t *router_port, nxt_unit_port_t *read_port, int *shared_port_fd, int *shared_queue_fd, @@ -117,8 +118,10 @@ static int nxt_unit_incoming_mmap(nxt_unit_ctx_t *ctx, pid_t pid, int fd); static void nxt_unit_awake_ctx(nxt_unit_ctx_t *ctx, nxt_unit_ctx_impl_t *ctx_impl); static void nxt_unit_mmaps_init(nxt_unit_mmaps_t *mmaps); -nxt_inline void nxt_unit_process_use(nxt_unit_process_t *process); -nxt_inline void nxt_unit_process_release(nxt_unit_process_t *process); +nxt_always_inline static inline void nxt_unit_process_use( + nxt_unit_process_t *process); +nxt_always_inline static inline void nxt_unit_process_release( + nxt_unit_process_t *process); static void nxt_unit_mmaps_destroy(nxt_unit_mmaps_t *mmaps); static int nxt_unit_check_rbuf_mmap(nxt_unit_ctx_t *ctx, nxt_unit_mmaps_t *mmaps, pid_t pid, uint32_t id, @@ -139,10 +142,13 @@ static int nxt_unit_read_buf(nxt_unit_ctx_t *ctx, nxt_unit_read_buf_t *rbuf); static int nxt_unit_chk_ready(nxt_unit_ctx_t *ctx); static int nxt_unit_process_pending_rbuf(nxt_unit_ctx_t *ctx); static void nxt_unit_process_ready_req(nxt_unit_ctx_t *ctx); -nxt_inline int nxt_unit_is_read_queue(nxt_unit_read_buf_t *rbuf); -nxt_inline int nxt_unit_is_read_socket(nxt_unit_read_buf_t *rbuf); -nxt_inline int nxt_unit_is_shm_ack(nxt_unit_read_buf_t *rbuf); -nxt_inline int nxt_unit_is_quit(nxt_unit_read_buf_t *rbuf); +nxt_always_inline static inline int nxt_unit_is_read_queue( + nxt_unit_read_buf_t *rbuf); +nxt_always_inline static inline int nxt_unit_is_read_socket( + nxt_unit_read_buf_t *rbuf); +nxt_always_inline static inline int nxt_unit_is_shm_ack( + nxt_unit_read_buf_t *rbuf); +nxt_always_inline static inline int nxt_unit_is_quit(nxt_unit_read_buf_t *rbuf); static int nxt_unit_process_port_msg_impl(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port); static void nxt_unit_ctx_free(nxt_unit_ctx_impl_t *ctx_impl); @@ -151,8 +157,10 @@ static nxt_unit_port_t *nxt_unit_create_port(nxt_unit_ctx_t *ctx); static int nxt_unit_send_port(nxt_unit_ctx_t *ctx, nxt_unit_port_t *dst, nxt_unit_port_t *port, int queue_fd); -nxt_inline void nxt_unit_port_use(nxt_unit_port_t *port); -nxt_inline void nxt_unit_port_release(nxt_unit_port_t *port); +nxt_always_inline static inline void nxt_unit_port_use( + nxt_unit_port_t *port); +nxt_always_inline static inline void nxt_unit_port_release( + nxt_unit_port_t *port); static nxt_unit_port_t *nxt_unit_add_port(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, void *queue); static void nxt_unit_process_awaiting_req(nxt_unit_ctx_t *ctx, @@ -173,7 +181,7 @@ static ssize_t nxt_unit_sendmsg(nxt_unit_ctx_t *ctx, int fd, const void *buf, size_t buf_size, const nxt_send_oob_t *oob); static int nxt_unit_ctx_port_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, nxt_unit_read_buf_t *rbuf); -nxt_inline void nxt_unit_rbuf_cpy(nxt_unit_read_buf_t *dst, +nxt_always_inline static inline void nxt_unit_rbuf_cpy(nxt_unit_read_buf_t *dst, nxt_unit_read_buf_t *src); static int nxt_unit_shared_port_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, nxt_unit_read_buf_t *rbuf); @@ -183,7 +191,7 @@ static int nxt_unit_port_queue_recv(nxt_unit_port_t *port, nxt_unit_read_buf_t *rbuf); static int nxt_unit_app_queue_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, nxt_unit_read_buf_t *rbuf); -nxt_inline int nxt_unit_close(int fd); +nxt_always_inline static inline int nxt_unit_close(int fd); static int nxt_unit_fd_blocking(int fd); static int nxt_unit_port_hash_add(nxt_lvlhsh_t *port_hash, @@ -707,7 +715,7 @@ nxt_unit_ctx_init(nxt_unit_impl_t *lib, nxt_unit_ctx_impl_t *ctx_impl, } -nxt_inline void +static inline void nxt_unit_ctx_use(nxt_unit_ctx_t *ctx) { nxt_unit_ctx_impl_t *ctx_impl; @@ -718,7 +726,7 @@ nxt_unit_ctx_use(nxt_unit_ctx_t *ctx) } -nxt_inline void +static inline void nxt_unit_ctx_release(nxt_unit_ctx_t *ctx) { long c; @@ -734,14 +742,14 @@ nxt_unit_ctx_release(nxt_unit_ctx_t *ctx) } -nxt_inline void +static inline void nxt_unit_lib_use(nxt_unit_impl_t *lib) { nxt_atomic_fetch_add(&lib->use_count, 1); } -nxt_inline void +static inline void nxt_unit_lib_release(nxt_unit_impl_t *lib) { long c; @@ -781,7 +789,7 @@ nxt_unit_lib_release(nxt_unit_impl_t *lib) } -nxt_inline void +static inline void nxt_unit_mmap_buf_insert(nxt_unit_mmap_buf_t **head, nxt_unit_mmap_buf_t *mmap_buf) { @@ -796,7 +804,7 @@ nxt_unit_mmap_buf_insert(nxt_unit_mmap_buf_t **head, } -nxt_inline void +static inline void nxt_unit_mmap_buf_insert_tail(nxt_unit_mmap_buf_t **prev, nxt_unit_mmap_buf_t *mmap_buf) { @@ -808,7 +816,7 @@ nxt_unit_mmap_buf_insert_tail(nxt_unit_mmap_buf_t **prev, } -nxt_inline void +static inline void nxt_unit_mmap_buf_unlink(nxt_unit_mmap_buf_t *mmap_buf) { nxt_unit_mmap_buf_t **prev; @@ -4115,14 +4123,14 @@ nxt_unit_mmaps_init(nxt_unit_mmaps_t *mmaps) } -nxt_inline void +static inline void nxt_unit_process_use(nxt_unit_process_t *process) { nxt_atomic_fetch_add(&process->use_count, 1); } -nxt_inline void +static inline void nxt_unit_process_release(nxt_unit_process_t *process) { long c; @@ -4885,7 +4893,7 @@ nxt_unit_run_ctx(nxt_unit_ctx_t *ctx) } -nxt_inline int +static inline int nxt_unit_is_read_queue(nxt_unit_read_buf_t *rbuf) { nxt_port_msg_t *port_msg; @@ -4900,7 +4908,7 @@ nxt_unit_is_read_queue(nxt_unit_read_buf_t *rbuf) } -nxt_inline int +static inline int nxt_unit_is_read_socket(nxt_unit_read_buf_t *rbuf) { if (nxt_fast_path(rbuf->size == 1)) { @@ -4911,7 +4919,7 @@ nxt_unit_is_read_socket(nxt_unit_read_buf_t *rbuf) } -nxt_inline int +static inline int nxt_unit_is_shm_ack(nxt_unit_read_buf_t *rbuf) { nxt_port_msg_t *port_msg; @@ -4926,7 +4934,7 @@ nxt_unit_is_shm_ack(nxt_unit_read_buf_t *rbuf) } -nxt_inline int +static inline int nxt_unit_is_quit(nxt_unit_read_buf_t *rbuf) { nxt_port_msg_t *port_msg; @@ -5372,7 +5380,7 @@ nxt_unit_send_port(nxt_unit_ctx_t *ctx, nxt_unit_port_t *dst, } -nxt_inline void nxt_unit_port_use(nxt_unit_port_t *port) +static inline void nxt_unit_port_use(nxt_unit_port_t *port) { nxt_unit_port_impl_t *port_impl; @@ -5382,7 +5390,7 @@ nxt_inline void nxt_unit_port_use(nxt_unit_port_t *port) } -nxt_inline void nxt_unit_port_release(nxt_unit_port_t *port) +static inline void nxt_unit_port_release(nxt_unit_port_t *port) { long c; nxt_unit_port_impl_t *port_impl; @@ -6133,7 +6141,7 @@ retry: } -nxt_inline void +static inline void nxt_unit_rbuf_cpy(nxt_unit_read_buf_t *dst, nxt_unit_read_buf_t *src) { memcpy(dst->buf, src->buf, src->size); @@ -6316,7 +6324,7 @@ retry: } -nxt_inline int +static inline int nxt_unit_close(int fd) { int res; diff --git a/src/nxt_websocket.c b/src/nxt_websocket.c index 9100223..a1bdafa 100644 --- a/src/nxt_websocket.c +++ b/src/nxt_websocket.c @@ -8,14 +8,16 @@ #include -nxt_inline uint16_t +nxt_always_inline +static inline uint16_t nxt_ntoh16(const uint8_t *b) { return ((uint16_t) b[0]) << 8 | ((uint16_t) b[1]); } -nxt_inline void +nxt_always_inline +static inline void nxt_hton16(uint8_t *b, uint16_t v) { b[0] = (v >> 8); @@ -23,7 +25,8 @@ nxt_hton16(uint8_t *b, uint16_t v) } -nxt_inline uint64_t +nxt_always_inline +static inline uint64_t nxt_ntoh64(const uint8_t *b) { return ((uint64_t) b[0]) << 56 @@ -37,7 +40,8 @@ nxt_ntoh64(const uint8_t *b) } -nxt_inline void +nxt_always_inline +static inline void nxt_hton64(uint8_t *b, uint64_t v) { b[0] = (v >> 56); diff --git a/src/nxt_work_queue.c b/src/nxt_work_queue.c index f38f700..e4cd87e 100644 --- a/src/nxt_work_queue.c +++ b/src/nxt_work_queue.c @@ -34,7 +34,8 @@ static nxt_uint_t nxt_work_queue_bucket_items = 409; #if (NXT_DEBUG) -nxt_inline void +nxt_always_inline +static inline void nxt_work_queue_thread_assert(nxt_work_queue_t *wq) { nxt_tid_t tid; diff --git a/src/perl/nxt_perl_psgi.c b/src/perl/nxt_perl_psgi.c index 08a6f29..96a6519 100644 --- a/src/perl/nxt_perl_psgi.c +++ b/src/perl/nxt_perl_psgi.c @@ -61,12 +61,15 @@ static int nxt_perl_psgi_ctx_init(const char *script, static SV *nxt_perl_psgi_env_create(PerlInterpreter *my_perl, nxt_unit_request_info_t *req); -nxt_inline int nxt_perl_psgi_add_sptr(PerlInterpreter *my_perl, HV *hash_env, - const char *name, uint32_t name_len, nxt_unit_sptr_t *sptr, uint32_t len); -nxt_inline int nxt_perl_psgi_add_str(PerlInterpreter *my_perl, HV *hash_env, - const char *name, uint32_t name_len, const char *str, uint32_t len); -nxt_inline int nxt_perl_psgi_add_value(PerlInterpreter *my_perl, HV *hash_env, - const char *name, uint32_t name_len, void *value); +nxt_always_inline static inline int nxt_perl_psgi_add_sptr( + PerlInterpreter *my_perl, HV *hash_env, const char *name, uint32_t name_len, + nxt_unit_sptr_t *sptr, uint32_t len); +nxt_always_inline static inline int nxt_perl_psgi_add_str( + PerlInterpreter *my_perl, HV *hash_env, const char *name, uint32_t name_len, + const char *str, uint32_t len); +nxt_always_inline static inline int nxt_perl_psgi_add_value( + PerlInterpreter *my_perl, HV *hash_env, const char *name, uint32_t name_len, + void *value); static char *nxt_perl_psgi_module_create(const char *script); @@ -226,7 +229,8 @@ XS(XS_NGINX__Unit__Sandbox_write) } -nxt_inline void +nxt_always_inline +static inline void nxt_perl_psgi_cb_request_done(nxt_perl_psgi_ctx_t *pctx, int status) { if (pctx->req != NULL) { @@ -712,7 +716,7 @@ fail: } -nxt_inline int +static inline int nxt_perl_psgi_add_sptr(PerlInterpreter *my_perl, HV *hash_env, const char *name, uint32_t name_len, nxt_unit_sptr_t *sptr, uint32_t len) { @@ -721,7 +725,7 @@ nxt_perl_psgi_add_sptr(PerlInterpreter *my_perl, HV *hash_env, } -nxt_inline int +static inline int nxt_perl_psgi_add_str(PerlInterpreter *my_perl, HV *hash_env, const char *name, uint32_t name_len, const char *str, uint32_t len) { @@ -737,7 +741,7 @@ nxt_perl_psgi_add_str(PerlInterpreter *my_perl, HV *hash_env, } -nxt_inline int +static inline int nxt_perl_psgi_add_value(PerlInterpreter *my_perl, HV *hash_env, const char *name, uint32_t name_len, void *value) { diff --git a/src/ruby/nxt_ruby.c b/src/ruby/nxt_ruby.c index 8f4afd3..1d2c7ed 100644 --- a/src/ruby/nxt_ruby.c +++ b/src/ruby/nxt_ruby.c @@ -56,8 +56,8 @@ static void nxt_ruby_join_threads(nxt_unit_ctx_t *ctx, static VALUE nxt_ruby_rack_app_run(VALUE arg); static int nxt_ruby_read_request(nxt_unit_request_info_t *req, VALUE hash_env); -nxt_inline void nxt_ruby_add_sptr(VALUE hash_env, VALUE name, - nxt_unit_sptr_t *sptr, uint32_t len); +nxt_always_inline static inline void nxt_ruby_add_sptr(VALUE hash_env, + VALUE name, nxt_unit_sptr_t *sptr, uint32_t len); static nxt_int_t nxt_ruby_rack_result_status(nxt_unit_request_info_t *req, VALUE result); static int nxt_ruby_rack_result_headers(nxt_unit_request_info_t *req, @@ -816,7 +816,7 @@ nxt_ruby_read_request(nxt_unit_request_info_t *req, VALUE hash_env) } -nxt_inline void +static inline void nxt_ruby_add_sptr(VALUE hash_env, VALUE name, nxt_unit_sptr_t *sptr, uint32_t len) { diff --git a/src/ruby/nxt_ruby_stream_io.c b/src/ruby/nxt_ruby_stream_io.c index 4ef69ce..73739c4 100644 --- a/src/ruby/nxt_ruby_stream_io.c +++ b/src/ruby/nxt_ruby_stream_io.c @@ -16,7 +16,8 @@ static VALUE nxt_ruby_stream_io_read(VALUE obj, VALUE args); static VALUE nxt_ruby_stream_io_rewind(VALUE obj); static VALUE nxt_ruby_stream_io_puts(VALUE obj, VALUE args); static VALUE nxt_ruby_stream_io_write(VALUE obj, VALUE args); -nxt_inline long nxt_ruby_stream_io_s_write(nxt_ruby_ctx_t *rctx, VALUE val); +nxt_always_inline static inline long nxt_ruby_stream_io_s_write( + nxt_ruby_ctx_t *rctx, VALUE val); static VALUE nxt_ruby_stream_io_flush(VALUE obj); static VALUE nxt_ruby_stream_io_close(VALUE obj); @@ -234,7 +235,7 @@ nxt_ruby_stream_io_write(VALUE obj, VALUE args) } -nxt_inline long +static inline long nxt_ruby_stream_io_s_write(nxt_ruby_ctx_t *rctx, VALUE val) { if (nxt_slow_path(val == Qnil)) { diff --git a/src/test/nxt_rbtree1.c b/src/test/nxt_rbtree1.c index 1ae059a..f551f08 100644 --- a/src/test/nxt_rbtree1.c +++ b/src/test/nxt_rbtree1.c @@ -15,10 +15,12 @@ */ -nxt_inline void nxt_rbtree1_left_rotate(nxt_rbtree1_node_t **root, - nxt_rbtree1_node_t *sentinel, nxt_rbtree1_node_t *node); -nxt_inline void nxt_rbtree1_right_rotate(nxt_rbtree1_node_t **root, - nxt_rbtree1_node_t *sentinel, nxt_rbtree1_node_t *node); +nxt_always_inline static inline void nxt_rbtree1_left_rotate( + nxt_rbtree1_node_t **root, nxt_rbtree1_node_t *sentinel, + nxt_rbtree1_node_t *node); +nxt_always_inline static inline void nxt_rbtree1_right_rotate( + nxt_rbtree1_node_t **root, nxt_rbtree1_node_t *sentinel, + nxt_rbtree1_node_t *node); void @@ -322,7 +324,7 @@ nxt_rbtree1_delete(nxt_rbtree1_t *tree, nxt_rbtree1_node_t *node) } -nxt_inline void +static inline void nxt_rbtree1_left_rotate(nxt_rbtree1_node_t **root, nxt_rbtree1_node_t *sentinel, nxt_rbtree1_node_t *node) { @@ -352,7 +354,7 @@ nxt_rbtree1_left_rotate(nxt_rbtree1_node_t **root, nxt_rbtree1_node_t *sentinel, } -nxt_inline void +static inline void nxt_rbtree1_right_rotate(nxt_rbtree1_node_t **root, nxt_rbtree1_node_t *sentinel, nxt_rbtree1_node_t *node) { diff --git a/src/test/nxt_rbtree1_test.c b/src/test/nxt_rbtree1_test.c index 1f23998..0e19a24 100644 --- a/src/test/nxt_rbtree1_test.c +++ b/src/test/nxt_rbtree1_test.c @@ -17,7 +17,8 @@ ((node) != (tree)->sentinel) -nxt_inline nxt_rbtree1_node_t * +nxt_always_inline +static inline nxt_rbtree1_node_t * nxt_rbtree1_node_successor(nxt_rbtree1_t *tree, nxt_rbtree1_node_t *node) { nxt_rbtree1_node_t *parent; @@ -187,7 +188,8 @@ nxt_rbtree1_test_insert_value(nxt_rbtree1_node_t *temp, * around some value as timeout values are. */ -nxt_inline nxt_int_t +nxt_always_inline +static inline nxt_int_t nxt_rbtree1_test_compare(nxt_rbtree1_node_t *node1, nxt_rbtree1_node_t *node2) { if (node1->key < node2->key) { -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:04 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:04 +0200 Subject: [PATCH 10/18] Removed nxt_always_inline from nxt_perl_psgi_cb_request_done(). In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-11-alx.manpages@gmail.com> We shouldn't be forcing the inline of a function that is used most of the time in nxt_slow_path (error cases). See the usage: $ grep -rh nxt_perl_psgi_cb_request_done src/ nxt_perl_psgi_cb_request_done(nxt_perl_psgi_ctx_t *pctx, int status) nxt_perl_psgi_cb_request_done(CvXSUBANY(cv).any_ptr, NXT_UNIT_OK); nxt_perl_psgi_cb_request_done(CvXSUBANY(cv).any_ptr, NXT_UNIT_ERROR); nxt_perl_psgi_cb_request_done(CvXSUBANY(cv).any_ptr, NXT_UNIT_ERROR); nxt_perl_psgi_cb_request_done(CvXSUBANY(cv).any_ptr, NXT_UNIT_ERROR); nxt_perl_psgi_cb_request_done(CvXSUBANY(cv).any_ptr, NXT_UNIT_OK); nxt_perl_psgi_cb_request_done(pctx, NXT_UNIT_ERROR); --- src/perl/nxt_perl_psgi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/perl/nxt_perl_psgi.c b/src/perl/nxt_perl_psgi.c index 96a6519..6700d39 100644 --- a/src/perl/nxt_perl_psgi.c +++ b/src/perl/nxt_perl_psgi.c @@ -229,7 +229,6 @@ XS(XS_NGINX__Unit__Sandbox_write) } -nxt_always_inline static inline void nxt_perl_psgi_cb_request_done(nxt_perl_psgi_ctx_t *pctx, int status) { -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:00 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:00 +0200 Subject: [PATCH 06/18] Requiring C99 inline. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-7-alx.manpages@gmail.com> Abort configuration if inline will be handled in GNU mode. --- auto/clang | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/auto/clang b/auto/clang index 3ea5f65..229cef7 100644 --- a/auto/clang +++ b/auto/clang @@ -6,6 +6,28 @@ # C language features. +nxt_feature='C99 inline' +nxt_feature_name= +nxt_feature_run= +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test='#if defined(__GNUC_GNU_INLINE__) + #error C99 inline not available + #endif + + int main() { + return 0; + }' +. auto/feature + +if [ $nxt_found = no ]; then + $echo + $echo $0: error: no C99 inline. + $echo + exit 1; +fi + + nxt_feature="C99 variadic macro" nxt_feature_name=NXT_HAVE_C99_VARIADIC_MACRO nxt_feature_run=yes -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:07 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:07 +0200 Subject: [PATCH 13/18] Removed nxt_always_inline from nxt_unit_close(). In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-14-alx.manpages@gmail.com> It's used several times in nxt_slow_path, where we shouldn't be forcing the inline. See the usage: $ grep -rnB2 nxt_unit_close src/nxt_unit.c-192-static int nxt_unit_app_queue_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, src/nxt_unit.c-193- nxt_unit_read_buf_t *rbuf); src/nxt_unit.c:194:nxt_always_inline static inline int nxt_unit_close(int fd); -- src/nxt_unit.c-553- } src/nxt_unit.c-554- src/nxt_unit.c:555: nxt_unit_close(shared_queue_fd); -- src/nxt_unit.c-569- } src/nxt_unit.c-570- src/nxt_unit.c:571: nxt_unit_close(ready_port.out_fd); src/nxt_unit.c:572: nxt_unit_close(queue_fd); -- src/nxt_unit.c-581- src/nxt_unit.c-582- if (queue_fd != -1) { src/nxt_unit.c:583: nxt_unit_close(queue_fd); -- src/nxt_unit.c-1151- src/nxt_unit.c-1152- if (recv_msg.fd[0] != -1) { src/nxt_unit.c:1153: nxt_unit_close(recv_msg.fd[0]); -- src/nxt_unit.c-1155- src/nxt_unit.c-1156- if (recv_msg.fd[1] != -1) { src/nxt_unit.c:1157: nxt_unit_close(recv_msg.fd[1]); -- src/nxt_unit.c-1807- src/nxt_unit.c-1808- if (req->content_fd != -1) { src/nxt_unit.c:1809: nxt_unit_close(req->content_fd); -- src/nxt_unit.c-3080- src/nxt_unit.c-3081- if (res < (ssize_t) size) { src/nxt_unit.c:3082: nxt_unit_close(req->content_fd); -- src/nxt_unit.c-3192- src/nxt_unit.c-3193- if (res < (ssize_t) size) { src/nxt_unit.c:3194: nxt_unit_close(req->content_fd); -- src/nxt_unit.c-3767- strerror(errno), errno); src/nxt_unit.c-3768- src/nxt_unit.c:3769: nxt_unit_close(fd); -- src/nxt_unit.c-3805- } src/nxt_unit.c-3806- src/nxt_unit.c:3807: nxt_unit_close(fd); -- src/nxt_unit.c-3886- strerror(errno), errno); src/nxt_unit.c-3887- src/nxt_unit.c:3888: nxt_unit_close(fd); -- src/nxt_unit.c-5161- } src/nxt_unit.c-5162- src/nxt_unit.c:5163: nxt_unit_close(queue_fd); -- src/nxt_unit.c-5168- src/nxt_unit.c-5169- if (queue_fd != -1) { src/nxt_unit.c:5170: nxt_unit_close(queue_fd); -- src/nxt_unit.c-5315- pthread_mutex_unlock(&lib->mutex); src/nxt_unit.c-5316- src/nxt_unit.c:5317: nxt_unit_close(port_sockets[0]); src/nxt_unit.c:5318: nxt_unit_close(port_sockets[1]); -- src/nxt_unit.c-5333- port = nxt_unit_add_port(ctx, &new_port, NULL); src/nxt_unit.c-5334- if (nxt_slow_path(port == NULL)) { src/nxt_unit.c:5335: nxt_unit_close(port_sockets[0]); src/nxt_unit.c:5336: nxt_unit_close(port_sockets[1]); -- src/nxt_unit.c-5408- src/nxt_unit.c-5409- if (port->in_fd != -1) { src/nxt_unit.c:5410: nxt_unit_close(port->in_fd); -- src/nxt_unit.c-5414- src/nxt_unit.c-5415- if (port->out_fd != -1) { src/nxt_unit.c:5416: nxt_unit_close(port->out_fd); -- src/nxt_unit.c-5463- src/nxt_unit.c-5464- if (port->in_fd != -1) { src/nxt_unit.c:5465: nxt_unit_close(port->in_fd); -- src/nxt_unit.c-5473- src/nxt_unit.c-5474- if (port->out_fd != -1) { src/nxt_unit.c:5475: nxt_unit_close(port->out_fd); -- src/nxt_unit.c-6326- src/nxt_unit.c-6327-static inline int src/nxt_unit.c:6328:nxt_unit_close(int fd) --- src/nxt_unit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nxt_unit.c b/src/nxt_unit.c index f3f8bb9..cac913d 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -191,7 +191,7 @@ static int nxt_unit_port_queue_recv(nxt_unit_port_t *port, nxt_unit_read_buf_t *rbuf); static int nxt_unit_app_queue_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, nxt_unit_read_buf_t *rbuf); -nxt_always_inline static inline int nxt_unit_close(int fd); +static inline int nxt_unit_close(int fd); static int nxt_unit_fd_blocking(int fd); static int nxt_unit_port_hash_add(nxt_lvlhsh_t *port_hash, -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:08 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:08 +0200 Subject: [PATCH 14/18] Removed nxt_always_inline from nxt_unit_process_release(). In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-15-alx.manpages@gmail.com> In various cases it's being called in error handling code (slow path), where we shouldn't be inlining. See usage: $ grep -rnB5 nxt_unit_process_release src/nxt_unit.c-118-static void nxt_unit_awake_ctx(nxt_unit_ctx_t *ctx, src/nxt_unit.c-119- nxt_unit_ctx_impl_t *ctx_impl); src/nxt_unit.c-120-static void nxt_unit_mmaps_init(nxt_unit_mmaps_t *mmaps); src/nxt_unit.c-121-nxt_always_inline static inline void nxt_unit_process_use( src/nxt_unit.c-122- nxt_unit_process_t *process); src/nxt_unit.c:123:nxt_always_inline static inline void nxt_unit_process_release( -- src/nxt_unit.c-4129- nxt_atomic_fetch_add(&process->use_count, 1); src/nxt_unit.c-4130-} src/nxt_unit.c-4131- src/nxt_unit.c-4132- src/nxt_unit.c-4133-static inline void src/nxt_unit.c:4134:nxt_unit_process_release(nxt_unit_process_t *process) -- src/nxt_unit.c-5326- new_port.out_fd = port_sockets[1]; src/nxt_unit.c-5327- new_port.data = NULL; src/nxt_unit.c-5328- src/nxt_unit.c-5329- pthread_mutex_unlock(&lib->mutex); src/nxt_unit.c-5330- src/nxt_unit.c:5331: nxt_unit_process_release(process); -- src/nxt_unit.c-5402- if (c == 1) { src/nxt_unit.c-5403- nxt_unit_debug(NULL, "destroy port{%d,%d} in_fd %d out_fd %d", src/nxt_unit.c-5404- (int) port->id.pid, (int) port->id.id, src/nxt_unit.c-5405- port->in_fd, port->out_fd); src/nxt_unit.c-5406- src/nxt_unit.c:5407: nxt_unit_process_release(port_impl->process); -- src/nxt_unit.c-5587-unlock: src/nxt_unit.c-5588- src/nxt_unit.c-5589- pthread_mutex_unlock(&lib->mutex); src/nxt_unit.c-5590- src/nxt_unit.c-5591- if (nxt_slow_path(process != NULL)) { src/nxt_unit.c:5592: nxt_unit_process_release(process); -- src/nxt_unit.c-5746- src/nxt_unit.c-5747- nxt_unit_port_release(&port->port); src/nxt_unit.c-5748- src/nxt_unit.c-5749- } nxt_queue_loop; src/nxt_unit.c-5750- src/nxt_unit.c:5751: nxt_unit_process_release(process); --- src/nxt_unit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/nxt_unit.c b/src/nxt_unit.c index cac913d..8b6a5b0 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -120,8 +120,7 @@ static void nxt_unit_awake_ctx(nxt_unit_ctx_t *ctx, static void nxt_unit_mmaps_init(nxt_unit_mmaps_t *mmaps); nxt_always_inline static inline void nxt_unit_process_use( nxt_unit_process_t *process); -nxt_always_inline static inline void nxt_unit_process_release( - nxt_unit_process_t *process); +static inline void nxt_unit_process_release(nxt_unit_process_t *process); static void nxt_unit_mmaps_destroy(nxt_unit_mmaps_t *mmaps); static int nxt_unit_check_rbuf_mmap(nxt_unit_ctx_t *ctx, nxt_unit_mmaps_t *mmaps, pid_t pid, uint32_t id, -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:10 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:10 +0200 Subject: [PATCH 16/18] Fixed static and static inline in a header to be C99 inline. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-17-alx.manpages@gmail.com> Also create a new .c file with their extern declarations. --- auto/sources | 1 + src/nxt_app_nncq.c | 29 +++++++++++++++++++++++++++++ src/nxt_app_nncq.h | 24 ++++++++++++------------ src/nxt_nncq.c | 2 ++ 4 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 src/nxt_app_nncq.c diff --git a/auto/sources b/auto/sources index 4042a63..dfbc580 100644 --- a/auto/sources +++ b/auto/sources @@ -7,6 +7,7 @@ NXT_LIB_SRCS=" \ src/nxt_lib.c \ src/nxt_gmtime.c \ src/nxt_errno.c \ + src/nxt_app_nncq.c \ src/nxt_nncq.c \ src/nxt_time.c \ src/nxt_malloc.c \ diff --git a/src/nxt_app_nncq.c b/src/nxt_app_nncq.c new file mode 100644 index 00000000..0531cb1 --- /dev/null +++ b/src/nxt_app_nncq.c @@ -0,0 +1,29 @@ + +#include + +#include + + +extern nxt_app_nncq_atomic_t nxt_app_nncq_head( + nxt_app_nncq_t const volatile *q); +extern nxt_app_nncq_atomic_t nxt_app_nncq_tail( + nxt_app_nncq_t const volatile *q); +extern void nxt_app_nncq_tail_cmp_inc(nxt_app_nncq_t volatile *q, + nxt_app_nncq_atomic_t t); +extern nxt_app_nncq_atomic_t nxt_app_nncq_index( + nxt_app_nncq_t const volatile *q, nxt_app_nncq_atomic_t i); +extern nxt_app_nncq_atomic_t nxt_app_nncq_map(nxt_app_nncq_t const volatile *q, + nxt_app_nncq_atomic_t i); +extern nxt_app_nncq_cycle_t nxt_app_nncq_cycle(nxt_app_nncq_t const volatile *q, + nxt_app_nncq_atomic_t i); +extern nxt_app_nncq_cycle_t nxt_app_nncq_next_cycle( + nxt_app_nncq_t const volatile *q, nxt_app_nncq_cycle_t i); +extern nxt_app_nncq_atomic_t nxt_app_nncq_new_entry( + nxt_app_nncq_t const volatile *q, nxt_app_nncq_cycle_t cycle, + nxt_app_nncq_atomic_t i); +extern nxt_app_nncq_atomic_t nxt_app_nncq_empty( + nxt_app_nncq_t const volatile *q); +extern void nxt_app_nncq_init(nxt_app_nncq_t volatile *q); +extern void nxt_app_nncq_enqueue(nxt_app_nncq_t volatile *q, + nxt_app_nncq_atomic_t val); +extern nxt_app_nncq_atomic_t nxt_app_nncq_dequeue(nxt_app_nncq_t volatile *q); diff --git a/src/nxt_app_nncq.h b/src/nxt_app_nncq.h index f9b8ce0..5768f73 100644 --- a/src/nxt_app_nncq.h +++ b/src/nxt_app_nncq.h @@ -21,49 +21,49 @@ typedef struct { } nxt_app_nncq_t; -static inline nxt_app_nncq_atomic_t +inline nxt_app_nncq_atomic_t nxt_app_nncq_head(nxt_app_nncq_t const volatile *q) { return q->head; } -static inline nxt_app_nncq_atomic_t +inline nxt_app_nncq_atomic_t nxt_app_nncq_tail(nxt_app_nncq_t const volatile *q) { return q->tail; } -static inline void +inline void nxt_app_nncq_tail_cmp_inc(nxt_app_nncq_t volatile *q, nxt_app_nncq_atomic_t t) { nxt_atomic_cmp_set(&q->tail, t, t + 1); } -static inline nxt_app_nncq_atomic_t +inline nxt_app_nncq_atomic_t nxt_app_nncq_index(nxt_app_nncq_t const volatile *q, nxt_app_nncq_atomic_t i) { return i % NXT_APP_NNCQ_SIZE; } -static inline nxt_app_nncq_atomic_t +inline nxt_app_nncq_atomic_t nxt_app_nncq_map(nxt_app_nncq_t const volatile *q, nxt_app_nncq_atomic_t i) { return i % NXT_APP_NNCQ_SIZE; } -static inline nxt_app_nncq_cycle_t +inline nxt_app_nncq_cycle_t nxt_app_nncq_cycle(nxt_app_nncq_t const volatile *q, nxt_app_nncq_atomic_t i) { return i / NXT_APP_NNCQ_SIZE; } -static inline nxt_app_nncq_cycle_t +inline nxt_app_nncq_cycle_t nxt_app_nncq_next_cycle(nxt_app_nncq_t const volatile *q, nxt_app_nncq_cycle_t i) { @@ -71,7 +71,7 @@ nxt_app_nncq_next_cycle(nxt_app_nncq_t const volatile *q, } -static inline nxt_app_nncq_atomic_t +inline nxt_app_nncq_atomic_t nxt_app_nncq_new_entry(nxt_app_nncq_t const volatile *q, nxt_app_nncq_cycle_t cycle, nxt_app_nncq_atomic_t i) @@ -80,14 +80,14 @@ nxt_app_nncq_new_entry(nxt_app_nncq_t const volatile *q, } -static inline nxt_app_nncq_atomic_t +inline nxt_app_nncq_atomic_t nxt_app_nncq_empty(nxt_app_nncq_t const volatile *q) { return NXT_APP_NNCQ_SIZE; } -static void +inline void nxt_app_nncq_init(nxt_app_nncq_t volatile *q) { q->head = NXT_APP_NNCQ_SIZE; @@ -97,7 +97,7 @@ nxt_app_nncq_init(nxt_app_nncq_t volatile *q) } -static void +inline void nxt_app_nncq_enqueue(nxt_app_nncq_t volatile *q, nxt_app_nncq_atomic_t val) { nxt_app_nncq_cycle_t e_cycle, t_cycle; @@ -131,7 +131,7 @@ nxt_app_nncq_enqueue(nxt_app_nncq_t volatile *q, nxt_app_nncq_atomic_t val) } -static nxt_app_nncq_atomic_t +inline nxt_app_nncq_atomic_t nxt_app_nncq_dequeue(nxt_app_nncq_t volatile *q) { nxt_app_nncq_cycle_t e_cycle, h_cycle; diff --git a/src/nxt_nncq.c b/src/nxt_nncq.c index 92ff81e..e6b126a 100644 --- a/src/nxt_nncq.c +++ b/src/nxt_nncq.c @@ -1,6 +1,8 @@ #include +#include + extern nxt_nncq_atomic_t nxt_nncq_head(nxt_nncq_t const volatile *q); extern nxt_nncq_atomic_t nxt_nncq_tail(nxt_nncq_t const volatile *q); -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:02 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:02 +0200 Subject: [PATCH 08/18] Removed nxt_always_inline from nxt_array_remove_last(). In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-9-alx.manpages@gmail.com> We shouldn't be forcing the inline in nxt_slow_path. Since we're changing from an nxt_always_inline to a C99 inline function, we now need to emit an extern function, which will be used when the function is not inlined. See the usage: $ grep -rnB1 nxt_array_remove_last src/nxt_cert.c-896- if (nxt_slow_path(ret != NXT_OK)) { src/nxt_cert.c:897: nxt_array_remove_last(certs); -- src/nxt_array.h-52-inline void * src/nxt_array.h:53:nxt_array_remove_last(nxt_array_t *array) --- src/nxt_array.c | 3 +++ src/nxt_array.h | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nxt_array.c b/src/nxt_array.c index 1e13c22..a05c05b 100644 --- a/src/nxt_array.c +++ b/src/nxt_array.c @@ -148,3 +148,6 @@ nxt_array_copy(nxt_mp_t *mp, nxt_array_t *dst, nxt_array_t *src) return dst; } + + +extern void *nxt_array_remove_last(nxt_array_t *array); diff --git a/src/nxt_array.h b/src/nxt_array.h index 548548f..c71927b 100644 --- a/src/nxt_array.h +++ b/src/nxt_array.h @@ -48,7 +48,6 @@ NXT_EXPORT nxt_array_t *nxt_array_copy(nxt_mp_t *mp, nxt_array_t *dst, ((array)->nelts == 0) -nxt_always_inline inline void * nxt_array_remove_last(nxt_array_t *array) { -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:11 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:11 +0200 Subject: [PATCH 17/18] Added const to a constant variable. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-18-alx.manpages@gmail.com> This fixes an error triggered by making these functions C99 inline (instead of nxt_always_inline), and improves const correctness (and probably it also helps optimize a little bit, by moving the code to a read-only section). --- src/nxt_http.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/nxt_http.h b/src/nxt_http.h index c916ae5..1756c8a 100644 --- a/src/nxt_http.h +++ b/src/nxt_http.h @@ -280,11 +280,12 @@ nxt_always_inline inline u_char * nxt_http_date(u_char *buf, struct tm *tm) { - static const char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", - "Sat" }; + static const char *const week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", + "Fri", "Sat" }; - static const char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + static const char *const month[] = { "Jan", "Feb", "Mar", "Apr", "May", + "Jun", "Jul", "Aug", "Sep", "Oct", + "Nov", "Dec" }; return nxt_sprintf(buf, buf + NXT_HTTP_DATE_LEN, "%s, %02d %s %4d %02d:%02d:%02d GMT", -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:06 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:06 +0200 Subject: [PATCH 12/18] Removed nxt_always_inline from (NXT_AIX) nxt_thread_get_tid(). In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-13-alx.manpages@gmail.com> It is a huge definition, and it's mostly used in slow paths. Since we're changing from an nxt_always_inline to a C99 inline function, we now need to emit an extern function, which will be used when the function is not inlined. --- auto/sources | 1 + src/nxt_thread_id.c | 5 +++++ src/nxt_thread_id.h | 1 - 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/nxt_thread_id.c diff --git a/auto/sources b/auto/sources index 27a45ed..dd0c90d 100644 --- a/auto/sources +++ b/auto/sources @@ -49,6 +49,7 @@ NXT_LIB_SRCS=" \ src/nxt_thread.c \ src/nxt_thread_mutex.c \ src/nxt_thread_cond.c \ + src/nxt_thread_id.c \ src/nxt_spinlock.c \ src/nxt_semaphore.c \ src/nxt_thread_pool.c \ diff --git a/src/nxt_thread_id.c b/src/nxt_thread_id.c new file mode 100644 index 00000000..913d816 --- /dev/null +++ b/src/nxt_thread_id.c @@ -0,0 +1,5 @@ + +#include + + +extern nxt_tid_t nxt_thread_get_tid(void); diff --git a/src/nxt_thread_id.h b/src/nxt_thread_id.h index 5f70987..f1922c8 100644 --- a/src/nxt_thread_id.h +++ b/src/nxt_thread_id.h @@ -109,7 +109,6 @@ nxt_thread_get_tid(void) typedef tid_t nxt_tid_t; -nxt_always_inline inline nxt_tid_t nxt_thread_get_tid(void) { -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:03 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:03 +0200 Subject: [PATCH 09/18] Removed nxt_always_inline from nxt_h1p_request_error(). In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-10-alx.manpages@gmail.com> We shouldn't be forcing the inline of a function that is only run in error cases (slow path). --- src/nxt_h1proto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c index e4a12a3..4f9ab4d 100644 --- a/src/nxt_h1proto.c +++ b/src/nxt_h1proto.c @@ -60,8 +60,8 @@ static void nxt_h1p_conn_request_timeout(nxt_task_t *task, void *obj, void *data); static void nxt_h1p_conn_request_send_timeout(nxt_task_t *task, void *obj, void *data); -nxt_always_inline static inline void nxt_h1p_request_error(nxt_task_t *task, - nxt_h1proto_t *h1p, nxt_http_request_t *r); +static inline void nxt_h1p_request_error(nxt_task_t *task, nxt_h1proto_t *h1p, + nxt_http_request_t *r); static void nxt_h1p_request_close(nxt_task_t *task, nxt_http_proto_t proto, nxt_socket_conf_joint_t *joint); static void nxt_h1p_conn_sent(nxt_task_t *task, void *obj, void *data); -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:09 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:09 +0200 Subject: [PATCH 15/18] Fixed static and static inline in a header to be C99 inline. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-16-alx.manpages@gmail.com> Also create a new .c file with their extern declarations. --- auto/sources | 1 + src/nxt_nncq.c | 21 +++++++++++++++++++++ src/nxt_nncq.h | 24 ++++++++++++------------ 3 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 src/nxt_nncq.c diff --git a/auto/sources b/auto/sources index dd0c90d..4042a63 100644 --- a/auto/sources +++ b/auto/sources @@ -7,6 +7,7 @@ NXT_LIB_SRCS=" \ src/nxt_lib.c \ src/nxt_gmtime.c \ src/nxt_errno.c \ + src/nxt_nncq.c \ src/nxt_time.c \ src/nxt_malloc.c \ src/nxt_file.c \ diff --git a/src/nxt_nncq.c b/src/nxt_nncq.c new file mode 100644 index 00000000..92ff81e --- /dev/null +++ b/src/nxt_nncq.c @@ -0,0 +1,21 @@ + +#include + + +extern nxt_nncq_atomic_t nxt_nncq_head(nxt_nncq_t const volatile *q); +extern nxt_nncq_atomic_t nxt_nncq_tail(nxt_nncq_t const volatile *q); +extern void nxt_nncq_tail_cmp_inc(nxt_nncq_t volatile *q, nxt_nncq_atomic_t t); +extern nxt_nncq_atomic_t nxt_nncq_index(nxt_nncq_t const volatile *q, + nxt_nncq_atomic_t i); +extern nxt_nncq_atomic_t nxt_nncq_map(nxt_nncq_t const volatile *q, + nxt_nncq_atomic_t i); +extern nxt_nncq_cycle_t nxt_nncq_cycle(nxt_nncq_t const volatile *q, + nxt_nncq_atomic_t i); +extern nxt_nncq_cycle_t nxt_nncq_next_cycle(nxt_nncq_t const volatile *q, + nxt_nncq_cycle_t i); +extern nxt_nncq_atomic_t nxt_nncq_new_entry(nxt_nncq_t const volatile *q, + nxt_nncq_cycle_t cycle, nxt_nncq_atomic_t i); +extern nxt_nncq_atomic_t nxt_nncq_empty(nxt_nncq_t const volatile *q); +extern void nxt_nncq_init(nxt_nncq_t volatile *q); +extern void nxt_nncq_enqueue(nxt_nncq_t volatile *q, nxt_nncq_atomic_t val); +extern nxt_nncq_atomic_t nxt_nncq_dequeue(nxt_nncq_t volatile *q); diff --git a/src/nxt_nncq.h b/src/nxt_nncq.h index 20e7ecf..2d3f7c3 100644 --- a/src/nxt_nncq.h +++ b/src/nxt_nncq.h @@ -21,56 +21,56 @@ typedef struct { } nxt_nncq_t; -static inline nxt_nncq_atomic_t +inline nxt_nncq_atomic_t nxt_nncq_head(nxt_nncq_t const volatile *q) { return q->head; } -static inline nxt_nncq_atomic_t +inline nxt_nncq_atomic_t nxt_nncq_tail(nxt_nncq_t const volatile *q) { return q->tail; } -static inline void +inline void nxt_nncq_tail_cmp_inc(nxt_nncq_t volatile *q, nxt_nncq_atomic_t t) { nxt_atomic_cmp_set(&q->tail, t, t + 1); } -static inline nxt_nncq_atomic_t +inline nxt_nncq_atomic_t nxt_nncq_index(nxt_nncq_t const volatile *q, nxt_nncq_atomic_t i) { return i % NXT_NNCQ_SIZE; } -static inline nxt_nncq_atomic_t +inline nxt_nncq_atomic_t nxt_nncq_map(nxt_nncq_t const volatile *q, nxt_nncq_atomic_t i) { return i % NXT_NNCQ_SIZE; } -static inline nxt_nncq_cycle_t +inline nxt_nncq_cycle_t nxt_nncq_cycle(nxt_nncq_t const volatile *q, nxt_nncq_atomic_t i) { return i / NXT_NNCQ_SIZE; } -static inline nxt_nncq_cycle_t +inline nxt_nncq_cycle_t nxt_nncq_next_cycle(nxt_nncq_t const volatile *q, nxt_nncq_cycle_t i) { return i + 1; } -static inline nxt_nncq_atomic_t +inline nxt_nncq_atomic_t nxt_nncq_new_entry(nxt_nncq_t const volatile *q, nxt_nncq_cycle_t cycle, nxt_nncq_atomic_t i) { @@ -78,14 +78,14 @@ nxt_nncq_new_entry(nxt_nncq_t const volatile *q, nxt_nncq_cycle_t cycle, } -static inline nxt_nncq_atomic_t +inline nxt_nncq_atomic_t nxt_nncq_empty(nxt_nncq_t const volatile *q) { return NXT_NNCQ_SIZE; } -static void +inline void nxt_nncq_init(nxt_nncq_t volatile *q) { q->head = NXT_NNCQ_SIZE; @@ -94,7 +94,7 @@ nxt_nncq_init(nxt_nncq_t volatile *q) } -static void +inline void nxt_nncq_enqueue(nxt_nncq_t volatile *q, nxt_nncq_atomic_t val) { nxt_nncq_cycle_t e_cycle, t_cycle; @@ -128,7 +128,7 @@ nxt_nncq_enqueue(nxt_nncq_t volatile *q, nxt_nncq_atomic_t val) } -static nxt_nncq_atomic_t +inline nxt_nncq_atomic_t nxt_nncq_dequeue(nxt_nncq_t volatile *q) { nxt_nncq_cycle_t e_cycle, h_cycle; -- 2.36.1 From alx.manpages at gmail.com Thu Jun 2 18:05:12 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 2 Jun 2022 20:05:12 +0200 Subject: [PATCH 18/18] Added extern version of C99 inline function. In-Reply-To: <20220602180512.56110-1-alx.manpages@gmail.com> References: <20220602180512.56110-1-alx.manpages@gmail.com> Message-ID: <20220602180512.56110-19-alx.manpages@gmail.com> Being C99 inline, even with nxt_always_inline, we need to provide an extern version of the function, to be used when the function pointer is used. --- src/nxt_buf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/nxt_buf.c b/src/nxt_buf.c index cbde069..d2b240e 100644 --- a/src/nxt_buf.c +++ b/src/nxt_buf.c @@ -327,3 +327,6 @@ nxt_buf_make_plain(nxt_mp_t *mp, nxt_buf_t *src, size_t size) return b; } + + +extern void nxt_buf_dummy_completion(nxt_task_t *task, void *obj, void *data); -- 2.36.1 From alx.manpages at gmail.com Wed Jun 8 16:05:08 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Wed, 8 Jun 2022 18:05:08 +0200 Subject: Devuan pytest failure Message-ID: <096d52a7-79c9-1e26-bf35-fec5dae25fc7@gmail.com> Hi Andrei, This is the error I have in Devuan when running the pytests. The error is a bit random: very few times it doesn't appear, and then most of the times it appears, but sometimes only some tests fail, and other times many tests fail. Could you please check the logs and see if makes any sense to you? Thanks, Alex -- Alejandro Colomar Linux man-pages comaintainer; http://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/ -------------- next part -------------- A non-text attachment was scrubbed... Name: pytest.log Type: text/x-log Size: 15190 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: unit.log Type: text/x-log Size: 1014 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 9 13:14:47 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 9 Jun 2022 15:14:47 +0200 Subject: Devuan pytest failure In-Reply-To: <096d52a7-79c9-1e26-bf35-fec5dae25fc7@gmail.com> References: <096d52a7-79c9-1e26-bf35-fec5dae25fc7@gmail.com> Message-ID: On 6/8/22 18:05, Alejandro Colomar wrote: > Hi Andrei, > > This is the error I have in Devuan when running the pytests.  The error > is a bit random: very few times it doesn't appear, and then most of the > times it appears, but sometimes only some tests fail, and other times > many tests fail.  Could you please check the logs and see if makes any > sense to you? > > Thanks, > > Alex > Another log -- Alejandro Colomar Linux man-pages comaintainer; http://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/ -------------- next part -------------- A non-text attachment was scrubbed... Name: unit.log Type: text/x-log Size: 571217 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Sat Jun 11 01:44:34 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Sat, 11 Jun 2022 02:44:34 +0100 Subject: Possible NULL pointer dereference in nxt_cache_wake_handler() Message-ID: <20220611024434.3e326cf9@kappa.digital-domain.net> So in src/nxt_cache.c we have the following function static void nxt_cache_wake_handler(nxt_thread_t *thr, void *obj, void *data) { nxt_cache_t *cache; nxt_work_handler_t handler; nxt_cache_query_t *q; nxt_cache_query_wait_t *qw; qw = obj; q = qw->query; cache = qw->cache; nxt_cache_lock(cache); handler = nxt_cache_node_test(cache, q); if (handler != NULL) { nxt_cache_query_wait_free(cache, qw); } else { /* Wait again. */ qw->next = q->node->waiting; q->node->waiting = qw; } nxt_cache_unlock(cache); handler(thr, q, NULL); } We set handler then check if it's NULL. However even if it is NULL we still call it with handler(thr, q, NULL); Or am I missing something? Andrew From max.romanov at gmail.com Sat Jun 11 10:50:11 2022 From: max.romanov at gmail.com (Max Romanov) Date: Sat, 11 Jun 2022 13:50:11 +0300 Subject: Possible NULL pointer dereference in nxt_cache_wake_handler() In-Reply-To: <20220611024434.3e326cf9@kappa.digital-domain.net> References: <20220611024434.3e326cf9@kappa.digital-domain.net> Message-ID: <5296E4AA-0A45-4A12-8ADA-A69E3EA1E36F@gmail.com> Hi Andrew, Good catch! This is potential NULL dereference issue and it should to be fixed before nxt_cache.c added to compiled files list :) — Best regards, Max > On 11 Jun 2022, at 04:44, Andrew Clayton wrote: > > So in src/nxt_cache.c we have the following function > > static void > nxt_cache_wake_handler(nxt_thread_t *thr, void *obj, void *data) > { > nxt_cache_t *cache; > nxt_work_handler_t handler; > nxt_cache_query_t *q; > nxt_cache_query_wait_t *qw; > > qw = obj; > q = qw->query; > cache = qw->cache; > > nxt_cache_lock(cache); > > handler = nxt_cache_node_test(cache, q); > > if (handler != NULL) { > nxt_cache_query_wait_free(cache, qw); > > } else { > /* Wait again. */ > qw->next = q->node->waiting; > q->node->waiting = qw; > } > > nxt_cache_unlock(cache); > > handler(thr, q, NULL); > } > > We set handler then check if it's NULL. However even if it is NULL we > still call it with > > handler(thr, q, NULL); > > Or am I missing something? > > Andrew > _______________________________________________ > unit mailing list -- unit at nginx.org > To unsubscribe send an email to unit-leave at nginx.org From andrew at digital-domain.net Mon Jun 13 21:27:34 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 13 Jun 2022 22:27:34 +0100 Subject: Possible NULL pointer dereference in nxt_cache_wake_handler() In-Reply-To: <5296E4AA-0A45-4A12-8ADA-A69E3EA1E36F@gmail.com> References: <20220611024434.3e326cf9@kappa.digital-domain.net> <5296E4AA-0A45-4A12-8ADA-A69E3EA1E36F@gmail.com> Message-ID: <20220613222734.2055d6f0@kappa.digital-domain.net> On Sat, 11 Jun 2022 13:50:11 +0300 Max Romanov wrote: > Hi Andrew, > > Good catch! > This is potential NULL dereference issue and it should to be fixed before nxt_cache.c added to compiled files list :) There seems to be a similar issue in src/nxt_file_cache.c::nxt_cache_wake_handler() Andrew From andrew at digital-domain.net Thu Jun 16 01:00:59 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:59 +0100 Subject: [PATCH 09/11] Router: removed unused structure member proxy_buffers. In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-10-andrew@digital-domain.net> proxy_buffers is declared as a structure member of nxt_socket_conf_t and is set in nxt_router_conf_create(), however it is not used anywhere. Removing it has the nice side effect of making the nxt_socket_conf_t structure require one less cacheline (on x86-64 at least) as the summary from pahole[0] shows Before /* size: 200, cachelines: 4, members: 25 */ /* sum members: 185, holes: 3, sum holes: 15 */ After /* size: 192, cachelines: 3, members: 24 */ /* sum members: 177, holes: 3, sum holes: 15 */ [0]: https://github.com/acmel/dwarves --- src/nxt_router.c | 1 - src/nxt_router.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/nxt_router.c b/src/nxt_router.c index 6b69b2c..b0f2ff1 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -1840,7 +1840,6 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, skcf->max_body_size = 8 * 1024 * 1024; skcf->proxy_header_buffer_size = 64 * 1024; skcf->proxy_buffer_size = 4096; - skcf->proxy_buffers = 256; skcf->idle_timeout = 180 * 1000; skcf->header_read_timeout = 30 * 1000; skcf->body_read_timeout = 30 * 1000; diff --git a/src/nxt_router.h b/src/nxt_router.h index 7e337d2..538e54e 100644 --- a/src/nxt_router.h +++ b/src/nxt_router.h @@ -181,7 +181,6 @@ typedef struct { size_t max_body_size; size_t proxy_header_buffer_size; size_t proxy_buffer_size; - size_t proxy_buffers; nxt_msec_t idle_timeout; nxt_msec_t header_read_timeout; -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:00:54 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:54 +0100 Subject: [PATCH 04/11] Port: removed useless msg->cancelled == 0 checks. In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-5-andrew@digital-domain.net> In src/nxt_port_socket.c::nxt_port_read_msg_process() msg->cancelled is set to 0 and is not touched again. However there are several checks for it being == 0 which are _always_ true, so remove them. I'm assuming that this is functioning as intended and that setting msg->cancelled to 0 is correct. msg->cancelled was set to 0 unconditionally in commit e227fc9 ("Introducing application and port shared memory queues."), so I guess the now redundant checks were simply missed for removal. --- src/nxt_port_socket.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/nxt_port_socket.c b/src/nxt_port_socket.c index 5752d5a..2649e69 100644 --- a/src/nxt_port_socket.c +++ b/src/nxt_port_socket.c @@ -1237,7 +1237,7 @@ nxt_port_read_msg_process(nxt_task_t *task, nxt_port_t *port, } else { if (nxt_slow_path(msg->port_msg.mf != 0)) { - if (msg->port_msg.mmap && msg->cancelled == 0) { + if (msg->port_msg.mmap) { nxt_port_mmap_read(task, msg); b = msg->buf; } @@ -1251,25 +1251,18 @@ nxt_port_read_msg_process(nxt_task_t *task, nxt_port_t *port, fmsg->port_msg.nf = 0; fmsg->port_msg.mf = 0; - if (nxt_fast_path(msg->cancelled == 0)) { - msg->buf = NULL; - msg->fd[0] = -1; - msg->fd[1] = -1; - b = NULL; + msg->buf = NULL; + msg->fd[0] = -1; + msg->fd[1] = -1; + b = NULL; - } else { - nxt_port_close_fds(msg->fd); - } } else { - if (nxt_fast_path(msg->cancelled == 0)) { - - if (msg->port_msg.mmap) { - nxt_port_mmap_read(task, msg); - b = msg->buf; - } - - port->handler(task, msg); + if (msg->port_msg.mmap) { + nxt_port_mmap_read(task, msg); + b = msg->buf; } + + port->handler(task, msg); } } -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:00:51 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:51 +0100 Subject: [PATCH 01/11] Array: avoided void pointer arithmetic in nxt_array_copy(). In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-2-andrew@digital-domain.net> As was pointed out by the cppcheck[0] static code analysis utility we were doing void pointer arithmetic on src->elts which is technically undefined behaviour. While GCC allows this by treating the size of void as 1[1]. Same with Clang. Other compilers I'm not sure about, so lets just be safe and cast src->nelts to (char *) where sizeof(char) is guaranteed to be 1. [0]: https://cppcheck.sourceforge.io/ [1]: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html --- src/nxt_array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nxt_array.c b/src/nxt_array.c index 1e13c22..0a7945e 100644 --- a/src/nxt_array.c +++ b/src/nxt_array.c @@ -140,7 +140,7 @@ nxt_array_copy(nxt_mp_t *mp, nxt_array_t *dst, nxt_array_t *src) return NULL; } - nxt_memcpy(data, src->elts + (i * size), size); + nxt_memcpy(data, (char *) src->elts + (i * size), size); } } -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:00:56 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:56 +0100 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-7-andrew@digital-domain.net> In src/nxt_unit_sptr.h::nxt_unit_sptr_set() we are setting one member of a union based on another member which cppcheck[0] flags as undefined behaviour src/nxt_unit_sptr.h:27:18: error: Overlapping read/write of union is undefined behavior [overlappingWriteUnion] sptr->offset = (uint8_t *) ptr - sptr->base; ^ I think this warning is correct as I can't see where we are setting sptr->base beforehand which I think would make this defined behaviour. To avoid any doubts take a copy of sptr->base and then use that value in the above. [0]: https://cppcheck.sourceforge.io/ --- src/nxt_unit_sptr.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nxt_unit_sptr.h b/src/nxt_unit_sptr.h index 314416e..6d867a5 100644 --- a/src/nxt_unit_sptr.h +++ b/src/nxt_unit_sptr.h @@ -24,7 +24,10 @@ union nxt_unit_sptr_u { static inline void nxt_unit_sptr_set(nxt_unit_sptr_t *sptr, void *ptr) { - sptr->offset = (uint8_t *) ptr - sptr->base; + const uint8_t *base; + + base = sptr->base; + sptr->offset = (uint8_t *) ptr - base; } -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:00:55 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:55 +0100 Subject: [PATCH 05/11] Socket: removed useless port < 1 check. In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-6-andrew@digital-domain.net> In src/nxt_sockaddr.c::nxt_job_sockaddr_inet_parse() there is a check that port > 0 then there is a check that port < 1 || port > 65535, well we _know_ it can't be less than 1. --- src/nxt_sockaddr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nxt_sockaddr.c b/src/nxt_sockaddr.c index 730428e..71e50e3 100644 --- a/src/nxt_sockaddr.c +++ b/src/nxt_sockaddr.c @@ -1090,7 +1090,7 @@ nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs) port = nxt_int_parse(host, length); if (port > 0) { - if (port < 1 || port > 65535) { + if (port > 65535) { goto invalid_port; } -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:00:52 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:52 +0100 Subject: [PATCH 02/11] Constified numerous function parameters. In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-3-andrew@digital-domain.net> As was pointed out by the cppcheck[0] static code analysis utility we can mark numerous function parameters as 'const'. This acts as a hint to the compiler about our intentions and the compiler will tell us when we deviate from them. [0]: https://cppcheck.sourceforge.io/ --- src/nxt_conf.c | 10 +++++----- src/nxt_conf.h | 6 +++--- src/nxt_http.h | 5 +++-- src/nxt_http_parse.c | 26 +++++++++++++------------- src/nxt_http_parse.h | 2 +- src/nxt_http_request.c | 12 ++++++------ src/nxt_http_static.c | 4 ++-- src/nxt_mp.c | 4 ++-- src/nxt_port_memory_int.h | 2 +- src/nxt_port_socket.c | 4 ++-- src/nxt_string.c | 2 +- src/nxt_string.h | 2 +- src/nxt_unit.c | 5 +++-- 13 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/nxt_conf.c b/src/nxt_conf.c index 79e776a..a44b8c7 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -102,7 +102,7 @@ typedef struct { static nxt_int_t nxt_conf_path_next_token(nxt_conf_path_parse_t *parse, nxt_str_t *token); -static u_char *nxt_conf_json_skip_space(u_char *start, u_char *end); +static u_char *nxt_conf_json_skip_space(u_char *start, const u_char *end); static u_char *nxt_conf_json_parse_value(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start, u_char *end, nxt_conf_json_error_t *error); static u_char *nxt_conf_json_parse_object(nxt_mp_t *mp, nxt_conf_value_t *value, @@ -266,7 +266,7 @@ nxt_conf_create_object(nxt_mp_t *mp, nxt_uint_t count) void nxt_conf_set_member(nxt_conf_value_t *object, nxt_str_t *name, - nxt_conf_value_t *value, uint32_t index) + const nxt_conf_value_t *value, uint32_t index) { nxt_conf_object_member_t *member; @@ -367,7 +367,7 @@ nxt_conf_create_array(nxt_mp_t *mp, nxt_uint_t count) void nxt_conf_set_element(nxt_conf_value_t *array, nxt_uint_t index, - nxt_conf_value_t *value) + const nxt_conf_value_t *value) { array->u.array->elements[index] = *value; } @@ -1271,7 +1271,7 @@ nxt_conf_json_parse(nxt_mp_t *mp, u_char *start, u_char *end, static u_char * -nxt_conf_json_skip_space(u_char *start, u_char *end) +nxt_conf_json_skip_space(u_char *start, const u_char *end) { u_char *p, ch; @@ -2605,7 +2605,7 @@ nxt_conf_json_escape(u_char *dst, u_char *src, size_t size) void -nxt_conf_json_position(u_char *start, u_char *pos, nxt_uint_t *line, +nxt_conf_json_position(u_char *start, const u_char *pos, nxt_uint_t *line, nxt_uint_t *column) { u_char *p; diff --git a/src/nxt_conf.h b/src/nxt_conf.h index cfbc599..46effac 100644 --- a/src/nxt_conf.h +++ b/src/nxt_conf.h @@ -109,7 +109,7 @@ size_t nxt_conf_json_length(nxt_conf_value_t *value, nxt_conf_json_pretty_t *pretty); u_char *nxt_conf_json_print(u_char *p, nxt_conf_value_t *value, nxt_conf_json_pretty_t *pretty); -void nxt_conf_json_position(u_char *start, u_char *pos, nxt_uint_t *line, +void nxt_conf_json_position(u_char *start, const u_char *pos, nxt_uint_t *line, nxt_uint_t *column); nxt_int_t nxt_conf_validate(nxt_conf_validation_t *vldt); @@ -125,7 +125,7 @@ NXT_EXPORT uint8_t nxt_conf_get_boolean(nxt_conf_value_t *value); NXT_EXPORT nxt_uint_t nxt_conf_object_members_count(nxt_conf_value_t *value); nxt_conf_value_t *nxt_conf_create_object(nxt_mp_t *mp, nxt_uint_t count); void nxt_conf_set_member(nxt_conf_value_t *object, nxt_str_t *name, - nxt_conf_value_t *value, uint32_t index); + const nxt_conf_value_t *value, uint32_t index); void nxt_conf_set_member_string(nxt_conf_value_t *object, nxt_str_t *name, nxt_str_t *value, uint32_t index); nxt_int_t nxt_conf_set_member_string_dup(nxt_conf_value_t *object, nxt_mp_t *mp, @@ -137,7 +137,7 @@ void nxt_conf_set_member_null(nxt_conf_value_t *object, nxt_str_t *name, nxt_conf_value_t *nxt_conf_create_array(nxt_mp_t *mp, nxt_uint_t count); void nxt_conf_set_element(nxt_conf_value_t *array, nxt_uint_t index, - nxt_conf_value_t *value); + const nxt_conf_value_t *value); nxt_int_t nxt_conf_set_element_string_dup(nxt_conf_value_t *array, nxt_mp_t *mp, nxt_uint_t index, nxt_str_t *value); NXT_EXPORT nxt_uint_t nxt_conf_array_elements_count(nxt_conf_value_t *value); diff --git a/src/nxt_http.h b/src/nxt_http.h index 37c2732..218d453 100644 --- a/src/nxt_http.h +++ b/src/nxt_http.h @@ -370,8 +370,9 @@ nxt_int_t nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_http_action_t *action, nxt_http_action_conf_t *acf); nxt_int_t nxt_http_static_mtypes_init(nxt_mp_t *mp, nxt_lvlhsh_t *hash); nxt_int_t nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash, - nxt_str_t *exten, nxt_str_t *type); -nxt_str_t *nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, nxt_str_t *exten); + const nxt_str_t *exten, nxt_str_t *type); +nxt_str_t *nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, + const nxt_str_t *exten); nxt_http_action_t *nxt_http_application_handler(nxt_task_t *task, nxt_http_request_t *r, nxt_http_action_t *action); diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c index 1ab6cc9..1bb4291 100644 --- a/src/nxt_http_parse.c +++ b/src/nxt_http_parse.c @@ -8,16 +8,16 @@ static nxt_int_t nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, - u_char **pos, u_char *end); + u_char **pos, const u_char *end); static nxt_int_t nxt_http_parse_request_line(nxt_http_request_parse_t *rp, - u_char **pos, u_char *end); + u_char **pos, const u_char *end); static nxt_int_t nxt_http_parse_field_name(nxt_http_request_parse_t *rp, - u_char **pos, u_char *end); + u_char **pos, const u_char *end); static nxt_int_t nxt_http_parse_field_value(nxt_http_request_parse_t *rp, - u_char **pos, u_char *end); -static u_char *nxt_http_lookup_field_end(u_char *p, u_char *end); + u_char **pos, const u_char *end); +static u_char *nxt_http_lookup_field_end(u_char *p, const u_char *end); static nxt_int_t nxt_http_parse_field_end(nxt_http_request_parse_t *rp, - u_char **pos, u_char *end); + u_char **pos, const u_char *end); static nxt_int_t nxt_http_parse_complex_target(nxt_http_request_parse_t *rp); @@ -62,7 +62,7 @@ static const uint8_t nxt_http_target_chars[256] nxt_aligned(64) = { nxt_inline nxt_http_target_traps_e -nxt_http_parse_target(u_char **pos, u_char *end) +nxt_http_parse_target(u_char **pos, const u_char *end) { u_char *p; nxt_uint_t trap; @@ -158,7 +158,7 @@ nxt_http_parse_fields(nxt_http_request_parse_t *rp, nxt_buf_mem_t *b) static nxt_int_t nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos, - u_char *end) + const u_char *end) { u_char *p, ch, *after_slash, *args; nxt_int_t rc; @@ -479,7 +479,7 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos, static nxt_int_t nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, u_char **pos, - u_char *end) + const u_char *end) { u_char *p, ch; @@ -517,7 +517,7 @@ nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, u_char **pos, static nxt_int_t nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos, - u_char *end) + const u_char *end) { u_char *p, c; size_t len; @@ -624,7 +624,7 @@ nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos, static nxt_int_t nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos, - u_char *end) + const u_char *end) { u_char *p, *start, ch; size_t len; @@ -704,7 +704,7 @@ nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos, static u_char * -nxt_http_lookup_field_end(u_char *p, u_char *end) +nxt_http_lookup_field_end(u_char *p, const u_char *end) { while (nxt_fast_path(end - p >= 16)) { @@ -771,7 +771,7 @@ nxt_http_lookup_field_end(u_char *p, u_char *end) static nxt_int_t nxt_http_parse_field_end(nxt_http_request_parse_t *rp, u_char **pos, - u_char *end) + const u_char *end) { u_char *p; nxt_http_field_t *field; diff --git a/src/nxt_http_parse.h b/src/nxt_http_parse.h index 3cd9bd1..2b71446 100644 --- a/src/nxt_http_parse.h +++ b/src/nxt_http_parse.h @@ -35,7 +35,7 @@ typedef union { struct nxt_http_request_parse_s { nxt_int_t (*handler)(nxt_http_request_parse_t *rp, - u_char **pos, u_char *end); + u_char **pos, const u_char *end); nxt_str_t method; diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c index 0eacf62..df17fd2 100644 --- a/src/nxt_http_request.c +++ b/src/nxt_http_request.c @@ -26,11 +26,11 @@ static u_char *nxt_http_date_cache_handler(u_char *buf, nxt_realtime_t *now, static nxt_http_name_value_t *nxt_http_argument(nxt_array_t *array, u_char *name, size_t name_length, uint32_t hash, u_char *start, - u_char *end); + const u_char *end); static nxt_int_t nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, - u_char *end); + const u_char *end); static nxt_http_name_value_t *nxt_http_cookie(nxt_array_t *array, u_char *name, - size_t name_length, u_char *start, u_char *end); + size_t name_length, u_char *start, const u_char *end); #define NXT_HTTP_COOKIE_HASH \ @@ -876,7 +876,7 @@ nxt_http_arguments_parse(nxt_http_request_t *r) static nxt_http_name_value_t * nxt_http_argument(nxt_array_t *array, u_char *name, size_t name_length, - uint32_t hash, u_char *start, u_char *end) + uint32_t hash, u_char *start, const u_char *end) { size_t length; nxt_http_name_value_t *nv; @@ -945,7 +945,7 @@ nxt_http_cookies_parse(nxt_http_request_t *r) static nxt_int_t -nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, u_char *end) +nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, const u_char *end) { size_t name_length; u_char c, *p, *name; @@ -994,7 +994,7 @@ nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, u_char *end) static nxt_http_name_value_t * nxt_http_cookie(nxt_array_t *array, u_char *name, size_t name_length, - u_char *start, u_char *end) + u_char *start, const u_char *end) { u_char c, *p; uint32_t hash; diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 61dd0cb..7c7991f 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -1023,7 +1023,7 @@ typedef struct { nxt_int_t nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash, - nxt_str_t *exten, nxt_str_t *type) + const nxt_str_t *exten, nxt_str_t *type) { nxt_lvlhsh_query_t lhq; nxt_http_static_mtype_t *mtype; @@ -1048,7 +1048,7 @@ nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash, nxt_str_t * -nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, nxt_str_t *exten) +nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, const nxt_str_t *exten) { nxt_lvlhsh_query_t lhq; nxt_http_static_mtype_t *mtype; diff --git a/src/nxt_mp.c b/src/nxt_mp.c index d0de2c0..2bd8cde 100644 --- a/src/nxt_mp.c +++ b/src/nxt_mp.c @@ -155,7 +155,7 @@ static void *nxt_mp_alloc_large(nxt_mp_t *mp, size_t alignment, size_t size, nxt_bool_t freeable); static intptr_t nxt_mp_rbtree_compare(nxt_rbtree_node_t *node1, nxt_rbtree_node_t *node2); -static nxt_mp_block_t *nxt_mp_find_block(nxt_rbtree_t *tree, u_char *p); +static nxt_mp_block_t *nxt_mp_find_block(nxt_rbtree_t *tree, const u_char *p); static const char *nxt_mp_chunk_free(nxt_mp_t *mp, nxt_mp_block_t *cluster, u_char *p); @@ -830,7 +830,7 @@ nxt_mp_free(nxt_mp_t *mp, void *p) static nxt_mp_block_t * -nxt_mp_find_block(nxt_rbtree_t *tree, u_char *p) +nxt_mp_find_block(nxt_rbtree_t *tree, const u_char *p) { nxt_mp_block_t *block; nxt_rbtree_node_t *node, *sentinel; diff --git a/src/nxt_port_memory_int.h b/src/nxt_port_memory_int.h index c84615d..21a05b1 100644 --- a/src/nxt_port_memory_int.h +++ b/src/nxt_port_memory_int.h @@ -100,7 +100,7 @@ nxt_inline void nxt_port_mmap_set_chunk_free(nxt_free_map_t *m, nxt_chunk_id_t c); nxt_inline nxt_chunk_id_t -nxt_port_mmap_chunk_id(nxt_port_mmap_header_t *hdr, u_char *p) +nxt_port_mmap_chunk_id(nxt_port_mmap_header_t *hdr, const u_char *p) { u_char *mm_start; diff --git a/src/nxt_port_socket.c b/src/nxt_port_socket.c index 2a51dfb..5752d5a 100644 --- a/src/nxt_port_socket.c +++ b/src/nxt_port_socket.c @@ -19,7 +19,7 @@ static uint8_t nxt_port_enqueue_buf(nxt_task_t *task, nxt_port_msg_t *pm, void *qbuf, nxt_buf_t *b); static nxt_int_t nxt_port_msg_chk_insert(nxt_task_t *task, nxt_port_t *port, nxt_port_send_msg_t *msg); -static nxt_port_send_msg_t *nxt_port_msg_alloc(nxt_port_send_msg_t *m); +static nxt_port_send_msg_t *nxt_port_msg_alloc(const nxt_port_send_msg_t *m); static void nxt_port_write_handler(nxt_task_t *task, void *obj, void *data); static nxt_port_send_msg_t *nxt_port_msg_first(nxt_port_t *port); nxt_inline void nxt_port_msg_close_fd(nxt_port_send_msg_t *msg); @@ -332,7 +332,7 @@ nxt_port_msg_chk_insert(nxt_task_t *task, nxt_port_t *port, static nxt_port_send_msg_t * -nxt_port_msg_alloc(nxt_port_send_msg_t *m) +nxt_port_msg_alloc(const nxt_port_send_msg_t *m) { nxt_port_send_msg_t *msg; diff --git a/src/nxt_string.c b/src/nxt_string.c index b7aef79..4d89c23 100644 --- a/src/nxt_string.c +++ b/src/nxt_string.c @@ -338,7 +338,7 @@ nxt_rmemstrn(const u_char *s, const u_char *end, const char *ss, size_t length) size_t -nxt_str_strip(u_char *start, u_char *end) +nxt_str_strip(const u_char *start, u_char *end) { u_char *p; diff --git a/src/nxt_string.h b/src/nxt_string.h index 80cdbb5..a8673c6 100644 --- a/src/nxt_string.h +++ b/src/nxt_string.h @@ -96,7 +96,7 @@ NXT_EXPORT u_char *nxt_memcasestrn(const u_char *s, const u_char *end, const char *ss, size_t length); NXT_EXPORT u_char *nxt_rmemstrn(const u_char *s, const u_char *end, const char *ss, size_t length); -NXT_EXPORT size_t nxt_str_strip(u_char *start, u_char *end); +NXT_EXPORT size_t nxt_str_strip(const u_char *start, u_char *end); typedef struct { diff --git a/src/nxt_unit.c b/src/nxt_unit.c index f183ac6..4be0906 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -196,7 +196,8 @@ static int nxt_unit_request_hash_add(nxt_unit_ctx_t *ctx, static nxt_unit_request_info_t *nxt_unit_request_hash_find( nxt_unit_ctx_t *ctx, uint32_t stream, int remove); -static char * nxt_unit_snprint_prefix(char *p, char *end, pid_t pid, int level); +static char * nxt_unit_snprint_prefix(char *p, const char *end, pid_t pid, + int level); static void *nxt_unit_lvlhsh_alloc(void *data, size_t size); static void nxt_unit_lvlhsh_free(void *data, void *p); static int nxt_unit_memcasecmp(const void *p1, const void *p2, size_t length); @@ -6666,7 +6667,7 @@ static const char * nxt_unit_log_levels[] = { static char * -nxt_unit_snprint_prefix(char *p, char *end, pid_t pid, int level) +nxt_unit_snprint_prefix(char *p, const char *end, pid_t pid, int level) { struct tm tm; struct timespec ts; -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:01:00 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:01:00 +0100 Subject: [PATCH 10/11] HTTP: removed unused nxt_http_cookie_t structure. In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-11-andrew@digital-domain.net> Turns out that struct nxt_http_cookie_t is completely unused. --- src/nxt_http_route.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index f702399..d1fe298 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -79,15 +79,6 @@ typedef struct { } nxt_http_route_pattern_t; -typedef struct { - uint16_t hash; - uint16_t name_length; - uint32_t value_length; - u_char *name; - u_char *value; -} nxt_http_cookie_t; - - struct nxt_http_route_rule_s { /* The object must be the first field. */ nxt_http_route_object_t object:8; -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:00:57 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:57 +0100 Subject: [PATCH 07/11] Route: avoided undefined behaviour. In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-8-andrew@digital-domain.net> In src/nxt_http_route_addr.c::nxt_http_route_addr_pattern_parse() there was potentially undefined behaviour when shifting a 32 bit value by 32 bits, this could happen if cidr_prefix was 0. Promote the shiftee to unsigned long to avoid this issue. --- src/nxt_http_route_addr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nxt_http_route_addr.c b/src/nxt_http_route_addr.c index 2907a90..67c781a 100644 --- a/src/nxt_http_route_addr.c +++ b/src/nxt_http_route_addr.c @@ -233,7 +233,7 @@ nxt_http_route_addr_pattern_parse(nxt_mp_t *mp, } addr.length = delim - addr.start; - inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFF << (32 - cidr_prefix))); + inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFFUL << (32 - cidr_prefix))); inet->start = nxt_inet_addr(addr.start, addr.length) & inet->end; if (nxt_slow_path(inet->start == INADDR_NONE)) { -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:00:58 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:58 +0100 Subject: [PATCH 08/11] Unit: avoided needlessly setting lib in nxt_unit_shm_open(). In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-9-andrew@digital-domain.net> As was pointed out by the cppcheck[0] static code analysis utility, lib was being set in nxt_unit_shm_open() regardless of platform when in fact it's only used when (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN). Move the variable declaration & definition to be within the #if (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN) block. [0]: https://cppcheck.sourceforge.io/ --- src/nxt_unit.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/nxt_unit.c b/src/nxt_unit.c index 4be0906..9baa680 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -3813,13 +3813,12 @@ static int nxt_unit_shm_open(nxt_unit_ctx_t *ctx, size_t size) { int fd; - nxt_unit_impl_t *lib; - - lib = nxt_container_of(ctx->unit, nxt_unit_impl_t, unit); #if (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN) char name[64]; + nxt_unit_impl_t *lib; + lib = nxt_container_of(ctx->unit, nxt_unit_impl_t, unit); snprintf(name, sizeof(name), NXT_SHM_PREFIX "unit.%d.%p", lib->pid, (void *) (uintptr_t) pthread_self()); #endif -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:01:01 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:01:01 +0100 Subject: [PATCH 11/11] Unit: removed a useless assignment. In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-12-andrew@digital-domain.net> As was pointed out by the cppcheck[0] static code analysis utility there was a useless assignment in nxt_unit_request_read(). The size parameter is passed in by value and was being modified without being used again. [0]: https://cppcheck.sourceforge.io/ --- src/nxt_unit.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nxt_unit.c b/src/nxt_unit.c index 9baa680..fd086b2 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -3076,7 +3076,6 @@ nxt_unit_request_read(nxt_unit_request_info_t *req, void *dst, size_t size) } req->content_length -= res; - size -= res; dst = nxt_pointer_to(dst, res); -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:00:53 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:53 +0100 Subject: [PATCH 03/11] Marked a couple of variables 'const'. In-Reply-To: <20220616010101.55677-1-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> Message-ID: <20220616010101.55677-4-andrew@digital-domain.net> As was pointed out by the cppcheck[0] static code analysis utility we can mark a couple of variables as 'const'. This acts as a hint to the compiler about our intentions and the compiler will tell us when we deviate from them. [0]: https://cppcheck.sourceforge.io/ --- src/nxt_time_parse.c | 2 +- src/nxt_websocket_accept.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nxt_time_parse.c b/src/nxt_time_parse.c index 94c4328..63620b0 100644 --- a/src/nxt_time_parse.c +++ b/src/nxt_time_parse.c @@ -22,7 +22,7 @@ nxt_time_parse(const u_char *p, size_t len) nxt_uint_t year, days; const u_char *end; - static nxt_int_t mday[12] = { + static const nxt_int_t mday[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; diff --git a/src/nxt_websocket_accept.c b/src/nxt_websocket_accept.c index 05cbcb5..0e2cef5 100644 --- a/src/nxt_websocket_accept.c +++ b/src/nxt_websocket_accept.c @@ -11,8 +11,8 @@ static void nxt_websocket_base64_encode(u_char *d, const uint8_t *s, size_t len) { - u_char c0, c1, c2; - static u_char basis[] = + u_char c0, c1, c2; + static const u_char basis[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; while (len > 2) { -- 2.36.1 From andrew at digital-domain.net Thu Jun 16 01:00:50 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 02:00:50 +0100 Subject: [PATCH 00/11] Various fixes/cleanups Message-ID: <20220616010101.55677-1-andrew@digital-domain.net> One of my favourite tools is the cppcheck[0] static code analyser. Running it on the Unit code base threw up numerous items of interest. These patches cover the following - arithOperationsOnVoidPointer Array: avoided void pointer arithmetic in nxt_array_copy(). - constParameter Constified numerous function parameters. - constVariable Marked a couple of variables 'const'. - knownConditionTrueFalse Port: removed useless msg->cancelled == 0 checks. Socket: removed useless port < 1 check. - overlappingWriteUnion Sptr: avoided potentially undefined behaviour. - shiftTooManyBits Route: avoided undefined behaviour. - unreadVariable Unit: avoided needlessly setting lib in nxt_unit_shm_open(). - unusedStructMember HTTP: removed unused nxt_http_cookie_t structure. Router: removed unused structure member proxy_buffers. - uselessAssignmentArg Unit: removed a useless assignment. I'm posting this patch series to get some initial review/feedback before opening a pull-request. All the tests under src/test continue to build and pytest runs successfully ======================= 91 passed, 687 skipped in 27.35s ======================= Hopefully things are split up enough to ease review and if somethings are not required, not wanted or just plain wrong they should be easily dropped. Andrew [0]: https://cppcheck.sourceforge.io/ Andrew Clayton (11): Array: avoided void pointer arithmetic in nxt_array_copy(). Constified numerous function parameters. Marked a couple of variables 'const'. Port: removed useless msg->cancelled == 0 checks. Socket: removed useless port < 1 check. Sptr: avoided potentially undefined behaviour. Route: avoided undefined behaviour. Unit: avoided needlessly setting lib in nxt_unit_shm_open(). Router: removed unused structure member proxy_buffers. HTTP: removed unused nxt_http_cookie_t structure. Unit: removed a useless assignment. src/nxt_array.c | 2 +- src/nxt_conf.c | 10 +++++----- src/nxt_conf.h | 6 +++--- src/nxt_http.h | 5 +++-- src/nxt_http_parse.c | 26 +++++++++++++------------- src/nxt_http_parse.h | 2 +- src/nxt_http_request.c | 12 ++++++------ src/nxt_http_route.c | 9 --------- src/nxt_http_route_addr.c | 2 +- src/nxt_http_static.c | 4 ++-- src/nxt_mp.c | 4 ++-- src/nxt_port_memory_int.h | 2 +- src/nxt_port_socket.c | 31 ++++++++++++------------------- src/nxt_router.c | 1 - src/nxt_router.h | 1 - src/nxt_sockaddr.c | 2 +- src/nxt_string.c | 2 +- src/nxt_string.h | 2 +- src/nxt_time_parse.c | 2 +- src/nxt_unit.c | 11 +++++------ src/nxt_unit_sptr.h | 5 ++++- src/nxt_websocket_accept.c | 4 ++-- 22 files changed, 65 insertions(+), 80 deletions(-) -- 2.36.1 From max.romanov at gmail.com Thu Jun 16 10:35:12 2022 From: max.romanov at gmail.com (Max Romanov) Date: Thu, 16 Jun 2022 13:35:12 +0300 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <20220616010101.55677-7-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-7-andrew@digital-domain.net> Message-ID: Hello, This patch is useless. Please try to understand the structure of sptr_t before made such changes. How extra assignment to temporary variable may change undefined behavior to defined? This change was made just to shut the cppcheck which warning is a false positive. -- Max -----Original Message----- From: Andrew Clayton To: unit at nginx.org Sent: чт, 16 июн. 2022 4:02 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In src/nxt_unit_sptr.h::nxt_unit_sptr_set() we are setting one member of a union based on another member which cppcheck[0] flags as undefined behaviour src/nxt_unit_sptr.h:27:18: error: Overlapping read/write of union is undefined behavior [overlappingWriteUnion] sptr->offset = (uint8_t *) ptr - sptr->base; ^ I think this warning is correct as I can't see where we are setting sptr->base beforehand which I think would make this defined behaviour. To avoid any doubts take a copy of sptr->base and then use that value in the above. [0]: https://cppcheck.sourceforge.io/ --- src/nxt_unit_sptr.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nxt_unit_sptr.h b/src/nxt_unit_sptr.h index 314416e..6d867a5 100644 --- a/src/nxt_unit_sptr.h +++ b/src/nxt_unit_sptr.h @@ -24,7 +24,10 @@ union nxt_unit_sptr_u { static inline void nxt_unit_sptr_set(nxt_unit_sptr_t *sptr, void *ptr) { - sptr->offset = (uint8_t *) ptr - sptr->base; + const uint8_t *base; + + base = sptr->base; + sptr->offset = (uint8_t *) ptr - base; } -- 2.36.1 _______________________________________________ unit mailing list -- unit at nginx.org To unsubscribe send an email to unit-leave at nginx.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew at digital-domain.net Thu Jun 16 15:03:38 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 16:03:38 +0100 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-7-andrew@digital-domain.net> Message-ID: <20220616160338.2466a9e5@kappa.digital-domain.net> On Thu, 16 Jun 2022 13:35:12 +0300 Max Romanov wrote: > Hello, Thanks for the review! > This patch is useless. Please try to understand the structure of sptr_t before made such changes. Yes, that union is a bit of a head scratcher! ;) > How extra assignment to temporary variable may change undefined behavior to defined? The idea was to avoid undefined memory ordering. > This change was made just to shut the cppcheck which warning is a false positive. So it wasn't just to shut up cppcheck, I already filtered out many false positives. This one was a bit tricky to nail down but between SO[0], the C(11) standard[1] and cppcheck I came down on the side of it being UB, due to thinking that the ordering of the read and write of the two union members was UB. So if we're sure that it is indeed OK, then this can simply be dropped. No problem. Cheers, Andrew [0]: https://stackoverflow.com/questions/33291146/c-c-unions-and-undefined-behaviour/33291213#33291213 [1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf From alx.manpages at gmail.com Thu Jun 16 15:32:22 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:32:22 +0200 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <20220616160338.2466a9e5@kappa.digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-7-andrew@digital-domain.net> <20220616160338.2466a9e5@kappa.digital-domain.net> Message-ID: <53004cc7-eb00-323b-3ec7-26162998fc27@gmail.com> Hi Andrew, and Max, On 6/16/22 17:03, Andrew Clayton wrote: > On Thu, 16 Jun 2022 13:35:12 +0300 > Max Romanov wrote: > >> Hello, > > Thanks for the review! > >> This patch is useless. Please try to understand the structure of sptr_t before made such changes. > > Yes, that union is a bit of a head scratcher! ;) > >> How extra assignment to temporary variable may change undefined behavior to defined? > > The idea was to avoid undefined memory ordering. Hmmm, AFAIR, `u.a = u.b + 1;` is fine, since the = creates a sequence point, isn't it? The only possible problem would be if the union hadn't been initialized, but that's a completely different story, and this wouldn't fix it :) Cheers, Alex From alx.manpages at gmail.com Thu Jun 16 15:41:02 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:41:02 +0200 Subject: [PATCH 01/11] Array: avoided void pointer arithmetic in nxt_array_copy(). In-Reply-To: <20220616010101.55677-2-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-2-andrew@digital-domain.net> Message-ID: <6604d061-e2cc-7971-5446-44058284c359@gmail.com> Hi Andrew, On 6/16/22 03:00, Andrew Clayton wrote: > As was pointed out by the cppcheck[0] static code analysis utility we > were doing void pointer arithmetic on src->elts which is technically > undefined behaviour. > > While GCC allows this by treating the size of void as 1[1]. Same with > Clang. Other compilers I'm not sure about, so lets just be safe and cast > src->nelts to (char *) where sizeof(char) is guaranteed to be 1. > > [0]: https://cppcheck.sourceforge.io/ > [1]: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html That is one of the GNU extensions I wish was in the standard, at least in POSIX. I hate casts for the danger they pose by shutting (almost) all warnings off, and I think that danger is more real than the possible dangers caused by pointer arithmetics on `void *`. In fact, the worst thing that could happen would be that the compiler refuses to compile, but if it compiles, it's almost forced to use `char *` rules, due to: 6.2.5-27: A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. Since we seem to have support from all compilers we care (otherwise one would have already complained), I prefer not fixing this. So, wontfix? :) Cheers, Alex BTW, if you would like to CC me in patches to the mailing list, it would help me notice them. > --- > src/nxt_array.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/nxt_array.c b/src/nxt_array.c > index 1e13c22..0a7945e 100644 > --- a/src/nxt_array.c > +++ b/src/nxt_array.c > @@ -140,7 +140,7 @@ nxt_array_copy(nxt_mp_t *mp, nxt_array_t *dst, nxt_array_t *src) > return NULL; > } > > - nxt_memcpy(data, src->elts + (i * size), size); > + nxt_memcpy(data, (char *) src->elts + (i * size), size); > } > } > -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 15:45:01 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:45:01 +0200 Subject: [PATCH 02/11] Constified numerous function parameters. In-Reply-To: <20220616010101.55677-3-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-3-andrew@digital-domain.net> Message-ID: Hi Andrew, On 6/16/22 03:00, Andrew Clayton wrote: > As was pointed out by the cppcheck[0] static code analysis utility we > can mark numerous function parameters as 'const'. This acts as a hint to > the compiler about our intentions and the compiler will tell us when we > deviate from them. > > [0]: https://cppcheck.sourceforge.io/ From my side, as long as it compiles, and doesn't require any casts, `const` is always welcome. I'm actually surprised that only 41 lines were changed with this. Reviewed-by: Alejandro Colomar (We don't use those in the commit logs, but just to state that I reviewed it). Cheers, Alex > --- > src/nxt_conf.c | 10 +++++----- > src/nxt_conf.h | 6 +++--- > src/nxt_http.h | 5 +++-- > src/nxt_http_parse.c | 26 +++++++++++++------------- > src/nxt_http_parse.h | 2 +- > src/nxt_http_request.c | 12 ++++++------ > src/nxt_http_static.c | 4 ++-- > src/nxt_mp.c | 4 ++-- > src/nxt_port_memory_int.h | 2 +- > src/nxt_port_socket.c | 4 ++-- > src/nxt_string.c | 2 +- > src/nxt_string.h | 2 +- > src/nxt_unit.c | 5 +++-- > 13 files changed, 43 insertions(+), 41 deletions(-) > > diff --git a/src/nxt_conf.c b/src/nxt_conf.c > index 79e776a..a44b8c7 100644 > --- a/src/nxt_conf.c > +++ b/src/nxt_conf.c > @@ -102,7 +102,7 @@ typedef struct { > static nxt_int_t nxt_conf_path_next_token(nxt_conf_path_parse_t *parse, > nxt_str_t *token); > > -static u_char *nxt_conf_json_skip_space(u_char *start, u_char *end); > +static u_char *nxt_conf_json_skip_space(u_char *start, const u_char *end); > static u_char *nxt_conf_json_parse_value(nxt_mp_t *mp, nxt_conf_value_t *value, > u_char *start, u_char *end, nxt_conf_json_error_t *error); > static u_char *nxt_conf_json_parse_object(nxt_mp_t *mp, nxt_conf_value_t *value, > @@ -266,7 +266,7 @@ nxt_conf_create_object(nxt_mp_t *mp, nxt_uint_t count) > > void > nxt_conf_set_member(nxt_conf_value_t *object, nxt_str_t *name, > - nxt_conf_value_t *value, uint32_t index) > + const nxt_conf_value_t *value, uint32_t index) > { > nxt_conf_object_member_t *member; > > @@ -367,7 +367,7 @@ nxt_conf_create_array(nxt_mp_t *mp, nxt_uint_t count) > > void > nxt_conf_set_element(nxt_conf_value_t *array, nxt_uint_t index, > - nxt_conf_value_t *value) > + const nxt_conf_value_t *value) > { > array->u.array->elements[index] = *value; > } > @@ -1271,7 +1271,7 @@ nxt_conf_json_parse(nxt_mp_t *mp, u_char *start, u_char *end, > > > static u_char * > -nxt_conf_json_skip_space(u_char *start, u_char *end) > +nxt_conf_json_skip_space(u_char *start, const u_char *end) > { > u_char *p, ch; > > @@ -2605,7 +2605,7 @@ nxt_conf_json_escape(u_char *dst, u_char *src, size_t size) > > > void > -nxt_conf_json_position(u_char *start, u_char *pos, nxt_uint_t *line, > +nxt_conf_json_position(u_char *start, const u_char *pos, nxt_uint_t *line, > nxt_uint_t *column) > { > u_char *p; > diff --git a/src/nxt_conf.h b/src/nxt_conf.h > index cfbc599..46effac 100644 > --- a/src/nxt_conf.h > +++ b/src/nxt_conf.h > @@ -109,7 +109,7 @@ size_t nxt_conf_json_length(nxt_conf_value_t *value, > nxt_conf_json_pretty_t *pretty); > u_char *nxt_conf_json_print(u_char *p, nxt_conf_value_t *value, > nxt_conf_json_pretty_t *pretty); > -void nxt_conf_json_position(u_char *start, u_char *pos, nxt_uint_t *line, > +void nxt_conf_json_position(u_char *start, const u_char *pos, nxt_uint_t *line, > nxt_uint_t *column); > > nxt_int_t nxt_conf_validate(nxt_conf_validation_t *vldt); > @@ -125,7 +125,7 @@ NXT_EXPORT uint8_t nxt_conf_get_boolean(nxt_conf_value_t *value); > NXT_EXPORT nxt_uint_t nxt_conf_object_members_count(nxt_conf_value_t *value); > nxt_conf_value_t *nxt_conf_create_object(nxt_mp_t *mp, nxt_uint_t count); > void nxt_conf_set_member(nxt_conf_value_t *object, nxt_str_t *name, > - nxt_conf_value_t *value, uint32_t index); > + const nxt_conf_value_t *value, uint32_t index); > void nxt_conf_set_member_string(nxt_conf_value_t *object, nxt_str_t *name, > nxt_str_t *value, uint32_t index); > nxt_int_t nxt_conf_set_member_string_dup(nxt_conf_value_t *object, nxt_mp_t *mp, > @@ -137,7 +137,7 @@ void nxt_conf_set_member_null(nxt_conf_value_t *object, nxt_str_t *name, > > nxt_conf_value_t *nxt_conf_create_array(nxt_mp_t *mp, nxt_uint_t count); > void nxt_conf_set_element(nxt_conf_value_t *array, nxt_uint_t index, > - nxt_conf_value_t *value); > + const nxt_conf_value_t *value); > nxt_int_t nxt_conf_set_element_string_dup(nxt_conf_value_t *array, nxt_mp_t *mp, > nxt_uint_t index, nxt_str_t *value); > NXT_EXPORT nxt_uint_t nxt_conf_array_elements_count(nxt_conf_value_t *value); > diff --git a/src/nxt_http.h b/src/nxt_http.h > index 37c2732..218d453 100644 > --- a/src/nxt_http.h > +++ b/src/nxt_http.h > @@ -370,8 +370,9 @@ nxt_int_t nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, > nxt_http_action_t *action, nxt_http_action_conf_t *acf); > nxt_int_t nxt_http_static_mtypes_init(nxt_mp_t *mp, nxt_lvlhsh_t *hash); > nxt_int_t nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash, > - nxt_str_t *exten, nxt_str_t *type); > -nxt_str_t *nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, nxt_str_t *exten); > + const nxt_str_t *exten, nxt_str_t *type); > +nxt_str_t *nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, > + const nxt_str_t *exten); > > nxt_http_action_t *nxt_http_application_handler(nxt_task_t *task, > nxt_http_request_t *r, nxt_http_action_t *action); > diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c > index 1ab6cc9..1bb4291 100644 > --- a/src/nxt_http_parse.c > +++ b/src/nxt_http_parse.c > @@ -8,16 +8,16 @@ > > > static nxt_int_t nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, > - u_char **pos, u_char *end); > + u_char **pos, const u_char *end); > static nxt_int_t nxt_http_parse_request_line(nxt_http_request_parse_t *rp, > - u_char **pos, u_char *end); > + u_char **pos, const u_char *end); > static nxt_int_t nxt_http_parse_field_name(nxt_http_request_parse_t *rp, > - u_char **pos, u_char *end); > + u_char **pos, const u_char *end); > static nxt_int_t nxt_http_parse_field_value(nxt_http_request_parse_t *rp, > - u_char **pos, u_char *end); > -static u_char *nxt_http_lookup_field_end(u_char *p, u_char *end); > + u_char **pos, const u_char *end); > +static u_char *nxt_http_lookup_field_end(u_char *p, const u_char *end); > static nxt_int_t nxt_http_parse_field_end(nxt_http_request_parse_t *rp, > - u_char **pos, u_char *end); > + u_char **pos, const u_char *end); > > static nxt_int_t nxt_http_parse_complex_target(nxt_http_request_parse_t *rp); > > @@ -62,7 +62,7 @@ static const uint8_t nxt_http_target_chars[256] nxt_aligned(64) = { > > > nxt_inline nxt_http_target_traps_e > -nxt_http_parse_target(u_char **pos, u_char *end) > +nxt_http_parse_target(u_char **pos, const u_char *end) > { > u_char *p; > nxt_uint_t trap; > @@ -158,7 +158,7 @@ nxt_http_parse_fields(nxt_http_request_parse_t *rp, nxt_buf_mem_t *b) > > static nxt_int_t > nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos, > - u_char *end) > + const u_char *end) > { > u_char *p, ch, *after_slash, *args; > nxt_int_t rc; > @@ -479,7 +479,7 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos, > > static nxt_int_t > nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, u_char **pos, > - u_char *end) > + const u_char *end) > { > u_char *p, ch; > > @@ -517,7 +517,7 @@ nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, u_char **pos, > > static nxt_int_t > nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos, > - u_char *end) > + const u_char *end) > { > u_char *p, c; > size_t len; > @@ -624,7 +624,7 @@ nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos, > > static nxt_int_t > nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos, > - u_char *end) > + const u_char *end) > { > u_char *p, *start, ch; > size_t len; > @@ -704,7 +704,7 @@ nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos, > > > static u_char * > -nxt_http_lookup_field_end(u_char *p, u_char *end) > +nxt_http_lookup_field_end(u_char *p, const u_char *end) > { > while (nxt_fast_path(end - p >= 16)) { > > @@ -771,7 +771,7 @@ nxt_http_lookup_field_end(u_char *p, u_char *end) > > static nxt_int_t > nxt_http_parse_field_end(nxt_http_request_parse_t *rp, u_char **pos, > - u_char *end) > + const u_char *end) > { > u_char *p; > nxt_http_field_t *field; > diff --git a/src/nxt_http_parse.h b/src/nxt_http_parse.h > index 3cd9bd1..2b71446 100644 > --- a/src/nxt_http_parse.h > +++ b/src/nxt_http_parse.h > @@ -35,7 +35,7 @@ typedef union { > > struct nxt_http_request_parse_s { > nxt_int_t (*handler)(nxt_http_request_parse_t *rp, > - u_char **pos, u_char *end); > + u_char **pos, const u_char *end); > > nxt_str_t method; > > diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c > index 0eacf62..df17fd2 100644 > --- a/src/nxt_http_request.c > +++ b/src/nxt_http_request.c > @@ -26,11 +26,11 @@ static u_char *nxt_http_date_cache_handler(u_char *buf, nxt_realtime_t *now, > > static nxt_http_name_value_t *nxt_http_argument(nxt_array_t *array, > u_char *name, size_t name_length, uint32_t hash, u_char *start, > - u_char *end); > + const u_char *end); > static nxt_int_t nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, > - u_char *end); > + const u_char *end); > static nxt_http_name_value_t *nxt_http_cookie(nxt_array_t *array, u_char *name, > - size_t name_length, u_char *start, u_char *end); > + size_t name_length, u_char *start, const u_char *end); > > > #define NXT_HTTP_COOKIE_HASH \ > @@ -876,7 +876,7 @@ nxt_http_arguments_parse(nxt_http_request_t *r) > > static nxt_http_name_value_t * > nxt_http_argument(nxt_array_t *array, u_char *name, size_t name_length, > - uint32_t hash, u_char *start, u_char *end) > + uint32_t hash, u_char *start, const u_char *end) > { > size_t length; > nxt_http_name_value_t *nv; > @@ -945,7 +945,7 @@ nxt_http_cookies_parse(nxt_http_request_t *r) > > > static nxt_int_t > -nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, u_char *end) > +nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, const u_char *end) > { > size_t name_length; > u_char c, *p, *name; > @@ -994,7 +994,7 @@ nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, u_char *end) > > static nxt_http_name_value_t * > nxt_http_cookie(nxt_array_t *array, u_char *name, size_t name_length, > - u_char *start, u_char *end) > + u_char *start, const u_char *end) > { > u_char c, *p; > uint32_t hash; > diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c > index 61dd0cb..7c7991f 100644 > --- a/src/nxt_http_static.c > +++ b/src/nxt_http_static.c > @@ -1023,7 +1023,7 @@ typedef struct { > > nxt_int_t > nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash, > - nxt_str_t *exten, nxt_str_t *type) > + const nxt_str_t *exten, nxt_str_t *type) > { > nxt_lvlhsh_query_t lhq; > nxt_http_static_mtype_t *mtype; > @@ -1048,7 +1048,7 @@ nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash, > > > nxt_str_t * > -nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, nxt_str_t *exten) > +nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, const nxt_str_t *exten) > { > nxt_lvlhsh_query_t lhq; > nxt_http_static_mtype_t *mtype; > diff --git a/src/nxt_mp.c b/src/nxt_mp.c > index d0de2c0..2bd8cde 100644 > --- a/src/nxt_mp.c > +++ b/src/nxt_mp.c > @@ -155,7 +155,7 @@ static void *nxt_mp_alloc_large(nxt_mp_t *mp, size_t alignment, size_t size, > nxt_bool_t freeable); > static intptr_t nxt_mp_rbtree_compare(nxt_rbtree_node_t *node1, > nxt_rbtree_node_t *node2); > -static nxt_mp_block_t *nxt_mp_find_block(nxt_rbtree_t *tree, u_char *p); > +static nxt_mp_block_t *nxt_mp_find_block(nxt_rbtree_t *tree, const u_char *p); > static const char *nxt_mp_chunk_free(nxt_mp_t *mp, nxt_mp_block_t *cluster, > u_char *p); > > @@ -830,7 +830,7 @@ nxt_mp_free(nxt_mp_t *mp, void *p) > > > static nxt_mp_block_t * > -nxt_mp_find_block(nxt_rbtree_t *tree, u_char *p) > +nxt_mp_find_block(nxt_rbtree_t *tree, const u_char *p) > { > nxt_mp_block_t *block; > nxt_rbtree_node_t *node, *sentinel; > diff --git a/src/nxt_port_memory_int.h b/src/nxt_port_memory_int.h > index c84615d..21a05b1 100644 > --- a/src/nxt_port_memory_int.h > +++ b/src/nxt_port_memory_int.h > @@ -100,7 +100,7 @@ nxt_inline void > nxt_port_mmap_set_chunk_free(nxt_free_map_t *m, nxt_chunk_id_t c); > > nxt_inline nxt_chunk_id_t > -nxt_port_mmap_chunk_id(nxt_port_mmap_header_t *hdr, u_char *p) > +nxt_port_mmap_chunk_id(nxt_port_mmap_header_t *hdr, const u_char *p) > { > u_char *mm_start; > > diff --git a/src/nxt_port_socket.c b/src/nxt_port_socket.c > index 2a51dfb..5752d5a 100644 > --- a/src/nxt_port_socket.c > +++ b/src/nxt_port_socket.c > @@ -19,7 +19,7 @@ static uint8_t nxt_port_enqueue_buf(nxt_task_t *task, nxt_port_msg_t *pm, > void *qbuf, nxt_buf_t *b); > static nxt_int_t nxt_port_msg_chk_insert(nxt_task_t *task, nxt_port_t *port, > nxt_port_send_msg_t *msg); > -static nxt_port_send_msg_t *nxt_port_msg_alloc(nxt_port_send_msg_t *m); > +static nxt_port_send_msg_t *nxt_port_msg_alloc(const nxt_port_send_msg_t *m); > static void nxt_port_write_handler(nxt_task_t *task, void *obj, void *data); > static nxt_port_send_msg_t *nxt_port_msg_first(nxt_port_t *port); > nxt_inline void nxt_port_msg_close_fd(nxt_port_send_msg_t *msg); > @@ -332,7 +332,7 @@ nxt_port_msg_chk_insert(nxt_task_t *task, nxt_port_t *port, > > > static nxt_port_send_msg_t * > -nxt_port_msg_alloc(nxt_port_send_msg_t *m) > +nxt_port_msg_alloc(const nxt_port_send_msg_t *m) > { > nxt_port_send_msg_t *msg; > > diff --git a/src/nxt_string.c b/src/nxt_string.c > index b7aef79..4d89c23 100644 > --- a/src/nxt_string.c > +++ b/src/nxt_string.c > @@ -338,7 +338,7 @@ nxt_rmemstrn(const u_char *s, const u_char *end, const char *ss, size_t length) > > > size_t > -nxt_str_strip(u_char *start, u_char *end) > +nxt_str_strip(const u_char *start, u_char *end) > { > u_char *p; > > diff --git a/src/nxt_string.h b/src/nxt_string.h > index 80cdbb5..a8673c6 100644 > --- a/src/nxt_string.h > +++ b/src/nxt_string.h > @@ -96,7 +96,7 @@ NXT_EXPORT u_char *nxt_memcasestrn(const u_char *s, const u_char *end, > const char *ss, size_t length); > NXT_EXPORT u_char *nxt_rmemstrn(const u_char *s, const u_char *end, > const char *ss, size_t length); > -NXT_EXPORT size_t nxt_str_strip(u_char *start, u_char *end); > +NXT_EXPORT size_t nxt_str_strip(const u_char *start, u_char *end); > > > typedef struct { > diff --git a/src/nxt_unit.c b/src/nxt_unit.c > index f183ac6..4be0906 100644 > --- a/src/nxt_unit.c > +++ b/src/nxt_unit.c > @@ -196,7 +196,8 @@ static int nxt_unit_request_hash_add(nxt_unit_ctx_t *ctx, > static nxt_unit_request_info_t *nxt_unit_request_hash_find( > nxt_unit_ctx_t *ctx, uint32_t stream, int remove); > > -static char * nxt_unit_snprint_prefix(char *p, char *end, pid_t pid, int level); > +static char * nxt_unit_snprint_prefix(char *p, const char *end, pid_t pid, > + int level); > static void *nxt_unit_lvlhsh_alloc(void *data, size_t size); > static void nxt_unit_lvlhsh_free(void *data, void *p); > static int nxt_unit_memcasecmp(const void *p1, const void *p2, size_t length); > @@ -6666,7 +6667,7 @@ static const char * nxt_unit_log_levels[] = { > > > static char * > -nxt_unit_snprint_prefix(char *p, char *end, pid_t pid, int level) > +nxt_unit_snprint_prefix(char *p, const char *end, pid_t pid, int level) > { > struct tm tm; > struct timespec ts; -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 15:45:50 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:45:50 +0200 Subject: [PATCH 03/11] Marked a couple of variables 'const'. In-Reply-To: <20220616010101.55677-4-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-4-andrew@digital-domain.net> Message-ID: On 6/16/22 03:00, Andrew Clayton wrote: > As was pointed out by the cppcheck[0] static code analysis utility we > can mark a couple of variables as 'const'. This acts as a hint to the > compiler about our intentions and the compiler will tell us when we > deviate from them. > > [0]: https://cppcheck.sourceforge.io/ Reviewed-by: Alejandro Colomar > --- > src/nxt_time_parse.c | 2 +- > src/nxt_websocket_accept.c | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/src/nxt_time_parse.c b/src/nxt_time_parse.c > index 94c4328..63620b0 100644 > --- a/src/nxt_time_parse.c > +++ b/src/nxt_time_parse.c > @@ -22,7 +22,7 @@ nxt_time_parse(const u_char *p, size_t len) > nxt_uint_t year, days; > const u_char *end; > > - static nxt_int_t mday[12] = { > + static const nxt_int_t mday[12] = { > 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 > }; > > diff --git a/src/nxt_websocket_accept.c b/src/nxt_websocket_accept.c > index 05cbcb5..0e2cef5 100644 > --- a/src/nxt_websocket_accept.c > +++ b/src/nxt_websocket_accept.c > @@ -11,8 +11,8 @@ > static void > nxt_websocket_base64_encode(u_char *d, const uint8_t *s, size_t len) > { > - u_char c0, c1, c2; > - static u_char basis[] = > + u_char c0, c1, c2; > + static const u_char basis[] = > "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; > > while (len > 2) { From alx.manpages at gmail.com Thu Jun 16 15:46:03 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:46:03 +0200 Subject: [PATCH 03/11] Marked a couple of variables 'const'. In-Reply-To: <20220616010101.55677-4-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-4-andrew@digital-domain.net> Message-ID: <14b187d6-41bc-d91f-d8a7-5ea539e6c159@gmail.com> On 6/16/22 03:00, Andrew Clayton wrote: > As was pointed out by the cppcheck[0] static code analysis utility we > can mark a couple of variables as 'const'. This acts as a hint to the > compiler about our intentions and the compiler will tell us when we > deviate from them. > > [0]: https://cppcheck.sourceforge.io/ Reviewed-by: Alejandro Colomar > --- > src/nxt_time_parse.c | 2 +- > src/nxt_websocket_accept.c | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/src/nxt_time_parse.c b/src/nxt_time_parse.c > index 94c4328..63620b0 100644 > --- a/src/nxt_time_parse.c > +++ b/src/nxt_time_parse.c > @@ -22,7 +22,7 @@ nxt_time_parse(const u_char *p, size_t len) > nxt_uint_t year, days; > const u_char *end; > > - static nxt_int_t mday[12] = { > + static const nxt_int_t mday[12] = { > 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 > }; > > diff --git a/src/nxt_websocket_accept.c b/src/nxt_websocket_accept.c > index 05cbcb5..0e2cef5 100644 > --- a/src/nxt_websocket_accept.c > +++ b/src/nxt_websocket_accept.c > @@ -11,8 +11,8 @@ > static void > nxt_websocket_base64_encode(u_char *d, const uint8_t *s, size_t len) > { > - u_char c0, c1, c2; > - static u_char basis[] = > + u_char c0, c1, c2; > + static const u_char basis[] = > "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; > > while (len > 2) { -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 15:51:30 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:51:30 +0200 Subject: [PATCH 04/11] Port: removed useless msg->cancelled == 0 checks. In-Reply-To: <20220616010101.55677-5-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-5-andrew@digital-domain.net> Message-ID: <841b008c-1848-ed0e-24f9-5191c7f69cd0@gmail.com> Hi Andrew, On 6/16/22 03:00, Andrew Clayton wrote: > In src/nxt_port_socket.c::nxt_port_read_msg_process() msg->cancelled is > set to 0 and is not touched again. > > However there are several checks for it being == 0 which are _always_ > true, so remove them. > > I'm assuming that this is functioning as intended and that setting > msg->cancelled to 0 is correct. > > msg->cancelled was set to 0 unconditionally in commit e227fc9 > ("Introducing application and port shared memory queues."), so I guess > the now redundant checks were simply missed for removal. This patch makes sense, but then, I guess we should go further and remove that field completely? I don't see it being used at all. Cheers, Alex alx at asus5775:~/src/nginx/unit$ grep -rn '[.>]cancelled' src/nxt_port_socket.c:1192: msg->cancelled = 0; src/nxt_port_socket.c:1202: if (nxt_fast_path(fmsg->cancelled == 0)) { src/nxt_port_socket.c:1240: if (msg->port_msg.mmap && msg->cancelled == 0) { src/nxt_port_socket.c:1254: if (nxt_fast_path(msg->cancelled == 0)) { src/nxt_port_socket.c:1264: if (nxt_fast_path(msg->cancelled == 0)) { src/nxt_port_rpc.c:516: msg.cancelled = 0; alx at asus5775:~/src/nginx/unit$ grep -rn '\bcancelled\b' | grep -v -e nodejs grep: build/src/nxt_process_title.o: binary file matches src/nxt_router.c:542: nxt_bool_t cancelled; src/nxt_router.c:555: cancelled = nxt_app_queue_cancel(app_port->queue, src/nxt_router.c:559: if (cancelled) { src/nxt_router.c:560: nxt_debug(task, "stream #%uD: cancelled by router", src/nxt_router.c:565: cancelled = 0; src/nxt_router.c:573: b->is_port_mmap_sent = cancelled == 0; src/nxt_router.c:581: return cancelled; src/nxt_router.c:4489: /* TODO cancel message and return if cancelled. */ src/nxt_port_socket.c:1192: msg->cancelled = 0; src/nxt_port_socket.c:1202: if (nxt_fast_path(fmsg->cancelled == 0)) { src/nxt_port_socket.c:1240: if (msg->port_msg.mmap && msg->cancelled == 0) { src/nxt_port_socket.c:1254: if (nxt_fast_path(msg->cancelled == 0)) { src/nxt_port_socket.c:1264: if (nxt_fast_path(msg->cancelled == 0)) { src/nxt_unit.c:6303: nxt_unit_debug(NULL, "app_queue_recv: message cancelled"); src/nxt_port_rpc.c:516: msg.cancelled = 0; src/nxt_port.h:203: nxt_bool_t cancelled; > --- > src/nxt_port_socket.c | 27 ++++++++++----------------- > 1 file changed, 10 insertions(+), 17 deletions(-) > > diff --git a/src/nxt_port_socket.c b/src/nxt_port_socket.c > index 5752d5a..2649e69 100644 > --- a/src/nxt_port_socket.c > +++ b/src/nxt_port_socket.c > @@ -1237,7 +1237,7 @@ nxt_port_read_msg_process(nxt_task_t *task, nxt_port_t *port, > } else { > if (nxt_slow_path(msg->port_msg.mf != 0)) { > > - if (msg->port_msg.mmap && msg->cancelled == 0) { > + if (msg->port_msg.mmap) { > nxt_port_mmap_read(task, msg); > b = msg->buf; > } > @@ -1251,25 +1251,18 @@ nxt_port_read_msg_process(nxt_task_t *task, nxt_port_t *port, > fmsg->port_msg.nf = 0; > fmsg->port_msg.mf = 0; > > - if (nxt_fast_path(msg->cancelled == 0)) { > - msg->buf = NULL; > - msg->fd[0] = -1; > - msg->fd[1] = -1; > - b = NULL; > + msg->buf = NULL; > + msg->fd[0] = -1; > + msg->fd[1] = -1; > + b = NULL; > > - } else { > - nxt_port_close_fds(msg->fd); > - } > } else { > - if (nxt_fast_path(msg->cancelled == 0)) { > - > - if (msg->port_msg.mmap) { > - nxt_port_mmap_read(task, msg); > - b = msg->buf; > - } > - > - port->handler(task, msg); > + if (msg->port_msg.mmap) { > + nxt_port_mmap_read(task, msg); > + b = msg->buf; > } > + > + port->handler(task, msg); > } > } > -- Alejandro Colomar From alx.manpages at gmail.com Thu Jun 16 15:52:42 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:52:42 +0200 Subject: [PATCH 05/11] Socket: removed useless port < 1 check. In-Reply-To: <20220616010101.55677-6-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-6-andrew@digital-domain.net> Message-ID: <6102279e-c29b-27b3-2c7a-6dee2cefeafb@gmail.com> On 6/16/22 03:00, Andrew Clayton wrote: > In src/nxt_sockaddr.c::nxt_job_sockaddr_inet_parse() there is a check > that port > 0 then there is a check that port < 1 || port > 65535, well > we _know_ it can't be less than 1. Reviewed-by: Alejandro Colomar > --- > src/nxt_sockaddr.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/nxt_sockaddr.c b/src/nxt_sockaddr.c > index 730428e..71e50e3 100644 > --- a/src/nxt_sockaddr.c > +++ b/src/nxt_sockaddr.c > @@ -1090,7 +1090,7 @@ nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs) > port = nxt_int_parse(host, length); > > if (port > 0) { > - if (port < 1 || port > 65535) { > + if (port > 65535) { > goto invalid_port; > } > -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 15:55:58 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:55:58 +0200 Subject: [PATCH 07/11] Route: avoided undefined behaviour. In-Reply-To: <20220616010101.55677-8-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-8-andrew@digital-domain.net> Message-ID: <0fae0f8e-01f9-7ac0-d8a6-ded82b9ff3b4@gmail.com> On 6/16/22 03:00, Andrew Clayton wrote: > In src/nxt_http_route_addr.c::nxt_http_route_addr_pattern_parse() there > was potentially undefined behaviour when shifting a 32 bit value by 32 > bits, this could happen if cidr_prefix was 0. > > Promote the shiftee to unsigned long to avoid this issue. > --- > src/nxt_http_route_addr.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/nxt_http_route_addr.c b/src/nxt_http_route_addr.c > index 2907a90..67c781a 100644 > --- a/src/nxt_http_route_addr.c > +++ b/src/nxt_http_route_addr.c > @@ -233,7 +233,7 @@ nxt_http_route_addr_pattern_parse(nxt_mp_t *mp, > } > > addr.length = delim - addr.start; > - inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFF << (32 - cidr_prefix))); > + inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFFUL << (32 - cidr_prefix))); Do we support platforms with 32-bit long? I'm not sure. To be safe, I'd use ULL. Makes sense? > > inet->start = nxt_inet_addr(addr.start, addr.length) & inet->end; > if (nxt_slow_path(inet->start == INADDR_NONE)) { -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 15:57:30 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:57:30 +0200 Subject: [PATCH 08/11] Unit: avoided needlessly setting lib in nxt_unit_shm_open(). In-Reply-To: <20220616010101.55677-9-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-9-andrew@digital-domain.net> Message-ID: <406a68c3-5c7c-8599-5a49-95b110ae8178@gmail.com> On 6/16/22 03:00, Andrew Clayton wrote: > As was pointed out by the cppcheck[0] static code analysis utility, lib > was being set in nxt_unit_shm_open() regardless of platform when in fact > it's only used when (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN). > > Move the variable declaration & definition to be within the > > #if (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN) > > block. > > [0]: https://cppcheck.sourceforge.io/ Reviewed-by: Alejandro Colomar > --- > src/nxt_unit.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/src/nxt_unit.c b/src/nxt_unit.c > index 4be0906..9baa680 100644 > --- a/src/nxt_unit.c > +++ b/src/nxt_unit.c > @@ -3813,13 +3813,12 @@ static int > nxt_unit_shm_open(nxt_unit_ctx_t *ctx, size_t size) > { > int fd; > - nxt_unit_impl_t *lib; > - > - lib = nxt_container_of(ctx->unit, nxt_unit_impl_t, unit); > > #if (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN) > char name[64]; > + nxt_unit_impl_t *lib; > > + lib = nxt_container_of(ctx->unit, nxt_unit_impl_t, unit); > snprintf(name, sizeof(name), NXT_SHM_PREFIX "unit.%d.%p", > lib->pid, (void *) (uintptr_t) pthread_self()); > #endif -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 15:59:25 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 17:59:25 +0200 Subject: [PATCH 09/11] Router: removed unused structure member proxy_buffers. In-Reply-To: <20220616010101.55677-10-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-10-andrew@digital-domain.net> Message-ID: <077bbf24-7f89-8df2-7a5a-be8966e2e9f2@gmail.com> On 6/16/22 03:00, Andrew Clayton wrote: > proxy_buffers is declared as a structure member of nxt_socket_conf_t and > is set in nxt_router_conf_create(), however it is not used anywhere. > > Removing it has the nice side effect of making the nxt_socket_conf_t > structure require one less cacheline (on x86-64 at least) as the summary > from pahole[0] shows > > Before > > /* size: 200, cachelines: 4, members: 25 */ > /* sum members: 185, holes: 3, sum holes: 15 */ > > After > > /* size: 192, cachelines: 3, members: 24 */ > /* sum members: 177, holes: 3, sum holes: 15 */ > > [0]: https://github.com/acmel/dwarves Reviewed-by: Alejandro Colomar > --- > src/nxt_router.c | 1 - > src/nxt_router.h | 1 - > 2 files changed, 2 deletions(-) > > diff --git a/src/nxt_router.c b/src/nxt_router.c > index 6b69b2c..b0f2ff1 100644 > --- a/src/nxt_router.c > +++ b/src/nxt_router.c > @@ -1840,7 +1840,6 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, > skcf->max_body_size = 8 * 1024 * 1024; > skcf->proxy_header_buffer_size = 64 * 1024; > skcf->proxy_buffer_size = 4096; > - skcf->proxy_buffers = 256; > skcf->idle_timeout = 180 * 1000; > skcf->header_read_timeout = 30 * 1000; > skcf->body_read_timeout = 30 * 1000; > diff --git a/src/nxt_router.h b/src/nxt_router.h > index 7e337d2..538e54e 100644 > --- a/src/nxt_router.h > +++ b/src/nxt_router.h > @@ -181,7 +181,6 @@ typedef struct { > size_t max_body_size; > size_t proxy_header_buffer_size; > size_t proxy_buffer_size; > - size_t proxy_buffers; > > nxt_msec_t idle_timeout; > nxt_msec_t header_read_timeout; -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 16:01:15 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 18:01:15 +0200 Subject: [PATCH 09/11] Router: removed unused structure member proxy_buffers. In-Reply-To: <20220616010101.55677-10-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-10-andrew@digital-domain.net> Message-ID: <6fdb2d3d-9e27-191f-1852-2f17ce524328@gmail.com> On 6/16/22 03:00, Andrew Clayton wrote: > proxy_buffers is declared as a structure member of nxt_socket_conf_t and > is set in nxt_router_conf_create(), however it is not used anywhere. > > Removing it has the nice side effect of making the nxt_socket_conf_t > structure require one less cacheline (on x86-64 at least) as the summary > from pahole[0] shows > > Before > > /* size: 200, cachelines: 4, members: 25 */ > /* sum members: 185, holes: 3, sum holes: 15 */ > > After > > /* size: 192, cachelines: 3, members: 24 */ > /* sum members: 177, holes: 3, sum holes: 15 */ > > [0]: https://github.com/acmel/dwarves BTW, I didn't know about pahole(1). It would be nice to show the command invocation before the command output, to see how it works :) Kind of: $ echo foo foo Cheers, Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 16:03:38 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 18:03:38 +0200 Subject: [PATCH 10/11] HTTP: removed unused nxt_http_cookie_t structure. In-Reply-To: <20220616010101.55677-11-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-11-andrew@digital-domain.net> Message-ID: <1ed4df9e-bbce-fd37-4701-fa009dd8a249@gmail.com> Hi Andrew, On 6/16/22 03:01, Andrew Clayton wrote: > Turns out that struct nxt_http_cookie_t is completely unused. I think this was added to give support to a future feature that will be added soon, but I don't remember the details exactly. Anyway, this patch is good on its own, so if the code continues not using this type in the future, I'm fine with applying this. We'll see soon, I guess. Cheers, Alex > --- > src/nxt_http_route.c | 9 --------- > 1 file changed, 9 deletions(-) > > diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c > index f702399..d1fe298 100644 > --- a/src/nxt_http_route.c > +++ b/src/nxt_http_route.c > @@ -79,15 +79,6 @@ typedef struct { > } nxt_http_route_pattern_t; > > > -typedef struct { > - uint16_t hash; > - uint16_t name_length; > - uint32_t value_length; > - u_char *name; > - u_char *value; > -} nxt_http_cookie_t; > - > - > struct nxt_http_route_rule_s { > /* The object must be the first field. */ > nxt_http_route_object_t object:8; -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 16:05:36 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 16 Jun 2022 18:05:36 +0200 Subject: [PATCH 11/11] Unit: removed a useless assignment. In-Reply-To: <20220616010101.55677-12-andrew@digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-12-andrew@digital-domain.net> Message-ID: On 6/16/22 03:01, Andrew Clayton wrote: > As was pointed out by the cppcheck[0] static code analysis utility there > was a useless assignment in nxt_unit_request_read(). The size parameter > is passed in by value and was being modified without being used again. > > [0]: https://cppcheck.sourceforge.io/ Makes sense: $ grepc -tfd nxt_unit_request_read ./src/nxt_unit.c:3054: ssize_t nxt_unit_request_read(nxt_unit_request_info_t *req, void *dst, size_t size) { ssize_t buf_res, res; ... size -= res; dst = nxt_pointer_to(dst, res); } else { res = 0; } return buf_res + res; } Reviewed-by: Alejandro Colomar > --- > src/nxt_unit.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/src/nxt_unit.c b/src/nxt_unit.c > index 9baa680..fd086b2 100644 > --- a/src/nxt_unit.c > +++ b/src/nxt_unit.c > @@ -3076,7 +3076,6 @@ nxt_unit_request_read(nxt_unit_request_info_t *req, void *dst, size_t size) > } > > req->content_length -= res; > - size -= res; > > dst = nxt_pointer_to(dst, res); > -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 17:09:27 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 18:09:27 +0100 Subject: [PATCH 02/11] Constified numerous function parameters. In-Reply-To: References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-3-andrew@digital-domain.net> Message-ID: <20220616180927.5fe02a49@kappa.digital-domain.net> On Thu, 16 Jun 2022 17:45:01 +0200 Alejandro Colomar wrote: > Hi Andrew, Hi Alex, > From my side, as long as it compiles, and doesn't require any casts, > `const` is always welcome. Heh, yeah it compiles and no casts were introduced :) > I'm actually surprised that only 41 lines were changed with this. There were some other places that could be made const but they would require more code changes... > Reviewed-by: Alejandro Colomar Thanks! > (We don't use those in the commit logs, but just to state that I > reviewed it). Though I think it would be beneficial if we did. Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 17:16:44 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 18:16:44 +0100 Subject: [PATCH 01/11] Array: avoided void pointer arithmetic in nxt_array_copy(). In-Reply-To: <6604d061-e2cc-7971-5446-44058284c359@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-2-andrew@digital-domain.net> <6604d061-e2cc-7971-5446-44058284c359@gmail.com> Message-ID: <20220616181644.7936cee7@kappa.digital-domain.net> On Thu, 16 Jun 2022 17:41:02 +0200 Alejandro Colomar wrote: > Since we seem to have support from all compilers we care (otherwise one > would have already complained), I prefer not fixing this. > > So, wontfix? :) OK, no problem. I'll drop this. > BTW, if you would like to CC me in patches to the mailing list, it would > help me notice them. Oh, OK, I assumed you'd be subscribed! Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 17:20:11 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 18:20:11 +0100 Subject: [PATCH 03/11] Marked a couple of variables 'const'. In-Reply-To: References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-4-andrew@digital-domain.net> Message-ID: <20220616182011.3c3c261a@kappa.digital-domain.net> On Thu, 16 Jun 2022 17:45:50 +0200 Alejandro Colomar wrote: > On 6/16/22 03:00, Andrew Clayton wrote: > > As was pointed out by the cppcheck[0] static code analysis utility we > > can mark a couple of variables as 'const'. This acts as a hint to the > > compiler about our intentions and the compiler will tell us when we > > deviate from them. > > > > [0]: https://cppcheck.sourceforge.io/ > > Reviewed-by: Alejandro Colomar Thanks! From andrew at digital-domain.net Thu Jun 16 17:25:33 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 18:25:33 +0100 Subject: [PATCH 04/11] Port: removed useless msg->cancelled == 0 checks. In-Reply-To: <841b008c-1848-ed0e-24f9-5191c7f69cd0@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-5-andrew@digital-domain.net> <841b008c-1848-ed0e-24f9-5191c7f69cd0@gmail.com> Message-ID: <20220616182533.16d4cfb1@kappa.digital-domain.net> On Thu, 16 Jun 2022 17:51:30 +0200 Alejandro Colomar wrote: > This patch makes sense, but then, I guess we should go further and > remove that field completely? I don't see it being used at all. Yes, I think you're right, I'll check again and add it to the patch. Thanks! Cheers, Andrew From andrew at digital-domain.net Thu Jun 16 17:26:09 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 18:26:09 +0100 Subject: [PATCH 05/11] Socket: removed useless port < 1 check. In-Reply-To: <6102279e-c29b-27b3-2c7a-6dee2cefeafb@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-6-andrew@digital-domain.net> <6102279e-c29b-27b3-2c7a-6dee2cefeafb@gmail.com> Message-ID: <20220616182609.576773f5@kappa.digital-domain.net> On Thu, 16 Jun 2022 17:52:42 +0200 Alejandro Colomar wrote: > On 6/16/22 03:00, Andrew Clayton wrote: > > In src/nxt_sockaddr.c::nxt_job_sockaddr_inet_parse() there is a check > > that port > 0 then there is a check that port < 1 || port > 65535, well > > we _know_ it can't be less than 1. > > Reviewed-by: Alejandro Colomar Thanks! Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 17:43:23 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 18:43:23 +0100 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <53004cc7-eb00-323b-3ec7-26162998fc27@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-7-andrew@digital-domain.net> <20220616160338.2466a9e5@kappa.digital-domain.net> <53004cc7-eb00-323b-3ec7-26162998fc27@gmail.com> Message-ID: <20220616184323.58b924bf@kappa.digital-domain.net> On Thu, 16 Jun 2022 17:32:22 +0200 Alejandro Colomar wrote: > Hmmm, AFAIR, `u.a = u.b + 1;` is fine, since the = creates a sequence > point, isn't it? > > So we're saying that 6.5.16 (p3): [...] The side effect of updating the stored value of the left operand is sequenced after the value computations of the left and right operands. makes it OK? Cheers, Andrew From andrew at digital-domain.net Thu Jun 16 17:55:54 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 18:55:54 +0100 Subject: [PATCH 07/11] Route: avoided undefined behaviour. In-Reply-To: <0fae0f8e-01f9-7ac0-d8a6-ded82b9ff3b4@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-8-andrew@digital-domain.net> <0fae0f8e-01f9-7ac0-d8a6-ded82b9ff3b4@gmail.com> Message-ID: <20220616185554.5577a163@kappa.digital-domain.net> On Thu, 16 Jun 2022 17:55:58 +0200 Alejandro Colomar wrote: > > - inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFF << (32 - cidr_prefix))); > > + inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFFUL << (32 - cidr_prefix))); > > Do we support platforms with 32-bit long? I'm not sure. To be safe, Actually, 32 bit Linux would count and I guess the same for FreeBSD et al.. > I'd use ULL. Makes sense? Indeed. Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 18:01:14 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 19:01:14 +0100 Subject: [PATCH 08/11] Unit: avoided needlessly setting lib in nxt_unit_shm_open(). In-Reply-To: <406a68c3-5c7c-8599-5a49-95b110ae8178@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-9-andrew@digital-domain.net> <406a68c3-5c7c-8599-5a49-95b110ae8178@gmail.com> Message-ID: <20220616190114.0a732e00@kappa.digital-domain.net> On Thu, 16 Jun 2022 17:57:30 +0200 Alejandro Colomar wrote: > On 6/16/22 03:00, Andrew Clayton wrote: > > As was pointed out by the cppcheck[0] static code analysis utility, lib > > was being set in nxt_unit_shm_open() regardless of platform when in fact > > it's only used when (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN). > > > > Move the variable declaration & definition to be within the > > > > #if (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN) > > > > block. > > > > [0]: https://cppcheck.sourceforge.io/ > > Reviewed-by: Alejandro Colomar Thanks! Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 18:03:08 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 19:03:08 +0100 Subject: [PATCH 09/11] Router: removed unused structure member proxy_buffers. In-Reply-To: <077bbf24-7f89-8df2-7a5a-be8966e2e9f2@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-10-andrew@digital-domain.net> <077bbf24-7f89-8df2-7a5a-be8966e2e9f2@gmail.com> Message-ID: <20220616190308.6d4ca6cf@kappa.digital-domain.net> On Thu, 16 Jun 2022 17:59:25 +0200 Alejandro Colomar wrote: > On 6/16/22 03:00, Andrew Clayton wrote: > > proxy_buffers is declared as a structure member of nxt_socket_conf_t and > > is set in nxt_router_conf_create(), however it is not used anywhere. > > > > Removing it has the nice side effect of making the nxt_socket_conf_t > > structure require one less cacheline (on x86-64 at least) as the summary > > from pahole[0] shows > > > > Before > > > > /* size: 200, cachelines: 4, members: 25 */ > > /* sum members: 185, holes: 3, sum holes: 15 */ > > > > After > > > > /* size: 192, cachelines: 3, members: 24 */ > > /* sum members: 177, holes: 3, sum holes: 15 */ > > > > [0]: https://github.com/acmel/dwarves > > Reviewed-by: Alejandro Colomar Thanks! Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 18:05:21 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 19:05:21 +0100 Subject: [PATCH 09/11] Router: removed unused structure member proxy_buffers. In-Reply-To: <6fdb2d3d-9e27-191f-1852-2f17ce524328@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-10-andrew@digital-domain.net> <6fdb2d3d-9e27-191f-1852-2f17ce524328@gmail.com> Message-ID: <20220616190521.7f37def5@kappa.digital-domain.net> On Thu, 16 Jun 2022 18:01:15 +0200 Alejandro Colomar wrote: > BTW, I didn't know about pahole(1). It would be nice to show the Yes, very handy and lesser known (I think) tool. The only reason I know about it is because it was posted to the Kernel mailing list many years ago... > command invocation before the command output, to see how it works :) > > Kind of: > > $ echo foo > foo Sure. I'll update the commit message. Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 18:17:06 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 19:17:06 +0100 Subject: [PATCH 09/11] Router: removed unused structure member proxy_buffers. In-Reply-To: <6fdb2d3d-9e27-191f-1852-2f17ce524328@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-10-andrew@digital-domain.net> <6fdb2d3d-9e27-191f-1852-2f17ce524328@gmail.com> Message-ID: <20220616191706.78b1d1aa@kappa.digital-domain.net> On Thu, 16 Jun 2022 18:01:15 +0200 Alejandro Colomar wrote: > BTW, I didn't know about pahole(1). It would be nice to show the > command invocation before the command output, to see how it works :) Actually I notice with TLS enabled we are back to 4 cachelines $ pahole -C nxt_socket_conf_t build/unitd typedef struct { uint32_t count; /* 0 4 */ /* XXX 4 bytes hole, try to pack */ nxt_queue_link_t link; /* 8 16 */ nxt_router_conf_t * router_conf; /* 24 8 */ nxt_http_action_t * action; /* 32 8 */ nxt_sockaddr_t * sockaddr; /* 40 8 */ nxt_listen_socket_t * listen; /* 48 8 */ size_t header_buffer_size; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ size_t large_header_buffer_size; /* 64 8 */ size_t large_header_buffers; /* 72 8 */ size_t body_buffer_size; /* 80 8 */ size_t max_body_size; /* 88 8 */ size_t proxy_header_buffer_size; /* 96 8 */ size_t proxy_buffer_size; /* 104 8 */ nxt_msec_t idle_timeout; /* 112 4 */ nxt_msec_t header_read_timeout; /* 116 4 */ nxt_msec_t body_read_timeout; /* 120 4 */ nxt_msec_t send_timeout; /* 124 4 */ /* --- cacheline 2 boundary (128 bytes) --- */ nxt_msec_t proxy_timeout; /* 128 4 */ nxt_msec_t proxy_send_timeout; /* 132 4 */ nxt_msec_t proxy_read_timeout; /* 136 4 */ /* XXX 4 bytes hole, try to pack */ nxt_websocket_conf_t websocket_conf; /* 144 16 */ nxt_str_t body_temp_path; /* 160 16 */ uint8_t discard_unsafe_fields; /* 176 1 */ /* XXX 7 bytes hole, try to pack */ nxt_http_client_ip_t * client_ip; /* 184 8 */ /* --- cacheline 3 boundary (192 bytes) --- */ nxt_tls_conf_t * tls; /* 192 8 */ /* size: 200, cachelines: 4, members: 25 */ /* sum members: 185, holes: 3, sum holes: 15 */ /* last cacheline: 8 bytes */ } nxt_socket_conf_t; However if we move count to after the nxt_msec_t's that brings us back down to 3 again even with TLS enabled. $ pahole -C nxt_socket_conf_t build/unitd typedef struct { nxt_queue_link_t link; /* 0 16 */ nxt_router_conf_t * router_conf; /* 16 8 */ nxt_http_action_t * action; /* 24 8 */ nxt_sockaddr_t * sockaddr; /* 32 8 */ nxt_listen_socket_t * listen; /* 40 8 */ size_t header_buffer_size; /* 48 8 */ size_t large_header_buffer_size; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ size_t large_header_buffers; /* 64 8 */ size_t body_buffer_size; /* 72 8 */ size_t max_body_size; /* 80 8 */ size_t proxy_header_buffer_size; /* 88 8 */ size_t proxy_buffer_size; /* 96 8 */ nxt_msec_t idle_timeout; /* 104 4 */ nxt_msec_t header_read_timeout; /* 108 4 */ nxt_msec_t body_read_timeout; /* 112 4 */ nxt_msec_t send_timeout; /* 116 4 */ nxt_msec_t proxy_timeout; /* 120 4 */ nxt_msec_t proxy_send_timeout; /* 124 4 */ /* --- cacheline 2 boundary (128 bytes) --- */ nxt_msec_t proxy_read_timeout; /* 128 4 */ uint32_t count; /* 132 4 */ nxt_websocket_conf_t websocket_conf; /* 136 16 */ nxt_str_t body_temp_path; /* 152 16 */ uint8_t discard_unsafe_fields; /* 168 1 */ /* XXX 7 bytes hole, try to pack */ nxt_http_client_ip_t * client_ip; /* 176 8 */ nxt_tls_conf_t * tls; /* 184 8 */ /* size: 192, cachelines: 3, members: 25 */ /* sum members: 185, holes: 1, sum holes: 7 */ } nxt_socket_conf_t; So unless there is a good reason that count is the first member then it's probably worth doing. Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 18:24:49 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 19:24:49 +0100 Subject: [PATCH 11/11] Unit: removed a useless assignment. In-Reply-To: References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-12-andrew@digital-domain.net> Message-ID: <20220616192449.2747fb3d@kappa.digital-domain.net> On Thu, 16 Jun 2022 18:05:36 +0200 Alejandro Colomar wrote: > On 6/16/22 03:01, Andrew Clayton wrote: > > As was pointed out by the cppcheck[0] static code analysis utility there > > was a useless assignment in nxt_unit_request_read(). The size parameter > > is passed in by value and was being modified without being used again. > > > > [0]: https://cppcheck.sourceforge.io/ > > Makes sense: > > $ grepc -tfd nxt_unit_request_read > ./src/nxt_unit.c:3054: > ssize_t > nxt_unit_request_read(nxt_unit_request_info_t *req, void *dst, size_t size) > { > ssize_t buf_res, res; > > ... > size -= res; > > dst = nxt_pointer_to(dst, res); > > } else { > res = 0; > } > > return buf_res + res; > } > > > Reviewed-by: Alejandro Colomar Thanks! Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From max.romanov at gmail.com Thu Jun 16 19:24:21 2022 From: max.romanov at gmail.com (Max Romanov) Date: Thu, 16 Jun 2022 22:24:21 +0300 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. Message-ID: <5cdaf4cf-cb4c-4116-a396-19be0f2cad91.maildroid@localhost> There is no side effects. It's just an 'offset to self' calculation. -- Max -----Original Message----- From: Andrew Clayton To: Alejandro Colomar Cc: unit at nginx.org Sent: чт, 16 июн. 2022 20:43 Subject: Re: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. On Thu, 16 Jun 2022 17:32:22 +0200 Alejandro Colomar wrote: > Hmmm, AFAIR, `u.a = u.b + 1;` is fine, since the = creates a sequence > point, isn't it? > > So we're saying that 6.5.16 (p3): [...] The side effect of updating the stored value of the left operand is sequenced after the value computations of the left and right operands. makes it OK? Cheers, Andrew _______________________________________________ unit mailing list -- unit at nginx.org To unsubscribe send an email to unit-leave at nginx.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew at digital-domain.net Thu Jun 16 20:15:21 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 16 Jun 2022 21:15:21 +0100 Subject: [PATCH 10/11] HTTP: removed unused nxt_http_cookie_t structure. In-Reply-To: <1ed4df9e-bbce-fd37-4701-fa009dd8a249@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-11-andrew@digital-domain.net> <1ed4df9e-bbce-fd37-4701-fa009dd8a249@gmail.com> Message-ID: <20220616211521.346ce2ee@kappa.digital-domain.net> On Thu, 16 Jun 2022 18:03:38 +0200 Alejandro Colomar wrote: > Hi Andrew, > > On 6/16/22 03:01, Andrew Clayton wrote: > > Turns out that struct nxt_http_cookie_t is completely unused. > > I think this was added to give support to a future feature that will be > added soon, but I don't remember the details exactly. > > Anyway, this patch is good on its own, so if the code continues not > using this type in the future, I'm fine with applying this. We'll see > soon, I guess. Sure. Just for interest this was added by commit 6a775f58af430bd2e1f41556e9bb28b089a5e068 Author: Igor Sysoev Date: Thu May 30 15:33:51 2019 +0300 Added routing based on cookies. Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Thu Jun 16 22:17:20 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Fri, 17 Jun 2022 00:17:20 +0200 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <20220616184323.58b924bf@kappa.digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-7-andrew@digital-domain.net> <20220616160338.2466a9e5@kappa.digital-domain.net> <53004cc7-eb00-323b-3ec7-26162998fc27@gmail.com> <20220616184323.58b924bf@kappa.digital-domain.net> Message-ID: <31a20c88-65d0-d678-c6cc-78844fe6c99d@gmail.com> Hi, Andrew, Max! On 6/16/22 19:43, Andrew Clayton wrote: > On Thu, 16 Jun 2022 17:32:22 +0200 > Alejandro Colomar wrote: > >> Hmmm, AFAIR, `u.a = u.b + 1;` is fine, since the = creates a sequence >> point, isn't it? >> >> > > So we're saying that > > 6.5.16 (p3): > > [...] The side effect of updating the stored value of the left operand > is sequenced after the value computations of the left and right operands. > > makes it OK? Woah, wait a bit. No it doesn't. Today I learnt: 6.5.16.1/3 (Assignment operators::Simple Assignment::Semantics): If the value being stored in an object is read from another object that overlaps in any way the storage of the first object, then the overlap shall be exact and the two objects shall have qualified or unqualified versions of a compatible type; otherwise, the behavior is undefined. I thought union would have this issue in C++, but not in C; but it does. So this patch is actually correct. We have: $ grepc nxt_unit_sptr_. ./src/nxt_unit_sptr.h:18: union nxt_unit_sptr_u { uint8_t base[1]; uint32_t offset; }; ./src/nxt_unit_typedefs.h:18: typedef union nxt_unit_sptr_u nxt_unit_sptr_t; Since `uint8_t [1]` (or `uint8_t *`, to which it decays) is incompatible with `uint32_t`, it is UB, and storing it in a temporary fixes that. So, for the patch: Reviewed-by: Alejandro Colomar BTW, updated Stackoverflow: Cheers, Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 16 23:05:08 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Fri, 17 Jun 2022 00:05:08 +0100 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <31a20c88-65d0-d678-c6cc-78844fe6c99d@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-7-andrew@digital-domain.net> <20220616160338.2466a9e5@kappa.digital-domain.net> <53004cc7-eb00-323b-3ec7-26162998fc27@gmail.com> <20220616184323.58b924bf@kappa.digital-domain.net> <31a20c88-65d0-d678-c6cc-78844fe6c99d@gmail.com> Message-ID: <20220617000508.01cd52ca@kappa.digital-domain.net> On Fri, 17 Jun 2022 00:17:20 +0200 Alejandro Colomar wrote: > Woah, wait a bit. No it doesn't. Today I learnt: > > 6.5.16.1/3 (Assignment operators::Simple Assignment::Semantics): > > If the value being stored in an object is read from another object that > overlaps in any way the storage of the first object, then the overlap > shall be exact and the two objects shall have qualified or unqualified > versions of a compatible type; otherwise, the behavior is undefined. > > > > I thought union would have this issue in C++, but not in C; but it does. > So this patch is actually correct. I knew it! ;) > We have: > > $ grepc nxt_unit_sptr_. > ./src/nxt_unit_sptr.h:18: > union nxt_unit_sptr_u { > uint8_t base[1]; > uint32_t offset; > }; > > > ./src/nxt_unit_typedefs.h:18: > typedef union nxt_unit_sptr_u nxt_unit_sptr_t; > > > Since `uint8_t [1]` (or `uint8_t *`, to which it decays) is incompatible > with `uint32_t`, it is UB, and storing it in a temporary fixes that. Thanks for looking into this. > So, for the patch: > > Reviewed-by: Alejandro Colomar Well, I'm glad I wasn't completely wrong! I'll maybe tweak the commit message and quote the spec... > BTW, updated Stackoverflow: And the above paragraph is in at least the C99 spec. Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Fri Jun 17 02:46:54 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Fri, 17 Jun 2022 03:46:54 +0100 Subject: [PATCH 04/11] Port: removed useless msg->cancelled == 0 checks. In-Reply-To: <20220616182533.16d4cfb1@kappa.digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-5-andrew@digital-domain.net> <841b008c-1848-ed0e-24f9-5191c7f69cd0@gmail.com> <20220616182533.16d4cfb1@kappa.digital-domain.net> Message-ID: <20220617034654.43513847@kappa.digital-domain.net> On Thu, 16 Jun 2022 18:25:33 +0100 Andrew Clayton wrote: > On Thu, 16 Jun 2022 17:51:30 +0200 > Alejandro Colomar wrote: > > > This patch makes sense, but then, I guess we should go further and > > remove that field completely? I don't see it being used at all. > > Yes, I think you're right, I'll check again and add it to the patch. So, this has led down a bit of a rabbit hole! ->cancelled is still used by 1196 fmsg = nxt_port_frag_find(task, port, msg); ... 1202 if (nxt_fast_path(fmsg->cancelled == 0)) { in src/nxt_port_socket.c::nxt_port_read_msg_process() From what I can tell fmsg is basically a copy of msg and stored in a hash table. So how is msg created? Seems to be generally just created and set directly on the stack e.g 738 nxt_port_recv_msg_t msg; ... 761 msg.fd[0] = -1; 762 msg.fd[1] = -1; ... 775 msg.buf = b; 776 msg.size = n; 777 778 nxt_port_read_msg_process(task, port, &msg); in src/nxt_port_socket.c::nxt_port_read_handler() However it doesn't seem to be zeroed out or anything and so unset fields will just contain whatever happens to be in memory. E.g At start up 2022/06/16 23:19:28 [info] 36687#36687 unit 1.27.0 started nxt_port_read_msg_process: msg->cancelled : 32767 nxt_port_read_msg_process: msg->cancelled : 32767 nxt_port_read_msg_process: msg->cancelled : 32767 nxt_port_read_msg_process: msg->cancelled : 32621 nxt_port_read_msg_process: msg->cancelled : 0 nxt_port_read_msg_process: msg->cancelled : 32767 nxt_port_read_msg_process: msg->cancelled : 32767 nxt_port_read_msg_process: msg->cancelled : 32767 nxt_port_read_msg_process: msg->cancelled : 32767 nxt_port_read_msg_process: msg->cancelled : 0 nxt_port_read_msg_process: msg->cancelled : 32767 nxt_port_read_msg_process: msg->cancelled : 32767 And I suspect fmsg->cancelled will be similar as it seem to just be essentially set from msg. So if we think that ->cancelled is a zombie member and the only place I see it getting set is 516 msg.cancelled = 0; in src/nxt_port_rpc.c::nxt_port_rpc_close() which looks like some clean up function. It isn't called before nxt_port_read_msg_process(), which follows the above output... and it doesn't _seem_ to be 0 initialised anywhere else, then it _appears_ we could just remove the whole of 1202 if (nxt_fast_path(fmsg->cancelled == 0)) { 1203 1204 if (msg->port_msg.mmap) { 1205 nxt_port_mmap_read(task, msg); 1206 } 1207 1208 nxt_buf_chain_add(&fmsg->buf, msg->buf); 1209 1210 fmsg->size += msg->size; 1211 msg->buf = NULL; 1212 b = NULL; 1213 1214 if (nxt_fast_path(msg->port_msg.mf == 0)) { 1215 1216 b = fmsg->buf; 1217 1218 port->handler(task, fmsg); 1219 1220 msg->buf = fmsg->buf; 1221 msg->fd[0] = fmsg->fd[0]; 1222 msg->fd[1] = fmsg->fd[1]; 1223 1224 /* 1225 * To disable instant completion or buffer re-usage, 1226 * handler should reset 'msg.buf'. 1227 */ 1228 if (!msg->port_msg.mmap && msg->buf == b) { 1229 nxt_port_buf_free(port, b); 1230 } 1231 } 1232 } from src/nxt_port_socket.c::nxt_port_read_msg_process() How we get to nxt_port_read_msg_process() is fairly straightforward (gdb) bt ... #4 0x00000000004103a1 in nxt_port_read_msg_process (task=0x14bdbf0, port=0x14c8230, msg=0x7ffeafc21c20) at src/nxt_port_socket.c:1177 #5 0x000000000040f529 in nxt_port_read_handler (task=0x14bdbf0, obj=0x14c8230, data=0x0) at src/nxt_port_socket.c:778 #6 0x000000000041f8cc in nxt_event_engine_start (engine=0x14bdbf0) at src/nxt_event_engine.c:542 #7 0x000000000040a227 in main (argc=2, argv=0x7ffeafc21ea8) at src/nxt_main.c:35 Thoughts? Cheers, Andrew From alx.manpages at gmail.com Fri Jun 17 09:34:03 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Fri, 17 Jun 2022 11:34:03 +0200 Subject: [PATCH 04/11] Port: removed useless msg->cancelled == 0 checks. In-Reply-To: <20220617034654.43513847@kappa.digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-5-andrew@digital-domain.net> <841b008c-1848-ed0e-24f9-5191c7f69cd0@gmail.com> <20220616182533.16d4cfb1@kappa.digital-domain.net> <20220617034654.43513847@kappa.digital-domain.net> Message-ID: <32459dcd-1f9b-1f00-4c26-b8c7384ba99f@gmail.com> Hi Andrew, On 6/17/22 04:46, Andrew Clayton wrote: > On Thu, 16 Jun 2022 18:25:33 +0100 > Andrew Clayton wrote: > >> On Thu, 16 Jun 2022 17:51:30 +0200 >> Alejandro Colomar wrote: >> >>> This patch makes sense, but then, I guess we should go further and >>> remove that field completely? I don't see it being used at all. >> >> Yes, I think you're right, I'll check again and add it to the patch. > > So, this has led down a bit of a rabbit hole! > > ->cancelled is still used by > > 1196 fmsg = nxt_port_frag_find(task, port, msg); > ... > 1202 if (nxt_fast_path(fmsg->cancelled == 0)) { > > in src/nxt_port_socket.c::nxt_port_read_msg_process() > > From what I can tell fmsg is basically a copy of msg and stored in a > hash table. > > So how is msg created? Seems to be generally just created and > set directly on the stack e.g > [...] > > However it doesn't seem to be zeroed out or anything and so unset > fields will just contain whatever happens to be in memory. Let me share my discoveries, maybe this helps you continue down the rabbit hole (I'm sure more than one point in this path is UB, but I'm not fixing it until I fully understand it; maybe you get it before me): $ grepc nxt_port_recv_msg_t ./src/nxt_main.h:18: typedef struct nxt_port_recv_msg_s nxt_port_recv_msg_t; $ grepc nxt_port_recv_msg_s ./src/nxt_port.h:194: struct nxt_port_recv_msg_s { ... nxt_bool_t cancelled; ... }; $ grepc -tfd nxt_port_read_msg_process ./src/nxt_port_socket.c:1200: static void nxt_port_read_msg_process(nxt_task_t *task, nxt_port_t *port, nxt_port_recv_msg_t *msg) { ... nxt_port_recv_msg_t *fmsg; ... fmsg = nxt_port_frag_find(task, port, msg); ... if (nxt_fast_path(fmsg->cancelled == 0)) { ... } $ grepc nxt_port_frag_find ./src/nxt_port_socket.c:1161: static nxt_port_recv_msg_t * nxt_port_frag_find(nxt_task_t *task, nxt_port_t *port, nxt_port_recv_msg_t *msg) { ... nxt_lvlhsh_query_t lhq; ... res = last != 0 ? nxt_lvlhsh_delete(&port->frags, &lhq) : nxt_lvlhsh_find(&port->frags, &lhq); ... return lhq.value; ... } $ grepc nxt_lvlhsh_query_t ./src/nxt_lvlhsh.h:11: typedef struct nxt_lvlhsh_query_s nxt_lvlhsh_query_t; $ grepc nxt_lvlhsh_query_s ./src/nxt_lvlhsh.h:88: struct nxt_lvlhsh_query_s { ... void *value; ... }; $ grepc -tfd nxt_lvlhsh_find ./src/nxt_lvlhsh.c:180: nxt_int_t nxt_lvlhsh_find(nxt_lvlhsh_t *lh, nxt_lvlhsh_query_t *lhq) { ... return nxt_lvlhsh_bucket_find(lhq, slot); } return nxt_lvlhsh_level_find(lhq, slot, lhq->key_hash, 0); ... } $ grepc -tfd nxt_lvlhsh_bucket_find ./src/nxt_lvlhsh.c:227: static nxt_int_t nxt_lvlhsh_bucket_find(nxt_lvlhsh_query_t *lhq, void **bkt) { ... bucket = nxt_lvlhsh_bucket(lhq->proto, bkt); n = nxt_lvlhsh_bucket_entries(lhq->proto, bkt); e = bucket; ... value = nxt_lvlhsh_entry_value(e); if (lhq->proto->test(lhq, value) == NXT_OK) { lhq->value = value; ... } $ grepc nxt_lvlhsh_entry_value ./src/nxt_lvlhsh.c:103: #define nxt_lvlhsh_entry_value(e) \ (void *) (((uintptr_t) (e)[1] << 32) + (e)[0]) ./src/nxt_lvlhsh.c:125: #define nxt_lvlhsh_entry_value(e) \ (void *) (e)[0] (Above, the first definition is for 64 bit archs, the other is for else.) $ grepc nxt_lvlhsh_bucket ./src/nxt_lvlhsh.c:78: #define nxt_lvlhsh_bucket(proto, bkt) \ (uint32_t *) ((uintptr_t) bkt & ~(uintptr_t) proto->bucket_mask) $ grepc nxt_lvlhsh_bucket_entries ./src/nxt_lvlhsh.c:82: #define nxt_lvlhsh_bucket_entries(proto, bkt) \ (((uintptr_t) bkt & (uintptr_t) proto->bucket_mask) >> 1) So my impression is that it's being used, although through the darkest of magics (uintptr_t), and I can't really follow it more to find the rabbit; maybe you do. I hope this helps. I wonder how the world did this without grepc(1) :p Cheers, Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Fri Jun 17 11:58:45 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Fri, 17 Jun 2022 13:58:45 +0200 Subject: [PATCH 09/11] Router: removed unused structure member proxy_buffers. In-Reply-To: <20220616191706.78b1d1aa@kappa.digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-10-andrew@digital-domain.net> <6fdb2d3d-9e27-191f-1852-2f17ce524328@gmail.com> <20220616191706.78b1d1aa@kappa.digital-domain.net> Message-ID: <0c43ab0e-5495-bde4-9aa2-e4be38cd655e@gmail.com> Hi Andrew, On 6/16/22 20:17, Andrew Clayton wrote: > On Thu, 16 Jun 2022 18:01:15 +0200 > Alejandro Colomar wrote: > > >> BTW, I didn't know about pahole(1). It would be nice to show the >> command invocation before the command output, to see how it works :) > > Actually I notice with TLS enabled we are back to 4 cachelines > > $ pahole -C nxt_socket_conf_t build/unitd [...] > > However if we move count to after the nxt_msec_t's that brings us back > down to 3 again even with TLS enabled. > [...] > > So unless there is a good reason that count is the first member then > it's probably worth doing. It would be good. But since this code uses a lot of aliasing, I'd like to be completely sure that we can do that. If you prove that no code relies on the order of the structure, it makes sense to me to reduce cache lines. Cheers, Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Fri Jun 17 12:52:21 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Fri, 17 Jun 2022 13:52:21 +0100 Subject: [PATCH 09/11] Router: removed unused structure member proxy_buffers. In-Reply-To: <0c43ab0e-5495-bde4-9aa2-e4be38cd655e@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-10-andrew@digital-domain.net> <6fdb2d3d-9e27-191f-1852-2f17ce524328@gmail.com> <20220616191706.78b1d1aa@kappa.digital-domain.net> <0c43ab0e-5495-bde4-9aa2-e4be38cd655e@gmail.com> Message-ID: <20220617135221.6809940e@kappa.digital-domain.net> On Fri, 17 Jun 2022 13:58:45 +0200 Alejandro Colomar wrote: > It would be good. But since this code uses a lot of aliasing, I'd like > to be completely sure that we can do that. If you prove that no code > relies on the order of the structure, it makes sense to me to reduce > cache lines. Hmm, good point, something to investigate, it would be a separate patch anyway. Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Fri Jun 17 22:03:23 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Fri, 17 Jun 2022 23:03:23 +0100 Subject: [PATCH 04/11] Port: removed useless msg->cancelled == 0 checks. In-Reply-To: <32459dcd-1f9b-1f00-4c26-b8c7384ba99f@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-5-andrew@digital-domain.net> <841b008c-1848-ed0e-24f9-5191c7f69cd0@gmail.com> <20220616182533.16d4cfb1@kappa.digital-domain.net> <20220617034654.43513847@kappa.digital-domain.net> <32459dcd-1f9b-1f00-4c26-b8c7384ba99f@gmail.com> Message-ID: <20220617230323.40e60487@kappa.digital-domain.net> On Fri, 17 Jun 2022 11:34:03 +0200 Alejandro Colomar wrote: > Hi Andrew, Hi Alex, [...] > Let me share my discoveries, maybe this helps you continue down the > rabbit hole (I'm sure more than one point in this path is UB, but I'm > not fixing it until I fully understand it; maybe you get it before me): > > $ grepc nxt_port_recv_msg_t > ./src/nxt_main.h:18: > typedef struct nxt_port_recv_msg_s nxt_port_recv_msg_t; > > $ grepc nxt_port_recv_msg_s > ./src/nxt_port.h:194: > struct nxt_port_recv_msg_s { > ... > nxt_bool_t cancelled; > ... > }; Aye. So getting values other than 1 or 0 likely indicates an issue (even though it's backed by an unsigned int). [...] > $ grepc nxt_lvlhsh_entry_value > ./src/nxt_lvlhsh.c:103: > #define nxt_lvlhsh_entry_value(e) > \ > (void *) (((uintptr_t) (e)[1] << 32) + (e)[0]) > > > ./src/nxt_lvlhsh.c:125: > #define nxt_lvlhsh_entry_value(e) > \ > (void *) (e)[0] > > > (Above, the first definition is for 64 bit archs, the other is for else.) So they just convert a (uint32_t *) to a (void *) ? Although isn't the shift superfluous? AFAICT #define nxt_lvlhsh_entry_value(e) \ (void *)((uintptr_t)(e)[0]) does the same thing. Of course I may be totally misunderstanding this. Happy to be corrected either way ;). > $ grepc nxt_lvlhsh_bucket > ./src/nxt_lvlhsh.c:78: > #define nxt_lvlhsh_bucket(proto, bkt) > \ > (uint32_t *) ((uintptr_t) bkt & ~(uintptr_t) proto->bucket_mask) > > > $ grepc nxt_lvlhsh_bucket_entries > ./src/nxt_lvlhsh.c:82: > #define nxt_lvlhsh_bucket_entries(proto, bkt) > \ > (((uintptr_t) bkt & (uintptr_t) proto->bucket_mask) >> 1) > > > So my impression is that it's being used, although through the darkest > of magics (uintptr_t), and I can't really follow it more to find the > rabbit; maybe you do. > I hope this helps. I admit I don't immediately see the connection with the hashtable stuff and ->cancelled... What I'd really like to do is to test and trace the code in src/nxt_port_socket.c::nxt_port_read_msg_process() that's enabled when msg->port_msg.nf != 0 1194 if (nxt_slow_path(msg->port_msg.nf != 0)) { I just don't know how to trigger that code, i.e what unit config would make use of this? > I wonder how the world did this without grepc(1) :p I have ctags set up for unit, useful. Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From max.romanov at gmail.com Fri Jun 17 23:04:35 2022 From: max.romanov at gmail.com (Max Romanov) Date: Sat, 18 Jun 2022 02:04:35 +0300 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. Message-ID: I'm sorry to be a pain, but the key thing is: ".. read from another object..". In the statement you are trying to "fix", the "base" does not actually _read_ from the object (structure, to be precise), instead the address of the structure itself used. In other words, "p->base" is a shortcut for "(uint8_t *) p". -- Max -----Original Message----- From: Andrew Clayton To: Alejandro Colomar Cc: unit at nginx.org, Max Romanov Sent: пт, 17 июн. 2022 2:05 Subject: Re: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. On Fri, 17 Jun 2022 00:17:20 +0200 Alejandro Colomar wrote: > Woah, wait a bit. No it doesn't. Today I learnt: > > 6.5.16.1/3 (Assignment operators::Simple Assignment::Semantics): > > If the value being stored in an object is read from another object that > overlaps in any way the storage of the first object, then the overlap > shall be exact and the two objects shall have qualified or unqualified > versions of a compatible type; otherwise, the behavior is undefined. > > > > I thought union would have this issue in C++, but not in C; but it does. > So this patch is actually correct. I knew it! ;) > We have: > > $ grepc nxt_unit_sptr_. > ./src/nxt_unit_sptr.h:18: > union nxt_unit_sptr_u { > uint8_t base[1]; > uint32_t offset; > }; > > > ./src/nxt_unit_typedefs.h:18: > typedef union nxt_unit_sptr_u nxt_unit_sptr_t; > > > Since `uint8_t [1]` (or `uint8_t *`, to which it decays) is incompatible > with `uint32_t`, it is UB, and storing it in a temporary fixes that. Thanks for looking into this. > So, for the patch: > > Reviewed-by: Alejandro Colomar Well, I'm glad I wasn't completely wrong! I'll maybe tweak the commit message and quote the spec... > BTW, updated Stackoverflow: And the above paragraph is in at least the C99 spec. Cheers, Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From alx.manpages at gmail.com Fri Jun 17 23:15:46 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sat, 18 Jun 2022 01:15:46 +0200 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: References: Message-ID: <0fa9f947-7b20-ae16-2f20-d63e1e8554a2@gmail.com> Hi Max On 6/18/22 01:04, Max Romanov wrote: > I'm sorry to be a pain, No problem :) but the key thing is: ".. read from another > object..". In this case, ISO C uses the term object to refer to a broader concept, that includes any variable. 3.15/1,2: " object region of data storage in the execution environment, the contents of which can represent values " > In the statement you are trying to "fix", the "base" does not > actually _read_ from the object (structure, to be precise), instead the > address of the structure itself used. In other words, "p->base" is a > shortcut for "(uint8_t *) p". the region of data storage pointed to by `p->base` would be an object (of type uint8_t, or maybe uint8_t[]). But the pointer itself does constitute another separate object. And that object is the one that is stored in the union (the uint8_t data is not stored in the union, but in some other allocated memory (probably)). Since we are reading a member of the union (and each member is an object, by definition, even if it's a pointer), and storing the value into another member of the union, that's not valid. As pointed by @supercat in StackOverflow (in the link I provided), the rationale was probably to allow compilers to do some optimizations, or for example, copy byte by byte; in archs where the union members are larger than a register, this will definitely cause a bug; in archs where the union members fit into a register (as in our case), the code is likely to work, but the standard makes no guarantees about it, and a compiler may still do bad stuff. It's better to be safe. Cheers, Alex >> -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Fri Jun 17 23:49:56 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sat, 18 Jun 2022 01:49:56 +0200 Subject: Unused struct field bucket_mask (was: Re: [PATCH 04/11] Port: removed useless msg->cancelled == 0 checks.) In-Reply-To: <20220617230323.40e60487@kappa.digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-5-andrew@digital-domain.net> <841b008c-1848-ed0e-24f9-5191c7f69cd0@gmail.com> <20220616182533.16d4cfb1@kappa.digital-domain.net> <20220617034654.43513847@kappa.digital-domain.net> <32459dcd-1f9b-1f00-4c26-b8c7384ba99f@gmail.com> <20220617230323.40e60487@kappa.digital-domain.net> Message-ID: <8ede83f9-34f2-e8db-5aa9-74f8ad6d5cef@gmail.com> Hi Andrew, On 6/18/22 00:03, Andrew Clayton wrote: > Aye. So getting values other than 1 or 0 likely indicates an issue > (even though it's backed by an unsigned int). Unless we're doing type punning on purpose. Type punning from a pointer to a bool might be useful... > > [...] > >> $ grepc nxt_lvlhsh_entry_value >> ./src/nxt_lvlhsh.c:103: >> #define nxt_lvlhsh_entry_value(e) >> \ >> (void *) (((uintptr_t) (e)[1] << 32) + (e)[0]) >> >> >> ./src/nxt_lvlhsh.c:125: >> #define nxt_lvlhsh_entry_value(e) >> \ >> (void *) (e)[0] >> >> >> (Above, the first definition is for 64 bit archs, the other is for else.) > > So they just convert a (uint32_t *) to a (void *) ? Although isn't the > shift superfluous? AFAICT So, bucket, which was set from some masking stuff, seems to be an `uint32_t[]`? Then, this code merges them into a (64-bit) `uintptr_t` (I guess the shift avoids endianness problems here) (it also makes sense that in 32-bit, the array has a size of 1, and therefore it has no endianness problems with the type punning. This kind of makes sense. So we got this pointer, created from magic, that is assigned into lhq->value, and it seems to have a field that is supposed to have a meaning as a boolean. It could make sense. But, I still wonder what kind of punning is going on here, since I can find nothing about the initialization; it may be using a completely different type to initialize, then reinterpret as `nxt_port_recv_msg_t`... > > #define nxt_lvlhsh_entry_value(e) \ > (void *)((uintptr_t)(e)[0]) > > does the same thing. Of course I may be totally misunderstanding this. > Happy to be corrected either way ;). > >> $ grepc nxt_lvlhsh_bucket >> ./src/nxt_lvlhsh.c:78: >> #define nxt_lvlhsh_bucket(proto, bkt) >> \ >> (uint32_t *) ((uintptr_t) bkt & ~(uintptr_t) proto->bucket_mask) This could be moved to inline functions, to improve readability (by removing some casts), and safety (by removing some casts, and limiting the effects of the remaining). >> >> >> $ grepc nxt_lvlhsh_bucket_entries >> ./src/nxt_lvlhsh.c:82: >> #define nxt_lvlhsh_bucket_entries(proto, bkt) >> \ >> (((uintptr_t) bkt & (uintptr_t) proto->bucket_mask) >> 1) bucket_mask is just an uint32_t mask (I don't understand what it means, but it looks good). And bkt comes from a `void **`, which, again, is opaque enough to stop my attempts to follow it. And there are many call sites, so it would be painful to follow them all (but if you feel like doing that, it could be interesting). >> >> >> So my impression is that it's being used, although through the darkest >> of magics (uintptr_t), and I can't really follow it more to find the >> rabbit; maybe you do. >> I hope this helps. > > I admit I don't immediately see the connection with the hashtable stuff > and ->cancelled... > > What I'd really like to do is to test and trace the code in > src/nxt_port_socket.c::nxt_port_read_msg_process() that's enabled when > msg->port_msg.nf != 0 > > 1194 if (nxt_slow_path(msg->port_msg.nf != 0)) { > > I just don't know how to trigger that code, i.e what unit config would > make use of this? Heh, good look triggering that! :p I guess you could add an abort there, and run the whole pytest (maybe even with some modules, if the base doesn't trigger it), to see if some of that triggers it? > >> I wonder how the world did this without grepc(1) :p > > I have ctags set up for unit, useful. I read about it, but didn't feel easy to use. I just wanted to grep for stuff, without having to set up anything. Also, it works integrated with the editor, which is something I try to avoid (I don't like IDEs, and wouldn't want to transform vim(1) into one). The UNIX way (one-shot run, dump stuff into stdout) seems better to my taste. Cheers, Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Sat Jun 18 02:17:14 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Sat, 18 Jun 2022 03:17:14 +0100 Subject: Unused struct field bucket_mask (was: Re: [PATCH 04/11] Port: removed useless msg->cancelled == 0 checks.) In-Reply-To: <8ede83f9-34f2-e8db-5aa9-74f8ad6d5cef@gmail.com> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-5-andrew@digital-domain.net> <841b008c-1848-ed0e-24f9-5191c7f69cd0@gmail.com> <20220616182533.16d4cfb1@kappa.digital-domain.net> <20220617034654.43513847@kappa.digital-domain.net> <32459dcd-1f9b-1f00-4c26-b8c7384ba99f@gmail.com> <20220617230323.40e60487@kappa.digital-domain.net> <8ede83f9-34f2-e8db-5aa9-74f8ad6d5cef@gmail.com> Message-ID: <20220618031714.7725be98@kappa.digital-domain.net> On Sat, 18 Jun 2022 01:49:56 +0200 Alejandro Colomar wrote: > Hi Andrew, Hi Alex, [...] Thanks for the detailed explanations, I'll need some time to digest it all! > > I just don't know how to trigger that code, i.e what unit config would > > make use of this? > > Heh, good look triggering that! :p > > I guess you could add an abort there, and run the whole pytest (maybe > even with some modules, if the base doesn't trigger it), to see if some > of that triggers it? Yeah, I had tried that, but good call on trying with modules enabled, unfortunately it never gets into that if block. I think I managed to test with all modules except ruby, the tests blow up there. > >> I wonder how the world did this without grepc(1) :p > > > > I have ctags set up for unit, useful. > > I read about it, but didn't feel easy to use. I just wanted to grep for > stuff, without having to set up anything. Also, it works integrated > with the editor, which is something I try to avoid (I don't like IDEs, > and wouldn't want to transform vim(1) into one). The UNIX way (one-shot > run, dump stuff into stdout) seems better to my taste. Heh. I'm all for the UNIX philosophy :) it's really all I've used for the past 25+ years! So I do use it with vim, but it is quite un-intrusive, you wouldn't even know it was there! Simply doing Ctrl-] will take you to the type definition of what's currently under the cursor and Ctrl-t will take you back. There's some other things you can do of course, but that's basically it. Other than setting a theme (colo iceberg), a ruler down the 80 column margin (set ruler, set cc=80) and having the current line highlighted (set cursorline) and various autocmd's for C and git commits my vim set up is pretty bog standard. Cheers, Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From max.romanov at gmail.com Sat Jun 18 09:39:57 2022 From: max.romanov at gmail.com (Max Romanov) Date: Sat, 18 Jun 2022 12:39:57 +0300 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. Message-ID: <8e460cdf-2c74-4e03-a99a-cade40626d10.maildroid@localhost> > But the pointer itself does constitute another separate object. And that object is the one that is stored in the union (the uint8_t data is not stored in the union, but in some other allocated memory (probably)). The pointer to structure's field does not stored in the structure. And reading the pointer to the field is just adding an offset to the object pointer. Why do you ignore my suggestion to replace "p->base" with "(uint8_t *) p" and try to understand the purpose of the object, 'base' and 'offset'? Instead you digging the specifications to prove the validation software behavior. -- Max -----Original Message----- From: Alejandro Colomar To: Max Romanov , Andrew Clayton Cc: unit at nginx.org Sent: сб, 18 июн. 2022 2:15 Subject: Re: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. Hi Max On 6/18/22 01:04, Max Romanov wrote: > I'm sorry to be a pain, No problem :) but the key thing is: ".. read from another > object..". In this case, ISO C uses the term object to refer to a broader concept, that includes any variable. 3.15/1,2: " object region of data storage in the execution environment, the contents of which can represent values " > In the statement you are trying to "fix", the "base" does not > actually _read_ from the object (structure, to be precise), instead the > address of the structure itself used. In other words, "p->base" is a > shortcut for "(uint8_t *) p". the region of data storage pointed to by `p->base` would be an object (of type uint8_t, or maybe uint8_t[]). But the pointer itself does constitute another separate object. And that object is the one that is stored in the union (the uint8_t data is not stored in the union, but in some other allocated memory (probably)). Since we are reading a member of the union (and each member is an object, by definition, even if it's a pointer), and storing the value into another member of the union, that's not valid. As pointed by @supercat in StackOverflow (in the link I provided), the rationale was probably to allow compilers to do some optimizations, or for example, copy byte by byte; in archs where the union members are larger than a register, this will definitely cause a bug; in archs where the union members fit into a register (as in our case), the code is likely to work, but the standard makes no guarantees about it, and a compiler may still do bad stuff. It's better to be safe. Cheers, Alex >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From alx.manpages at gmail.com Sat Jun 18 11:00:46 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sat, 18 Jun 2022 13:00:46 +0200 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <8e460cdf-2c74-4e03-a99a-cade40626d10.maildroid@localhost> References: <8e460cdf-2c74-4e03-a99a-cade40626d10.maildroid@localhost> Message-ID: <971775fd-b9e6-8579-9174-152d7a567937@gmail.com> Hi Max, On 6/18/22 11:39, Max Romanov wrote: > The pointer to structure's field does not stored in the structure. And > reading the pointer to the field is just adding an offset to the object > pointer. Okay, now I got it. So, p->base is reinterpreting as uint_8[], the contents of some stucture. p, the pointer to the union, is really a pointer to that structure. p->base, when used in pointer arithmetics, decays to a pointer to the first element, which is the same as a pointer to the union, which is the same as a pointer to the reinterpreted structure. And p->offset is just an offset to that pointer, so it's the offset of ptr to the start to the structure (reinterpreted as a uint8_t[]), and it's stored as the first element of said structure. Now it makes sense. So, yes, the patch was wrong, and the linter has a bug (but they'll probably ignore it because unions in C++ are so crap that it doesn't pay out fixing it). > > Why do you ignore my suggestion to replace "p->base" with "(uint8_t *) > p" Sory, I misunderstood it yesterday. > and try to understand the purpose of the object, 'base' and 'offset'? > Instead you digging the specifications to prove the validation software > behavior. Thanks! Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From max.romanov at gmail.com Sat Jun 18 13:27:30 2022 From: max.romanov at gmail.com (Max Romanov) Date: Sat, 18 Jun 2022 16:27:30 +0300 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. Message-ID: I'm appreciate your patience and effort to make it clear! I also admit it is not obvious way to describe the relocatable offset in C. -- Max -----Original Message----- From: Alejandro Colomar To: Max Romanov , Andrew Clayton Cc: unit at nginx.org Sent: сб, 18 июн. 2022 14:00 Subject: Re: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. Hi Max, On 6/18/22 11:39, Max Romanov wrote: > The pointer to structure's field does not stored in the structure. And > reading the pointer to the field is just adding an offset to the object > pointer. Okay, now I got it. So, p->base is reinterpreting as uint_8[], the contents of some stucture. p, the pointer to the union, is really a pointer to that structure. p->base, when used in pointer arithmetics, decays to a pointer to the first element, which is the same as a pointer to the union, which is the same as a pointer to the reinterpreted structure. And p->offset is just an offset to that pointer, so it's the offset of ptr to the start to the structure (reinterpreted as a uint8_t[]), and it's stored as the first element of said structure. Now it makes sense. So, yes, the patch was wrong, and the linter has a bug (but they'll probably ignore it because unions in C++ are so crap that it doesn't pay out fixing it). > > Why do you ignore my suggestion to replace "p->base" with "(uint8_t *) > p" Sory, I misunderstood it yesterday. > and try to understand the purpose of the object, 'base' and 'offset'? > Instead you digging the specifications to prove the validation software > behavior. Thanks! Alex -- Alejandro Colomar -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew at digital-domain.net Sat Jun 18 14:04:45 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Sat, 18 Jun 2022 15:04:45 +0100 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <971775fd-b9e6-8579-9174-152d7a567937@gmail.com> References: <8e460cdf-2c74-4e03-a99a-cade40626d10.maildroid@localhost> <971775fd-b9e6-8579-9174-152d7a567937@gmail.com> Message-ID: <20220618150445.52eae95c@kappa.digital-domain.net> On Sat, 18 Jun 2022 13:00:46 +0200 Alejandro Colomar wrote: > So, p->base is reinterpreting as uint_8[], the contents of some stucture. > p, the pointer to the union, is really a pointer to that structure. > p->base, when used in pointer arithmetics, decays to a pointer to the > first element, which is the same as a pointer to the union, which is the > same as a pointer to the reinterpreted structure. > And p->offset is just an offset to that pointer, so it's the offset of > ptr to the start to the structure (reinterpreted as a uint8_t[]), and > it's stored as the first element of said structure. Ugh, that code definitely needs a comment! Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Sat Jun 18 14:07:51 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sat, 18 Jun 2022 16:07:51 +0200 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <20220618150445.52eae95c@kappa.digital-domain.net> References: <8e460cdf-2c74-4e03-a99a-cade40626d10.maildroid@localhost> <971775fd-b9e6-8579-9174-152d7a567937@gmail.com> <20220618150445.52eae95c@kappa.digital-domain.net> Message-ID: <0e92e167-e739-409d-d922-7623bf18e16d@gmail.com> On 6/18/22 16:04, Andrew Clayton wrote: > On Sat, 18 Jun 2022 13:00:46 +0200 > Alejandro Colomar wrote: > >> So, p->base is reinterpreting as uint_8[], the contents of some stucture. >> p, the pointer to the union, is really a pointer to that structure. >> p->base, when used in pointer arithmetics, decays to a pointer to the >> first element, which is the same as a pointer to the union, which is the >> same as a pointer to the reinterpreted structure. >> And p->offset is just an offset to that pointer, so it's the offset of >> ptr to the start to the structure (reinterpreted as a uint8_t[]), and >> it's stored as the first element of said structure. > > Ugh, that code definitely needs a comment! I strongly prefer not having comments about how code works. They tend to be obsolete, and maintaining comments is harder than the code. Better improve the code, adding these details to the commit log, where the comment is tied to the point in time where it was true, forever. Cheers, Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Sat Jun 18 14:18:41 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Sat, 18 Jun 2022 15:18:41 +0100 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <0e92e167-e739-409d-d922-7623bf18e16d@gmail.com> References: <8e460cdf-2c74-4e03-a99a-cade40626d10.maildroid@localhost> <971775fd-b9e6-8579-9174-152d7a567937@gmail.com> <20220618150445.52eae95c@kappa.digital-domain.net> <0e92e167-e739-409d-d922-7623bf18e16d@gmail.com> Message-ID: <20220618151841.176c4e60@kappa.digital-domain.net> On Sat, 18 Jun 2022 16:07:51 +0200 Alejandro Colomar wrote: > I strongly prefer not having comments about how code works. > They tend to be obsolete, and maintaining comments is harder than the code. There is certainly a fine line about when and what to comment. > Better improve the code, adding these details to the commit log, where > the comment is tied to the point in time where it was true, forever. In this case the code is so baroque that it really deserves a comment or you'll get people trying to fix it when it ain't broke ;) Either that or as you suggest, re-work the code to make it more obvious about what's going on. Now which patch (adding a comment or changing the code) has more chance of being accepted?! Andrew -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Sat Jun 18 14:39:07 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sat, 18 Jun 2022 16:39:07 +0200 Subject: [PATCH 06/11] Sptr: avoided potentially undefined behaviour. In-Reply-To: <20220618151841.176c4e60@kappa.digital-domain.net> References: <8e460cdf-2c74-4e03-a99a-cade40626d10.maildroid@localhost> <971775fd-b9e6-8579-9174-152d7a567937@gmail.com> <20220618150445.52eae95c@kappa.digital-domain.net> <0e92e167-e739-409d-d922-7623bf18e16d@gmail.com> <20220618151841.176c4e60@kappa.digital-domain.net> Message-ID: <55501bc5-792d-647a-6db4-cd6d088020c7@gmail.com> Hi Andrew, On 6/18/22 16:18, Andrew Clayton wrote: > On Sat, 18 Jun 2022 16:07:51 +0200 > Alejandro Colomar wrote: > >> I strongly prefer not having comments about how code works. >> They tend to be obsolete, and maintaining comments is harder than the code. > > There is certainly a fine line about when and what to comment. > >> Better improve the code, adding these details to the commit log, where >> the comment is tied to the point in time where it was true, forever. > > In this case the code is so baroque that it really deserves a comment > or you'll get people trying to fix it when it ain't broke ;) > > Either that or as you suggest, re-work the code to make it more obvious > about what's going on. > > Now which patch (adding a comment or changing the code) has more chance > of being accepted?! If you simplify the code, you'll have all of my support. I bet it can be simplified in terms of offsetof(3); you'll probably have to check all call sites for that. If you manage to do it, and prove the patch is a no-op, you got me :-} For the comment, I'm going to be _very_ picky. Cheers, Alex -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Sun Jun 19 13:50:13 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:13 +0200 Subject: [PATCH 03/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-4-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index b7c30ebe..34f5bb01 100644 --- a/auto/headers +++ b/auto/headers @@ -3,6 +3,19 @@ # System headers. +nxt_feature="" +nxt_feature_name=NXT_HAVE_LINUX_OPENAT2_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_MNTENT_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index d8eaabc3..16d27383 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -242,7 +242,7 @@ #include #endif -#if (NXT_HAVE_OPENAT2) +#if (NXT_HAVE_LINUX_OPENAT2_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:15 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:15 +0200 Subject: [PATCH 05/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-6-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 10 +++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/auto/headers b/auto/headers index 34f5bb01..578c0a27 100644 --- a/auto/headers +++ b/auto/headers @@ -40,3 +40,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_RANDOM_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_unix.h b/src/nxt_unix.h index ab9e2d17..d1de8660 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -230,12 +230,12 @@ #include #endif -#if (NXT_HAVE_GETRANDOM) -#include /* getrandom(). */ -#elif (NXT_HAVE_LINUX_SYS_GETRANDOM) +#if (NXT_HAVE_SYS_RANDOM_H) +#include +#endif + +#if (NXT_HAVE_LINUX_SYS_GETRANDOM) #include /* SYS_getrandom. */ -#elif (NXT_HAVE_GETENTROPY_SYS_RANDOM) -#include /* getentropy(). */ #endif #include -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:18 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:18 +0200 Subject: [PATCH 08/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-9-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 2f31736b..64200044 100644 --- a/auto/headers +++ b/auto/headers @@ -29,6 +29,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_DEVPOLL_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_POLLSET_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 74b67dd1..f8d9f4ea 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -214,7 +214,7 @@ #include #endif -#if (NXT_HAVE_DEVPOLL) +#if (NXT_HAVE_SYS_DEVPOLL_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:10 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:10 +0200 Subject: [PATCH 00/22] Simplify inclusion conditionals Message-ID: <20220619135032.19351-1-alx.manpages@gmail.com> Hi Andrew, This patch set simplifies the rules for including files, so that widely-available headers, especially those required by POSIX.1-2001, are included unconditionally. Then, headers that may not exist in some systems are included conditionally to their existence. For that we need to add a new set of NXT_HAVE_..._H macros created by the new script. This patch set fixes some obscure dependencies between headers, which when reordering some include files, triggers MacOS to include , which doesn't exist in that system. After this patch set, since the header doesn't exist, it's not included. This is a prerequisite for even attempting to use iwyu(1). Cheers, Alex Alejandro Colomar (22): Including iff it exists. Including iff it exists. Including iff it exists. Including unconditionally. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Removed code used when NXT_HAVE_POSIX_SPAWN is false. Including iff it exists. Including iff it exists. Including unconditionally. Including unconditionally. Including and unconditionally. Including iff it exists. Including iff it exists. auto/headers | 224 ++++++++++++++++++++++++++++++++++++++++++ auto/unix | 15 --- configure | 1 + src/nxt_application.c | 2 +- src/nxt_capability.c | 8 +- src/nxt_fs.c | 2 - src/nxt_isolation.c | 2 +- src/nxt_port_memory.c | 7 +- src/nxt_process.c | 50 +--------- src/nxt_process.h | 4 +- src/nxt_socket_msg.h | 2 +- src/nxt_unit.c | 2 +- src/nxt_unix.h | 47 ++++----- 13 files changed, 261 insertions(+), 105 deletions(-) create mode 100644 auto/headers -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:11 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:11 +0200 Subject: [PATCH 01/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-2-alx.manpages@gmail.com> With NXT_HAVE_PIVOT_ROOT I had issues in MacOS. Headers should normally be included unconditionally, except of course if they don't exist. --- auto/headers | 16 ++++++++++++++++ configure | 1 + src/nxt_isolation.c | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 auto/headers diff --git a/auto/headers b/auto/headers new file mode 100644 index 00000000..8abf58eb --- /dev/null +++ b/auto/headers @@ -0,0 +1,16 @@ +# Copyright (C) NGINX, Inc. + +# System headers. + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_MNTENT_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/configure b/configure index bc21e579..ad4b02b2 100755 --- a/configure +++ b/configure @@ -127,6 +127,7 @@ NXT_LIBRT= . auto/sendfile . auto/files . auto/unix +. auto/headers . auto/os/conf . auto/ssltls diff --git a/src/nxt_isolation.c b/src/nxt_isolation.c index e3cb1f22..c52adfab 100644 --- a/src/nxt_isolation.c +++ b/src/nxt_isolation.c @@ -7,7 +7,7 @@ #include #include -#if (NXT_HAVE_PIVOT_ROOT) +#if (NXT_HAVE_MNTENT_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:20 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:20 +0200 Subject: [PATCH 10/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-11-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 3b93d5ec..4db0f046 100644 --- a/auto/headers +++ b/auto/headers @@ -55,6 +55,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_EVENT_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_POLLSET_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 56603f01..72234939 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -206,7 +206,7 @@ #include #endif -#if (NXT_HAVE_KQUEUE) +#if (NXT_HAVE_SYS_EVENT_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:12 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:12 +0200 Subject: [PATCH 02/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-3-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_application.c | 2 +- src/nxt_process.c | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index 8abf58eb..b7c30ebe 100644 --- a/auto/headers +++ b/auto/headers @@ -14,3 +14,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_PRCTL_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_application.c b/src/nxt_application.c index 594574b1..3785d9e8 100644 --- a/src/nxt_application.c +++ b/src/nxt_application.c @@ -18,7 +18,7 @@ #include -#if (NXT_HAVE_PR_SET_NO_NEW_PRIVS) +#if (NXT_HAVE_SYS_PRCTL_H) #include #endif diff --git a/src/nxt_process.c b/src/nxt_process.c index 82e66a99..b7174850 100644 --- a/src/nxt_process.c +++ b/src/nxt_process.c @@ -12,7 +12,7 @@ #include -#if (NXT_HAVE_PR_SET_NO_NEW_PRIVS) +#if (NXT_HAVE_SYS_PRCTL_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:19 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:19 +0200 Subject: [PATCH 09/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-10-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 64200044..3b93d5ec 100644 --- a/auto/headers +++ b/auto/headers @@ -29,6 +29,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_PORT_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_DEVPOLL_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index f8d9f4ea..56603f01 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -210,7 +210,7 @@ #include #endif -#if (NXT_HAVE_EVENTPORT) +#if (NXT_HAVE_PORT_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:22 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:22 +0200 Subject: [PATCH 12/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-13-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index d6918cec..69a66550 100644 --- a/auto/headers +++ b/auto/headers @@ -131,3 +131,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_SIGNALFD_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_unix.h b/src/nxt_unix.h index c5c4de72..ddfe434c 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -198,7 +198,7 @@ #endif -#if (NXT_HAVE_SIGNALFD) +#if (NXT_HAVE_SYS_SIGNALFD_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:14 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:14 +0200 Subject: [PATCH 04/22] Including unconditionally. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-5-alx.manpages@gmail.com> It's a commonly available header. --- src/nxt_unix.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 16d27383..ab9e2d17 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -238,9 +238,7 @@ #include /* getentropy(). */ #endif -#if (NXT_HAVE_ISOLATION_ROOTFS) #include -#endif #if (NXT_HAVE_LINUX_OPENAT2_H) #include -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:21 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:21 +0200 Subject: [PATCH 11/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-12-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 4db0f046..d6918cec 100644 --- a/auto/headers +++ b/auto/headers @@ -55,6 +55,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_EVENTFD_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_EVENT_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 72234939..c5c4de72 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -202,7 +202,7 @@ #include #endif -#if (NXT_HAVE_EVENTFD) +#if (NXT_HAVE_SYS_EVENTFD_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:23 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:23 +0200 Subject: [PATCH 13/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-14-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 7 +++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/auto/headers b/auto/headers index 69a66550..dee13ead 100644 --- a/auto/headers +++ b/auto/headers @@ -55,6 +55,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_EPOLL_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_EVENTFD_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index ddfe434c..9100cccf 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -186,18 +186,17 @@ #include #include -#if (NXT_HAVE_EPOLL) +#if (NXT_HAVE_SYS_EPOLL_H) #include +#endif -#ifdef EPOLLRDHUP +#if (NXT_HAVE_EPOLL && defined(EPOLLRDHUP)) /* * Epoll edge-tiggered mode is pretty much useless without EPOLLRDHUP support. */ #define NXT_HAVE_EPOLL_EDGE 1 #endif -#endif - #if (NXT_HAVE_SYS_SIGNALFD_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:25 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:25 +0200 Subject: [PATCH 15/22] Removed code used when NXT_HAVE_POSIX_SPAWN is false. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-16-alx.manpages@gmail.com> posix_spawn(3POSIX) was introduced by POSIX.1d (IEEE Std 1003.1d-1999), and was later consolidated in POSIX.1-2001, requiring it in all POSIX-compliant systems. It's safe to assume it's always available, more than 20 years after its standardization. Link: --- auto/unix | 15 --------------- src/nxt_process.c | 48 ----------------------------------------------- src/nxt_unix.h | 2 -- 3 files changed, 65 deletions(-) diff --git a/auto/unix b/auto/unix index 7c241650..45c6a139 100644 --- a/auto/unix +++ b/auto/unix @@ -178,21 +178,6 @@ if [ $nxt_found = no ]; then fi -nxt_feature="posix_spawn()" -nxt_feature_name=NXT_HAVE_POSIX_SPAWN -nxt_feature_run= -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="#include - #include - - int main(int argc, char *argv[]) { - (void) posix_spawn(NULL, \"\", NULL, NULL, argv, NULL); - return 0; - }" -. auto/feature - - # NetBSD 1.0, OpenBSD 1.0, FreeBSD 2.2 setproctitle(). nxt_feature="setproctitle()" diff --git a/src/nxt_process.c b/src/nxt_process.c index b7174850..bc59e7d5 100644 --- a/src/nxt_process.c +++ b/src/nxt_process.c @@ -798,8 +798,6 @@ nxt_process_send_ready(nxt_task_t *task, nxt_process_t *process) } -#if (NXT_HAVE_POSIX_SPAWN) - /* * Linux glibc 2.2 posix_spawn() is implemented via fork()/execve(). * Linux glibc 2.4 posix_spawn() without file actions and spawn @@ -834,52 +832,6 @@ nxt_process_execute(nxt_task_t *task, char *name, char **argv, char **envp) return pid; } -#else - -nxt_pid_t -nxt_process_execute(nxt_task_t *task, char *name, char **argv, char **envp) -{ - nxt_pid_t pid; - - /* - * vfork() is better than fork() because: - * it is faster several times; - * its execution time does not depend on private memory mapping size; - * it has lesser chances to fail due to the ENOMEM error. - */ - - pid = vfork(); - - switch (pid) { - - case -1: - nxt_alert(task, "vfork() failed while executing \"%s\" %E", - name, nxt_errno); - break; - - case 0: - /* A child. */ - nxt_debug(task, "execve(\"%s\")", name); - - (void) execve(name, argv, envp); - - nxt_alert(task, "execve(\"%s\") failed %E", name, nxt_errno); - - exit(1); - nxt_unreachable(); - break; - - default: - /* A parent. */ - nxt_debug(task, "vfork(): %PI", pid); - break; - } - - return pid; -} - -#endif - nxt_int_t nxt_process_daemon(nxt_task_t *task) diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 5d7a59b6..fab51f38 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -156,9 +156,7 @@ #include #include #include -#if (NXT_HAVE_POSIX_SPAWN) #include -#endif #include #include /* offsetof() */ #include -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:16 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:16 +0200 Subject: [PATCH 06/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-7-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 6 +----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/auto/headers b/auto/headers index 578c0a27..5d21ad06 100644 --- a/auto/headers +++ b/auto/headers @@ -53,3 +53,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_SENDFILE_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_unix.h b/src/nxt_unix.h index d1de8660..85a40416 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -222,11 +222,7 @@ #include #endif -#if (NXT_HAVE_LINUX_SENDFILE) -#include -#endif - -#if (NXT_HAVE_SOLARIS_SENDFILEV) +#if (NXT_HAVE_SYS_SENDFILE_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:17 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:17 +0200 Subject: [PATCH 07/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-8-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 5d21ad06..2f31736b 100644 --- a/auto/headers +++ b/auto/headers @@ -29,6 +29,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_POLLSET_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_PRCTL_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 85a40416..74b67dd1 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -218,7 +218,7 @@ #include #endif -#if (NXT_HAVE_POLLSET) +#if (NXT_HAVE_SYS_POLLSET_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:27 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:27 +0200 Subject: [PATCH 17/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-18-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index 7ae572d5..9f528caa 100644 --- a/auto/headers +++ b/auto/headers @@ -16,6 +16,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_MALLOC_NP_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_MNTENT_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 2fe784c0..7f9a2914 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -45,8 +45,8 @@ #if (NXT_FREEBSD) -#if (NXT_HAVE_MALLOC_USABLE_SIZE) -#include /* malloc_usable_size(). */ +#if (NXT_HAVE_MALLOC_NP_H) +#include #endif #if (__FreeBSD_version >= 900007) -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:31 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:31 +0200 Subject: [PATCH 21/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-22-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_port_memory.c | 2 +- src/nxt_unit.c | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index 9f528caa..a240b2d5 100644 --- a/auto/headers +++ b/auto/headers @@ -3,6 +3,19 @@ # System headers. +nxt_feature="" +nxt_feature_name=NXT_HAVE_LINUX_MEMFD_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_LINUX_OPENAT2_H nxt_feature_run=no diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c index 84f5ebc2..1f5a2432 100644 --- a/src/nxt_port_memory.c +++ b/src/nxt_port_memory.c @@ -9,7 +9,7 @@ #include #include -#if (NXT_HAVE_MEMFD_CREATE) +#if (NXT_HAVE_LINUX_MEMFD_H) #include #endif diff --git a/src/nxt_unit.c b/src/nxt_unit.c index f183ac6e..71964b33 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -16,7 +16,7 @@ #include "nxt_websocket.h" -#if (NXT_HAVE_MEMFD_CREATE) +#if (NXT_HAVE_LINUX_MEMFD_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:24 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:24 +0200 Subject: [PATCH 14/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-15-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_socket_msg.h | 2 +- src/nxt_unix.h | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index dee13ead..98865630 100644 --- a/auto/headers +++ b/auto/headers @@ -157,3 +157,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_UN_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_socket_msg.h b/src/nxt_socket_msg.h index 04de1761..3601c6b8 100644 --- a/src/nxt_socket_msg.h +++ b/src/nxt_socket_msg.h @@ -5,7 +5,7 @@ #ifndef _NXT_SOCKET_MSG_H_INCLUDED_ #define _NXT_SOCKET_MSG_H_INCLUDED_ -#if (NXT_HAVE_UCRED) +#if (NXT_HAVE_SYS_UN_H) #include #endif diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 9100cccf..5d7a59b6 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -178,7 +178,7 @@ #include #include #include -#if (NXT_HAVE_UNIX_DOMAIN) +#if (NXT_HAVE_SYS_UN_H) #include #endif #include -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:32 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:32 +0200 Subject: [PATCH 22/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-23-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_capability.c | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index a240b2d5..835d4096 100644 --- a/auto/headers +++ b/auto/headers @@ -3,6 +3,19 @@ # System headers. +nxt_feature="" +nxt_feature_name=NXT_HAVE_LINUX_CAPABILITY_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_LINUX_MEMFD_H nxt_feature_run=no diff --git a/src/nxt_capability.c b/src/nxt_capability.c index 13e01329..d225f028 100644 --- a/src/nxt_capability.c +++ b/src/nxt_capability.c @@ -8,11 +8,13 @@ #include -#if (NXT_HAVE_LINUX_CAPABILITY) - +#if (NXT_HAVE_LINUX_CAPABILITY_H) #include +#endif +#if (NXT_HAVE_LINUX_CAPABILITY) + #if (_LINUX_CAPABILITY_VERSION_3) #define NXT_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3 #elif (_LINUX_CAPABILITY_VERSION_2) -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:26 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:26 +0200 Subject: [PATCH 16/22] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-17-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 98865630..7ae572d5 100644 --- a/auto/headers +++ b/auto/headers @@ -94,6 +94,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_MERCURY_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_POLLSET_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index fab51f38..2fe784c0 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -132,7 +132,7 @@ #include -#if (NXT_HAVE_HG_GETHRTIME) +#if (NXT_HAVE_SYS_MERCURY_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:30 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:30 +0200 Subject: [PATCH 20/22] Including and unconditionally. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-21-alx.manpages@gmail.com> --- src/nxt_capability.c | 4 +++- src/nxt_port_memory.c | 7 +++---- src/nxt_process.h | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/nxt_capability.c b/src/nxt_capability.c index 24fd55d0..13e01329 100644 --- a/src/nxt_capability.c +++ b/src/nxt_capability.c @@ -3,12 +3,14 @@ * Copyright (C) NGINX, Inc. */ + #include +#include + #if (NXT_HAVE_LINUX_CAPABILITY) #include -#include #if (_LINUX_CAPABILITY_VERSION_3) diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c index 0a4a6c53..84f5ebc2 100644 --- a/src/nxt_port_memory.c +++ b/src/nxt_port_memory.c @@ -6,12 +6,11 @@ #include -#if (NXT_HAVE_MEMFD_CREATE) - -#include -#include #include +#include +#if (NXT_HAVE_MEMFD_CREATE) +#include #endif #include diff --git a/src/nxt_process.h b/src/nxt_process.h index 694f457e..a65bdddf 100644 --- a/src/nxt_process.h +++ b/src/nxt_process.h @@ -7,8 +7,10 @@ #ifndef _NXT_PROCESS_H_INCLUDED_ #define _NXT_PROCESS_H_INCLUDED_ -#if (NXT_HAVE_CLONE) + #include + +#if (NXT_HAVE_CLONE) #include #endif -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:28 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:28 +0200 Subject: [PATCH 18/22] Including unconditionally. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-19-alx.manpages@gmail.com> --- src/nxt_fs.c | 3 ++- src/nxt_unix.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nxt_fs.c b/src/nxt_fs.c index 71498f99..0e461e46 100644 --- a/src/nxt_fs.c +++ b/src/nxt_fs.c @@ -4,8 +4,9 @@ #include -#if (NXT_HAVE_FREEBSD_NMOUNT) #include + +#if (NXT_HAVE_FREEBSD_NMOUNT) #include #endif diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 7f9a2914..00f70e56 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -169,7 +169,7 @@ #endif #include #include -#include /* MAXPATHLEN */ +#include #include #include #include -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 13:50:29 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 15:50:29 +0200 Subject: [PATCH 19/22] Including unconditionally. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619135032.19351-20-alx.manpages@gmail.com> --- src/nxt_fs.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/nxt_fs.c b/src/nxt_fs.c index 0e461e46..a0d5d36c 100644 --- a/src/nxt_fs.c +++ b/src/nxt_fs.c @@ -5,10 +5,7 @@ #include #include - -#if (NXT_HAVE_FREEBSD_NMOUNT) #include -#endif static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode); -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 15:00:41 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 17:00:41 +0200 Subject: [PATCH 24/24] Moded test to . In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619150041.21415-2-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ auto/sockets | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/auto/headers b/auto/headers index 835d4096..4449a999 100644 --- a/auto/headers +++ b/auto/headers @@ -133,6 +133,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_FILIO_H +nxt_feature_run= +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_MERCURY_H nxt_feature_run=no diff --git a/auto/sockets b/auto/sockets index e344a3db..0835453d 100644 --- a/auto/sockets +++ b/auto/sockets @@ -213,19 +213,6 @@ if [ $NXT_SYSTEM != DragonFly ]; then fi -nxt_feature="sys/filio.h" -nxt_feature_name=NXT_HAVE_SYS_FILIO_H -nxt_feature_run= -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="#include - - int main() { - return 0; - }" -. auto/feature - - nxt_feature="ioctl(FIONBIO)" nxt_feature_name=NXT_HAVE_FIONBIO nxt_feature_run= -- 2.36.1 From alx.manpages at gmail.com Sun Jun 19 15:00:40 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Jun 2022 17:00:40 +0200 Subject: [PATCH 23/24] Removed unnecessary include. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220619150041.21415-1-alx.manpages@gmail.com> Some OSes, as Linux, provide FIONBIO in . Others, such as the BSDs and Illumos, provide it in , but they all include that header from , so for this test, we can simplify and just include . --- auto/sockets | 7 ------- 1 file changed, 7 deletions(-) diff --git a/auto/sockets b/auto/sockets index e6ef326d..e344a3db 100644 --- a/auto/sockets +++ b/auto/sockets @@ -225,12 +225,6 @@ nxt_feature_test="#include }" . auto/feature -if [ $nxt_found = yes ]; then - NXT_SYS_FILIO_H="#include " -else - NXT_SYS_FILIO_H= -fi - nxt_feature="ioctl(FIONBIO)" nxt_feature_name=NXT_HAVE_FIONBIO @@ -239,7 +233,6 @@ nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include #include - $NXT_SYS_FILIO_H #include int main() { -- 2.36.1 From andrew at digital-domain.net Mon Jun 20 02:06:47 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 03:06:47 +0100 Subject: [PATCH 24/24] Moded test to . In-Reply-To: <20220619150041.21415-2-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220619150041.21415-2-alx.manpages@gmail.com> Message-ID: <20220620030647.72cfd440@kappa.digital-domain.net> Hi Alex, Re Subject. s/Moded/Moved/ From andrew at digital-domain.net Mon Jun 20 02:32:01 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 03:32:01 +0100 Subject: [PATCH 02/22] Including iff it exists. In-Reply-To: <20220619135032.19351-3-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220619135032.19351-3-alx.manpages@gmail.com> Message-ID: <20220620033201.76d619a0@kappa.digital-domain.net> On Sun, 19 Jun 2022 15:50:12 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_application.c | 2 +- > src/nxt_process.c | 2 +- > 3 files changed, 15 insertions(+), 2 deletions(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Mon Jun 20 02:33:30 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 03:33:30 +0100 Subject: [PATCH 03/22] Including iff it exists. In-Reply-To: <20220619135032.19351-4-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220619135032.19351-4-alx.manpages@gmail.com> Message-ID: <20220620033330.0ad4006f@kappa.digital-domain.net> On Sun, 19 Jun 2022 15:50:13 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 2 +- > 2 files changed, 14 insertions(+), 1 deletion(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Mon Jun 20 03:00:14 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 04:00:14 +0100 Subject: [PATCH 05/22] Including iff it exists. In-Reply-To: <20220619135032.19351-6-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220619135032.19351-6-alx.manpages@gmail.com> Message-ID: <20220620040014.70ad57cd@kappa.digital-domain.net> On Sun, 19 Jun 2022 15:50:15 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 10 +++++----- > 2 files changed, 18 insertions(+), 5 deletions(-) Reviewed-by: Andrew Clayton From alx.manpages at gmail.com Mon Jun 20 07:10:43 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:43 +0200 Subject: [PATCH v2 00/25] Simplify inclusion conditionals In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-1-alx.manpages@gmail.com> Hi Andrew, v2: - 05/25: elif -> if - 20/25: Added a few more cases I found. - 24/25: Subject wfix - 25/25: Added patch for The rest should be the same as v1, IIRC. But patch 25/25 for some reason breaks completely unrelated stuff from that I can't fix even if I include directly in the file that breaks. I can't make any sense of it right now; could you please have a look at it? Try to compile after 24, which should work, and then compile after 25 and you'll be shocked, I guess;). Cheers, Alex Alejandro Colomar (25): Including iff it exists. Including iff it exists. Including iff it exists. Including unconditionally. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Including iff it exists. Removed code used when NXT_HAVE_POSIX_SPAWN is false. Including iff it exists. Including iff it exists. Including unconditionally. Including unconditionally. Including and unconditionally. Including iff it exists. Including iff it exists. Removed unnecessary include. Moved test to . Including iff it exists. auto/headers | 250 ++++++++++++++++++++++++++++++++++++++++++ auto/sockets | 20 ---- auto/unix | 15 --- configure | 1 + src/nxt_application.c | 2 +- src/nxt_capability.c | 8 +- src/nxt_fs.c | 2 - src/nxt_isolation.c | 2 +- src/nxt_port_memory.c | 7 +- src/nxt_process.c | 50 +-------- src/nxt_process.h | 4 +- src/nxt_socket_msg.h | 2 +- src/nxt_unit.c | 2 +- src/nxt_unix.h | 57 +++++----- 14 files changed, 294 insertions(+), 128 deletions(-) create mode 100644 auto/headers -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:44 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:44 +0200 Subject: [PATCH v2 01/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-2-alx.manpages@gmail.com> With NXT_HAVE_PIVOT_ROOT I had issues in MacOS. Headers should normally be included unconditionally, except of course if they don't exist. --- auto/headers | 16 ++++++++++++++++ configure | 1 + src/nxt_isolation.c | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 auto/headers diff --git a/auto/headers b/auto/headers new file mode 100644 index 00000000..8abf58eb --- /dev/null +++ b/auto/headers @@ -0,0 +1,16 @@ +# Copyright (C) NGINX, Inc. + +# System headers. + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_MNTENT_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/configure b/configure index bc21e579..ad4b02b2 100755 --- a/configure +++ b/configure @@ -127,6 +127,7 @@ NXT_LIBRT= . auto/sendfile . auto/files . auto/unix +. auto/headers . auto/os/conf . auto/ssltls diff --git a/src/nxt_isolation.c b/src/nxt_isolation.c index e3cb1f22..c52adfab 100644 --- a/src/nxt_isolation.c +++ b/src/nxt_isolation.c @@ -7,7 +7,7 @@ #include #include -#if (NXT_HAVE_PIVOT_ROOT) +#if (NXT_HAVE_MNTENT_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:46 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:46 +0200 Subject: [PATCH v2 03/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-4-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index b7c30ebe..34f5bb01 100644 --- a/auto/headers +++ b/auto/headers @@ -3,6 +3,19 @@ # System headers. +nxt_feature="" +nxt_feature_name=NXT_HAVE_LINUX_OPENAT2_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_MNTENT_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index d8eaabc3..16d27383 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -242,7 +242,7 @@ #include #endif -#if (NXT_HAVE_OPENAT2) +#if (NXT_HAVE_LINUX_OPENAT2_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:47 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:47 +0200 Subject: [PATCH v2 04/25] Including unconditionally. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-5-alx.manpages@gmail.com> It's a commonly available header. --- src/nxt_unix.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 16d27383..ab9e2d17 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -238,9 +238,7 @@ #include /* getentropy(). */ #endif -#if (NXT_HAVE_ISOLATION_ROOTFS) #include -#endif #if (NXT_HAVE_LINUX_OPENAT2_H) #include -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:48 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:48 +0200 Subject: [PATCH v2 05/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-6-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 10 +++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/auto/headers b/auto/headers index 34f5bb01..578c0a27 100644 --- a/auto/headers +++ b/auto/headers @@ -40,3 +40,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_RANDOM_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_unix.h b/src/nxt_unix.h index ab9e2d17..d1de8660 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -230,12 +230,12 @@ #include #endif -#if (NXT_HAVE_GETRANDOM) -#include /* getrandom(). */ -#elif (NXT_HAVE_LINUX_SYS_GETRANDOM) +#if (NXT_HAVE_SYS_RANDOM_H) +#include +#endif + +#if (NXT_HAVE_LINUX_SYS_GETRANDOM) #include /* SYS_getrandom. */ -#elif (NXT_HAVE_GETENTROPY_SYS_RANDOM) -#include /* getentropy(). */ #endif #include -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:45 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:45 +0200 Subject: [PATCH v2 02/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-3-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_application.c | 2 +- src/nxt_process.c | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index 8abf58eb..b7c30ebe 100644 --- a/auto/headers +++ b/auto/headers @@ -14,3 +14,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_PRCTL_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_application.c b/src/nxt_application.c index 594574b1..3785d9e8 100644 --- a/src/nxt_application.c +++ b/src/nxt_application.c @@ -18,7 +18,7 @@ #include -#if (NXT_HAVE_PR_SET_NO_NEW_PRIVS) +#if (NXT_HAVE_SYS_PRCTL_H) #include #endif diff --git a/src/nxt_process.c b/src/nxt_process.c index 82e66a99..b7174850 100644 --- a/src/nxt_process.c +++ b/src/nxt_process.c @@ -12,7 +12,7 @@ #include -#if (NXT_HAVE_PR_SET_NO_NEW_PRIVS) +#if (NXT_HAVE_SYS_PRCTL_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:51 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:51 +0200 Subject: [PATCH v2 08/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-9-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 2f31736b..64200044 100644 --- a/auto/headers +++ b/auto/headers @@ -29,6 +29,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_DEVPOLL_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_POLLSET_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 74b67dd1..f8d9f4ea 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -214,7 +214,7 @@ #include #endif -#if (NXT_HAVE_DEVPOLL) +#if (NXT_HAVE_SYS_DEVPOLL_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:52 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:52 +0200 Subject: [PATCH v2 09/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-10-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 64200044..3b93d5ec 100644 --- a/auto/headers +++ b/auto/headers @@ -29,6 +29,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_PORT_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_DEVPOLL_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index f8d9f4ea..56603f01 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -210,7 +210,7 @@ #include #endif -#if (NXT_HAVE_EVENTPORT) +#if (NXT_HAVE_PORT_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:53 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:53 +0200 Subject: [PATCH v2 10/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-11-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 3b93d5ec..4db0f046 100644 --- a/auto/headers +++ b/auto/headers @@ -55,6 +55,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_EVENT_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_POLLSET_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 56603f01..72234939 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -206,7 +206,7 @@ #include #endif -#if (NXT_HAVE_KQUEUE) +#if (NXT_HAVE_SYS_EVENT_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:54 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:54 +0200 Subject: [PATCH v2 11/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-12-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 4db0f046..d6918cec 100644 --- a/auto/headers +++ b/auto/headers @@ -55,6 +55,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_EVENTFD_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_EVENT_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 72234939..c5c4de72 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -202,7 +202,7 @@ #include #endif -#if (NXT_HAVE_EVENTFD) +#if (NXT_HAVE_SYS_EVENTFD_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:56 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:56 +0200 Subject: [PATCH v2 13/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-14-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 7 +++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/auto/headers b/auto/headers index 69a66550..dee13ead 100644 --- a/auto/headers +++ b/auto/headers @@ -55,6 +55,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_EPOLL_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_EVENTFD_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index ddfe434c..9100cccf 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -186,18 +186,17 @@ #include #include -#if (NXT_HAVE_EPOLL) +#if (NXT_HAVE_SYS_EPOLL_H) #include +#endif -#ifdef EPOLLRDHUP +#if (NXT_HAVE_EPOLL && defined(EPOLLRDHUP)) /* * Epoll edge-tiggered mode is pretty much useless without EPOLLRDHUP support. */ #define NXT_HAVE_EPOLL_EDGE 1 #endif -#endif - #if (NXT_HAVE_SYS_SIGNALFD_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:55 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:55 +0200 Subject: [PATCH v2 12/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-13-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index d6918cec..69a66550 100644 --- a/auto/headers +++ b/auto/headers @@ -131,3 +131,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_SIGNALFD_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_unix.h b/src/nxt_unix.h index c5c4de72..ddfe434c 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -198,7 +198,7 @@ #endif -#if (NXT_HAVE_SIGNALFD) +#if (NXT_HAVE_SYS_SIGNALFD_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:50 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:50 +0200 Subject: [PATCH v2 07/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-8-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 5d21ad06..2f31736b 100644 --- a/auto/headers +++ b/auto/headers @@ -29,6 +29,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_POLLSET_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_PRCTL_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 85a40416..74b67dd1 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -218,7 +218,7 @@ #include #endif -#if (NXT_HAVE_POLLSET) +#if (NXT_HAVE_SYS_POLLSET_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:49 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:49 +0200 Subject: [PATCH v2 06/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-7-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 6 +----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/auto/headers b/auto/headers index 578c0a27..5d21ad06 100644 --- a/auto/headers +++ b/auto/headers @@ -53,3 +53,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_SENDFILE_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_unix.h b/src/nxt_unix.h index d1de8660..85a40416 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -222,11 +222,7 @@ #include #endif -#if (NXT_HAVE_LINUX_SENDFILE) -#include -#endif - -#if (NXT_HAVE_SOLARIS_SENDFILEV) +#if (NXT_HAVE_SYS_SENDFILE_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:57 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:57 +0200 Subject: [PATCH v2 14/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-15-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_socket_msg.h | 2 +- src/nxt_unix.h | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index dee13ead..98865630 100644 --- a/auto/headers +++ b/auto/headers @@ -157,3 +157,16 @@ nxt_feature_test="#include return 0; }" . auto/feature + + +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_UN_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature diff --git a/src/nxt_socket_msg.h b/src/nxt_socket_msg.h index 04de1761..3601c6b8 100644 --- a/src/nxt_socket_msg.h +++ b/src/nxt_socket_msg.h @@ -5,7 +5,7 @@ #ifndef _NXT_SOCKET_MSG_H_INCLUDED_ #define _NXT_SOCKET_MSG_H_INCLUDED_ -#if (NXT_HAVE_UCRED) +#if (NXT_HAVE_SYS_UN_H) #include #endif diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 9100cccf..5d7a59b6 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -178,7 +178,7 @@ #include #include #include -#if (NXT_HAVE_UNIX_DOMAIN) +#if (NXT_HAVE_SYS_UN_H) #include #endif #include -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:11:00 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:11:00 +0200 Subject: [PATCH v2 17/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-18-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index 7ae572d5..9f528caa 100644 --- a/auto/headers +++ b/auto/headers @@ -16,6 +16,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_MALLOC_NP_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_MNTENT_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 2fe784c0..7f9a2914 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -45,8 +45,8 @@ #if (NXT_FREEBSD) -#if (NXT_HAVE_MALLOC_USABLE_SIZE) -#include /* malloc_usable_size(). */ +#if (NXT_HAVE_MALLOC_NP_H) +#include #endif #if (__FreeBSD_version >= 900007) -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:59 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:59 +0200 Subject: [PATCH v2 16/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-17-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto/headers b/auto/headers index 98865630..7ae572d5 100644 --- a/auto/headers +++ b/auto/headers @@ -94,6 +94,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_MERCURY_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_POLLSET_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index fab51f38..2fe784c0 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -132,7 +132,7 @@ #include -#if (NXT_HAVE_HG_GETHRTIME) +#if (NXT_HAVE_SYS_MERCURY_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:11:02 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:11:02 +0200 Subject: [PATCH v2 19/25] Including unconditionally. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-20-alx.manpages@gmail.com> --- src/nxt_fs.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/nxt_fs.c b/src/nxt_fs.c index 0e461e46..a0d5d36c 100644 --- a/src/nxt_fs.c +++ b/src/nxt_fs.c @@ -5,10 +5,7 @@ #include #include - -#if (NXT_HAVE_FREEBSD_NMOUNT) #include -#endif static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode); -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:11:03 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:11:03 +0200 Subject: [PATCH v2 20/25] Including and unconditionally. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-21-alx.manpages@gmail.com> --- src/nxt_capability.c | 4 +++- src/nxt_port_memory.c | 7 +++---- src/nxt_process.h | 4 +++- src/nxt_unix.h | 4 +++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/nxt_capability.c b/src/nxt_capability.c index 24fd55d0..13e01329 100644 --- a/src/nxt_capability.c +++ b/src/nxt_capability.c @@ -3,12 +3,14 @@ * Copyright (C) NGINX, Inc. */ + #include +#include + #if (NXT_HAVE_LINUX_CAPABILITY) #include -#include #if (_LINUX_CAPABILITY_VERSION_3) diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c index 0a4a6c53..84f5ebc2 100644 --- a/src/nxt_port_memory.c +++ b/src/nxt_port_memory.c @@ -6,12 +6,11 @@ #include -#if (NXT_HAVE_MEMFD_CREATE) - -#include -#include #include +#include +#if (NXT_HAVE_MEMFD_CREATE) +#include #endif #include diff --git a/src/nxt_process.h b/src/nxt_process.h index 694f457e..a65bdddf 100644 --- a/src/nxt_process.h +++ b/src/nxt_process.h @@ -7,8 +7,10 @@ #ifndef _NXT_PROCESS_H_INCLUDED_ #define _NXT_PROCESS_H_INCLUDED_ -#if (NXT_HAVE_CLONE) + #include + +#if (NXT_HAVE_CLONE) #include #endif diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 00f70e56..60062610 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -9,6 +9,9 @@ #define _NXT_UNIX_H_INCLUDED_ +#include + + #if (NXT_LINUX) #ifdef _FORTIFY_SOURCE @@ -30,7 +33,6 @@ #define _FILE_OFFSET_BITS 64 #include /* malloc_usable_size(). */ -#include /* syscall(SYS_gettid). */ #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 4) /* -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:11:04 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:11:04 +0200 Subject: [PATCH v2 21/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-22-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_port_memory.c | 2 +- src/nxt_unit.c | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index 9f528caa..a240b2d5 100644 --- a/auto/headers +++ b/auto/headers @@ -3,6 +3,19 @@ # System headers. +nxt_feature="" +nxt_feature_name=NXT_HAVE_LINUX_MEMFD_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_LINUX_OPENAT2_H nxt_feature_run=no diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c index 84f5ebc2..1f5a2432 100644 --- a/src/nxt_port_memory.c +++ b/src/nxt_port_memory.c @@ -9,7 +9,7 @@ #include #include -#if (NXT_HAVE_MEMFD_CREATE) +#if (NXT_HAVE_LINUX_MEMFD_H) #include #endif diff --git a/src/nxt_unit.c b/src/nxt_unit.c index f183ac6e..71964b33 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -16,7 +16,7 @@ #include "nxt_websocket.h" -#if (NXT_HAVE_MEMFD_CREATE) +#if (NXT_HAVE_LINUX_MEMFD_H) #include #endif -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:10:58 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:10:58 +0200 Subject: [PATCH v2 15/25] Removed code used when NXT_HAVE_POSIX_SPAWN is false. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-16-alx.manpages@gmail.com> posix_spawn(3POSIX) was introduced by POSIX.1d (IEEE Std 1003.1d-1999), and was later consolidated in POSIX.1-2001, requiring it in all POSIX-compliant systems. It's safe to assume it's always available, more than 20 years after its standardization. Link: --- auto/unix | 15 --------------- src/nxt_process.c | 48 ----------------------------------------------- src/nxt_unix.h | 2 -- 3 files changed, 65 deletions(-) diff --git a/auto/unix b/auto/unix index 7c241650..45c6a139 100644 --- a/auto/unix +++ b/auto/unix @@ -178,21 +178,6 @@ if [ $nxt_found = no ]; then fi -nxt_feature="posix_spawn()" -nxt_feature_name=NXT_HAVE_POSIX_SPAWN -nxt_feature_run= -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="#include - #include - - int main(int argc, char *argv[]) { - (void) posix_spawn(NULL, \"\", NULL, NULL, argv, NULL); - return 0; - }" -. auto/feature - - # NetBSD 1.0, OpenBSD 1.0, FreeBSD 2.2 setproctitle(). nxt_feature="setproctitle()" diff --git a/src/nxt_process.c b/src/nxt_process.c index b7174850..bc59e7d5 100644 --- a/src/nxt_process.c +++ b/src/nxt_process.c @@ -798,8 +798,6 @@ nxt_process_send_ready(nxt_task_t *task, nxt_process_t *process) } -#if (NXT_HAVE_POSIX_SPAWN) - /* * Linux glibc 2.2 posix_spawn() is implemented via fork()/execve(). * Linux glibc 2.4 posix_spawn() without file actions and spawn @@ -834,52 +832,6 @@ nxt_process_execute(nxt_task_t *task, char *name, char **argv, char **envp) return pid; } -#else - -nxt_pid_t -nxt_process_execute(nxt_task_t *task, char *name, char **argv, char **envp) -{ - nxt_pid_t pid; - - /* - * vfork() is better than fork() because: - * it is faster several times; - * its execution time does not depend on private memory mapping size; - * it has lesser chances to fail due to the ENOMEM error. - */ - - pid = vfork(); - - switch (pid) { - - case -1: - nxt_alert(task, "vfork() failed while executing \"%s\" %E", - name, nxt_errno); - break; - - case 0: - /* A child. */ - nxt_debug(task, "execve(\"%s\")", name); - - (void) execve(name, argv, envp); - - nxt_alert(task, "execve(\"%s\") failed %E", name, nxt_errno); - - exit(1); - nxt_unreachable(); - break; - - default: - /* A parent. */ - nxt_debug(task, "vfork(): %PI", pid); - break; - } - - return pid; -} - -#endif - nxt_int_t nxt_process_daemon(nxt_task_t *task) diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 5d7a59b6..fab51f38 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -156,9 +156,7 @@ #include #include #include -#if (NXT_HAVE_POSIX_SPAWN) #include -#endif #include #include /* offsetof() */ #include -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:11:06 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:11:06 +0200 Subject: [PATCH v2 23/25] Removed unnecessary include. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-24-alx.manpages@gmail.com> Some OSes, as Linux, provide FIONBIO in . Others, such as the BSDs and Illumos, provide it in , but they all include that header from , so for this test, we can simplify and just include . --- auto/sockets | 7 ------- 1 file changed, 7 deletions(-) diff --git a/auto/sockets b/auto/sockets index e6ef326d..e344a3db 100644 --- a/auto/sockets +++ b/auto/sockets @@ -225,12 +225,6 @@ nxt_feature_test="#include }" . auto/feature -if [ $nxt_found = yes ]; then - NXT_SYS_FILIO_H="#include " -else - NXT_SYS_FILIO_H= -fi - nxt_feature="ioctl(FIONBIO)" nxt_feature_name=NXT_HAVE_FIONBIO @@ -239,7 +233,6 @@ nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include #include - $NXT_SYS_FILIO_H #include int main() { -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:11:05 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:11:05 +0200 Subject: [PATCH v2 22/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-23-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_capability.c | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index a240b2d5..835d4096 100644 --- a/auto/headers +++ b/auto/headers @@ -3,6 +3,19 @@ # System headers. +nxt_feature="" +nxt_feature_name=NXT_HAVE_LINUX_CAPABILITY_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_LINUX_MEMFD_H nxt_feature_run=no diff --git a/src/nxt_capability.c b/src/nxt_capability.c index 13e01329..d225f028 100644 --- a/src/nxt_capability.c +++ b/src/nxt_capability.c @@ -8,11 +8,13 @@ #include -#if (NXT_HAVE_LINUX_CAPABILITY) - +#if (NXT_HAVE_LINUX_CAPABILITY_H) #include +#endif +#if (NXT_HAVE_LINUX_CAPABILITY) + #if (_LINUX_CAPABILITY_VERSION_3) #define NXT_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3 #elif (_LINUX_CAPABILITY_VERSION_2) -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:11:07 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:11:07 +0200 Subject: [PATCH v2 24/25] Moved test to . In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-25-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ auto/sockets | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/auto/headers b/auto/headers index 835d4096..4449a999 100644 --- a/auto/headers +++ b/auto/headers @@ -133,6 +133,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_SYS_FILIO_H +nxt_feature_run= +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_SYS_MERCURY_H nxt_feature_run=no diff --git a/auto/sockets b/auto/sockets index e344a3db..0835453d 100644 --- a/auto/sockets +++ b/auto/sockets @@ -213,19 +213,6 @@ if [ $NXT_SYSTEM != DragonFly ]; then fi -nxt_feature="sys/filio.h" -nxt_feature_name=NXT_HAVE_SYS_FILIO_H -nxt_feature_run= -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="#include - - int main() { - return 0; - }" -. auto/feature - - nxt_feature="ioctl(FIONBIO)" nxt_feature_name=NXT_HAVE_FIONBIO nxt_feature_run= -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:11:08 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:11:08 +0200 Subject: [PATCH v2 25/25] Including iff it exists. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-26-alx.manpages@gmail.com> --- auto/headers | 13 +++++++++++++ src/nxt_unix.h | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/auto/headers b/auto/headers index 4449a999..33cad6aa 100644 --- a/auto/headers +++ b/auto/headers @@ -42,6 +42,19 @@ nxt_feature_test="#include . auto/feature +nxt_feature="" +nxt_feature_name=NXT_HAVE_MALLOC_H +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include + + int main(void) { + return 0; + }" +. auto/feature + + nxt_feature="" nxt_feature_name=NXT_HAVE_MALLOC_NP_H nxt_feature_run=no diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 60062610..891375fc 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -11,6 +11,10 @@ #include +#if (NXT_HAVE_MALLOC_H) +#include +#endif + #if (NXT_LINUX) @@ -32,8 +36,6 @@ #define _FILE_OFFSET_BITS 64 -#include /* malloc_usable_size(). */ - #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 4) /* * POSIX semaphores using NPTL atomic/futex operations -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:11:01 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:11:01 +0200 Subject: [PATCH v2 18/25] Including unconditionally. In-Reply-To: <20220619135032.19351-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> Message-ID: <20220620071108.16798-19-alx.manpages@gmail.com> --- src/nxt_fs.c | 3 ++- src/nxt_unix.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nxt_fs.c b/src/nxt_fs.c index 71498f99..0e461e46 100644 --- a/src/nxt_fs.c +++ b/src/nxt_fs.c @@ -4,8 +4,9 @@ #include -#if (NXT_HAVE_FREEBSD_NMOUNT) #include + +#if (NXT_HAVE_FREEBSD_NMOUNT) #include #endif diff --git a/src/nxt_unix.h b/src/nxt_unix.h index 7f9a2914..00f70e56 100644 --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -169,7 +169,7 @@ #endif #include #include -#include /* MAXPATHLEN */ +#include #include #include #include -- 2.36.1 From alx.manpages at gmail.com Mon Jun 20 07:22:29 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:22:29 +0200 Subject: [PATCH v2 00/25] Simplify inclusion conditionals In-Reply-To: <20220620071108.16798-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-1-alx.manpages@gmail.com> Message-ID: On 6/20/22 09:10, Alejandro Colomar wrote: > Hi Andrew, > > v2: > - 05/25: elif -> if > - 20/25: Added a few more cases I found. > - 24/25: Subject wfix > - 25/25: Added patch for > > The rest should be the same as v1, IIRC. > > But patch 25/25 for some reason breaks completely unrelated stuff > from that I can't fix even if I include > directly in the file that breaks. I can't make any > sense of it right now; could you please have a look at it? Try to > compile after 24, which should work, and then compile after 25 and > you'll be shocked, I guess;). Oh, and I forgot to mention: 02/25: Reviewed-by: Andrew Clayton 03/25: Reviewed-by: Andrew Clayton I don't count 05 because it has changed. > > Cheers, > > Alex > > Alejandro Colomar (25): > Including iff it exists. > Including iff it exists. > Including iff it exists. > Including unconditionally. > Including iff it exists. > Including iff it exists. > Including iff it exists. > Including iff it exists. > Including iff it exists. > Including iff it exists. > Including iff it exists. > Including iff it exists. > Including iff it exists. > Including iff it exists. > Removed code used when NXT_HAVE_POSIX_SPAWN is false. > Including iff it exists. > Including iff it exists. > Including unconditionally. > Including unconditionally. > Including and unconditionally. > Including iff it exists. > Including iff it exists. > Removed unnecessary include. > Moved test to . > Including iff it exists. > > auto/headers | 250 ++++++++++++++++++++++++++++++++++++++++++ > auto/sockets | 20 ---- > auto/unix | 15 --- > configure | 1 + > src/nxt_application.c | 2 +- > src/nxt_capability.c | 8 +- > src/nxt_fs.c | 2 - > src/nxt_isolation.c | 2 +- > src/nxt_port_memory.c | 7 +- > src/nxt_process.c | 50 +-------- > src/nxt_process.h | 4 +- > src/nxt_socket_msg.h | 2 +- > src/nxt_unit.c | 2 +- > src/nxt_unix.h | 57 +++++----- > 14 files changed, 294 insertions(+), 128 deletions(-) > create mode 100644 auto/headers > -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From alx.manpages at gmail.com Mon Jun 20 07:32:03 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Mon, 20 Jun 2022 09:32:03 +0200 Subject: [PATCH v2 00/25] Simplify inclusion conditionals In-Reply-To: References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-1-alx.manpages@gmail.com> Message-ID: On 6/20/22 09:22, Alejandro Colomar wrote: > > > On 6/20/22 09:10, Alejandro Colomar wrote: >> Hi Andrew, >> >> v2: >>   - 05/25: elif -> if Oh, for some reason I sent the good version in v1, but for some reason, I kept locally the wrong old version, and I thought I had sent the wrong one. So, ignore the line about 05 :) >>   - 20/25: Added a few more cases I found. >>   - 24/25: Subject wfix >>   - 25/25: Added patch for >> >> The rest should be the same as v1, IIRC. >> >> But patch 25/25 for some reason breaks completely unrelated stuff >> from that I can't fix even if I include >> directly in the file that breaks.  I can't make any >> sense of it right now; could you please have a look at it?  Try to >> compile after 24, which should work, and then compile after 25 and >> you'll be shocked, I guess;). > > Oh, and I forgot to mention: > > 02/25: Reviewed-by: Andrew Clayton > 03/25: Reviewed-by: Andrew Clayton > > I don't count 05 because it has changed. 05/25 is also Reviewed-by: Andrew Clayton -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Mon Jun 20 12:28:41 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 13:28:41 +0100 Subject: [PATCH v2 00/25] Simplify inclusion conditionals In-Reply-To: <20220620071108.16798-1-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-1-alx.manpages@gmail.com> Message-ID: <20220620132841.6307390d@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:43 +0200 Alejandro Colomar wrote: > Hi Andrew, Hi Alex, [...] > But patch 25/25 for some reason breaks completely unrelated stuff > from that I can't fix even if I include > directly in the file that breaks. I can't make any > sense of it right now; could you please have a look at it? Try to > compile after 24, which should work, and then compile after 25 and > you'll be shocked, I guess;). Hmm, it's fine here, Fedora 36, glibc 2.35. Actually last night when I was testing I initially got the following $ make cc -c -pipe -fPIC -fvisibility=hidden -O0 -W -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-prototypes -Werror -g3 -I src -I build \ \ \ -o build/src/nxt_lib.o \ -MMD -MF build/src/nxt_lib.dep -MT build/src/nxt_lib.o \ src/nxt_lib.c In file included from src/nxt_main.h:80, from src/nxt_lib.c:7: src/nxt_socket.h:69:37: error: invalid application of ‘sizeof’ to incomplete type ‘struct sockaddr_un’ 69 | #define NXT_SOCKADDR_LEN sizeof(struct sockaddr_un) | ^~~~~~ src/nxt_socket.h:82:36: note: in expansion of macro ‘NXT_SOCKADDR_LEN’ 82 | char space[NXT_SOCKADDR_LEN]; | ^~~~~~~~~~~~~~~~ In file included from src/nxt_main.h:143: src/nxt_event_engine.h:194:35: error: field ‘event’ has incomplete type 194 | struct epoll_event event; | ^~~~~ In file included from src/nxt_main.h:150: src/nxt_sockaddr.h:55:35: error: field ‘sockaddr_un’ has incomplete type 55 | struct sockaddr_un sockaddr_un; | ^~~~~~~~~~~ make: *** [build/Makefile:163: build/src/nxt_lib.o] Error 1 But then I did a make clean and ./configure && make and all was good. If that doesn't clear it for you, post the failure... I have a Debian VM I can try if the problem persists. Cheers, Andrew From andrew at digital-domain.net Mon Jun 20 12:36:00 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 13:36:00 +0100 Subject: [PATCH v2 00/25] Simplify inclusion conditionals In-Reply-To: <20220620132841.6307390d@kappa.digital-domain.net> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-1-alx.manpages@gmail.com> <20220620132841.6307390d@kappa.digital-domain.net> Message-ID: <20220620133600.63574a3a@kappa.digital-domain.net> On Mon, 20 Jun 2022 13:28:41 +0100 Andrew Clayton wrote: > But then I did a make clean and ./configure && make and all was good. Hmm, so taking my own advice, _now_ I see a load of errors... will investigate. Cheers, Andrew From andrew at digital-domain.net Mon Jun 20 14:32:31 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 15:32:31 +0100 Subject: [PATCH v2 00/25] Simplify inclusion conditionals In-Reply-To: <20220620133600.63574a3a@kappa.digital-domain.net> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-1-alx.manpages@gmail.com> <20220620132841.6307390d@kappa.digital-domain.net> <20220620133600.63574a3a@kappa.digital-domain.net> Message-ID: <20220620153231.28d6cfd8@kappa.digital-domain.net> On Mon, 20 Jun 2022 13:36:00 +0100 Andrew Clayton wrote: > On Mon, 20 Jun 2022 13:28:41 +0100 > Andrew Clayton wrote: > > > But then I did a make clean and ./configure && make and all was good. > > Hmm, so taking my own advice, _now_ I see a load of errors... will > investigate. Not got right to the bottom of it, but here's where we're at. The first error is cc -c -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-prototypes -Werror -g -I src -I build \ \ \ -o build/src/nxt_socketpair.o \ -MMD -MF build/src/nxt_socketpair.dep -MT build/src/nxt_socketpair.o \ src/nxt_socketpair.c In file included from /usr/include/sys/socket.h:33, from /usr/include/netinet/in.h:23, from /usr/include/netdb.h:27, from src/nxt_unix.h:157, from src/nxt_main.h:31, from src/nxt_socketpair.c:7: src/nxt_socket_msg.h:32:54: error: invalid application of ‘sizeof’ to incomplete type ‘nxt_socket_cred_t’ {aka ‘struct ucred’} 32 | (CMSG_SPACE(2 * sizeof(int)) + CMSG_SPACE(sizeof(nxt_socket_cred_t))) | ^~~~~~~~~~~~~~~~~ On Linux/glibc at least, struct ucred is defined in /usr/include/bits/socket.h as #ifdef __USE_GNU /* User visible structure for SCM_CREDENTIALS message */ struct ucred { pid_t pid; /* PID of sending process. */ uid_t uid; /* UID of sending process. */ gid_t gid; /* GID of sending process. */ }; #endif So it needs _GNU_SOURCE defined, as confirmed by this test case #define _GNU_SOURCE 1 #include int main(void) { sizeof(struct ucred); return 0; } Commenting out the #define makes it fail to compile. $ make m cc m.c -o m m.c: In function ‘main’: m.c:9:16: error: invalid application of ‘sizeof’ to incomplete type ‘struct ucred’ 9 | sizeof(struct ucred); | ^~~~~~ make: *** [: m] Error 1 Now previously malloc.h was being included _after_ _GNU_SOURCE was being defined. malloc.h seems to somehow be interfering with that, as demonstrated by #include #define _GNU_SOURCE 1 #include int main(void) { sizeof(struct ucred); return 0; } which fails to build. Indeed if in unit, I comment out the malloc.h include, it builds, or if I define _GNU_SOURCE before it, it builds. Hmm, actually, including any system (at least) header file before _GNU_SOURCE is defined breaks the test program. Arghhhh.... Of course, all these header files include features.h which deals with all the standards macros. So if we include a header file before _GNU_SOURCE is defined, then _FEATURES_H is defined, then if we define _GNU_SOURCE and include more header files, then features.h won't do anything due to _FEATURES_H already being defined and _GNU_SOURCE will have no effect as in /usr/include/features.h #ifdef _GNU_SOURCE # define __USE_GNU 1 #endif won't happen. (__USE_GNU is what glibc seems to use internally for _GNU_SOURCE). OK, so not every header file includes features.h, for example sys/syscall.h which is why things worked before. So maybe we did get to the bottom of it... So it just remains to see how to solve this current issue. But basically you need to define _GNU_SOURCE before including any header file that includes features.h. Cheers, Andrew From imranrazair142 at gmail.com Mon Jun 20 14:33:58 2022 From: imranrazair142 at gmail.com (pubg lover) Date: Mon, 20 Jun 2022 20:03:58 +0530 Subject: [PATCH v2 00/25] Simplify inclusion conditionals In-Reply-To: <20220620153231.28d6cfd8@kappa.digital-domain.net> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-1-alx.manpages@gmail.com> <20220620132841.6307390d@kappa.digital-domain.net> <20220620133600.63574a3a@kappa.digital-domain.net> <20220620153231.28d6cfd8@kappa.digital-domain.net> Message-ID: Hindi language please On Mon, Jun 20, 2022, 8:02 PM Andrew Clayton wrote: > On Mon, 20 Jun 2022 13:36:00 +0100 > Andrew Clayton wrote: > > > On Mon, 20 Jun 2022 13:28:41 +0100 > > Andrew Clayton wrote: > > > > > But then I did a make clean and ./configure && make and all was good. > > > > Hmm, so taking my own advice, _now_ I see a load of errors... will > > investigate. > > Not got right to the bottom of it, but here's where we're at. > > The first error is > > cc -c -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra > -Wno-unused-parameter -Wwrite-strings -Wmissing-prototypes -Werror -g -I > src -I build \ > \ > \ > -o build/src/nxt_socketpair.o \ > -MMD -MF build/src/nxt_socketpair.dep -MT build/src/nxt_socketpair.o \ > src/nxt_socketpair.c > In file included from /usr/include/sys/socket.h:33, > from /usr/include/netinet/in.h:23, > from /usr/include/netdb.h:27, > from src/nxt_unix.h:157, > from src/nxt_main.h:31, > from src/nxt_socketpair.c:7: > src/nxt_socket_msg.h:32:54: error: invalid application of ‘sizeof’ to > incomplete type ‘nxt_socket_cred_t’ {aka ‘struct ucred’} > 32 | (CMSG_SPACE(2 * sizeof(int)) + > CMSG_SPACE(sizeof(nxt_socket_cred_t))) > | > ^~~~~~~~~~~~~~~~~ > > On Linux/glibc at least, struct ucred is defined in > /usr/include/bits/socket.h as > > #ifdef __USE_GNU > > /* User visible structure for SCM_CREDENTIALS message */ > > struct ucred > > { > > pid_t pid; /* PID of sending process. */ > > uid_t uid; /* UID of sending process. */ > > gid_t gid; /* GID of sending process. */ > > }; > > #endif > > So it needs _GNU_SOURCE defined, as confirmed by this test case > > #define _GNU_SOURCE 1 > > > #include > > > int main(void) > > { > > sizeof(struct ucred); > > return 0; > > } > > Commenting out the #define makes it fail to compile. > > $ make m > cc m.c -o m > m.c: In function ‘main’: > m.c:9:16: error: invalid application of ‘sizeof’ to incomplete type > ‘struct ucred’ > 9 | sizeof(struct ucred); > | ^~~~~~ > make: *** [: m] Error 1 > > Now previously malloc.h was being included _after_ _GNU_SOURCE was being > defined. > malloc.h seems to somehow be interfering with that, as demonstrated by > > #include > > > #define _GNU_SOURCE 1 > > > #include > > > int main(void) > > { > > sizeof(struct ucred); > > return 0; > > } > > > which fails to build. > > Indeed if in unit, I comment out the malloc.h include, it builds, or if > I define _GNU_SOURCE before it, it builds. > > Hmm, actually, including any system (at least) header file before > _GNU_SOURCE is defined breaks the test program. > > Arghhhh.... > > Of course, all these header files include features.h which deals with > all the standards macros. > > So if we include a header file before _GNU_SOURCE is defined, then > _FEATURES_H is defined, then if we define _GNU_SOURCE and include more > header files, then features.h won't do anything due to _FEATURES_H > already being defined and _GNU_SOURCE will have no effect as in > /usr/include/features.h > > #ifdef _GNU_SOURCE > # define __USE_GNU 1 > #endif > > won't happen. (__USE_GNU is what glibc seems to use internally for > _GNU_SOURCE). > > OK, so not every header file includes features.h, for example > sys/syscall.h which is why things worked before. > > So maybe we did get to the bottom of it... > > So it just remains to see how to solve this current issue. But > basically you need to define _GNU_SOURCE before including any header > file that includes features.h. > > Cheers, > Andrew > > _______________________________________________ > unit mailing list -- unit at nginx.org > To unsubscribe send an email to unit-leave at nginx.org > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew at digital-domain.net Mon Jun 20 14:47:19 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 15:47:19 +0100 Subject: [PATCH v2 25/25] Including iff it exists. In-Reply-To: <20220620071108.16798-26-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-26-alx.manpages@gmail.com> Message-ID: <20220620154719.75ca6f8f@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:11:08 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 6 ++++-- > 2 files changed, 17 insertions(+), 2 deletions(-) [...] > diff --git a/src/nxt_unix.h b/src/nxt_unix.h > index 60062610..891375fc 100644 > --- a/src/nxt_unix.h > +++ b/src/nxt_unix.h > @@ -11,6 +11,10 @@ > > #include > > +#if (NXT_HAVE_MALLOC_H) > +#include > +#endif > + > > #if (NXT_LINUX) > > @@ -32,8 +36,6 @@ > > #define _FILE_OFFSET_BITS 64 > > -#include /* malloc_usable_size(). */ > - > #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 4) > /* > * POSIX semaphores using NPTL atomic/futex operations So to re-cap (from the other email, Message-ID: <20220620153231.28d6cfd8 at kappa.digital-domain.net>) this breaks the build on at least Linux due to malloc.h being included before _GNU_SOURCE is defined. _GNU_SOURCE needs to be defined before features.h is included and malloc.h includes features.h before _GNU_SOURCE is being defined now. Cheers, Andrew From andrew at digital-domain.net Mon Jun 20 19:40:32 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 20:40:32 +0100 Subject: [PATCH v2 24/25] Moved test to . In-Reply-To: <20220620071108.16798-25-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-25-alx.manpages@gmail.com> Message-ID: <20220620204032.5099e5de@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:11:07 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > auto/sockets | 13 ------------- > 2 files changed, 13 insertions(+), 13 deletions(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Mon Jun 20 19:52:02 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 20:52:02 +0100 Subject: [PATCH v2 13/25] Including iff it exists. In-Reply-To: <20220620071108.16798-14-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-14-alx.manpages@gmail.com> Message-ID: <20220620205202.110d0dde@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:56 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 7 +++---- > 2 files changed, 16 insertions(+), 4 deletions(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Mon Jun 20 19:53:22 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 20:53:22 +0100 Subject: [PATCH v2 11/25] Including iff it exists. In-Reply-To: <20220620071108.16798-12-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-12-alx.manpages@gmail.com> Message-ID: <20220620205322.775420c6@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:54 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 2 +- > 2 files changed, 14 insertions(+), 1 deletion(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Mon Jun 20 19:59:20 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 20:59:20 +0100 Subject: [PATCH v2 12/25] Including iff it exists. In-Reply-To: <20220620071108.16798-13-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-13-alx.manpages@gmail.com> Message-ID: <20220620205920.00a78083@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:55 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 2 +- > 2 files changed, 14 insertions(+), 1 deletion(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Mon Jun 20 20:09:54 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 21:09:54 +0100 Subject: [PATCH v2 00/25] Simplify inclusion conditionals In-Reply-To: <20220620153231.28d6cfd8@kappa.digital-domain.net> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-1-alx.manpages@gmail.com> <20220620132841.6307390d@kappa.digital-domain.net> <20220620133600.63574a3a@kappa.digital-domain.net> <20220620153231.28d6cfd8@kappa.digital-domain.net> Message-ID: <20220620210954.6ad6f4b6@kappa.digital-domain.net> On Mon, 20 Jun 2022 15:32:31 +0100 Andrew Clayton wrote: > OK, so not every header file includes features.h, for example > sys/syscall.h which is why things worked before. Ah, OK, sys/syscall.h was moved by one of the patches, but it doesn't cause any issues... From andrew at digital-domain.net Mon Jun 20 20:18:58 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 21:18:58 +0100 Subject: [PATCH v2 23/25] Removed unnecessary include. In-Reply-To: <20220620071108.16798-24-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-24-alx.manpages@gmail.com> Message-ID: <20220620211858.7ad24d3a@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:11:06 +0200 Alejandro Colomar wrote: > Some OSes, as Linux, provide FIONBIO in . Others, > such as the BSDs and Illumos, provide it in , but > they all include that header from , so for this test, > we can simplify and just include . > --- > auto/sockets | 7 ------- > 1 file changed, 7 deletions(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Mon Jun 20 20:21:51 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Mon, 20 Jun 2022 21:21:51 +0100 Subject: [PATCH v2 22/25] Including iff it exists. In-Reply-To: <20220620071108.16798-23-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-23-alx.manpages@gmail.com> Message-ID: <20220620212151.7c168466@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:11:05 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_capability.c | 6 ++++-- > 2 files changed, 17 insertions(+), 2 deletions(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Tue Jun 21 01:35:39 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Tue, 21 Jun 2022 02:35:39 +0100 Subject: [PATCH v2 14/25] Including iff it exists. In-Reply-To: <20220620071108.16798-15-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-15-alx.manpages@gmail.com> Message-ID: <20220621023539.78c0879d@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:57 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_socket_msg.h | 2 +- > src/nxt_unix.h | 2 +- > 3 files changed, 15 insertions(+), 2 deletions(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Tue Jun 21 01:59:10 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Tue, 21 Jun 2022 02:59:10 +0100 Subject: [PATCH v2 19/25] Including unconditionally. In-Reply-To: <20220620071108.16798-20-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-20-alx.manpages@gmail.com> Message-ID: <20220621025910.27dc7f1b@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:11:02 +0200 Alejandro Colomar wrote: > --- > src/nxt_fs.c | 3 --- > 1 file changed, 3 deletions(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Tue Jun 21 02:01:33 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Tue, 21 Jun 2022 03:01:33 +0100 Subject: [PATCH v2 07/25] Including iff it exists. In-Reply-To: <20220620071108.16798-8-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-8-alx.manpages@gmail.com> Message-ID: <20220621030133.4b324e2a@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:50 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 2 +- > 2 files changed, 14 insertions(+), 1 deletion(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Tue Jun 21 02:02:24 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Tue, 21 Jun 2022 03:02:24 +0100 Subject: [PATCH v2 08/25] Including iff it exists. In-Reply-To: <20220620071108.16798-9-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-9-alx.manpages@gmail.com> Message-ID: <20220621030224.2abeff5f@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:51 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 2 +- > 2 files changed, 14 insertions(+), 1 deletion(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Tue Jun 21 02:03:59 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Tue, 21 Jun 2022 03:03:59 +0100 Subject: [PATCH v2 09/25] Including iff it exists. In-Reply-To: <20220620071108.16798-10-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-10-alx.manpages@gmail.com> Message-ID: <20220621030359.295a433b@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:52 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 2 +- > 2 files changed, 14 insertions(+), 1 deletion(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Tue Jun 21 02:05:03 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Tue, 21 Jun 2022 03:05:03 +0100 Subject: [PATCH v2 10/25] Including iff it exists. In-Reply-To: <20220620071108.16798-11-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-11-alx.manpages@gmail.com> Message-ID: <20220621030503.3c7131cb@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:53 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 2 +- > 2 files changed, 14 insertions(+), 1 deletion(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Tue Jun 21 02:06:00 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Tue, 21 Jun 2022 03:06:00 +0100 Subject: [PATCH v2 16/25] Including iff it exists. In-Reply-To: <20220620071108.16798-17-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-17-alx.manpages@gmail.com> Message-ID: <20220621030600.181a33d6@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:10:59 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 2 +- > 2 files changed, 14 insertions(+), 1 deletion(-) Reviewed-by: Andrew Clayton From andrew at digital-domain.net Tue Jun 21 02:14:38 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Tue, 21 Jun 2022 03:14:38 +0100 Subject: [PATCH v2 17/25] Including iff it exists. In-Reply-To: <20220620071108.16798-18-alx.manpages@gmail.com> References: <20220619135032.19351-1-alx.manpages@gmail.com> <20220620071108.16798-18-alx.manpages@gmail.com> Message-ID: <20220621031438.18a04b81@kappa.digital-domain.net> On Mon, 20 Jun 2022 09:11:00 +0200 Alejandro Colomar wrote: > --- > auto/headers | 13 +++++++++++++ > src/nxt_unix.h | 4 ++-- > 2 files changed, 15 insertions(+), 2 deletions(-) Reviewed-by: Andrew Clayton From alx.manpages at gmail.com Tue Jun 21 23:01:06 2022 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Wed, 22 Jun 2022 01:01:06 +0200 Subject: [PATCH 09/11] Router: removed unused structure member proxy_buffers. In-Reply-To: <20220616190308.6d4ca6cf@kappa.digital-domain.net> References: <20220616010101.55677-1-andrew@digital-domain.net> <20220616010101.55677-10-andrew@digital-domain.net> <077bbf24-7f89-8df2-7a5a-be8966e2e9f2@gmail.com> <20220616190308.6d4ca6cf@kappa.digital-domain.net> Message-ID: <365deda4-9828-c1f9-52a1-d0cb6485ebfb@gmail.com> Hi Andrew, On 6/16/22 20:03, Andrew Clayton wrote: > On Thu, 16 Jun 2022 17:59:25 +0200 > Alejandro Colomar wrote: > >> On 6/16/22 03:00, Andrew Clayton wrote: >>> proxy_buffers is declared as a structure member of nxt_socket_conf_t and >>> is set in nxt_router_conf_create(), however it is not used anywhere. >>> >>> Removing it has the nice side effect of making the nxt_socket_conf_t >>> structure require one less cacheline (on x86-64 at least) as the summary >>> from pahole[0] shows >>> >>> Before >>> >>> /* size: 200, cachelines: 4, members: 25 */ >>> /* sum members: 185, holes: 3, sum holes: 15 */ >>> >>> After >>> >>> /* size: 192, cachelines: 3, members: 24 */ >>> /* sum members: 177, holes: 3, sum holes: 15 */ >>> >>> [0]: https://github.com/acmel/dwarves >> >> Reviewed-by: Alejandro Colomar I run this patch under the build bot 2 times, one of them triggered errors I hadn't seen before, and the other went well. That looks like undefined behavior somewhere (I'm attributing it to this patch because it's the only one from the reviewed ones that actually changes something that's not compile-time-only); I'm not saying that it's a problem of this patch; it could be that this change triggers another UB that was already existing but hidden). So I'm not applying this patch until we know more about it. :/ Cheers, Alex > > Thanks! > > Cheers, > Andrew -- Alejandro Colomar -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From andrew at digital-domain.net Thu Jun 23 19:09:48 2022 From: andrew at digital-domain.net (Andrew Clayton) Date: Thu, 23 Jun 2022 20:09:48 +0100 Subject: [PATCH V2] Route: avoided undefined behaviour. In-Reply-To: <20220616010101.55677-8-andrew@digital-domain.net> References: <20220616010101.55677-8-andrew@digital-domain.net> Message-ID: <20220623190948.6976-1-andrew@digital-domain.net> In src/nxt_http_route_addr.c::nxt_http_route_addr_pattern_parse() there was potentially undefined behaviour when shifting a 32 bit value by 32 bits, this could happen if cidr_prefix was 0. Promote the shiftee to unsigned long long to avoid this issue. --- V2 Changes * Promote the shiftee to ULL rather than just UL src/nxt_http_route_addr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nxt_http_route_addr.c b/src/nxt_http_route_addr.c index 2907a90..985fb73 100644 --- a/src/nxt_http_route_addr.c +++ b/src/nxt_http_route_addr.c @@ -233,7 +233,7 @@ nxt_http_route_addr_pattern_parse(nxt_mp_t *mp, } addr.length = delim - addr.start; - inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFF << (32 - cidr_prefix))); + inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFFULL << (32 - cidr_prefix))); inet->start = nxt_inet_addr(addr.start, addr.length) & inet->end; if (nxt_slow_path(inet->start == INADDR_NONE)) { -- 2.36.1 From imranrazair142 at gmail.com Thu Jun 23 23:38:06 2022 From: imranrazair142 at gmail.com (pubg lover) Date: Fri, 24 Jun 2022 05:08:06 +0530 Subject: [PATCH V2] Route: avoided undefined behaviour. In-Reply-To: <20220623190948.6976-1-andrew@digital-domain.net> References: <20220616010101.55677-8-andrew@digital-domain.net> <20220623190948.6976-1-andrew@digital-domain.net> Message-ID: Hindi language please On Fri, Jun 24, 2022, 12:40 AM Andrew Clayton wrote: > In src/nxt_http_route_addr.c::nxt_http_route_addr_pattern_parse() there > was potentially undefined behaviour when shifting a 32 bit value by 32 > bits, this could happen if cidr_prefix was 0. > > Promote the shiftee to unsigned long long to avoid this issue. > --- > V2 Changes > > * Promote the shiftee to ULL rather than just UL > > src/nxt_http_route_addr.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/nxt_http_route_addr.c b/src/nxt_http_route_addr.c > index 2907a90..985fb73 100644 > --- a/src/nxt_http_route_addr.c > +++ b/src/nxt_http_route_addr.c > @@ -233,7 +233,7 @@ nxt_http_route_addr_pattern_parse(nxt_mp_t *mp, > } > > addr.length = delim - addr.start; > - inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFF << (32 - > cidr_prefix))); > + inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFFULL << (32 - > cidr_prefix))); > > inet->start = nxt_inet_addr(addr.start, addr.length) & inet->end; > if (nxt_slow_path(inet->start == INADDR_NONE)) { > -- > 2.36.1 > > _______________________________________________ > unit mailing list -- unit at nginx.org > To unsubscribe send an email to unit-leave at nginx.org > -------------- next part -------------- An HTML attachment was scrubbed... URL: