summaryrefslogtreecommitdiff
path: root/source3/tdb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-02-20 18:54:12 +0000
committerJeremy Allison <jra@samba.org>2003-02-20 18:54:12 +0000
commit14401bb368464295936bd18fb011d551a36576ce (patch)
tree6a554d34a4ef96ba9e3b5505de4aadbfec6dadb7 /source3/tdb
parentd7b4f389e98e6b9cf32965e4ff41d39aa0d2cd4b (diff)
downloadsamba-14401bb368464295936bd18fb011d551a36576ce.tar.gz
samba-14401bb368464295936bd18fb011d551a36576ce.tar.bz2
samba-14401bb368464295936bd18fb011d551a36576ce.zip
Ensure tdb error code is set for corrupt and i/o errors before calling
the log function. This allows the log function to take action. Jeremy. (This used to be commit 0fa310cbc3f7ced0b15be0ffaeb70dc82e1d5d12)
Diffstat (limited to 'source3/tdb')
-rw-r--r--source3/tdb/tdb.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c
index 8410538f01..097209ff7a 100644
--- a/source3/tdb/tdb.c
+++ b/source3/tdb/tdb.c
@@ -205,6 +205,11 @@ static int tdb_brlock(TDB_CONTEXT *tdb, tdb_off offset,
if (ret == -1) {
if (!probe && lck_type != F_SETLK) {
+ /* Ensure error code is set for log fun to examine. */
+ if (errno == EINTR && palarm_fired && *palarm_fired)
+ tdb->ecode = TDB_ERR_LOCK_TIMEOUT;
+ else
+ tdb->ecode = TDB_ERR_LOCK;
TDB_LOG((tdb, 5,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d\n",
tdb->fd, offset, rw_type, lck_type));
}
@@ -312,6 +317,8 @@ static int tdb_oob(TDB_CONTEXT *tdb, tdb_off len, int probe)
return 0;
if (tdb->flags & TDB_INTERNAL) {
if (!probe) {
+ /* Ensure ecode is set for log fn. */
+ tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, 0,"tdb_oob len %d beyond internal malloc size %d\n",
(int)len, (int)tdb->map_size));
}
@@ -323,6 +330,8 @@ static int tdb_oob(TDB_CONTEXT *tdb, tdb_off len, int probe)
if (st.st_size < (size_t)len) {
if (!probe) {
+ /* Ensure ecode is set for log fn. */
+ tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, 0,"tdb_oob len %d beyond eof at %d\n",
(int)len, (int)st.st_size));
}
@@ -351,6 +360,8 @@ static int tdb_write(TDB_CONTEXT *tdb, tdb_off off, void *buf, tdb_len len)
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| write(tdb->fd, buf, len) != (ssize_t)len) {
#endif
+ /* Ensure ecode is set for log fn. */
+ tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, 0,"tdb_write failed at %d len=%d (%s)\n",
off, len, strerror(errno)));
return TDB_ERRCODE(TDB_ERR_IO, -1);
@@ -372,6 +383,8 @@ static int tdb_read(TDB_CONTEXT *tdb,tdb_off off,void *buf,tdb_len len,int cv)
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| read(tdb->fd, buf, len) != (ssize_t)len) {
#endif
+ /* Ensure ecode is set for log fn. */
+ tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, 0,"tdb_read failed at %d len=%d (%s)\n",
off, len, strerror(errno)));
return TDB_ERRCODE(TDB_ERR_IO, -1);
@@ -387,6 +400,8 @@ static char *tdb_alloc_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_len len)
char *buf;
if (!(buf = malloc(len))) {
+ /* Ensure ecode is set for log fn. */
+ tdb->ecode = TDB_ERR_OOM;
TDB_LOG((tdb, 0,"tdb_alloc_read malloc failed len=%d (%s)\n",
len, strerror(errno)));
return TDB_ERRCODE(TDB_ERR_OOM, buf);
@@ -415,6 +430,8 @@ static int rec_read(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec)
if (tdb_read(tdb, offset, rec, sizeof(*rec),DOCONV()) == -1)
return -1;
if (TDB_BAD_MAGIC(rec)) {
+ /* Ensure ecode is set for log fn. */
+ tdb->ecode = TDB_ERR_CORRUPT;
TDB_LOG((tdb, 0,"rec_read bad magic 0x%x at offset=%d\n", rec->magic, offset));
return TDB_ERRCODE(TDB_ERR_CORRUPT, -1);
}
@@ -443,6 +460,8 @@ static int rec_free_read(TDB_CONTEXT *tdb, tdb_off off, struct list_struct *rec)
}
if (rec->magic != TDB_FREE_MAGIC) {
+ /* Ensure ecode is set for log fn. */
+ tdb->ecode = TDB_ERR_CORRUPT;
TDB_LOG((tdb, 0,"rec_free_read bad magic 0x%x at offset=%d\n",
rec->magic, off));
return TDB_ERRCODE(TDB_ERR_CORRUPT, -1);