--- src/core/ngx_cycle.c.orig	2011-01-03 19:24:20.000000000 +0200
+++ src/core/ngx_cycle.c	2011-01-03 19:27:50.000000000 +0200
@@ -1187,11 +1187,13 @@
                 }
             }
 
-            if (fi.st_uid != user) {
-                if (chown((const char *) file[i].name.data, user, -1) == -1) {
+            if ((fi.st_mode & S_IRWXU) != S_IWUSR) {
+
+                fi.st_mode = (fi.st_mode & ~S_IRWXU) | S_IWUSR;
+
+                if (chmod((const char *) file[i].name.data, fi.st_mode) == -1) {
                     ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
-                                  "chown(\"%s\", %d) failed",
-                                  file[i].name.data, user);
+                                  "chmod() \"%s\" failed", file[i].name.data);
 
                     if (ngx_close_file(fd) == NGX_FILE_ERROR) {
                         ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
@@ -1201,13 +1203,11 @@
                 }
             }
 
-            if ((fi.st_mode & S_IRWXU) != S_IWUSR) {
-
-                fi.st_mode = (fi.st_mode & ~S_IRWXU) | S_IWUSR;
-
-                if (chmod((const char *) file[i].name.data, fi.st_mode) == -1) {
+            if (fi.st_uid != user) {
+                if (chown((const char *) file[i].name.data, user, -1) == -1) {
                     ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
-                                  "chmod() \"%s\" failed", file[i].name.data);
+                                  "chown(\"%s\", %d) failed",
+                                  file[i].name.data, user);
 
                     if (ngx_close_file(fd) == NGX_FILE_ERROR) {
                         ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,