r23980: Fix one more use of pwrite in expand_file.
authorMichael Adam <obnox@samba.org>
Fri, 20 Jul 2007 16:31:32 +0000 (16:31 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:28:52 +0000 (12:28 -0500)
Michael

source/lib/tdb/common/io.c

index a24b5e24a2d30394bb7d86acc97e73e9d696ccf4..df924a9dcd7ee98beaf15ce35c8f4be353bb45ad 100644 (file)
@@ -220,7 +220,16 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad
 
        if (ftruncate(tdb->fd, size+addition) == -1) {
                char b = 0;
-               if (pwrite(tdb->fd,  &b, 1, (size+addition) - 1) != 1) {
+               ssize_t written = pwrite(tdb->fd,  &b, 1, (size+addition) - 1);
+               if (written == 0) {
+                       /* try once more, potentially revealing errno */
+                       written = pwrite(tdb->fd,  &b, 1, (size+addition) - 1);
+               }
+               if (written == 0) {
+                       /* again - give up, guessing errno */
+                       errno = ENOSPC;
+               }
+               if (written != 1) {
                        TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %d failed (%s)\n", 
                                 size+addition, strerror(errno)));
                        return -1;