nginx-0.0.2-2004-03-09-22:47:07 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index ef4ceca..5515b90 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -35,7 +35,7 @@
 
 #endif
 
-static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp);
+static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
 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);
@@ -112,7 +112,7 @@
 ngx_int_t     ngx_change_binary;
 
 
-int main(int argc, char *const *argv, char **envp)
+int main(int argc, char *const *argv)
 {
     ngx_int_t          i;
     ngx_log_t         *log;
@@ -145,6 +145,10 @@
     init_cycle.log = log;
     ngx_cycle = &init_cycle;
 
+#if 0
+    /* STUB */ log->log_level = NGX_LOG_DEBUG_ALL;
+#endif
+
     ngx_memzero(&ctx, sizeof(ngx_master_ctx_t));
     ctx.argc = argc;
     ctx.argv = argv;
@@ -172,7 +176,7 @@
         return 1;
     }
 
-    if (ngx_add_inherited_sockets(&init_cycle, envp) == NGX_ERROR) {
+    if (ngx_add_inherited_sockets(&init_cycle) == NGX_ERROR) {
         return 1;
     }
 
@@ -256,49 +260,48 @@
 }
 
 
-static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp)
+static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
 {
-    char                *p, *v;
+    char                *p, *v, *inherited;
     ngx_socket_t         s;
     ngx_listening_t     *ls;
 
-    for ( /* void */ ; *envp; envp++) {
-        if (ngx_strncmp(*envp, NGINX_VAR, NGINX_VAR_LEN) != 0) {
-            continue;
-        }
+    inherited = getenv(NGINX_VAR);
 
-        ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
-                      "using inherited sockets from \"%s\"", *envp);
-
-        ngx_init_array(cycle->listening, cycle->pool,
-                       10, sizeof(ngx_listening_t), NGX_ERROR);
-
-        for (p = *envp + NGINX_VAR_LEN, v = p; *p; p++) {
-            if (*p == ':' || *p == ';') {
-                s = ngx_atoi(v, p - v);
-                if (s == NGX_ERROR) {
-                    ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
-                                  "invalid socket number \"%s\" "
-                                  "in NGINX enviroment variable, "
-                                  "ignoring the rest of the variable", v);
-                    break;
-                }
-                v = p + 1;
-
-                if (!(ls = ngx_push_array(&cycle->listening))) {
-                    return NGX_ERROR;
-                }
-
-                ls->fd = s;
-            }
-        }
-
-        ngx_inherited = 1;
-
-        return ngx_set_inherited_sockets(cycle);
+    if (inherited == NULL) {
+        return NGX_OK;
     }
 
-    return NGX_OK;
+    ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
+                  "using inherited sockets from \"%s\"", inherited);
+
+    ngx_init_array(cycle->listening, cycle->pool,
+                   10, sizeof(ngx_listening_t), NGX_ERROR);
+
+    for (p = inherited, v = p; *p; p++) {
+        if (*p == ':' || *p == ';') {
+            s = ngx_atoi(v, p - v);
+            if (s == NGX_ERROR) {
+                ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
+                              "invalid socket number \"%s\" in "
+                              NGINX_VAR " enviroment variable, "
+                              "ignoring the rest of the variable", v);
+                break;
+            }
+
+        v = p + 1;
+
+        if (!(ls = ngx_push_array(&cycle->listening))) {
+                return NGX_ERROR;
+        }
+
+            ls->fd = s;
+        }
+    }
+
+    ngx_inherited = 1;
+
+    return ngx_set_inherited_sockets(cycle);
 }
 
 
@@ -314,17 +317,19 @@
     ctx.name = "new binary process";
     ctx.argv = argv;
 
-    var = ngx_alloc(NGINX_VAR_LEN
-                            + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 1,
+    var = ngx_alloc(sizeof(NGINX_VAR)
+                            + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
                     cycle->log);
 
-    p = ngx_cpymem(var, NGINX_VAR, NGINX_VAR_LEN);
+    p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
 
     ls = cycle->listening.elts;
     for (i = 0; i < cycle->listening.nelts; i++) {
         p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd);
     }
 
+    ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var);
+
     env[0] = var;
     env[1] = NULL;
     ctx.envp = (char *const *) &env;
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 6680de1..8703688 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,8 +8,7 @@
 #define NGINX_NEW_PID_EXT  ".newbin"
 #define NGINX_NEW_PID      NGINX_PID NGINX_NEW_PID_EXT
 
-#define NGINX_VAR          "NGINX="
-#define NGINX_VAR_LEN      (sizeof(NGINX_VAR) - 1)
+#define NGINX_VAR          "NGINX"
 
 extern ngx_module_t        ngx_core_module;
 
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index 8a85873..54fd0f9 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -78,7 +78,7 @@
 
     /* TODO: tries configurable */
 
