diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 08:13:26 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 08:13:26 +0930 |
commit | ef70f5dd35974115a85850d04b0f4b64e511659f (patch) | |
tree | 7904ff676e509cc4feec0887b8034f9c570eaaf1 /lib | |
parent | 6b11a2630123453a7f40f728641882c440b57010 (diff) | |
download | samba-ef70f5dd35974115a85850d04b0f4b64e511659f.tar.gz samba-ef70f5dd35974115a85850d04b0f4b64e511659f.tar.bz2 samba-ef70f5dd35974115a85850d04b0f4b64e511659f.zip |
tdb2: log allocation failures in tdb1 backend.
The TDB2 tests are stricter about this; they want every error logged.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from CCAN commit 670ba98f74b52df541d153eeab9d3310932e75cd)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tdb2/tdb1_check.c | 11 | ||||
-rw-r--r-- | lib/tdb2/tdb1_io.c | 3 | ||||
-rw-r--r-- | lib/tdb2/tdb1_open.c | 24 | ||||
-rw-r--r-- | lib/tdb2/tdb1_tdb.c | 4 |
4 files changed, 30 insertions, 12 deletions
diff --git a/lib/tdb2/tdb1_check.c b/lib/tdb2/tdb1_check.c index 4d71712c47..a8e54b2ee0 100644 --- a/lib/tdb2/tdb1_check.c +++ b/lib/tdb2/tdb1_check.c @@ -339,6 +339,7 @@ int tdb1_check(struct tdb_context *tdb, bool found_recovery = false; tdb1_len_t dead; bool locked; + size_t alloc_len; /* We may have a write lock already, so don't re-lock. */ if (tdb->file->allrecord_lock.count != 0) { @@ -364,11 +365,13 @@ int tdb1_check(struct tdb_context *tdb, } /* One big malloc: pointers then bit arrays. */ - hashes = (unsigned char **)calloc( - 1, sizeof(hashes[0]) * (1+tdb->tdb1.header.hash_size) - + BITMAP_BITS / CHAR_BIT * (1+tdb->tdb1.header.hash_size)); + alloc_len = sizeof(hashes[0]) * (1+tdb->tdb1.header.hash_size) + + BITMAP_BITS / CHAR_BIT * (1+tdb->tdb1.header.hash_size); + hashes = (unsigned char **)calloc(1, alloc_len); if (!hashes) { - tdb->last_error = TDB_ERR_OOM; + tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR, + "tdb_check: could not allocate %zu", + alloc_len); goto unlock; } diff --git a/lib/tdb2/tdb1_io.c b/lib/tdb2/tdb1_io.c index ba6deeef20..f3d139d043 100644 --- a/lib/tdb2/tdb1_io.c +++ b/lib/tdb2/tdb1_io.c @@ -370,6 +370,9 @@ int tdb1_expand(struct tdb_context *tdb, tdb1_off_t size) char *new_map_ptr = (char *)realloc(tdb->file->map_ptr, tdb->file->map_size); if (!new_map_ptr) { + tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, + TDB_LOG_ERROR, + "tdb1_expand: no memory"); tdb->file->map_size -= size; goto fail; } diff --git a/lib/tdb2/tdb1_open.c b/lib/tdb2/tdb1_open.c index e22a6d1428..e668616a04 100644 --- a/lib/tdb2/tdb1_open.c +++ b/lib/tdb2/tdb1_open.c @@ -74,7 +74,7 @@ enum TDB_ERROR tdb1_new_database(struct tdb_context *tdb, struct tdb1_header *newdb; size_t size; int hash_size = TDB1_DEFAULT_HASH_SIZE; - enum TDB_ERROR ret = TDB_ERR_IO; + enum TDB_ERROR ret; tdb_context_init(tdb, max_dead); @@ -88,7 +88,8 @@ enum TDB_ERROR tdb1_new_database(struct tdb_context *tdb, /* We make it up in memory, then write it out if not internal */ size = sizeof(struct tdb1_header) + (hash_size+1)*sizeof(tdb1_off_t); if (!(newdb = (struct tdb1_header *)calloc(size, 1))) { - return TDB_ERR_OOM; + return tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR, + "Could not allocate new database header"); } /* Fill in the header */ @@ -113,15 +114,24 @@ enum TDB_ERROR tdb1_new_database(struct tdb_context *tdb, tdb->file->map_ptr = (char *)newdb; return TDB_SUCCESS; } - if (lseek(tdb->file->fd, 0, SEEK_SET) == -1) + if (lseek(tdb->file->fd, 0, SEEK_SET) == -1) { + ret = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR, + "tdb1_new_database: lseek failed"); goto fail; + } - if (ftruncate(tdb->file->fd, 0) == -1) + if (ftruncate(tdb->file->fd, 0) == -1) { + ret = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR, + "tdb1_new_database: ftruncate failed"); goto fail; + } - /* we still have "ret == TDB_ERR_IO" here */ - if (tdb1_write_all(tdb->file->fd, newdb, size)) - ret = TDB_SUCCESS; + if (!tdb1_write_all(tdb->file->fd, newdb, size)) { + ret = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR, + "tdb1_new_database: write failed"); + goto fail; + } + ret = TDB_SUCCESS; fail: SAFE_FREE(newdb); diff --git a/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c index 9730dceffc..45db2ba33b 100644 --- a/lib/tdb2/tdb1_tdb.c +++ b/lib/tdb2/tdb1_tdb.c @@ -498,7 +498,9 @@ static int _tdb1_store(struct tdb_context *tdb, TDB_DATA key, fails and we are left with a dead spot in the tdb. */ if (!(p = (char *)malloc(key.dsize + dbuf.dsize))) { - tdb->last_error = TDB_ERR_OOM; + tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR, + "tdb1_store: out of memory" + " allocating copy"); goto fail; } |