xref: /unit/src/nxt_router_access_log.c (revision 2166)
12165Sz.hong@f5.com 
22165Sz.hong@f5.com /*
32165Sz.hong@f5.com  * Copyright (C) Igor Sysoev
42165Sz.hong@f5.com  * Copyright (C) Valentin V. Bartenev
52165Sz.hong@f5.com  * Copyright (C) NGINX, Inc.
62165Sz.hong@f5.com  */
72165Sz.hong@f5.com 
82165Sz.hong@f5.com #include <nxt_router.h>
92165Sz.hong@f5.com #include <nxt_conf.h>
102165Sz.hong@f5.com #include <nxt_http.h>
112165Sz.hong@f5.com 
122165Sz.hong@f5.com 
13*2166Sz.hong@f5.com typedef struct {
14*2166Sz.hong@f5.com     nxt_str_t                 path;
15*2166Sz.hong@f5.com     nxt_str_t                 format;
16*2166Sz.hong@f5.com } nxt_router_access_log_conf_t;
17*2166Sz.hong@f5.com 
18*2166Sz.hong@f5.com 
19*2166Sz.hong@f5.com typedef struct {
20*2166Sz.hong@f5.com     nxt_str_t                 text;
21*2166Sz.hong@f5.com     nxt_router_access_log_t   *access_log;
22*2166Sz.hong@f5.com } nxt_router_access_log_ctx_t;
23*2166Sz.hong@f5.com 
24*2166Sz.hong@f5.com 
252165Sz.hong@f5.com static void nxt_router_access_log_writer(nxt_task_t *task,
26*2166Sz.hong@f5.com     nxt_http_request_t *r, nxt_router_access_log_t *access_log,
27*2166Sz.hong@f5.com     nxt_var_t *format);
28*2166Sz.hong@f5.com static void nxt_router_access_log_write_ready(nxt_task_t *task, void *obj,
29*2166Sz.hong@f5.com     void *data);
30*2166Sz.hong@f5.com static void nxt_router_access_log_write_error(nxt_task_t *task, void *obj,
31*2166Sz.hong@f5.com     void *data);
322165Sz.hong@f5.com static void nxt_router_access_log_ready(nxt_task_t *task,
332165Sz.hong@f5.com     nxt_port_recv_msg_t *msg, void *data);
342165Sz.hong@f5.com static void nxt_router_access_log_error(nxt_task_t *task,
352165Sz.hong@f5.com     nxt_port_recv_msg_t *msg, void *data);
362165Sz.hong@f5.com static void nxt_router_access_log_reopen_completion(nxt_task_t *task, void *obj,
372165Sz.hong@f5.com     void *data);
382165Sz.hong@f5.com static void nxt_router_access_log_reopen_ready(nxt_task_t *task,
392165Sz.hong@f5.com     nxt_port_recv_msg_t *msg, void *data);
402165Sz.hong@f5.com static void nxt_router_access_log_reopen_error(nxt_task_t *task,
412165Sz.hong@f5.com     nxt_port_recv_msg_t *msg, void *data);
422165Sz.hong@f5.com 
432165Sz.hong@f5.com 
44*2166Sz.hong@f5.com static nxt_conf_map_t  nxt_router_access_log_conf[] = {
45*2166Sz.hong@f5.com     {
46*2166Sz.hong@f5.com         nxt_string("path"),
47*2166Sz.hong@f5.com         NXT_CONF_MAP_STR,
48*2166Sz.hong@f5.com         offsetof(nxt_router_access_log_conf_t, path),
49*2166Sz.hong@f5.com     },
50*2166Sz.hong@f5.com 
51*2166Sz.hong@f5.com     {
52*2166Sz.hong@f5.com         nxt_string("format"),
53*2166Sz.hong@f5.com         NXT_CONF_MAP_STR,
54*2166Sz.hong@f5.com         offsetof(nxt_router_access_log_conf_t, format),
55*2166Sz.hong@f5.com     },
56*2166Sz.hong@f5.com };
57*2166Sz.hong@f5.com 
58*2166Sz.hong@f5.com 
592165Sz.hong@f5.com nxt_int_t
602165Sz.hong@f5.com nxt_router_access_log_create(nxt_task_t *task, nxt_router_conf_t *rtcf,
612165Sz.hong@f5.com     nxt_conf_value_t *value)
622165Sz.hong@f5.com {
63*2166Sz.hong@f5.com     u_char                        *p;
64*2166Sz.hong@f5.com     nxt_int_t                     ret;
65*2166Sz.hong@f5.com     nxt_str_t                     str;
66*2166Sz.hong@f5.com     nxt_var_t                     *format;
67*2166Sz.hong@f5.com     nxt_router_t                  *router;
68*2166Sz.hong@f5.com     nxt_router_access_log_t       *access_log;
69*2166Sz.hong@f5.com     nxt_router_access_log_conf_t  alcf;
70*2166Sz.hong@f5.com 
71*2166Sz.hong@f5.com     static nxt_str_t  log_format_str = nxt_string("$remote_addr - - "
72*2166Sz.hong@f5.com         "[$time_local] \"$request_line\" $status $body_bytes_sent "
73*2166Sz.hong@f5.com         "\"$header_referer\" \"$header_user_agent\"");
74*2166Sz.hong@f5.com 
75*2166Sz.hong@f5.com     alcf.format = log_format_str;
76*2166Sz.hong@f5.com 
77*2166Sz.hong@f5.com     if (nxt_conf_type(value) == NXT_CONF_STRING) {
78*2166Sz.hong@f5.com         nxt_conf_get_string(value, &alcf.path);
79*2166Sz.hong@f5.com 
80*2166Sz.hong@f5.com     } else {
81*2166Sz.hong@f5.com         ret = nxt_conf_map_object(rtcf->mem_pool, value,
82*2166Sz.hong@f5.com                                   nxt_router_access_log_conf,
83*2166Sz.hong@f5.com                                   nxt_nitems(nxt_router_access_log_conf),
84*2166Sz.hong@f5.com                                   &alcf);
85*2166Sz.hong@f5.com         if (ret != NXT_OK) {
86*2166Sz.hong@f5.com             nxt_alert(task, "access log map error");
87*2166Sz.hong@f5.com             return NXT_ERROR;
88*2166Sz.hong@f5.com         }
89*2166Sz.hong@f5.com     }
902165Sz.hong@f5.com 
912165Sz.hong@f5.com     router = nxt_router;
922165Sz.hong@f5.com 
932165Sz.hong@f5.com     access_log = router->access_log;
942165Sz.hong@f5.com 
95*2166Sz.hong@f5.com     if (access_log != NULL && nxt_strstr_eq(&alcf.path, &access_log->path)) {
962165Sz.hong@f5.com         nxt_router_access_log_use(&router->lock, access_log);
972165Sz.hong@f5.com 
982165Sz.hong@f5.com     } else {
992165Sz.hong@f5.com         access_log = nxt_malloc(sizeof(nxt_router_access_log_t)
100*2166Sz.hong@f5.com                                 + alcf.path.length);
1012165Sz.hong@f5.com         if (access_log == NULL) {
1022165Sz.hong@f5.com             nxt_alert(task, "failed to allocate access log structure");
1032165Sz.hong@f5.com             return NXT_ERROR;
1042165Sz.hong@f5.com         }
1052165Sz.hong@f5.com 
1062165Sz.hong@f5.com         access_log->fd = -1;
1072165Sz.hong@f5.com         access_log->handler = &nxt_router_access_log_writer;
1082165Sz.hong@f5.com         access_log->count = 1;
1092165Sz.hong@f5.com 
110*2166Sz.hong@f5.com         access_log->path.length = alcf.path.length;
1112165Sz.hong@f5.com         access_log->path.start = (u_char *) access_log
1122165Sz.hong@f5.com                                  + sizeof(nxt_router_access_log_t);
1132165Sz.hong@f5.com 
114*2166Sz.hong@f5.com         nxt_memcpy(access_log->path.start, alcf.path.start, alcf.path.length);
115*2166Sz.hong@f5.com     }
116*2166Sz.hong@f5.com 
117*2166Sz.hong@f5.com     str.length = alcf.format.length + 1;
118*2166Sz.hong@f5.com 
119*2166Sz.hong@f5.com     str.start = nxt_malloc(str.length);
120*2166Sz.hong@f5.com     if (str.start == NULL) {
121*2166Sz.hong@f5.com         nxt_alert(task, "failed to allocate log format structure");
122*2166Sz.hong@f5.com         return NXT_ERROR;
123*2166Sz.hong@f5.com     }
124*2166Sz.hong@f5.com 
125*2166Sz.hong@f5.com     p = nxt_cpymem(str.start, alcf.format.start, alcf.format.length);
126*2166Sz.hong@f5.com     *p = '\n';
127*2166Sz.hong@f5.com 
128*2166Sz.hong@f5.com     format = nxt_var_compile(&str, rtcf->mem_pool, rtcf->var_fields,
129*2166Sz.hong@f5.com                              NXT_VAR_LOGGING);
130*2166Sz.hong@f5.com     if (nxt_slow_path(format == NULL)) {
131*2166Sz.hong@f5.com         return NXT_ERROR;
1322165Sz.hong@f5.com     }
1332165Sz.hong@f5.com 
1342165Sz.hong@f5.com     rtcf->access_log = access_log;
135*2166Sz.hong@f5.com     rtcf->log_format = format;
1362165Sz.hong@f5.com 
1372165Sz.hong@f5.com     return NXT_OK;
1382165Sz.hong@f5.com }
1392165Sz.hong@f5.com 
1402165Sz.hong@f5.com 
1412165Sz.hong@f5.com static void
1422165Sz.hong@f5.com nxt_router_access_log_writer(nxt_task_t *task, nxt_http_request_t *r,
143*2166Sz.hong@f5.com     nxt_router_access_log_t *access_log, nxt_var_t *format)
1442165Sz.hong@f5.com {
145*2166Sz.hong@f5.com     nxt_int_t                    ret;
146*2166Sz.hong@f5.com     nxt_router_access_log_ctx_t  *ctx;
1472165Sz.hong@f5.com 
148*2166Sz.hong@f5.com     ctx = nxt_mp_get(r->mem_pool, sizeof(nxt_router_access_log_ctx_t));
149*2166Sz.hong@f5.com     if (nxt_slow_path(ctx == NULL)) {
1502165Sz.hong@f5.com         return;
1512165Sz.hong@f5.com     }
1522165Sz.hong@f5.com 
153*2166Sz.hong@f5.com     ctx->access_log = access_log;
1542165Sz.hong@f5.com 
155*2166Sz.hong@f5.com     if (nxt_var_is_const(format)) {
156*2166Sz.hong@f5.com         nxt_var_raw(format, &ctx->text);
1572165Sz.hong@f5.com 
158*2166Sz.hong@f5.com         nxt_router_access_log_write_ready(task, r, ctx);
1592165Sz.hong@f5.com 
1602165Sz.hong@f5.com     } else {
161*2166Sz.hong@f5.com         ret = nxt_var_query_init(&r->var_query, r, r->mem_pool);
162*2166Sz.hong@f5.com         if (nxt_slow_path(ret != NXT_OK)) {
163*2166Sz.hong@f5.com             return;
164*2166Sz.hong@f5.com         }
1652165Sz.hong@f5.com 
166*2166Sz.hong@f5.com         nxt_var_query(task, r->var_query, format, &ctx->text);
167*2166Sz.hong@f5.com         nxt_var_query_resolve(task, r->var_query, ctx,
168*2166Sz.hong@f5.com                               nxt_router_access_log_write_ready,
169*2166Sz.hong@f5.com                               nxt_router_access_log_write_error);
170*2166Sz.hong@f5.com      }
1712165Sz.hong@f5.com }
1722165Sz.hong@f5.com 
1732165Sz.hong@f5.com 
174*2166Sz.hong@f5.com static void
175*2166Sz.hong@f5.com nxt_router_access_log_write_ready(nxt_task_t *task, void *obj, void *data)
1762165Sz.hong@f5.com {
177*2166Sz.hong@f5.com     nxt_http_request_t           *r;
178*2166Sz.hong@f5.com     nxt_router_access_log_ctx_t  *ctx;
1792165Sz.hong@f5.com 
180*2166Sz.hong@f5.com     r = obj;
181*2166Sz.hong@f5.com     ctx = data;
1822165Sz.hong@f5.com 
183*2166Sz.hong@f5.com     nxt_fd_write(ctx->access_log->fd, ctx->text.start, ctx->text.length);
184*2166Sz.hong@f5.com 
185*2166Sz.hong@f5.com     nxt_http_request_close_handler(task, r, r->proto.any);
186*2166Sz.hong@f5.com }
1872165Sz.hong@f5.com 
1882165Sz.hong@f5.com 
189*2166Sz.hong@f5.com static void
190*2166Sz.hong@f5.com nxt_router_access_log_write_error(nxt_task_t *task, void *obj, void *data)
191*2166Sz.hong@f5.com {
192*2166Sz.hong@f5.com 
1932165Sz.hong@f5.com }
1942165Sz.hong@f5.com 
1952165Sz.hong@f5.com 
1962165Sz.hong@f5.com void
1972165Sz.hong@f5.com nxt_router_access_log_open(nxt_task_t *task, nxt_router_temp_conf_t *tmcf)
1982165Sz.hong@f5.com {
1992165Sz.hong@f5.com     uint32_t                 stream;
2002165Sz.hong@f5.com     nxt_int_t                ret;
2012165Sz.hong@f5.com     nxt_buf_t                *b;
2022165Sz.hong@f5.com     nxt_port_t               *main_port, *router_port;
2032165Sz.hong@f5.com     nxt_runtime_t            *rt;
2042165Sz.hong@f5.com     nxt_router_access_log_t  *access_log;
2052165Sz.hong@f5.com 
2062165Sz.hong@f5.com     access_log = tmcf->router_conf->access_log;
2072165Sz.hong@f5.com 
2082165Sz.hong@f5.com     b = nxt_buf_mem_alloc(tmcf->mem_pool, access_log->path.length + 1, 0);
2092165Sz.hong@f5.com     if (nxt_slow_path(b == NULL)) {
2102165Sz.hong@f5.com         goto fail;
2112165Sz.hong@f5.com     }
2122165Sz.hong@f5.com 
2132165Sz.hong@f5.com     b->completion_handler = nxt_buf_dummy_completion;
2142165Sz.hong@f5.com 
2152165Sz.hong@f5.com     nxt_buf_cpystr(b, &access_log->path);
2162165Sz.hong@f5.com     *b->mem.free++ = '\0';
2172165Sz.hong@f5.com 
2182165Sz.hong@f5.com     rt = task->thread->runtime;
2192165Sz.hong@f5.com     main_port = rt->port_by_type[NXT_PROCESS_MAIN];
2202165Sz.hong@f5.com     router_port = rt->port_by_type[NXT_PROCESS_ROUTER];
2212165Sz.hong@f5.com 
2222165Sz.hong@f5.com     stream = nxt_port_rpc_register_handler(task, router_port,
2232165Sz.hong@f5.com                                            nxt_router_access_log_ready,
2242165Sz.hong@f5.com                                            nxt_router_access_log_error,
2252165Sz.hong@f5.com                                            -1, tmcf);
2262165Sz.hong@f5.com     if (nxt_slow_path(stream == 0)) {
2272165Sz.hong@f5.com         goto fail;
2282165Sz.hong@f5.com     }
2292165Sz.hong@f5.com 
2302165Sz.hong@f5.com     ret = nxt_port_socket_write(task, main_port, NXT_PORT_MSG_ACCESS_LOG, -1,
2312165Sz.hong@f5.com                                 stream, router_port->id, b);
2322165Sz.hong@f5.com 
2332165Sz.hong@f5.com     if (nxt_slow_path(ret != NXT_OK)) {
2342165Sz.hong@f5.com         nxt_port_rpc_cancel(task, router_port, stream);
2352165Sz.hong@f5.com         goto fail;
2362165Sz.hong@f5.com     }
2372165Sz.hong@f5.com 
2382165Sz.hong@f5.com     return;
2392165Sz.hong@f5.com 
2402165Sz.hong@f5.com fail:
2412165Sz.hong@f5.com 
2422165Sz.hong@f5.com     nxt_router_conf_error(task, tmcf);
2432165Sz.hong@f5.com }
2442165Sz.hong@f5.com 
2452165Sz.hong@f5.com 
2462165Sz.hong@f5.com static void
2472165Sz.hong@f5.com nxt_router_access_log_ready(nxt_task_t *task, nxt_port_recv_msg_t *msg,
2482165Sz.hong@f5.com     void *data)
2492165Sz.hong@f5.com {
2502165Sz.hong@f5.com     nxt_router_temp_conf_t   *tmcf;
2512165Sz.hong@f5.com     nxt_router_access_log_t  *access_log;
2522165Sz.hong@f5.com 
2532165Sz.hong@f5.com     tmcf = data;
2542165Sz.hong@f5.com 
2552165Sz.hong@f5.com     access_log = tmcf->router_conf->access_log;
2562165Sz.hong@f5.com 
2572165Sz.hong@f5.com     access_log->fd = msg->fd[0];
2582165Sz.hong@f5.com 
2592165Sz.hong@f5.com     nxt_work_queue_add(&task->thread->engine->fast_work_queue,
2602165Sz.hong@f5.com                        nxt_router_conf_apply, task, tmcf, NULL);
2612165Sz.hong@f5.com }
2622165Sz.hong@f5.com 
2632165Sz.hong@f5.com 
2642165Sz.hong@f5.com static void
2652165Sz.hong@f5.com nxt_router_access_log_error(nxt_task_t *task, nxt_port_recv_msg_t *msg,
2662165Sz.hong@f5.com     void *data)
2672165Sz.hong@f5.com {
2682165Sz.hong@f5.com     nxt_router_temp_conf_t  *tmcf;
2692165Sz.hong@f5.com 
2702165Sz.hong@f5.com     tmcf = data;
2712165Sz.hong@f5.com 
2722165Sz.hong@f5.com     nxt_router_conf_error(task, tmcf);
2732165Sz.hong@f5.com }
2742165Sz.hong@f5.com 
2752165Sz.hong@f5.com 
2762165Sz.hong@f5.com void
2772165Sz.hong@f5.com nxt_router_access_log_use(nxt_thread_spinlock_t *lock,
2782165Sz.hong@f5.com     nxt_router_access_log_t *access_log)
2792165Sz.hong@f5.com {
2802165Sz.hong@f5.com     if (access_log == NULL) {
2812165Sz.hong@f5.com         return;
2822165Sz.hong@f5.com     }
2832165Sz.hong@f5.com 
2842165Sz.hong@f5.com     nxt_thread_spin_lock(lock);
2852165Sz.hong@f5.com 
2862165Sz.hong@f5.com     access_log->count++;
2872165Sz.hong@f5.com 
2882165Sz.hong@f5.com     nxt_thread_spin_unlock(lock);
2892165Sz.hong@f5.com }
2902165Sz.hong@f5.com 
2912165Sz.hong@f5.com 
2922165Sz.hong@f5.com void
2932165Sz.hong@f5.com nxt_router_access_log_release(nxt_task_t *task, nxt_thread_spinlock_t *lock,
2942165Sz.hong@f5.com     nxt_router_access_log_t *access_log)
2952165Sz.hong@f5.com {
2962165Sz.hong@f5.com     if (access_log == NULL) {
2972165Sz.hong@f5.com         return;
2982165Sz.hong@f5.com     }
2992165Sz.hong@f5.com 
3002165Sz.hong@f5.com     nxt_thread_spin_lock(lock);
3012165Sz.hong@f5.com 
3022165Sz.hong@f5.com     if (--access_log->count != 0) {
3032165Sz.hong@f5.com         access_log = NULL;
3042165Sz.hong@f5.com     }
3052165Sz.hong@f5.com 
3062165Sz.hong@f5.com     nxt_thread_spin_unlock(lock);
3072165Sz.hong@f5.com 
3082165Sz.hong@f5.com     if (access_log != NULL) {
3092165Sz.hong@f5.com 
3102165Sz.hong@f5.com         if (access_log->fd != -1) {
3112165Sz.hong@f5.com             nxt_fd_close(access_log->fd);
3122165Sz.hong@f5.com         }
3132165Sz.hong@f5.com 
3142165Sz.hong@f5.com         nxt_free(access_log);
3152165Sz.hong@f5.com     }
3162165Sz.hong@f5.com }
3172165Sz.hong@f5.com 
3182165Sz.hong@f5.com 
3192165Sz.hong@f5.com typedef struct {
3202165Sz.hong@f5.com     nxt_mp_t                 *mem_pool;
3212165Sz.hong@f5.com     nxt_router_access_log_t  *access_log;
3222165Sz.hong@f5.com } nxt_router_access_log_reopen_t;
3232165Sz.hong@f5.com 
3242165Sz.hong@f5.com 
3252165Sz.hong@f5.com void
3262165Sz.hong@f5.com nxt_router_access_log_reopen_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
3272165Sz.hong@f5.com {
3282165Sz.hong@f5.com     nxt_mp_t                        *mp;
3292165Sz.hong@f5.com     uint32_t                        stream;
3302165Sz.hong@f5.com     nxt_int_t                       ret;
3312165Sz.hong@f5.com     nxt_buf_t                       *b;
3322165Sz.hong@f5.com     nxt_port_t                      *main_port, *router_port;
3332165Sz.hong@f5.com     nxt_runtime_t                   *rt;
3342165Sz.hong@f5.com     nxt_router_access_log_t         *access_log;
3352165Sz.hong@f5.com     nxt_router_access_log_reopen_t  *reopen;
3362165Sz.hong@f5.com 
3372165Sz.hong@f5.com     access_log = nxt_router->access_log;
3382165Sz.hong@f5.com 
3392165Sz.hong@f5.com     if (access_log == NULL) {
3402165Sz.hong@f5.com         return;
3412165Sz.hong@f5.com     }
3422165Sz.hong@f5.com 
3432165Sz.hong@f5.com     mp = nxt_mp_create(1024, 128, 256, 32);
3442165Sz.hong@f5.com     if (nxt_slow_path(mp == NULL)) {
3452165Sz.hong@f5.com         return;
3462165Sz.hong@f5.com     }
3472165Sz.hong@f5.com 
3482165Sz.hong@f5.com     reopen = nxt_mp_get(mp, sizeof(nxt_router_access_log_reopen_t));
3492165Sz.hong@f5.com     if (nxt_slow_path(reopen == NULL)) {
3502165Sz.hong@f5.com         goto fail;
3512165Sz.hong@f5.com     }
3522165Sz.hong@f5.com 
3532165Sz.hong@f5.com     reopen->mem_pool = mp;
3542165Sz.hong@f5.com     reopen->access_log = access_log;
3552165Sz.hong@f5.com 
3562165Sz.hong@f5.com     b = nxt_buf_mem_alloc(mp, access_log->path.length + 1, 0);
3572165Sz.hong@f5.com     if (nxt_slow_path(b == NULL)) {
3582165Sz.hong@f5.com         goto fail;
3592165Sz.hong@f5.com     }
3602165Sz.hong@f5.com 
3612165Sz.hong@f5.com     b->completion_handler = nxt_router_access_log_reopen_completion;
3622165Sz.hong@f5.com 
3632165Sz.hong@f5.com     nxt_buf_cpystr(b, &access_log->path);
3642165Sz.hong@f5.com     *b->mem.free++ = '\0';
3652165Sz.hong@f5.com 
3662165Sz.hong@f5.com     rt = task->thread->runtime;
3672165Sz.hong@f5.com     main_port = rt->port_by_type[NXT_PROCESS_MAIN];
3682165Sz.hong@f5.com     router_port = rt->port_by_type[NXT_PROCESS_ROUTER];
3692165Sz.hong@f5.com 
3702165Sz.hong@f5.com     stream = nxt_port_rpc_register_handler(task, router_port,
3712165Sz.hong@f5.com                                            nxt_router_access_log_reopen_ready,
3722165Sz.hong@f5.com                                            nxt_router_access_log_reopen_error,
3732165Sz.hong@f5.com                                            -1, reopen);
3742165Sz.hong@f5.com     if (nxt_slow_path(stream == 0)) {
3752165Sz.hong@f5.com         goto fail;
3762165Sz.hong@f5.com     }
3772165Sz.hong@f5.com 
3782165Sz.hong@f5.com     ret = nxt_port_socket_write(task, main_port, NXT_PORT_MSG_ACCESS_LOG, -1,
3792165Sz.hong@f5.com                                 stream, router_port->id, b);
3802165Sz.hong@f5.com 
3812165Sz.hong@f5.com     if (nxt_slow_path(ret != NXT_OK)) {
3822165Sz.hong@f5.com         nxt_port_rpc_cancel(task, router_port, stream);
3832165Sz.hong@f5.com         goto fail;
3842165Sz.hong@f5.com     }
3852165Sz.hong@f5.com 
3862165Sz.hong@f5.com     nxt_mp_retain(mp);
3872165Sz.hong@f5.com 
3882165Sz.hong@f5.com     return;
3892165Sz.hong@f5.com 
3902165Sz.hong@f5.com fail:
3912165Sz.hong@f5.com 
3922165Sz.hong@f5.com     nxt_mp_destroy(mp);
3932165Sz.hong@f5.com }
3942165Sz.hong@f5.com 
3952165Sz.hong@f5.com 
3962165Sz.hong@f5.com static void
3972165Sz.hong@f5.com nxt_router_access_log_reopen_completion(nxt_task_t *task, void *obj, void *data)
3982165Sz.hong@f5.com {
3992165Sz.hong@f5.com     nxt_mp_t   *mp;
4002165Sz.hong@f5.com     nxt_buf_t  *b;
4012165Sz.hong@f5.com 
4022165Sz.hong@f5.com     b = obj;
4032165Sz.hong@f5.com     mp = b->data;
4042165Sz.hong@f5.com 
4052165Sz.hong@f5.com     nxt_mp_release(mp);
4062165Sz.hong@f5.com }
4072165Sz.hong@f5.com 
4082165Sz.hong@f5.com 
4092165Sz.hong@f5.com static void
4102165Sz.hong@f5.com nxt_router_access_log_reopen_ready(nxt_task_t *task, nxt_port_recv_msg_t *msg,
4112165Sz.hong@f5.com     void *data)
4122165Sz.hong@f5.com {
4132165Sz.hong@f5.com     nxt_router_access_log_t         *access_log;
4142165Sz.hong@f5.com     nxt_router_access_log_reopen_t  *reopen;
4152165Sz.hong@f5.com 
4162165Sz.hong@f5.com     reopen = data;
4172165Sz.hong@f5.com 
4182165Sz.hong@f5.com     access_log = reopen->access_log;
4192165Sz.hong@f5.com 
4202165Sz.hong@f5.com     if (access_log == nxt_router->access_log) {
4212165Sz.hong@f5.com 
4222165Sz.hong@f5.com         if (nxt_slow_path(dup2(msg->fd[0], access_log->fd) == -1)) {
4232165Sz.hong@f5.com             nxt_alert(task, "dup2(%FD, %FD) failed %E",
4242165Sz.hong@f5.com                       msg->fd[0], access_log->fd, nxt_errno);
4252165Sz.hong@f5.com         }
4262165Sz.hong@f5.com     }
4272165Sz.hong@f5.com 
4282165Sz.hong@f5.com     nxt_fd_close(msg->fd[0]);
4292165Sz.hong@f5.com     nxt_mp_release(reopen->mem_pool);
4302165Sz.hong@f5.com }
4312165Sz.hong@f5.com 
4322165Sz.hong@f5.com 
4332165Sz.hong@f5.com static void
4342165Sz.hong@f5.com nxt_router_access_log_reopen_error(nxt_task_t *task, nxt_port_recv_msg_t *msg,
4352165Sz.hong@f5.com     void *data)
4362165Sz.hong@f5.com {
4372165Sz.hong@f5.com     nxt_router_access_log_reopen_t  *reopen;
4382165Sz.hong@f5.com 
4392165Sz.hong@f5.com     reopen = data;
4402165Sz.hong@f5.com 
4412165Sz.hong@f5.com     nxt_mp_release(reopen->mem_pool);
4422165Sz.hong@f5.com }
443