Author: obnox
Date: 2007-07-20 16:31:32 +0000 (Fri, 20 Jul 2007)
New Revision: 23980

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23980

Log:
Fix one more use of pwrite in expand_file.

Michael


Modified:
   branches/SAMBA_3_2/source/lib/tdb/common/io.c
   branches/SAMBA_3_2_0/source/lib/tdb/common/io.c
   branches/SAMBA_4_0/source/lib/tdb/common/io.c


Changeset:
Modified: branches/SAMBA_3_2/source/lib/tdb/common/io.c
===================================================================
--- branches/SAMBA_3_2/source/lib/tdb/common/io.c       2007-07-20 15:00:58 UTC 
(rev 23979)
+++ branches/SAMBA_3_2/source/lib/tdb/common/io.c       2007-07-20 16:31:32 UTC 
(rev 23980)
@@ -220,7 +220,16 @@
 
        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;

Modified: branches/SAMBA_3_2_0/source/lib/tdb/common/io.c
===================================================================
--- branches/SAMBA_3_2_0/source/lib/tdb/common/io.c     2007-07-20 15:00:58 UTC 
(rev 23979)
+++ branches/SAMBA_3_2_0/source/lib/tdb/common/io.c     2007-07-20 16:31:32 UTC 
(rev 23980)
@@ -220,7 +220,16 @@
 
        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;

Modified: branches/SAMBA_4_0/source/lib/tdb/common/io.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/io.c       2007-07-20 15:00:58 UTC 
(rev 23979)
+++ branches/SAMBA_4_0/source/lib/tdb/common/io.c       2007-07-20 16:31:32 UTC 
(rev 23980)
@@ -220,7 +220,16 @@
 
        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;

Reply via email to