-    for (tries = 10; tries; tries--) {
+    for (tries = /* STUB */ 1; tries; tries--) {
         failed = 0;
 
         /* for each listening socket */
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index 3827c0d..7fcc679 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -227,9 +227,13 @@
     }
 
 #if (WIN32)
+#if 0
     /* TODO: TEST */
+fprintf(stderr, "BEFORE\n");
     CloseHandle(GetStdHandle(STD_ERROR_HANDLE));
     SetStdHandle(STD_ERROR_HANDLE, cycle->log->file->fd);
+fprintf(stderr, "AFTER\n");
+#endif
 #else
     if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) {
         ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c
index e0a042c..2056fd6 100644
--- a/src/event/modules/ngx_iocp_module.c
+++ b/src/event/modules/ngx_iocp_module.c
@@ -245,7 +245,7 @@
         ev->available = bytes;
 
         ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
-                       "iocp event handler: %08x" PTR_FMT, ev->event_handler);
+                       "iocp event handler: " PTR_FMT, ev->event_handler);
 
         ev->event_handler(ev);
     }
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c
index 9cf377e..b68ca31 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter.c
@@ -549,9 +549,9 @@
 
 static void ngx_http_gzip_filter_free(void *opaque, void *address)
 {
+#if 0
     ngx_http_gzip_ctx_t *ctx = opaque;
 
-#if 0
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
                    "gzip free: %X", address);
 #endif
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 20c7a55..e717a6a 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -844,13 +844,16 @@
 {
     char                      *rv;
     ngx_int_t                  m;
-    ngx_str_t                 *value, err;
+    ngx_str_t                 *value;
     ngx_http_module_t         *module;
     ngx_conf_t                 pvcf;
     ngx_http_conf_ctx_t       *ctx, *pvctx;
     ngx_http_core_srv_conf_t  *cscf;
     ngx_http_core_loc_conf_t  *clcf, **clcfp;
+#if (HAVE_PCRE)
+    ngx_str_t                  err;
     char                       errstr[NGX_MAX_CONF_ERRSTR];
+#endif
 
     if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
         return NGX_CONF_ERROR;
diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c
index b34bd1b..f2ac5a3 100644
--- a/src/http/ngx_http_log_handler.c
+++ b/src/http/ngx_http_log_handler.c
@@ -95,9 +95,6 @@
 static ngx_str_t http_access_log = ngx_string("access.log");
 
 
-static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-                          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
-
 static ngx_str_t ngx_http_combined_fmt =
     ngx_string("%addr - - [%time] \"%request\" %status %apache_length "
                "\"%{Referer}i\" \"%{User-Agent}i\"");
diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c
index 8ffef52..7b26d6b 100644
--- a/src/os/win32/ngx_process_cycle.c
+++ b/src/os/win32/ngx_process_cycle.c
@@ -25,4 +25,22 @@
 
 void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
 {
+    ngx_int_t  i;
+
+    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(2);
+            }
+        }
+    }
+
+    for ( ;; ) {
+        ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
+
+        ngx_process_events(cycle->log);
+    }
 }
diff --git a/src/os/win32/ngx_socket.h b/src/os/win32/ngx_socket.h
index 8623103..ec519c3 100644
--- a/src/os/win32/ngx_socket.h
+++ b/src/os/win32/ngx_socket.h
@@ -35,6 +35,62 @@
 #define ngx_close_socket_n  "closesocket()"
 
 
