mirror of
https://github.com/samba-team/samba.git
synced 2025-03-01 04:58:35 +03:00
r24738: Fix one more use of pwrite in tdb code in the spirit of r23972 and r23977.
Michael (This used to be commit 7b2cabea55cebb98e0fcee17066a0871667cd83f)
This commit is contained in:
parent
9cca9ddc79
commit
8277256cee
@ -88,12 +88,31 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
|
|||||||
|
|
||||||
if (tdb->map_ptr) {
|
if (tdb->map_ptr) {
|
||||||
memcpy(off + (char *)tdb->map_ptr, buf, len);
|
memcpy(off + (char *)tdb->map_ptr, buf, len);
|
||||||
} else if (pwrite(tdb->fd, buf, len, off) != (ssize_t)len) {
|
} else {
|
||||||
|
ssize_t written = pwrite(tdb->fd, buf, len, off);
|
||||||
|
if ((written != (ssize_t)len) && (written != -1)) {
|
||||||
|
/* try once more */
|
||||||
|
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: wrote only "
|
||||||
|
"%d of %d bytes at %d, trying once more\n",
|
||||||
|
written, len, off));
|
||||||
|
errno = ENOSPC;
|
||||||
|
written = pwrite(tdb->fd, (void *)((char *)buf+written),
|
||||||
|
len-written,
|
||||||
|
off+written);
|
||||||
|
}
|
||||||
|
if (written == -1) {
|
||||||
/* Ensure ecode is set for log fn. */
|
/* Ensure ecode is set for log fn. */
|
||||||
tdb->ecode = TDB_ERR_IO;
|
tdb->ecode = TDB_ERR_IO;
|
||||||
TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d len=%d (%s)\n",
|
TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d "
|
||||||
off, len, strerror(errno)));
|
"len=%d (%s)\n", off, len, strerror(errno)));
|
||||||
return TDB_ERRCODE(TDB_ERR_IO, -1);
|
return TDB_ERRCODE(TDB_ERR_IO, -1);
|
||||||
|
} else if (written != (ssize_t)len) {
|
||||||
|
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: failed to "
|
||||||
|
"write %d bytes at %d in two attempts\n",
|
||||||
|
len, off));
|
||||||
|
errno = ENOSPC;
|
||||||
|
return TDB_ERRCODE(TDB_ERR_IO, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user