summaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nginx.c87
-rw-r--r--src/core/ngx_conf_file.c57
-rw-r--r--src/core/ngx_conf_file.h13
-rw-r--r--src/core/ngx_config.h7
-rw-r--r--src/core/ngx_log.c33
5 files changed, 145 insertions, 52 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 4bc9a218b..dce1a5d15 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -66,8 +66,10 @@ int rotate;
int main(int argc, char *const *argv)
{
int i;
+ ngx_fd_t fd;
ngx_log_t *log;
ngx_cycle_t *cycle;
+ ngx_open_file_t *file;
ngx_core_conf_t *ccf;
#if (NGX_DEBUG) && (__FreeBSD__)
@@ -150,6 +152,55 @@ int main(int argc, char *const *argv)
if (rotate) {
ngx_log_debug(ngx_cycle->log, "rotate");
+
+ file = cycle->open_files.elts;
+ for (i = 0; i < cycle->open_files.nelts; i++) {
+ if (file[i].name.data == NULL) {
+ continue;
+ }
+
+ fd = ngx_open_file(file[i].name.data,
+ NGX_FILE_RDWR,
+ NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
+
+ngx_log_debug(log, "REOPEN: %d:%d:%s" _ fd _ file[i].fd _ file[i].name.data);
+
+ if (fd == NGX_INVALID_FILE) {
+ ngx_log_error(NGX_LOG_EMERG,
+ ngx_cycle->log, ngx_errno,
+ ngx_open_file_n " \"%s\" failed",
+ file[i].name.data);
+ continue;
+ }
+
+#if (WIN32)
+ if (ngx_file_append_mode(fd) == NGX_ERROR) {
+ ngx_log_error(NGX_LOG_EMERG,
+ ngx_cycle->log, ngx_errno,
+ ngx_file_append_mode_n
+ " \"%s\" failed",
+ file[i].name.data);
+
+ if (ngx_close_file(fd) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_EMERG,
+ ngx_cycle->log, ngx_errno,
+ ngx_close_file_n " \"%s\" failed",
+ file[i].name.data);
+ }
+
+ continue;
+ }
+#endif
+
+ if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_EMERG,
+ ngx_cycle->log, ngx_errno,
+ ngx_close_file_n " \"%s\" failed",
+ file[i].name.data);
+ }
+
+ file[i].fd = fd;
+ }
}
if (restart) {
@@ -275,25 +326,33 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
file = cycle->open_files.elts;
for (i = 0; i < cycle->open_files.nelts; i++) {
- if (file->name.data == NULL) {
+ if (file[i].name.data == NULL) {
continue;
}
- file->fd = ngx_open_file(file->name.data,
- NGX_FILE_RDWR,
- NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
+ file[i].fd = ngx_open_file(file[i].name.data,
+ NGX_FILE_RDWR,
+ NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
-ngx_log_debug(log, "OPEN: %d:%s" _ file->fd _ file->name.data);
+ngx_log_debug(log, "OPEN: %d:%s" _ file[i].fd _ file[i].name.data);
- if (file->fd == NGX_INVALID_FILE) {
+ if (file[i].fd == NGX_INVALID_FILE) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
ngx_open_file_n " \"%s\" failed",
- file->name.data);
+ file[i].name.data);
failed = 1;
break;
}
- /* TODO: Win32 append */
+#if (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",
+ file[i].name.data);
+ failed = 1;
+ break;
+ }
+#endif
}
/* STUB */ cycle->log->log_level = NGX_LOG_DEBUG;
@@ -341,14 +400,14 @@ ngx_log_debug(log, "OPEN: %d:%s" _ file->fd _ file->name.data);
file = cycle->open_files.elts;
for (i = 0; i < cycle->open_files.nelts; i++) {
- if (file->fd == NGX_INVALID_FILE) {
+ if (file[i].fd == NGX_INVALID_FILE) {
continue;
}
- if (ngx_close_file(file->fd) == NGX_FILE_ERROR) {
+ if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
ngx_close_file_n " \"%s\" failed",
- file->name.data);
+ file[i].name.data);
}
}
@@ -405,14 +464,14 @@ ngx_log_debug(log, "OPEN: %d:%s" _ file->fd _ file->name.data);
file = old_cycle->open_files.elts;
for (i = 0; i < old_cycle->open_files.nelts; i++) {
- if (file->fd == NGX_INVALID_FILE) {
+ if (file[i].fd == NGX_INVALID_FILE) {
continue;
}
- if (ngx_close_file(file->fd) == NGX_FILE_ERROR) {
+ if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
ngx_close_file_n " \"%s\" failed",
- file->name.data);
+ file[i].name.data);
}
}
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index bea7a4c52..249f10fba 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -3,8 +3,8 @@
#include <ngx_core.h>
-char ngx_conf_errstr[MAX_CONF_ERRSTR];
+#define MAX_CONF_ERRSTR 256
static int argument_number[] = {
NGX_CONF_NOARGS,
@@ -212,19 +212,11 @@ ngx_log_debug(cf->log, "rv: %d" _ rv);
break;
} else {
- if (rv == ngx_conf_errstr) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "%s in %s:%d",
- rv,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- } else {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "\"%s\" directive %s in %s:%d",
- name->data, rv,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- }
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "\"%s\" directive %s in %s:%d",
+ name->data, rv,
+ cf->conf_file->file.name.data,
+ cf->conf_file->line);
rc = NGX_ERROR;
break;
@@ -475,6 +467,34 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
}
+ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
+{
+ int i;
+ ngx_open_file_t *file;
+
+ if (name) {
+ file = cycle->open_files.elts;
+ for (i = 0; i < cycle->open_files.nelts; i++) {
+ if (name->len != file[i].name.len) {
+ continue;
+ }
+
+ if (ngx_strcmp(name->data, file[i].name.data) == 0) {
+ return &file[i];
+ }
+ }
+ }
+
+ ngx_test_null(file, ngx_push_array(&cycle->open_files), NULL);
+ file->fd = NGX_INVALID_FILE;
+ if (name) {
+ file->name = *name;
+ }
+
+ return file;
+}
+
+
void ngx_conf_log_error(int level, ngx_conf_t *cf, ngx_err_t err,
char *fmt, ...)
{
@@ -526,10 +546,11 @@ char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
flag = 0;
} else {
- ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
- "invalid value \"%s\", it must be \"on\" or \"off\"",
- value[1].data);
- return ngx_conf_errstr;
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid value \"%s\" in \"%s\" directive, "
+ "it must be \"on\" or \"off\"",
+ value[1].data, cmd->name.data);
+ return NGX_CONF_ERROR;
}
*(int *) (p + cmd->offset) = flag;
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index f618d9be2..f47b7f71c 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -40,9 +40,6 @@
#define NGX_CONF_MODULE 0x464E4F43 /* "CONF" */
-#define MAX_CONF_ERRSTR 256
-extern char ngx_conf_errstr[MAX_CONF_ERRSTR];
-
struct ngx_command_s {
ngx_str_t name;
@@ -59,6 +56,13 @@ struct ngx_command_s {
struct ngx_open_file_s {
ngx_fd_t fd;
ngx_str_t name;
+#if 0
+ /* e.g. append mode, error_log */
+ int flags;
+ /* e.g. reopen db file */
+ int (*handler)(void *data, ngx_open_file_t *file);
+ void *data;
+#endif
};
@@ -178,6 +182,7 @@ struct ngx_conf_s {
char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename);
+ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name);
void ngx_conf_log_error(int level, ngx_conf_t *cf, ngx_err_t err,
char *fmt, ...);
@@ -192,8 +197,10 @@ char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
+
extern ngx_module_t *ngx_modules[];
extern ngx_cycle_t *ngx_cycle;
extern ngx_array_t ngx_old_cycles;
+
#endif /* _NGX_HTTP_CONF_FILE_H_INCLUDED_ */
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index 4d7f86d59..3621f8cf8 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -32,6 +32,13 @@
#endif
+#ifndef NGX_SERVER_ROOT
+#define NGX_SERVER_ROOT "./"
+#if 0
+#define NGX_SERVER_ROOT "/usr/local/nginx/"
+#endif
+#endif
+
#if !(WIN32)
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 9ebac94e6..9f422d3af 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -69,6 +69,10 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
int written;
#endif
+ if (log->file->fd == NGX_INVALID_FILE) {
+ return;
+ }
+
ngx_localtime(&tm);
len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d",
tm.ngx_tm_year, tm.ngx_tm_mon, tm.ngx_tm_mday,
@@ -121,21 +125,16 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
}
#if (WIN32)
- errstr[len++] = '\r';
- errstr[len++] = '\n';
- if (log->file->fd) {
- WriteFile(log->file->fd, errstr, len, &written, NULL);
- }
+
+ errstr[len++] = CR;
+ errstr[len++] = LF;
+ WriteFile(log->file->fd, errstr, len, &written, NULL);
+
#else
- errstr[len++] = '\n';
- write(log->file->fd, errstr, len);
-#endif
+ errstr[len++] = LF;
+ write(log->file->fd, errstr, len);
-#if 0
- errstr[len] = '\0';
- fputs(errstr, stderr);
- fflush(stderr);
#endif
}
@@ -225,6 +224,8 @@ ngx_log_t *ngx_log_init_errlog()
} else if (ngx_stderr.fd == NULL) {
/* there are no associated standard handles */
/* TODO: where we can log possible errors ? */
+
+ ngx_stderr.fd = NGX_INVALID_FILE;
}
#else
@@ -246,11 +247,9 @@ ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name)
ngx_log_t *log;
ngx_test_null(log, ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)), NULL);
- ngx_test_null(log->file, ngx_push_array(&cycle->open_files), NULL);
- log->file->fd = NGX_INVALID_FILE;
- if (name) {
- log->file->name = *name;
- }
+ ngx_test_null(log->file, ngx_conf_open_file(cycle, name), NULL);
+
+ /* STUB */ log->log_level = NGX_LOG_DEBUG;
return log;
}