+#ifndef WSAID_ACCEPTEX
+
+typedef BOOL (PASCAL FAR * LPFN_ACCEPTEX)(
+    IN SOCKET sListenSocket,
+    IN SOCKET sAcceptSocket,
+    IN PVOID lpOutputBuffer,
+    IN DWORD dwReceiveDataLength,
+    IN DWORD dwLocalAddressLength,
+    IN DWORD dwRemoteAddressLength,
+    OUT LPDWORD lpdwBytesReceived,
+    IN LPOVERLAPPED lpOverlapped
+    );
+
+#define WSAID_ACCEPTEX \
+        {0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
+
+#endif
+
+
+#ifndef WSAID_GETACCEPTEXSOCKADDRS
+
+typedef VOID (PASCAL FAR * LPFN_GETACCEPTEXSOCKADDRS)(
+    IN PVOID lpOutputBuffer,
+    IN DWORD dwReceiveDataLength,
+    IN DWORD dwLocalAddressLength,
+    IN DWORD dwRemoteAddressLength,
+    OUT struct sockaddr **LocalSockaddr,
+    OUT LPINT LocalSockaddrLength,
+    OUT struct sockaddr **RemoteSockaddr,
+    OUT LPINT RemoteSockaddrLength
+    );
+
+#define WSAID_GETACCEPTEXSOCKADDRS \
+        {0xb5367df2,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
+
+#endif
+
+
+#ifndef LPFN_TRANSMITFILE
+
+typedef BOOL (PASCAL FAR * LPFN_TRANSMITFILE)(
+    IN SOCKET hSocket,
+    IN HANDLE hFile,
+    IN DWORD nNumberOfBytesToWrite,
+    IN DWORD nNumberOfBytesPerSend,
+    IN LPOVERLAPPED lpOverlapped,
+    IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
+    IN DWORD dwReserved
+    );
+
+#define WSAID_TRANSMITFILE \
+        {0xb5367df0,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
+
+#endif
+
+
 extern LPFN_ACCEPTEX              acceptex;
 extern LPFN_GETACCEPTEXSOCKADDRS  getacceptexsockaddrs;
 extern LPFN_TRANSMITFILE          transmitfile;
diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h
index b1d7d57..38cca91 100644
--- a/src/os/win32/ngx_win32_config.h
+++ b/src/os/win32/ngx_win32_config.h
@@ -7,13 +7,9 @@
 #define STRICT
 #define WIN32_LEAN_AND_MEAN
 
-#ifdef __WATCOMC__
-#pragma disable_message(107)
-#endif
-
 /*
  * we need to include windows.h explicity before winsock2.h because
- * warning 4201 is enabled in windows.h
+ * the warning 4201 is enabled in windows.h
  */
 #include <windows.h>
 
@@ -35,19 +31,16 @@
 #pragma warning(disable:4100)
 
 /* STUB */
+#if 0
 #pragma warning(disable:4127)
 #endif
+#endif
 
 
 #ifdef __WATCOMC__
-#pragma enable_message(107)
-#if 0
-/* Symbol 'ngx_rbtree_min' has been defined, but not referenced */
+/* disable "Symbol 'ngx_rbtree_min' has been defined, but not referenced" */
 #pragma disable_message(202)
 #endif
-/* No prototype found for 'stricmp' */
-#pragma disable_message(301)
-#endif
 
 #include <ngx_auto_config.h>
 
diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c
index aaeca21..c4ffc11 100644
--- a/src/os/win32/ngx_win32_init.c
+++ b/src/os/win32/ngx_win32_init.c
@@ -17,6 +17,13 @@
 };
 
 
+typedef struct {
+    WORD  wServicePackMinor;
+    WORD  wSuiteMask;
+    BYTE  wProductType;
+} ngx_osviex_stub_t;
+
+
 /* Should these pointers be per protocol ? */
 LPFN_ACCEPTEX              acceptex;
 LPFN_GETACCEPTEXSOCKADDRS  getacceptexsockaddrs;
@@ -29,11 +36,12 @@
 
 int ngx_os_init(ngx_log_t *log)
 {
-    u_int            osviex;
-    DWORD            bytes;
-    SOCKET           s;
-    WSADATA          wsd;
-    OSVERSIONINFOEX  osvi;
+    u_int               osviex;
+    DWORD               bytes;
+    SOCKET              s;
+    WSADATA             wsd;
+    OSVERSIONINFOEX     osvi;
+    ngx_osviex_stub_t  *osviex_stub;
 
     /* get Windows version */
 
@@ -75,17 +83,16 @@
         ngx_win32_version += osvi.wServicePackMajor * 10
                              + osvi.wServicePackMinor;
 
-        ngx_log_error(NGX_LOG_INFO, log, 0,
-                      "OS: %u build:%u, \"%s\", suite:%x, type:%u",
-                      ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
-                      osvi.wReserved[0], osvi.wReserved[1]);
+        /*
+         * the MSVC 6.0 SP2 defines wSuiteMask and wProductType
+         * as WORD wReserved[2]
+         */
+        osviex_stub = (ngx_osviex_stub_t *) &osvi.wServicePackMinor;
 
-#if 0
         ngx_log_error(NGX_LOG_INFO, log, 0,
                       "OS: %u build:%u, \"%s\", suite:%x, type:%u",
                       ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
-                      osvi.wSuiteMask, osvi.wProductType);
-#endif
+                      osviex_stub->wSuiteMask, osviex_stub->wProductType);
 
     } else {
         if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
@@ -123,6 +130,10 @@
         return NGX_ERROR;
     }
 
+    if (ngx_win32_version < NGX_WIN_NT) {
+        return NGX_OK;
+    }
+
     /* get AcceptEx(), GetAcceptExSockAddrs() and TransmitFile() addresses */
 
     s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
diff --git a/src/os/win32/ngx_wsarecv.c b/src/os/win32/ngx_wsarecv.c
index 2de1110..040adc4 100644
--- a/src/os/win32/ngx_wsarecv.c
+++ b/src/os/win32/ngx_wsarecv.c
@@ -64,7 +64,7 @@
     rev = c->read;
 
     if (!rev->ready) {
-        ngx_log_error(NGX_LOG_ALERT, rev->log, 0, "second wsa post");
+        ngx_log_error(NGX_LOG_ALERT, c->log, 0, "second wsa post");
         return NGX_AGAIN;
     }