summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-09-19 03:33:47 +0000
committerJeremy Allison <jra@samba.org>2001-09-19 03:33:47 +0000
commit0e75c0fc1aa742fb0c29716c99a81cf5b33ef6e6 (patch)
tree5e1010389e758f10dbe9c7b1b650affa8970fe84
parent1a04ea247680fa7ad1ae7dc3f9953f753d8cf955 (diff)
downloadsamba-0e75c0fc1aa742fb0c29716c99a81cf5b33ef6e6.tar.gz
samba-0e75c0fc1aa742fb0c29716c99a81cf5b33ef6e6.tar.xz
samba-0e75c0fc1aa742fb0c29716c99a81cf5b33ef6e6.zip
Fix based on Andrew's insight as re-using a tdb after fork means
parent and child share seek pointer. Damn.... Jeremy.
-rw-r--r--source/tdb/tdb.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/source/tdb/tdb.c b/source/tdb/tdb.c
index 4714844758c..bb589509489 100644
--- a/source/tdb/tdb.c
+++ b/source/tdb/tdb.c
@@ -281,8 +281,12 @@ static int tdb_write(TDB_CONTEXT *tdb, tdb_off off, void *buf, tdb_len len)
if (tdb->map_ptr)
memcpy(off + (char *)tdb->map_ptr, buf, len);
+#ifdef HAVE_PWRITE
+ else if (pwrite(tdb->fd, buf, len, off) != (ssize_t)len) {
+#else
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| write(tdb->fd, buf, len) != (ssize_t)len) {
+#endif
TDB_LOG((tdb, 0,"tdb_write failed at %d len=%d (%s)\n",
off, len, strerror(errno)));
return TDB_ERRCODE(TDB_ERR_IO, -1);
@@ -298,8 +302,12 @@ static int tdb_read(TDB_CONTEXT *tdb,tdb_off off,void *buf,tdb_len len,int cv)
if (tdb->map_ptr)
memcpy(buf, off + (char *)tdb->map_ptr, len);
+#ifdef HAVE_PREAD
+ else if (pread(tdb->fd, buf, len, off) != (ssize_t)len) {
+#else
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| read(tdb->fd, buf, len) != (ssize_t)len) {
+#endif
TDB_LOG((tdb, 0,"tdb_read failed at %d len=%d (%s)\n",
off, len, strerror(errno)));
return TDB_ERRCODE(TDB_ERR_IO, -1);
@@ -602,27 +610,39 @@ static int expand_file(TDB_CONTEXT *tdb, tdb_off size, tdb_off addition)
}
#else
char b = 0;
+
+#ifdef HAVE_PWRITE
+ if (pwrite(tdb->fd, &b, 1, (size+addition) - 1) != 1) {
+#else
if (lseek(tdb->fd, (size+addition) - 1, SEEK_SET) != (size+addition) - 1 ||
write(tdb->fd, &b, 1) != 1) {
+#endif
TDB_LOG((tdb, 0, "expand_file to %d failed (%s)\n",
size+addition, strerror(errno)));
return -1;
}
#endif
+
/* now fill the file with something. This ensures that the file isn't sparse, which would be
very bad if we ran out of disk. This must be done with write, not via mmap */
memset(buf, 0x42, sizeof(buf));
- if (lseek(tdb->fd, size, SEEK_SET) != size)
- return -1;
while (addition) {
int n = addition>sizeof(buf)?sizeof(buf):addition;
- int ret = write(tdb->fd, buf, n);
+#ifdef HAVE_PWRITE
+ int ret = pwrite(tdb->fd, buf, n, size);
+#else
+ int ret;
+ if (lseek(tdb->fd, size, SEEK_SET) != size)
+ return -1;
+ ret = write(tdb->fd, buf, n);
+#endif
if (ret != n) {
TDB_LOG((tdb, 0, "expand_file write of %d failed (%s)\n",
n, strerror(errno)));
return -1;
}
addition -= n;
+ size += n;
}
return 0;
}