diff options
author | Jeremy Allison <jra@samba.org> | 2001-09-19 03:33:47 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2001-09-19 03:33:47 +0000 |
commit | af0d86a9fc2b8a6094bdf79d071f71a8532a1dc9 (patch) | |
tree | ee01f74ae5047045f8e6d359ddfb9afba170951b /source3 | |
parent | 3e9bcd111df39a5801193bd79d22f7fbacaade45 (diff) | |
download | samba-af0d86a9fc2b8a6094bdf79d071f71a8532a1dc9.tar.gz samba-af0d86a9fc2b8a6094bdf79d071f71a8532a1dc9.tar.bz2 samba-af0d86a9fc2b8a6094bdf79d071f71a8532a1dc9.zip |
Fix based on Andrew's insight as re-using a tdb after fork means
parent and child share seek pointer. Damn....
Jeremy.
(This used to be commit 0e75c0fc1aa742fb0c29716c99a81cf5b33ef6e6)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/tdb/tdb.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c index 4714844758..bb58950948 100644 --- a/source3/tdb/tdb.c +++ b/source3/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; } |