nginx-0.0.2-2004-02-03-19:43:54 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 61cc53e..21a22d0 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -82,6 +82,7 @@
 ngx_uint_t  ngx_connection_counter;
 
 ngx_int_t   ngx_process;
+ngx_pid_t   ngx_pid;
 ngx_pid_t   ngx_new_binary;
 
 ngx_int_t   ngx_inherited;
@@ -122,6 +123,7 @@
 #endif
 
     log = ngx_log_init_errlog();
+    ngx_pid = ngx_getpid();
 
     /* init_cycle->log is required for signal handlers */
 
@@ -179,12 +181,6 @@
         }
     }
 
-    if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
-        ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
-                      "dup2(STDERR) failed");
-        return 1;
-    }
-
     if (ccf->pid.len == 0) {
         ccf->pid.len = sizeof(NGINX_PID) - 1;
         ccf->pid.data = NGINX_PID;
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index 796d7a2..b691c3c 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -2,9 +2,6 @@
 #define _NGX_CONFIG_H_INCLUDED_
 
 
-#include <ngx_auto_config.h>
-
-
 #if 1
 /* STUB to allocate a big ngx_connections */
 #undef  FD_SETSIZE
@@ -36,6 +33,8 @@
 
 #else /* posix */
 
+#include <ngx_auto_config.h>
+
 #endif
 
 
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index dcae4a0..8450998 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -228,6 +228,14 @@
         }
     }
 
+    /* TODO: Win32 DuplicateHandle ? */
+    if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
+        ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
+                      "dup2(STDERR) failed");
+        failed = 1;
+    }
+
+
     if (failed) {
 
         /* rollback the new cycle configuration */
@@ -262,6 +270,7 @@
         return NULL;
     }
 
+
     /* commit the new cycle configuration */
 
     pool->log = cycle->log;
@@ -438,6 +447,12 @@
 
         file[i].fd = fd;
     }
+
+    /* TODO: Win32 DuplicateHandle ? */
+    if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
+        ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+                      "dup2(STDERR) failed");
+    }
 }
 
 
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 1f7bb11..a902f1e 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -79,7 +79,7 @@
 
     /* pid#tid */
     len += ngx_snprintf(errstr + len, max - len,
-                        PID_T_FMT "#%d: ", ngx_getpid(), /* STUB */ 0);
+                        PID_T_FMT "#%d: ", ngx_pid, /* STUB */ 0);
 
     if (log->data) {
         len += ngx_snprintf(errstr + len, max - len,