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 812234e2f5
commit 38a7faadfe

View File

@ -59,26 +59,33 @@ ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
ssize_t
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,
"write: %d, %p, %uz, %O", file->fd, buf, size, offset);
written = 0;
#if (NGX_HAVE_PWRITE)
n = pwrite(file->fd, buf, size, offset);
for ( ;; ) {
n = pwrite(file->fd, buf, size, offset);
if (n == -1) {
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
"pwrite() \"%s\" failed", file->name.data);
return NGX_ERROR;
}
if (n == -1) {
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
"pwrite() \"%s\" failed", file->name.data);
return NGX_ERROR;
}
if ((size_t) n != size) {
ngx_log_error(NGX_LOG_CRIT, file->log, 0,
"pwrite() \"%s\" has written only %z of %uz",
file->name.data, n, size);
return NGX_ERROR;
file->offset += n;
written += n;
if ((size_t) n == size) {
return written;
}
offset += n;
size -= n;
}
#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;
}
n = write(file->fd, buf, size);
for ( ;; ) {
n = write(file->fd, buf, size);
if (n == -1) {
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
"write() \"%s\" failed", file->name.data);
return NGX_ERROR;
if (n == -1) {
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
"write() \"%s\" failed", file->name.data);
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
file->offset += n;
return n;
}