+ /*
+ Trivial Database 2: fetch, store and misc routines.
+ Copyright (C) Rusty Russell 2010
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
#include "private.h"
#include <ccan/asprintf/asprintf.h>
#include <stdarg.h>
/* We didn't like the existing one: remove it. */
if (old_off) {
- add_stat(tdb, frees, 1);
+ tdb->stats.frees++;
ecode = add_free_record(tdb, old_off,
sizeof(struct tdb_used_record)
- + key.dsize + old_room);
+ + key.dsize + old_room,
+ TDB_LOCK_WAIT, true);
if (ecode == TDB_SUCCESS)
ecode = replace_in_hash(tdb, h, new_off);
} else {
}
/* Free the deleted entry. */
- add_stat(tdb, frees, 1);
+ tdb->stats.frees++;
ecode = add_free_record(tdb, off,
sizeof(struct tdb_used_record)
+ rec_key_length(&rec)
+ rec_data_length(&rec)
- + rec_extra_padding(&rec));
+ + rec_extra_padding(&rec),
+ TDB_LOCK_WAIT, true);
if (tdb->flags & TDB_SEQNUM)
tdb_inc_seqnum(tdb);
case TDB_SEQNUM:
tdb->flags |= TDB_SEQNUM;
break;
+ case TDB_ALLOW_NESTING:
+ tdb->flags |= TDB_ALLOW_NESTING;
+ break;
default:
tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL,
TDB_LOG_USE_ERROR,
case TDB_SEQNUM:
tdb->flags &= ~TDB_SEQNUM;
break;
+ case TDB_ALLOW_NESTING:
+ tdb->flags &= ~TDB_ALLOW_NESTING;
+ break;
default:
tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL,
TDB_LOG_USE_ERROR,
/* tdb_open paths care about errno, so save it. */
int saved_errno = errno;
- if (!tdb->logfn)
+ if (!tdb->log_fn)
return ecode;
va_start(ap, fmt);
va_end(ap);
if (len < 0) {
- tdb->logfn(tdb, TDB_LOG_ERROR, tdb->log_data,
- "out of memory formatting message:");
- tdb->logfn(tdb, level, tdb->log_data, fmt);
+ tdb->log_fn(tdb, TDB_LOG_ERROR,
+ "out of memory formatting message:", tdb->log_data);
+ tdb->log_fn(tdb, level, fmt, tdb->log_data);
} else {
- tdb->logfn(tdb, level, tdb->log_data, message);
+ tdb->log_fn(tdb, level, message, tdb->log_data);
free(message);
}
errno = saved_errno;