Compilation errors on Ubuntu 8.10 Intrepid Ibex

Maxim Dounin mdounin at mdounin.ru
Tue Nov 11 03:30:15 MSK 2008


Hello!

[... warn_unused_result discussion skipped ...]

What about attached patch instead?  Actually, there is only 1 
place where we really can't do anything - write() while logging 
error.  In other places sensible behaviour is possible.

Maxim Dounin
-------------- next part --------------
diff --git a/src/core/nginx.c b/src/core/nginx.c
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -240,22 +240,34 @@ main(int argc, char *const *argv)
     }
 
     if (ngx_show_version) {
-        ngx_write_fd(ngx_stderr_fileno, "nginx version: " NGINX_VER CRLF,
-                     sizeof("nginx version: " NGINX_VER CRLF) - 1);
+        if (ngx_write_fd(ngx_stderr_fileno, "nginx version: " NGINX_VER CRLF,
+                         sizeof("nginx version: " NGINX_VER CRLF) - 1)
+            != sizeof("nginx version: " NGINX_VER CRLF) - 1)
+        {
+            return 1;
+        }
 
         if (ngx_show_configure) {
 #ifdef NGX_COMPILER
-            ngx_write_fd(ngx_stderr_fileno, "built by " NGX_COMPILER CRLF,
-                         sizeof("built by " NGX_COMPILER CRLF) - 1);
+            if (ngx_write_fd(ngx_stderr_fileno, "built by " NGX_COMPILER CRLF,
+                             sizeof("built by " NGX_COMPILER CRLF) - 1)
+                != sizeof("built by " NGX_COMPILER CRLF) - 1)
+            {
+                return 1;
+            }
 #endif
 
 #ifndef __WATCOMC__
 
             /* OpenWatcomC could not build the long NGX_CONFIGURE string */
 
-            ngx_write_fd(ngx_stderr_fileno,
+            if (ngx_write_fd(ngx_stderr_fileno,
                         "configure arguments: " NGX_CONFIGURE CRLF,
-                        sizeof("configure arguments :" NGX_CONFIGURE CRLF) - 1);
+                        sizeof("configure arguments :" NGX_CONFIGURE CRLF) - 1)
+                != sizeof("configure arguments :" NGX_CONFIGURE CRLF) - 1)
+            {
+                return 1;
+            }
 #endif
         }
 
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -912,6 +912,7 @@ static void
 static void
 ngx_conf_flush_files(ngx_cycle_t *cycle)
 {
+    ngx_int_t         n;
     ngx_uint_t        i;
     ngx_list_part_t  *part;
     ngx_open_file_t  *file;
@@ -936,7 +937,17 @@ ngx_conf_flush_files(ngx_cycle_t *cycle)
             continue;
         }
 
-        ngx_write_fd(file[i].fd, file[i].buffer, file[i].pos - file[i].buffer);
+        n = ngx_write_fd(file[i].fd, file[i].buffer, file[i].pos - file[i].buffer);
+
+        if (n == NGX_FILE_ERROR) {
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                          ngx_write_fd_n " to \"%s\" failed", file[i].name.data);
+
+        } else if (n != file[i].pos - file[i].buffer) {
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
+                          ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
+                          file[i].name.data, n, file[i].pos - file[i].buffer);
+        }
     }
 }
 
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -997,6 +997,7 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx
 ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
 {
     ngx_fd_t          fd;
+    ngx_int_t         n;
     ngx_uint_t        i;
     ngx_list_part_t  *part;
     ngx_open_file_t  *file;
@@ -1020,8 +1021,19 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx
         }
 
         if (file[i].buffer && file[i].pos - file[i].buffer != 0) {
-            ngx_write_fd(file[i].fd, file[i].buffer,
-                         file[i].pos - file[i].buffer);
+            n = ngx_write_fd(file[i].fd, file[i].buffer,
+                             file[i].pos - file[i].buffer);
+
+            if (n == NGX_FILE_ERROR) {
+                ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                              ngx_write_fd_n " to \"%s\" failed", file[i].name.data);
+
+            } else if (n != file[i].pos - file[i].buffer) {
+                ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
+                              ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
+                              file[i].name.data, n, file[i].pos - file[i].buffer);
+            }
+
             file[i].pos = file[i].buffer;
         }
 
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -158,7 +158,9 @@ ngx_log_error_core(ngx_uint_t level, ngx
 
     ngx_linefeed(p);
 
-    ngx_write_fd(log->file->fd, errstr, p - errstr);
+    if (ngx_write_fd(log->file->fd, errstr, p - errstr) == NGX_FILE_ERROR) {
+        /* error logging error - ignore */
+    }
 }
 
 


More information about the nginx mailing list