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
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-06-15 22:32:13 +0400
committerIgor Sysoev <igor@sysoev.ru>2003-06-15 22:32:13 +0400
commitbe2cfc3d28c90b0e911f22d6f14ce927b7f5bfad (patch)
tree52bcfd54a3779fd021278e28dffad5d5bd2f2f4a /src
parent0915977df53c486abbc6081e1c83f9f8e7a8f111 (diff)
nginx-0.0.1-2003-06-15-22:32:13 import
Diffstat (limited to 'src')
-rw-r--r--src/core/nginx.c4
-rw-r--r--src/core/ngx_conf_file.h5
-rw-r--r--src/core/ngx_log.c3
-rw-r--r--src/core/ngx_log.h5
-rw-r--r--src/event/modules/ngx_kqueue_module.c85
-rw-r--r--src/event/ngx_event.c2
-rw-r--r--src/event/ngx_event_timer.c30
-rw-r--r--src/http/ngx_http_cache.c6
-rw-r--r--src/http/ngx_http_core_module.c2
-rw-r--r--src/os/unix/ngx_daemon.c24
-rw-r--r--src/os/unix/ngx_freebsd_config.h1
11 files changed, 110 insertions, 57 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 4f3be980c..28b5fa9fb 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -41,6 +41,7 @@ int main(int argc, char *const *argv)
/* STUB */ ngx_log.log_level = NGX_LOG_DEBUG;
#endif
+
log = ngx_log_init_errlog();
if (ngx_os_init(log) == NGX_ERROR) {
@@ -230,6 +231,9 @@ static int ngx_open_listening_sockets(ngx_log_t *log)
}
if (failed) {
+
+ /* TODO: configurable */
+
ngx_log_error(NGX_LOG_EMERG, log, 0, "can not bind(), exiting");
return NGX_ERROR;
}
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index 046ee2c75..07deeb6a1 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -102,6 +102,11 @@ struct ngx_conf_s {
conf = default; \
}
+#define ngx_conf_init_unsigned_value(conf, default) \
+ if (conf == (unsigned) NGX_CONF_UNSET) { \
+ conf = default; \
+ }
+
#define ngx_conf_init_size_value(conf, default) \
if (conf == NGX_CONF_UNSET) { \
conf = default; \
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 3da25f0a5..5acbaba73 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -219,6 +219,7 @@ static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_log_t *ngx_log_init_errlog()
{
#if (WIN32)
+
ngx_log.fd = GetStdHandle(STD_ERROR_HANDLE);
if (ngx_log.fd == NGX_INVALID_FILE) {
@@ -231,7 +232,9 @@ ngx_log_t *ngx_log_init_errlog()
}
#else
+
ngx_log.fd = STDERR_FILENO;
+
#endif
ngx_log.log_level = NGX_LOG_INFO;
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index d1d382c45..7707acdd7 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -68,10 +68,12 @@ typedef struct {
ngx_fd_t fd;
void *data;
size_t (*handler)(void *ctx, char *buf, size_t len);
+#if 0
/* STUB */
char *action;
char *context;
/* */
+#endif
} ngx_log_t;
#define MAX_ERROR_STR 2048
@@ -161,6 +163,9 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
#endif /* VARIADIC MACROS */
+#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_errlog();
char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log);
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index 3846d5f72..fa3aa9bd6 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -11,8 +11,8 @@
typedef struct {
- int changes;
- int events;
+ u_int changes;
+ u_int events;
} ngx_kqueue_conf_t;
@@ -27,11 +27,10 @@ static void *ngx_kqueue_create_conf(ngx_pool_t *pool);
static char *ngx_kqueue_init_conf(ngx_pool_t *pool, void *conf);
-int ngx_kqueue;
+int ngx_kqueue = -1;
static struct kevent *change_list, *event_list;
-static u_int max_changes, nchanges;
-static int nevents;
+static u_int max_changes, nchanges, nevents;
static ngx_str_t kqueue_name = ngx_string("kqueue");
@@ -86,6 +85,7 @@ ngx_module_t ngx_kqueue_module = {
static int ngx_kqueue_init(ngx_log_t *log)
{
+ struct timespec ts;
ngx_kqueue_conf_t *kcf;
kcf = ngx_event_get_conf(ngx_kqueue_module);
@@ -93,28 +93,57 @@ static int ngx_kqueue_init(ngx_log_t *log)
ngx_log_debug(log, "CH: %d" _ kcf->changes);
ngx_log_debug(log, "EV: %d" _ kcf->events);
+ if (ngx_kqueue == -1) {
+ ngx_kqueue = kqueue();
+
+ if (ngx_kqueue == -1) {
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed");
+ return NGX_ERROR;
+ }
+ }
+
+ if (max_changes < kcf->changes) {
+ if (nchanges) {
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
+
+ if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent() failed");
+ return NGX_ERROR;
+ }
+ }
+
+ if (change_list) {
+ ngx_free(change_list);
+ }
+
+ ngx_test_null(change_list,
+ ngx_alloc(kcf->changes * sizeof(struct kevent), log),
+ NGX_ERROR);
+ }
+
max_changes = kcf->changes;
- nevents = kcf->events;
nchanges = 0;
- ngx_kqueue = kqueue();
+ if (nevents < kcf->events) {
+ if (event_list) {
+ ngx_free(event_list);
+ }
- if (ngx_kqueue == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed");
- return NGX_ERROR;
+ ngx_test_null(event_list,
+ ngx_alloc(kcf->events * sizeof(struct kevent), log),
+ NGX_ERROR);
}
- ngx_test_null(change_list,
- ngx_alloc(kcf->changes * sizeof(struct kevent), log),
- NGX_ERROR);
- ngx_test_null(event_list,
- ngx_alloc(kcf->events * sizeof(struct kevent), log),
- NGX_ERROR);
+ nevents = kcf->events;
if (ngx_event_timer_init(log) == NGX_ERROR) {
return NGX_ERROR;
}
+ /* TODO: re-add active events with new udata
+ if ecf->connections was increased */
+
ngx_event_actions = ngx_kqueue_module_ctx.actions;
ngx_event_flags = NGX_HAVE_LEVEL_EVENT
@@ -139,10 +168,18 @@ static void ngx_kqueue_done(ngx_log_t *log)
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kqueue close() failed");
}
+ ngx_kqueue = -1;
+
ngx_event_timer_done(log);
ngx_free(change_list);
ngx_free(event_list);
+
+ change_list = NULL;
+ event_list = NULL;
+ max_changes = 0;
+ nchanges = 0;
+ nevents = 0;
}
@@ -209,8 +246,8 @@ static int ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags)
static int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags)
{
- struct timespec ts;
- ngx_connection_t *c;
+ struct timespec ts;
+ ngx_connection_t *c;
c = ev->data;
@@ -227,7 +264,7 @@ static int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags)
ts.tv_nsec = 0;
if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) {
- ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent failed");
+ ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent() failed");
return NGX_ERROR;
}
@@ -295,7 +332,7 @@ static int ngx_kqueue_process_events(ngx_log_t *log)
events = kevent(ngx_kqueue, change_list, nchanges, event_list, nevents, tp);
if (events == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent failed");
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent() failed");
return NGX_ERROR;
}
@@ -313,7 +350,7 @@ static int ngx_kqueue_process_events(ngx_log_t *log)
} else {
if (events == 0) {
ngx_log_error(NGX_LOG_ALERT, log, 0,
- "kevent returns no events without timeout");
+ "kevent() returned no events without timeout");
return NGX_ERROR;
}
}
@@ -342,7 +379,7 @@ static int ngx_kqueue_process_events(ngx_log_t *log)
if (event_list[i].flags & EV_ERROR) {
ngx_log_error(NGX_LOG_ALERT, log, event_list[i].data,
- "kevent error on %d", event_list[i].ident);
+ "kevent() error on %d", event_list[i].ident);
continue;
}
@@ -414,8 +451,8 @@ static char *ngx_kqueue_init_conf(ngx_pool_t *pool, void *conf)
{
ngx_kqueue_conf_t *kcf = conf;
- ngx_conf_init_value(kcf->changes, 512);
- ngx_conf_init_value(kcf->events, 512);
+ ngx_conf_init_unsigned_value(kcf->changes, 512);
+ ngx_conf_init_unsigned_value(kcf->events, 512);
return NGX_CONF_OK;
}
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index b7069793a..f6d10cc4b 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -42,7 +42,6 @@ static int ngx_event_connections;
static ngx_str_t events_name = ngx_string("events");
-static ngx_str_t event_name = ngx_string("event");
static ngx_command_t ngx_events_commands[] = {
@@ -66,6 +65,7 @@ ngx_module_t ngx_events_module = {
};
+static ngx_str_t event_name = ngx_string("event");
static ngx_command_t ngx_event_commands[] = {
diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c
index 081afdb25..a49cc9260 100644
--- a/src/event/ngx_event_timer.c
+++ b/src/event/ngx_event_timer.c
@@ -12,20 +12,33 @@ static int ngx_timer_queue_num;
int ngx_event_timer_init(ngx_log_t *log)
{
int i;
+ ngx_event_t *new_queue;
ngx_event_conf_t *ecf;
ecf = ngx_event_get_conf(ngx_event_module);
- ngx_timer_queue_num = ecf->timer_queues;
- ngx_timer_cur_queue = 0;
+ if (ngx_timer_queue_num < ecf->timer_queues) {
+ ngx_test_null(new_queue,
+ ngx_alloc(ecf->timer_queues * sizeof(ngx_event_t), log),
+ NGX_ERROR);
- ngx_test_null(ngx_timer_queue,
- ngx_alloc(ngx_timer_queue_num * sizeof(ngx_event_t), log),
- NGX_ERROR);
+ for (i = 0; i < ngx_timer_queue_num; i++) {
+ new_queue[i] = ngx_timer_queue[i];
+ }
- for (i = 0; i < ngx_timer_queue_num; i++) {
- ngx_timer_queue[i].timer_prev = &ngx_timer_queue[i];
- ngx_timer_queue[i].timer_next = &ngx_timer_queue[i];
+ if (ngx_timer_queue) {
+ ngx_free(ngx_timer_queue);
+ }
+
+ ngx_timer_queue = new_queue;
+
+ ngx_timer_queue_num = ecf->timer_queues;
+ ngx_timer_cur_queue = 0;
+
+ for (/* void */; i < ngx_timer_queue_num; i++) {
+ ngx_timer_queue[i].timer_prev = &ngx_timer_queue[i];
+ ngx_timer_queue[i].timer_next = &ngx_timer_queue[i];
+ }
}
return NGX_OK;;
@@ -35,6 +48,7 @@ int ngx_event_timer_init(ngx_log_t *log)
void ngx_event_timer_done(ngx_log_t *log)
{
ngx_free(ngx_timer_queue);
+ ngx_timer_queue = NULL;
}
diff --git a/src/http/ngx_http_cache.c b/src/http/ngx_http_cache.c
index 0c563206c..b156966dc 100644
--- a/src/http/ngx_http_cache.c
+++ b/src/http/ngx_http_cache.c
@@ -2,7 +2,7 @@
/*
* small file in malloc()ed memory, mmap()ed file, file descriptor only,
- * file access time only (to estimate can pages pages still be in memory),
+ * file access time only (to estimate could pages still be in memory),
* translated URI (ngx_http_index_hanlder),
* compiled script (ngx_http_ssi_filter).
*/
@@ -14,7 +14,9 @@
/* "/" -> "/index.html" in ngx_http_index_handler */
#define NGX_HTTP_CACHE_ENTRY_URI 0x00000004
-/* complied script */
+/* 301 location "/dir" -> "dir/" in ngx_http_core_handler */
+
+/* compiled script in ngx_http_ssi_filter */
#define NGX_HTTP_CACHE_ENTRY_SCRIPT 0x00000008
#define NGX_HTTP_CACHE_FILTER_FLAGS 0xFFFF0000
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index a4e6023c3..c1024e25c 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -359,6 +359,8 @@ ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ r->file.name.data);
}
}
+ngx_log_debug(r->connection->log, "FILE: %d" _ r->file.fd);
+
if (!r->file.info_valid) {
if (ngx_stat_fd(r->file.fd, &r->file.info) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
diff --git a/src/os/unix/ngx_daemon.c b/src/os/unix/ngx_daemon.c
index 93d3571b0..7d05fef9b 100644
--- a/src/os/unix/ngx_daemon.c
+++ b/src/os/unix/ngx_daemon.c
@@ -1,9 +1,7 @@
#include <ngx_config.h>
#include <ngx_core.h>
-#include <ngx_log.h>
-/* daemon in Linux */
int ngx_daemon(ngx_log_t *log)
{
@@ -26,27 +24,8 @@ int ngx_daemon(ngx_log_t *log)
return NGX_ERROR;
}
-#if (__SVR4 || linux)
-
- /* need HUP IGN ? check in Solaris and Linux */
-
- switch (fork()) {
- case -1:
- ngx_log_error(NGX_LOG_EMERG, log, errno, "fork() failed");
- return NGX_ERROR;
-
- case 0:
- break;
-
- default:
- exit(0);
- }
-
-#endif
-
umask(0);
-#if 0
fd = open("/dev/null", O_RDWR);
if (fd == -1) {
ngx_log_error(NGX_LOG_EMERG, log, errno, "open(\"/dev/null\") failed");
@@ -63,10 +42,12 @@ int ngx_daemon(ngx_log_t *log)
return NGX_ERROR;
}
+#if 0
if (dup2(fd, STDERR_FILENO) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed");
return NGX_ERROR;
}
+#endif
if (fd > STDERR_FILENO) {
if (close(fd) == -1) {
@@ -74,7 +55,6 @@ int ngx_daemon(ngx_log_t *log)
return NGX_ERROR;
}
}
-#endif
return NGX_OK;
}
diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
index 64175fe82..31602f831 100644
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -14,6 +14,7 @@
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
+#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h> /* TCP_NOPUSH */