nginx-0.0.2-2004-03-04-10:04:55 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 21363d2..92c938d 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 @@
 #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 @@
 
 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 @@
 }
 
 
+#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 @@
 
 #endif
 
+#endif
+
 
 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp)
 {
@@ -791,7 +797,7 @@
 }
 
 
-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 @@
     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 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 @@
     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 bf771e9..17362aa 100644
--- a/src/core/ngx_atomic.h
+++ b/src/core/ngx_atomic.h
@@ -72,8 +72,8 @@
 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 989a0de..8a85873 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -248,7 +248,12 @@
         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 7735ab1..57bdafc 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -21,6 +21,7 @@
 #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 @@
 #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 017db87..3827c0d 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -24,7 +24,6 @@
 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 @@
         }
     }
 
-    /* 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 @@
 }
 
 
-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 @@
             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 @@
             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 @@
         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 d9f1a60..4d301f9 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -25,12 +25,25 @@
 };
 
 
+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 349fe6b..371c725 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -47,10 +47,10 @@
 
 
 #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 @@
 
 #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 375acae..d1fdab6 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -92,7 +92,7 @@
 #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 @@
 #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 @@
 
 #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, ...);