handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
This commit is contained in:
parent
03f5b99e8f
commit
3629664881
1 changed files with 35 additions and 31 deletions
|
@ -59,13 +59,16 @@ 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)
|
||||||
|
|
||||||
|
for ( ;; ) {
|
||||||
n = pwrite(file->fd, buf, size, offset);
|
n = pwrite(file->fd, buf, size, offset);
|
||||||
|
|
||||||
if (n == -1) {
|
if (n == -1) {
|
||||||
|
@ -74,11 +77,15 @@ ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
|
||||||
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,6 +100,7 @@ ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
|
||||||
file->sys_offset = offset;
|
file->sys_offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for ( ;; ) {
|
||||||
n = write(file->fd, buf, size);
|
n = write(file->fd, buf, size);
|
||||||
|
|
||||||
if (n == -1) {
|
if (n == -1) {
|
||||||
|
@ -101,20 +109,16 @@ ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
|
||||||
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;
|
||||||
"write() \"%s\" has written only %z of %uz",
|
|
||||||
file->name.data, n, size);
|
if ((size_t) n == size) {
|
||||||
return NGX_ERROR;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
file->sys_offset += n;
|
size -= n;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
file->offset += n;
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue