]> git.kaiwu.me - nginx.git/commitdiff
Core: added disk_full_time checks to error log.
authorMaxim Dounin <mdounin@mdounin.ru>
Tue, 13 Jan 2015 16:51:37 +0000 (19:51 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Tue, 13 Jan 2015 16:51:37 +0000 (19:51 +0300)
src/core/ngx_log.c
src/core/ngx_log.h

index 005d9ff88dcfd7d038ecd7bb5538589f573295a2..0cf235998e499a7fb1bc57f32e3ff7503ad9dd47 100644 (file)
@@ -91,8 +91,9 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
     va_list      args;
 #endif
     u_char      *p, *last, *msg;
-    u_char       errstr[NGX_MAX_ERROR_STR];
+    ssize_t      n;
     ngx_uint_t   wrote_stderr, debug_connection;
+    u_char       errstr[NGX_MAX_ERROR_STR];
 
     last = errstr + NGX_MAX_ERROR_STR;
 
@@ -150,16 +151,32 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
 
         if (log->writer) {
             log->writer(log, level, errstr, p - errstr);
-            log = log->next;
-            continue;
+            goto next;
         }
 
-        (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
+        if (ngx_time() == log->disk_full_time) {
+
+            /*
+             * on FreeBSD writing to a full filesystem with enabled softupdates
+             * may block process for much longer time than writing to non-full
+             * filesystem, so we skip writing to a log for one second
+             */
+
+            goto next;
+        }
+
+        n = ngx_write_fd(log->file->fd, errstr, p - errstr);
+
+        if (n == -1 && ngx_errno == NGX_ENOSPC) {
+            log->disk_full_time = ngx_time();
+        }
 
         if (log->file->fd == ngx_stderr) {
             wrote_stderr = 1;
         }
 
+    next:
+
         log = log->next;
     }
 
index 95ecca52843071bd9777c2a548d0e7f7a852a0dd..6b04b78764f0fc61a49010c46e93d2073a4b1e42 100644 (file)
@@ -53,6 +53,8 @@ struct ngx_log_s {
 
     ngx_atomic_uint_t    connection;
 
+    time_t               disk_full_time;
+
     ngx_log_handler_pt   handler;
     void                *data;