The branch, master has been updated
       via  91e4a17... tdb: fix short write logic in tdb_new_database
      from  a9e008e... Fix bug #7263 - Unable to print using Samba 3.5.1 and 
cups-1.1.23-40.46 on SLES10.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 91e4a1760dee22e9a40ca52f1e5a1b549d9e066d
Author: Rusty Russell <[email protected]>
Date:   Wed May 5 15:37:18 2010 +0930

    tdb: fix short write logic in tdb_new_database
    
    Commit 207a213c/24fed55d purported to fix the problem of signals during
    tdb_new_database (which could cause a spurious short write, hence a 
failure).
    However, the code is wrong: newdb+written is not correct.
    
    Fix this by introducing a general tdb_write_all() and using it here and in
    the tracing code.
    
    Cc: Stefan Metzmacher <[email protected]>
    Signed-off-by: Rusty Russell <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 lib/tdb/common/open.c        |   16 +---------------
 lib/tdb/common/tdb.c         |   16 +++++++++++++++-
 lib/tdb/common/tdb_private.h |    2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c
index dfe780d..3ff6b17 100644
--- a/lib/tdb/common/open.c
+++ b/lib/tdb/common/open.c
@@ -83,22 +83,8 @@ static int tdb_new_database(struct tdb_context *tdb, int 
hash_size)
        /* Don't endian-convert the magic food! */
        memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
        /* we still have "ret == -1" here */
-       written = write(tdb->fd, newdb, size);
-       if (written == size) {
+       if (tdb_write_all(tdb->fd, newdb, size))
                ret = 0;
-       } else if (written != -1) {
-               /* call write once again, this usually should return -1 and
-                * set errno appropriately */
-               size -= written;
-               written = write(tdb->fd, newdb+written, size);
-               if (written == size) {
-                       ret = 0;
-               } else if (written >= 0) {
-                       /* a second incomplete write - we give up.
-                        * guessing the errno... */
-                       errno = ENOSPC;
-               }
-       }
 
   fail:
        SAFE_FREE(newdb);
diff --git a/lib/tdb/common/tdb.c b/lib/tdb/common/tdb.c
index dac3f4e..4d8c5fc 100644
--- a/lib/tdb/common/tdb.c
+++ b/lib/tdb/common/tdb.c
@@ -989,10 +989,24 @@ int tdb_repack(struct tdb_context *tdb)
        return 0;
 }
 
+/* Even on files, we can get partial writes due to signals. */
+bool tdb_write_all(int fd, const void *buf, size_t count)
+{
+       while (count) {
+               size_t ret;
+               ret = write(fd, buf, count);
+               if (ret < 0)
+                       return false;
+               buf = (const char *)buf + ret;
+               count -= ret;
+       }
+       return true;
+}
+
 #ifdef TDB_TRACE
 static void tdb_trace_write(struct tdb_context *tdb, const char *str)
 {
-       if (write(tdb->tracefd, str, strlen(str)) != strlen(str)) {
+       if (!tdb_write_alltdb->tracefd, str, strlen(str)) {
                close(tdb->tracefd);
                tdb->tracefd = -1;
        }
diff --git a/lib/tdb/common/tdb_private.h b/lib/tdb/common/tdb_private.h
index e216713..9d0f3bc 100644
--- a/lib/tdb/common/tdb_private.h
+++ b/lib/tdb/common/tdb_private.h
@@ -266,5 +266,5 @@ void tdb_io_init(struct tdb_context *tdb);
 int tdb_expand(struct tdb_context *tdb, tdb_off_t size);
 int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off,
                      struct tdb_record *rec);
-
+bool tdb_write_all(int fd, const void *buf, size_t count);
 int tdb_transaction_recover(struct tdb_context *tdb);


-- 
Samba Shared Repository

Reply via email to