[PATCH] Fix tdb_check() to work with read-only tdb databases. The function tdb_lockall() uses F_WRLCK internally, which doesn't work on a fd opened with O_RDONLY. In this case use tdb_lockall_read() instead.

Jeremy Allison jra at samba.org
Wed Jul 28 04:01:40 MDT 2010


Jeremy.
---
 lib/tdb/common/check.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/lib/tdb/common/check.c b/lib/tdb/common/check.c
index 6bbfd7d..020bd84 100644
--- a/lib/tdb/common/check.c
+++ b/lib/tdb/common/check.c
@@ -310,9 +310,17 @@ int tdb_check(struct tdb_context *tdb,
 	tdb_off_t off, recovery_start;
 	struct tdb_record rec;
 	bool found_recovery = false;
+	int ret;
 
-	if (tdb_lockall(tdb) == -1)
+	if (tdb->read_only) {
+		ret = tdb_lockall_read(tdb);
+	} else {
+		ret = tdb_lockall(tdb);
+	}
+
+	if (ret == -1) {
 		return -1;
+	}
 
 	/* Make sure we know true size of the underlying file. */
 	tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1);
@@ -412,12 +420,20 @@ int tdb_check(struct tdb_context *tdb,
 	}
 
 	free(hashes);
-	tdb_unlockall(tdb);
+	if (tdb->read_only) {
+		tdb_unlockall_read(tdb);
+	} else {
+		tdb_unlockall(tdb);
+	}
 	return 0;
 
 free:
 	free(hashes);
 unlock:
-	tdb_unlockall(tdb);
+	if (tdb->read_only) {
+		tdb_unlockall_read(tdb);
+	} else {
+		tdb_unlockall(tdb);
+	}
 	return -1;
 }
-- 
1.7.0.4


--OXfL5xGRrasGEqWY--


More information about the samba-technical mailing list