]> git.kaiwu.me - nginx.git/commitdiff
Fixed handling of ngx_write_fd() and ngx_read_fd() errors.
authorValentin Bartenev <vbart@nginx.com>
Fri, 14 Dec 2012 15:24:24 +0000 (15:24 +0000)
committerValentin Bartenev <vbart@nginx.com>
Fri, 14 Dec 2012 15:24:24 +0000 (15:24 +0000)
The ngx_write_fd() and ngx_read_fd() functions return -1 in case of error,
so the incorrect comparison with NGX_FILE_ERROR (which is 0 on windows
platforms) might result in inaccurate error message in the error log.

Also the ngx_errno global variable is being set only if the returned value
is -1.

src/core/ngx_conf_file.c
src/core/ngx_cycle.c
src/core/ngx_file.c

index 6da2dae809db085b6d040cdfe0026c41e39886e7..12bb5cf8a5dca4f926d8b78608b70d14b825aa10 100644 (file)
@@ -983,7 +983,7 @@ ngx_conf_flush_files(ngx_cycle_t *cycle)
 
         n = ngx_write_fd(file[i].fd, file[i].buffer, len);
 
-        if (n == NGX_FILE_ERROR) {
+        if (n == -1) {
             ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
                           ngx_write_fd_n " to \"%s\" failed",
                           file[i].name.data);
index e8b1559212bc22ce3102f6dbfb5142177842b411..e5dad4607da75a18844f496c4c5a15796dc9c65b 100644 (file)
@@ -1145,7 +1145,7 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
 
             n = ngx_write_fd(file[i].fd, file[i].buffer, len);
 
-            if (n == NGX_FILE_ERROR) {
+            if (n == -1) {
                 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
                               ngx_write_fd_n " to \"%s\" failed",
                               file[i].name.data);
index f13fb495234b0aace51791c0581b21d9461cd818..35f5f8dc38b119173603e7d77b2f25dcbb9c4e41 100644 (file)
@@ -732,14 +732,14 @@ ngx_copy_file(u_char *from, u_char *to, ngx_copy_file_t *cf)
 
         n = ngx_read_fd(fd, buf, len);
 
-        if (n == NGX_FILE_ERROR) {
+        if (n == -1) {
             ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
                           ngx_read_fd_n " \"%s\" failed", from);
             goto failed;
         }
 
         if ((size_t) n != len) {
-            ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
+            ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
                           ngx_read_fd_n " has read only %z of %uz from %s",
                           n, size, from);
             goto failed;
@@ -747,14 +747,14 @@ ngx_copy_file(u_char *from, u_char *to, ngx_copy_file_t *cf)
 
         n = ngx_write_fd(nfd, buf, len);
 
-        if (n == NGX_FILE_ERROR) {
+        if (n == -1) {
             ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
                           ngx_write_fd_n " \"%s\" failed", to);
             goto failed;
         }
 
         if ((size_t) n != len) {
-            ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
+            ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
                           ngx_write_fd_n " has written only %z of %uz to %s",
                           n, size, to);
             goto failed;