Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: fix two bogus returns in check.c
Two missed cases in
b21004624683 (tdb2: change API to return the error
value.)
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: use vasprintf.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
tdb2: use config.h instead of setting _XOPEN_SOURCE etc.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
tdb2: update tools/speed.c, tools/tdbtool.c and tools/tdbtorture.c to new API
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
tdb2: clear bogus gcc uninitialized warnings with -O3
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
failtest: include config.h first
It's now important, since it defines _GNU_SOURCE.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ccanlint: fix gdb line in tests_pass helper.
Recent changes shifted line numbers in tap.c, so the break is now in
the wrong place. We should probably have an explicit function we can
breakpoint instead.
Rusty Russell [Thu, 17 Mar 2011 11:45:13 +0000 (22:15 +1030)]
tools: fix ctype.h and string usage.
Enable CCAN_STR_DEBUG in the default flags, so our tools get checked,
and fix up the resulting errors.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
str: replacements for ctype functions.
The standard ctype.h variants will make you go insane if you
contemplate them for too long.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
tap: fix isdigit and isspace usage.
isspace() and isdigit() want an unsigned value.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ciniparser: fix ctype.h usage, and lazy strrchr.
tolower(), toupper() and isupper want an unsigned value. Also, fix
lazy cost-discarding inside strrchr for extra safety.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ccanlint: objects_build_with_stringchecks
If we detect any mention of a problematic string function, try compiling
the entire module with string debugging enabled.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
str: provide checks for ctype.h char functions, and strstr and strchr functions.
In the former case, we were bitten by the fact that you don't pass a char
to isalpha() et al: you pass an int. This means on most platforms you want
to do:
if (isalpha((unsigned char)c)) ...
Insane? Yes, but I assure you I'm not making this up.
Similarly, I've always wanted strstr, strchr and strrchr to return
const char * when given a const char * argument to search, to avoid
constness leak.
In both cases, the actual versions from the headers may be macros, so
we need to be very careful overriding them. The result is that they
become out-of-line functions which is unacceptable for general
performance.
So we only activate these when CCAN_STR_DEBUG is defined.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
build_assert: rename EXPR_BUILD_ASSERT to BUILD_ASSERT_OR_ZERO
Same thing (a BUILD_ASSERT which evaluates to zero), but there's a
strong preference for all modules to stick with their own names as
prefixes.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ccanlint: don't ever used pre-built modules as dependencies.
They're often out-of-date, and we're about to do special things to the
str module compile flags, so we don't *ever* want the default.
It doesn't add much to build times, and it eliminates a nasty source
of weird errors.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ccanlint: fix mangled output for 'make scores'
We need to flush stdout before forking.
Brad Hards [Tue, 8 Mar 2011 09:28:13 +0000 (20:28 +1100)]
tools: avoid needless post increment on size
Also add a note about a possible segfault.
Rusty Russell [Wed, 16 Mar 2011 04:22:21 +0000 (14:52 +1030)]
tools: actually add non-source files to other_files in manifest
We don't use it for the moment, but Brad Hards noted that assigning to
dest ten continuing was pointless, revealing this bug.
Brad Hards [Tue, 8 Mar 2011 09:28:11 +0000 (20:28 +1100)]
alloc: avoid dead store to hdrlen
We only ever write to this variable, so can just be removed.
Brad Hards [Tue, 8 Mar 2011 09:28:10 +0000 (20:28 +1100)]
ciniparser: avoid dead store to sta
This is always overwritten later in the function.
Brad Hards [Tue, 8 Mar 2011 09:28:09 +0000 (20:28 +1100)]
ccan_tokenizer: avoid dead store
obe is always overwritten later.
Brad Hards [Tue, 8 Mar 2011 09:28:08 +0000 (20:28 +1100)]
tdb2: trivial spelling fixes
Brad Hards [Tue, 8 Mar 2011 09:28:06 +0000 (20:28 +1100)]
tdb: remove unused last_ptr
Brad Hards [Tue, 8 Mar 2011 09:28:05 +0000 (20:28 +1100)]
ciniparser: remove dead store
last is unconditionally set to zero later in this function.
Brad Hards [Tue, 8 Mar 2011 09:28:04 +0000 (20:28 +1100)]
alloc: remove unused variable
lp_bits was only ever written to.
Rusty Russell [Tue, 1 Mar 2011 13:01:09 +0000 (23:31 +1030)]
asprintf: new asprintf module.
asprintf is a PITA to use, and it's not in POSIX anyway. Provide
replacements, and also provide a nicer-to-use afmt() wrapper.
Joey Adams [Fri, 25 Feb 2011 04:24:36 +0000 (23:24 -0500)]
tools: Fixed unchecked *strrchr in a couple places.
tools/ccan_depends --compile ccan/module (without a trailing slash)
results in a segfault.
Joey Adams [Tue, 8 Mar 2011 00:20:20 +0000 (10:50 +1030)]
tools: Added "-I." to fix ccan_depends --compile
(Patched forward by Rusty)
Andreas Schlick [Fri, 4 Mar 2011 16:08:06 +0000 (17:08 +0100)]
asort: Remove constness from ctx pointer.
Andreas Schlick [Fri, 4 Mar 2011 15:41:53 +0000 (16:41 +0100)]
tdb2: Correct the comment explaining tdb_brlock().
Rusty Russell [Wed, 2 Mar 2011 03:57:07 +0000 (14:27 +1030)]
cast: new limited cast package inspired by Jan Engelhardt's libhx.
Rusty Russell [Wed, 2 Mar 2011 03:54:02 +0000 (14:24 +1030)]
ccanlint: give a point per compile_ok/compile_fail test
We get a point for every run or api test, rather than 1 point for all of them,
so be consistent.
Rusty Russell [Wed, 2 Mar 2011 03:53:21 +0000 (14:23 +1030)]
ccanlint: don't fail just because we don't have positive tests.
cast package has all negative tests, plus testable examples.
Rusty Russell [Wed, 2 Mar 2011 00:15:51 +0000 (10:45 +1030)]
configurator: more robust test for HAVE_NESTED_FUNCTIONS
Thanks to Andreas Schlick, we have a nicer test for when gcc warns about
trampolines (gcc 4.6's -Wtrampolines). This works at any optimization level,
and means when that warning is enabled we recognize that we shouldn't allow
nested functions.
Rusty Russell [Tue, 1 Mar 2011 13:10:21 +0000 (23:40 +1030)]
iscsi, nfs, opt, tap: use config.h instead of defining _GNU_SOURCE.
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: update design.lyx
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: failtest on tdb_fetch
Increase from:
1985 of 2553 lines covered
to:
2020 of 2552 lines covered
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: failtest on tdb_store
Increase from:
1985 of 2553 lines covered
to:
2018 of 2552 lines covered
Rusty Russell [Tue, 1 Mar 2011 12:54:29 +0000 (23:24 +1030)]
tdb2: failtest on tdb_expand
Increase from:
1962 of 2553 lines covered
to:
1985 of 2553 lines covered
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: fix pread/pwrite error handling in fill and tdb_write.
The "ret < n" was done as an unsigned comparison, so it didn't work as
expected when ret was negative.
Simplest fix is to do an equals comparison everywhere, which is also
slightly stricter.
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: allow read-only databases to use locking.
You can always specify the TDB_NOLOCK flag along with O_RDONLY for the old
behaviour.
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: remove zero-length write optimization.
If benchmarking indicates a problem later, we can restore it.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: change API to return the error value.
Mostly a fairly simple transformation, since 0 still means success.
One new twist is that tdb_nextkey now frees the .dptr of the key; this
us usually what we want but does cause issues for our weird test code.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework tdb.c internal functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework summary.c internal functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework check.c internal functions to return enum TDB_ERROR.
Of course, we leave the API the same, but percolate error codes all the
way back to tdb_check().
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework transaction.c internal functions to return enum TDB_ERROR.
In particular, tdb_needs_recovery() can now indicate an error occurred,
rather than returning true.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework free.c functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework hash.c functions to return enum TDB_ERROR.
This time we have to use our tri-value "tdb_bool_err" type to indicate
true, false, or error, which now allows us to correctly handle errors
in key matching (rather than treating it as a non-match).
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework remaining io.c functions to return enum TDB_ERROR.
In particular, we replace the TDB_OFF_ERR ((off_t)-1) with a range of
negative error values.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework some io.c functions to encode errors in their pointer returns.
This causes a subtle enhancement in tdb_direct(): it previously
returned NULL on both "can't use direct access" or "some error
occurred", as the caller always uses read/write functions as a
fallback anyway. Now we distinguish the error case.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework some io.c functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework io functions to return enum TDB_ERROR.
We have a series of I/O functions which change depending on whether we're
inside a transaction or not. This makes them return enum TDB_ERROR instead
of int.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: restore file filling code.
This snuck in
fe55330a which added the stats attribute. Without it,
TDB works but is vulnerable to segmenation faults or write errors when
disk is exhausted.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework lock.c functions to return enum TDB_ERROR.
Make the other functions in lock.s return an error code, too.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework lock.c static functions to return enum TDB_ERROR.
We make tdb_brlock() and tdb_lock_gradual() return an error code directly:
the callers have to set tdb->ecode.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: Internal error helpers.
I use the "high pointers hold error numbers" trick, and also make
tdb_logerr return the error code, which enables the common case of
"return tdb_logerr(...)".
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: make error numbers negative.
This prepares us for changing function returns over.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: remove tdb_traverse_read
It's not actually different from tdb_traverse(). We can re-add it later if
it makes sense.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: add comments to tdb2.h, reorder for maximum readability.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: remove redundant pending transaction error check.
We do this lower down anyway.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: remove tdb_hashfn_t prototype
It doesn't help the user, since they can't use it to declare their hash
function, and it just adds a level of mental indirection for us.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: remove nesting support.
We don't actually support it, so take it away for the moment. If you
try to nmest you get a TDB_LOG_USE_ERROR message.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: simplify logging levels, rename TDB_DEBUG_* to TDB_LOG_*
It was never clear to me which levels should be used for what cases.
I can only usefully distinguish three at the moment:
(1) TDB errors, which render the TDB unreliable.
(2) TDB user errors, caused by API misuse.
(3) TDB notifications of strange behaviour, from which we have recovered.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: remove extraneous whitespace.
Gets us one extra ccanlint point, too.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: fix leak on lock failure during open.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: log as a ERROR (not as TRACE) when unlocking fails.
This should never happen.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: log a message on allocation failure in tdb_check()
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: log an error when out of memory formatting message.
Log it at level ERROR and log the raw unformatted message at the requested
level.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: close memory leak in traverse.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: close memory leak in tdb_check()
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: use failtest for opening and checking database.
This is a fairly sophisticated use of failtest:
1) There are a few places where we can inject failures without revealing it
at the API level, eg. opening /dev/urandom, or allocation failure in logging.
2) We want to be sure that (almost) all failures cause a message to be logged.
3) We need to exit as soon as possible when a failure is injected, to avoid
combinatorial explosion.
4) We don't want to simply exit on any log message, since we want to be sure
that cleanup happens.
This test found four different bugs failure paths. Erk!
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: fix leak in tests.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: rename ->read and ->write functions.
Since failtest uses macros to override read and write, we need to avoid
those names, even inside our ops structure.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: remove looping for write
On normal files, pwrite and write should never return short except on error.
As we never create sparse files, so any short write is an I/O error.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: remove looping for read on normal files.
Simply assume that any short read on a TDB in an I/O error.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
failtest: enhance tracing
Do it properly, with a printf-style interface.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
ccanlint: prepend module headers before standard ones.
Especially since they probably define _GNU_SOURCE.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
config.h: HAVE_ASPRINTF
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
config.h: define _GNU_SOURCE
Otherwise we don't get goodies like asprintf, and 64-bit offsets. Should
be a harmless-define on non-glibc systems.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
ccanlint: don't crash when given --target=hash_if and there's no _info file.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
noerr: don't use tempnam
We run in a temporary directory now. Also, avoids warning and memory leak.
Andreas Schlick [Thu, 24 Feb 2011 16:27:11 +0000 (17:27 +0100)]
failtest: Fix incorrect reuse of va_list in test/run-malloc.c.
Rusty Russell [Tue, 1 Mar 2011 07:21:22 +0000 (17:51 +1030)]
endian: use byteswap.h where available
And use those names, too.
Rusty Russell [Tue, 1 Mar 2011 07:20:07 +0000 (17:50 +1030)]
compiler, talloc, tap, tdb2: use #if instead of #ifdef.
Rusty Russell [Tue, 1 Mar 2011 07:20:32 +0000 (17:50 +1030)]
ccanlint: check for #ifdef
Old habits die hard; it's better to use #if <FEATURE> than #ifdef <FEATURE>;
they're similar, because undefined identifiers evaluate to zero, but with
GCC's -Wundef flag you can detect mis-spelled or missing features with
#if.
autoconf-style config.h leave unset features undefined, so this works for
those config.h too.
Rusty Russell [Tue, 1 Mar 2011 07:17:49 +0000 (17:47 +1030)]
ccanlint: run tests with reduced-feature config.h
Rusty Russell [Tue, 1 Mar 2011 07:17:24 +0000 (17:47 +1030)]
ccanlint: compile module with reduced-feature config.h
Rusty Russell [Tue, 1 Mar 2011 07:18:11 +0000 (17:48 +1030)]
ccanlint: create reduce-feature config.h
A common mistake is not to try compiling with features disabled in
config.h. The ideal case would determine how features interact and
test all combinations of them: this simply disables any features
mentioned in the code which were previously enabled.
Rusty Russell [Tue, 1 Mar 2011 05:34:49 +0000 (16:04 +1030)]
ccanlint: --compiler and --cflags options.
Rusty Russell [Tue, 1 Mar 2011 05:38:57 +0000 (16:08 +1030)]
ccanlint: read config.h to get compilation flags at runtime.
This means you don't have to recompile ccanlint to get the new flags;
it's a small step towards making ccanlint useful outside the ccan repo.
Rusty Russell [Tue, 1 Mar 2011 05:31:20 +0000 (16:01 +1030)]
ccanlint: handle weird directories.
David Gibson reports (and I confirmed) that running ccanlint in /tmp
causes an very uninformative segv. Fix that, and add a more useful message,
as well as delaying recursing until we're confident there's code around.
Rusty Russell [Tue, 1 Mar 2011 05:30:05 +0000 (16:00 +1030)]
config.h: idempotent-wrap the generated config.h
Rusty Russell [Tue, 1 Mar 2011 05:29:40 +0000 (15:59 +1030)]
asort: handle !HAVE_NESTED_FUNCTIONS
Andreas Schlick reports that PaX et. al. dislike trampolines, so open-code
qsort from glibc.
Interestingly, _quicksort from glibc seems to have a void * parameter, but
I can't find any information on it.
Rusty Russell [Tue, 1 Mar 2011 00:52:56 +0000 (11:22 +1030)]
failtest: fix locking code.
We need to get the locks back *after* the child runs.
Rusty Russell [Tue, 1 Mar 2011 00:52:39 +0000 (11:22 +1030)]
failtest: fix tracepath bug.
Aborts on a short write with --tracepath.
Rusty Russell [Thu, 24 Feb 2011 05:33:46 +0000 (16:03 +1030)]
tdb2: make tdb2 compile clean under -Wshadow.
This isn't a general requirement for CCAN modules, but Samba uses it, so
make sure tdb2 doesn't upset it.
Rusty Russell [Thu, 24 Feb 2011 05:09:32 +0000 (15:39 +1030)]
jmap,likely,tdb2: use CCAN_<MODNAME>_DEBUG instead of DEBUG.
Samba (for example) uses a DEBUG() macro, which triggers these heuristics.
Better to make it per-module anyway.
Rusty Russell [Thu, 24 Feb 2011 02:50:01 +0000 (13:20 +1030)]
ccanlint: fix more potential segvs when reporting ccanlint errors.
When I changed score_file_error() to printf-style, I didn't audit all
the callers who were handing string literals. I've finally done that;
I should have broken the compile by renaming it.
Rusty fails refactoring 101.
Reported-by: Andreas Schlick
Joey Adams [Sat, 19 Feb 2011 10:53:04 +0000 (05:53 -0500)]
ccan_tokenizer: update to be compatible with darray.