[PATCH] Improved code readablity of ngx_cache_manager_process_cycle.
Ruslan Ermilov
ru at nginx.com
Thu Apr 5 11:12:04 UTC 2018
On Thu, Apr 05, 2018 at 12:37:19PM +0800, Zexuan Luo wrote:
> # HG changeset patch
> # User spacewander <spacewanderlzx at gmail.com>
> # Date 1522902794 -28800
> # Thu Apr 05 12:33:14 2018 +0800
> # Branch ident
> # Node ID e0834ca20c9c68c4f0728f85efb3651732134ee2
> # Parent d4cc2edb4ff8391d0c7419e91e6fcc988c510654
> Improved code readablity of ngx_cache_manager_process_cycle.
>
> diff -r d4cc2edb4ff8 -r e0834ca20c9c src/os/unix/ngx_process_cycle.c
> --- a/src/os/unix/ngx_process_cycle.c Tue Apr 03 17:38:10 2018 +0300
> +++ b/src/os/unix/ngx_process_cycle.c Thu Apr 05 12:33:14 2018 +0800
> @@ -1128,7 +1128,7 @@
> {
> ngx_cache_manager_ctx_t *ctx = data;
>
> - void *ident[4];
> + u_char ident[offsetof(ngx_connection_t, fd) +
> sizeof(ngx_socket_t)];
> ngx_event_t ev;
>
> /*
> @@ -1148,7 +1148,7 @@
> ev.handler = ctx->handler;
> ev.data = ident;
> ev.log = cycle->log;
> - ident[3] = (void *) -1;
> + *(ngx_socket_t *)(ident + offsetof(ngx_connection_t, fd)) = -1;
>
> ngx_use_accept_mutex = 0;
How's this instead? A similar comment also exists in ngx_resolver.h.
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -1128,8 +1128,10 @@ ngx_cache_manager_process_cycle(ngx_cycl
{
ngx_cache_manager_ctx_t *ctx = data;
- void *ident[4];
- ngx_event_t ev;
+ /* event ident must be after 3 pointers as in ngx_connection_t */
+ void *ident[4];
+ ngx_event_t ev;
+ ngx_connection_t *c;
/*
* Set correct process type since closing listening Unix domain socket
@@ -1144,11 +1146,13 @@ ngx_cache_manager_process_cycle(ngx_cycl
ngx_worker_process_init(cycle, -1);
+ c = (ngx_connection_t *) ident;
+ c->fd = (ngx_socket_t) -1;
+
ngx_memzero(&ev, sizeof(ngx_event_t));
ev.handler = ctx->handler;
- ev.data = ident;
+ ev.data = c;
ev.log = cycle->log;
- ident[3] = (void *) -1;
ngx_use_accept_mutex = 0;
More information about the nginx-devel
mailing list