handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG

This commit is contained in:
Igor Sysoev 2009-09-25 13:55:46 +00:00
parent 03f5b99e8f
commit 3629664881

View file

@ -59,26 +59,33 @@ ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
ssize_t ssize_t
ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
{ {
ssize_t n; ssize_t n, written;
ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
"write: %d, %p, %uz, %O", file->fd, buf, size, offset); "write: %d, %p, %uz, %O", file->fd, buf, size, offset);
written = 0;
#if (NGX_HAVE_PWRITE) #if (NGX_HAVE_PWRITE)
n = pwrite(file->fd, buf, size, offset); for ( ;; ) {
n = pwrite(file->fd, buf, size, offset);
if (n == -1) { if (n == -1) {
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
"pwrite() \"%s\" failed", file->name.data); "pwrite() \"%s\" failed", file->name.data);
return NGX_ERROR; return NGX_ERROR;
} }
if ((size_t) n != size) { file->offset += n;
ngx_log_error(NGX_LOG_CRIT, file->log, 0, written += n;
"pwrite() \"%s\" has written only %z of %uz",
file->name.data, n, size); if ((size_t) n == size) {
return NGX_ERROR; return written;
}
offset += n;
size -= n;
} }
#else #else
@ -93,28 +100,25 @@ ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
file->sys_offset = offset; file->sys_offset = offset;
} }
n = write(file->fd, buf, size); for ( ;; ) {
n = write(file->fd, buf, size);
if (n == -1) { if (n == -1) {
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
"write() \"%s\" failed", file->name.data); "write() \"%s\" failed", file->name.data);
return NGX_ERROR; return NGX_ERROR;
}
file->offset += n;
written += n;
if ((size_t) n == size) {
return written;
}
size -= n;
} }
if ((size_t) n != size) {
ngx_log_error(NGX_LOG_CRIT, file->log, 0,
"write() \"%s\" has written only %z of %uz",
file->name.data, n, size);
return NGX_ERROR;
}
file->sys_offset += n;
#endif #endif
file->offset += n;
return n;
} }