nginx-0.0.1-2003-07-10-20:26:57 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 1de6e32..fd2f2db 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -61,7 +61,20 @@
ngx_cycle = cycle;
- /* daemon */
+#if !(WIN32)
+
+ if (0) {
+ if (ngx_daemon(cycle->log) == NGX_ERROR) {
+ return 1;
+ }
+ }
+
+ if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed");
+ return 1;
+ }
+
+#endif
/* life cycle */
@@ -154,7 +167,7 @@
cycle->open_files.nalloc = n;
cycle->open_files.pool = pool;
- cycle->log = ngx_log_create_errlog(cycle);
+ cycle->log = ngx_log_create_errlog(cycle, NULL);
if (cycle->log == NULL) {
ngx_destroy_pool(pool);
return NULL;
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index 879dad3..1b885c6 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -18,9 +18,9 @@
typedef struct ngx_event_s ngx_event_t;
typedef struct ngx_connection_s ngx_connection_t;
+#include <ngx_string.h>
#include <ngx_log.h>
#include <ngx_alloc.h>
-#include <ngx_string.h>
#include <ngx_hunk.h>
#include <ngx_array.h>
#include <ngx_table.h>
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 2f8276b..c3cec38 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -240,13 +240,16 @@
}
-ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle)
+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;
+ }
return log;
}
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index f180272..dcbbef8 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -168,7 +168,7 @@
#define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t))
ngx_log_t *ngx_log_init_errlog();
-ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle);
+ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name);
extern ngx_module_t ngx_errlog_module;
diff --git a/src/core/ngx_os_init.h b/src/core/ngx_os_init.h
index 18e7574..e10a07d 100644
--- a/src/core/ngx_os_init.h
+++ b/src/core/ngx_os_init.h
@@ -34,6 +34,10 @@
int ngx_os_init(ngx_log_t *log);
+#if !(WIN32)
+int ngx_daemon(ngx_log_t *log);
+#endif
+
extern ngx_os_io_t ngx_os_io;
extern int ngx_max_sockets;
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index 05aed62..9c37449 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -6,7 +6,6 @@
#include <ngx_config.h>
#include <ngx_core.h>
-#include <ngx_connection.h>
#include <ngx_event.h>
@@ -32,19 +31,15 @@
} ngx_devpoll_conf_t;
-static int ngx_devpoll_init(ngx_log_t *log);
-static void ngx_devpoll_done(ngx_log_t *log);
+static int ngx_devpoll_init(ngx_cycle_t *cycle);
+static void ngx_devpoll_done(ngx_cycle_t *cycle);
static int ngx_devpoll_add_event(ngx_event_t *ev, int event, u_int flags);
static int ngx_devpoll_del_event(ngx_event_t *ev, int event, u_int flags);
static int ngx_devpoll_set_event(ngx_event_t *ev, int event, u_int flags);
static int ngx_devpoll_process_events(ngx_log_t *log);
-static void *ngx_devpoll_create_conf(ngx_pool_t *pool);
-static char *ngx_devpoll_init_conf(ngx_pool_t *pool, void *conf);
-
-/* STUB */
-#define DEVPOLL_NCHANGES 512
-#define DEVPOLL_NEVENTS 512
+static void *ngx_devpoll_create_conf(ngx_cycle_t *cycle);
+static char *ngx_devpoll_init_conf(ngx_cycle_t *cycle, void *conf);
static int dp;
static struct pollfd *change_list, *event_list;
@@ -104,61 +99,107 @@
};
-static int ngx_devpoll_init(ngx_log_t *log)
+static int ngx_devpoll_init(ngx_cycle_t *cycle)
{
+ int n;
ngx_devpoll_conf_t *dpcf;
- dpcf = ngx_event_get_conf(ngx_devpoll_module);
+ dpcf = ngx_event_get_conf(cycle->conf_ctx, ngx_devpoll_module);
-ngx_log_debug(log, "CH: %d" _ dpcf->changes);
-ngx_log_debug(log, "EV: %d" _ dpcf->events);
-
- max_changes = dpcf->changes;
- nevents = dpcf->events;
- nchanges = 0;
-
- dp = open("/dev/poll", O_RDWR);
+ngx_log_debug(cycle->log, "CH: %d" _ dpcf->changes);
+ngx_log_debug(cycle->log, "EV: %d" _ dpcf->events);
if (dp == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "open(/dev/poll) failed");
+ dp = open("/dev/poll", O_RDWR);
+
+ if (dp == -1) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "open(/dev/poll) failed");
+ return NGX_ERROR;
+ }
+ }
+
+ if (max_changes < dpcf->changes) {
+ if (nchanges) {
+ n = nchanges * sizeof(struct pollfd);
+ if (write(dp, change_list, n) != n) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "write(/dev/poll) failed");
+ return NGX_ERROR;
+ }
+
+ nchanges = 0;
+ }
+
+ if (change_list) {
+ ngx_free(change_list);
+ }
+
+ ngx_test_null(change_list,
+ ngx_alloc(sizeof(struct pollfd) * dpcf->changes,
+ cycle->log),
+ NGX_ERROR);
+
+ if (change_index) {
+ ngx_free(change_index);
+ }
+
+ ngx_test_null(change_index,
+ ngx_alloc(sizeof(ngx_event_t *) * dpcf->changes,
+ cycle->log),
+ NGX_ERROR);
+ }
+
+ max_changes = dpcf->changes;
+
+ if (nevents < dpcf->events) {
+ if (event_list) {
+ ngx_free(event_list);
+ }
+
+ ngx_test_null(event_list,
+ ngx_alloc(sizeof(struct pollfd) * dpcf->events,
+ cycle->log),
+ NGX_ERROR);
+ }
+
+ nevents = dpcf->events;
+
+ if (ngx_event_timer_init(cycle) == NGX_ERROR) {
return NGX_ERROR;
}
- ngx_test_null(change_list,
- ngx_alloc(sizeof(struct pollfd) * dpcf->changes, log),
- NGX_ERROR);
-
- ngx_test_null(event_list,
- ngx_alloc(sizeof(struct pollfd) * dpcf->events, log),
- NGX_ERROR);
-
- ngx_test_null(change_index,
- ngx_alloc(sizeof(ngx_event_t *) * dpcf->changes, log),
- NGX_ERROR);
-
- if (ngx_event_timer_init(log) == NGX_ERROR) {
- return NGX_ERROR;
- }
+ ngx_io = ngx_os_io;
ngx_event_actions = ngx_devpoll_module_ctx.actions;
+
ngx_event_flags = NGX_HAVE_LEVEL_EVENT|NGX_USE_LEVEL_EVENT;
return NGX_OK;
}
-static void ngx_devpoll_done(ngx_log_t *log)
+static void ngx_devpoll_done(ngx_cycle_t *cycle)
{
if (close(dp) == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close(/dev/poll) failed");
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "close(/dev/poll) failed");
}
- ngx_event_timer_done(log);
+ dp = -1;
+
+ ngx_event_timer_done(cycle);
ngx_free(change_list);
ngx_free(event_list);
ngx_free(change_index);
+ change_list = NULL;
+ event_list = NULL;
+ change_index = NULL;
+ max_changes = 0;
+ nchanges = 0;
+ nevents = 0;
}
@@ -280,12 +321,13 @@
int ngx_devpoll_process_events(ngx_log_t *log)
{
- int events, n, i;
- ngx_msec_t timer, delta;
- ngx_err_t err;
- ngx_connection_t *c;
- struct dvpoll dvp;
- struct timeval tv;
+ int events, n, i;
+ ngx_msec_t timer, delta;
+ ngx_err_t err;
+ ngx_cycle_t **cycle;
+ ngx_connection_t *c;
+ struct dvpoll dvp;
+ struct timeval tv;
timer = ngx_event_find_timer();
@@ -351,6 +393,25 @@
}
for (i = 0; i < events; i++) {
+ c = &ngx_cycle->connections[event_list[i].fd];
+
+ if (c->fd == -1) {
+ cycle = ngx_old_cycles.elts;
+ for (i = 0; i < ngx_old_cycles.nelts; i++) {
+ if (cycle[i] == NULL) {
+ continue;
+ }
+ c = &cycle[i]->connections[event_list[i].fd];
+ if (c->fd != -1) {
+ break;
+ }
+ }
+ }
+
+ if (c->fd == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, 0, "unkonwn cycle");
+ exit(1);
+ }
#if (NGX_DEBUG_EVENT)
ngx_log_debug(log, "devpoll: %d: ev:%d rev:%d" _
@@ -358,8 +419,6 @@
event_list[i].events _ event_list[i].revents);
#endif
- c = &ngx_connections[event_list[i].fd];
-
if (event_list[i].revents & POLLIN) {
if (!c->read->active) {
continue;
@@ -394,11 +453,11 @@
}
-static void *ngx_devpoll_create_conf(ngx_pool_t *pool)
+static void *ngx_devpoll_create_conf(ngx_cycle_t *cycle)
{
ngx_devpoll_conf_t *dpcf;
- ngx_test_null(dpcf, ngx_palloc(pool, sizeof(ngx_devpoll_conf_t)),
+ ngx_test_null(dpcf, ngx_palloc(cycle->pool, sizeof(ngx_devpoll_conf_t)),
NGX_CONF_ERROR);
dpcf->changes = NGX_CONF_UNSET;
@@ -408,7 +467,7 @@
}
-static char *ngx_devpoll_init_conf(ngx_pool_t *pool, void *conf)
+static char *ngx_devpoll_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_devpoll_conf_t *dpcf = conf;
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c
index 71ac7f2..278375b 100644
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_poll_module.c
@@ -126,6 +126,8 @@
ngx_free(ready_index);
event_list = NULL;
+ event_index = NULL;
+ ready_index = NULL;
}
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 60a9fcf..0601f3f 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1061,10 +1061,9 @@
value = cf->args->elts;
- ngx_test_null(lcf->err_log, ngx_log_create_errlog(cf->cycle),
+ ngx_test_null(lcf->err_log,
+ ngx_log_create_errlog(cf->cycle, &value[1]),
NGX_CONF_ERROR);
- lcf->err_log->file->name = value[1];
-
return NGX_CONF_OK;
}
diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
index 31602f8..7ec14a6 100644
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <stddef.h> /* offsetof */
#include <stdlib.h>
+#include <stdarg.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h
index 9056657..6055cc6 100644
--- a/src/os/unix/ngx_linux_config.h
+++ b/src/os/unix/ngx_linux_config.h
@@ -11,6 +11,7 @@
#include <unistd.h>
#include <stddef.h> /* offsetof */
#include <stdlib.h>
+#include <stdarg.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h
index a5b66c4..43423aa 100644
--- a/src/os/unix/ngx_solaris_config.h
+++ b/src/os/unix/ngx_solaris_config.h
@@ -11,6 +11,7 @@
#include <unistd.h>
#include <stddef.h> /* offsetof */
#include <stdlib.h>
+#include <stdarg.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>