Latest update - 7223

This commit is contained in:
Hakase
2018-03-03 21:06:27 +09:00
parent 83318d2cea
commit ca23833d5c
5 changed files with 178 additions and 22 deletions
+24
View File
@@ -791,6 +791,30 @@ ngx_feature_test="struct tm t; time_t c=0; localtime_r(&c, &t)"
. auto/feature
ngx_feature="clock_gettime(CLOCK_MONOTONIC)"
ngx_feature_name="NGX_HAVE_CLOCK_MONOTONIC"
ngx_feature_run=no
ngx_feature_incs="#include <time.h>"
ngx_feature_path=
ngx_feature_libs=
ngx_feature_test="struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts)"
. auto/feature
if [ $ngx_found = no ]; then
# Linux before glibc 2.17, notably CentOS 6
ngx_feature="clock_gettime(CLOCK_MONOTONIC) in librt"
ngx_feature_libs="-lrt"
. auto/feature
if [ $ngx_found = yes ]; then
CORE_LIBS="$CORE_LIBS -lrt"
fi
fi
ngx_feature="posix_memalign()"
ngx_feature_name="NGX_HAVE_POSIX_MEMALIGN"
ngx_feature_run=no
+29 -1
View File
@@ -9,6 +9,9 @@
#include <ngx_core.h>
static ngx_msec_t ngx_monotonic_time(time_t sec, ngx_uint_t msec);
/*
* The time may be updated by signal handler or by several threads.
* The time update operations are rare and require to hold the ngx_time_lock.
@@ -93,7 +96,7 @@ ngx_time_update(void)
sec = tv.tv_sec;
msec = tv.tv_usec / 1000;
ngx_current_msec = (ngx_msec_t) sec * 1000 + msec;
ngx_current_msec = ngx_monotonic_time(sec, msec);
tp = &cached_time[slot];
@@ -189,6 +192,31 @@ ngx_time_update(void)
}
static ngx_msec_t
ngx_monotonic_time(time_t sec, ngx_uint_t msec)
{
#if (NGX_HAVE_CLOCK_MONOTONIC)
struct timespec ts;
#if defined(CLOCK_MONOTONIC_FAST)
clock_gettime(CLOCK_MONOTONIC_FAST, &ts);
#elif defined(CLOCK_MONOTONIC_COARSE)
clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
#else
clock_gettime(CLOCK_MONOTONIC, &ts);
#endif
sec = ts.tv_sec;
msec = ts.tv_nsec / 1000000;
#endif
return (ngx_msec_t) sec * 1000 + msec;
}
#if !(NGX_WIN32)
void
+60 -8
View File
@@ -90,6 +90,11 @@ typedef struct {
} ngx_http_log_var_t;
#define NGX_HTTP_LOG_ESCAPE_DEFAULT 0
#define NGX_HTTP_LOG_ESCAPE_JSON 1
#define NGX_HTTP_LOG_ESCAPE_NONE 2
static void ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log,
u_char *buf, size_t len);
static ssize_t ngx_http_log_script_write(ngx_http_request_t *r,
@@ -126,7 +131,7 @@ static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op);
static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf,
ngx_http_log_op_t *op, ngx_str_t *value, ngx_uint_t json);
ngx_http_log_op_t *op, ngx_str_t *value, ngx_uint_t escape);
static size_t ngx_http_log_variable_getlen(ngx_http_request_t *r,
uintptr_t data);
static u_char *ngx_http_log_variable(ngx_http_request_t *r, u_char *buf,
@@ -136,6 +141,10 @@ static size_t ngx_http_log_json_variable_getlen(ngx_http_request_t *r,
uintptr_t data);
static u_char *ngx_http_log_json_variable(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op);
static size_t ngx_http_log_unescaped_variable_getlen(ngx_http_request_t *r,
uintptr_t data);
static u_char *ngx_http_log_unescaped_variable(ngx_http_request_t *r,
u_char *buf, ngx_http_log_op_t *op);
static void *ngx_http_log_create_main_conf(ngx_conf_t *cf);
@@ -905,7 +914,7 @@ ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf,
static ngx_int_t
ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
ngx_str_t *value, ngx_uint_t json)
ngx_str_t *value, ngx_uint_t escape)
{
ngx_int_t index;
@@ -916,11 +925,18 @@ ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
op->len = 0;
if (json) {
switch (escape) {
case NGX_HTTP_LOG_ESCAPE_JSON:
op->getlen = ngx_http_log_json_variable_getlen;
op->run = ngx_http_log_json_variable;
break;
} else {
case NGX_HTTP_LOG_ESCAPE_NONE:
op->getlen = ngx_http_log_unescaped_variable_getlen;
op->run = ngx_http_log_unescaped_variable;
break;
default: /* NGX_HTTP_LOG_ESCAPE_DEFAULT */
op->getlen = ngx_http_log_variable_getlen;
op->run = ngx_http_log_variable;
}
@@ -1073,6 +1089,39 @@ ngx_http_log_json_variable(ngx_http_request_t *r, u_char *buf,
}
static size_t
ngx_http_log_unescaped_variable_getlen(ngx_http_request_t *r, uintptr_t data)
{
ngx_http_variable_value_t *value;
value = ngx_http_get_indexed_variable(r, data);
if (value == NULL || value->not_found) {
return 0;
}
value->escape = 0;
return value->len;
}
static u_char *
ngx_http_log_unescaped_variable(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op)
{
ngx_http_variable_value_t *value;
value = ngx_http_get_indexed_variable(r, op->data);
if (value == NULL || value->not_found) {
return buf;
}
return ngx_cpymem(buf, value->data, value->len);
}
static void *
ngx_http_log_create_main_conf(ngx_conf_t *cf)
{
@@ -1536,18 +1585,21 @@ ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes,
size_t i, len;
ngx_str_t *value, var;
ngx_int_t *flush;
ngx_uint_t bracket, json;
ngx_uint_t bracket, escape;
ngx_http_log_op_t *op;
ngx_http_log_var_t *v;
json = 0;
escape = NGX_HTTP_LOG_ESCAPE_DEFAULT;
value = args->elts;
if (s < args->nelts && ngx_strncmp(value[s].data, "escape=", 7) == 0) {
data = value[s].data + 7;
if (ngx_strcmp(data, "json") == 0) {
json = 1;
escape = NGX_HTTP_LOG_ESCAPE_JSON;
} else if (ngx_strcmp(data, "none") == 0) {
escape = NGX_HTTP_LOG_ESCAPE_NONE;
} else if (ngx_strcmp(data, "default") != 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
@@ -1636,7 +1688,7 @@ ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes,
}
}
if (ngx_http_log_variable_compile(cf, op, &var, json)
if (ngx_http_log_variable_compile(cf, op, &var, escape)
!= NGX_OK)
{
return NGX_CONF_ERROR;
+5 -5
View File
@@ -191,11 +191,6 @@ ngx_http_postpone_filter_in_memory(ngx_http_request_t *r, ngx_chain_t *in)
"http postpone filter in memory");
if (r->out == NULL) {
r->out = ngx_alloc_chain_link(r->pool);
if (r->out == NULL) {
return NGX_ERROR;
}
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (r->headers_out.content_length_n != -1) {
@@ -218,6 +213,11 @@ ngx_http_postpone_filter_in_memory(ngx_http_request_t *r, ngx_chain_t *in)
b->last_buf = 1;
r->out = ngx_alloc_chain_link(r->pool);
if (r->out == NULL) {
return NGX_ERROR;
}
r->out->buf = b;
r->out->next = NULL;
}
+60 -8
View File
@@ -89,6 +89,11 @@ typedef struct {
} ngx_stream_log_var_t;
#define NGX_STREAM_LOG_ESCAPE_DEFAULT 0
#define NGX_STREAM_LOG_ESCAPE_JSON 1
#define NGX_STREAM_LOG_ESCAPE_NONE 2
static void ngx_stream_log_write(ngx_stream_session_t *s, ngx_stream_log_t *log,
u_char *buf, size_t len);
static ssize_t ngx_stream_log_script_write(ngx_stream_session_t *s,
@@ -106,7 +111,7 @@ static void ngx_stream_log_flush(ngx_open_file_t *file, ngx_log_t *log);
static void ngx_stream_log_flush_handler(ngx_event_t *ev);
static ngx_int_t ngx_stream_log_variable_compile(ngx_conf_t *cf,
ngx_stream_log_op_t *op, ngx_str_t *value, ngx_uint_t json);
ngx_stream_log_op_t *op, ngx_str_t *value, ngx_uint_t escape);
static size_t ngx_stream_log_variable_getlen(ngx_stream_session_t *s,
uintptr_t data);
static u_char *ngx_stream_log_variable(ngx_stream_session_t *s, u_char *buf,
@@ -116,6 +121,10 @@ static size_t ngx_stream_log_json_variable_getlen(ngx_stream_session_t *s,
uintptr_t data);
static u_char *ngx_stream_log_json_variable(ngx_stream_session_t *s,
u_char *buf, ngx_stream_log_op_t *op);
static size_t ngx_stream_log_unescaped_variable_getlen(ngx_stream_session_t *s,
uintptr_t data);
static u_char *ngx_stream_log_unescaped_variable(ngx_stream_session_t *s,
u_char *buf, ngx_stream_log_op_t *op);
static void *ngx_stream_log_create_main_conf(ngx_conf_t *cf);
@@ -682,7 +691,7 @@ ngx_stream_log_copy_long(ngx_stream_session_t *s, u_char *buf,
static ngx_int_t
ngx_stream_log_variable_compile(ngx_conf_t *cf, ngx_stream_log_op_t *op,
ngx_str_t *value, ngx_uint_t json)
ngx_str_t *value, ngx_uint_t escape)
{
ngx_int_t index;
@@ -693,11 +702,18 @@ ngx_stream_log_variable_compile(ngx_conf_t *cf, ngx_stream_log_op_t *op,
op->len = 0;
if (json) {
switch (escape) {
case NGX_STREAM_LOG_ESCAPE_JSON:
op->getlen = ngx_stream_log_json_variable_getlen;
op->run = ngx_stream_log_json_variable;
break;
} else {
case NGX_STREAM_LOG_ESCAPE_NONE:
op->getlen = ngx_stream_log_unescaped_variable_getlen;
op->run = ngx_stream_log_unescaped_variable;
break;
default: /* NGX_STREAM_LOG_ESCAPE_DEFAULT */
op->getlen = ngx_stream_log_variable_getlen;
op->run = ngx_stream_log_variable;
}
@@ -851,6 +867,39 @@ ngx_stream_log_json_variable(ngx_stream_session_t *s, u_char *buf,
}
static size_t
ngx_stream_log_unescaped_variable_getlen(ngx_stream_session_t *s, uintptr_t data)
{
ngx_stream_variable_value_t *value;
value = ngx_stream_get_indexed_variable(s, data);
if (value == NULL || value->not_found) {
return 0;
}
value->escape = 0;
return value->len;
}
static u_char *
ngx_stream_log_unescaped_variable(ngx_stream_session_t *s, u_char *buf,
ngx_stream_log_op_t *op)
{
ngx_stream_variable_value_t *value;
value = ngx_stream_get_indexed_variable(s, op->data);
if (value == NULL || value->not_found) {
return buf;
}
return ngx_cpymem(buf, value->data, value->len);
}
static void *
ngx_stream_log_create_main_conf(ngx_conf_t *cf)
{
@@ -1265,17 +1314,20 @@ ngx_stream_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes,
size_t i, len;
ngx_str_t *value, var;
ngx_int_t *flush;
ngx_uint_t bracket, json;
ngx_uint_t bracket, escape;
ngx_stream_log_op_t *op;
json = 0;
escape = NGX_STREAM_LOG_ESCAPE_DEFAULT;
value = args->elts;
if (s < args->nelts && ngx_strncmp(value[s].data, "escape=", 7) == 0) {
data = value[s].data + 7;
if (ngx_strcmp(data, "json") == 0) {
json = 1;
escape = NGX_STREAM_LOG_ESCAPE_JSON;
} else if (ngx_strcmp(data, "none") == 0) {
escape = NGX_STREAM_LOG_ESCAPE_NONE;
} else if (ngx_strcmp(data, "default") != 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
@@ -1350,7 +1402,7 @@ ngx_stream_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes,
goto invalid;
}
if (ngx_stream_log_variable_compile(cf, op, &var, json)
if (ngx_stream_log_variable_compile(cf, op, &var, escape)
!= NGX_OK)
{
return NGX_CONF_ERROR;