summaryrefslogtreecommitdiff
path: root/source3/lib/tdb/common
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2007-08-28 14:25:46 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:30:16 -0500
commitc7489a5d96b20c0d9437560978de03e8ff38abd7 (patch)
treebe8a8b81e09b3e695955cbdbd446d5d46ed1d6da /source3/lib/tdb/common
parent1c72c4c360b6443f5b9705f2781fa9917492537e (diff)
downloadsamba-c7489a5d96b20c0d9437560978de03e8ff38abd7.tar.gz
samba-c7489a5d96b20c0d9437560978de03e8ff38abd7.tar.bz2
samba-c7489a5d96b20c0d9437560978de03e8ff38abd7.zip
r24738: Fix one more use of pwrite in tdb code in the spirit of r23972 and r23977.
Michael (This used to be commit a3506f291abfb8a9516b79c10c79841a7391651e)
Diffstat (limited to 'source3/lib/tdb/common')
-rw-r--r--source3/lib/tdb/common/io.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/source3/lib/tdb/common/io.c b/source3/lib/tdb/common/io.c
index c8ea26c06c..40b0288ba8 100644
--- a/source3/lib/tdb/common/io.c
+++ b/source3/lib/tdb/common/io.c
@@ -88,12 +88,31 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
if (tdb->map_ptr) {
memcpy(off + (char *)tdb->map_ptr, buf, len);
- } else if (pwrite(tdb->fd, buf, len, off) != (ssize_t)len) {
- /* Ensure ecode is set for log fn. */
- tdb->ecode = TDB_ERR_IO;
- TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d len=%d (%s)\n",
- off, len, strerror(errno)));
- return TDB_ERRCODE(TDB_ERR_IO, -1);
+ } 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. */
+ tdb->ecode = TDB_ERR_IO;
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d "
+ "len=%d (%s)\n", off, len, strerror(errno)));
+ 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;
}