diff options
36 files changed, 930 insertions, 131 deletions
@@ -36,21 +36,29 @@ echo >> $MAKEFILE echo "CORE_DEPS = \\" >> $MAKEFILE for dep in $CORE_DEPS do + if [ $PLATFORM = win32 ]; then + dep=`echo $dep | sed -e "s/\//\\\\\\/g"` + fi echo " $dep \\" >> $MAKEFILE done echo >> $MAKEFILE -echo "CORE_INCS = $CORE_INCS -I $OBJS" >> $MAKEFILE +inc=`echo "$CORE_INCS -I $OBJS" | sed -e "s/\//\\\\\\/g"` +echo "CORE_INCS = $inc" >> $MAKEFILE echo >> $MAKEFILE echo "HTTP_DEPS = \\" >> $MAKEFILE for inc in $HTTP_DEPS do + if [ $PLATFORM = win32 ]; then + inc=`echo $inc | sed -e "s/\//\\\\\\/g"` + fi echo " $inc \\" >> $MAKEFILE done echo >> $MAKEFILE -echo "HTTP_INCS = $HTTP_INCS" >> $MAKEFILE +inc=`echo "$HTTP_INCS" | sed -e "s/\//\\\\\\/g"` +echo "HTTP_INCS = $inc" >> $MAKEFILE echo >> $MAKEFILE @@ -60,12 +68,21 @@ echo "nginx: \\" >> $MAKEFILE for src in $CORE_SRCS $HTTP_SRCS do obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/" -e "s/\.S\$/.$OBJEXT/"` - echo " $OBJS/$obj \\" >> $MAKEFILE + obj="$OBJS/$obj" + if [ $PLATFORM = win32 ]; then + obj=`echo $obj | sed -e "s/\//\\\\\\/g"` + fi + + echo " $obj \\" >> $MAKEFILE done for src in $NGX_MODULES_C $LINK_DEPS do obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/"` + if [ $PLATFORM = win32 ]; then + obj=`echo $obj | sed -e "s/\//\\\\\\/g"` + fi + echo " $obj \\" >> $MAKEFILE done @@ -75,10 +92,18 @@ echo " \$(CC) ${BINOUT}nginx \\" >> $MAKEFILE for src in $CORE_SRCS $HTTP_SRCS do obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/" -e "s/\.S\$/.$OBJEXT/"` - echo " $OBJS/$obj \\" >> $MAKEFILE + obj="$OBJS/$obj" + if [ $PLATFORM = win32 ]; then + obj=`echo $obj | sed -e "s/\//\\\\\\/g"` + fi + + echo " $obj \\" >> $MAKEFILE done obj=`echo $NGX_MODULES_C | sed -e "s/\.c\$/.$OBJEXT/"` +if [ $PLATFORM = win32 ]; then + obj=`echo $obj | sed -e "s/\//\\\\\\/g"` +fi echo " $obj \\" >> $MAKEFILE echo " $CORE_LIBS \\" >> $MAKEFILE echo " $CORE_LINK" >> $MAKEFILE diff --git a/auto/os/conf b/auto/os/conf index 837e6d304..4ae08e856 100644 --- a/auto/os/conf +++ b/auto/os/conf @@ -32,8 +32,10 @@ case $PLATFORM in CORE_DEPS="$WIN32_DEPS" CORE_SRCS="$WIN32_SRCS $SELECT_SRCS $IOCP_SRCS" EVENT_MODULES="$EVENT_MODULES $SELECT_MODULE $IOCP_MODULE" + EVENT_FOUND=YES - CFLAGS="$CFLAGS -D HAVE_AIO=1 -D HAVE_IOCP=1" + have=HAVE_AIO . auto/have + have=HAVE_IOCP . auto/have CORE_LIBS="$CORE_LIBS ws2_32.lib" # msvcrt.dll diff --git a/auto/sources b/auto/sources index c30c9a6e0..026a5e0c5 100644 --- a/auto/sources +++ b/auto/sources @@ -103,20 +103,21 @@ UNIX_DEPS="$CORE_DEPS $EVENT_DEPS \ src/os/unix/ngx_process.h \ src/os/unix/ngx_thread.h \ src/os/unix/ngx_socket.h \ - src/os/unix/ngx_os.h" + src/os/unix/ngx_os.h \ + src/os/unix/ngx_process_cycle.h" UNIX_SRCS="$CORE_SRCS $EVENT_SRCS \ src/os/unix/ngx_time.c \ src/os/unix/ngx_errno.c \ - src/os/unix/ngx_sendv.c \ src/os/unix/ngx_files.c \ src/os/unix/ngx_socket.c \ src/os/unix/ngx_recv.c \ src/os/unix/ngx_readv_chain.c \ src/os/unix/ngx_writev_chain.c \ - src/os/unix/ngx_posix_init.c \ + src/os/unix/ngx_daemon.c \ src/os/unix/ngx_process.c \ - src/os/unix/ngx_daemon.c" + src/os/unix/ngx_posix_init.c \ + src/os/unix/ngx_process_cycle.c" FREEBSD_DEPS=src/os/unix/ngx_freebsd_config.h FREEBSD_SRCS=src/os/unix/ngx_freebsd_init.c @@ -144,18 +145,20 @@ WIN32_DEPS="$CORE_DEPS $EVENT_DEPS \ src/os/win32/ngx_files.h \ src/os/win32/ngx_process.h \ src/os/win32/ngx_socket.h \ - src/os/win32/ngx_os.h" + src/os/win32/ngx_os.h \ + src/os/win32/ngx_process_cycle.h" WIN32_SRCS="$CORE_SRCS $EVENT_SRCS \ src/os/win32/ngx_errno.c \ src/os/win32/ngx_files.c \ src/os/win32/ngx_time.c \ + src/os/win32/ngx_process.c \ src/os/win32/ngx_socket.c \ src/os/win32/ngx_wsarecv.c \ src/os/win32/ngx_wsarecv_chain.c \ src/os/win32/ngx_wsasend_chain.c \ - src/os/win32/ngx_sendv.c \ src/os/win32/ngx_win32_init.c \ + src/os/win32/ngx_process_cycle.c \ src/event/ngx_event_acceptex.c" diff --git a/src/core/nginx.c b/src/core/nginx.c index 21363d268..92c938d60 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -5,6 +5,8 @@ #include <nginx.h> +#if 0 + typedef struct { ngx_flag_t daemon; ngx_flag_t master; @@ -30,8 +32,10 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); #if (NGX_THREADS) static int ngx_worker_thread_cycle(void *data); #endif + +#endif + static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp); -static ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv); static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle); static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle); static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -110,11 +114,9 @@ ngx_int_t ngx_change_binary; int main(int argc, char *const *argv, char **envp) { - ngx_fd_t fd; ngx_int_t i; ngx_log_t *log; ngx_cycle_t *cycle, init_cycle; - ngx_open_file_t *file; ngx_core_conf_t *ccf; ngx_master_ctx_t ctx; #if !(WIN32) @@ -254,6 +256,8 @@ int main(int argc, char *const *argv, char **envp) } +#if 0 + /* TODO: broken NGX_PROCESS_SINGLE */ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) @@ -744,6 +748,8 @@ int ngx_worker_thread_cycle(void *data) #endif +#endif + static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp) { @@ -791,7 +797,7 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp) } -static ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) +ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) { char *env[2], *var, *p; ngx_int_t i; @@ -885,8 +891,8 @@ static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle) ccf->daemon = NGX_CONF_UNSET; ccf->master = NGX_CONF_UNSET; ccf->worker_reopen = NGX_CONF_UNSET; - ccf->user = (uid_t) NGX_CONF_UNSET; - ccf->group = (gid_t) NGX_CONF_UNSET; + ccf->user = (ngx_uid_t) NGX_CONF_UNSET; + ccf->group = (ngx_gid_t) NGX_CONF_UNSET; ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf; @@ -896,6 +902,15 @@ static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle) static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { +#if (WIN32) + + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, + "\"user\" is not supported, ignored"); + + return NGX_CONF_OK; + +#else + struct passwd *pwd; struct group *grp; ngx_str_t *value; @@ -932,4 +947,6 @@ static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ccf->group = grp->gr_gid; return NGX_CONF_OK; + +#endif } diff --git a/src/core/ngx_atomic.h b/src/core/ngx_atomic.h index bf771e95c..17362aa32 100644 --- a/src/core/ngx_atomic.h +++ b/src/core/ngx_atomic.h @@ -72,8 +72,8 @@ static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock, typedef volatile uint32_t ngx_atomic_t; /* STUB */ -#define ngx_atomic_inc(x) x++; -#define ngx_atomic_dec(x) x--; +#define ngx_atomic_inc(x) (*(x))++; +#define ngx_atomic_dec(x) (*(x))--; #define ngx_atomic_cmp_set(lock, old, set) 1; /**/ diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 989a0de1f..8a858735e 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -248,7 +248,12 @@ ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text) return 0; } - if (err == NGX_ECONNRESET || err == NGX_EPIPE || err == NGX_ENOTCONN) { + if (err == NGX_ECONNRESET +#if !(WIN32) + || err == NGX_EPIPE +#endif + || err == NGX_ENOTCONN) + { switch (c->log_error) { diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h index 7735ab10b..57bdafc64 100644 --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -21,6 +21,7 @@ typedef struct ngx_connection_s ngx_connection_t; #include <ngx_errno.h> #include <ngx_process.h> #include <ngx_thread.h> +#include <ngx_user.h> #include <ngx_string.h> #include <ngx_parse.h> #include <ngx_log.h> @@ -39,6 +40,7 @@ typedef struct ngx_connection_s ngx_connection_t; #include <ngx_times.h> #include <ngx_inet.h> #include <ngx_cycle.h> +#include <ngx_process_cycle.h> #include <ngx_conf_file.h> #include <ngx_os.h> #include <ngx_connection.h> diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index 017db87f1..3827c0d4e 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -24,7 +24,6 @@ static ngx_connection_t dumb; ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) { ngx_int_t i, n, failed; - ngx_str_t conf_file; ngx_log_t *log; ngx_conf_t conf; ngx_pool_t *pool; @@ -227,13 +226,17 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) } } - /* TODO: Win32 DuplicateHandle ? */ - if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { +#if (WIN32) + /* TODO: TEST */ + CloseHandle(GetStdHandle(STD_ERROR_HANDLE)); + SetStdHandle(STD_ERROR_HANDLE, cycle->log->file->fd); +#else + if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed"); failed = 1; } - +#endif if (failed) { @@ -370,7 +373,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) } -void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user) +void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) { ngx_fd_t fd; ngx_int_t i; @@ -395,19 +398,6 @@ void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user) continue; } - if (user != (uid_t) -1) { - if (chown(file[i].name.data, user, -1) == -1) { - ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - "chown \"%s\" failed", file[i].name.data); - - if (ngx_close_file(fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - ngx_close_file_n " \"%s\" failed", - file[i].name.data); - } - } - } - #if (WIN32) if (ngx_file_append_mode(fd) == NGX_ERROR) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, @@ -423,6 +413,19 @@ void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user) continue; } #else + if (user != (ngx_uid_t) -1) { + if (chown(file[i].name.data, user, -1) == -1) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + "chown \"%s\" failed", file[i].name.data); + + if (ngx_close_file(fd) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + ngx_close_file_n " \"%s\" failed", + file[i].name.data); + } + } + } + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, "fcntl(FD_CLOEXEC) \"%s\" failed", @@ -447,11 +450,16 @@ void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user) file[i].fd = fd; } - /* TODO: Win32 DuplicateHandle ? */ +#if (WIN32) + /* TODO: TEST */ + CloseHandle(GetStdHandle(STD_ERROR_HANDLE)); + SetStdHandle(STD_ERROR_HANDLE, cycle->log->file->fd); +#else if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, "dup2(STDERR) failed"); } +#endif } diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index d9f1a607b..4d301f94d 100644 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -25,12 +25,25 @@ struct ngx_cycle_s { }; +typedef struct { + ngx_flag_t daemon; + ngx_flag_t master; + ngx_flag_t worker_reopen; + ngx_uid_t user; + ngx_gid_t group; + ngx_str_t pid; + ngx_str_t newpid; +} ngx_core_conf_t; + + ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle); -void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user); +void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user); +ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv); extern volatile ngx_cycle_t *ngx_cycle; extern ngx_array_t ngx_old_cycles; +extern ngx_module_t ngx_core_module; #endif /* _NGX_CYCLE_H_INCLUDED_ */ diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index 349fe6bb1..371c72519 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -47,10 +47,10 @@ static const char *debug_levels[] = { #if (HAVE_VARIADIC_MACROS) -void ngx_log_error_core(int 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, ...) #else -void ngx_log_error_core(int 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) #endif { @@ -176,7 +176,7 @@ static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len) #if !(HAVE_VARIADIC_MACROS) -void ngx_log_error(int level, ngx_log_t *log, ngx_err_t err, +void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, const char *fmt, ...) { va_list args; diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h index 375acae73..d1fdab63d 100644 --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -92,7 +92,7 @@ struct ngx_log_s { #define ngx_log_error(level, log, args...) \ if (log->log_level >= level) ngx_log_error_core(level, log, args) -void ngx_log_error_core(int 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, ...); /*********************************/ @@ -104,7 +104,7 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, #define ngx_log_error(level, log, ...) \ if (log->log_level >= level) ngx_log_error_core(level, log, __VA_ARGS__) -void ngx_log_error_core(int 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, ...); /*********************************/ @@ -113,9 +113,9 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, #define HAVE_VARIADIC_MACROS 0 -void ngx_log_error(int level, ngx_log_t *log, ngx_err_t err, +void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, const char *fmt, ...); -void ngx_log_error_core(int 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, ...); diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c index e95a81974..0adc0c74c 100644 --- a/src/event/modules/ngx_iocp_module.c +++ b/src/event/modules/ngx_iocp_module.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2002-2003 Igor Sysoev, http://sysoev.ru + * Copyright (C) 2002-2004 Igor Sysoev, http://sysoev.ru/en/ */ @@ -10,11 +10,11 @@ #include <ngx_iocp_module.h> -static int ngx_iocp_init(ngx_cycle_t *cycle); +static ngx_int_t ngx_iocp_init(ngx_cycle_t *cycle); static void ngx_iocp_done(ngx_cycle_t *cycle); -static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key); -static int ngx_iocp_del_connection(ngx_connection_t *c, u_int flags); -static int ngx_iocp_process_events(ngx_log_t *log); +static ngx_int_t ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key); +static ngx_int_t ngx_iocp_del_connection(ngx_connection_t *c, u_int flags); +static ngx_int_t ngx_iocp_process_events(ngx_log_t *log); static void *ngx_iocp_create_conf(ngx_cycle_t *cycle); static char *ngx_iocp_init_conf(ngx_cycle_t *cycle, void *conf); @@ -89,7 +89,7 @@ ngx_os_io_t ngx_iocp_io = { static HANDLE iocp; -static int ngx_iocp_init(ngx_cycle_t *cycle) +static ngx_int_t ngx_iocp_init(ngx_cycle_t *cycle) { ngx_iocp_conf_t *cf; @@ -106,10 +106,6 @@ static int ngx_iocp_init(ngx_cycle_t *cycle) return NGX_ERROR; } - if (ngx_event_timer_init(cycle) == NGX_ERROR) { - return NGX_ERROR; - } - ngx_io = ngx_iocp_io; ngx_event_actions = ngx_iocp_module_ctx.actions; @@ -128,12 +124,10 @@ static void ngx_iocp_done(ngx_cycle_t *cycle) } iocp = NULL; - - ngx_event_timer_done(cycle); } -static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key) +static ngx_int_t ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key) { ngx_connection_t *c; @@ -142,7 +136,8 @@ static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key) c->read->active = 1; c->write->active = 1; - ngx_log_debug(ev->log, "iocp add: %d, %d:%08x" _ c->fd _ key _ &ev->ovlp); + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, + "iocp add: fd:%d k:%d ov:" PTR_FMT, c->fd, key, &ev->ovlp); if (CreateIoCompletionPort((HANDLE) c->fd, iocp, key, 0) == NULL) { ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, @@ -154,7 +149,7 @@ static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key) } -static int ngx_iocp_del_connection(ngx_connection_t *c, u_int flags) +static ngx_int_t ngx_iocp_del_connection(ngx_connection_t *c, u_int flags) { if (CancelIo((HANDLE) c->fd) == 0) { ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, "CancelIo() failed"); @@ -165,7 +160,7 @@ static int ngx_iocp_del_connection(ngx_connection_t *c, u_int flags) } -static int ngx_iocp_process_events(ngx_log_t *log) +static ngx_int_t ngx_iocp_process_events(ngx_log_t *log) { int rc; u_int key; @@ -178,23 +173,17 @@ static int ngx_iocp_process_events(ngx_log_t *log) ngx_event_ovlp_t *ovlp; timer = ngx_event_find_timer(); + ngx_old_elapsed_msec = ngx_elapsed_msec; - if (timer) { - ngx_gettimeofday(&tv); - delta = tv.tv_sec * 1000 + tv.tv_usec / 1000; - - } else { + if (timer == 0) { timer = INFINITE; - delta = 0; } - ngx_log_debug(log, "iocp timer: %d" _ timer); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "iocp timer: %d", timer); rc = GetQueuedCompletionStatus(iocp, &bytes, (LPDWORD) &key, (LPOVERLAPPED *) &ovlp, timer); - ngx_log_debug(log, "iocp: %d, %d, %d:%08x" _ rc _ bytes _ key _ ovlp); - if (rc == 0) { err = ngx_errno; } else { @@ -202,16 +191,13 @@ static int ngx_iocp_process_events(ngx_log_t *log) } ngx_gettimeofday(&tv); + ngx_time_update(tv.tv_sec); - if (ngx_cached_time != tv.tv_sec) { - ngx_cached_time = tv.tv_sec; - ngx_time_update(); - } + ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0, + "iocp: %d b:%d k:%d ov:" PTR_FMT, rc, bytes, key, ovlp); - if (timer != INFINITE) { - delta = tv.tv_sec * 1000 + tv.tv_usec / 1000 - delta; - ngx_event_expire_timers((ngx_msec_t) delta); - } + delta = ngx_elapsed_msec; + ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec; if (err) { if (ovlp == NULL) { @@ -227,12 +213,20 @@ static int ngx_iocp_process_events(ngx_log_t *log) } } + if (timer != INFINITE) { + delta = ngx_elapsed_msec - delta; + + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, + "iocp timer: %d, delta: %d", timer, (int) delta); + } + if (ovlp) { ev = ovlp->event; -ngx_log_debug(log, "iocp ev: %08x" _ ev); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "iocp event:" PTR_FMT, ev); switch (key) { + case NGX_IOCP_ACCEPT: if (bytes) { ev->ready = 1; @@ -250,11 +244,16 @@ ngx_log_debug(log, "iocp ev: %08x" _ ev); ev->available = bytes; -ngx_log_debug(log, "iocp ev handler: %08x" _ ev->event_handler); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, + "iocp event handler: %08x" PTR_FMT, ev->event_handler); ev->event_handler(ev); } + if (timer != INFINITE && delta) { + ngx_event_expire_timers((ngx_msec_t) delta); + } + return NGX_OK; } diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c index 88b150123..a890a262d 100644 --- a/src/event/modules/ngx_select_module.c +++ b/src/event/modules/ngx_select_module.c @@ -361,8 +361,12 @@ static int ngx_select_process_events(ngx_log_t *log) ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "select ready %d", ready); if (err) { +#if (WIN32) + ngx_log_error(NGX_LOG_ALERT, log, err, "select() failed"); +#else ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, log, err, "select() failed"); +#endif return NGX_ERROR; } diff --git a/src/event/ngx_event_acceptex.c b/src/event/ngx_event_acceptex.c index c737434b7..164db0ed4 100644 --- a/src/event/ngx_event_acceptex.c +++ b/src/event/ngx_event_acceptex.c @@ -70,7 +70,9 @@ int ngx_event_post_acceptex(ngx_listening_t *ls, int n) /* TODO: look up reused sockets */ s = ngx_socket(ls->family, ls->type, ls->protocol, ls->flags); - ngx_log_debug(ls->log, ngx_socket_n ": %d:%d" _ s _ ls->flags); + + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ls->log, 0, + ngx_socket_n " s:%d fl:%d", s, ls->flags); if (s == -1) { ngx_log_error(NGX_LOG_ALERT, ls->log, ngx_socket_errno, diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c index 4aed6ae20..65ce128b9 100644 --- a/src/http/modules/ngx_http_ssi_filter.c +++ b/src/http/modules/ngx_http_ssi_filter.c @@ -21,6 +21,7 @@ typedef struct { typedef struct { + int dummy; } ngx_http_ssi_command_t; diff --git a/src/os/unix/ngx_aio_read.c b/src/os/unix/ngx_aio_read.c index 1fc020d76..84301886a 100644 --- a/src/os/unix/ngx_aio_read.c +++ b/src/os/unix/ngx_aio_read.c @@ -25,7 +25,7 @@ ssize_t ngx_aio_read(ngx_connection_t *c, char *buf, size_t size) rev = c->read; if (!rev->ready) { - ngx_log_error(NGX_LOG_ALERT, c->log, 0, "SECOND AIO POST"); + ngx_log_error(NGX_LOG_ALERT, c->log, 0, "second aio post"); return NGX_AGAIN; } diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c index c2a2c8fca..c90a437ae 100644 --- a/src/os/unix/ngx_files.c +++ b/src/os/unix/ngx_files.c @@ -1,10 +1,6 @@ #include <ngx_config.h> #include <ngx_core.h> -#include <ngx_hunk.h> -#include <ngx_array.h> -#include <ngx_file.h> -#include <ngx_files.h> ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset) diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h index 09fc856a4..641ccfa0b 100644 --- a/src/os/unix/ngx_files.h +++ b/src/os/unix/ngx_files.h @@ -3,11 +3,7 @@ #include <ngx_config.h> - -#include <ngx_types.h> -#include <ngx_alloc.h> -#include <ngx_hunk.h> -#include <ngx_file.h> +#include <ngx_core.h> #define NGX_INVALID_FILE -1 diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index 90d253912..85e5dbeed 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -49,6 +49,8 @@ extern int ngx_max_sockets; extern int ngx_inherited_nonblocking; +#if 0 + extern ngx_int_t ngx_process; extern ngx_pid_t ngx_new_binary; @@ -62,6 +64,8 @@ extern ngx_int_t ngx_reconfigure; extern ngx_int_t ngx_reopen; extern ngx_int_t ngx_change_binary; +#endif + #ifdef __FreeBSD__ #include <ngx_freebsd.h> diff --git a/src/os/unix/ngx_process.h b/src/os/unix/ngx_process.h index bc68a054b..62c6b90c0 100644 --- a/src/os/unix/ngx_process.h +++ b/src/os/unix/ngx_process.h @@ -29,10 +29,6 @@ typedef struct { } ngx_exec_ctx_t; -#define NGX_PROCESS_SINGLE 0 -#define NGX_PROCESS_MASTER 1 -#define NGX_PROCESS_WORKER 2 - #define NGX_MAX_PROCESSES 1024 #define NGX_PROCESS_NORESPAWN -1 diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c new file mode 100644 index 000000000..8e8bec66e --- /dev/null +++ b/src/os/unix/ngx_process_cycle.c @@ -0,0 +1,517 @@ + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_event.h> + + +static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); +static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); +#if (NGX_THREADS) +static int ngx_worker_thread_cycle(void *data); +#endif + + +ngx_int_t ngx_process; +ngx_pid_t ngx_pid; +ngx_pid_t ngx_new_binary; +ngx_int_t ngx_inherited; + +sig_atomic_t ngx_reap; +sig_atomic_t ngx_timer; +sig_atomic_t ngx_terminate; +sig_atomic_t ngx_quit; +sig_atomic_t ngx_noaccept; +sig_atomic_t ngx_reconfigure; +sig_atomic_t ngx_reopen; +sig_atomic_t ngx_change_binary; + + +/* TODO: broken NGX_PROCESS_SINGLE */ + +void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) +{ + int signo; + sigset_t set; + struct timeval tv; + struct itimerval itv; + ngx_uint_t i, live; + ngx_msec_t delay; + ngx_core_conf_t *ccf; + + sigemptyset(&set); + sigaddset(&set, SIGCHLD); + sigaddset(&set, SIGALRM); + sigaddset(&set, SIGINT); + sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL)); + sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL)); + sigaddset(&set, ngx_signal_value(NGX_NOACCEPT_SIGNAL)); + sigaddset(&set, ngx_signal_value(NGX_TERMINATE_SIGNAL)); + sigaddset(&set, ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); + sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL)); + + if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "sigprocmask() failed"); + } + + sigemptyset(&set); + + ngx_setproctitle("master process"); + + ngx_new_binary = 0; + delay = 0; + signo = 0; + live = 0; + + for ( ;; ) { + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); + + if (ngx_process == NGX_PROCESS_MASTER) { + ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, + "worker process", NGX_PROCESS_RESPAWN); + + /* + * we have to limit the maximum life time of the worker processes + * by 1 month because our millisecond event timer is limited + * by 49 days on 32-bit platforms + */ + + itv.it_interval.tv_sec = 0; + itv.it_interval.tv_usec = 0; + itv.it_value.tv_sec = 30 * 24 * 60 * 60; + itv.it_value.tv_usec = 0; + + if (setitimer(ITIMER_REAL, &itv, NULL) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "setitimer() failed"); + } + + live = 1; + + } else { + ngx_init_temp_number(); + + for (i = 0; ngx_modules[i]; i++) { + if (ngx_modules[i]->init_process) { + if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { + /* fatal */ + exit(1); + } + } + } + } + + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, + ngx_core_module); + + /* a cycle with the same configuration because a new one is invalid */ + + for ( ;; ) { + + /* an event loop */ + + for ( ;; ) { + + if (ngx_process == NGX_PROCESS_MASTER) { + if (delay) { + delay *= 2; + + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "temination cycle: %d", delay); + + itv.it_interval.tv_sec = 0; + itv.it_interval.tv_usec = 0; + itv.it_value.tv_sec = delay / 1000; + itv.it_value.tv_usec = (delay % 1000 ) * 1000; + + if (setitimer(ITIMER_REAL, &itv, NULL) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "setitimer() failed"); + } + } + + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "sigsuspend"); + + sigsuspend(&set); + + ngx_gettimeofday(&tv); + ngx_time_update(tv.tv_sec); + + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "wake up"); + + } else { /* NGX_PROCESS_SINGLE */ + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "worker cycle"); + + ngx_process_events(cycle->log); + live = 0; + } + + if (ngx_reap) { + ngx_reap = 0; + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "reap childs"); + + live = 0; + for (i = 0; i < ngx_last_process; i++) { + + ngx_log_debug5(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "child: " PID_T_FMT + " e:%d t:%d d:%d r:%d", + ngx_processes[i].pid, + ngx_processes[i].exiting, + ngx_processes[i].exited, + ngx_processes[i].detached, + ngx_processes[i].respawn); + + if (ngx_processes[i].exited) { + + if (ngx_processes[i].respawn + && !ngx_processes[i].exiting + && !ngx_terminate + && !ngx_quit) + { + if (ngx_spawn_process(cycle, + ngx_processes[i].proc, + ngx_processes[i].data, + ngx_processes[i].name, i) + == NGX_ERROR) + { + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, + "can not respawn %s", + ngx_processes[i].name); + continue; + } + + live = 1; + + continue; + } + + if (ngx_processes[i].pid == ngx_new_binary) { + ngx_new_binary = 0; + + /* TODO: if (ngx_noaccept) ngx_configure = 1 */ + } + + if (i != --ngx_last_process) { + ngx_processes[i--] = + ngx_processes[ngx_last_process]; + } + + } else if (ngx_processes[i].exiting + || !ngx_processes[i].detached) + { + live = 1; + } + } + } + + if (!live && (ngx_terminate || ngx_quit)) { + ngx_master_exit(cycle, ctx); + } + + if (ngx_terminate) { + if (delay == 0) { + delay = 50; + } + + if (delay > 1000) { + signo = SIGKILL; + } else { + signo = ngx_signal_value(NGX_TERMINATE_SIGNAL); + } + + } else if (ngx_quit) { + signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); + + } else if (ngx_timer) { + signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); + + } else { + + if (ngx_noaccept) { + signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); + } + + if (ngx_change_binary) { + ngx_change_binary = 0; + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, + "changing binary"); + ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv); + } + + if (ngx_reconfigure) { + signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, + "reconfiguring"); + } + + if (ngx_reopen) { + if (ngx_process == NGX_PROCESS_MASTER) { + if (ccf->worker_reopen != 0) { + signo = ngx_signal_value(NGX_REOPEN_SIGNAL); + ngx_reopen = 0; + + } else if (ngx_noaccept) { + ngx_reopen = 0; + + } else { + signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); + } + + } else { /* NGX_PROCESS_SINGLE */ + ngx_reopen = 0; + } + + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, + "reopening logs"); + ngx_reopen_files(cycle, + ccf->worker_reopen != 0 ? ccf->user : (uid_t) -1); + } + } + + if (signo) { + for (i = 0; i < ngx_last_process; i++) { + + if (ngx_processes[i].detached) { + continue; + } + + ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, + "kill (" PID_T_FMT ", %d)" , + ngx_processes[i].pid, signo); + + if (kill(ngx_processes[i].pid, signo) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "kill(%d, %d) failed", + ngx_processes[i].pid, signo); + continue; + } + + if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) { + ngx_processes[i].exiting = 1; + } + } + + signo = 0; + } + + if (ngx_reopen || ngx_reconfigure || ngx_timer) { + break; + } + } + + if (ngx_reopen) { + ngx_reopen = 0; + + } else if (ngx_timer) { + ngx_timer = 0; + + } else if (ngx_noaccept) { + ngx_noaccept = 0; + ngx_reconfigure = 0; + + } else { + cycle = ngx_init_cycle(cycle); + if (cycle == NULL) { + cycle = (ngx_cycle_t *) ngx_cycle; + continue; + } + + ngx_cycle = cycle; + ngx_reconfigure = 0; + } + + break; + } + } +} + + +static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) +{ + char *name; + + if (ngx_inherited && getppid() > 1) { + name = ctx->pid.name.data; + + } else { + name = ctx->name; + } + + if (ngx_delete_file(name) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_delete_file_n " \"%s\" failed", name); + } + + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit"); + exit(0); +} + + +static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) +{ + sigset_t set; + ngx_int_t i; + ngx_listening_t *ls; + ngx_core_conf_t *ccf; +#if (NGX_THREADS) + ngx_tid_t tid; +#endif + + ngx_process = NGX_PROCESS_WORKER; + ngx_last_process = 0; + + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); + + if (ccf->group != (gid_t) NGX_CONF_UNSET) { + if (setuid(ccf->group) == -1) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + "setgid(%d) failed", ccf->group); + /* fatal */ + exit(2); + } + } + + if (ccf->user != (uid_t) NGX_CONF_UNSET && geteuid() == 0) { + if (setuid(ccf->user) == -1) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + "setuid(%d) failed", ccf->user); + /* fatal */ + exit(2); + } + } + +#if (HAVE_PR_SET_DUMPABLE) + + /* allow coredump after setuid() in Linux 2.4.x */ + + if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "prctl(PR_SET_DUMPABLE) failed"); + } + +#endif + + sigemptyset(&set); + + if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "sigprocmask() failed"); + } + + ngx_init_temp_number(); + + /* + * disable deleting previous events for the listening sockets because + * in the worker processes there are no events at all at this point + */ + ls = cycle->listening.elts; + for (i = 0; i < cycle->listening.nelts; i++) { + ls[i].remain = 0; + } + + for (i = 0; ngx_modules[i]; i++) { + if (ngx_modules[i]->init_process) { + if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { + /* fatal */ + exit(1); + } + } + } + + ngx_setproctitle("worker process"); + +#if (NGX_THREADS) + + if (ngx_init_threads(5, 128 * 1024 * 1024, cycle) == NGX_ERROR) { + /* fatal */ + exit(1); + } + + for (i = 0; i < 1; i++) { + if (ngx_create_thread(&tid, ngx_worker_thread_cycle, + cycle, cycle->log) != 0) + { + /* fatal */ + exit(1); + } + } + +#endif + + for ( ;; ) { + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); + + ngx_process_events(cycle->log); + + if (ngx_terminate) { + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exiting"); + exit(0); + } + + if (ngx_quit) { + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, + "gracefully shutting down"); + ngx_setproctitle("worker process is shutting down"); + break; + } + + if (ngx_reopen) { + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopen logs"); + ngx_reopen_files(cycle, -1); + ngx_reopen = 0; + } + } + + ngx_close_listening_sockets(cycle); + + for ( ;; ) { + if (ngx_event_timer_rbtree == &ngx_event_timer_sentinel) { + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exiting"); + exit(0); + } + + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); + + ngx_process_events(cycle->log); + + if (ngx_reopen) { + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopen logs"); + ngx_reopen_files(cycle, -1); + ngx_reopen = 0; + } + } +} + + +#if (NGX_THREADS) + +int ngx_worker_thread_cycle(void *data) +{ + ngx_cycle_t *cycle = data; + + struct timeval tv; + + /* STUB */ + + ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, ngx_errno, + "thread %d started", ngx_thread_self()); + + ngx_setproctitle("worker thread"); + + sleep(5); + + ngx_gettimeofday(&tv); + ngx_time_update(tv.tv_sec); + + ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, ngx_errno, + "thread %d done", ngx_thread_self()); + + return 1; +} + +#endif diff --git a/src/os/unix/ngx_process_cycle.h b/src/os/unix/ngx_process_cycle.h new file mode 100644 index 000000000..c863b6213 --- /dev/null +++ b/src/os/unix/ngx_process_cycle.h @@ -0,0 +1,40 @@ +#ifndef _NGX_PROCESS_CYCLE_H_INCLUDED_ +#define _NGX_PROCESS_CYCLE_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +typedef struct { + ngx_file_t pid; + char *name; + int argc; + char *const *argv; +} ngx_master_ctx_t; + + +#define NGX_PROCESS_SINGLE 0 +#define NGX_PROCESS_MASTER 1 +#define NGX_PROCESS_WORKER 2 + + +void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); + + +extern ngx_int_t ngx_process; +extern ngx_pid_t ngx_pid; +extern ngx_pid_t ngx_new_binary; +extern ngx_int_t ngx_inherited; + +extern sig_atomic_t ngx_reap; +extern sig_atomic_t ngx_timer; +extern sig_atomic_t ngx_quit; +extern sig_atomic_t ngx_terminate; +extern sig_atomic_t ngx_noaccept; +extern sig_atomic_t ngx_reconfigure; +extern sig_atomic_t ngx_reopen; +extern sig_atomic_t ngx_change_binary; + + +#endif /* _NGX_PROCESS_CYCLE_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_user.h b/src/os/unix/ngx_user.h new file mode 100644 index 000000000..0aed208cc --- /dev/null +++ b/src/os/unix/ngx_user.h @@ -0,0 +1,13 @@ +#ifndef _NGX_USER_H_INCLUDED_ +#define _NGX_USER_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +typedef uid_t ngx_uid_t; +typedef gid_t ngx_gid_t; + + +#endif /* _NGX_USER_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_errno.h b/src/os/win32/ngx_errno.h index 179cbbce5..a7acf53a2 100644 --- a/src/os/win32/ngx_errno.h +++ b/src/os/win32/ngx_errno.h @@ -17,10 +17,13 @@ typedef DWORD ngx_err_t; #define NGX_EACCES ERROR_ACCESS_DENIED #define NGX_EEXIST ERROR_FILE_EXISTS #define NGX_ENOTDIR ERROR_PATH_NOT_FOUND +#define NGX_EPIPE EPIPE #define NGX_EAGAIN WSAEWOULDBLOCK #define NGX_EINPROGRESS WSAEINPROGRESS #define NGX_EADDRINUSE WSAEADDRINUSE -#define NGX_ECONNRESET ECONNRESET +#define NGX_ECONNABORTED WSAECONNABORTED +#define NGX_ECONNRESET WSAECONNRESET +#define NGX_ENOTCONN WSAENOTCONN #define NGX_ETIMEDOUT WSAETIMEDOUT #define NGX_ENOMOREFILES ERROR_NO_MORE_FILES diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h index 1268d47c0..1b13f4c7d 100644 --- a/src/os/win32/ngx_files.h +++ b/src/os/win32/ngx_files.h @@ -21,8 +21,6 @@ #define NGX_FILE_ERROR 0 -#define STDERR_FILENO (HANDLE) 2 - #define ngx_open_file(name, access, create) \ CreateFile(name, access, \ diff --git a/src/os/win32/ngx_os.h b/src/os/win32/ngx_os.h index 212d57fb1..39af212b3 100644 --- a/src/os/win32/ngx_os.h +++ b/src/os/win32/ngx_os.h @@ -46,8 +46,13 @@ extern int ngx_inherited_nonblocking; extern int ngx_win32_version; -extern int reconfigure; -extern int reopen; +extern ngx_int_t ngx_process; + +extern ngx_int_t ngx_quit; +extern ngx_int_t ngx_terminate; + +extern ngx_int_t ngx_reconfigure; +extern ngx_int_t ngx_reopen; diff --git a/src/os/win32/ngx_process.c b/src/os/win32/ngx_process.c new file mode 100644 index 000000000..e3a278647 --- /dev/null +++ b/src/os/win32/ngx_process.c @@ -0,0 +1,9 @@ + +#include <ngx_config.h> +#include <ngx_core.h> + + +ngx_pid_t ngx_exec(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx) +{ + return /* STUB */ 0; +} diff --git a/src/os/win32/ngx_process.h b/src/os/win32/ngx_process.h index a4d4bbcc7..35d9bb904 100644 --- a/src/os/win32/ngx_process.h +++ b/src/os/win32/ngx_process.h @@ -2,7 +2,29 @@ #define _NGX_PROCESS_H_INCLUDED_ -#define ngx_getpid GetCurrentProcessId +typedef DWORD ngx_pid_t; + +#define ngx_getpid GetCurrentProcessId +#define ngx_log_pid ngx_pid + + +typedef struct { + char *path; + char *name; + char *const *argv; + char *const *envp; +} ngx_exec_ctx_t; + + +#define NGX_PROCESS_SINGLE 0 +#define NGX_PROCESS_MASTER 1 +#define NGX_PROCESS_WORKER 2 + + +ngx_pid_t ngx_exec(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx); + + +extern ngx_pid_t ngx_pid; #endif /* _NGX_PROCESS_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c new file mode 100644 index 000000000..8ffef52dc --- /dev/null +++ b/src/os/win32/ngx_process_cycle.c @@ -0,0 +1,28 @@ + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_event.h> + + +#if 0 + +ngx_int_t ngx_process; +ngx_pid_t ngx_pid; +ngx_pid_t ngx_new_binary; +ngx_int_t ngx_inherited; + +sig_atomic_t ngx_reap; +sig_atomic_t ngx_timer; +sig_atomic_t ngx_terminate; +sig_atomic_t ngx_quit; +sig_atomic_t ngx_noaccept; +sig_atomic_t ngx_reconfigure; +sig_atomic_t ngx_reopen; +sig_atomic_t ngx_change_binary; + +#endif + + +void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) +{ +} diff --git a/src/os/win32/ngx_process_cycle.h b/src/os/win32/ngx_process_cycle.h new file mode 100644 index 000000000..c863b6213 --- /dev/null +++ b/src/os/win32/ngx_process_cycle.h @@ -0,0 +1,40 @@ +#ifndef _NGX_PROCESS_CYCLE_H_INCLUDED_ +#define _NGX_PROCESS_CYCLE_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +typedef struct { + ngx_file_t pid; + char *name; + int argc; + char *const *argv; +} ngx_master_ctx_t; + + +#define NGX_PROCESS_SINGLE 0 +#define NGX_PROCESS_MASTER 1 +#define NGX_PROCESS_WORKER 2 + + +void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); + + +extern ngx_int_t ngx_process; +extern ngx_pid_t ngx_pid; +extern ngx_pid_t ngx_new_binary; +extern ngx_int_t ngx_inherited; + +extern sig_atomic_t ngx_reap; +extern sig_atomic_t ngx_timer; +extern sig_atomic_t ngx_quit; +extern sig_atomic_t ngx_terminate; +extern sig_atomic_t ngx_noaccept; +extern sig_atomic_t ngx_reconfigure; +extern sig_atomic_t ngx_reopen; +extern sig_atomic_t ngx_change_binary; + + +#endif /* _NGX_PROCESS_CYCLE_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_thread.h b/src/os/win32/ngx_thread.h new file mode 100644 index 000000000..cb282fbc0 --- /dev/null +++ b/src/os/win32/ngx_thread.h @@ -0,0 +1,26 @@ +#ifndef _NGX_THREAD_H_INCLUDED_ +#define _NGX_THREAD_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +#if (NGX_THREADS) + +#define ngx_thread_volatile volatile + +#else /* !NGX_THREADS */ + +#define ngx_thread_volatile + +#define ngx_log_tid 0 +#define TID_T_FMT "%d" + +#define ngx_mutex_lock(m) NGX_OK +#define ngx_mutex_unlock(m) + +#endif + + +#endif /* _NGX_THREAD_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_user.h b/src/os/win32/ngx_user.h new file mode 100644 index 000000000..480a25885 --- /dev/null +++ b/src/os/win32/ngx_user.h @@ -0,0 +1,14 @@ +#ifndef _NGX_USER_H_INCLUDED_ +#define _NGX_USER_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +/* STUB */ +#define ngx_uid_t ngx_int_t +#define ngx_gid_t ngx_int_t + + +#endif /* _NGX_USER_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h index 7b1fd130b..00f6426e3 100644 --- a/src/os/win32/ngx_win32_config.h +++ b/src/os/win32/ngx_win32_config.h @@ -4,8 +4,6 @@ #define WIN32 1 -#define NGX_WIN_NT 200000 - #define STRICT #define WIN32_LEAN_AND_MEAN @@ -36,16 +34,19 @@ #pragma warning(disable:4127) #endif +#include <ngx_auto_config.h> + #define ngx_inline __inline -#if 0 -/* owc have not __int32 */ +#if 1 typedef unsigned __int32 uint32_t; #else +/* OWC has not __int32 */ typedef unsigned int uint32_t; #endif + typedef __int64 int64_t; typedef unsigned __int64 uint64_t; typedef u_int uintptr_t; @@ -54,6 +55,7 @@ typedef int ssize_t; typedef long time_t; typedef __int64 off_t; typedef uint32_t in_addr_t; +typedef int sig_atomic_t; #define OFF_T_FMT "%I64d" @@ -61,7 +63,10 @@ typedef uint32_t in_addr_t; #define SIZE_T_X_FMT "%x" #define PID_T_FMT "%d" #define TIME_T_FMT "%lu" +#define PTR_FMT "%08X" + +#define NGX_WIN_NT 200000 #ifndef HAVE_INHERITED_NONBLOCK diff --git a/src/os/win32/ngx_wsarecv.c b/src/os/win32/ngx_wsarecv.c index 2a43498ad..96fa0ff4c 100644 --- a/src/os/win32/ngx_wsarecv.c +++ b/src/os/win32/ngx_wsarecv.c @@ -20,7 +20,8 @@ ssize_t ngx_wsarecv(ngx_connection_t *c, char *buf, size_t size) rc = WSARecv(c->fd, wsabuf, 1, &bytes, &flags, NULL, NULL); - ngx_log_debug(c->log, "WSARecv: %d:%d" _ rc _ bytes); + ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, + "WSARecv: fd:%d rc:%d %d of %d", c->fd, rc, bytes, size); rev = c->read; @@ -29,12 +30,14 @@ ssize_t ngx_wsarecv(ngx_connection_t *c, char *buf, size_t size) err = ngx_socket_errno; if (err == WSAEWOULDBLOCK) { - ngx_log_error(NGX_LOG_INFO, c->log, err, "WSARecv() EAGAIN"); + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, + "WSARecv() not ready"); return NGX_AGAIN; } rev->error = 1; - ngx_log_error(NGX_LOG_CRIT, c->log, err, "WSARecv() failed"); + ngx_connection_error(c, err, "WSARecv() failed"); + return NGX_ERROR; } @@ -63,19 +66,19 @@ ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, char *buf, size_t size) rev = c->read; if (!rev->ready) { - ngx_log_error(NGX_LOG_ALERT, rev->log, 0, "SECOND WSA POST"); + ngx_log_error(NGX_LOG_ALERT, rev->log, 0, "second wsa post"); return NGX_AGAIN; } - ngx_log_debug(c->log, "rev->complete: %d" _ rev->complete); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, + "rev->complete: %d", rev->complete); if (rev->complete) { rev->complete = 0; if (ngx_event_flags & NGX_USE_IOCP_EVENT) { if (rev->ovlp.error) { - ngx_log_error(NGX_LOG_ERR, c->log, rev->ovlp.error, - "WSARecv() failed"); + ngx_connection_error(c, rev->ovlp.error, "WSARecv() failed"); return NGX_ERROR; } @@ -84,9 +87,8 @@ ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, char *buf, size_t size) if (WSAGetOverlappedResult(c->fd, (LPWSAOVERLAPPED) &rev->ovlp, &bytes, 0, NULL) == 0) { - ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, - "WSARecv() or WSAGetOverlappedResult() failed"); - + ngx_connection_error(c, ngx_socket_errno, + "WSARecv() or WSAGetOverlappedResult() failed"); return NGX_ERROR; } @@ -104,7 +106,8 @@ ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, char *buf, size_t size) rev->complete = 0; - ngx_log_debug(c->log, "WSARecv: %d:%d" _ rc _ bytes); + ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, + "WSARecv: fd:%d rc:%d %d of %d", c->fd, rc, bytes, size); if (rc == -1) { err = ngx_socket_errno; @@ -114,7 +117,7 @@ ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, char *buf, size_t size) } rev->error = 1; - ngx_log_error(NGX_LOG_CRIT, c->log, err, "WSARecv() failed"); + ngx_connection_error(c, err, "WSARecv() failed"); return NGX_ERROR; } diff --git a/src/os/win32/ngx_wsarecv_chain.c b/src/os/win32/ngx_wsarecv_chain.c index edc4421dd..afdfa05c0 100644 --- a/src/os/win32/ngx_wsarecv_chain.c +++ b/src/os/win32/ngx_wsarecv_chain.c @@ -40,7 +40,9 @@ ssize_t ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain) chain = chain->next; } -ngx_log_debug(c->log, "WSARecv: %d:%d" _ io.nelts _ wsabuf->len); + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, + "WSARecv: %d:%d", io.nelts, wsabuf->len); + rc = WSARecv(c->fd, io.elts, io.nelts, &bytes, &flags, NULL, NULL); @@ -51,12 +53,13 @@ ngx_log_debug(c->log, "WSARecv: %d:%d" _ io.nelts _ wsabuf->len); err = ngx_socket_errno; if (err == WSAEWOULDBLOCK) { - ngx_log_error(NGX_LOG_INFO, c->log, err, "WSARecv() EAGAIN"); + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, + "WSARecv() not ready"); return NGX_AGAIN; } rev->error = 1; - ngx_log_error(NGX_LOG_CRIT, c->log, err, "WSARecv() failed"); + ngx_connection_error(c, err, "WSARecv() failed"); return NGX_ERROR; } diff --git a/src/os/win32/ngx_wsasend_chain.c b/src/os/win32/ngx_wsasend_chain.c index 438f3dbd0..a52296a09 100644 --- a/src/os/win32/ngx_wsasend_chain.c +++ b/src/os/win32/ngx_wsasend_chain.c @@ -53,18 +53,19 @@ ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in) err = ngx_errno; if (err == WSAEWOULDBLOCK) { - ngx_log_error(NGX_LOG_INFO, c->log, err, "WSASend() EAGAIN"); + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, + "WSASend() not ready"); wev->ready = 0; return in; } else { wev->error = 1; - ngx_log_error(NGX_LOG_CRIT, c->log, err, "WSASend() failed"); + ngx_connection_error(c, err, "WSASend() failed"); return NGX_CHAIN_ERROR; } } - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "WSASend(): %d", sent); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "WSASend: %d", sent); c->sent += sent; @@ -162,7 +163,7 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in) } else { wev->error = 1; - ngx_log_error(NGX_LOG_CRIT, c->log, err, "WSASend() failed"); + ngx_connection_error(c, err, "WSASend() failed"); return NGX_CHAIN_ERROR; } @@ -187,8 +188,7 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in) if (ngx_event_flags & NGX_USE_IOCP_EVENT) { if (wev->ovlp.error) { - ngx_log_error(NGX_LOG_ERR, c->log, wev->ovlp.error, - "WSASend() failed"); + ngx_connection_error(c, wev->ovlp.error, "WSASend() failed"); return NGX_CHAIN_ERROR; } @@ -197,15 +197,15 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in) } else { if (WSAGetOverlappedResult(c->fd, (LPWSAOVERLAPPED) &wev->ovlp, &sent, 0, NULL) == 0) { - ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, - "WSASend() or WSAGetOverlappedResult() failed"); + ngx_connection_error(c, ngx_socket_errno, + "WSASend() or WSAGetOverlappedResult() failed"); return NGX_CHAIN_ERROR; } } } - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "WSASend(): %d", sent); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "WSASend: %d", sent); c->sent += sent; |