summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2007-12-19 16:44:53 +0000
committerJonathan Kolb <jon@b0g.us>2007-12-19 16:44:53 +0000
commit73cd30361418f277067c128cedee4990aa72840b (patch)
tree31543ed1e42e73f4ae58ba4618ce478528ed6b97 /src/core
parenta877b91668afa1325162965b701bb4268ee870cd (diff)
downloadnginx-73cd30361418f277067c128cedee4990aa72840b.tar.gz
Changes with nginx 0.6.22 19 Dec 2007v0.6.22
*) Change: now all ngx_http_perl_module methods return values copied to perl's allocated memory. *) Bugfix: if nginx was built with ngx_http_perl_module, the perl before 5.8.6 was used, and perl supported threads, then during reconfiguration the master process aborted; bug appeared in 0.5.9. Thanks to Boris Zhmurov. *) Bugfix: the ngx_http_perl_module methods may get invalid values of the regex captures. *) Bugfix: a segmentation fault occurred in worker process, if the $r->has_request_body() method was called for a request whose small request body was already received. *) Bugfix: large_client_header_buffers did not freed before going to keep-alive state. Thanks to Olexander Shtepa. *) Bugfix: the last address was missed in the $upstream_addr variable; bug appeared in 0.6.18. *) Bugfix: the "fastcgi_catch_stderr" directive did return error code; now it returns 502 code, that can be rerouted to a next server using the "fastcgi_next_upstream invalid_header" directive. *) Bugfix: a segmentation fault occurred in master process if the "fastcgi_catch_stderr" directive was used; bug appeared in 0.6.10. Thanks to Manlio Perillo.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nginx.c18
-rw-r--r--src/core/nginx.h2
-rw-r--r--src/core/ngx_conf_file.c2
-rw-r--r--src/core/ngx_crc32.c2
-rw-r--r--src/core/ngx_crc32.h25
-rw-r--r--src/core/ngx_cycle.c47
-rw-r--r--src/core/ngx_file.c147
-rw-r--r--src/core/ngx_file.h4
-rw-r--r--src/core/ngx_open_file_cache.c7
-rw-r--r--src/core/ngx_palloc.c10
-rw-r--r--src/core/ngx_rbtree.c53
-rw-r--r--src/core/ngx_resolver.c25
-rw-r--r--src/core/ngx_string.c13
-rw-r--r--src/core/ngx_string.h2
14 files changed, 242 insertions, 115 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 579ee161b..ee636825b 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -273,9 +273,11 @@ main(int argc, char *const *argv)
return 1;
}
- /* ngx_crc32_init() requires ngx_cacheline_size set in ngx_os_init() */
+ /*
+ * ngx_crc32_table_init() requires ngx_cacheline_size set in ngx_os_init()
+ */
- if (ngx_crc32_init() != NGX_OK) {
+ if (ngx_crc32_table_init() != NGX_OK) {
return 1;
}
@@ -756,12 +758,6 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_core_conf_t *ccf = conf;
-#if !(NGX_WIN32)
- ngx_str_t lock_file;
- struct group *grp;
- struct passwd *pwd;
-#endif
-
ngx_conf_init_value(ccf->daemon, 1);
ngx_conf_init_value(ccf->master, 1);
ngx_conf_init_msec_value(ccf->timer_resolution, 0);
@@ -794,6 +790,8 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
#if !(NGX_WIN32)
if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) {
+ struct group *grp;
+ struct passwd *pwd;
ngx_set_errno(0);
pwd = getpwnam(NGX_USER);
@@ -846,6 +844,9 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
return NGX_CONF_ERROR;
}
+ {
+ ngx_str_t lock_file;
+
lock_file = cycle->old_cycle->lock_file;
if (lock_file.len) {
@@ -879,6 +880,7 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ccf->lock_file.len),
".accept", sizeof(".accept"));
}
+ }
#endif
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 3221a75c6..bae7d8339 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_
-#define NGINX_VERSION "0.6.21"
+#define NGINX_VERSION "0.6.22"
#define NGINX_VER "nginx/" NGINX_VERSION
#define NGINX_VAR "NGINX"
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 6084abb4b..f00cf019b 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -934,7 +934,7 @@ ngx_conf_set_str_array_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a = (ngx_array_t **) (p + cmd->offset);
- if (*a == NULL) {
+ if (*a == NGX_CONF_UNSET_PTR) {
*a = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
if (*a == NULL) {
return NGX_CONF_ERROR;
diff --git a/src/core/ngx_crc32.c b/src/core/ngx_crc32.c
index 64b02ac7a..624510cee 100644
--- a/src/core/ngx_crc32.c
+++ b/src/core/ngx_crc32.c
@@ -102,7 +102,7 @@ uint32_t *ngx_crc32_table_short = ngx_crc32_table16;
ngx_int_t
-ngx_crc32_init(void)
+ngx_crc32_table_init(void)
{
void *p;
diff --git a/src/core/ngx_crc32.h b/src/core/ngx_crc32.h
index 7d5279d36..4435e4517 100644
--- a/src/core/ngx_crc32.h
+++ b/src/core/ngx_crc32.h
@@ -49,7 +49,30 @@ ngx_crc32_long(u_char *p, size_t len)
}
-ngx_int_t ngx_crc32_init(void);
+#define ngx_crc32_init(crc) \
+ crc = 0xffffffff
+
+
+static ngx_inline void
+ngx_crc32_update(uint32_t *crc, u_char *p, size_t len)
+{
+ uint32_t c;
+
+ c = *crc;
+
+ while (len--) {
+ c = ngx_crc32_table256[(c ^ *p++) & 0xff] ^ (c >> 8);
+ }
+
+ *crc = c;
+}
+
+
+#define ngx_crc32_final(crc) \
+ crc ^= 0xffffffff
+
+
+ngx_int_t ngx_crc32_table_init(void);
#endif /* _NGX_CRC32_H_INCLUDED_ */
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index f900a2824..edcb6b5b0 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -42,20 +42,21 @@ static ngx_str_t error_log = ngx_null_string;
ngx_cycle_t *
ngx_init_cycle(ngx_cycle_t *old_cycle)
{
- void *rv;
- u_char *lock_file;
- ngx_uint_t i, n;
- ngx_log_t *log;
- ngx_conf_t conf;
- ngx_pool_t *pool;
- ngx_cycle_t *cycle, **old;
- ngx_shm_zone_t *shm_zone, *oshm_zone;
- ngx_slab_pool_t *shpool;
- ngx_list_part_t *part, *opart;
- ngx_open_file_t *file;
- ngx_listening_t *ls, *nls;
- ngx_core_conf_t *ccf, *old_ccf;
- ngx_core_module_t *module;
+ void *rv;
+ char **senv, **env;
+ u_char *lock_file;
+ ngx_uint_t i, n;
+ ngx_log_t *log;
+ ngx_conf_t conf;
+ ngx_pool_t *pool;
+ ngx_cycle_t *cycle, **old;
+ ngx_shm_zone_t *shm_zone, *oshm_zone;
+ ngx_slab_pool_t *shpool;
+ ngx_list_part_t *part, *opart;
+ ngx_open_file_t *file;
+ ngx_listening_t *ls, *nls;
+ ngx_core_conf_t *ccf, *old_ccf;
+ ngx_core_module_t *module;
log = old_cycle->log;
@@ -187,6 +188,9 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
}
+ senv = environ;
+
+
ngx_memzero(&conf, sizeof(ngx_conf_t));
/* STUB: init array ? */
conf.args = ngx_array_create(pool, 10, sizeof(ngx_str_t));
@@ -694,9 +698,20 @@ old_shm_zone_done:
if (ngx_process == NGX_PROCESS_MASTER || ngx_is_init_cycle(old_cycle)) {
+ /*
+ * perl_destruct() frees environ if it is not the same as it was at
+ * perl_construct() time. So we have saved an previous cycle
+ * environment before ngx_conf_parse() where it will be changed.
+ */
+
+ env = environ;
+ environ = senv;
+
ngx_destroy_pool(old_cycle->pool);
cycle->old_cycle = NULL;
+ environ = env;
+
return cycle;
}
@@ -938,9 +953,6 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
ngx_uint_t i;
ngx_list_part_t *part;
ngx_open_file_t *file;
-#if !(NGX_WIN32)
- ngx_file_info_t fi;
-#endif
part = &cycle->open_files.part;
file = part->elts;
@@ -996,6 +1008,7 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
}
#else
if (user != (ngx_uid_t) NGX_CONF_UNSET_UINT) {
+ ngx_file_info_t fi;
if (ngx_file_info((const char *) file[i].name.data, &fi) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index f85578623..b6b15ca5f 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -61,16 +61,19 @@ ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool,
n = (uint32_t) ngx_next_temp_number(0);
+ cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t));
+ if (cln == NULL) {
+ return NGX_ERROR;
+ }
+
for ( ;; ) {
(void) ngx_sprintf(file->name.data + path->name.len + 1 + path->len,
"%010uD%Z", n);
- ngx_create_hashed_filename(file, path);
+ ngx_create_hashed_filename(path, file->name.data, file->name.len);
- cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t));
- if (cln == NULL) {
- return NGX_ERROR;
- }
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0,
+ "hashed path: %s", file->name.data);
file->fd = ngx_open_tempfile(file->name.data, persistent, access);
@@ -117,31 +120,27 @@ ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool,
void
-ngx_create_hashed_filename(ngx_file_t *file, ngx_path_t *path)
+ngx_create_hashed_filename(ngx_path_t *path, u_char *file, size_t len)
{
- size_t name, pos, level;
- ngx_uint_t i;
+ size_t i, level;
+ ngx_uint_t n;
- name = file->name.len;
- pos = path->name.len + 1;
+ i = path->name.len + 1;
- file->name.data[path->name.len + path->len] = '/';
+ file[path->name.len + path->len] = '/';
- for (i = 0; i < 3; i++) {
- level = path->level[i];
+ for (n = 0; n < 3; n++) {
+ level = path->level[n];
if (level == 0) {
break;
}
- name -= level;
- file->name.data[pos - 1] = '/';
- ngx_memcpy(&file->name.data[pos], &file->name.data[name], level);
- pos += level + 1;
+ len -= level;
+ file[i - 1] = '/';
+ ngx_memcpy(&file[i], &file[len], level);
+ i += level + 1;
}
-
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0,
- "hashed path: %s", file->name.data);
}
@@ -425,9 +424,6 @@ ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user)
ngx_err_t err;
ngx_uint_t i;
ngx_path_t **path;
-#if !(NGX_WIN32)
- ngx_file_info_t fi;
-#endif
path = cycle->pathes.elts;
for (i = 0; i < cycle->pathes.nelts; i++) {
@@ -447,6 +443,8 @@ ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user)
}
#if !(NGX_WIN32)
+ {
+ ngx_file_info_t fi;
if (ngx_file_info((const char *) path[i]->name.data, &fi) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
@@ -474,7 +472,7 @@ ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user)
return NGX_ERROR;
}
}
-
+ }
#endif
}
@@ -483,6 +481,107 @@ ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user)
ngx_int_t
+ngx_create_path_and_rename_file(ngx_str_t *src, ngx_str_t *to,
+ ngx_uint_t access, ngx_uint_t full_path, ngx_uint_t delete, ngx_log_t *log)
+{
+ ngx_err_t err;
+
+#if !(NGX_WIN32)
+
+ if (ngx_change_file_access(src->data, access) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
+ ngx_change_file_access_n " \"%s\" failed", src->data);
+ err = 0;
+ goto failed;
+ }
+
+#endif
+
+ if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) {
+ return NGX_OK;
+ }
+
+ err = ngx_errno;
+
+ if (err == NGX_ENOENT) {
+
+ if (!full_path) {
+ goto failed;
+ }
+
+ err = ngx_create_full_path(to->data, ngx_dir_access(access));
+
+ if (err) {
+ ngx_log_error(NGX_LOG_CRIT, log, err,
+ ngx_create_dir_n " \"%s\" failed", to->data);
+ err = 0;
+ goto failed;
+ }
+
+ if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) {
+ return NGX_OK;
+ }
+
+ err = ngx_errno;
+ goto failed;
+ }
+
+#if (NGX_WIN32)
+
+ if (err == NGX_EEXIST) {
+ if (ngx_win32_rename_file(src, to, log) == NGX_OK) {
+
+ if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) {
+ return NGX_OK;
+ }
+
+ err = ngx_errno;
+
+ } else {
+ err = 0;
+ }
+ }
+
+#endif
+
+failed:
+
+ if (delete) {
+ if (ngx_delete_file(src->data) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
+ ngx_delete_file_n " \"%s\" failed", src->data);
+ }
+ }
+
+ if (err) {
+ ngx_log_error(NGX_LOG_CRIT, log, err,
+ ngx_rename_file_n " \"%s\" to \"%s\" failed",
+ src->data, to->data);
+ }
+
+ return NGX_ERROR;
+}
+
+
+/*
+ * ctx->init_handler() - see ctx->alloc
+ * ctx->file_handler() - file handler
+ * ctx->pre_tree_handler() - handler is called before entering directory
+ * ctx->post_tree_handler() - handler is called after leaving directory
+ * ctx->spec_handler() - special (socket, FIFO, etc.) file handler
+ *
+ * ctx->data - some data structure, it may be the same on all levels, or
+ * reallocated if ctx->alloc is nonzero
+ *
+ * ctx->alloc - a size of data structure that is allocated at every level
+ * and is initilialized by ctx->init_handler()
+ *
+ * ctx->log - a log
+ *
+ * on fatal (memory) error handler must return NGX_ABORT to stop walking tree
+ */
+
+ngx_int_t
ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree)
{
void *data, *prev;
diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h
index 063b0fb83..61089ff34 100644
--- a/src/core/ngx_file.h
+++ b/src/core/ngx_file.h
@@ -84,11 +84,13 @@ ssize_t ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain);
ngx_int_t ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
ngx_pool_t *pool, ngx_uint_t persistent, ngx_uint_t clean,
ngx_uint_t access);
-void ngx_create_hashed_filename(ngx_file_t *file, ngx_path_t *path);
+void ngx_create_hashed_filename(ngx_path_t *path, u_char *file, size_t len);
ngx_int_t ngx_create_path(ngx_file_t *file, ngx_path_t *path);
ngx_err_t ngx_create_full_path(u_char *dir, ngx_uint_t access);
ngx_int_t ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot);
ngx_int_t ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user);
+ngx_int_t ngx_create_path_and_rename_file(ngx_str_t *src, ngx_str_t *to,
+ ngx_uint_t access, ngx_uint_t full_path, ngx_uint_t delete, ngx_log_t *log);
ngx_int_t ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree);
void ngx_init_temp_number(void);
diff --git a/src/core/ngx_open_file_cache.c b/src/core/ngx_open_file_cache.c
index dab98b3ff..d518f4b96 100644
--- a/src/core/ngx_open_file_cache.c
+++ b/src/core/ngx_open_file_cache.c
@@ -53,11 +53,8 @@ ngx_open_file_cache_init(ngx_pool_t *pool, ngx_uint_t max, time_t inactive)
return NULL;
}
- ngx_rbtree_sentinel_init(sentinel);
-
- cache->rbtree.root = sentinel;
- cache->rbtree.sentinel = sentinel;
- cache->rbtree.insert = ngx_open_file_cache_rbtree_insert_value;
+ ngx_rbtree_init(&cache->rbtree, sentinel,
+ ngx_open_file_cache_rbtree_insert_value);
cache->current = 0;
cache->max = max;
diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c
index 978fc30f0..4cf7e8a4b 100644
--- a/src/core/ngx_palloc.c
+++ b/src/core/ngx_palloc.c
@@ -40,6 +40,8 @@ ngx_destroy_pool(ngx_pool_t *pool)
for (c = pool->cleanup; c; c = c->next) {
if (c->handler) {
+ ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
+ "run cleanup: %p", c);
c->handler(c->data);
}
}
@@ -245,8 +247,8 @@ ngx_pool_cleanup_file(void *data)
{
ngx_pool_cleanup_file_t *c = data;
- ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, c->log, 0, "run cleanup: %p, fd:%d",
- c, c->fd);
+ ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, c->log, 0, "file cleanup: fd:%d",
+ c->fd);
if (ngx_close_file(c->fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
@@ -262,8 +264,8 @@ ngx_pool_delete_file(void *data)
ngx_err_t err;
- ngx_log_debug3(NGX_LOG_DEBUG_ALLOC, c->log, 0, "run cleanup: %p, fd:%d %s",
- c, c->fd, c->name);
+ ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, c->log, 0, "file cleanup: fd:%d %s",
+ c->fd, c->name);
if (ngx_delete_file(c->name) == NGX_FILE_ERROR) {
err = ngx_errno;
diff --git a/src/core/ngx_rbtree.c b/src/core/ngx_rbtree.c
index 0a5753cdf..7d240fe81 100644
--- a/src/core/ngx_rbtree.c
+++ b/src/core/ngx_rbtree.c
@@ -97,28 +97,20 @@ void
ngx_rbtree_insert_value(ngx_rbtree_node_t *temp, ngx_rbtree_node_t *node,
ngx_rbtree_node_t *sentinel)
{
- for ( ;; ) {
-
- if (node->key < temp->key) {
-
- if (temp->left == sentinel) {
- temp->left = node;
- break;
- }
-
- temp = temp->left;
+ ngx_rbtree_node_t **p;
- } else {
+ for ( ;; ) {
- if (temp->right == sentinel) {
- temp->right = node;
- break;
- }
+ p = (node->key < temp->key) ? &temp->left : &temp->right;
- temp = temp->right;
+ if (*p == sentinel) {
+ break;
}
+
+ temp = *p;
}
+ *p = node;
node->parent = temp;
node->left = sentinel;
node->right = sentinel;
@@ -130,6 +122,8 @@ void
ngx_rbtree_insert_timer_value(ngx_rbtree_node_t *temp, ngx_rbtree_node_t *node,
ngx_rbtree_node_t *sentinel)
{
+ ngx_rbtree_node_t **p;
+
for ( ;; ) {
/*
@@ -139,29 +133,20 @@ ngx_rbtree_insert_timer_value(ngx_rbtree_node_t *temp, ngx_rbtree_node_t *node,
* The comparison takes into account that overflow.
*/
- if ((ngx_rbtree_key_int_t) node->key - (ngx_rbtree_key_int_t) temp->key
- < 0)
- {
- /* node->key < temp->key */
-
- if (temp->left == sentinel) {
- temp->left = node;
- break;
- }
-
- temp = temp->left;
+ /* node->key < temp->key */
- } else {
-
- if (temp->right == sentinel) {
- temp->right = node;
- break;
- }
+ p = ((ngx_rbtree_key_int_t) node->key - (ngx_rbtree_key_int_t) temp->key
+ < 0)
+ ? &temp->left : &temp->right;
- temp = temp->right;
+ if (*p == sentinel) {
+ break;
}
+
+ temp = *p;
}
+ *p = node;
node->parent = temp;
node->left = sentinel;
node->right = sentinel;
diff --git a/src/core/ngx_resolver.c b/src/core/ngx_resolver.c
index ab4dcdabc..be0121e2e 100644
--- a/src/core/ngx_resolver.c
+++ b/src/core/ngx_resolver.c
@@ -67,9 +67,9 @@ static void ngx_resolver_read_response(ngx_event_t *rev);
static void ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf,
size_t n);
static void ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t n,
- ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan, ngx_uint_t i);
+ ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan, ngx_uint_t ans);
static void ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n,
- ngx_uint_t ident, ngx_uint_t code);
+ ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan);
static ngx_resolver_node_t *ngx_resolver_lookup_name(ngx_resolver_t *r,
ngx_str_t *name, uint32_t hash);
static ngx_resolver_node_t *ngx_resolver_lookup_addr(ngx_resolver_t *r,
@@ -884,11 +884,6 @@ ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf, size_t n)
goto done;
}
- if (code == 0 && nan == 0) {
- err = "no answers in DNS response";
- goto done;
- }
-
i = sizeof(ngx_resolver_query_t);
while (i < (ngx_uint_t) n) {
@@ -934,13 +929,13 @@ found:
case NGX_RESOLVE_A:
ngx_resolver_process_a(r, buf, n, ident, code, nan,
- i + sizeof(ngx_resolver_qs_t));
+ i + sizeof(ngx_resolver_qs_t));
break;
case NGX_RESOLVE_PTR:
- ngx_resolver_process_ptr(r, buf, n, ident, code);
+ ngx_resolver_process_ptr(r, buf, n, ident, code, nan);
break;
@@ -1006,6 +1001,10 @@ ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t last,
goto failed;
}
+ if (code == 0 && nan == 0) {
+ code = 3; /* NXDOMAIN */
+ }
+
if (code) {
next = rn->waiting;
rn->waiting = NULL;
@@ -1204,6 +1203,8 @@ ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t last,
ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0,
"resolver cname:\"%V\"", &name);
+ ngx_queue_remove(&rn->queue);
+
rn->cnlen = (u_short) name.len;
rn->u.cname = name.data;
rn->valid = ngx_time() + r->valid;
@@ -1250,7 +1251,7 @@ failed:
static void
ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n,
- ngx_uint_t ident, ngx_uint_t code)
+ ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan)
{
char *err;
size_t len;
@@ -1307,6 +1308,10 @@ ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n,
goto failed;
}
+ if (code == 0 && nan == 0) {
+ code = 3; /* NXDOMAIN */
+ }
+
if (code) {
next = rn->waiting;
rn->waiting = NULL;
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 2eaffd60d..f878c559f 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -816,18 +816,17 @@ ngx_hextoi(u_char *line, size_t n)
}
-void
-ngx_md5_text(u_char *text, u_char *md5)
+u_char *
+ngx_hex_dump(u_char *dst, u_char *src, size_t len)
{
- int i;
static u_char hex[] = "0123456789abcdef";
- for (i = 0; i < 16; i++) {
- *text++ = hex[md5[i] >> 4];
- *text++ = hex[md5[i] & 0xf];
+ while (len--) {
+ *dst++ = hex[*src >> 4];
+ *dst++ = hex[*src++ & 0xf];
}
- *text = '\0';
+ return dst;
}
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index 1bca791bf..4fe5cb604 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -141,7 +141,7 @@ off_t ngx_atoof(u_char *line, size_t n);
time_t ngx_atotm(u_char *line, size_t n);
ngx_int_t ngx_hextoi(u_char *line, size_t n);
-void ngx_md5_text(u_char *text, u_char *md5);
+u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len);
#define ngx_base64_encoded_length(len) (((len + 2) / 3) * 4)