Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-11-11 17:07:14 +0300
committerIgor Sysoev <igor@sysoev.ru>2004-11-11 17:07:14 +0300
commit1b73583ba2c0e4b72d951218827e0c621427d389 (patch)
tree9e4d204e2cce91560d5cb8908b8a1a9f2c1d92ee /src/core
parentd6f24959428caed68a509a19ca4fd866d978a69c (diff)
nginx-0.1.5-RELEASE importrelease-0.1.5
*) Bugfix: on Solaris and Linux there may be too many "recvmsg() returned not enough data" alerts. *) Bugfix: there were the "writev() failed (22: Invalid argument)" errors on Solaris in proxy mode without sendfile. On other platforms that do not support sendfile at all the process got caught in an endless loop. *) Bugfix: segmentation fault on Solaris in proxy mode and using sendfile. *) Bugfix: segmentation fault on Solaris. *) Bugfix: on-line upgrade did not work on Linux. *) Bugfix: the ngx_http_autoindex_module module did not escape the spaces, the quotes, and the percent signs in the directory listing. *) Change: the decrease of the copy operations. *) Feature: the userid_p3p directive.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nginx.c61
-rw-r--r--src/core/nginx.h2
-rw-r--r--src/core/ngx_conf_file.c90
-rw-r--r--src/core/ngx_conf_file.h5
-rw-r--r--src/core/ngx_config.h13
-rw-r--r--src/core/ngx_connection.c68
-rw-r--r--src/core/ngx_connection.h4
-rw-r--r--src/core/ngx_cycle.c74
-rw-r--r--src/core/ngx_cycle.h5
-rw-r--r--src/core/ngx_file.c7
-rw-r--r--src/core/ngx_inet.c24
-rw-r--r--src/core/ngx_log.c193
-rw-r--r--src/core/ngx_log.h11
-rw-r--r--src/core/ngx_output_chain.c20
-rw-r--r--src/core/ngx_palloc.c8
-rw-r--r--src/core/ngx_regex.c4
-rw-r--r--src/core/ngx_string.c377
-rw-r--r--src/core/ngx_string.h29
-rw-r--r--src/core/ngx_times.c85
19 files changed, 601 insertions, 479 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index ab85b2373..53ac666cd 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -18,6 +18,13 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf);
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static ngx_conf_enum_t ngx_debug_points[] = {
+ { ngx_string("stop"), NGX_DEBUG_POINTS_STOP },
+ { ngx_string("abort"), NGX_DEBUG_POINTS_ABORT },
+ { ngx_null_string, 0 }
+};
+
+
static ngx_command_t ngx_core_commands[] = {
{ ngx_string("daemon"),
@@ -41,6 +48,13 @@ static ngx_command_t ngx_core_commands[] = {
offsetof(ngx_core_conf_t, worker_processes),
NULL },
+ { ngx_string("debug_points"),
+ NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_enum_slot,
+ 0,
+ offsetof(ngx_core_conf_t, debug_points),
+ &ngx_debug_points },
+
#if (NGX_THREADS)
{ ngx_string("worker_threads"),
@@ -97,6 +111,7 @@ ngx_module_t ngx_core_module = {
ngx_uint_t ngx_max_module;
+
int main(int argc, char *const *argv, char *const *envp)
{
ngx_int_t i;
@@ -118,7 +133,7 @@ int main(int argc, char *const *argv, char *const *envp)
ngx_pid = ngx_getpid();
- if (!(log = ngx_log_init_stderr())) {
+ if (!(log = ngx_log_init())) {
return 1;
}
@@ -165,7 +180,7 @@ int main(int argc, char *const *argv, char *const *envp)
if (cycle == NULL) {
if (ngx_test_config) {
ngx_log_error(NGX_LOG_EMERG, log, 0,
- "the configuration file %s test failed",
+ "the configuration file \"%s\" test failed",
init_cycle.conf_file.data);
}
@@ -174,7 +189,7 @@ int main(int argc, char *const *argv, char *const *envp)
if (ngx_test_config) {
ngx_log_error(NGX_LOG_INFO, log, 0,
- "the configuration file %s was tested successfully",
+ "the configuration file \"%s\" was tested successfully",
cycle->conf_file.data);
return 0;
}
@@ -187,7 +202,7 @@ int main(int argc, char *const *argv, char *const *envp)
ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE;
-#if (WIN32)
+#if (NGX_WIN32)
#if 0
@@ -241,11 +256,14 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
return NGX_OK;
}
- ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
"using inherited sockets from \"%s\"", inherited);
- ngx_init_array(cycle->listening, cycle->pool,
- 10, sizeof(ngx_listening_t), NGX_ERROR);
+ if (ngx_array_init(&cycle->listening, cycle->pool, 10,
+ sizeof(ngx_listening_t)) == NGX_ERROR)
+ {
+ return NGX_ERROR;
+ }
for (p = inherited, v = p; *p; p++) {
if (*p == ':' || *p == ';') {
@@ -260,7 +278,7 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
v = p + 1;
- if (!(ls = ngx_push_array(&cycle->listening))) {
+ if (!(ls = ngx_array_push(&cycle->listening))) {
return NGX_ERROR;
}
@@ -276,7 +294,8 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
{
- char *env[3], *var, *p;
+ char *env[3], *var;
+ u_char *p;
ngx_uint_t i;
ngx_pid_t pid;
ngx_exec_ctx_t ctx;
@@ -290,20 +309,22 @@ ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
+ cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
cycle->log);
- p = (char *) ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
+ p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
ls = cycle->listening.elts;
for (i = 0; i < cycle->listening.nelts; i++) {
- p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd);
+ p = ngx_sprintf(p, "%ud;", ls[i].fd);
}
+ *p = '\0';
+
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var);
env[0] = var;
#if (NGX_SETPROCTITLE_USES_ENV)
- /* allocate spare 300 bytes for the new binary process title */
+ /* allocate the spare 300 bytes for the new binary process title */
env[1] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
@@ -430,12 +451,13 @@ static void *ngx_core_module_create_conf(ngx_cycle_t *cycle)
ccf->daemon = NGX_CONF_UNSET;
ccf->master = NGX_CONF_UNSET;
ccf->worker_processes = NGX_CONF_UNSET;
+ ccf->debug_points = NGX_CONF_UNSET;
+ ccf->user = (ngx_uid_t) NGX_CONF_UNSET;
+ ccf->group = (ngx_gid_t) NGX_CONF_UNSET;
#if (NGX_THREADS)
ccf->worker_threads = NGX_CONF_UNSET;
- ccf->thread_stack_size = NGX_CONF_UNSET;
+ ccf->thread_stack_size = NGX_CONF_UNSET_SIZE;
#endif
- ccf->user = (ngx_uid_t) NGX_CONF_UNSET;
- ccf->group = (ngx_gid_t) NGX_CONF_UNSET;
return ccf;
}
@@ -445,7 +467,7 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_core_conf_t *ccf = conf;
-#if !(WIN32)
+#if !(NGX_WIN32)
struct passwd *pwd;
struct group *grp;
#endif
@@ -453,6 +475,7 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_value(ccf->daemon, 1);
ngx_conf_init_value(ccf->master, 1);
ngx_conf_init_value(ccf->worker_processes, 1);
+ ngx_conf_init_value(ccf->debug_points, 0);
#if (NGX_THREADS)
ngx_conf_init_value(ccf->worker_threads, 0);
@@ -460,9 +483,9 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024);
#endif
-#if !(WIN32)
+#if !(NGX_WIN32)
- if (ccf->user == (uid_t) NGX_CONF_UNSET) {
+ if (ccf->user == (uid_t) NGX_CONF_UNSET && geteuid() == 0) {
pwd = getpwnam(NGX_USER);
if (pwd == NULL) {
@@ -509,7 +532,7 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
-#if (WIN32)
+#if (NGX_WIN32)
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"user\" is not supported, ignored");
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 0d42998f4..2be26e06b 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_
-#define NGINX_VER "nginx/0.1.4"
+#define NGINX_VER "nginx/0.1.5"
#define NGINX_VAR "NGINX"
#define NGX_NEWPID_EXT ".newbin"
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index fb629a439..3c7898ae2 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -73,7 +73,7 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
fd = ngx_open_file(filename->data, NGX_FILE_RDONLY, NGX_FILE_OPEN);
if (fd == NGX_INVALID_FILE) {
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
- ngx_open_file_n " %s failed", filename->data);
+ ngx_open_file_n " \"%s\" failed", filename->data);
return NGX_CONF_ERROR;
}
@@ -84,7 +84,7 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) {
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
- ngx_fd_info_n " %s failed", filename->data);
+ ngx_fd_info_n " \"%s\" failed", filename->data);
}
if (!(cf->conf_file->buffer = ngx_create_temp_buf(cf->pool, 1024))) {
@@ -103,8 +103,12 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
rc = ngx_conf_read_token(cf);
/*
- * ngx_conf_read_token() returns NGX_OK, NGX_ERROR,
- * NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE
+ * ngx_conf_read_token() may return
+ * NGX_ERROR there is error
+ * NGX_OK the token terminated by ";" was found
+ * NGX_CONF_BLOCK_START the token terminated by "{" was found
+ * NGX_CONF_BLOCK_DONE the "}" was found
+ * NGX_CONF_FILE_DONE the configuration file is done
*/
#if 0
@@ -115,13 +119,16 @@ ngx_log_debug(cf->log, "token %d" _ rc);
break;
}
- if (rc != NGX_OK) {
+ if (rc != NGX_OK && rc != NGX_CONF_BLOCK_START) {
break;
}
if (cf->handler) {
- /* custom handler, i.e. used in http "types { ... }" directive */
+ /*
+ * the custom handler, i.e., that is used in the http's
+ * "types { ... }" directive
+ */
rv = (*cf->handler)(cf, NULL, cf->handler_conf);
if (rv == NGX_CONF_OK) {
@@ -182,6 +189,31 @@ ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data);
break;
}
+ if (!(cmd->type & NGX_CONF_BLOCK) && rc != NGX_OK)
+ {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "is not terminated by \";\"",
+ name->data,
+ cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ rc = NGX_ERROR;
+ break;
+ }
+
+ if ((cmd->type & NGX_CONF_BLOCK)
+ && rc != NGX_CONF_BLOCK_START)
+ {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "has not the opening \"{\"",
+ name->data,
+ cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ rc = NGX_ERROR;
+ break;
+ }
+
/* is the directive's argument count right ? */
if (cmd->type & NGX_CONF_ANY) {
@@ -396,10 +428,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
continue;
}
- if (ch == ';' || ch == '{') {
+ if (ch == ';') {
return NGX_OK;
}
+ if (ch == '{') {
+ return NGX_CONF_BLOCK_START;
+ }
+
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"unexpected '%c' in %s:%d",
ch, cf->conf_file->file.name.data,
@@ -427,6 +463,10 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
return NGX_ERROR;
}
+ if (ch == '{') {
+ return NGX_CONF_BLOCK_START;
+ }
+
return NGX_OK;
case '}':
@@ -538,10 +578,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
#endif
- if (ch == ';' || ch == '{') {
+ if (ch == ';') {
return NGX_OK;
}
+ if (ch == '{') {
+ return NGX_CONF_BLOCK_START;
+ }
+
found = 0;
}
}
@@ -575,6 +619,18 @@ ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name)
return NGX_OK;
}
+#if (NGX_WIN32)
+
+ if (name->len > 2
+ && name->data[1] == ':'
+ && ((name->data[0] >= 'a' && name->data[0] <= 'z')
+ || (name->data[0] >= 'A' && name->data[0] <= 'Z')))
+ {
+ return NGX_OK;
+ }
+
+#endif
+
old = *name;
name->len = cycle->root.len + old.len;
@@ -664,20 +720,22 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
void ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
char *fmt, ...)
{
- int len;
- char errstr[NGX_MAX_CONF_ERRSTR];
+ u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last;
va_list args;
+ last = errstr + NGX_MAX_CONF_ERRSTR;
+
va_start(args, fmt);
- len = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
+ buf = ngx_vsnprintf(errstr, last - errstr, fmt, args);
va_end(args);
+ *buf = '\0';
+
if (err) {
- len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
- " (%d: ", err);
- len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1);
- errstr[len++] = ')';
- errstr[len] = '\0';
+ buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err);
+ buf = ngx_strerror_r(err, buf, last - buf - 1);
+ *buf++ = ')';
+ *buf = '\0';
}
ngx_log_error(level, cf->log, 0, "%s in %s:%d",
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index 3a3db52b9..0e94056af 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -59,8 +59,9 @@
#define NGX_CONF_OK NULL
#define NGX_CONF_ERROR (char *) -1
-#define NGX_CONF_BLOCK_DONE 1
-#define NGX_CONF_FILE_DONE 2
+#define NGX_CONF_BLOCK_START 1
+#define NGX_CONF_BLOCK_DONE 2
+#define NGX_CONF_FILE_DONE 3
#define NGX_MODULE 0, 0
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index 3590fae7a..9faf00a2d 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -39,7 +39,7 @@
#endif
-#if !(WIN32)
+#if !(NGX_WIN32)
#define ngx_signal_helper(n) SIG##n
#define ngx_signal_value(n) ngx_signal_helper(n)
@@ -72,8 +72,6 @@ typedef int ngx_int_t;
typedef u_int ngx_uint_t;
typedef int ngx_flag_t;
#define NGX_INT_T_LEN sizeof("-2147483648") - 1
-#define NGX_INT_T_FMT "d"
-#define NGX_UINT_T_FMT "u"
#else
@@ -81,8 +79,6 @@ typedef long ngx_int_t;
typedef u_long ngx_uint_t;
typedef long ngx_flag_t;
#define NGX_INT_T_LEN sizeof("-9223372036854775808") - 1
-#define NGX_INT_T_FMT "lld"
-#define NGX_UINT_T_FMT "llu"
#endif
@@ -131,5 +127,12 @@ typedef long ngx_flag_t;
#define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN
*/
+#if ((__GNU__ == 2) && (__GNUC_MINOR__ < 8))
+#define NGX_MAX_UINT32_VALUE 0xffffffffLL
+#else
+#define NGX_MAX_UINT32_VALUE 0xffffffff
+#endif
+
+
#endif /* _NGX_CONFIG_H_INCLUDED_ */
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index 19f56292a..06fd85cde 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -30,28 +30,27 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
return NULL;
}
-#if (HAVE_SIN_LEN)
- addr_in->sin_len = sizeof(struct sockaddr_in);
-#endif
addr_in->sin_family = AF_INET;
addr_in->sin_addr.s_addr = addr;
addr_in->sin_port = htons(port);
- if (!(ls->addr_text.data = ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6))) {
+
+ ls->addr_text.data = ngx_palloc(cf->pool,
+ INET_ADDRSTRLEN - 1 + sizeof(":65535") - 1);
+ if (ls->addr_text.data == NULL) {
return NULL;
}
len = ngx_inet_ntop(AF_INET, &addr, ls->addr_text.data, INET_ADDRSTRLEN);
- ls->addr_text.len = ngx_snprintf((char *) ls->addr_text.data + len,
- 6, ":%d", port);
+
+ ls->addr_text.len = ngx_sprintf(ls->addr_text.data + len, ":%d", port)
+ - ls->addr_text.data;
+
ls->fd = (ngx_socket_t) -1;
ls->family = AF_INET;
ls->type = SOCK_STREAM;
ls->protocol = IPPROTO_IP;
-#if (WIN32)
- ls->flags = WSA_FLAG_OVERLAPPED;
-#endif
ls->sockaddr = (struct sockaddr *) addr_in;
ls->socklen = sizeof(struct sockaddr_in);
ls->addr = offsetof(struct sockaddr_in, sin_addr);
@@ -63,6 +62,7 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
{
+ size_t len;
ngx_uint_t i;
ngx_listening_t *ls;
struct sockaddr_in *addr_in;
@@ -95,20 +95,26 @@ ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
ls[i].ignore = 1;
continue;
}
+
ls[i].addr_text_max_len = INET_ADDRSTRLEN;
- ls[i].addr_text.data = ngx_palloc(cycle->pool, ls[i].addr_text_max_len);
+
+ ls[i].addr_text.data = ngx_palloc(cycle->pool, INET_ADDRSTRLEN - 1
+ + sizeof(":65535") - 1);
if (ls[i].addr_text.data == NULL) {
return NGX_ERROR;
}
ls[i].family = addr_in->sin_family;
- ls[i].addr_text.len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr,
- ls[i].addr_text.data,
- ls[i].addr_text_max_len);
- if (ls[i].addr_text.len == 0) {
+ len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr,
+ ls[i].addr_text.data, INET_ADDRSTRLEN);
+ if (len == 0) {
return NGX_ERROR;
}
+
+ ls[i].addr_text.len = ngx_sprintf(ls[i].addr_text.data + len, ":%d",
+ ntohs(addr_in->sin_port))
+ - ls[i].addr_text.data;
}
return NGX_OK;
@@ -157,16 +163,15 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
continue;
}
- s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol,
- ls[i].flags);
+ s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol);
if (s == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_socket_n " %s failed", ls[i].addr_text.data);
+ ngx_socket_n " %V failed", &ls[i].addr_text);
return NGX_ERROR;
}
-#if (WIN32)
+#if (NGX_WIN32)
/*
* Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number by 4.
@@ -182,8 +187,8 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
(const void *) &reuseaddr, sizeof(int)) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "setsockopt(SO_REUSEADDR) %s failed",
- ls[i].addr_text.data);
+ "setsockopt(SO_REUSEADDR) %V failed",
+ &ls[i].addr_text);
return NGX_ERROR;
}
@@ -192,8 +197,8 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (!(ngx_event_flags & NGX_USE_AIO_EVENT)) {
if (ngx_nonblocking(s) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_nonblocking_n " %s failed",
- ls[i].addr_text.data);
+ ngx_nonblocking_n " %V failed",
+ &ls[i].addr_text);
return NGX_ERROR;
}
}
@@ -202,8 +207,8 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (ls[i].nonblocking) {
if (ngx_nonblocking(s) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_nonblocking_n " %s failed",
- ls[i].addr_text.data);
+ ngx_nonblocking_n " %V failed",
+ &ls[i].addr_text);
return NGX_ERROR;
}
}
@@ -212,15 +217,15 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (bind(s, ls[i].sockaddr, ls[i].socklen) == -1) {
err = ngx_socket_errno;
ngx_log_error(NGX_LOG_EMERG, log, err,
- "bind() to %s failed", ls[i].addr_text.data);
+ "bind() to %V failed", &ls[i].addr_text);
if (err != NGX_EADDRINUSE)
return NGX_ERROR;
if (ngx_close_socket(s) == -1)
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_close_socket_n " %s failed",
- ls[i].addr_text.data);
+ ngx_close_socket_n " %V failed",
+ &ls[i].addr_text);
failed = 1;
continue;
@@ -228,7 +233,7 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (listen(s, ls[i].backlog) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "listen() to %s failed", ls[i].addr_text.data);
+ "listen() to %V failed", &ls[i].addr_text);
return NGX_ERROR;
}
@@ -273,7 +278,7 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
for (i = 0; i < cycle->listening.nelts; i++) {
fd = ls[i].fd;
-#if (WIN32)
+#if (NGX_WIN32)
/*
* Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number by 4.
@@ -296,8 +301,7 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
if (ngx_close_socket(ls[i].fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
- ngx_close_socket_n " %s failed",
- ls[i].addr_text.data);
+ ngx_close_socket_n " %V failed", &ls[i].addr_text);
}
cycle->connections[fd].fd = (ngx_socket_t) -1;
@@ -408,7 +412,7 @@ ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
}
if (err == NGX_ECONNRESET
-#if !(WIN32)
+#if !(NGX_WIN32)
|| err == NGX_EPIPE
#endif
|| err == NGX_ENOTCONN
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h
index 8e2ba3970..e2257ac6c 100644
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -24,7 +24,6 @@ typedef struct {
int family;
int type;
int protocol;
- int flags; /* Winsock2 flags */
void (*handler)(ngx_connection_t *c); /* handler of accepted
connection */
@@ -48,9 +47,6 @@ typedef struct {
unsigned inherited:1; /* inherited from previous process */
unsigned nonblocking_accept:1;
unsigned nonblocking:1;
-#if 0
- unsigned overlapped:1; /* Winsock2 overlapped */
-#endif
unsigned shared:1; /* shared between threads or processes */
#if (HAVE_DEFERRED_ACCEPT)
unsigned deferred_accept:1;
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index a1402f123..85d945809 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -9,6 +9,7 @@
#include <ngx_event.h>
+static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *s1, struct sockaddr *s2);
static void ngx_clean_old_cycles(ngx_event_t *ev);
@@ -195,7 +196,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
failed = 0;
-#if !(WIN32)
+#if !(NGX_WIN32)
if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) {
failed = 1;
}
@@ -204,6 +205,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (!failed) {
+ /* open the new files */
+
part = &cycle->open_files.part;
file = part->elts;
@@ -227,7 +230,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
- "log: %0X %d \"%s\"",
+ "log: %p %d \"%s\"",
&file[i], file[i].fd, file[i].name.data);
if (file[i].fd == NGX_INVALID_FILE) {
@@ -238,7 +241,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
break;
}
-#if (WIN32)
+#if (NGX_WIN32)
if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
ngx_file_append_mode_n " \"%s\" failed",
@@ -266,6 +269,9 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
if (!failed) {
+
+ /* handle the listening sockets */
+
if (old_cycle->listening.nelts) {
ls = old_cycle->listening.elts;
for (i = 0; i < old_cycle->listening.nelts; i++) {
@@ -274,16 +280,17 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
nls = cycle->listening.elts;
for (n = 0; n < cycle->listening.nelts; n++) {
+
for (i = 0; i < old_cycle->listening.nelts; i++) {
if (ls[i].ignore) {
continue;
}
- if (ngx_memcmp(nls[n].sockaddr,
- ls[i].sockaddr, ls[i].socklen) == 0)
+ if (ngx_cmp_sockaddr(nls[n].sockaddr, ls[i].sockaddr)
+ == NGX_OK)
{
fd = ls[i].fd;
-#if (WIN32)
+#if (NGX_WIN32)
/*
* Winsock assignes a socket number divisible by 4 so
* to find a connection we divide a socket number by 4.
@@ -294,10 +301,10 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (fd >= (ngx_socket_t) cycle->connection_n) {
ngx_log_error(NGX_LOG_EMERG, log, 0,
"%d connections is not enough to hold "
- "an open listening socket on %s, "
+ "an open listening socket on %V, "
"required at least %d connections",
cycle->connection_n,
- ls[i].addr_text.data, fd);
+ &ls[i].addr_text, fd);
failed = 1;
break;
}
@@ -372,8 +379,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (ngx_close_socket(ls[i].fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_close_socket_n " %s failed",
- ls[i].addr_text.data);
+ ngx_close_socket_n " %V failed",
+ &ls[i].addr_text);
}
}
@@ -384,12 +391,12 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
/* commit the new cycle configuration */
-#if !(WIN32)
+#if !(NGX_WIN32)
if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
- "dup2: %0X %d \"%s\"",
+ "dup2: %p %d \"%s\"",
cycle->log->file,
cycle->log->file->fd, cycle->log->file->name.data);
@@ -426,8 +433,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (ngx_close_socket(ls[i].fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_close_socket_n " %s failed",
- ls[i].addr_text.data);
+ ngx_close_socket_n " %V failed",
+ &ls[i].addr_text);
}
}
@@ -512,13 +519,38 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
-#if !(WIN32)
+static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *s1, struct sockaddr *s2)
+{
+ struct sockaddr_in *sin1, *sin2;
+
+ /* AF_INET only */
+
+ if (s1->sa_family != AF_INET || s2->sa_family != AF_INET) {
+ return NGX_DECLINED;
+ }
+
+ sin1 = (struct sockaddr_in *) s1;
+ sin2 = (struct sockaddr_in *) s2;
+
+ if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) {
+ return NGX_DECLINED;
+ }
+
+ if (sin1->sin_port != sin2->sin_port) {
+ return NGX_DECLINED;
+ }
+
+ return NGX_OK;
+}
+
+
+#if !(NGX_WIN32)
ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
{
ngx_uint_t trunc;
size_t len;
- u_char *name, pid[NGX_INT64_LEN + 1];
+ u_char *name, pid[NGX_INT64_LEN];
ngx_file_t file;
ngx_core_conf_t *ccf, *old_ccf;
@@ -548,8 +580,6 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
}
}
- len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid);
-
ngx_memzero(&file, sizeof(ngx_file_t));
file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid;
file.log = cycle->log;
@@ -566,6 +596,8 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
}
if (!ngx_test_config) {
+ len = ngx_sprintf(pid, "%P", ngx_pid) - pid;
+
if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) {
return NGX_ERROR;
}
@@ -615,7 +647,7 @@ void 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 !(WIN32)
+#if !(NGX_WIN32)
ngx_file_info_t fi;
#endif
@@ -649,7 +681,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
continue;
}
-#if (WIN32)
+#if (NGX_WIN32)
if (ngx_file_append_mode(fd) == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
ngx_file_append_mode_n " \"%s\" failed",
@@ -730,7 +762,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
file[i].fd = fd;
}
-#if !(WIN32)
+#if !(NGX_WIN32)
if (cycle->log->file->fd != STDERR_FILENO) {
if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index 45b7b23b0..2baf82904 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -12,6 +12,10 @@
#include <ngx_core.h>
+#define NGX_DEBUG_POINTS_STOP 1
+#define NGX_DEBUG_POINTS_ABORT 2
+
+
struct ngx_cycle_s {
void ****conf_ctx;
ngx_pool_t *pool;
@@ -40,6 +44,7 @@ typedef struct {
ngx_flag_t master;
ngx_int_t worker_processes;
+ ngx_int_t debug_points;
ngx_uid_t user;
ngx_gid_t group;
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index c7ee51372..8e1edbd1f 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -55,9 +55,8 @@ int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
num = ngx_next_temp_number(0);
for ( ;; ) {
- ngx_snprintf((char *)
- (file->name.data + path->name.len + 1 + path->len),
- 11, "%010u", num);
+ ngx_sprintf(file->name.data + path->name.len + 1 + path->len,
+ "%010ud%Z", num);
ngx_create_hashed_filename(file, path);
@@ -83,7 +82,7 @@ int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
if ((path->level[0] == 0)
|| (err != NGX_ENOENT
-#if (WIN32)
+#if (NGX_WIN32)
&& err != NGX_ENOTDIR
#endif
)) {
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
index bf8a788ea..5cabb49b5 100644
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -9,6 +9,17 @@
#include <ngx_core.h>
+/*
+ * ngx_sock_ntop() and ngx_inet_ntop() may be implemented as
+ * "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])",
+ * however, they were implemented long before the ngx_sprintf() appeared
+ * and they are faster by 1.5-2.5 times, so it is worth to keep them.
+ *
+ * By the way, the implementation using ngx_sprintf() is faster by 2.5-3 times
+ * than using FreeBSD libc's snrpintf().
+ */
+
+
ngx_inline static size_t ngx_sprint_uchar(u_char *text, u_char c, size_t len)
{
size_t n;
@@ -105,15 +116,8 @@ size_t ngx_sock_ntop(int family, struct sockaddr *addr, u_char *text,
text[n] = '\0';
return n;
-
-#if 0
- return ngx_snprintf((char *) text,
- len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len,
- "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
-#endif
}
-
size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len)
{
u_char *p;
@@ -163,12 +167,6 @@ size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len)
text[n] = '\0';
return n;
-
-#if 0
- return ngx_snprintf((char *) text,
- len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len,
- "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
-#endif
}
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index f1c0e97f3..521ba7aa3 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -8,7 +8,7 @@
#include <ngx_core.h>
-static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len);
+static void ngx_log_write(ngx_log_t *log, u_char *errstr, size_t len);
static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@@ -38,7 +38,7 @@ ngx_module_t ngx_errlog_module = {
ngx_errlog_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -65,121 +65,104 @@ void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, va_list args)
#endif
{
- char errstr[MAX_ERROR_STR];
- size_t len, max;
#if (NGX_HAVE_VARIADIC_MACROS)
- va_list args;
+ va_list args;
#endif
+ u_char errstr[NGX_MAX_ERROR_STR], *p, *last;
if (log->file->fd == NGX_INVALID_FILE) {
return;
}
+ last = errstr + NGX_MAX_ERROR_STR;
+
ngx_memcpy(errstr, ngx_cached_err_log_time.data,
ngx_cached_err_log_time.len);
-#if (WIN32)
- max = MAX_ERROR_STR - 2;
-#else
- max = MAX_ERROR_STR - 1;
-#endif
-
- len = ngx_cached_err_log_time.len;
+ p = errstr + ngx_cached_err_log_time.len;
- len += ngx_snprintf(errstr + len, max - len, " [%s] ", err_levels[level]);
+ p = ngx_sprintf(p, " [%s] ", err_levels[level]);
/* pid#tid */
- len += ngx_snprintf(errstr + len, max - len,
- PID_T_FMT "#" TID_T_FMT ": ", ngx_log_pid, ngx_log_tid);
+ p = ngx_sprintf(p, "%P#" NGX_TID_T_FMT ": ", ngx_log_pid, ngx_log_tid);
if (log->data && *(int *) log->data != -1) {
- len += ngx_snprintf(errstr + len, max - len,
- "*%u ", *(u_int *) log->data);
+ p = ngx_sprintf(p, "*%ud ", *(u_int *) log->data);
}
#if (NGX_HAVE_VARIADIC_MACROS)
va_start(args, fmt);
- len += ngx_vsnprintf(errstr + len, max - len, fmt, args);
+ p = ngx_vsnprintf(p, last - p, fmt, args);
va_end(args);
#else
- len += ngx_vsnprintf(errstr + len, max - len, fmt, args);
+ p = ngx_vsnprintf(p, last - p, fmt, args);
#endif
if (err) {
- if (len > max - 50) {
+ if (p > last - 50) {
/* leave a space for an error code */
- len = max - 50;
- errstr[len++] = '.';
- errstr[len++] = '.';
- errstr[len++] = '.';
+ p = last - 50;
+ *p++ = '.';
+ *p++ = '.';
+ *p++ = '.';
}
-#if (WIN32)
+#if (NGX_WIN32)
+
if ((unsigned) err >= 0x80000000) {
- len += ngx_snprintf(errstr + len, max - len, " (%X: ", err);
- } else {
- len += ngx_snprintf(errstr + len, max - len, " (%d: ", err);
- }
-#else
- len += ngx_snprintf(errstr + len, max - len, " (%d: ", err);
-#endif
+ p = ngx_snprintf(p, last - p, " (%Xd: ", err);
- if (len >= max) {
- ngx_log_write(log, errstr, max);
- return;
+ } else {
+ p = ngx_snprintf(p, last - p, " (%d: ", err);
}
- len += ngx_strerror_r(err, errstr + len, max - len);
+#else
- if (len >= max) {
- ngx_log_write(log, errstr, max);
- return;
- }
+ p = ngx_snprintf(p, last - p, " (%d: ", err);
- errstr[len++] = ')';
+#endif
- if (len >= max) {
- ngx_log_write(log, errstr, max);
- return;
- }
+ p = ngx_strerror_r(err, p, last - p);
- } else {
- if (len >= max) {
- ngx_log_write(log, errstr, max);
- return;
+ if (p < last) {
+ *p++ = ')';
}
}
if (level != NGX_LOG_DEBUG && log->handler) {
- len += log->handler(log->data, errstr + len, max - len);
-
- if (len >= max) {
- len = max;
- }
+ p = log->handler(log->data, p, last - p);
}
- ngx_log_write(log, errstr, len);
+ ngx_log_write(log, errstr, p - errstr);
}
-static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len)
+static void ngx_log_write(ngx_log_t *log, u_char *errstr, size_t len)
{
-#if (WIN32)
+#if (NGX_WIN32)
u_long written;
+ if (len >= NGX_MAX_ERROR_STR - 1) {
+ len = NGX_MAX_ERROR_STR - 2;
+ }
+
errstr[len++] = CR;
errstr[len++] = LF;
WriteFile(log->file->fd, errstr, len, &written, NULL);
#else
+ if (len == NGX_MAX_ERROR_STR) {
+ len--;
+ }
+
errstr[len++] = LF;
write(log->file->fd, errstr, len);
@@ -192,7 +175,7 @@ static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len)
void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...)
{
- va_list args;
+ va_list args;
if (log->log_level >= level) {
va_start(args, fmt);
@@ -204,108 +187,50 @@ void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...)
{
- va_list args;
+ va_list args;
va_start(args, fmt);
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, args);
va_end(args);
}
-
-void ngx_assert_core(ngx_log_t *log, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- ngx_log_error_core(NGX_LOG_ALERT, log, 0, fmt, args);
- va_end(args);
-}
-
#endif
-ngx_log_t *ngx_log_init_stderr()
+ngx_log_t *ngx_log_init()
{
-#if (WIN32)
-
- ngx_stderr_fileno = GetStdHandle(STD_ERROR_HANDLE);
- ngx_stderr.fd = ngx_stderr_fileno;
-
- if (ngx_stderr_fileno == NGX_INVALID_FILE) {
-
- /* TODO: where can we log error ? */
-
- return NULL;
-
- } else if (ngx_stderr_fileno == NULL) {
-
- /* there are no associated standard handles */
-
- /* TODO: where can we can log possible errors ? */
-
- ngx_stderr.fd = NGX_INVALID_FILE;
- }
-
-#else
-
- ngx_stderr.fd = STDERR_FILENO;
-
-#endif
-
ngx_log.file = &ngx_stderr;
ngx_log.log_level = NGX_LOG_NOTICE;
- return &ngx_log;
-}
-
+#if (NGX_WIN32)
-#if 0
+ ngx_stderr.fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR,
+ NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
-ngx_int_t ngx_log_init_error_log()
-{
- ngx_fd_t fd;
-
-#ifdef NGX_ERROR_LOG_PATH
-
- fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR,
- NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
-
- if (fd == NGX_INVALID_FILE) {
- ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno,
- ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed");
- return NGX_ERROR;
+ if (ngx_stderr.fd == NGX_INVALID_FILE) {
+ ngx_message_box("nginx", MB_OK, ngx_errno,
+ "Could not open error log file: "
+ ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed");
+ return NULL;
}
-#if (WIN32)
-
- if (ngx_file_append_mode(fd) == NGX_ERROR) {
- ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno,
- ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH
- "\" failed");
- return NGX_ERROR;
+ if (ngx_file_append_mode(ngx_stderr.fd) == NGX_ERROR) {
+ ngx_message_box("nginx", MB_OK, ngx_errno,
+ "Could not open error log file: "
+ ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH
+ "\" failed");
+ return NULL;
}
#else
- if (dup2(fd, STDERR_FILENO) == NGX_ERROR) {
- ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno,
- "dup2(STDERR) failed");
- return NGX_ERROR;
- }
-
-#endif
-
-#else /* no NGX_ERROR_LOG_PATH */
-
- ngx_log.log_level = NGX_LOG_INFO;
+ ngx_stderr.fd = STDERR_FILENO;
#endif
- return NGX_OK;
+ return &ngx_log;
}
-#endif
-
ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args)
{
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index 5ddd8fc65..c54c18723 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -40,7 +40,7 @@
#define NGX_LOG_DEBUG_ALL 0x7ffffff0
-typedef size_t (*ngx_log_handler_pt) (void *ctx, char *buf, size_t len);
+typedef u_char *(*ngx_log_handler_pt) (void *ctx, u_char *buf, size_t len);
struct ngx_log_s {
@@ -50,7 +50,8 @@ struct ngx_log_s {
ngx_log_handler_pt handler;
};
-#define MAX_ERROR_STR 2048
+
+#define NGX_MAX_ERROR_STR 2048
/*********************************/
@@ -88,7 +89,6 @@ void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, va_list args);
void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...);
-void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
#endif /* VARIADIC MACROS */
@@ -195,10 +195,7 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
#define ngx_log_alloc_log(pool, log) ngx_palloc(pool, log, sizeof(ngx_log_t))
#define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t))
-ngx_log_t *ngx_log_init_stderr();
-#if 0
-ngx_int_t ngx_log_init_error_log();
-#endif
+ngx_log_t *ngx_log_init();
ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args);
char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
index 23b7846b9..30dda35be 100644
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -162,7 +162,11 @@ ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in)
ctx->in = ctx->in->next;
}
- ngx_alloc_link_and_set_buf(cl, ctx->buf, ctx->pool, NGX_ERROR);
+ if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ return NGX_ERROR;
+ }
+ cl->buf = ctx->buf;
+ cl->next = NULL;
*last_out = cl;
last_out = &cl->next;
ctx->buf = NULL;
@@ -266,7 +270,7 @@ static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src,
if ((size_t) n != size) {
ngx_log_error(NGX_LOG_ALERT, src->file->log, 0,
- ngx_read_file_n " reads only %d of %d from file",
+ ngx_read_file_n " reads only %z of %uz from file",
n, size);
if (n == 0) {
return NGX_ERROR;
@@ -306,20 +310,24 @@ ngx_int_t ngx_chain_writer(void *data, ngx_chain_t *in)
for (/* void */; in; in = in->next) {
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
- "WRITER buf: %d", ngx_buf_size(in->buf));
+ "chain writer buf size: %uz", ngx_buf_size(in->buf));
- ngx_alloc_link_and_set_buf(cl, in->buf, ctx->pool, NGX_ERROR);
+ if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ return NGX_ERROR;
+ }
+ cl->buf = in->buf;
+ cl->next = NULL;
*ctx->last = cl;
ctx->last = &cl->next;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
- "WRITER0: %X", ctx->out);
+ "chain writer in: %p", ctx->out);
ctx->out = ngx_send_chain(ctx->connection, ctx->out, ctx->limit);
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
- "WRITER1: %X", ctx->out);
+ "chain writer out: %p", ctx->out);
if (ctx->out == NGX_CHAIN_ERROR) {
return NGX_ERROR;
diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c
index e41e971f9..ed13de513 100644
--- a/src/core/ngx_palloc.c
+++ b/src/core/ngx_palloc.c
@@ -33,8 +33,7 @@ void ngx_destroy_pool(ngx_pool_t *pool)
for (l = pool->large; l; l = l->next) {
- ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
- "free: " PTR_FMT, l->alloc);
+ ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc);
if (l->alloc) {
free(l->alloc);
@@ -50,8 +49,7 @@ void ngx_destroy_pool(ngx_pool_t *pool)
for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
- "free: " PTR_FMT ", unused: " SIZE_T_FMT,
- p, p->end - p->last);
+ "free: %p, unused: %uz", p, p->end - p->last);
if (n == NULL) {
break;
@@ -164,7 +162,7 @@ ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p)
for (l = pool->large; l; l = l->next) {
if (p == l->alloc) {
ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
- "free: " PTR_FMT, l->alloc);
+ "free: %p", l->alloc);
free(l->alloc);
l->alloc = NULL;
diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c
index 27dad8d06..35b489229 100644
--- a/src/core/ngx_regex.c
+++ b/src/core/ngx_regex.c
@@ -53,11 +53,11 @@ ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options,
if (re == NULL) {
if ((size_t) erroff == pattern->len) {
- ngx_snprintf((char *) err->data, err->len - 1,
+ ngx_snprintf(err->data, err->len - 1,
"pcre_compile() failed: %s in \"%s\"",
errstr, pattern->data);
} else {
- ngx_snprintf((char *) err->data, err->len - 1,
+ ngx_snprintf(err->data, err->len - 1,
"pcre_compile() failed: %s in \"%s\" at \"%s\"",
errstr, pattern->data, pattern->data + erroff);
}
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 390ca431d..94eadfbe2 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -30,42 +30,92 @@ u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n)
/*
* supported formats:
- * %[0][width]O off_t
- * %[0][width]T time_t
- * %[0][width]S ssize_t
- * %[0][width]uS size_t
- * %[0][width]uxS size_t in hex
- * %[0][width]l long
- * %[0][width]d int
- * %[0][width]i ngx_int_t
- * %[0][width]ui ngx_uint_t
- * %[0][width]uxi ngx_uint_t in hex
- * %s null-terminated string
- * %c char
- * %% %
+ * %[0][width]O off_t
+ * %[0][width]T time_t
+ * %[0][width][u][x|X]z ssize_t/size_t
+ * %[0][width][u][x|X]d int/u_int
+ * %[0][width][u][x|X]l long
+ * %[0][width|m][u][x|X]i ngx_int_t/ngx_uint_t
+ * %[0][width][u][x|X]D int32_t/uint32_t
+ * %[0][width][u][x|X]L int64_t/uint64_t
+ * %P ngx_pid_t
+ * %r rlim_t
+ * %p pointer
+ * %V pointer to ngx_str_t
+ * %s null-terminated string
+ * %Z '\0'
+ * %c char
+ * %% %
*
+ * TODO:
+ * %M ngx_msec_t
+ * %A ngx_atomic_t
+ *
+ * reserved:
+ * %t ptrdiff_t
+ * %S null-teminated wchar string
+ * %C wchar
*/
-u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
+
+u_char *ngx_sprintf(u_char *buf, const char *fmt, ...)
{
- u_char *p, c, temp[NGX_MAX_INT_LEN];
- int d;
- long l;
- off_t offset;
- size_t size, len;
- ssize_t ssize;
- time_t sec;
- va_list arg;
- ngx_int_t i;
- ngx_uint_t ui, zero, width, sign, hexadecimal;
- static u_char hex[] = "0123456789abcdef";
+ u_char *p;
+ va_list args;
+
+ va_start(args, fmt);
+ p = ngx_vsnprintf(buf, /* STUB */ 65536, fmt, args);
+ va_end(args);
+
+ return p;
+}
+
+
+u_char *ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)
+{
+ u_char *p;
+ va_list args;
+
+ va_start(args, fmt);
+ p = ngx_vsnprintf(buf, max, fmt, args);
+ va_end(args);
+
+ return p;
+}
+
+
+u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)
+{
+ u_char *p, zero, *last, temp[NGX_MAX_INT_LEN];
+ int d;
+ size_t len;
+ uint32_t ui32;
+ int64_t i64;
+ uint64_t ui64;
+ ngx_str_t *s;
+ ngx_uint_t width, sign, hexadecimal;
+ static u_char hex[] = "0123456789abcdef";
+ static u_char HEX[] = "0123456789ABCDEF";
+
+ if (max == 0) {
+ return buf;
+ }
- va_start(arg, fmt);
+ last = buf + max;
+
+ while (*fmt && buf < last) {
+
+ /*
+ * "buf < last" means that we could copy at least one character:
+ * the plain character, "%%", "%c", and minus without the checking
+ */
- while (*fmt) {
if (*fmt == '%') {
- zero = (*++fmt == '0') ? 1 : 0;
+ i64 = 0;
+ ui64 = 0;
+
+ zero = (u_char) ((*++fmt == '0') ? '0' : ' ');
width = 0;
sign = 1;
hexadecimal = 0;
@@ -85,8 +135,15 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
fmt++;
continue;
+ case 'X':
+ hexadecimal = 2;
+ sign = 0;
+ fmt++;
+ continue;
+
case 'x':
hexadecimal = 1;
+ sign = 0;
fmt++;
continue;
@@ -100,133 +157,112 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
switch (*fmt) {
- case 'O':
- offset = va_arg(arg, off_t);
+ case 'V':
+ s = va_arg(args, ngx_str_t *);
- if (offset < 0) {
- *buf++ = '-';
- offset = -offset;
- }
-
- do {
- *--p = (u_char) (offset % 10 + '0');
- } while (offset /= 10);
+ len = (buf + s->len < last) ? s->len : (size_t) (last - buf);
+ buf = ngx_cpymem(buf, s->data, len);
+ fmt++;
- break;
+ continue;
- case 'T':
- sec = va_arg(arg, time_t);
+ case 's':
+ p = va_arg(args, u_char *);
- if (sec < 0) {
- *buf++ = '-';
- sec = -sec;
+ while (*p && buf < last) {
+ *buf++ = *p++;
}
+ fmt++;
- do {
- *--p = (u_char) (sec % 10 + '0');
- } while (sec /= 10);
+ continue;
+ case 'O':
+ i64 = (int64_t) va_arg(args, off_t);
+ sign = 1;
break;
- case 'S':
- if (sign) {
- ssize = va_arg(arg, ssize_t);
-
- if (ssize < 0) {
- *buf++ = '-';
- size = (size_t) -ssize;
+ case 'P':
+ i64 = (int64_t) va_arg(args, ngx_pid_t);
+ sign = 1;
+ break;
- } else {
- size = (size_t) ssize;
- }
+ case 'T':
+ i64 = (int64_t) va_arg(args, time_t);
+ sign = 1;
+ break;
+ case 'z':
+ if (sign) {
+ i64 = (int64_t) va_arg(args, ssize_t);
} else {
- size = va_arg(arg, size_t);
+ ui64 = (uint64_t) va_arg(args, size_t);
}
+ break;
- if (hexadecimal) {
- do {
- *--p = hex[size & 0xf];
- } while (size >>= 4);
-
+ case 'i':
+ if (sign) {
+ i64 = (int64_t) va_arg(args, ngx_int_t);
} else {
- do {
- *--p = (u_char) (size % 10 + '0');
- } while (size /= 10);
+ ui64 = (uint64_t) va_arg(args, ngx_uint_t);
}
-
break;
- case 'l':
- l = va_arg(arg, long);
-
- if (l < 0) {
- *buf++ = '-';
- l = -l;
+ case 'd':
+ if (sign) {
+ i64 = (int64_t) va_arg(args, int);
+ } else {
+ ui64 = (uint64_t) va_arg(args, u_int);
}
-
- do {
- *--p = (u_char) (l % 10 + '0');
- } while (l /= 10);
-
break;
- case 'd':
- d = va_arg(arg, int);
-
- if (d < 0) {
- *buf++ = '-';
- d = -d;
+ case 'l':
+ if (sign) {
+ i64 = (int64_t) va_arg(args, long);
+ } else {
+ ui64 = (uint64_t) va_arg(args, u_long);
}
-
- do {
- *--p = (u_char) (d % 10 + '0');
- } while (d /= 10);
-
break;
- case 'i':
+ case 'D':
if (sign) {
- i = va_arg(arg, ngx_int_t);
-
- if (i < 0) {
- *buf++ = '-';
- ui = (ngx_uint_t) -i;
-
- } else {
- ui = (ngx_uint_t) i;
- }
-
+ i64 = (int64_t) va_arg(args, int32_t);
} else {
- ui = va_arg(arg, ngx_uint_t);
+ ui64 = (uint64_t) va_arg(args, uint32_t);
}
+ break;
- if (hexadecimal) {
- do {
- *--p = hex[ui & 0xf];
- } while (ui >>= 4);
-
+ case 'L':
+ if (sign) {
+ i64 = va_arg(args, int64_t);
} else {
- do {
- *--p = (u_char) (ui % 10 + '0');
- } while (ui /= 10);
+ ui64 = va_arg(args, uint64_t);
}
-
break;
- case 's':
- p = va_arg(arg, u_char *);
+#if !(NGX_WIN32)
+ case 'r':
+ i64 = (int64_t) va_arg(args, rlim_t);
+ sign = 1;
+ break;
+#endif
+
+ case 'p':
+ ui64 = (uintptr_t) va_arg(args, void *);
+ hexadecimal = 2;
+ sign = 0;
+ zero = '0';
+ width = 8;
+ break;
- while (*p) {
- *buf++ = *p++;
- }
+ case 'c':
+ d = va_arg(args, int);
+ *buf++ = (u_char) (d & 0xff);
fmt++;
continue;
- case 'c':
- d = va_arg(arg, int);
- *buf++ = (u_char) (d & 0xff);
+ case 'Z':
+ *buf++ = '\0';
fmt++;
continue;
@@ -243,15 +279,71 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
continue;
}
+ if (sign) {
+ if (i64 < 0) {
+ *buf++ = '-';
+ ui64 = (uint64_t) -i64;
+
+ } else {
+ ui64 = (uint64_t) i64;
+ }
+ }
+
+ if (hexadecimal == 1) {
+ do {
+
+ /* the "(uint32_t)" cast disables the BCC's warning */
+ *--p = hex[(uint32_t) (ui64 & 0xf)];
+
+ } while (ui64 >>= 4);
+
+ } else if (hexadecimal == 2) {
+ do {
+
+ /* the "(uint32_t)" cast disables the BCC's warning */
+ *--p = HEX[(uint32_t) (ui64 & 0xf)];
+
+ } while (ui64 >>= 4);
+
+ } else if (ui64 <= NGX_MAX_UINT32_VALUE) {
+
+ /*
+ * To divide 64-bit number and to find the remainder
+ * on the x86 platform gcc and icc call the libc functions
+ * [u]divdi3() and [u]moddi3(), they call another function
+ * in return. On FreeBSD it is the qdivrem() function,
+ * its source code is about 170 lines of the code.
+ * The glibc counterpart is about 150 lines of the code.
+ *
+ * For 32-bit numbers gcc and icc use the inlined
+ * multiplication and shifts. For example, unsigned
+ * "i32 / 10" is compiled to "(i32 * 0xCCCCCCCD) >> 35".
+ */
+
+ ui32 = (uint32_t) ui64;
+
+ do {
+ *--p = (u_char) (ui32 % 10 + '0');
+ } while (ui32 /= 10);
+
+ } else {
+ do {
+ *--p = (u_char) (ui64 % 10 + '0');
+ } while (ui64 /= 10);
+ }
+
len = (temp + NGX_MAX_INT_LEN) - p;
- c = (u_char) (zero ? '0' : ' ');
+ while (len++ < width && buf < last) {
+ *buf++ = zero;
+ }
- while (len++ < width) {
- *buf++ = c;
+ len = (temp + NGX_MAX_INT_LEN) - p;
+ if (buf + len > last) {
+ len = last - buf;
}
- buf = ngx_cpymem(buf, p, ((temp + NGX_MAX_INT_LEN) - p));
+ buf = ngx_cpymem(buf, p, len);
fmt++;
@@ -260,10 +352,6 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
}
}
- va_end(arg);
-
- *buf = '\0';
-
return buf;
}
@@ -505,12 +593,14 @@ ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src)
}
-ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size)
+ngx_uint_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
+ ngx_uint_t type)
{
- ngx_int_t n;
- ngx_uint_t i;
+ ngx_uint_t i, n;
+ uint32_t *escape;
static u_char hex[] = "0123456789abcdef";
- static uint32_t escape[] =
+
+ static uint32_t uri[] =
{ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
@@ -527,6 +617,31 @@ ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size)
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
+ static uint32_t html[] =
+ { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
+ 0x80000021, /* 0000 0000 0000 0000 0000 0000 1010 0101 */
+
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
+
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
+
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
+
+
+ if (type == NGX_ESCAPE_HTML) {
+ escape = html;
+
+ } else {
+ escape = uri;
+ }
+
if (dst == NULL) {
/* find the number of the characters to be escaped */
@@ -555,5 +670,5 @@ ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size)
}
}
- return NGX_OK;
+ return 0;
}
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index d7caaaf3d..51e0fd027 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -22,16 +22,13 @@ typedef struct {
#define ngx_null_string { 0, NULL }
-#if (WIN32)
+#if (NGX_WIN32)
#define ngx_strncasecmp(s1, s2, n) \
strnicmp((const char *) s1, (const char *) s2, n)
#define ngx_strcasecmp(s1, s2) \
stricmp((const char *) s1, (const char *) s2)
-#define ngx_snprintf _snprintf
-#define ngx_vsnprintf _vsnprintf
-
#else
#define ngx_strncasecmp(s1, s2, n) \
@@ -39,21 +36,20 @@ typedef struct {
#define ngx_strcasecmp(s1, s2) \
strcasecmp((const char *) s1, (const char *) s2)
-#define ngx_snprintf snprintf
-#define ngx_vsnprintf vsnprintf
-
#endif
-#define ngx_strncmp(s1, s2, n) \
- strncmp((const char *) s1, (const char *) s2, n)
+#define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n)
+
/* msvc and icc compile strcmp() to inline loop */
#define ngx_strcmp(s1, s2) strcmp((const char *) s1, (const char *) s2)
+
#define ngx_strstr(s1, s2) strstr((const char *) s1, (const char *) s2)
#define ngx_strlen(s) strlen((const char *) s)
+
/*
* msvc and icc compile memset() to the inline "rep stos"
* while ZeroMemory() and bzero() are the calls.
@@ -62,15 +58,20 @@ typedef struct {
#define ngx_memzero(buf, n) memset(buf, 0, n)
#define ngx_memset(buf, c, n) memset(buf, c, n)
+
/* msvc and icc compile memcpy() to the inline "rep movs" */
#define ngx_memcpy(dst, src, n) memcpy(dst, src, n)
#define ngx_cpymem(dst, src, n) ((u_char *) memcpy(dst, src, n)) + n
+
/* msvc and icc compile memcmp() to the inline loop */
#define ngx_memcmp memcmp
+
u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n);
-u_char *ngx_sprintf(u_char *buf, char *fmt, ...);
+u_char *ngx_sprintf(u_char *buf, const char *fmt, ...);
+u_char *ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...);
+u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args);
ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n);
ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
@@ -86,7 +87,13 @@ void ngx_md5_text(u_char *text, u_char *md5);
void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src);
ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src);
-ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size);
+
+
+#define NGX_ESCAPE_URI 0
+#define NGX_ESCAPE_HTML 1
+
+ngx_uint_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
+ ngx_uint_t type);
#define ngx_qsort qsort
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index 40dbbdbaf..f06d64476 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -94,7 +94,7 @@ void ngx_time_init()
ngx_old_elapsed_msec = 0;
ngx_elapsed_msec = 0;
-#if !(WIN32)
+#if !(NGX_WIN32)
tzset();
#endif
@@ -150,15 +150,14 @@ void ngx_time_update(time_t s)
p = cached_http_time[slot];
- ngx_snprintf((char *) p, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"),
- "%s, %02d %s %4d %02d:%02d:%02d GMT",
- week[ngx_cached_gmtime.ngx_tm_wday],
- ngx_cached_gmtime.ngx_tm_mday,
- months[ngx_cached_gmtime.ngx_tm_mon - 1],
- ngx_cached_gmtime.ngx_tm_year,
- ngx_cached_gmtime.ngx_tm_hour,
- ngx_cached_gmtime.ngx_tm_min,
- ngx_cached_gmtime.ngx_tm_sec);
+ ngx_sprintf(p, "%s, %02d %s %4d %02d:%02d:%02d GMT",
+ week[ngx_cached_gmtime.ngx_tm_wday],
+ ngx_cached_gmtime.ngx_tm_mday,
+ months[ngx_cached_gmtime.ngx_tm_mon - 1],
+ ngx_cached_gmtime.ngx_tm_year,
+ ngx_cached_gmtime.ngx_tm_hour,
+ ngx_cached_gmtime.ngx_tm_min,
+ ngx_cached_gmtime.ngx_tm_sec);
ngx_cached_http_time.data = p;
@@ -183,24 +182,22 @@ void ngx_time_update(time_t s)
p = cached_err_log_time[slot];
- ngx_snprintf((char *) p, sizeof("1970/09/28 12:00:00"),
- "%4d/%02d/%02d %02d:%02d:%02d",
- tm.ngx_tm_year, tm.ngx_tm_mon,
- tm.ngx_tm_mday, tm.ngx_tm_hour,
- tm.ngx_tm_min, tm.ngx_tm_sec);
+ ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d",
+ tm.ngx_tm_year, tm.ngx_tm_mon,
+ tm.ngx_tm_mday, tm.ngx_tm_hour,
+ tm.ngx_tm_min, tm.ngx_tm_sec);
ngx_cached_err_log_time.data = p;
p = cached_http_log_time[slot];
- ngx_snprintf((char *) p, sizeof("28/Sep/1970:12:00:00 +0600"),
- "%02d/%s/%d:%02d:%02d:%02d %c%02d%02d",
- tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1],
- tm.ngx_tm_year, tm.ngx_tm_hour,
- tm.ngx_tm_min, tm.ngx_tm_sec,
- ngx_gmtoff < 0 ? '-' : '+',
- abs(ngx_gmtoff / 60), abs(ngx_gmtoff % 60));
+ ngx_sprintf(p, "%02d/%s/%d:%02d:%02d:%02d %c%02d%02d",
+ tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1],
+ tm.ngx_tm_year, tm.ngx_tm_hour,
+ tm.ngx_tm_min, tm.ngx_tm_sec,
+ ngx_gmtoff < 0 ? '-' : '+',
+ abs(ngx_gmtoff / 60), abs(ngx_gmtoff % 60));
ngx_cached_http_log_time.data = p;
@@ -213,9 +210,6 @@ void ngx_time_update(time_t s)
u_char *ngx_http_time(u_char *buf, time_t t)
-#if 0
-size_t ngx_http_time(u_char *buf, time_t t)
-#endif
{
ngx_tm_t tm;
@@ -229,25 +223,10 @@ size_t ngx_http_time(u_char *buf, time_t t)
tm.ngx_tm_hour,
tm.ngx_tm_min,
tm.ngx_tm_sec);
-
-#if 0
- return ngx_snprintf((char *) buf, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"),
- "%s, %02d %s %4d %02d:%02d:%02d GMT",
- week[tm.ngx_tm_wday],
- tm.ngx_tm_mday,
- months[tm.ngx_tm_mon - 1],
- tm.ngx_tm_year,
- tm.ngx_tm_hour,
- tm.ngx_tm_min,
- tm.ngx_tm_sec);
-#endif
}
u_char *ngx_http_cookie_time(u_char *buf, time_t t)
-#if 0
-size_t ngx_http_cookie_time(u_char *buf, time_t t)
-#endif
{
ngx_tm_t tm;
@@ -270,32 +249,6 @@ size_t ngx_http_cookie_time(u_char *buf, time_t t)
tm.ngx_tm_hour,
tm.ngx_tm_min,
tm.ngx_tm_sec);
-
-#if 0
- if (tm.ngx_tm_year > 2037) {
- return ngx_snprintf((char *) buf,
- sizeof("Mon, 28-Sep-1970 06:00:00 GMT"),
- "%s, %02d-%s-%d %02d:%02d:%02d GMT",
- week[tm.ngx_tm_wday],
- tm.ngx_tm_mday,
- months[tm.ngx_tm_mon - 1],
- tm.ngx_tm_year,
- tm.ngx_tm_hour,
- tm.ngx_tm_min,
- tm.ngx_tm_sec);
- } else {
- return ngx_snprintf((char *) buf,
- sizeof("Mon, 28-Sep-70 06:00:00 GMT"),
- "%s, %02d-%s-%02d %02d:%02d:%02d GMT",
- week[tm.ngx_tm_wday],
- tm.ngx_tm_mday,
- months[tm.ngx_tm_mon - 1],
- tm.ngx_tm_year % 100,
- tm.ngx_tm_hour,
- tm.ngx_tm_min,
- tm.ngx_tm_sec);
- }
-#endif
}