[nginx] Handled EINTR from write() and pwrite() syscalls.

Valentin Bartenev vbart at nginx.com
Tue Nov 17 16:02:18 UTC 2015


details:   http://hg.nginx.org/nginx/rev/5170c3040ce1
branches:  
changeset: 6299:5170c3040ce1
user:      Valentin Bartenev <vbart at nginx.com>
date:      Tue Nov 17 19:01:41 2015 +0300
description:
Handled EINTR from write() and pwrite() syscalls.

This is in addition to 6fce16b1fc10.

diffstat:

 src/os/unix/ngx_files.c |  23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diffs (47 lines):

diff -r 8f6d753c1953 -r 5170c3040ce1 src/os/unix/ngx_files.c
--- a/src/os/unix/ngx_files.c	Tue Nov 17 19:01:41 2015 +0300
+++ b/src/os/unix/ngx_files.c	Tue Nov 17 19:01:41 2015 +0300
@@ -176,7 +176,8 @@ ngx_thread_read_handler(void *data, ngx_
 ssize_t
 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
 {
-    ssize_t  n, written;
+    ssize_t    n, written;
+    ngx_err_t  err;
 
     ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
                    "write: %d, %p, %uz, %O", file->fd, buf, size, offset);
@@ -189,7 +190,15 @@ ngx_write_file(ngx_file_t *file, u_char 
         n = pwrite(file->fd, buf + written, size, offset);
 
         if (n == -1) {
-            ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
+            err = ngx_errno;
+
+            if (err == NGX_EINTR) {
+                ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
+                               "pwrite() was interrupted");
+                continue;
+            }
+
+            ngx_log_error(NGX_LOG_CRIT, file->log, err,
                           "pwrite() \"%s\" failed", file->name.data);
             return NGX_ERROR;
         }
@@ -221,7 +230,15 @@ ngx_write_file(ngx_file_t *file, u_char 
         n = write(file->fd, buf + written, size);
 
         if (n == -1) {
-            ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
+            err = ngx_errno;
+
+            if (err == NGX_EINTR) {
+                ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
+                               "write() was interrupted");
+                continue;
+            }
+
+            ngx_log_error(NGX_LOG_CRIT, file->log, err,
                           "write() \"%s\" failed", file->name.data);
             return NGX_ERROR;
         }



More information about the nginx-devel mailing list