nginx-0.0.1-2003-12-05-20:07:27 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 8c4716d..d52933a 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -15,11 +15,6 @@
static void ngx_clean_old_cycles(ngx_event_t *ev);
-#if (NGX_DEBUG) && (__FreeBSD__)
-extern char *malloc_options;
-#endif
-
-
typedef struct {
int daemon;
} ngx_core_conf_t;
@@ -81,13 +76,8 @@
ngx_core_conf_t *ccf;
#endif
-#if (NGX_DEBUG) && (__FreeBSD__)
-#if __FreeBSD_version >= 500014
- _malloc_options
-#else
- malloc_options
-#endif
- = "J";
+#if __FreeBSD__
+ ngx_debug_init();
#endif
/* TODO */ ngx_max_sockets = -1;
@@ -134,7 +124,9 @@
/* life cycle */
for ( ;; ) {
+#if 0
/* STUB */ cycle->log->log_level = NGX_LOG_DEBUG|NGX_LOG_DEBUG_HTTP;
+#endif
#if 0
@@ -255,13 +247,11 @@
ngx_listening_t *ls, *nls;
- pool = ngx_create_pool(16 * 1024, log);
- if (pool == NULL) {
+ if (!(pool = ngx_create_pool(16 * 1024, log))) {
return NULL;
}
- cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t));
- if (cycle == NULL) {
+ if (!(cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t)))) {
ngx_destroy_pool(pool);
return NULL;
}
@@ -271,8 +261,7 @@
n = old_cycle ? old_cycle->pathes.nelts : 10;
- cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *));
- if (cycle->pathes.elts == NULL) {
+ if (!(cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)))) {
ngx_destroy_pool(pool);
return NULL;
}
@@ -294,8 +283,7 @@
cycle->open_files.pool = pool;
- cycle->log = ngx_log_create_errlog(cycle, NULL);
- if (cycle->log == NULL) {
+ if (!(cycle->log = ngx_log_create_errlog(cycle, NULL))) {
ngx_destroy_pool(pool);
return NULL;
}
@@ -320,8 +308,7 @@
}
- ccf = ngx_pcalloc(pool, sizeof(ngx_core_conf_t));
- if (ccf == NULL) {
+ if (!(ccf = ngx_pcalloc(pool, sizeof(ngx_core_conf_t)))) {
ngx_destroy_pool(pool);
return NULL;
}
@@ -386,7 +373,9 @@
#endif
}
+#if 0
/* STUB */ cycle->log->log_level = NGX_LOG_DEBUG;
+#endif
if (!failed) {
if (old_cycle) {
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index e3e292c..3f578fc 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -22,7 +22,7 @@
static ngx_command_t ngx_errlog_commands[] = {
{ngx_string("error_log"),
- NGX_MAIN_CONF|NGX_CONF_TAKE1,
+ NGX_MAIN_CONF|NGX_CONF_TAKE12,
ngx_set_error_log,
0,
0,
@@ -233,12 +233,14 @@
ngx_stderr.fd = GetStdHandle(STD_ERROR_HANDLE);
if (ngx_stderr.fd == NGX_INVALID_FILE) {
- /* TODO: where we can log error ? */
+ /* TODO: where can we log error ? */
return NULL;
} else if (ngx_stderr.fd == NULL) {
+
/* there are no associated standard handles */
- /* TODO: where we can log possible errors ? */
+
+ /* TODO: where can we can log possible errors ? */
ngx_stderr.fd = NGX_INVALID_FILE;
}
@@ -251,7 +253,10 @@
ngx_log.file = &ngx_stderr;
ngx_log.log_level = NGX_LOG_INFO;
+
+#if 0
/* STUB */ ngx_log.log_level = NGX_LOG_DEBUG;
+#endif
return &ngx_log;
}
@@ -264,7 +269,9 @@
ngx_test_null(log, ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)), NULL);
ngx_test_null(log->file, ngx_conf_open_file(cycle, name), NULL);
+#if 0
/* STUB */ log->log_level = NGX_LOG_DEBUG;
+#endif
return log;
}
@@ -272,6 +279,7 @@
static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
+ ngx_int_t i;
ngx_str_t *value;
value = cf->args->elts;
@@ -283,51 +291,19 @@
cf->cycle->log->file->name = value[1];
}
- return NGX_CONF_OK;
-}
-
-
-#if 0
-
-char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log)
-{
- int len;
- ngx_err_t err;
- ngx_str_t *value;
-
- value = cf->args->elts;
-
- log->file->fd = ngx_open_file(value[1].data,
- NGX_FILE_RDWR,
- NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
-
- if (log->file->fd == NGX_INVALID_FILE) {
- err = ngx_errno;
- len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
- ngx_open_file_n " \"%s\" failed (%d: ",
- value[1].data, err);
- len += ngx_strerror_r(err, ngx_conf_errstr + len,
- sizeof(ngx_conf_errstr) - len - 1);
- ngx_conf_errstr[len++] = ')';
- ngx_conf_errstr[len++] = '\0';
- return ngx_conf_errstr;
+ if (cf->args->nelts == 3) {
+ for (i = 1; i <= /* STUB ??? */ NGX_LOG_DEBUG; i++) {
+ if (ngx_strcmp(value[2].data, err_levels[i]) == 0) {
+ cf->cycle->log->log_level = i;
+ break;
+ }
+ }
+ if (i > NGX_LOG_DEBUG) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid log level \"%s\"", value[2].data);
+ return NGX_CONF_ERROR;
+ }
}
-#if (WIN32)
- if (ngx_file_append_mode(log->file->fd) == NGX_ERROR) {
- err = ngx_errno;
- len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
- ngx_file_append_mode_n " \"%s\" failed (%d: ",
- value[1].data, err);
- len += ngx_strerror_r(err, ngx_conf_errstr + len,
- sizeof(ngx_conf_errstr) - len - 1);
- ngx_conf_errstr[len++] = ')';
- ngx_conf_errstr[len++] = '\0';
- return ngx_conf_errstr;
- }
-#endif
-
return NGX_CONF_OK;
}
-
-#endif
diff --git a/src/core/ngx_rbtree.c b/src/core/ngx_rbtree.c
index ea78e22..3e6025f 100644
--- a/src/core/ngx_rbtree.c
+++ b/src/core/ngx_rbtree.c
@@ -15,23 +15,25 @@
#define ngx_rbt_copy_color(n1, n2) (n1->color = n2->color)
-ngx_inline void ngx_rbtree_left_rotate(ngx_rbtree_t **root, ngx_rbtree_t *node);
+ngx_inline void ngx_rbtree_left_rotate(ngx_rbtree_t **root,
+ ngx_rbtree_t *sentinel,
+ ngx_rbtree_t *node);
ngx_inline void ngx_rbtree_right_rotate(ngx_rbtree_t **root,
+ ngx_rbtree_t *sentinel,
ngx_rbtree_t *node);
-ngx_rbtree_t sentinel;
-
-void ngx_rbtree_insert(ngx_rbtree_t **root, ngx_rbtree_t *node)
+void ngx_rbtree_insert(ngx_rbtree_t **root, ngx_rbtree_t *sentinel,
+ ngx_rbtree_t *node)
{
ngx_rbtree_t *temp;
/* a binary tree insert */
- if (*root == &sentinel) {
- node->parent = &sentinel;
- node->left = &sentinel;
- node->right = &sentinel;
+ if (*root == sentinel) {
+ node->parent = sentinel;
+ node->left = sentinel;
+ node->right = sentinel;
ngx_rbt_black(node);
*root = node;
@@ -42,7 +44,7 @@
for ( ;; ) {
if (node->key < temp->key) {
- if (temp->left == &sentinel) {
+ if (temp->left == sentinel) {
temp->left = node;
break;
}
@@ -51,7 +53,7 @@
continue;
}
- if (temp->right == &sentinel) {
+ if (temp->right == sentinel) {
temp->right = node;
break;
}
@@ -61,8 +63,8 @@
}
node->parent = temp;
- node->left = &sentinel;
- node->right = &sentinel;
+ node->left = sentinel;
+ node->right = sentinel;
/* re-balance tree */
@@ -83,12 +85,12 @@
} else {
if (node == node->parent->right) {
node = node->parent;
- ngx_rbtree_left_rotate(root, node);
+ ngx_rbtree_left_rotate(root, sentinel, node);
}
ngx_rbt_black(node->parent);
ngx_rbt_red(node->parent->parent);
- ngx_rbtree_right_rotate(root, node->parent->parent);
+ ngx_rbtree_right_rotate(root, sentinel, node->parent->parent);
}
} else {
@@ -103,12 +105,12 @@
} else {
if (node == node->parent->left) {
node = node->parent;
- ngx_rbtree_right_rotate(root, node);
+ ngx_rbtree_right_rotate(root, sentinel, node);
}
ngx_rbt_black(node->parent);
ngx_rbt_red(node->parent->parent);
- ngx_rbtree_left_rotate(root, node->parent->parent);
+ ngx_rbtree_left_rotate(root, sentinel, node->parent->parent);
}
}
@@ -118,34 +120,35 @@
}
-void ngx_rbtree_delete(ngx_rbtree_t **root, ngx_rbtree_t *node)
+void ngx_rbtree_delete(ngx_rbtree_t **root, ngx_rbtree_t *sentinel,
+ ngx_rbtree_t *node)
{
ngx_rbtree_t *subst, *temp, *w;
/* a binary tree delete */
- if (node->left == &sentinel || node->right == &sentinel) {
+ if (node->left == sentinel || node->right == sentinel) {
subst = node;
} else {
/* find a node successor */
- if (node->right == &sentinel) {
+ if (node->right == sentinel) {
temp = node;
subst = node->parent;
- while (subst != &sentinel && temp == subst->right) {
+ while (subst != sentinel && temp == subst->right) {
temp = subst;
subst = subst->parent;
}
} else {
- subst = ngx_rbtree_min(node->right);
+ subst = ngx_rbtree_min(node->right, sentinel);
}
}
- if (subst->left != &sentinel) {
+ if (subst->left != sentinel) {
temp = subst->left;
} else {
temp = subst->right;
@@ -153,7 +156,7 @@
temp->parent = subst->parent;
- if (subst->parent == &sentinel) {
+ if (subst->parent == sentinel) {
*root = temp;
} else if (subst == subst->parent->left) {
@@ -174,14 +177,14 @@
/* a delete fixup */
- while (temp->parent != &sentinel && ngx_rbt_is_black(temp)) {
+ while (temp->parent != sentinel && ngx_rbt_is_black(temp)) {
if (temp == temp->parent->left) {
w = temp->parent->right;
if (ngx_rbt_is_red(w)) {
ngx_rbt_black(w);
ngx_rbt_red(temp->parent);
- ngx_rbtree_left_rotate(root, temp->parent);
+ ngx_rbtree_left_rotate(root, sentinel, temp->parent);
w = temp->parent->right;
}
@@ -193,14 +196,14 @@
if (ngx_rbt_is_black(w->right)) {
ngx_rbt_black(w->left);
ngx_rbt_red(w);
- ngx_rbtree_right_rotate(root, w);
+ ngx_rbtree_right_rotate(root, sentinel, w);
w = temp->parent->right;
}
ngx_rbt_copy_color(w, temp->parent);
ngx_rbt_black(temp->parent);
ngx_rbt_black(w->right);
- ngx_rbtree_left_rotate(root, temp->parent);
+ ngx_rbtree_left_rotate(root, sentinel, temp->parent);
temp = *root;
}
@@ -210,7 +213,7 @@
if (ngx_rbt_is_red(w)) {
ngx_rbt_black(w);
ngx_rbt_red(temp->parent);
- ngx_rbtree_right_rotate(root, temp->parent);
+ ngx_rbtree_right_rotate(root, sentinel, temp->parent);
w = temp->parent->left;
}
@@ -222,14 +225,14 @@
if (ngx_rbt_is_black(w->left)) {
ngx_rbt_black(w->right);
ngx_rbt_red(w);
- ngx_rbtree_left_rotate(root, w);
+ ngx_rbtree_left_rotate(root, sentinel, w);
w = temp->parent->left;
}
ngx_rbt_copy_color(w, temp->parent);
ngx_rbt_black(temp->parent);
ngx_rbt_black(w->left);
- ngx_rbtree_right_rotate(root, temp->parent);
+ ngx_rbtree_right_rotate(root, sentinel, temp->parent);
temp = *root;
}
}
@@ -239,20 +242,22 @@
}
-ngx_inline void ngx_rbtree_left_rotate(ngx_rbtree_t **root, ngx_rbtree_t *node)
+ngx_inline void ngx_rbtree_left_rotate(ngx_rbtree_t **root,
+ ngx_rbtree_t *sentinel,
+ ngx_rbtree_t *node)
{
ngx_rbtree_t *temp;
temp = node->right;
node->right = temp->left;
- if (temp->left != &sentinel) {
+ if (temp->left != sentinel) {
temp->left->parent = node;
}
temp->parent = node->parent;
- if (node->parent == &sentinel) {
+ if (node->parent == sentinel) {
*root = temp;
} else if (node == node->parent->left) {
@@ -267,20 +272,22 @@
}
-ngx_inline void ngx_rbtree_right_rotate(ngx_rbtree_t **root, ngx_rbtree_t *node)
+ngx_inline void ngx_rbtree_right_rotate(ngx_rbtree_t **root,
+ ngx_rbtree_t *sentinel,
+ ngx_rbtree_t *node)
{
ngx_rbtree_t *temp;
temp = node->left;
node->left = temp->right;
- if (temp->right != &sentinel) {
+ if (temp->right != sentinel) {
temp->right->parent = node;
}
temp->parent = node->parent;
- if (node->parent == &sentinel) {
+ if (node->parent == sentinel) {
*root = temp;
} else if (node == node->parent->right) {
diff --git a/src/core/ngx_rbtree.h b/src/core/ngx_rbtree.h
index af0f2ec..db435ff 100644
--- a/src/core/ngx_rbtree.h
+++ b/src/core/ngx_rbtree.h
@@ -16,16 +16,17 @@
char color;
};
-extern ngx_rbtree_t sentinel;
+
+void ngx_rbtree_insert(ngx_rbtree_t **root, ngx_rbtree_t *sentinel,
+ ngx_rbtree_t *node);
+void ngx_rbtree_delete(ngx_rbtree_t **root, ngx_rbtree_t *sentinel,
+ ngx_rbtree_t *node);
-void ngx_rbtree_insert(ngx_rbtree_t **root, ngx_rbtree_t *node);
-void ngx_rbtree_delete(ngx_rbtree_t **root, ngx_rbtree_t *node);
-
-
-ngx_inline static ngx_rbtree_t *ngx_rbtree_min(ngx_rbtree_t *root)
+ngx_inline static ngx_rbtree_t *ngx_rbtree_min(ngx_rbtree_t *root,
+ ngx_rbtree_t *sentinel)
{
- while (root->left != &sentinel) {
+ while (root->left != sentinel) {
root = root->left;
}
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index 12dc229..a1ffdce 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -5,18 +5,19 @@
time_t ngx_cached_time;
ngx_epoch_msec_t ngx_elapsed_msec;
+ngx_epoch_msec_t ngx_old_elapsed_msec;
ngx_epoch_msec_t ngx_start_msec;
ngx_tm_t ngx_cached_gmtime;
-static char cached_err_log_time[] = "1970/09/28 12:00:00";
-ngx_str_t ngx_cached_err_log_time;
+static char cached_err_log_time[] = "1970/09/28 12:00:00";
+ngx_str_t ngx_cached_err_log_time;
-static char cached_http_time[] = "Mon, 28 Sep 1970 06:00:00 GMT";
-ngx_str_t ngx_cached_http_time;
+static char cached_http_time[] = "Mon, 28 Sep 1970 06:00:00 GMT";
+ngx_str_t ngx_cached_http_time;
-static char cached_http_log_time[] = "28/Sep/1970:12:00:00";
-ngx_str_t ngx_cached_http_log_time;
+static char cached_http_log_time[] = "28/Sep/1970:12:00:00";
+ngx_str_t ngx_cached_http_log_time;
static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fir", "Sat" };
@@ -40,6 +41,7 @@
ngx_gettimeofday(&tv);
ngx_cached_time = tv.tv_sec;
ngx_start_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ ngx_old_elapsed_msec = 0;
ngx_elapsed_msec = 0;
ngx_time_update();
diff --git a/src/core/ngx_times.h b/src/core/ngx_times.h
index 6ff316d..98382b6 100644
--- a/src/core/ngx_times.h
+++ b/src/core/ngx_times.h
@@ -16,6 +16,7 @@
extern time_t ngx_cached_time;
extern ngx_epoch_msec_t ngx_elapsed_msec;
+extern ngx_epoch_msec_t ngx_old_elapsed_msec;
extern ngx_epoch_msec_t ngx_start_msec;
extern ngx_str_t ngx_cached_err_log_time;