comparison src/core/ngx_file.c @ 4966:c821975c9068

Fixed handling of ngx_write_fd() and ngx_read_fd() errors. 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.
author Valentin Bartenev <vbart@nginx.com>
date Fri, 14 Dec 2012 15:24:24 +0000
parents 8a9b7b4e9f2d
children 12dd27b74117
comparison
equal deleted inserted replaced
4965:58dfef910ccd 4966:c821975c9068
730 len = (size_t) size; 730 len = (size_t) size;
731 } 731 }
732 732
733 n = ngx_read_fd(fd, buf, len); 733 n = ngx_read_fd(fd, buf, len);
734 734
735 if (n == NGX_FILE_ERROR) { 735 if (n == -1) {
736 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, 736 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
737 ngx_read_fd_n " \"%s\" failed", from); 737 ngx_read_fd_n " \"%s\" failed", from);
738 goto failed; 738 goto failed;
739 } 739 }
740 740
741 if ((size_t) n != len) { 741 if ((size_t) n != len) {
742 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, 742 ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
743 ngx_read_fd_n " has read only %z of %uz from %s", 743 ngx_read_fd_n " has read only %z of %uz from %s",
744 n, size, from); 744 n, size, from);
745 goto failed; 745 goto failed;
746 } 746 }
747 747
748 n = ngx_write_fd(nfd, buf, len); 748 n = ngx_write_fd(nfd, buf, len);
749 749
750 if (n == NGX_FILE_ERROR) { 750 if (n == -1) {
751 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, 751 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
752 ngx_write_fd_n " \"%s\" failed", to); 752 ngx_write_fd_n " \"%s\" failed", to);
753 goto failed; 753 goto failed;
754 } 754 }
755 755
756 if ((size_t) n != len) { 756 if ((size_t) n != len) {
757 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, 757 ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
758 ngx_write_fd_n " has written only %z of %uz to %s", 758 ngx_write_fd_n " has written only %z of %uz to %s",
759 n, size, to); 759 n, size, to);
760 goto failed; 760 goto failed;
761 } 761 }
762 762