aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nginx.c10
-rw-r--r--src/core/ngx_conf_file.c78
-rw-r--r--src/core/ngx_conf_file.h1
-rw-r--r--src/core/ngx_file.c34
-rw-r--r--src/core/ngx_file.h4
-rw-r--r--src/core/ngx_log.c13
-rw-r--r--src/core/ngx_string.c14
7 files changed, 127 insertions, 27 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 36a28f887..30c068007 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -89,6 +89,8 @@ int main(int argc, char *const *argv)
return 1;
}
+ ngx_init_temp_number();
+
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->init_module) {
if (ngx_modules[i]->init_module(ngx_pool) == NGX_ERROR) {
@@ -97,14 +99,6 @@ int main(int argc, char *const *argv)
}
}
-
-#if 0
- /* STUB */
- /* TODO: init chain of global modules (like ngx_http.c),
- they would init its modules and ngx_listening_sockets */
- ngx_http_init(ngx_pool, &ngx_log);
-#endif
-
ngx_open_listening_sockets(&ngx_log);
/* TODO: daemon */
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 12537bd63..45533be75 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -432,16 +432,34 @@ char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
{
- int size;
+ int size, len, scale;
+ char last;
ngx_str_t *value;
value = (ngx_str_t *) cf->args->elts;
- size = atoi(value[1].data);
- if (size < 0) {
+ len = value[1].len;
+ last = value[1].data[len - 1];
+
+ if (last == 'K' || last == 'k') {
+ len--;
+ scale = 1024;
+
+ } else if (last == 'M' || last == 'm') {
+ len--;
+ scale = 1024 * 1024;
+
+ } else {
+ scale = 1;
+ }
+
+ size = ngx_atoi(value[1].data, len);
+ if (size == NGX_ERROR) {
return "value must be greater or equal to zero";
}
+ size *= scale;
+
*(int *) (conf + cmd->offset) = size;
return NGX_CONF_OK;
@@ -450,17 +468,65 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
{
- int size;
+ int size, len, scale;
+ char last;
ngx_str_t *value;
value = (ngx_str_t *) cf->args->elts;
- size = atoi(value[1].data);
+ len = value[1].len;
+ last = value[1].data[len - 1];
+
+ if (last == 'm') {
+ len--;
+ scale = 1000 * 60;
+
+ } else if (last == 'h') {
+ len--;
+ scale = 1000 * 60 * 60;
+
+ } else if (last == 'd') {
+ len--;
+ scale = 1000 * 60 * 60 * 24;
+
+ } else if (last == 'w') {
+ len--;
+ scale = 1000 * 60 * 60 * 24 * 7;
+
+#if 0 /* overflow */
+
+ } else if (last == 'M') {
+ len--;
+ scale = 1000 * 60 * 60 * 24 * 30;
+
+ } else if (last == 'y') {
+ len--;
+ scale = 1000 * 60 * 60 * 24 * 365;
+
+#endif
+
+ } else if (last == 's') {
+ len--;
+ if (value[1].data[len - 1] == 'm') {
+ len--;
+ scale = 1;
+
+ } else {
+ scale = 1000;
+ }
+
+ } else {
+ scale = 1000;
+ }
+
+ size = ngx_atoi(value[1].data, len);
if (size < 0) {
return "value must be greater or equal to zero";
}
- *(int *) (conf + cmd->offset) = size * 1000;
+ size *= scale;
+
+ *(int *) (conf + cmd->offset) = size;
return NGX_CONF_OK;
}
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index beb148a13..f6c9e0292 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -45,6 +45,7 @@ struct ngx_command_s {
char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, char *conf);
int conf;
int offset;
+ void *bounds;
};
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index 7576c9b5f..b8f15e17d 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -7,10 +7,14 @@
#include <ngx_files.h>
+static int ngx_temp_number;
+static int ngx_random;
+
+
int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
- ngx_pool_t *pool, int num, int step, int persistent)
+ ngx_pool_t *pool, int persistent)
{
- int i;
+ int i, num;
ngx_err_t err;
file->name.len = path->name.len + 1 + path->len + 10;
@@ -26,6 +30,8 @@ int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
ngx_memcpy(file->name.data, path->name.data, path->name.len);
+ num = ngx_next_temp_number(0);
+
for ( ;; ) {
snprintf(file->name.data + path->name.len + 1 + path->len, 11,
"%010u", num);
@@ -58,7 +64,7 @@ ngx_log_debug(file->log, "temp fd: %d" _ file->fd);
err = ngx_errno;
if (err == NGX_EEXIST) {
- num = (num + 1) * step;
+ num = ngx_next_temp_number(1);
continue;
}
@@ -140,3 +146,25 @@ int ngx_create_path(ngx_file_t *file, ngx_path_t *path)
return NGX_OK;
}
+
+
+void ngx_init_temp_number()
+{
+ ngx_random = 0;
+
+ ngx_temp_number = ngx_random;
+
+ while (ngx_random < 10000) {
+ ngx_random = 123456;
+ }
+}
+
+
+int ngx_next_temp_number(int collision)
+{
+ if (collision) {
+ ngx_temp_number += ngx_random;
+ }
+
+ return ngx_temp_number++;
+}
diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h
index d07384810..2cd2f762c 100644
--- a/src/core/ngx_file.h
+++ b/src/core/ngx_file.h
@@ -30,10 +30,12 @@ typedef struct {
int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
- ngx_pool_t *pool, int num, int step, int persistent);
+ ngx_pool_t *pool, int persistent);
void ngx_create_hashed_filename(ngx_file_t *file, ngx_path_t *path);
int ngx_create_path(ngx_file_t *file, ngx_path_t *path);
+void ngx_init_temp_number();
+int ngx_next_temp_number(int collision);
#endif /* _NGX_FILE_H_INCLUDED_ */
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 30e42ad4b..4057d7a81 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -4,7 +4,7 @@
*/
/*
- "[time as ctime()] [alert] 412:3 (32)Broken pipe: anything"
+ "[time as ctime()] [alert] 412#3 (32)Broken pipe: anything"
"[time as ctime()] [alert] (32)Broken pipe: anything"
"[time as ctime()] [alert] anything"
@@ -58,14 +58,19 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
#endif
if (err) {
+
#if (WIN32)
- if ((unsigned) err >= 0x80000000)
+ if ((unsigned) err >= 0x80000000) {
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
" (%X: ", err);
- else
-#endif
+ } else {
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
" (%d: ", err);
+ }
+#else
+ len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
+ " (%d: ", err);
+#endif
len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1);
if (len < sizeof(errstr) - 2) {
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 4beb11d67..15104985f 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -27,14 +27,18 @@ int ngx_atoi(char *line, size_t n)
int value;
for (value = 0; n--; line++) {
- if (*line < '0' || *line > '9') {
- return NGX_ERROR;
- }
+ if (*line < '0' || *line > '9') {
+ return NGX_ERROR;
+ }
- value = value * 10 + (*line - '0');
+ value = value * 10 + (*line - '0');
}
- return value;
+ if (value < 0) {
+ return NGX_ERROR;
+ } else {
+ return value;
+ }
}