diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2010-05-05 15:37:18 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2010-05-05 15:37:18 +0930 |
commit | 91e4a1760dee22e9a40ca52f1e5a1b549d9e066d (patch) | |
tree | 879c390a4be016332c981a4392eaa2a5175a3117 /lib/tdb/common/open.c | |
parent | a9e008ee36c8fd9ca79b3bdfdc78111939c3e539 (diff) | |
download | samba-91e4a1760dee22e9a40ca52f1e5a1b549d9e066d.tar.gz samba-91e4a1760dee22e9a40ca52f1e5a1b549d9e066d.tar.bz2 samba-91e4a1760dee22e9a40ca52f1e5a1b549d9e066d.zip |
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 <metze@samba.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb/common/open.c')
-rw-r--r-- | lib/tdb/common/open.c | 16 |
1 files changed, 1 insertions, 15 deletions
diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c index dfe780d21b..3ff6b17c03 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); |