summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2010-11-29 15:29:38 +0000
committerJonathan Kolb <jon@b0g.us>2010-11-29 15:29:38 +0000
commit3f13cc6b2c2c6f71bcaa8b1e3a2e2190db6d852f (patch)
tree2ee4bc413b131dd56b1849f26bcc489da97750c3 /src
parentdf5fa5fcb16c6fd65657add97be5f056b58afa36 (diff)
downloadnginx-0.9.0.tar.gz
Changes with nginx 0.9.0 29 Nov 2010v0.9.0
*) Feature: the "keepalive_disable" directive. *) Feature: the "map" directive supports variables as value of a defined variable. *) Feature: the "map" directive supports empty strings as value of the first parameter. *) Feature: the "map" directive supports expressions as the first parameter. *) Feature: nginx(8) manual page. Thanks to Sergey Osokin. *) Feature: Linux accept4() support. Thanks to Simon Liu. *) Workaround: elimination of Linux linker warning about "sys_errlist" and "sys_nerr"; the warning had appeared in 0.8.35. *) Bugfix: a segmentation fault might occur in a worker process, if the "auth_basic" directive was used. Thanks to Michail Laletin. *) Bugfix: compatibility with ngx_http_eval_module; the bug had appeared in 0.8.42.
Diffstat (limited to 'src')
-rw-r--r--src/core/nginx.c4
-rw-r--r--src/core/nginx.h4
-rw-r--r--src/core/ngx_log.c11
-rw-r--r--src/event/ngx_event_accept.c4
-rw-r--r--src/http/modules/ngx_http_degradation_module.c7
-rw-r--r--src/http/modules/ngx_http_map_module.c134
-rw-r--r--src/http/modules/perl/nginx.pm2
-rw-r--r--src/http/ngx_http_core_module.c72
-rw-r--r--src/http/ngx_http_core_module.h6
-rw-r--r--src/http/ngx_http_upstream.h2
-rw-r--r--src/os/unix/ngx_errno.c91
-rw-r--r--src/os/unix/ngx_errno.h26
-rw-r--r--src/os/unix/ngx_posix_init.c2
-rw-r--r--src/os/unix/ngx_process.c10
-rw-r--r--src/os/unix/ngx_user.c8
15 files changed, 232 insertions, 151 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 0f19371e6..b8bab37e3 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -203,6 +203,10 @@ main(int argc, char *const *argv)
ngx_cycle_t *cycle, init_cycle;
ngx_core_conf_t *ccf;
+ if (ngx_strerror_init() != NGX_OK) {
+ return 1;
+ }
+
if (ngx_get_options(argc, argv) != NGX_OK) {
return 1;
}
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 208a5f634..3a67533e2 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,8 +8,8 @@
#define _NGINX_H_INCLUDED_
-#define nginx_version 8053
-#define NGINX_VERSION "0.8.53"
+#define nginx_version 9000
+#define NGINX_VERSION "0.9.0"
#define NGINX_VER "nginx/" NGINX_VERSION
#define NGINX_VAR "NGINX"
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index c0485c61b..ec0430355 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -148,9 +148,9 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
return;
}
- msg -= (err_levels[level].len + 4);
+ msg -= (7 + err_levels[level].len + 4);
- (void) ngx_sprintf(msg, "[%V]: ", &err_levels[level]);
+ (void) ngx_sprintf(msg, "nginx: [%V]: ", &err_levels[level]);
(void) ngx_write_console(ngx_stderr, msg, p - msg);
}
@@ -209,9 +209,12 @@ ngx_log_stderr(ngx_err_t err, const char *fmt, ...)
u_char errstr[NGX_MAX_ERROR_STR];
last = errstr + NGX_MAX_ERROR_STR;
+ p = errstr + 7;
+
+ ngx_memcpy(errstr, "nginx: ", 7);
va_start(args, fmt);
- p = ngx_vslprintf(errstr, last, fmt, args);
+ p = ngx_vslprintf(p, last, fmt, args);
va_end(args);
if (err) {
@@ -248,7 +251,7 @@ ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err)
buf = ngx_slprintf(buf, last, " (%d: ", err);
#endif
- buf = ngx_strerror_r(err, buf, last - buf);
+ buf = ngx_strerror(err, buf, last - buf);
if (buf < last) {
*buf++ = ')';
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c
index ed5762e18..67751faf7 100644
--- a/src/event/ngx_event_accept.c
+++ b/src/event/ngx_event_accept.c
@@ -46,7 +46,11 @@ ngx_event_accept(ngx_event_t *ev)
do {
socklen = NGX_SOCKADDRLEN;
+#if (NGX_HAVE_ACCEPT4)
+ s = accept4(lc->fd, (struct sockaddr *) sa, &socklen, SOCK_NONBLOCK);
+#else
s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
+#endif
if (s == -1) {
err = ngx_socket_errno;
diff --git a/src/http/modules/ngx_http_degradation_module.c b/src/http/modules/ngx_http_degradation_module.c
index a35733f81..a5f83bb20 100644
--- a/src/http/modules/ngx_http_degradation_module.c
+++ b/src/http/modules/ngx_http_degradation_module.c
@@ -86,9 +86,6 @@ ngx_module_t ngx_http_degradation_module = {
};
-static ngx_uint_t ngx_degraded;
-
-
static ngx_int_t
ngx_http_degradation_handler(ngx_http_request_t *r)
{
@@ -139,8 +136,6 @@ ngx_http_degraded(ngx_http_request_t *r)
/* unlock mutex */
if (sbrk_size >= dmcf->sbrk_size) {
- ngx_degraded = 1;
-
if (log) {
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
"degradation sbrk:%uzM",
@@ -151,8 +146,6 @@ ngx_http_degraded(ngx_http_request_t *r)
}
}
- ngx_degraded = 0;
-
return 0;
}
diff --git a/src/http/modules/ngx_http_map_module.c b/src/http/modules/ngx_http_map_module.c
index fe3fa7751..5f263a55d 100644
--- a/src/http/modules/ngx_http_map_module.c
+++ b/src/http/modules/ngx_http_map_module.c
@@ -19,15 +19,17 @@ typedef struct {
ngx_hash_keys_arrays_t keys;
ngx_array_t *values_hash;
+ ngx_array_t var_values;
ngx_http_variable_value_t *default_value;
+ ngx_conf_t *cf;
ngx_uint_t hostnames; /* unsigned hostnames:1 */
} ngx_http_map_conf_ctx_t;
typedef struct {
ngx_hash_combined_t hash;
- ngx_int_t index;
+ ngx_http_complex_value_t value;
ngx_http_variable_value_t *default_value;
ngx_uint_t hostnames; /* unsigned hostnames:1 */
} ngx_http_map_ctx_t;
@@ -105,49 +107,43 @@ ngx_http_map_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
ngx_http_map_ctx_t *map = (ngx_http_map_ctx_t *) data;
size_t len;
- u_char *name;
+ ngx_str_t val;
ngx_uint_t key;
- ngx_http_variable_value_t *vv, *value;
+ ngx_http_variable_value_t *value;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http map started");
- vv = ngx_http_get_flushed_variable(r, map->index);
-
- if (vv == NULL || vv->not_found) {
- *v = *map->default_value;
- return NGX_OK;
+ if (ngx_http_complex_value(r, &map->value, &val) != NGX_OK) {
+ return NGX_ERROR;
}
- len = vv->len;
+ len = val.len;
- if (len && map->hostnames && vv->data[len - 1] == '.') {
+ if (len && map->hostnames && val.data[len - 1] == '.') {
len--;
}
- if (len == 0) {
- *v = *map->default_value;
- return NGX_OK;
- }
-
- name = ngx_pnalloc(r->pool, len);
- if (name == NULL) {
- return NGX_ERROR;
- }
+ key = ngx_hash_strlow(val.data, val.data, len);
- key = ngx_hash_strlow(name, vv->data, len);
+ value = ngx_hash_find_combined(&map->hash, key, val.data, len);
- value = ngx_hash_find_combined(&map->hash, key, name, len);
+ if (value == NULL) {
+ value = map->default_value;
+ }
- if (value) {
- *v = *value;
+ if (!value->valid) {
+ value = ngx_http_get_flushed_variable(r, (ngx_uint_t) value->data);
- } else {
- *v = *map->default_value;
+ if (value == NULL || value->not_found) {
+ value = &ngx_http_variable_null_value;
+ }
}
+ *v = *value;
+
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http map: \"%v\" \"%v\"", vv, v);
+ "http map: \"%v\" \"%v\"", &val, v);
return NGX_OK;
}
@@ -175,14 +171,15 @@ ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_map_conf_t *mcf = conf;
- char *rv;
- ngx_str_t *value, name;
- ngx_conf_t save;
- ngx_pool_t *pool;
- ngx_hash_init_t hash;
- ngx_http_map_ctx_t *map;
- ngx_http_variable_t *var;
- ngx_http_map_conf_ctx_t ctx;
+ char *rv;
+ ngx_str_t *value, name;
+ ngx_conf_t save;
+ ngx_pool_t *pool;
+ ngx_hash_init_t hash;
+ ngx_http_map_ctx_t *map;
+ ngx_http_variable_t *var;
+ ngx_http_map_conf_ctx_t ctx;
+ ngx_http_compile_complex_value_t ccv;
if (mcf->hash_max_size == NGX_CONF_UNSET_UINT) {
mcf->hash_max_size = 2048;
@@ -203,13 +200,13 @@ ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
value = cf->args->elts;
- name = value[1];
- name.len--;
- name.data++;
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
- map->index = ngx_http_get_variable_index(cf, &name);
+ ccv.cf = cf;
+ ccv.value = &value[1];
+ ccv.complex_value = &map->value;
- if (map->index == NGX_ERROR) {
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
return NGX_CONF_ERROR;
}
@@ -244,7 +241,16 @@ ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
+ if (ngx_array_init(&ctx.var_values, cf->pool, 2,
+ sizeof(ngx_http_variable_value_t))
+ != NGX_OK)
+ {
+ ngx_destroy_pool(pool);
+ return NGX_CONF_ERROR;
+ }
+
ctx.default_value = NULL;
+ ctx.cf = &save;
ctx.hostnames = 0;
save = *cf;
@@ -344,8 +350,8 @@ ngx_http_map_cmp_dns_wildcards(const void *one, const void *two)
static char *
ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
{
- ngx_int_t rc;
- ngx_str_t *value, file;
+ ngx_int_t rc, index;
+ ngx_str_t *value, file, name;
ngx_uint_t i, key;
ngx_http_map_conf_ctx_t *ctx;
ngx_http_variable_value_t *var, **vp;
@@ -364,11 +370,6 @@ ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid number of the map parameters");
return NGX_CONF_ERROR;
-
- } else if (value[0].len == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid first parameter");
- return NGX_CONF_ERROR;
}
if (ngx_strcmp(value[0].data, "include") == 0) {
@@ -383,6 +384,45 @@ ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
return ngx_conf_parse(cf, &file);
}
+ if (value[1].data[0] == '$') {
+ name = value[1];
+ name.len--;
+ name.data++;
+
+ index = ngx_http_get_variable_index(ctx->cf, &name);
+ if (index == NGX_ERROR) {
+ return NGX_CONF_ERROR;
+ }
+
+ var = ctx->var_values.elts;
+
+ for (i = 0; i < ctx->var_values.nelts; i++) {
+ if (index == (ngx_int_t) var[i].data) {
+ goto found;
+ }
+ }
+
+ var = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_variable_value_t));
+ if (var == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var->valid = 0;
+ var->no_cacheable = 0;
+ var->not_found = 0;
+ var->len = 0;
+ var->data = (u_char *) index;
+
+ vp = ngx_array_push(&ctx->var_values);
+ if (vp == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ *vp = var;
+
+ goto found;
+ }
+
key = 0;
for (i = 0; i < value[1].len; i++) {
@@ -451,7 +491,7 @@ found:
return NGX_CONF_OK;
}
- if (value[0].len && value[0].data[0] == '!') {
+ if (value[0].len && value[0].data[0] == '\\') {
value[0].len--;
value[0].data++;
}
diff --git a/src/http/modules/perl/nginx.pm b/src/http/modules/perl/nginx.pm
index faff340e2..a2a0f7470 100644
--- a/src/http/modules/perl/nginx.pm
+++ b/src/http/modules/perl/nginx.pm
@@ -48,7 +48,7 @@ our @EXPORT = qw(
HTTP_INSUFFICIENT_STORAGE
);
-our $VERSION = '0.8.53';
+our $VERSION = '0.9.0';
require XSLoader;
XSLoader::load('nginx', $VERSION);
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 0345be965..0e8d5a497 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -133,6 +133,14 @@ static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
};
+static ngx_conf_enum_t ngx_http_core_keepalive_disable[] = {
+ { ngx_string("none"), NGX_HTTP_KEEPALIVE_DISABLE_NONE },
+ { ngx_string("msie6"), NGX_HTTP_KEEPALIVE_DISABLE_MSIE6 },
+ { ngx_string("safari"), NGX_HTTP_KEEPALIVE_DISABLE_SAFARI },
+ { ngx_null_string, 0 }
+};
+
+
static ngx_path_init_t ngx_http_client_temp_path = {
ngx_string(NGX_HTTP_CLIENT_TEMP_PATH), { 0, 0, 0 }
};
@@ -494,6 +502,13 @@ static ngx_command_t ngx_http_core_commands[] = {
offsetof(ngx_http_core_loc_conf_t, keepalive_requests),
NULL },
+ { ngx_string("keepalive_disable"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_enum_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_core_loc_conf_t, keepalive_disable),
+ &ngx_http_core_keepalive_disable },
+
{ ngx_string("satisfy"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_enum_slot,
@@ -790,26 +805,6 @@ ngx_http_handler(ngx_http_request_t *r)
break;
}
- if (r->keepalive) {
-
- if (r->headers_in.msie6) {
- if (r->method == NGX_HTTP_POST) {
- /*
- * MSIE may wait for some time if an response for
- * a POST request was sent over a keepalive connection
- */
- r->keepalive = 0;
- }
-
- } else if (r->headers_in.safari) {
- /*
- * Safari may send a POST request to a closed keepalive
- * connection and stalls for some time
- */
- r->keepalive = 0;
- }
- }
-
if (r->headers_in.content_length_n > 0) {
r->lingering_close = 1;
@@ -905,12 +900,21 @@ ngx_http_core_rewrite_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
rc = ph->handler(r);
+ if (rc == NGX_OK) {
+ r->phase_handler = ph->next;
+ return NGX_AGAIN;
+ }
+
if (rc == NGX_DECLINED) {
r->phase_handler++;
return NGX_AGAIN;
}
- /* rc == NGX_OK || rc == NGX_ERROR || rc == NGX_HTTP_... */
+ if (rc == NGX_DONE) {
+ return NGX_OK;
+ }
+
+ /* NGX_AGAIN || rc == NGX_ERROR || rc == NGX_HTTP_... */
ngx_http_finalize_request(r, rc);
@@ -1432,6 +1436,28 @@ ngx_http_update_location_config(ngx_http_request_t *r)
} else if (r->connection->requests >= clcf->keepalive_requests) {
r->keepalive = 0;
+
+ } else if (r->headers_in.msie6
+ && r->method == NGX_HTTP_POST
+ && (clcf->keepalive_disable
+ & NGX_HTTP_KEEPALIVE_DISABLE_MSIE6))
+ {
+ /*
+ * MSIE may wait for some time if an response for
+ * a POST request was sent over a keepalive connection
+ */
+ r->keepalive = 0;
+
+ } else if (r->headers_in.safari
+ && (clcf->keepalive_disable
+ & NGX_HTTP_KEEPALIVE_DISABLE_SAFARI))
+ {
+ /*
+ * Safari may send a POST request to a closed keepalive
+ * connection and may stall for some time, see
+ * https://bugs.webkit.org/show_bug.cgi?id=5760
+ */
+ r->keepalive = 0;
}
}
@@ -3061,6 +3087,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
clcf->client_max_body_size = NGX_CONF_UNSET;
clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
clcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
+ clcf->keepalive_disable = NGX_CONF_UNSET_UINT;
clcf->satisfy = NGX_CONF_UNSET_UINT;
clcf->if_modified_since = NGX_CONF_UNSET_UINT;
clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT;
@@ -3261,6 +3288,9 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_msec_value(conf->client_body_timeout,
prev->client_body_timeout, 60000);
+ ngx_conf_merge_uint_value(conf->keepalive_disable, prev->keepalive_disable,
+ NGX_HTTP_KEEPALIVE_DISABLE_MSIE6
+ |NGX_HTTP_KEEPALIVE_DISABLE_SAFARI);
ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
NGX_HTTP_SATISFY_ALL);
ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 273586b1c..729ef9721 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -38,6 +38,11 @@
#define NGX_HTTP_IMS_BEFORE 2
+#define NGX_HTTP_KEEPALIVE_DISABLE_NONE 0x0002
+#define NGX_HTTP_KEEPALIVE_DISABLE_MSIE6 0x0004
+#define NGX_HTTP_KEEPALIVE_DISABLE_SAFARI 0x0008
+
+
typedef struct ngx_http_location_tree_node_s ngx_http_location_tree_node_t;
typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t;
@@ -349,6 +354,7 @@ struct ngx_http_core_loc_conf_s {
time_t keepalive_header; /* keepalive_timeout */
ngx_uint_t keepalive_requests; /* keepalive_requests */
+ ngx_uint_t keepalive_disable; /* keepalive_disable */
ngx_uint_t satisfy; /* satisfy */
ngx_uint_t if_modified_since; /* if_modified_since */
ngx_uint_t client_body_in_file_only; /* client_body_in_file_only */
diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
index ef460a488..01e2e1e51 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -53,7 +53,7 @@ typedef struct {
ngx_uint_t status;
time_t response_sec;
ngx_uint_t response_msec;
- off_t response_length;
+ off_t response_length;
ngx_str_t *peer;
} ngx_http_upstream_state_t;
diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c
index a250f496d..02994b808 100644
--- a/src/os/unix/ngx_errno.c
+++ b/src/os/unix/ngx_errno.c
@@ -8,54 +8,79 @@
#include <ngx_core.h>
-#if (NGX_HAVE_STRERROR_R)
+/*
+ * The strerror() messages are copied because:
+ *
+ * 1) strerror() and strerror_r() functions are not Async-Signal-Safe,
+ * therefore, they can not be used in signal handlers;
+ *
+ * 2) a direct sys_errlist[] array may be used instead of these functions,
+ * but Linux linker warns about its usage:
+ *
+ * warning: `sys_errlist' is deprecated; use `strerror' or `strerror_r' instead
+ * warning: `sys_nerr' is deprecated; use `strerror' or `strerror_r' instead
+ *
+ * causing false bug reports.
+ */
-u_char *
-ngx_strerror_r(int err, u_char *errstr, size_t size)
-{
- if (size == 0) {
- return errstr;
- }
- errstr[0] = '\0';
+static ngx_str_t *ngx_sys_errlist;
+static ngx_str_t ngx_unknown_error = ngx_string("Unknown error");
- strerror_r(err, (char *) errstr, size);
- while (*errstr && size) {
- errstr++;
- size--;
- }
+u_char *
+ngx_strerror(ngx_err_t err, u_char *errstr, size_t size)
+{
+ ngx_str_t *msg;
- return errstr;
-}
+ msg = ((ngx_uint_t) err < NGX_SYS_NERR) ? &ngx_sys_errlist[err]:
+ &ngx_unknown_error;
+ size = ngx_min(size, msg->len);
-#elif (NGX_HAVE_GNU_STRERROR_R)
+ return ngx_cpymem(errstr, msg->data, size);
+}
-/* Linux strerror_r() */
-u_char *
-ngx_strerror_r(int err, u_char *errstr, size_t size)
+ngx_uint_t
+ngx_strerror_init(void)
{
- char *str;
+ char *msg;
+ u_char *p;
+ size_t len;
+ ngx_err_t err;
+
+ /*
+ * ngx_strerror() is not ready to work at this stage, therefore,
+ * malloc() is used and possible errors are logged using strerror().
+ */
+
+ len = NGX_SYS_NERR * sizeof(ngx_str_t);
- if (size == 0) {
- return errstr;
+ ngx_sys_errlist = malloc(len);
+ if (ngx_sys_errlist == NULL) {
+ goto failed;
}
- errstr[0] = '\0';
+ for (err = 0; err < NGX_SYS_NERR; err++) {
+ msg = strerror(err);
+ len = ngx_strlen(msg);
- str = strerror_r(err, (char *) errstr, size);
+ p = malloc(len);
+ if (p == NULL) {
+ goto failed;
+ }
- if (str != (char *) errstr) {
- return ngx_cpystrn(errstr, (u_char *) str, size);
+ ngx_memcpy(p, msg, len);
+ ngx_sys_errlist[err].len = len;
+ ngx_sys_errlist[err].data = p;
}
- while (*errstr && size) {
- errstr++;
- size--;
- }
+ return NGX_OK;
- return errstr;
-}
+failed:
-#endif
+ err = errno;
+ ngx_log_stderr(0, "malloc(%uz) failed (%d: %s)", len, err, strerror(err));
+
+ return NGX_ERROR;
+}
diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h
index e1891e74b..3d51f3cfc 100644
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -60,30 +60,8 @@ typedef int ngx_err_t;
#define ngx_set_socket_errno(err) errno = err
-#if (NGX_HAVE_STRERROR_R || NGX_HAVE_GNU_STRERROR_R)
-
-u_char *ngx_strerror_r(int err, u_char *errstr, size_t size);
-
-#else
-
-/* Solaris and Tru64 UNIX have thread-safe strerror() */
-
-#define ngx_strerror_r(err, errstr, size) \
- ngx_cpystrn(errstr, (u_char *) strerror(err), size)
-
-#endif
-
-
-#if (NGX_HAVE_SYS_ERRLIST)
-
-#define ngx_sigsafe_strerror(err) \
- (err > 0 && err < sys_nerr) ? sys_errlist[err] : "Unknown error"
-
-#else
-
-#define ngx_sigsafe_strerror(err) ""
-
-#endif
+u_char *ngx_strerror(ngx_err_t err, u_char *errstr, size_t size);
+ngx_uint_t ngx_strerror_init(void);
#endif /* _NGX_ERRNO_H_INCLUDED_ */
diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c
index f21614499..2357ab31f 100644
--- a/src/os/unix/ngx_posix_init.c
+++ b/src/os/unix/ngx_posix_init.c
@@ -60,7 +60,7 @@ ngx_os_init(ngx_log_t *log)
ngx_max_sockets = (ngx_int_t) rlmt.rlim_cur;
-#if (NGX_HAVE_INHERITED_NONBLOCK)
+#if (NGX_HAVE_INHERITED_NONBLOCK || NGX_HAVE_ACCEPT4)
ngx_inherited_nonblocking = 1;
#else
ngx_inherited_nonblocking = 0;
diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c
index 4574dfaf3..605558786 100644
--- a/src/os/unix/ngx_process.c
+++ b/src/os/unix/ngx_process.c
@@ -479,17 +479,15 @@ ngx_process_get_status(void)
*/
if (err == NGX_ECHILD) {
- ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0,
- "waitpid() failed (%d: %s)",
- err, ngx_sigsafe_strerror(err));
+ ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, err,
+ "waitpid() failed");
return;
}
#endif
- ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
- "waitpid() failed (%d: %s)",
- err, ngx_sigsafe_strerror(err));
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err,
+ "waitpid() failed");
return;
}
diff --git a/src/os/unix/ngx_user.c b/src/os/unix/ngx_user.c
index 4bad1c307..165c6a46b 100644
--- a/src/os/unix/ngx_user.c
+++ b/src/os/unix/ngx_user.c
@@ -41,11 +41,11 @@ ngx_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
err = ngx_errno;
if (err == 0) {
- len = ngx_strlen(value);
+ len = ngx_strlen(value) + 1;
*encrypted = ngx_pnalloc(pool, len);
if (*encrypted) {
- ngx_memcpy(*encrypted, value, len + 1);
+ ngx_memcpy(*encrypted, value, len);
return NGX_OK;
}
}
@@ -79,11 +79,11 @@ ngx_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
value = crypt((char *) key, (char *) salt);
if (value) {
- len = ngx_strlen(value);
+ len = ngx_strlen(value) + 1;
*encrypted = ngx_pnalloc(pool, len);
if (*encrypted) {
- ngx_memcpy(*encrypted, value, len + 1);
+ ngx_memcpy(*encrypted, value, len);
}
#if (NGX_THREADS && NGX_NONREENTRANT_CRYPT)