blob: 8658506aa981a664be40b9f16fa641ad896115c0 [file] [log] [blame]
2009-01-29 Scott James Remnant <scott@netsplit.com>
* nih/test_alloc.h (TEST_ALLOC_FAIL): Initialise the count in the
loop pre-condition, still doesn't solve gcc's issues but I prefer
it.
* nih/tests/test_command.c (test_help): Array was too small, increase
the size.
* nih/tests/test_string.c (test_str_split): Oops, left some debugging
in here.
* nih/file.c (nih_file_read): Never trust a changelog entry that
says "minor clean-up"; make sure we raise the error before returning
NULL.
* nih-dbus/dbus_connection.c (nih_dbus_setup)
(nih_dbus_add_watch, nih_dbus_add_timeout): We should discard
objects attached to the D-Bus connection since they're floating;
nobody should take a reference, but good practice and all that.
* nih/alloc.h: Document the different usage patterns
* nih/io.c (nih_io_buffer_resize): Use nih_unref() instead of
nih_free(), while nothing should have taken a reference, it's a
good pattern to stick to.
(nih_io_message_recv): Use nih_local for ctrl_buf
(nih_io_message_send): Use nih_local for ctrl_buf
(nih_io_send_message): Take a reference to messages on the send q
(nih_io_watcher_write): Unreference the message from the NihIo
object instead of freeing, in case a reference is used elsewhere
(nih_io_read): Unreference instead of freeing
(nih_io_get): Unreference instead of freeing
(nih_io_message_new): Parent should not be the NihIo
(nih_io_write): Obey that rule here
* nih/tests/test_io.c (test_send_message): Make sure that a
reference is taken after all.
(test_watcher): Don't create object with parent as io
* nih/file.c (nih_file_read): Minor clean-up
* nih/main.c (nih_main_set_pidfile): Discard the pid file in case
someone took a reference to it.
* nih/main.c (nih_main_init_full): Discard the package string in
case another part of the code has taken a reference to it; since
it never changes unless this function is called, generate it here
(nih_main_package_string): dropping this function
(nih_main_version): Fetch package_string
* nih/main.h: Add external package_string and drop function proto.
* nih/tests/test_main.c (test_package_string): Fold these tests into
(test_init): here.
* nih/libnih.supp: Update suppression
* nih/logging.c (nih_log_message): Use nih_local for message
* nih/io.c (nih_io_printf): Use nih_local for str
* nih/config.c (nih_config_parse_stanza): Use nih_local for name.
2009-01-28 Scott James Remnant <scott@netsplit.com>
* nih/file.c (nih_dir_walk_visit): Can't allocate nih_local var
with a parent, otherwise it'll never be cleaned up.
* nih/config.c (nih_config_parse): Initialise nih_local var to NULL.
* nih/alloc.c (nih_alloc_context_free): After the destructor has
been called, an object is dead. Attempting to reference it should
fail, so we need to store a flag that this has happened.
(nih_realloc, nih_free, nih_discard, nih_alloc_real_set_destructor)
(nih_alloc_ref_new, nih_unref, nih_alloc_parent)
(nih_alloc_ref_lookup, nih_alloc_size): Forbid operations on
finalised objects.
* nih/tests/test_alloc.c (test_free): Once again I've tripped over
bugs where the ordering of allocations between siblings in a child
matters if they refer to each other in their destructor (typical
case, a hash table in a struct).
* nih/alloc.c (nih_realloc, nih_alloc_ref_new): Reverse the free
order, so that the last member allocated is the first one freed.
This was the original fix for the above bug, but this just moves
the problem without really fixing it. I do think it's generally
correct that the order should be backwards though.
(nih_free): Since this is the only function that needs to do it,
take care of casting off parents here.
(nih_unref): Again, since this is the only function that needs
to free the context when there are no parents, do it here after
freeing the reference.
(nih_alloc_ref_free): Which means this function no longer needs
to recurse; nih_free() and nih_discard() always directly free a
context, and nih_unref() knows to if there are no parents left;
nih_unref() explicitly doesn't free the context.
(nih_unref_only): No need to pass FALSE to nih_alloc_ref_free() now.
(nih_alloc_context_free): This gets the big rewrite; rather than
just recursively freeing the heirarchy, finalise them first by
calling destructors and then reparenting them to the context
being freed. Only free the objects after all destructors are called.
* nih/macros.h (MIN, MAX): Replace with newer evaluation-safe
nih_min() and nih_max()
* nih/io.c (nih_io_select_fds): Replace MAX with nih_max
(nih_io_buffer_pop): Replace MIN with nih_min
(nih_io_buffer_shrink): Replace MIN with nih_min
* nih/command.c (nih_command_group_help): Replace MAX with nih_max,
nicely avoiding multiple function call there.
* nih/option.c (nih_option_group_help): Likewise.
* nih/tests/test_io.c (test_select_fds): Replace MAX with nih_max
* nih-dbus/nih_dbus_tool.py (Method.replyFunction): Don't free the
message passed in to the function. Since we now require the handler
function to take a reference to the message during async processing,
we can't just go around freeing it.
(Method.replyPrototype): Warn if the error from the reply function
is ignored, since this is important.
* nih-dbus/dbus_message.c (nih_dbus_message_error): Likewise we
should not free the message when passed in for a caller either.
* nih-dbus/tests/test_dbus_message.c (my_return_error_cb): Update
to make sure the message is not freed.
* nih-dbus/tests/com.netsplit.Nih.Test_impl.c (async_method_reply):
Make sure message is not freed.
* NEWS: Document the change
2009-01-26 Scott James Remnant <scott@netsplit.com>
* configure.ac: Officially mandate libtool 2.2
* HACKING: Bump dependency on libtool to 2.2.4
* NEWS: Document change.
* configure.ac (AC_INIT): Bump version to 0.2.0 since we're making
a number of large API changes.
(AC_COPYRIGHT): Bump the copyright year too.
* NEWS (0.1.0): Declare 0.1.0 to have happened at revision 600 before
we started the most recent round of changes; this is the version
shipped with Upstart 0.5 but with the fixed list iteration.
(0.2.0): Begin documenting changes in the API since then; this file
can therefore be used as a checklist for updating software.
* nih-dbus/dbus.c, nih-dbus/dbus.h: Seperate out the code into
separate files to make maintenance much easier. The new files are
nih-dbus/dbus_error.c, nih-dbus/dbus_error.h,
nih-dbus/dbus_connection.c, nih-dbus/dbus_connection.h,
nih-dbus/dbus_message.c, nih-dbus/dbus_message.h,
nih-dbus/dbus_object.c, nih-dbus/dbus_object.h,
nih-dbus/dbus_proxy.c, nih-dbus/dbus_proxy.h,
nih-dbus/dbus_util.c, nih-dbus/dbus_util.h.
* nih-dbus/nih_dbus_tool.py (Output.sourceFile): Change include
to separate ones for error, message, object and proxy.
(Output.headerFile): Change include to separate ones for message,
object and proxy.
* nih-dbus/dbus_message.c (nih_dbus_message_new): New function
separated out of nih_dbus_object_message(); also no need to cast
the destructor.
* nih-dbus/dbus_object.c (nih_dbus_object_message): Clean up to
call new nih_dbus_message_new function.
* nih-dbus/libnih-dbus.h: New top-level header to include everything
* nih-dbus/tests/test_dbus.c: Separate out the tests into files
to match the sources. The new files are
nih-dbus/tests/test_dbus_error.c,
nih-dbus/tests/test_dbus_connection.c,
nih-dbus/tests/test_dbus_message.c,
nih-dbus/tests/test_dbus_object.c,
nih-dbus/tests/test_dbus_proxy.c,
nih-dbus/tests/test_dbus_util.c.
* nih-dbus/tests/test_dbus_error.c (test_error_raise_printf):
Looks like this function was never run in the old test suite, oops.
* nih-dbus/tests/test_dbus_message.c (test_message_new): Test the
new function
* nih-dbus/tests/test_com.netsplit.Nih.Test_object.c: Drop includes
we don't actually seem to use the library!
* nih-dbus/tests/test_com.netsplit.Nih.Test_proxy.c: Update includes
to include proxy
* nih-dbus/tests/com.netsplit.Nih.Test_impl.c: Replace includes
with separate ones.
* nih-dbus/tests/com.netsplit.Nih.Test_impl.h: Drop include.
* nih-dbus/Makefile.am (include_HEADERS): Install the top-level header
(nihdbusinclude_HEADERS): Update paths to new headers
(libnih_dbus_la_SOURCES): Build from new sources
(TESTS, test_dbus_error_SOURCES, test_dbus_error_CFLAGS)
(test_dbus_error_LDFLAGS, test_dbus_error_LDADD)
(test_dbus_connection_SOURCES, test_dbus_connection_CFLAGS)
(test_dbus_connection_LDFLAGS, test_dbus_connection_LDADD)
(test_dbus_message_SOURCES, test_dbus_message_CFLAGS)
(test_dbus_message_LDFLAGS, test_dbus_message_LDADD)
(test_dbus_object_SOURCES, test_dbus_object_CFLAGS)
(test_dbus_object_LDFLAGS, test_dbus_object_LDADD)
(test_dbus_proxy_SOURCES, test_dbus_proxy_CFLAGS)
(test_dbus_proxy_LDFLAGS, test_dbus_proxy_LDADD)
(test_dbus_util_SOURCES, test_dbus_util_CFLAGS)
(test_dbus_util_LDFLAGS, test_dbus_util_LDADD): Add details for
new tests, replacing old ones
* nih/dbus.c, nih/dbus.h, nih/libnih-dbus.supp, nih/libnih-dbus.ver,
nih/nih_dbus_tool.py, nih/test_dbus.h,
nih/tests/com.netsplit.Nih.Test.xml,
nih/tests/com.netsplit.Nih.Test_impl.c,
nih/tests/com.netsplit.Nih.Test_impl.h,
nih/tests/test_com.netsplit.Nih.Test_object.c,
nih/tests/test_com.netsplit.Nih.Test_proxy.c,
nih/tests/test_dbus.c: Move all D-Bus related code into a new
sub-directory
* nih/Makefile.am: Move D-Bus related rules into
* nih-dbus/Makefile.am: here.
* nih-dbus/tests/test_dbus.c: Update include path for D-Bus test
macros and dbus.h
* nih-dbus/tests/test_com.netsplit.Nih.Test_object.c: Update include
path for dbus.h
* nih-dbus/tests/test_com.netsplit.Nih.Test_proxy.c: Update include
path for dbus.h
* nih-dbus/tests/com.netsplit.Nih.Test_impl.c: Update include path
for dbus.h
* nih-dbus/tests/com.netsplit.Nih.Test_impl.h: Update include path
for dbus.h
* nih-dbus/nih_dbus_tool.py (Output.sourceFile, Output.headerFile):
Generate includes with correct path for dbus.h
* Makefile.am (SUBDIRS): Iterate into new sub-directory
* configure.ac (AC_CONFIG_FILES): Generate new Makefile
* nihify: Create symlink to nih-dbus as well
* nih/tests/com.netsplit.Nih.Test_impl.c (my_test_async_method):
Take a reference to the message
* nih/libnih-dbus.supp: Update D-Bus suppressions.
* TODO: Update
* nih/libnih.supp: Update suppressions for new calling stack
* nih/dbus.c (nih_dbus_object_new): Update documentation to match
new nih_alloc(), no need to cast destructor
(nih_dbus_proxy_new, nih_dbus_path): Update documentation to match
new nih_alloc()
(nih_dbus_object_message): Make the message nih_local, this means
the handler must now reference the message otherwise it will be
freed.
(nih_dbus_object_introspect): Make the xml string nih_local
(nih_dbus_message_error): Make the string nih_local
* nih/tests/test_dbus.c (test_error_raise)
(test_error_raise_printf): Don't check for no parent if we don't
need to.
(my_return_error): Must reference the message
(test_error_raise, test_error_raise_printf): Must mean TEST_ALLOC_FAIL
* nih/main.c (nih_main_loop_add_func): Update documentation to match
new nih_alloc(), no need to cast destructor function.
(nih_main_version): Use nih_local
(nih_main_write_pidfile): Use nih_local
* nih/tests/test_main.c: Include limits.h
* nih/io.c (nih_io_watcher): Can't just break if we catch a free,
we have to at least process errors first!
* nih/watch.c (nih_watch_new): Update documentation to match new
nih_alloc(), no need to cast destructor function.
(nih_watch_add): No need to cast destructor function; free the
not a directory error as well.
(nih_watch_handle): Use nih_local on the path so it's always cleaned
up if we don't reference it; reference it when delaying the create
handler instead of reparenting
* nih/tests/test_watch.c: Include limits.h
(test_new): Free watch inside loop, don't select fds; no idea why
this code is here.
(test_reader): Can't just call select then handle, we actually have
to wait for activity first.
(my_create_handler, my_modify_handler, my_delete_handler): Loop over
allocations, we can't use TEST_ALLOC_SAFE if we don't know we're in
a TEST_ALLOC_FAIL.
2009-01-25 Scott James Remnant <scott@netsplit.com>
* nih/file.c (nih_file_read): Update documentation to match
new nih_alloc()
(nih_dir_walk, nih_dir_walk_visit): No need to cast destructor
function, use nih_local to clean up code a little bit.
(nih_dir_walk_scan): Use nih_local to make this easier.
* nih/tests/test_file.c: Include limits.h
(my_visitor): No need to cast destructor
* nih/test.h: Include config.h since that defines _GNU_SOURCE
* nih/tests/test_child.c, nih/tests/test_signal.c: Remove extra
double include.
* nih/test_alloc.h (TEST_FREE_TAG): Remove incorrect "extern"
* nih/alloc.c (nih_unref_only): Add function to allow unreferencing
without freeing, for example if we return something from our state
and want to reparent but still allow NULL.
* nih/alloc.h: Add prototype.
* nih/io.c (nih_io_add_watch, nih_io_message_new, nih_io_reopen):
Update documentation to match new nih_alloc(), no need to cast
destructor function.
(nih_io_buffer_new, nih_io_buffer_pop, nih_io_read, nih_io_get):
Update documentation to match new nih_alloc()
(nih_io_read_message): Update documentation to match new nih_alloc(),
reparent message by referencing to parent before unreferencing from
io structure.
* nih/tests/test_io.c (test_read_message, test_send_message):
Replace TEST_ALLOC_PARENT with NULL parent with TEST_ALLOC_OPRHAN
(test_read_message): Message must reference the io watch
(test_message_add_control): Remove strange allocator changing.
(test_message_recv): Call nih_error_init to avoid valgrind issue
* nih/child.c (nih_child_add_watch): Update documentation to match new
nih_alloc(), no need to cast destructor function.
* nih/tests/test_child.c: Include config.h
* nih/signal.c (nih_signal_add_handler): Update documentation to
match new nih_alloc(), no need to cast destructor function.
* nih/tests/test_signal.c: Include config.h
* nih/timer.c (nih_timer_add_timeout, nih_timer_add_periodic)
(nih_timer_add_scheduled): Update documentation to match new
nih_alloc(), no need to cast destructor function.
* nih/alloc.c (nih_alloc_parent, nih_alloc_size): Pointer argument
should be const since we don't modify it.
* nih/alloc.h: Update prototype.
* nih/error.h: Add documentation for header.
(NIH_SHOULD): Much needed docstring.
* nih/logging.c: Include nih/macros.h
* nih/logging.h: Add documentation for header.
* nih/config.c (nih_config_next_token, nih_config_next_arg)
(nih_config_parse_args, nih_config_parse_command)
(nih_config_parse_block): Update documentation to match new
nih_alloc()
(nih_config_parse): Rewrite to use nih_file_read() into an nih_local
variable, instead of mmap which has strange behaviours in the face
of updates.
* nih/config.h: Add documentation header.
* nih/tests/test_config.c: Include limits.h
* nih/command.c (nih_command_parser): Update documentation to
match new nih_alloc(), use nih_local where possible to clean up
code.
(nih_command_join): Update documentation to match new nih_alloc()
(nih_command_handle): Update documentation to match new nih_alloc(),
use nih_local where possible to clean up code.
(nih_command_help): Use nih_local for groups array
(nih_command_group_help): Use nih_local for wrapped string
* nih/command.h: Add documentation string for header.
* nih/option.c (nih_option_parser): Update documentation to match
new nih_alloc(), should not use parent for any old allocation.
(nih_option_join): Update documentation to match new nih_alloc()
(nih_option_help): Use nih_local for temporary strings and groups
(nih_option_group_help): Use nih_local for temporary string.
* nih/option.h: Add documentation string for header.
* nih/list.h, nih/hash.h: Provide a much better documentation string.
* nih/tree.c (nih_tree_new, nih_tree_entry_new): Update documentation
to match new nih_alloc(); no need to cast destructor function
* nih/tree.h: Add documentation string for the header.
* nih/hash.c (nih_hash_new): Update documentation to match
new nih_alloc(); update comment to reflect what we actually do to
pick a prime.
(nih_hash_pointer_key, nih_hash_pointer_hash)
(nih_hash_pointer_cmp): Drop these, we were looking at the raw bytes
of a pointer, which is almost certainly naughty.
* nih/hash.h: Add documentation string, remove prototypes.
(NIH_HASH_FOREACH, NIH_HASH_FOREACH_SAFE): Update documentation in
same manner as the list functions.
(nih_hash_pointer_new): Drop, this is probably illegal C ;-)
(nih_hash_string_new): Update documentation to match new nih_alloc()
* nih/tests/test_hash.c (test_pointer_new, test_pointer_key): Drop.
(test_lookup): Modify to use string hashes instead.
(test_foreach, test_foreach_safe): Fix function name comment.
* nih/list.c (nih_list_new, nih_list_entry_new): Update documentation
to match new nih_alloc(); No need to cast the destructor function
anymore.
* nih/list.h: Add documentation string for the header.
(NIH_LIST_FOREACH, NIH_LIST_FOREACH_SAFE): Improve documentation
about which is best.
(NIH_LIST_ITER): Add macro to make iterating a list with an offset
head easier.
* nih/macros.h: Add sorely-missed documentation strings, including
one for the header itself.
(NULL): Drop, NULL is defined by the C compiler.
* nih/string.c: Update all documentation to match new nih_alloc()
(nih_str_array_addp): Take a reference to the passed variable
instead of reparenting (which isn't possible anymore).
(nih_str_array_add, nih_str_array_addn): Since these just call
nih_str_array_addp() which now takes a reference rather than
reparents, we can change these functions to make new_str as a
local variable.
(nih_strv_free): Drop this function, it's not used and it's utterly
inconsistent with the others as it expressly isn't used with
nih_alloc().
(nih_strncat): This function worryingly did not work if NULL was
passed, catch that and call nih_strndup() instead.
* nih/string.h: Add a documentation string and drop prototype.
* nih/tests/test_string.c (test_strv_free): Drop.
(test_sprintf, test_vsprintf, test_strdup, test_strndup): Replace
TEST_ALLOC_PARENT calls with NULL as the second argument with
TEST_ALLOC_ORPHAN instead.
(test_strcat, test_strncat, test_strcat_sprintf)
(test_strcat_vsprintf): Strangely these test cases don't appear to
have worked before, the functions return NULL in case of memory
allocation failure so we need to check the string against a temporary
copy stored before, and we need to free that string as well.
Also add test cases for NULL being passed in as the source string.
* nih/test_alloc.h: Expose references to nih_alloc()'s pointers to
malloc, realloc and free so we can replace them for testing purposes.
(TEST_ALLOC_SIZE): Since this returns the size of the allocated object,
rather than the request, check that the block is at least as large
as the argument given - not exactly as large.
(TEST_ALLOC_PARENT): Call nih_alloc_parent directly with both
arguments, since it's compatible with our calling - can't output the
current parent now they're may be multiple though. When passed NULL
this now checks if it *has* a parent (almost the exact inverse of the
previous meaning).
(TEST_ALLOC_ORPHAN): New test to make sure that an object does not
have a parent.
(_test_free_tag): Reimplement to lookup the tag block in a linked
list, instead of a static array, and only return TRUE or FALSE.
(_test_destructor): Drop, we can just use nih_list_destroy instead.
(TEST_FREE_TAG): Reimplement to allocate the tag struct itself as
the child, and place in a linked list.
(_test_malloc): Add malloc wrapper.
(_test_allocator): Rename to _test_realloc
(TEST_ALLOC_FAIL, TEST_ALLOC_SAFE): Change allocator through the
exposed variables.
* nih/alloc.h (nih_local): Macro to add a variable attribute that
calls a nih_discard() as a cleanup function when the variable goes
out of scope.
* nih/alloc.c (_nih_discard_local): gcc cleanup function wrapper that
takes the address of the local variable, it gets the actual pointer
out and passes it to nih_discard(). Unlike the other functions,
this actually allows the pointer to be NULL.
* nih/tests/test_alloc.c (test_local): Test local variables work!
* nih/alloc.c (nih_alloc_has_ref): Rename back to nih_alloc_parent.
(nih_alloc_parent): Accept NULL, if given returns TRUE if there are
any parents.
* nih/alloc.h: Update prototype.
* nih/tests/test_alloc.c (test_parent): Since it's a bit more
complex, we should probably explicitly test this ;-)
* nih/test.h, nih/test_output.h, nih/test_values.h, nih/test_process.h,
nih/test_divert.h, nih/test_files.h, nih/test_alloc.h, nih/test_list.h,
nih/test_hash.h, nih/test_dbus.h: Split the test macros out into
separate files to make maintaining them easier. None of them may
be included directly, execept nih/test_dbus.h which is now no longer
included by default.
* nih/Makefile.am (nihinclude_HEADERS): Install new headers.
* nih/alloc.c: Re-implement as a multi-reference allocator; an object
may now have as many parents as you wish, each one holding its own
reference to it.
(NihAllocCtx): Restructure.
(NihAllocRef): New object linked by context to hold a reference.
(nih_alloc_init, nih_alloc_set_allocator, nih_alloc_using): Drop
support for custom allocators, knowing that we always use malloc
is useful for the implementation - we still allow the test suite
to change them, but nothing else.
(nih_alloc): Reimplement from original nih_alloc_using() function,
now calls nih_alloc_ref_new() if parent is not NULL.
(nih_realloc): Reimplement for multi-referenceness; much of the
this remains the same.
(nih_free): Reimplement as a wrap around nih_alloc_context_free().
(nih_discard): New function to discard an object if it has no
parent references, used if you believe references may have been
taken by functions you have called.
(nih_alloc_context_free): Common function to free an object, calling
its destructor after discarding parent references but before cleaning
up children.
(nih_alloc_reparent): Drop, it's no longer possible to simply reparent
an object. Instead you should call the new functions:
(nih_ref, nih_alloc_ref_new, nih_unref, nih_alloc_ref_free): Handle
NihAllocRef objects, linking them to a context and removing them from
a context; when the last reference to a child is removed, we
automatically call nih_alloc_context_free().
(nih_alloc_parent, nih_alloc_has_ref): Replace the former function
with the latter, it's no longer possible to query the exact parent
since there isn't one.
(nih_alloc_ref_lookup): Internal function to find a reference.
(nih_alloc_size): Reimplement assuming malloc, which saves us some
space in the context structure.
* nih/alloc.h: Update all prototypes and documentation, including
adding module documentation to the top of the header file.
(NihAllocator): Drop typedef.
(nih_alloc_set_destructor): Add casting macro with name of original
function that calls nih_alloc_real_set_destructor().
* nih/tests/test_alloc.c (test_new, test_alloc): Fix to check for a
reference rather than the explicit parent; also include a test for
allocation failure using a malloc hook.
(test_realloc): Fix to check for a reference rather than the
explicit parent, change allocatil failure test to use a realloc hook
instead of a different allocator.
(test_free): Add a with parent test.
(test_discard): New test, as test_free() but with different expected
result for the parent test.
(test_set_allocator): Drop test.
(test_reparent, test_ref, test_unref): Drop the former test and
replace with checking that referencing and unreferencing works.
2008-10-24 Scott James Remnant <scott@netsplit.com>
* nih/list.h (NIH_LIST_FOREACH_SAFE): Mark the cursor to be
automatically cleaned up should we exit the loop; this somewhat
simplifies the definition and allows returning from within the loop.
* nih/list.h (NIH_LIST_FOREACH_SAFE): Fix a typo that caused only
once cursor variable to be used, rather than one per iteration.
* nih/main.h, nih/main.c, nih/dbus.c, nih/tests/test_dbus.c: Revert
previous "delete" patch now that we can iterate linked lists
without tripping over the bug we found here.
* nih/libnih-dbus.supp: Update suppressions for newer glibc and
D-Bus without debugging enabled.
* nih/list.h (NIH_LIST_FOREACH_SAFE): Replace with a more ingenious
version based on work by Casey Dahlin and myself; instead of caching
the next pointer, place a cursor node in the list instead. This
solves the issue where the next pointer may be changed or freed, and,
in fact solves all issues of list rearrangement.
* nih/tests/test_list.c (test_foreach_safe): Add test cases.
* nih/hash.h (NIH_HASH_FOREACH_SAFE): Update comment to match.
2008-08-12 Casey Dahlin <cdahlin@redhat.com>
* nih/main.h (NihMainLoopFunc): Add delete member.
* nih/main.c (nih_main_loop): Don't run the callback for any function
marked for deletion, instead call nih_free on it.
(nih_main_loop_add_func): Initialise delete to FALSE.
* nih/dbus.c (nih_dbus_release_callback): Add function to mark a
loop function as deleted.
(nih_dbus_setup): and use it as the free function instead of nih_free.
* nih/tests/test_dbus.c (test_connect, test_bus, test_setup): Check
that the loop functions are marked for deletion instead of freed.
* nih/nih_dbus_tool.py (Output.sourceFile): Include limits.h
2008-07-02 Scott James Remnant <scott@netsplit.com>
* nih/Makefile.am (test_com_netsplit_Nih_Test_object_SOURCES)
(test_com_netsplit_Nih_Test_proxy_SOURCES): Add forgotten header.
2008-07-01 Scott James Remnant <scott@netsplit.com>
* TODO: Update.
* nih/tests/test_com.netsplit.Nih.Test_proxy.c (test_method_dispatch):
Add test cases for input and output arguments of various types.
* nih/nih_dbus_tool.py (DBusArray.marshal): Add extra parens in
array setting call for precedence reasons.
* nih/tests/test_com.netsplit.Nih.Test_proxy.c (test_method_dispatch):
Add basic tests of calls to synchronous and async methods, and the
usual error returns.
* nih/tests/com.netsplit.Nih.Test_impl.c (async_method_reply):
Add replies that have the wrong combinations of arguments.
* nih/tests/com.netsplit.Nih.Test_impl.c,
* nih/tests/test_com.netsplit.Nih.Test_object.c (my_connect_handler)
(my_setup, my_teardown): Move these functions across too.
* nih/tests/com.netsplit.Nih.Test_impl.h: Add prototypes.
* nih/dbus.c (nih_dbus_proxy_new): Allow name to be NULL.
* nih/tests/test_dbus.c (test_proxy_new): Test without a name.
* nih/tests/test_com.netsplit.Nih.Test_object.c,
* nih/tests/com.netsplit.Nih.Test_impl.c: Separate out the server
object implementation so that the proxy code could use it.
* nih/tests/com.netsplit.Nih.Test_impl.h: Header for object definition
* nih/Makefile.am (test_com_netsplit_Nih_Test_object_SOURCES)
(test_com_netsplit_Nih_Test_proxy_SOURCES): Include the object
implementation code.
* nih/tests/test_com.netsplit.Nih.Test_proxy.c: Stub file for proxy
test cases.
* nih/Makefile.am (TESTS): Build the proxy test suite.
(test_com_netsplit_Nih_Test_proxy_SOURCES)
(test_com_netsplit_Nih_Test_proxy_CFLAGS)
(test_com_netsplit_Nih_Test_proxy_LDFLAGS)
(test_com_netsplit_Nih_Test_proxy_LDADD): Details for the proxy
test suite, which actually includes the object code since it needs
to implement objects too
* nih/nih_dbus_tool.py (MemberWithArgs.variables): Only include arg
array in object mode.
* nih/Makefile.am ($(com_netsplit_Nih_Test_object_OUTPUTS)):
($(com_netsplit_Nih_Test_proxy_OUTPUTS)): Must be newer than the
source for the python tool
* nih/nih_dbus_tool.py (Interface.variables, Interface.exports):
Only include the interface definition in object mode, we will need
something for proxying signals later, but right now this means
problems when building an object and its proxy together.
* nih/Makefile.am (com_netsplit_Nih_Test_proxy_OUTPUTS)
(com_netsplit_Nih_Test_proxy_XML)
($(com_netsplit_Nih_Test_proxy_OUTPUTS)): Generate sources in proxy
mode for the test interfaces.
(BUILT_SOURCES, MAINTAINERCLEANFILES, EXTRA_DIST): Build if necessary
before anything else, clean in maintainer-clean and include in the
distribution.
2008-06-30 Scott James Remnant <scott@netsplit.com>
* m4/libs.m4 (NIH_LIB_DBUS): Always check for Python, but don't error
or disable D-Bus unless the install option is defined. Otherwise if
we don't have it, don't define HAVE_PYTHON.
* nih/Makefile.am (noinst_SCRIPTS): Only build if we have python.
* nih/Makefile.am: Redress the Makefile such that the generated test
sources are actually included in the distribution tarball.
* nih/dbus.h (NihDDusProxy): Add definition for proxy structure
and prototype for function to create one.
* nih/nih_dbus_tool.py (Method.dispatchFunction): Adjust name of
destination member in the proxy.
* nih/dbus.c (nih_dbus_proxy_new): Simple function to create a new
proxy object.
* nih/tests/test_dbus.c (test_proxy_new): Add simple test for the
simple function, which will get more complicated if we add signal
filter registration later.
* nih/errors.h (NIH_DBUS_INVALID_ARGS): Add error caused when the
reply arguments on a method call were not what we expected.
* nih/nih_dbus_tool.py: Implement the simplest of the method dispatch
cases, a blocking method call with the reply data returned as arguments
to the call.
* nih/nih_dbus_tool.py: Allocate a copy of string arguments when
passing, this makes them consistent with arrays, and also means that
we can actually do method dispatching which requires the reply data
to last longer than the underlying message.
* nih/nih_dbus_tool.py: Add parent argument to marshal functions for
when we need to allocate something (ie. arrays)
* nih/nih_dbus_tool.py (DBusArray.marshal): Add extra parens around
possible deferenced length variable, not needed for precedence but
helps clarity in generated code.
(DBusArray.dispatch): Increment the length inside the for loop, rather
than always leaving it at zero, useful for debugging.
* nih/nih_dbus_tool.py: Have a bash at sorting out the whole pointer
and const problem again. Make them properties of a group, passed to
type functions that can add * and const as appropriate, and allows
DBusArray to be more clever about things. Works for the existing
cases, anyway.
* nih/nih_dbus_tool.py (Method.handlerPrototype): Only include
function pointers when the mode is object.
* nih/nih_dbus_tool.py: Allow mode to be changed to proxy, but don't
specify anything to be generated for that mode yet.
2008-06-11 Scott James Remnant <scott@netsplit.com>
* Makefile.am (SUBDIRS): po has to come last to make sure we've
built any auto-generated code before update-po
* nih/nih_dbus_tool.py (Method.marshalFunction): Allow the message
for the invalid args/type message to be translated.
* nih/tests/test_child.c (test_poll): We end up creating a core file,
so unlink it.
* nih/Makefile.am (tests/com.netsplit.Nih.Test_object.c tests/com.netsplit.Nih.Test_object.h):
Create the tests directory.
2008-06-08 Scott James Remnant <scott@netsplit.com>
* nih/Makefile.am (tests/com.netsplit.Nih.Test_object.c tests/com.netsplit.Nih.Test_object.h):
Make the tests directory in the output.
* nih/Makefile.am (EXTRA_DIST): Forgot to distribute the test XML
* nih/file.c (nih_file_read): Implement a simpler function for reading
a file into memory that does literally just that, better than map
for various reasons.
* nih/file.h: Add prototype.
* nih/tests/test_file.c (test_read): Test it works.
2008-06-06 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_DBUS, TEST_DBUS_OPEN, TEST_DBUS_MESSAGE)
(TEST_DBUS_CLOSE, TEST_DBUS_END): Various useful macros to set up,
connect to, pop messages from, close and kill D-Bus connections to
a private bus daemon.
* nih/tests/test_string.c (test_array_copy): Add a test case for a
zero-length array, which we need to be able to support.
* nih/string.c (nih_str_array_copy): Fix it by always creating a
new array to copy into, since array can't be NULL.
2008-06-04 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_com.netsplit.Nih.Test_object.c (test_method_marshal):
Why would I be allocating a string array using sizeof (int32_t),
fix C&P error to make amd64 happy again.
2008-06-02 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_DBUS): Initialise _test_address to zeros so
valgrind shuts up.
* nih/test.h (TEST_DBUS, TEST_DBUS_END): Macros to set up a
temporary D-Bus session bus for testing purposes.
* nih/tests/test_dbus.c (test_object_new, test_object_destroy)
(test_object_unregister): Use the system bus for testing, since
there may be no session bus.
* nih/tests/test_dbus.c (test_bus): We get an error when the
session bus is not available, so we should eat that before skipping.
2008-06-01 Scott James Remnant <scott@netsplit.com>
* nih/dbus.c (nih_dbus_object_message): Keep a reference on the
connection, as well as the message; otherwise if the connection is
disconnected while handling a async method, we'll end up trying to
send it to a freed connection instead of just a disconnected and
forgotten one.
(nih_dbus_message_destroy): Unreference the connection when freeing
the message object.
2008-05-28 Scott James Remnant <scott@netsplit.com>
* TODO (main, timers): Update.
* nih/nih_dbus_tool.py: The C type of string-like types should be
just "char *"; instead we should add "const" when needed, such as
in the prototype of handlers and in reply functions. This avoids
some const-bending games.
* nih/tests/test_com.netsplit.Nih.Test_object.c (my_emit_signal):
Adjust type of string array to match.
2008-05-24 Scott James Remnant <scott@netsplit.com>
* HACKING: Changed branch location again.
2008-05-18 Scott James Remnant <scott@netsplit.com>
* nih/error.h (nih_return_no_memory_error): Add a convenience macro
for raising the ENOMEM system error with the right string, rather
than setting errno just do it directly.
* nih/tests/test_error.c (test_return_no_memory_error): Make sure
the macro is tested.
* nih/dbus.c (nih_dbus_connect, nih_dbus_bus, nih_dbus_server):
Use new macro to return ENOMEM when we're not sure that it's the
current errno.
2008-05-14 Scott James Remnant <scott@netsplit.com>
* TODO: Update.
* nih/tests/test_com.netsplit.Nih.Test_object.c (my_str_to_int32_array):
Forgot to clean up parts after splitting.
(test_method_marshal): Forgot to free self-allocated arrays, and
we have to free a string array returned by D-Bus as well.
(test_signal_dispatch): Another string array to be freed.
* nih/tests/test_dbus.c (test_object_message): Don't use timeouts
to guess when the reply should have arrived, just use a pending
call notify function. This speeds the whole thing up a hundred
fold and removes valgrind slowness issues.
* nih/dbus.c (nih_dbus_message_error): Asynchronous messages need
a way to return an error message to the sender after the handler
function has terminated; this function fulfills that need
* nih/dbus.h: Add prototype.
* nih/tests/test_dbus.c (test_message_error): Add test case for
replying to an asynchronous message with an error; this ends up
somewhat evil since we're not using the bindings.
* nih/nih_dbus_tool.py: Use a namespaced attribute to specify
whether methods should be generated synchronous (reply generated
after handler returns) or asynchronous (handler expected to keep
the message object and call a reply function later).
* nih/tests/com.netsplit.Nih.Test.xml: Add a test asynchronous
method, the same basic method as the ordinary test method, but
which is specified to generate an asynchronous call.
* nih/tests/test_com.netsplit.Nih.Test_object.c: Add many tests
for async calls, in fact, we pretty much just duplicate the sync
tests but use a timer in the server to deliver the reply.
* nih/dbus.c (nih_dbus_object_message): Set a destructor for the
message that unreferences the attached D-Bus message when it
is freed, and don't unreference it ourselves. Also allow the
handler to return "not yet handled" to mean that the method
has actually been handled, but the reply hasn't been sent yet.
(nih_dbus_message_destroy): Destructor for the message.
2008-05-11 Scott James Remnant <scott@netsplit.com>
* nih/nih_dbus_tool.py: Implement handling for arrays of simple C
types with an extra length variable, and handling for arrays of
pointer types with an extra NULL element
* nih/tests/com.netsplit.Nih.Test.xml: Add test methods with an
int32 and string array as input and output, and test signals
with both array types.
* nih/tests/test_com.netsplit.Nih.Test_object.c: Add tests for
the new methods and signals, testing the underlying automatic
generation.
2008-05-10 Scott James Remnant <scott@netsplit.com>
* nih/string.c (nih_strncat, nih_strcat_vsprintf): Ok, there
was a minor technical reason after all; don't strlen the
string if we don't have it.
* nih/string.c (nih_strcat, nih_strncat, nih_strcat_sprintf)
(nih_strcat_vsprintf): Remove the restriction that the string
must be pre-allocated, there's no technical reason for it, I was
just trying to enforce a style.
2008-05-09 Scott James Remnant <scott@netsplit.com>
* nih/nih_dbus_tool.py: Drop the data type argument, and just
pass around void *; we never have the types available, and since
we have our own prototype anyway, we never upset gcc.
* nih/dbus.c (nih_dbus_path): Empty path components are named
as "_" instead.
* nih/tests/test_dbus.c (test_path): Test the new functionality.
2008-05-08 Casey Dahlin <cdahlin@redhat.com>
* nih/file.c (nih_file_is_packaging): Add matches for various
RPM temporary and atomicity files.
2008-05-08 Scott James Remnant <scott@netsplit.com>
* nih/dbus.c (nih_dbus_error_raise_printf): Add formatted error
function, I held out as long as I could
* nih/dbus.h: Add prototype.
* nih/tests/test_dbus.c (test_error_raise_printf): And test for it.
* nih/error.h: Add missing attribute
* nih/Makefile.am: No need for version info if not installing
2008-05-06 Scott James Remnant <scott@netsplit.com>
* m4/compiler.m4: -Wformat is already in -Wall
* nih/main.c (nih_main_daemonise): Deliberately ignore chdir
return value, repeat the dup calls until they work.
(nih_main_loop_interrupt): repeat write call until it succeeds.
* nih/test.h (TEST_CHILD, TEST_CHILD_WAIT, TEST_CHILD_RELEASE):
assert that pipe() returns zero and read() and write() both return 1.
(TEST_DIVERT_STDOUT_FD, TEST_DIVERT_STDERR_FD): assert that dup2
returns a file descriptor.
(TEST_FILE_RESET): assert ftruncate works.
* nih/tests/test_io.c (test_add_watch, test_select_fds)
(test_handle_fds, test_reopen, test_shutdown, test_destroy)
(test_watcher, test_read_message, test_send_message, test_read)
(test_write, test_get, test_printf, test_set_nonblock)
(test_set_cloexec): assert that the pipe() calls work.
(test_watcher): assert that write() returns expected number.
* nih/tests/test_file.c (test_map): Check the fgets works.
(test_dir_walk): assert that the symlink call works.
* nih/tests/test_main.c (test_daemonise): assert pipe(), write()
and getcwd() calls work.
* nih/tests/test_com.netsplit.Nih.Test_object.c (my_setup):
initialise wait_fd to get around gcc's blindness.
(my_emit_signal): initialise ret.
* m4/compiler.m4: Add -Wformat, -Wformat-security and
-D_FORTIFY_SOURCE=2 to our default CFLAGS unless compiler warnings
are disabled.
2008-04-29 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_com.netsplit.Nih.Test_object.c (test_method_marshal)
(test_signal_dispatch): For some reason valgrind needs some
reassurance that it's ok to pass uninitialised data around in various
cases; probably good for testing anyway.
* nih/dbus.c (nih_dbus_path): Function to generate D-Bus paths with
appropriate escaping of non-root elements.
* nih/dbus.h: Add prototype.
* nih/tests/test_dbus.c (test_path): Test the new function.
* nih/dbus.c (nih_dbus_object_introspect): Free the introspection
string after sending the message (oops!)
2008-04-27 Scott James Remnant <scott@netsplit.com>
* nih/tests/com.netsplit.Nih.Test.xml: Add signals to the test
interface for the variety of basic argument types, we also need
a glue function to make the server emit the signal.
* nih/tests/test_com.netsplit.Nih.Test_object.c (my_emit_signal)
(test_signal_dispatch): Test the signals are emitted and dispatched
properly by catching them and checking them.
2008-04-26 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_GROUP): Add macro for when we don't test functions.
* nih/tests/test_com.netsplit.Nih.Test_object.c (test_method_marshal):
Use TEST_GROUP here.
* nih/tests/com.netsplit.Nih.Test.xml: Add more methods to test,
one generic method and two methods (in and out) for each basic type.
* nih/tests/test_com.netsplit.Nih.Test_object.c: Slightly redo the
way we do the tests, do the basic set of tests using a single method
that can return cases such as errors, etc. Then have input and output
marshal tests for each of the basic types.
* nih/nih_dbus_tool.py (NAME_RE): Cope with numerics in member names,
treat them the same as lowerspace characters.
2008-04-25 Scott James Remnant <scott@netsplit.com>
* TODO: Update, adding missing pieces for D-Bus support and an
idea for changing the way that timers/signals/io/etc. work.
* nih_dbus_tool.py: Handle the basic D-Bus types and generate
marshalling functions for methods and dispatch functions for
signals, along with all of the glue needed for nih_dbus_object_new()
* nih/tests/com.netsplit.Nih.Test.xml: Interface to be used for
testing of the generated code.
* nih/tests/test_com.netsplit.Nih.Test_object.c: Test suite for
the generated code (in object mode), so far this just tests a
couple of methods but will be adding a lot more tests soon.
* nih/Makefile.am (TESTS): Add the above test suite.
(test_com_netsplit_Nih_Test_object_SOURCES)
(test_com_netsplit_Nih_Test_object_CFLAGS)
(test_com_netsplit_Nih_Test_object_LDFLAGS)
(test_com_netsplit_Nih_Test_object_LDADD): Details for the test suite.
(BUILT_SOURCES): Interface definitions are auto-generated and need
to be done so at the start of the build so deps work properly.
(CLEANFILES): All built sources need to be cleaned on "make clean"
(tests/com.netsplit.Nih.Test_object.c tests/com.netsplit.Nih.Test_object.h):
Generate the interface definitions with the binding tool, being
sure to regenerate if the XML or binding tool change.
* nih/dbus.c (nih_dbus_object_new): Register an object with D-Bus
and hook it up to an internal message handling function that deals
with introspection and the like, while passing off actual handling
to marshaller functions for individual methods.
(nih_dbus_object_destroy): When the object is freed, unregister
it from the bus making sure that doing so doesn't try to free it
a second time.
(nih_dbus_object_unregister): When the bus connection is dropped
or object otherwise unregistered, free it, making sure that doing
so doesn't try to unregister it a second time.
(nih_dbus_object_message): Handle messages for the object, locate
the marshaller function in the interface structures or pass off
to internal handler for introspection.
(nih_dbus_object_introspect): Handle the Introspect method by
generating XML which we return in a reply.
* nih/dbus.h: Add prototype for new function.
(NihDBusObject, NihDBusMessage, NihDBusMarshaller, NihDBusArgDir)
(NihDBusArg, NihDBusMethod, NihDBusSignal, NihDBusAccess)
(NihDBusProperty, NihDBusInterface): Add the truly insane number
of structures and enums we need to fully specify the interfaces
that a D-Bus object provides; you'll never do this by hand! :-)
* nih/tests/test_dbus.c (test_object_new, test_object_destroy)
(test_object_unregister, test_object_message): Test cases for new
functions.
(test_connect, test_bus): Check error messages using the macros
rather than by name.
2008-04-23 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_nih_dbus_tool.py: In hindsight, it's unnecessary
to test the binding tool directly since the tests will basically
just compare the output to an expected C file which will make
maintaining it damned hard and doesn't actually guarantee it works;
instead we'll test generated output.
* nih/Makefile.am (TESTS): Remove the call to the Python test suite,
and reverse the TESTS/check_PROGRAMS thing again to match.
2008-04-22 Scott James Remnant <scott@netsplit.com>
* nih/libnih-dbus.supp: D-Bus init_system_db() related leaks
were likely a missing dbus_shutdown() since they've gone away
now.
* nih/dbus.c (nih_dbus_add_timeout, nih_dbus_timeout_toggled):
Slightly adjust the millisecond to second conversion to always
round up to the nearest whole second rather than down; that way
we have a 1s minimum timeout instead of an immediate one.
2008-04-21 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_dbus.c (test_bus): Cope when the session bus
is not available.
* nih/libnih-dbus.supp: Suppress annoying NSS problems on i686
as well (we did x86-64 last time). Also found that a couple of
the suppressions were caused by failing to shutdown properly,
so remove those (and uncover a D-Bus bug or two in the process).
* nih/tests/test_dbus.c: Remove unnecessary SIGPIPE setting.
* nih/libnih-dbus.supp: I keep finding ways in which D-Bus holds
on to data, not to mention annoying NSS problems.
* nih/libnih.supp: Add long-missing suppression for the main loop
functions list, seems we've never actually tested that without
freeing it manually.
2008-04-18 Scott James Remnant <scott@netsplit.com>
* nih/dbus.c (nih_dbus_connect, nih_dbus_bus): Functions to connect
to an abitrary address or a well-known bus, calling our own handler
on disconnect instead of exit() and setting things up in the main
loop properly.
(nih_dbus_setup): Function called by the above, and callable
externally, to set up the disconnect handler and main loop hook-ups;
deals with shared connections by checking the main loop slot.
(nih_dbus_server): Similar function to create a listening server
and hook it up to the main loop.
(nih_dbus_add_watch, nih_dbus_remove_watch)
(nih_dbus_watch_toggled, nih_dbus_watcher): Glue functions so that
D-Bus can watch file descriptors using our main loop.
(nih_dbus_add_timeout, nih_dbus_remove_timeout)
(nih_dbus_timeout_toggled, nih_dbus_timer): Glue functions so that
D-Bus can set timeouts using our main loop.
(nih_dbus_wakeup_main): Glue function so that D-Bus can interrupt
the main loop (I think this is really for multi-threaded apps, but
it does no harm to force an iteration).
(nih_dbus_callback): Glue function to dispatch D-Bus messages
within the main loop.
(nih_dbus_connection_disconnected): Filter function to catch the
org.freedesktop.DBus.Local.Disconnected signal and call any
disconnect handler before unreferencing the connection.
(nih_dbus_new_connection): Handle new server connections by calling
the connect handler if set, referencing the new connection then
setting it up in the main loop.
* nih/dbus.h (NihDBusDisconnectHandler, NihDBusConnectHandler):
Function prototype typedefs for disconnect and connect handlers.
* nih/tests/test_dbus.c (test_connect, test_bus, test_setup)
(test_server): Test the new functions as best we can.
* nih/libnih-dbus.supp: D-Bus slot allocator doesn't free memory.
* nih/main.c (nih_main_loop_init): Make a non-static function.
* nih/main.h: Add prototype.
2008-04-16 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_FILE_NE, TEST_FILE_NE_N): Fix logic of tests.
2008-04-12 Scott James Remnant <scott@netsplit.com>
* nih/Makefile.am: If we're not installing the library then we
want to still make the script but don't want to install it.
* nih/nih_dbus_tool.py: Skeleton code for the Python binding tool.
* nih/tests/test_nih_dbus_tool.py: Test cases for the dbus tool.
* nih/Makefile.am (TESTS): When building the dbus library, also run
the Python test suite for the Python binding tool; this requires
reversing the check_PROGRAMS/TESTS setting since it needs to only
be in TESTS.
* nih/libnih-dbus.supp, nih/libnih-dbus.ver: Library support files.
* nih/dbus.c (nih_dbus_error_raise): Begin the D-Bus library with
a function to raise an NihError that can be converted into a
DBusError when necessary (to be used in function returns).
* nih/dbus.h (NihDBusError): Type for the structure since we need
to include a name member.
* nih/tests/test_dbus.c (test_error_raise): Test case.
* nih/errors.h: Add NIH_DBUS_ERROR error; no string for this since
each individual error will have its own.
2008-04-11 Scott James Remnant <scott@netsplit.com>
* m4/misc.m4: Reverse the sense of the noinstall option, so that
"install" needs to be present for libnih to be installed.
* configure.ac: Install libnih when built from its own source.
2008-03-29 Scott James Remnant <scott@netsplit.com>
* nih/Makefile.am (libraries): Build optional libnih-dbus.la
(libnih_dbus_la_SOURCES, libnih_dbus_la_CFLAGS)
(libnih_dbus_la_LIBS, -version-info 0, libnih_dbus_la_LDFLAGS):
Details for optional library.
(EXTRA_DIST): Distribute the version script and suppressions files.
(nihinclude_HEADERS): Install the optional libdbus header
(bin_SCRIPTS): Build optional nih-dbus-tool binding tool script
(CLEANFILES, EXTRA_DIST, do_subst, nih-dbus-tool): Create installed
script by substituting in another, be sure to distribute the other
and clean the intermediate file.
(TESTS): Optional test suite
(test_dbus_SOURCES, test_dbus_CFLAGS, test_dbus_LDFLAGS)
(test_dbus_LDADD): Details for the optional dbus test suite.
* m4/misc.m4 (AC_COPYRIGHT): Also add a Makefile PACKAGE_COPYRIGHT
variable for substitution.
(NIH_INIT): We have separate cflags for dbus-related tools, so we
need to check that gcc supports -c and -o.
* m4/libs.m4 (NIH_LIB_DBUS): Macro to detet whether pkg-config,
D-Bus and Python are available and decide based on that whether or
not we can build an optional D-Bus binding library; configure options
and arguments determine whether being unable to is a warning or an
error.
* m4/misc.m4: Add the dbus option to the help and the call to check
for the libraries.
* README: Add a section on the dependencies this introduces.
* m4/libs.m4: Add an empty file to hold macros relating to library
detection.
* m4/Makefile.am (dist_aclocal_DATA): Install and distribute the
new macro file.
* nihify: Symlink the new macro file across as well.
2008-03-19 Scott James Remnant <scott@netsplit.com>
* nih/hash.c (nih_hash_pointer_hash): Fix hash generation on 64-bit
systems by using each byte rather than trying to be clever.
2008-03-14 Scott James Remnant <scott@netsplit.com>
* nih/hash.c (nih_hash_new): Also require hash and cmp functions
and store in the structure.
(nih_hash_add, nih_hash_add_unique, nih_hash_add_replace)
(nih_hash_search, nih_hash_lookup): Change key type to void,
use hash and cmp functions from the structure.
(fnv_hash): Rename to nih_hash_string_key
(nih_hash_string_cmp): String comparison function.
(nih_hash_pointer_key, nih_hash_pointer_hash, nih_hash_pointer_cmp):
Pointer hash functions.
* nih/hash.h (NihHashFunction): Prototype for hash function.
(NihCmpFunction): Prototype for key comparison function.
(NihHash): Add hash_function and cmp_function members.
(nih_hash_pointer_new, nih_hash_string_new): Macros to wrap function
and pass in common key, hash and cmp functions.
* nih/tests/test_hash.c: Update tests to include new functions and
macros.
* nih/watch.c: Use nih_hash_string_new() to create the hash table.
* nih/command.c: Add const to local structures.
(nih_command_join): Expect to not change the structures passed
(nih_command_handle): Iterate structure as const.
* nih/command.h: Add const to prototype.
* nih/option.c: Add const to local structures.
(nih_option_join): Expect to not change the structures passed
* nih/option.h: Add const to prototype.
* nih/error.c (nih_error_init): Make extern for consistency.
* nih/error.h: Add prototype.
* nih/logging.c (nih_log_init): Make extern for consistency.
* nih/logging.h: Add prototype.
* nih/child.c (child_watches): Rename to nih_child_watches and
make extern.
(nih_child_init): Make extern, update name of global.
(nih_child_add_watch, nih_child_poll): Update name of global.
* nih/child.h: Add prototypes.
* nih/io.c (io_watches): Rename to nih_io_watches and make extern.
(nih_io_init): Make extern, update name of global.
(nih_io_add_watch, nih_io_select_fds, nih_io_handle_fds): Update
name of global.
* nih/io.h: Add prototypes.
* nih/main.c (loop_functions): Rename to nih_main_loop_functions
and make extern.
(nih_main_loop_init, nih_main_loop, nih_main_loop_add_func): Update
name of global.
* nih/main.h: Add prototype.
* nih/signal.c (signals): Rename to nih_signals and make extern.
(nih_signal_init): Make extern, update name of global.
(nih_signal_add_handler, nih_signal_poll): Update name of global.
* nih/signal.h: Add prototypes.
* nih/timer.c (timers): Rename to nih_timers and make extern.
(nih_timer_init): Make extern, update name of global.
(nih_timer_add_timeout, nih_timer_add_periodic)
(nih_timer_add_scheduled, nih_timer_next_due, nih_timer_poll): Update
name of global.
* nih/timer.h: Add prototypes.
* m4/misc.m4 (NIH_INIT): Allow the macro to take options, the first
of which shall be "noinstall" which defines a Makefile conditional
that prevents installation of files -- useful when embedded in
things like Upstart.
* m4/Makefile.am (dist_aclocal_DATA): Don't install if "noinstall"
is defined.
* nih/Makefile.am (lib_LTLIBRARIES): If "noinstall" is defined,
still build the library but do not install it.
(include_HEADERS): Don't install if "noinstall" is defined.
2008-03-08 Scott James Remnant <scott@netsplit.com>
* HACKING: Don't even need /product/ anymore.
* HACKING: Terminology changes: Bazaar-NG is now just Bazaar;
Malone is now just Launchpad's bug tracking system.
2008-03-07 Scott James Remnant <scott@netsplit.com>
* nih/error.h (NIH_SHOULD): We quite often need to loop while
we get ENOMEM, but break on another error; this does that.
* nih/watch.c (nih_watch_new): Use here, fixing a bug in the process
where we didn't re-raise the error again.
2008-03-06 Scott James Remnant <scott@netsplit.com>
* nih/string.c (nih_strcat, nih_strncat, nih_strcat_sprintf)
(nih_strcat_vsprintf): I'm needing to use realloc more than I should
for string concatenation, so lets have some functions to do that.
* nih/string.h: Prototypes for new functions.
* nih/tests/test_string.c (test_strcat, test_strncat)
(test_strcat_sprintf, test_strcat_vsprintf): Test the new functions.
* TODO: Update.
2008-03-03 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_config.c (test_token): Also check that backslashes
can escape themselves; since you may want a literal one followed by
whitespace or a newline.
* nih/config.c (nih_config_token): Dequote blackslash following a
blackslash.
* nih/tests/test_config.c (test_token): We don't want to dequote
anything other than newlines and whitespace, since the quote
characters may be important for the value (e.g. \$FOO being different
to $FOO). Add tests to make sure we don't.
* nih/config.c (nih_config_token): After a slash, only dequote
whitespace otherwise if we're copying, copy a literal slash character
first.
* nih/tests/test_string.c (test_array_append): Should work with a
NULL array argument.
* nih/string.c (nih_str_array_append): Make it work.
(nih_str_array_copy): Which makes this function somewhat simpler.
2008-03-02 Scott James Remnant <scott@netsplit.com>
* nih/libnih.supp (nih-command-parser, nih-option-parser): Suppress
leak of internal state during --help tests.
(nih-main-package-string-test): Modify suppression to also catch
when it's allocated within a test case.
2008-03-01 Scott James Remnant <scott@netsplit.com>
* nih/tree.h (NIH_TREE_FOREACH_FULL, NIH_TREE_FOREACH_PRE_FULL)
(NIH_TREE_FOREACH_POST_FULL): The lack of these macros was silly.
* nih/tests/test_tree.c (test_foreach_full)
(test_foreach_pre_full, test_foreach_post_full): Add tests.
* nih/tree.c (nih_tree_next, nih_tree_prev, nih_tree_next_pre)
(nih_tree_prev_pre, nih_tree_next_post, nih_tree_prev_post): Rename
these functions to *_full and add filter and data pointers, where
the filter must return FALSE if given otherwise a node is ignored.
* nih/tree.h: Update prototypes, and keep previous behaviour with
the old names through the use of macros. Typedef the filter function
pointer type.
* nih/tests/test_tree.c (test_next_full, test_prev_full)
(test_next_pre_full, test_prev_pre_full, text_next_post_full)
(test_prev_post_full): Test iteration with filters.
2008-01-16 Scott James Remnant <scott@netsplit.com>
* nih/tree.c (nih_tree_next, nih_tree_prev, nih_tree_next_pre)
(nih_tree_prev_pre, nih_tree_next_post, nih_tree_prev_post): It's
never possible to break out of the loop since we always return
inside it.
* nih/tests/test_child.c (test_poll): Add test case for the watch
being on the wrong event.
* m4/compiler.m4 (NIH_COMPILER_COVERAGE): Allow this to disable
use of -Os, which otherwise wouldn't be.
* configure.ac (AC_COPYRIGHT): Update copyright to 2008.
2008-01-15 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_child.c (test_poll): Don't run the ptrace tests
under valgrind, since they upset it somewhat and return different
things (I expect we end up tracing valgrind itself).
* nih/main.c (nih_main_daemonise): Formatting fix.
2008-01-14 Scott James Remnant <scott@netsplit.com>
* HACKING: Correct bzr URL to trunk.
2007-12-06 Scott James Remnant <scott@netsplit.com>
* nih/child.c (nih_child_poll): I give up. The wait queue can change
between an invocation of waitid with WNOWAIT and the invocation later
to "remove" the entry. WNOWAIT is a waste of time, and no matter how
useful it might have been, I just see no way of actually using it.
* nih/child.h: Update documentation.
2007-12-02 Scott James Remnant <scott@netsplit.com>
* nih/signal.c (nih_signal_set_handler): Drop the SA_NOCLDSTOP flag
from when we were setting SIGCHLD, I've no idea why this crept in
and it now stops us doing things we want to.
* nih/tests/test_signal.c (test_set_handler): Remove the test for it.
* nih/tests/test_child.c (test_poll): Fix for AMD64, the data
argument for PTRACE_GETEVENTMSG is unsigned long, which is larger
than pid_t here.
* nih/tests/test_child.c (test_poll): Fix up several race
conditions in the ptrace test cases, there are a lot of quirks you
have to remember when dealing this most insane of syscalls.
(signal from traced child): Once we've finished the test we must
detach from the child otherwise we'll trap our own SIGTERM and the
child won't exit. Tthere's no need to send SIGCONT since this
is an ordinary ptrace signal trap.
(exec by traced child): Detach and send SIGCONT in case the process
we run gets a signal delivered to it; if that happened, we'd trap
that signal and the child would never exit.
(fork by traced child): This is the most pathalogical. We had a
race where nih_child_poll() was actually reaping the event for the
child stopping. Change to get the child pid and wait for it before
calling the poll function. Don't bother waiting for the child to
terminate, we shouldn't ever find out if we've detached properly.
2007-11-29 Scott James Remnant <scott@netsplit.com>
* nih/main.c (nih_main_write_pidfile): Have to cast the difference
in pointers to int, otherwise we get a compiler warning on amd64.
* nih/child.c (nih_child_poll): Remove the hacks that shift the
status information back now that we have a kernel patch in akpm's
tree to fix it.
2007-11-15 Scott James Remnant <scott@netsplit.com>
* nih/child.c (nih_child_poll): I found out what was causing the
signal information to be missing for CLD_STOPPED, a kernel bug;
cope with it for now by shifting the status across 8 bits for
CLD_TRAPPED and CLD_STOPPED until I get Roland to fix that bit.
* nih/tests/test_child.c (test_poll): Replace sleeps with waitid
WNOWAIT calls now that that particular kernel bug is fixed; add
a couple of pauses so that the child doesn't exit and clean up
the wait queue before we get a chance to look. Add a wait on the
child stopping after fork to avoid a race condition where the child
isn't actually running yet when we try and detach from it.
* nih/child.h (NihChildWatch): Add events member and rename reaper
to handler, since it can now be called for things like stop, trap
and ptrace events.
(NihReaper): Rename to NihChildHandler
(NihChildEvents): Enumeration/bit flags for events member
* nih/child.c (WAITOPTS): Define wait options in one place to make
repeating them easier.
(nih_child_add_watch): Add events argument and change type and name
of function argument, set in the structure.
(nih_child_poll): Rather than just working out a killed boolean (which
was wrong anyway since it didn't take CLD_DUMPED into account), we
store one of many events in the event argument and convert status if
necessary (bit shifting for CLD_TRAPPED and ptrace events). Check
this event against the events mask in the watch, and pass to the
handler.
* nih/tests/test_child.c (test_add_watch): Check that events and
handler are initialised correctly.
(test_poll): Many new test cases for exiting, killing, aborting,
stopping, continuing, trapping and ptracing.
2007-11-03 Scott James Remnant <scott@netsplit.com>
* nih/watch.h (NihWatch): Add created hash table so we can easily
delay the create_handler until the file is closed.
* nih/watch.c (nih_watch_new): Initialise the created hash table.
(nih_watch_handle): When a file is created, add an entry to the
created hash table and return without calling a handler -- for all
paths, check for and remove any remove any existing created entry;
call create_handler instead of modify_handler if this exists, and
don't call delete_handler at all.
* nih/tests/test_watch.c (test_new): Check created is initialised.
(test_reader): Test that creating a file doesn't trigger create
until it's closed and that unlinking a file before it's been closed
doesn't trigger at all.
* nih/test.h (TEST_FREE_TAG): assert that we don't use this on
a NULL pointer.
2007-11-02 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_FUNCTION_FEATURE): Add macro for when we're
testing a specific feature of a function.
2007-10-27 Scott James Remnant <scott@netsplit.com>
* m4/compiler.m4 (NIH_COMPILER_OPTIMISATIONS): Add extra [...]
* m4/compiler.m4 (NIH_COMPILER_WARNINGS): Add missing [...] around
the second argument to AS_IF.
(NIH_COMPILER_OPTIMISATIONS): Fix wrong use of [..][..] to [....]
(NIH_COMPILER_COVERAGE): Remove extraneous comma
* m4/linker.m4 (NIH_LINKER_VERSION_SCRIPT): Restore AM_CONDITIONAL
that was mistakenly dropped.
2007-10-26 Scott James Remnant <scott@netsplit.com>
* m4/linker.m4 (NIH_LINKER_SYMBOLIC_FUNCTIONS): Test that checks
for -Bsymbolic-functions
* m4/linker.m4: Style fix.
* m4/compiler.m4 (NIH_COMPILER_COVERAGE, NIH_COMPILER_OPTIMISATIONS)
(NIH_COMPILER_WARNINGS): Update to use AS_IF.
* m4/compiler.m4 (NIH_C_THREAD): Shell fix.
* m4/linker.m4 (NIH_LINKER_OPTIMISATIONS): Update to use AS_IF.
* m4/linker.m4 (NIH_LINKER_VERSION_SCRIPT): Update so it supports
a config.cache
2007-10-24 Scott James Remnant <scott@netsplit.com>
* nih/file.c (nih_file_map): Catch a file larger than the length of
size_t and raise the standard EFBIG error message. Noticed by
Kees Cook.
2007-10-15 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c (nih_alloc_using, nih_alloc_reparent, nih_realloc):
Change the order in which children allocations are stored in the
list such that the last allocation is freed first rather than
the other way around. This solves issues of children being stored
inside an allocated hash table which will be freed first.
* m4/misc.m4 (NIH_INIT): Use AC_PROG_CC_C99 instead of NIH_C_C99
* configure.ac: Bump Autoconf dependency to 2.61
* HACKING: Likewise increase documentation
* HACKING: Correct Bazaar branch now we're natively hosted on LP
* nih/test.h (_test_allocator): Mark used in case it isn't.
(_test_free_tag, _test_free_tags, _test_destructor)
(TEST_FREE_TAG, TEST_FREE, TEST_NOT_FREE): Since destructors are
now intended for internal use by an object, we shouldn't abuse them
in test cases like we were doing - since we might not chain up
properly and miss vital behaviour as a result. Instead implement
some tests that use a destructor on an nih_alloc() child of the object
to determine freeness.
* nih/tests/test_watch.c (test_reader): Use TEST_FREE instead of
a custom destructor, which are no longer favoured for this kind
of work.
* nih/tests/test_error.c (test_raise_again, test_pop_context):
Use TEST_FREE instead of custom destructor.
* nih/tests/test_timer.c (test_poll): Use TEST_FREE/TEST_NOT_FREE
* nih/tests/test_child.c (test_poll): Use TEST_FREE, etc.
* nih/tests/test_io.c (test_shutdown, test_watcher)
(test_read_message, test_read, test_get): Use TEST_FREE, etc.
* nih/hash.c, nih/timer.c, nih/signal.c, nih/child.c, nih/io.c,
nih/watch.c: Document why non-allocated versions of functions
are missing.
* TODO: Update.
2007-10-14 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c (nih_free): Call destructors before freeing children,
this makes them more consistent with being structure clean-up
functions rather than using them to detect a free. Don't return
values from children destructors.
* nih/tests/test_alloc.c (test_free): Adjust test, return values
from children destructors are never returned.
* nih/watch.c (nih_watch_new): Make the io structure an nih_alloc
child of the watch, now that we don't perform any kind of lazy
freeing or closing.
(nih_watch_destroy): No need to close the io structure since it'll
be automatically freed, just set the flag to be caught in the reader.
* nih/tests/test_watch.c (test_new): Check parent of watch->io
is watch, not NUL.
(test_destroy): Don't use the destructor anymore, nih_alloc is tested
elsewhere.
(test_reader): Don't use destructor to test watch->io
(my_destructor): Always call nih_watch_destroy since this is only
used for that.
* nih/io.c (nih_io_close): Rename to nih_io_destroy, setting a free
flag in the structure if necessary before closing the descriptor
and calling the error handler if there's a problem.
(nih_io_reopen): Set destructor
(nih_io_watcher): Rename lazy_close to caught_free and check its
value after any calls to the reader, error handler or close handler
functions; if true, simply bail out. Reorder leaving so that a
shutdown check happens last (since this can free the structure).
(nih_io_closed): Now simply calls the close handler if it exists,
otherwise frees the structure.
* nih/io.h (NihIo): Rename close member to free.
Update prototypes.
* nih/tests/test_io.c (my_reader, test_reopen): Use nih_free
instead of nih_io_close.
(test_reopen): Create new fds each time, since they are closed
on free now.
(destructor_called): Chain up to call nih_io_destroy
(test_close): Rename to test_destroy and alter appropriately.
(test_watcher): Adjust documentation to say we're checking that free
is called in the reader.
(test_send_message, test_write, test_printf): Open pipes rather
than just stdout, because that will end up closed.
2007-10-12 Scott James Remnant <scott@netsplit.com>
* nih/watch.h (NihCreateHandler, NihModifyHandler, NihDeleteHandler):
Modify doc strings to mention nih_free instead of nih_watch_free
* nih/tests/test_file.c (my_visitor): Set destructor for the list
entries we create as we go.
* nih/watch.c (nih_watch_reader): Rework the function slightly,
instead of using the free pointer to free at the end of the handler,
use it to detect the free after the handler returns and immediately
abort -- it means we won't process remaining watches but meh.
(nih_watch_handle): Get passed the caught_free flag and check it
after calling any handlers to make sure we abort properly.
(nih_watch_free): Rename to nih_watch_destroy and just handle the
internal cleanup.
(nih_watch_new): Set the destructor properly.
* nih/watch.h: Update prototypes.
* nih/tests/test_watch.c (test_free): Rename to test_destroy.
(my_delete_handler): Use nih_free not nih_watch_free
(my_destructor): Chain up to nih_watch_destroy for NihWatch.
* nih/tests/test_watch.c (my_destructor): Neither NihWatch nor NihIo
need a destructor to be called.
* nih/tests/test_child.c (test_poll): Fix erroneous removal of "1"
* TODO: Update.
2007-10-11 Scott James Remnant <scott@netsplit.com>
* nih/option.c, nih/command.c, nih/config.c: Remove references to
nih_alloc_set_destructor() from doc strings since this is now
considered bad practice.
* nih/main.c (nih_main_loop_add_func): Adjust call to set destructor
* nih/tests/test_main.c (test_main_loop)
(test_main_loop_add_func): Call nih_free instead of nih_list_free
* nih/watch.c (nih_watch_add, nih_watch_handle): Call nih_free
instead of nih_list_free
(nih_watch_add): Set destructor to nih_list_destroy for now.
* nih/tests/test_watch.c (my_destructor): Call nih_list_destroy
for NihWatch structure.
* nih/file.c (nih_dir_walk_visit): Call nih_free instead of
nih_list_free
(nih_dir_walk, nih_dir_walk_visit): Set destructor on object.
* nih/tests/test_io.c (test_add_watch, test_select_fds)
(test_handle_fds, test_shutdown, test_watcher): Call nih-free
instead of nih_list_free
(destructor_called): Call nih_list_destroy when passed an
NihIoMessage; a bit icky since this is also called for an NihIo
which doesn't have a destructor (yet)
* nih/io.c (nih_io_watcher_write, nih_io_read, nih_io_get): Call
nih_free instead of nih_list_free.
(nih_io_add_watch): Adjust call to set destructor
(nih_io_message_new): Set a destructor so the message is removed
from a list when freed.
* nih/child.c (nih_child_add_watch): Adjust call to set destructor
(nih_child_poll): Call nih_free instead of nih_list_free
* nih/tests/test_child.c (test_add_watch, test_poll): Call nih_free
instead of nih_list_free.
(my_destructor): Call nih_list_destroy().
* nih/string.c: Fix documentation as below.
* nih/hash.c: Fix doc string, destructors are now considered internal
and shouldn't be set by callers.
* nih/signal.c (nih_signal_add_handler): Adjust call to set destructor
* nih/tests/test_signal.c (test_add_handler): Call nih_free instead
of nih_list_free
* nih/timer.c: Fix doc strings
* nih/timer.c (nih_timer_add_timeout, nih_timer_add_periodic)
(nih_timer_add_scheduled): Adjust calls to set destructor.
(nih_timer_poll): Call nih_free rather than nih_list_free.
* nih/tests/test_timer.c (test_add_timeout, test_add_periodic)
(test_add_scheduled, test_next_due): Call nih_free rather than
nih_list_free
(my_destructor): Call the list destructor.
* nih/tree.c (nih_tree_destructor): Rename to nih_tree_destroy()
(nih_tree_free): Drop.
(nih_tree_new, nih_tree_entry_new): Set destructor.
* nih/tree.h: Update prototypes.
* nih/tests/test_tree.c (test_destructor): Rename.
(test_free): Drop
* nih/: Documentation string fix.
* nih/tests/test_hash.c (test_string_key): Replace nih_list_free
call with nih_free, since we're not overriding the destructor.
* nih/list.c (nih_list_free): Drop this function.
(nih_list_destructor): Rename to nih_list_destroy()
(nih_list_new, nih_list_entry_new): Set destructor function.
* nih/list.h: Update prototypes.
* nih/tests/test_list.c (test_destructor): Rename.
(test_free): Drop.
(test_add): Replace nih_list_free calls with nih_free
2007-10-08 Scott James Remnant <scott@netsplit.com>
* configure.ac (AM_GNU_GETTEXT_VERSION): Bump to 0.16.1 since this
version of gettext is needed for compatibility with Automake 1.10
* HACKING: Bump version in the docs too.
* Makefile.am (ACLOCAL_AMFLAGS): Specify that aclocal install
ordinarily system-wide macros into m4 (libtool.m4, specifically).
This makes it easier for packagers to modify autoconfery since
aclocal is no longer a destructive event.
* configure.ac (AM_INIT_AUTOMAKE): Increase Automake requirement to
1.10 to ensure we have aclocal --instal
* HACKING: Increase Automake version in the docs.
2007-06-22 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_tree.c (test_next, test_prev, test_next_pre)
(test_prev_pre, test_next_post, test_pre_post): Add tests for a
single-node tree, because we found a bug where it didn't work.
* nih/tree.c (nih_tree_next): Bug fix; check there is a right node
before checking whether we've returned from it, otherwise we could
confuse it with starting at the top of the tree.
(nih_tree_prev): Likewise check there is a left node before checking
whether we've returned from it.
2007-06-20 Scott James Remnant <scott@netsplit.com>
* nih/config.c (nih_config_parse_stanza): Free name after use.
* nih/config.c (nih_config_parse_stanza): Don't dequote stanza
names, since otherwise they can't be made non-special; if we don't
recognise the stanza we parsed, raise the error without updating
pos, since we want it to point to the start of the token.
* nih/tests/test_config.c (test_parse_stanza): Update pos in test.
2007-06-18 Scott James Remnant <scott@netsplit.com>
* nih/list.h (NihListEntry): Define structure combining an NihList
with a union of common types.
* nih/list.c (nih_list_entry_new): Add a helper function for when
we need a simple entry without any extra structure around it.
* nih/tests/test_list.c (test_entry_new): Test the new function.
* nih/tree.h (NihTreeEntry): Define structure combining an NihTree
with a union of common types.
* nih/tree.c (nih_tree_entry_new): Add a helper function for when
we need a simple node without any extra structure around it.
* nih/tests/test_tree.c (test_entry_new): Test the new function.
2007-06-15 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_tree.c (test_next, test_foreach, test_prev)
(test_next_pre, test_foreach_pre, test_prev_pre, test_next_post)
(test_foreach_post, test_prev_post): Add tests for partial tree
traversal, we don't expect to break out of the confines of the
root that we've set, even if it has a parent.
* nih/tree.c (nih_tree_next, nih_tree_prev, nih_tree_next_pre)
(nih_tree_prev_pre, nih_tree_next_post, nih_tree_prev_post): Before
moving up to the parent node, check whether the current node is the
tree root; if it is, return NULL instead since we've iterated the
sub-tree we were looking at.
* nih/tests/test_tree.c (test_next, test_foreach, test_prev)
(test_next_pre, test_foreach_pre, test_prev_pre, test_next_post)
(test_foreach_post, test_prev_post): Use two different arrays to
make it really obvious how the tree is constructed and what order
we really expect it to be in. This makes it easier to get ready for
the next bit ...
* nih/tree.c (nih_tree_next, nih_tree_prev): Minor bug fix, set the
previous to the tree's parent when visiting for the first time so that
partial tree iterations might be able to work. Make algorithm code
simpler and more readable.
(nih_tree_next_pre, nih_tree_prev_pre): Algorithm for non-recursive
pre-order tree iteration, note that unlike the above, these are not
symmetrical.
(nih_tree_next_post, nih_tree_prev_post): Algorithm for non-recursive
post-order tree iteration, note that these aren't symmetrical with
each other, but are the symmetrical equivalents of the pre-order
functions.
* nih/tree.h: Add prototypes for new functions.
(NIH_TREE_FOREACH_PRE, NIH_TREE_FOREACH_POST): Add convenience
iteration macros for pre-order and post-order iteration.
* nih/tests/test_tree.c (test_next, test_foreach, test_prev): Add
some documentation for the tree shape, and how we work out the node
numbers. In each case, we were accidentally giving the expected
first node (which fortunately always worked); to test this harder,
give the root node instead!
(test_next_pre, test_foreach_pre, text_prev_pre): Test pre-order
tree iteration with the same basic code.
(test_next_post, test_foreach_post, text_prev_post): Test post-order
tree iteration with the same basic code.
2007-06-12 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_HASH_NOT_EMPTY): Add missing ;
* nih/main.c (nih_main_unlink_pidfile): Add for completeness.
* nih/main.h: Add prototype.
* nih/tests/test_main.c: Use the new function here for testing.
* nih/main.c (nih_main_pidfile): Rename to nih_main_write_pidfile
(nih_main_set_pidfile, nih_main_get_pidfile)
(nih_main_read_pidfile): Add companion functions to set and get the
current location, and also read from it.
* nih/main.h: Add prototypes.
* nih/tests/test_main.c (test_set_pidfile, test_read_pidfile)
(test_write_pidfile): Test the functions as best we can.
* nih/main.c (nih_main_daemonise): Cut the pid file writing out
(nih_main_pidfile): and place it into its own function, since we
seem to use this elsewhere too.
* nih/main.h: add prototype.
* nih/main.c (nih_main_daemonise): Don't just write the pid file
directly, and hope it works. Write to a temporary file, flush and
sync it, then rename to the real filename. This provides a "if the
pid file exists, a pid can be read from it" contract - or at least,
the nearest we can to that.
2007-06-11 Scott James Remnant <scott@netsplit.com>
* nih/config.c (nih_config_skip_block): Simple function to skip over
a block inline without parsing it into a string.
* nih/config.h: Add prototype.
* nih/tests/test_config.c (test_skip_block): Test the new function.
2007-06-10 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_HASH_EMPTY, TEST_HASH_NOT_EMPTY): Add some
tests for hash emptyness.
2007-06-03 Scott James Remnant <scott@netsplit.com>
* nih/file.h (NihFileFilter): add missing data pointer to definition.
* nih/file.c (nih_dir_walk_scan): Take the data pointer and pass it
to the filter function.
(nih_dir_walk, nih_dir_walk_visit): Pass data pointer to scan function.
(nih_file_ignore): Accept and ignore a data pointer.
* nih/tests/test_file.c (my_filter): Add data pointer.
(test_ignore): Pass NULL for data pointer.
* nih/watch.c (nih_watch_handle): Pass data to filter function.
* nih/tests/test_watch.c (my_filter): Add data pointer.
2007-05-27 Scott James Remnant <scott@netsplit.com>
* nih/config.c (nih_config_parse): Since we've elimated all of the
uses of ssize_t in this code, we're safe to parse a file larger
than SSIZE_MAX, so drop the check.
* nih/errors.h (NIH_CONFIG_TOO_LONG): Drop this error, since there
can be no such case anymore; technically we don't handle very large
files since we can only map 4GB of memory, but we fail by mapping
a smaller part of the file, rather than overrunning any buffers.
* nih/config.c (nih_config_parse_block): Don't use -1 in ws to
indicate we've not counted it yet, instead use the current value
of lines; this elimates the last ssize_t from the code.
* nih/config.c (nih_config_block_end): Modify to return TRUE or
FALSE, and set the end position through an argument instead.
(nih_config_parse_block): Update the way we call nih_config_block_end
to receive the end location via the pointer, rather than as the
return value.
* nih/config.c (nih_config_token): Change return value to an int,
and return the token length through an argument pointer if given.
This eliminates a need for ssize_t for this function.
(nih_config_next_token, nih_config_parse_command): Update way we
call nih_config_token to obtain the length through a pointer, and
directly check the return value to decide whether to abandon it.
* nih/config.h: Update prototype.
* nih/tests/test_config.c (test_token): Update the tests to check
the pointed value for the length, and the return value for error.
2007-05-18 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_string.c (test_array_append): Make sure that the
array is returned unaltered (at least, apparently) if any allocation
fails during the append.
* nih/string.c (nih_str_array_append): Record the original length,
and pass always pass our local length variable to nih_str_array_add.
Before returning, overwrite the returned length; if any allocation
fails, unwind other allocations and restore the NULL pointer before
returning NULL.
* nih/string.c (nih_str_array_copy, nih_str_array_append): Add a
couple of functions to copy a string array, and to append one onto
the end of another. Saves reimplementing this each time.
* nih/string.h: Add prototypes.
* nih/tests/test_string.c (test_array_copy, test_array_append):
Test the new functions.
2007-04-24 Scott James Remnant <scott@netsplit.com>
* nih/string.c (nih_vsprintf): Add va_end to va_copy; C standard
says so.
2007-03-13 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_io.c (test_get_family): The elmos of this world
like to disable various networking protocols, so expect that and
skip test cases.
* nih/io.h: Change int_data type to a plain old int; there's no
reason for it to be a fixed width type, and we may as well think
about supporting ILP64 in case someone does something silly one day.
2007-03-11 Scott James Remnant <scott@netsplit.com>
* m4/compiler.m4: Don't check for __thread unless --enable-threading
given to configure, instead define it to empty.
* TODO: Update.
2007-03-09 Scott James Remnant <scott@netsplit.com>
* nih/logging.c: Make the current log priority available globally
through the nih_log_priority variable.
* nih/logging.h: Update.
2007-03-08 Scott James Remnant <scott@netsplit.com>
* nih/macros.h (_n): Add a macro to wrap ngettext() for plural forms.
2007-03-02 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_watch.c: Skip these tests if inotify is not
available, since there's not much we can do.
2007-02-16 Scott James Remnant <scott@netsplit.com>
* nih/tree.c (nih_tree_next, nih_tree_prev): Add non-recursive
functions to iterate a tree in-order either forwards or backwards.
* nih/tree.h (NIH_TREE_FOREACH): Standard macro for wrapping
nih_tree_next and turning it into a for loop.
* nih/tests/test_tree.c (test_next, test_foreach, test_prev): Test
things with a complex tree to see whether they work out ok.
* nih/list.h: Fix formatting and ordering.
* nih/list.c: Fix function ordering.
* nih/tree.c: Add generic code to implement pure binary trees.
* nih/tree.h: Structures, typedefs and prototypes.
* nih/tests/test_tree.c: Binary tree test suite.
* nih/libnih.h: Include tree.h
* nih/Makefile.am (libnih_la_SOURCES): Build and link tree.c
(nihinclude_HEADERS): Install tree.h
(TESTS): Build and run binary tree test suite.
(test_tree_SOURCES, test_tree_LDFLAGS, test_tree_LDADD): Details for
binary tree test suite binary.
2007-02-15 Scott James Remnant <scott@netsplit.com>
* nih/watch.c (INOTIFY_EVENTS): Use IN_CLOSE_WRITE instead of
IN_MODIFY; since that guarantees the file has actually been closed,
and is probably on the filesystem now.
2007-02-13 Scott James Remnant <scott@netsplit.com>
* nih/signal.c: Add SIGUNUSED to the list of signals that might not
exist.
* nih/tests/test_option.c (test_parser): gcc doesn't like using
variables inside fixed for loops, so initialise it deliberately.
* nih/tests/test_command.c (test_help): Was mistakenly repeatedly
opening output.
(test_parser): Similar for loop issue.
* nih/signal.c: Update signal name list, some signals don't exist on
sparc and some turn up unexpectedly.
2007-02-11 Johan Kiviniemi <johan@kiviniemi.name>
* nih/hash.h (NIH_HASH_FOREACH, NIH_HASH_FOREACH_SAFE): Added missing
parenthesis around hash, in case it's a complicated expression with
unsurprising precedence results.
2007-02-11 Scott James Remnant <scott@netsplit.com>
* nih/config.c (nih_config_skip_whitespace): It turns out that when
parsing, it's often useful to skip any whitespace while retaining the
"step over newlines" behaviour. Seperate it out into its own
function.
(nih_config_next_token): Call the new function.
* nih/config.h: Add prototype.
* nih/tests/test_config.c (test_skip_whitespace): Check the function
* nih/config.c: Remove macro definitions
* nih/config.h: and make them public instead
* nih/tests/test_config.c: Use macros.
* nih/config.c (nih_config_next_token): Strange hybrid function,
it behaves like next_arg() but accepts the same arguments as token();
it skips whitespace, but only if the initial whitespace character is
in the delim argument.
(nih_config_next_arg): This becomes a wrapper around next_token.
* nih/config.h: Add prototype.
* nih/tests/test_config.c (test_next_token): Check the new function.
* nih/config.c (nih_config_next_token): Rename to nih_config_token,
since this doesn't behave like the next_arg() function, and we want
a similar token function that behaves like that.
* nih/config.h: Update.
* nih/tests/test_config.c (test_next_token): Rename and update.
2007-02-09 Scott James Remnant <scott@netsplit.com>
* nih/hash.h (NIH_HASH_FOREACH_SAFE): Oops, s/list/hash/
* nih/hash.h (NIH_HASH_FOREACH, NIH_HASH_FOREACH_SAFE): Add macros
to iterate over an entire hash table.
* nih/tests/test_hash.c (test_foreach, test_foreach_safe): Test the
macros.
* nih/hash.c (nih_hash_string_key): Add a useful function to return
the first member after the list header.
* nih/hash.h: Add prototype.
* nih/tests/test_hash.c (test_string_key): Add test case.
* nih/file.c (nih_file_is_packaging): Check for common packaging
filenames -- I swore I wrote this, but I can't find it.
(nih_file_ignore): Ignore packaging files.
* nih/file.h: Update.
* nih/tests/test_file.c (test_is_packaging, test_ignore): Test.
2007-02-07 Scott James Remnant <scott@netsplit.com>
* nih/logging.c (nih_logger_printf): Change printf logger to not
prefix anything intended for stdout.
* nih/logging.h: Rearrange.
* nih/tests/test_logging.c (test_logger_printf): Make sure that
we don't prefix the program name for messages that go to stdout.
2007-02-06 Scott James Remnant <scott@netsplit.com>
* nih/signal.c (nih_signal_from_name): Table changed to not contain
SIG, so this now strips it off the front if present.
* nih/tests/test_signal.c (test_to_name): Strip SIG from the front
(test_from_name): Check that we can omit SIG from the front.
* nih/signal.c (nih_signal_to_name, nih_signal_from_name): Functions
annoyingly missing from the standard library; convert signal names
and numbers between each other (e.g. SIGTERM -> 15).
* nih/signal.h: Add prototypes.
* nih/tests/test_signal.c (test_to_name, test_from_name): Put the
new functions through their paces.
* nih/string.c (nih_str_array_add, nih_str_array_addn): Correct leak
when array allocation fails.
* nih/string.c (nih_str_array_add, nih_str_array_addn)
(nih_str_array_addp): Allow the array pointed to to be NULL, after all,
realloc works anyway. Also allow len to be NULL, in which case, we
count the elements automatically.
* nih/tests/test_string.c (test_array_addp): Update test cases.
* nih/config.c (nih_config_parse_args): Use nih_str_array functions.
* nih/file.c (nih_dir_walk_scan): Use nih_str_array functions.
* nih/option.c (nih_option_parser): Use nih_str_array functions.
(nih_option_add_arg): Drop this function now.
* nih/string.c (nih_str_array_addp): Yet another variation on a theme;
this one saves duplicating allocs, which is always messy.
(nih_str_array_addn): Wrap around the above function.
(nih_str_array_add): Make this a wrapper around addp instead.
* nih/string.h: Update.
* nih/tests/test_string.c (test_array_addp): Check that one works.
* nih/string.c (nih_str_split): Use nih_str_array functions.
* nih/string.c (nih_str_array_addn): Add a version of nih_str_array_add
that calls nih_strndup instead of nih_strdup.
(nih_str_array_add): turn into a thin wrapper around the above.
* nih/string.h: Update.
* nih/tests/test_string.c (test_array_addn): Test new function.
* nih/string.c (nih_str_array_add): Flip array and parent arguments
to make it more like realloc.
* nih/string.h: Update.
* nih/tests/test_string.c (test_array_add): Update.
* nih/string.c (nih_str_array_new, nih_str_array_add): Functions
to handle the common cases of arrays of strings.
* nih/string.h: Update.
* nih/tests/test_string.c (test_array_new, test_array_add): Test.
* nih/watch.c (nih_watch_handle): Never assert on data received from
an untrusted source (well, the kernel, anyway). Also make sure nobody
sneaks a '/' into the name of an inotify event.
2007-02-05 Scott James Remnant <scott@netsplit.com>
* nih/string.c (nih_vsprintf): Make sure vsnprintf never returns
a negative value; C99 says it can't, of course, but Kees was
paranoid.
2007-02-03 Scott James Remnant <scott@netsplit.com>
* nih/watch.c (nih_watch_new): Tidy up ENOMEM loop.
* nih/tests/test_file.c (test_dir_walk): Fix leak of directory caused
by not removing a symlink.
* nih/tests/test_watch.c (test_new, test_add): Fix leaks of
directories caused by not changing permissions back so we can unlink
under them.
* nih/watch.h (NihCreateHandler, NihModifyHandler): Add stat argument.
* nih/watch.c (nih_watch_handle): stat any object created or modified,
and pass the stat buf to the handler function.
(nih_watch_add_visitor): Pass stat argument here too.
* nih/tests/test_watch.c: Add arguments.
* nih/option.c (nih_option_int): Function to parse integer values
on the command line.
* nih/option.h: Add prototype.
* nih/tests/test_option.c (test_int): test case for it.
* nih/file.c (nih_file_is_hidden, nih_file_is_backup)
(nih_file_is_swap, nih_file_is_rcs): Functions to match common
file types by their path.
(nih_file_ignore): Function to combine calls to all of the above.
* nih/file.h: Add prototypes.
* nih/tests/test_file.c: Add test cases for the new functions.
* TODO: Update.
2007-02-02 Scott James Remnant <scott@netsplit.com>
* TODO: Update.
* nih/watch.c (nih_watch_new): Add a create argument to avoid
walking a directory tree twice; store in the structure.
(nih_watch_add_visitor): Call the create handler if necessary.
* nih/watch.h: Update structure to include member and prototype.
* nih/tests/test_watch.c (test_new): Check that, when called with
create, the handler is called for each file that exists.
(test_reader): Check that a directory is recursed when moved in
or created with existing files.
* nih/tests/test_watch.c (test_reader): Add test case for watching
sub-directories again.
* nih/watch.c (nih_watch_new, nih_watch_add): Make safe against
ENOMEM; otherwise it's just tricky to decide when it's good and bad
to throw things out.
* nih/tests/test_watch.c: Update test cases accordingly.
* nih/watch.c (nih_watch_add): It's not an error for subdirs to be
TRUE when we get passed a filename.
* nih/tests/test_watch.c (test_add): Check that it works.
* nih/file.c (nih_dir_walk): Initialise ret to zero, otherwise
can return an uninitialised value when walking an empty directory.
* nih/tests/test_child.c (test_poll): Reap the child we kill,
otherwise the next test might fail sometimes.
* nih/watch.c (nih_watch_add): Make being unable to recurse into
sub-directories to watch them an error.
* nih/tests/test_watch.c (test_new, test_add): Update test cases.
* nih/file.c (nih_dir_walk): Rework this function to support
detection of directory loops, and reporting of errors with a callback
handler rather than just aborting the walk.
(nih_dir_walk_scan): Build up a sorted list of paths under a directory,
filtered with the filter function. Split out because it has different
error handling semantics.
(nih_dir_walk_visit): Visit a single path and if it's a directory,
descend into it.
* nih/file.h (NihFileVisitor): Add arguments to pass the top-level
directory and the stat buffer of the path (to avoid stating the same
things multiple times).
(NihFileErrorHandler): Duplicate prototype for the error handler.
* nih/errors.h (NIH_DIR_LOOP_DETECTED): Add new error.
* nih/tests/test_file.c (test_dir_walk): Update test cases, improving
test coverage at the same time.
* nih/watch.c (nih_watch_add_visitor): Update to check the stat
passed to the visitor, as well as accept the directory name,
2007-02-01 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_io.c: Replace NIH_ZERO in test cases with assert0
* nih/tests/test_main.c (test_main_loop): Eliminate use of NIH_MUST
* nih/tests/test_io.c (test_watcher): Remove unnecessary NIH_MUST
* nih/test.h (assert0): Add an assert wrapper for the common
alternate case.
2007-01-30 Scott James Remnant <scott@netsplit.com>
* nih/io.c (nih_io_buffer_resize): Always keep a buffer filled with
zeros when we extend it, so we never pass uninitialised data to
syscalls.
* m4/misc.m4 (NIH_INIT): Detect valgrind/valgrind.h
* nih/tests/test_signal.c: Detect valgrind and don't check the error
values from trying to set SIG_DFL or SIG_IGN for SIGKILL; which for
no readily apparent reason, works under valgrind.
* HACKING: Add newline to end of file.
* nih/test.h (TEST_ALLOC_SAFE): Add macro to guard allocations so
they aren't counted.
* nih/tests/test_file.c (my_visitor, test_dir_walk): Use
TEST_ALLOC_SAFE instead of changing the allocator by hand.
* nih/tests/test_io.c (test_watcher): Use TEST_ALLOC_SAFE instead of
changing the allocator by hand,
* nih/macros.h (NIH_MUST_NOT): Rename to NIH_ZERO
* nih/io.c (nih_io_message_recv): Use NIH_ZERO, instead of == 0
* nih/main.c (nih_main_loop_init): Use NIH_ZERO, instead of == 0
* nih/tests/test_io.c: Use NIH_ZERO not NIH_MUST...== 0
* nih/tests/test_io.c (test_watcher): Ensure that we don't ignore
the return value from nih_io_printf; but also don't fail it.
* HACKING: Clarify that returning to indicate insufficient memory
warrants warn_unused_result.
* nih/io.h: Add warn_unused_result attribute to nih_io_printf.
* nih/string.c: Correct doc strings.
* nih/string.c (nih_vsprintf): We need to copy the arguments before
iterating either time, otherwise we could return NULL after moving
the current argument off the end.
* TODO: Update.
2007-01-22 Scott James Remnant <scott@netsplit.com>
* nih/io.c (nih_io_reopen): Raises an error (usually ENOMEM), since
it can also raise EBADF.
* nih/tests/test_io.c (test_reopen): Make sure ENOMEM is raised.
* nih/watch.c: New watch API, this is a little higher level than
what previously existing in nih/file.c; but is substantially easier
to use and should cover all of the corner cases.
(INOTIFY_EVENTS): inotify events we always watch for.
(nih_watch_new): The master function; this creates a new inotify
instance and adds a watch for a path in it.
(nih_watch_handle_by_wd): Obtain a watch handle by descriptor
(nih_watch_handle_by_path): Obtain a watch handle by path
(nih_watch_add): Another useful function, adds a second path to
an existing watch; normally used just for sub-directories, but
possible for anything.
(nih_watch_add_visitor): nih_dir_walk() callback that calls the above
(nih_watch_free): Free a watch, and the associated NihIo; closing the
inotify descriptor.
(nih_watch_reader): Reader function; handles the incoming stream of
inotify events by locating the watch handle and dispatching through
(nih_watch_handle): this function which handles all the various
event ordering corner-cases and dispatches to the watch functions
proper.
* nih/watch.h: Typedefs, structures and prototypes for the new watch
API.
* nih/tests/test_watch.c: Test suite for the watch code; covers most
of the paths -- though malloc checking here is tricky and could do
with improving later.
* nih/libnih.h: Include nih/watch.h
* nih/Makefile.am (libnih_la_SOURCES): Build and link watch.c
(nihinclude_HEADERS): Install watch.h
(TESTS): Build and run watch test suite
(test_watch_SOURCES, test_watch_LDFLAGS, test_watch_LDADD): Details
for watch test suite binary.
* nih/file.c: Strip out anything related to inotify, leaving us
with just three functions; nih_file_map(), nih_file_unmap() and
nih_dir_walk(). Others that will turn up here will be matching
and filtering functions.
* nih/file.h: Strip out typedefs, structures and prototypes for
anything watch-related; add attributes to functions as necessary.
* nih/tests/test_file.c: Remove watch-related test cases, and
use TEST_ALLOC_FAIL for test_dir_walk().
* nih/tests/test_io.c (test_shutdown): Test NIH_IO_MESSAGE using
AF_UNIX socketpairs, not pipes.
* HACKING: Document the requirements for function attributes and
using TEST_ALLOC_FAIL in test cases.
* TODO: Update.
* nih/tests/test_signal.c (test_set_handler): Check that SIGCHLD
gets the SA_NOCLDSTOP flag, and that SIGKILL returns an error.
(test_set_default, test_set_ignore): Check SIGKILL returns error.
* nih/tests/test_option.c (test_parser): Check that duplicated
options result in the previous string being freed.
* nih/main.c (nih_main_daemonise): SIGHUP can always be ignored.
* nih/tests/test_io.c (test_reopen): Make sure that we can't reopen
a closed file descriptor.
(test_set_nonblock, test_set_cloexec): Check with closed descriptors.
* nih/config.c: When we call nih_config_skip_comment, we can usually
assert that this will never fail; so do so.
* nih/tests/test_command.c (test_help): Check a few missing pieces
of the command help output to make sure it's right.
* nih/file.c (nih_dir_walk): Correct doc string to indicate that
this function raises errors.
* nih/alloc.h: Fix prototype orders.
* nih/child.h: Add attributes to important return values.
* nih/config.c: Add attributes to important return values.
* nih/config.h: Add attributes to important return values.
* nih/error.h: Add attributes to important return values.
* nih/io.h: Add attributes to important return values.
* nih/main.h: Add attributes to important return values.
* nih/signal.h: Add attributes to important return values.
* nih/string.h: Add attributes to important return values.
* nih/timer.h: Add attributes to important return values.
* nih/io.c (nih_io_reopen): Don't ignore failure to ignore SIGPIPE.
(nih_io_set_cloexec, nih_io_set_nonblock): The only useful errors
returned is EBADF, so just return -1 for that.
* nih/main.c (nih_main_daemonise): Don't ignore failure to ignore
SIGHUP.
* nih/signal.c (nih_signal_set_handler, nih_signal_set_default)
(nih_signal_set_ignore): The only useful error sigaction returns
is EINVAL, so just return -1.
(nih_signal_reset): Ignore EINVAL errors.
* nih/tests/test_io.c: Use NIH_MUST around function calls that
can fail.
* nih/tests/test_main.c: Use NIH_MUST around function calls that
can fail.
2007-01-21 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_ALLOC_FAIL): Macro that loops over a block of code
as many times as malloc is called within it, causing each malloc in
turn to be failed so we can increase code coverage.
(nih_test_allocator): Support function for the above; allows dumping
of malloc calls.
* nih/tests/test_child.c (test_add_watch): Use TEST_ALLOC_FAIL
and call nih_child_poll() first to not debug the init function
(test_poll): Remove race conditions by making sure the signal
has reached the child using waitid(). Test the "child we don't
know about has died" branch, along with waitid returning 0 with no
pid (needs a child process).
* nih/tests/test_command.c (test_parser, test_help): Use
TEST_ALLOC_FAIL
* nih/tests/test_config.c (test_next_arg, test_parse_args)
(test_parse_command, test_parse_block): Use TEST_ALLOC_FAIL
* nih/tests/test_error.c (test_raise, test_raise_printf)
(test_push_context, test_return_error): Use TEST_ALLOC_FAIL, to
make sure allocations are retried.
(test_pop_context): Split out from test_push_context.
* nih/tests/test_hash.c (test_new): Use TEST_ALLOC_FAIL
* nih/tests/test_io.c (test_add_watch, test_buffer_new)
(test_buffer_resize, test_buffer_pop, test_buffer_shrink)
(test_buffer_push, test_message_new, test_message_add_control)
(test_message_recv, test_message_send, test_reopen, test_watcher)
(test_read, test_write, test_get, test_printf): Use TEST_ALLOC_FAIL
liberally, make sure every code path involving a malloc gets tested.
* nih/tests/test_list.c (test_new): Use TEST_ALLOC_FAIL
* nih/tests/test_logging.c (test_log_message): Use TEST_ALLOC_FAIL
* nih/tests/test_main.c (test_main_loop_add_func): Use TEST_ALLOC_FAIL
(test_package_string): Use TEST_ALLOC_FAIL and also check repeated
calls return the same string.
(test_version): Use TEST_ALLOC_FAIL to check that allocation can
never fail.
* nih/tests/test_option.c (test_parser, test_version, test_help):
Use TEST_ALLOC_FAIL to make sure we behave
* nih/tests/test_signal.c (test_add_handler): Use TEST_ALLOC_FAIL
and call nih_signal_poll() first to not debug the init function
* nih/tests/test_string.c (test_sprintf, test_vsprintf)
(test_strdup, test_strndup, test_str_split, test_str_wrap)
(test_str_screen_wrap): Use TEST_ALLOC_FAIL
(test_str_screen_width): Check that we discard an illegal columns
variable.
* nih/tests/test_timer.c (test_add_timeout, test_add_periodic)
(test_add_scheduled): Use TEST_ALLOC_FAIL and call nih_timer_poll()
first to make sure we don't debug the init function
* nih/config.c (nih_config_next_arg, nih_config_parse_args)
(nih_config_parse_command, nih_config_parse_block): Allow us to fail
reading a configuration file because we run out of memory; it's not
that important.
* nih/io.c (nih_io_get): Catch failure to remove the string, and
don't remove the delimiter if that happens.
(nih_io_printf): Fix doc, this returns zero, not a length.
* nih/io.h: Fix prototype of nih_io_printf
* nih/logging.c (nih_log_message): Potentially failing message output
is crazy; loop until the alloc succeeds.
* nih/option.c (nih_option_handle): Free the options and arguments
before exiting; not really necessary, but makes valgrind happier.
* nih/string.c (nih_strndup): Failed to correctly detect a failed
allocation.
(nih_str_split): Correct some mistakes with allocations not
being checked.
* nih/libnih.supp: Add tmpfile.
* TODO: Update.
2007-01-11 Scott James Remnant <scott@netsplit.com>
* nih/file.h (NihDirWatch): New structure that defines a high-level
watch on a directory with various handlers to be called.
(NihCreateHandler, NihChangeHandler, NihDeleteHandler): Typedefs.
* nih/file.c (nih_dir_add_watch): Function to create an NihDirWatch
structure and fill it in.
(nih_dir_add_file_watch): Add a watch on a single directory,
catching errors and logging a warning if we can't watch it.
(nih_dir_watcher): Deal with inotify events within a directory tree,
taking care of issues such as re-organising of the directory structure
without ending up with duplicate watches.
(nih_file_reader): Only call the first matching watcher; we hit a
limitation in the inotify API caused by our usage of a single
descriptor. Will fix that shortly.
* nih/tests/test_file.c (test_dir_add_watch): Test that we can add
watches and have everything filled in nicely.
2007-01-10 Scott James Remnant <scott@netsplit.com>
* nih/file.c (nih_dir_walk): Function to walk a directory tree
calling a function for each object found.
* nih/file.h (NihFileFilter, NihFileVisitor): typedefs for
function pointers used for nih_dir_walk.
* nih/tests/test_file.c (test_walk): Test the walker.
* nih/file.c (nih_file_reader): Pass the cookie to the watcher.
* nih/file.h (NihFileWatcher): Add cookie argument.
* nih/tests/test_file.c (test_add_watch): Check the cookie is
passed for a rename.
* nih/file.c (nih_file_add_watch): Fix this to not add the inotify
watch unless it can allocate memory to handle it.
2007-01-09 Scott James Remnant <scott@netsplit.com>
* nih/config.c (nih_config_get_stanza): Catch entries with a zero
length name, and return one instead of NULL if it exists.
* nih/tests/test_config.c (test_parse_stanza): Make sure that ""
in a stanza table acts as a catch-all.
* nih/test.h (TEST_FILENAME): Use dashes not colons, to make things
more clear.
2007-01-08 Scott James Remnant <scott@netsplit.com>
* nih/config.c (nih_config_has_token): add a very small test function
so parsers can peek to see whether there is a next argument or not.
(nih_config_skip_comment, nih_config_parse_args)
(nih_config_parse_file): Use the new test function to make it more
obvious what we're doing.
* nih/config.h: Add prototype.
* nih/tests/test_config.c (test_has_token): Add test cases.
* nih/config.c: Allow all functions to be called with a zero length
file, we're completely guarded against pos going past the length,
so this cannot be a bad thing. Plus this allows zero-length tokens
to be extracted trivially.
(nih_config_next_arg): Raise an error if called in a position where
there is no argument. If you want to speculatively check for args,
peek first.
(nih_config_parse_stanza): No need to check for an empty stanza now,
nih_config_next_arg() handles that for us.
(nih_config_skip_comment): Function to allow us to skip only a
comment, while raising an error if we hit anything else.
(nih_config_parse_args, nih_config_parse_command): Skip comment only,
to guard against parser errors.
* nih/config.h: Update.
* nih/tests/test_config.c (test_next_arg): Check the new error is
raised, instead of the empty string being returned.
(test_parse_stanza): Check the expected token error is raised.
(test_skip_comment): Test the new function.
* nih/errors.h: Add new errors.
* nih/errors.h: Fix capitalisation of error messages.
* nih/tests/test_config.c (test_parse_command): Add missing free
calls to strings obtained.
2007-01-07 Scott James Remnant <scott@netsplit.com>
* nih/config.c: Convert this file to use size_t where appropriate
instead of ssize_t, and raise exceptions for parsing errors rather
than logging them.
(nih_config_parse): Check a size is not greater then SSIZE_MAX (2GB)
to avoid overflows.
* nih/config.h: Update prototypes and handler function typedef.
* nih/errors.h: Add new error codes and strings.
* nih/tests/test_config.c: Adjust test cases.
* nih/config.c (nih_config_parse_file): Function to parse a mapped
file or string line-by-line starting from the given position.
(nih_config_parse): Function to map a file into memory and parse it
* nih/config.h: Add prototypes.
* nih/tests/test_config.c (test_parse_file): Test the function with
a small variety of different valid files.
(test_parse): Check we can parse a file, and get an error if it
doesn't exist.
* nih/config.c (nih_config_parse_stanza): Take a data pointer and
pass it to the handler, otherwise we can't fill in structures.
* nih/config.h: Update.
* nih/tests/test_config.c (test_parse_stanza): Check the data
pointer is passed properly.
* nih/tests/test_option.c (test_version, test_help): Capture the
return value from nih_option_parser, as we've set gcc attributes to
not let us do otherwise.
* nih/config.h: Add structures, typedefs and macros to allow lists
of configuration stanzas to be built up.
* nih/config.c (nih_config_parse_args): Split argument parsing into
(nih_config_next_arg): This new function that wraps next_token and
also skips following whitespace.
(nih_config_next_line): Another new function that skips to the end
of the line, replacing severael copies of this code.
(nih_config_get_stanza): Simple function to find a stanza in a table
by its name.
(nih_config_parse_stanza): Simple stanza dispatch function; parses an
argument at the current position, looks it up in the table, then
calls the function.
* nih/tests/test_config.c (test_next_arg): Check this function works,
we know it does because it was covered by other tests, but it's worth
having its own as well.
(test_next_line): Check this function works too.
(test_parse_stanza): Make sure the dispatcher works properly.
* nih/config.c: Write from the code that was used for upstart,
making them exported functions to act as a configuration file kit.
(nih_config_parse_args): Fix a bug where lineno wasn't incremented
for an embedded newline in between arguments. Fix another bug where
a line containing only whitespace or whitespace and a comment would
hit an assertion - not a problem in practice, but it's a bug.
* nih/config.h: Function prototypes.
* nih/libnih.h: Include config.h
* nih/tests/test_config.c: Write an all new test suite that tests
the individual parsing functions for their functionality, rather
than trying to squeeze it into something larger.
* nih/Makefile.am (libnih_la_SOURCES): Build and link config.c
(nihinclude_HEADERS): Install config.h
(TESTS): Build and run config test suite
(test_config_SOURCES, test_config_LDFLAGS, test_config_LDADD): Config
test suite binary details.
2007-01-06 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_io.c (test_watcher): Missing a priority that needed
changing to message.
* nih/command.h: Warn against unused results.
* nih/option.h: Warn against unused results.
* nih/logging.h (NihLogLevel): Add a message level between info
and warn, as we can't just re-use warn as that goes to stderr!
(nih_message): Change to use the new message level.
* nih/logging.c (nih_logger_syslog): Output messages at the notice
level, rather than the warning level.
(nih_log_init): Change the default priority to message.
* nih/tests/test_logging.c (test_log_message): Check that messages
are logged with the new message priority; reset to the new default.
(test_logger_printf): Make sure that ordinary messages go to stdout
and warning messages go to stderr.
(test_set_logger, test_set_priority): Reset to the new default.
* nih/tests/test_option.c (test_quiet, test_verbose, test_debug):
Check that messages are also logged, as well as warning; and set
the new default priority.
* nih/tests/test_error.c (test_raise_again, test_push_context):
Set log priority to the new default.
* nih/tests/test_io.c (test_watcher): Reset priority to the new
default.
2007-01-05 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_io.c (test_shutdown): Uncomment the test for
shutdown when all messages are processed by the watcher.
* nih/io.c (nih_io_message_recv): Remove note about the remote end
being closed; when in message mode, this doesn't usually happen.
(nih_io_watcher): Only check for a zero length return if we're in
stream mode, otherwise it just means we got a zero length message.
(nih_io_watcher_read): Accept zero length messages and return them.
* nih/tests/test_io.c (test_watcher): Remove tests that tried to
mix a message-mode io and a dgram socket, that way lies disaster.
* nih/io.c (nih_io_watcher_read, nih_io_watcher_write): Initialise
len to zero, as valgrind can be fussy about this when we call things
directly.
* nih/io.h (NihIoMessage): Add a user data field to the message
structure so we can carry the pid around when queuing notification
messages in upstart.
2007-01-02 Scott James Remnant <scott@netsplit.com>
* nih/alloc.h, nih/child.h, nih/command.h, nih/file.h, nih/hash.h:
nih/io.h, nih/logging.h, nih/main.h, nih/option.h, nih/signal.h:
nih/timer.h: Give names for all arguments in function pointer typedefs
so the documentation strings make more sense.
* nih/test.h (TEST_EQ_MEM, TEST_NE_MEM): Cast argument for number
of bytes to size_t.
* configure.ac (AC_COPYRIGHT): Update copyright to 2007.
2006-12-29 Scott James Remnant <scott@netsplit.com>
* nih/errors.h: Drop the NIH_IO_MESSAGE_TRUNCATED error.
* nih/io.h (NihIoMessage): Rename msg_buf member to data, and change
ctrl_buf member to be an array of cmsg structures called control.
* nih/io.c: Update references to NihIoMessage members.
(nih_io_message_push_control): Rename to nih_io_message_add_control
(nih_io_message_add_control): Rewrite to add the control message
header onto the end of an array, rather than a control buffer,
(nih_io_message_recv): After receiving the message, extract all
control messages and put them into the array.
(nih_io_message_send): Take control messages from the array into a
single buffer and send them.
* nih/tests/test_io.c: Update references to NihIoMessage members.
(test_message_new): Check that the control member is initialised to
a one-element array containing NULL.
(test_message_push_control): Rename to test_message_add_control.
(test_message_add_control): Check the array is extended.
* nih/io.c (nih_io_message_recv): Loop over a call to recvmsg() with
MSG_PEEK in its arguments to avoid ever returning truncated messages.
* nih/tests/test_io.c (test_message_recv): Adjust test for truncated
messages to make sure they do in fact work.
(test_watcher): Remove the oversized message error check.
2006-12-21 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_option.c (test_verbose): Add missing call to free
args.
* nih/io.c (nih_io_message_send): Change to return the ssize_t
received from sendmsg(), rather than an int.
(nih_io_watcher_read): Move read functionality out of
nih_io_watcher into a separate function that can deal with both
stream and message mode.
(nih_io_watcher_write): Move write functionality out of nih_io_watcher
into a separate function that can deal with both stream and message
mode.
(nih_io_watcher): Call the separate functions, and handle calling
the reader when in message mode. In addition, we now check the
error code when writing to a socket as well; there are useful errors
there (like ECONNREFUSED).
* nih/io.h: Update prototype of nih_io_message_send.
* nih/tests/test_io.c (test_message_send): Update return checks.
(test_watcher): Test that the error handled can now be called when
writing data to a socket, as well as just when reading. Test
message mode behaviour.
* nih/io.c (nih_io_send_message): Watch socket for writability.
(nih_io_write): Extend this function to work in message mode;
it allocates a new message, stores the data in that buffer, and
adds it to the send queue.
(nih_io_printf): Remove restriction that this only be called in
stream mode; the fact this calls nih_io_write is sufficient to
ensure correct behaviour.
* nih/tests/test_io.c (test_send_message): Check that we're testing
for writability.
(test_write): Test that this works in message mode.
(test_printf): Check that this works too, even though this only
really calls nih_io_write.
* nih/io.c (nih_io_get): Extend so that this can operate in message
mode on the oldest message in the queue.
* nih/tests/test_io.c (test_get): Check that this works properly
in message mode; complete with shutdown check.
* nih/io.c (nih_io_message_new): Do not assign a default list
destructor, it's not in a hidden list and there are bad consequences
of freeing a child with a default destructor if the list its in gets
freed first; new rule - default destructors only if the list is hidden
and never freed!
(nih_io_closed, nih_io_shutdown): Don't call the close handler if
the structure is already marked to be closed; there seems little
point, and we could accidentally call it multiple times.
(nih_io_read_message, nih_io_read, nih_io_get): Check whether we
need to shutdown the socket here, in case the watcher isn't polled
again.
* nih/tests/test_io.c (test_shutdown): Check that shutdown works
with message-mode structures (part of this disabled for now).
(test_read_message, test_read, test_get): Check that a shutdown
socket is closed when these are called.
2006-12-20 Scott James Remnant <scott@netsplit.com>
* nih/io.c (nih_io_read): Extend so that it can be called in
message mode, it reads from the first message until it has been
exhausted; at which point it frees the message and the next call
would read from the next.
* nih/tests/test_io.c (test_read): Check that the new functionality
works properly.
* nih/io.c (nih_io_first_message): Simple static function to obtain
the oldest message in the receive queue.
(nih_io_read_message, nih_io_send_message): Functions to take the
oldest message out of the receive queue and append a message to the
send queue.
* nih/io.h: Add prototypes.
* nih/tests/test_io.c (test_read_message, test_send_message): Check
the new functions do what they say on the tin.
General clean-up of nih_io, fixing a few API issues and making it
more suitable for using in message mode.
* nih/io.c (nih_io_buffer_pop, nih_io_buffer_shrink): Remove the
silly restrictions that these cannot be called with a length greater
than the buffer size, instead just truncate it to the buffer size.
(nih_io_buffer_pop): Length is now updated to the actual number of
bytes being returned.
(nih_io_message_add_control): Rename to nih_io_message_push_control.
(nih_io_message_recv): Change the len parameter to a pointer that's
updated with the actual number of bytes read.
(nih_io_stream_watcher): Rename back to nih_io_watcher.
(nih_io_reopen): Use a single watcher function again, initialise close
to NULL. Treat failure to set a descriptor non-blocking as a failure
to open; otherwise we'll end up screwing up the main loop.
(nih_io_watcher): Remove the restriction that this is only called
when in the stream mode. Leave data in the receive buffer if there's
no reader function, it's now valid to query the buffer size and read
by other means. Catch the ENOMEM error and ignore it. Set and keep
an eye on the structure close member, if it is TRUE before we return,
close the socket. This also means we check for shutdown sockets in
the case of error, which we probably should have done.
(nih_io_maybe_shutdown): Rename to nih_io_shutdown_check.
(nih_io_close): If the close member of the structure is not NULL
we're inside a watcher function, so need to set the variable this
points to to TRUE instead of closing or freeing the structure.
(nih_io_read): Change the len parameter to be updated with the
actual number of bytes being returned.
* nih/io.h: Renamed function prototype. Updated documentation for
function typedefs to clarify that they may all call nih_io_close,
but may not call nih_free.
* nih/errors.h: Rename NIH_TRUNCATED_MESSAGE to
NIH_IO_MESSAGE_TRUNCATED, we should probably namespace these.
* nih/tests/test_io.c (test_buffer_pop, test_buffer_shrink): Check
that we can pop or shrink the entire buffer if we ask for more.
(test_message_add_control): Rename to test_push_control.
(test_message_recv): Check that the cases of remote end closed,
error received or truncated message are handled properly.
(test_message_send): Check that an error is handled.
(test_stream_watcher): Rename back to test_watcher.
(test_reopen): Check that the socket is not being shutdown or closed.
(test_shutdown): Drain the buffer before calling handle on it, as
it's not done automatically now.
(test_close): Check that a lazy close is performed if io->close is
not NULL.
* nih/file.c (nih_file_reader): Update call to nih_io_read.
* nih/logging.h (nih_assert_notreached): Rename to
nih_assert_not_reached, this was annoying me.
2006-12-19 Scott James Remnant <scott@netsplit.com>
* nih/io.c (nih_io_read, nih_io_write, nih_io_get, nih_io_printf):
Ensure the NihIo structure is in stream mode; as these only really
make sense if there's a limitless buffer.
* nih/tests/test_io.c (test_shutdown): Make sure the socket is
shut down immediately.
* nih/io.c (nih_io_shutdown): Bugfix, should close the socket
immediately if there's nothing in the queue, otherwise it may
hang around forever if it never polls.
* nih/io.c (nih_io_reopen): Receive the type from the arguments,
instead of hard-coding to be stream. Set up the structure accordingly.
* nih/io.h: Update prototype.
* nih/tests/test_io.c (test_reopen): Check message mode is allocated
properly.
* nih/file.c (nih_file_init): Open in stream mode.
* nih/io.c (nih_io_message_new): Catch failure to allocate message
or control buffer.
(nih_io_message_add_control): No need to try and allocate the control
buffer here.
(nih_io_message_recv): Only need to resize the buffers here as well.
(nih_io_message_send): No need to deal with there being no message
or control buffer here either.
* nih/tests/test_io.c: Fix test assumptions based on above.
* nih/libnih.supp: Add missing nih_io_init suppression.
* nih/tests/test_io.c (test_message_add_control): Non need to check
allocation of the buffer itself.
* nih/io.c (nih_io_message_add_control): Function to add a control
message to the control buffer, to save mucking around with difficult
bits ourselves.
* nih/io.h: Add prototype.
* nih/tests/test_io.c (test_message_add_control): Check that it
works properly.
* nih/io.c (nih_io_buffer_shrink): Make an exported function, resize
the buffer once done to save on memory.
(nih_io_buffer_pop, nih_io_stream_watcher): No need to explicitly
resize here now, as it gets called from shrink.
* nih/io.h: Add prototype.
* nih/tests/test_io.c (test_buffer_shrink): Test shrink.
* nih/io.c (nih_io_message_recv, nih_io_message_send): Functions
to send and receive a message over a socket, hiding the difficult
bits of dealing with msghdr/iovec.
(nih_io_get_family): Function to detect the family of a socket.
* nih/io.h: Update.
* nih/errors.h: Add truncated message error.
* nih/tests/test_io.c (test_message_recv, test_message_send): Check
that we can send and receive messages by using socket pairs.
(test_get_family): Check that we can get the families of the standard
three socket types.
2006-12-18 Scott James Remnant <scott@netsplit.com>
* nih/io.h (NihIoMessage): Structure that represents an individual
message in a queue; has a buffer for the message, and for ancillary
control data, as well as an address that the message is being sent
to or received from.
(NihIoType): Enum to select whether an NihIo structure is in stream
mode or message mode.
(NihIo): Add a type member to select whether this is in stream or
message mode, and a union to select whether we're using buffers
or message queues.
* nih/io.c (nih_io_message_new): Allocate an NihIoMessage and its
child buffers.
(nih_io_reopen): Initialise the type to NIH_IO_STREAM.
(nih_io_watcher): Rename to nih_io_stream_watcher.
* nih/tests/test_io.c (test_message_new): Check that the new message
structure is initialised properly.
(test_reopen): Check that we get a stream structure by default.
(test_watcher): Rename to test_stream_watcher.
2006-12-17 Scott James Remnant <scott@netsplit.com>
* nih/logging.h (nih_assert_notreached): Add an assertion for the
use in default bits of switches, etc.
* nih/test.h (TEST_EQ_U, TEST_NE_U): Versions of the original macros
that cast to size_t for display, instead of ssize_t.
* nih/tests/test_logging.c, nih/tests/test_string.c: Set local
variables to avoid gcc thinking that they may be unused when
using TEST_DIVERT_*.
2006-12-14 Scott James Remnant <scott@netsplit.com>
* HACKING: Correct some typos.
2006-12-13 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_FILENAME): Wrap with do { ... } while (0)
in case this gets used as a single line statement.
2006-12-13 Johan Kiviniemi <johan@kiviniemi.name>
* nih/test.h (TEST_FILE_RESET): Wrap with do { ... } while (0)
in case this gets used as a single line statement.
2006-12-13 Scott James Remnant <scott@netsplit.com>
* nihify: Link to the nih ChangeLog.
2006-12-12 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_CHILD_WAIT, TEST_CHILD_RELEASE): Sometimes the
primitive "when the child is running" locking provided by TEST_CHILD
isn't sufficient, and we actually need to perform some actions in
the child before we let the parent carry on. These two macros
allow that.
* nih/libnih.supp: Include a valgrind suppressions file.
* nih/Makefile.am (EXTRA_DIST): Distribute the suppressions file.
* nih/tests/test_alloc.c (test_realloc): Fix missing free.
* configure.ac (AM_GNU_GETTEXT_VERSION): Quote version number.
2006-12-09 Scott James Remnant <scott@netsplit.com>
* nih/test.h (TEST_DIVERT_STDOUT_FD, TEST_DIVERT_STDERR_FD): Flush
before dup2ing the original file descriptor back, otherwise we end
up with the content still in the buffer later.
2006-12-08 Scott James Remnant <scott@netsplit.com>
* HACKING: Document that test cases are expected.
* nih/tests/test_command.c: Port to the new test framework.
* nih/tests/test_option.c: Drop unused include.
* nih/tests/test_option.c: Port to the new test framework.
2006-12-07 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_io.c: Port to the new test framework.
* nih/tests/test_hash.c: Drop use of assert.
* nih/tests/test_timer.c (test_poll): Formatting fix.
* nih/tests/test_string.c: Port to the new test framework.
* nih/test.h (TEST_DIVERT_STDOUT_FD, TEST_DIVERT_STDERR_FD): Macros
to divert to a file descriptor instead of a file.
(TEST_DIVERT_STDOUT, TEST_DIVERT_STDERR): Redefine as wrappers around
the new macros.
* nih/tests/test_timer.c: Port to the new test framework.
* nih/tests/test_signal.c: Port to the new test framework.
* nih/tests/test_main.c: Port to the new test framework.
* nih/test.h: Cast strlen return value to int when used to give
the length of a string in printf.
* nih/tests/test_logging.c: Port to the new test framework.
* nih/test.h (TEST_DIVERT_STDOUT, TEST_DIVERT_STDERR): Crazy macros
to divert stdout or stderr to a different file, making sure it's
flushed before both dups.
(TEST_EQ_STRN, TEST_NE_STRN): Functions to check a string up to a
particular point.
(TEST_FILE_EQ, TEST_FILE_EQ_N, TEST_FILE_NE, TEST_FILE_NE_N):
Functions to grab a line from a file and check it against a string.
(TEST_FILE_END): Function to determine end of file.
(TEST_FILE_RESET): Another function so I don't need to remember the
runes to flush, rewind and truncate a file.
2006-12-06 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_file.c: Port to the new test framework.
* nih/test.h (TEST_EQ_MEM, TEST_NE_MEM): Tests that wrap memcmp.
(TEST_FILENAME): Macro to generate a filename.
* nih/tests/test_error.c: Port to the new test framework.
* nih/tests/test_alloc.c, nih/tests/test_list.c, nih/tests/test_hash.c:
Undo over-zealous removing of includes.
* nih/tests/test_child.c: Port to the new test framework.
* nih/test.h (TEST_CHILD): Macro to spawn an interlocked child
process, so we don't keep having to remember how to.
* nih/test.h (TEST_ALLOC_SIZE, TEST_ALLOC_PARENT): Include the
expression that generated the pointer, as well as the pointer.
(TEST_LIST_EMPTY, TEST_LIST_NOT_EMPTY): Check whether a list is
empty or not.
* nih/tests/test_list.c (test_empty, test_foreach_safe): Use the
new list test macros instead of TEST_TRUE/TEST_FALSE.
* nih/tests/test_hash.c (test_new): Likewise.
2006-12-05 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_hash.c: Port to the new test framework.
* nih/tests/test_list.c: Port to the new test framework.
* nih/tests/test_alloc.c: Port to the new test framework.
(test_set_allocator): Test that the allocator is called with zero
as the argument.
* nih/test.h: Include config.h on behalf of the test suites.
* nih/test.h (TEST_EQ_STR, TEST_NE_STR): String comparison tests.
* nih/test.h (TEST_FAILED): abort is much better than exit
* nih/test.h (INIT_TEST): Drop this, we'll just return directly.
(TEST_FAILED): Return directly on failure.
(CALL_TEST): Drop this again.
* nih/test.h (CALL_TEST): Add "call a function" macro.
* nih/test.h: Macros that implement a simple test framework based
on the patterns I was using anyway.
* nih/Makefile.am (nihinclude_HEADERS): Install nih/test.h
* nih/tests/test_command.c (test_parser, test_help): flush stdout
or stderr before calling dup2().
* nih/tests/test_option.c (test_parser, test_version, test_help):
flush stdout or stderr before calling dup2().
* nih/tests/test_io.c: Formatting fix.
* nih/file.c (nih_file_map): Tidy up; in particular don't allow
opening in just write mode, seeing as that doesn't work.
* nih/tests/test_file.c (test_unmap): Test unmap separately.
(test_map): Update for new checks.
* nih/file.c (nih_file_add_watch): No need to set ENOMEM if
nih_new fails, that will be already set.
(nih_file_reader): Clarify why nih_io_read must return a pointer.
* nih/tests/test_string.c (test_str_screen_width)
(test_str_screen_wrap): flush stdout before calling dup2().
* nih/tests/test_main.c (test_suggest_help, test_version): flush
stdout or stderr before calling dup2().
* nih/tests/test_logging.c (test_logger_printf): flush stdout or
stderr before calling dup2(), otherwise we don't know which stream
the buffered output will be going to.
* nih/tests/test_error.c (test_push_context): Check that unhandled
errors within a context are notified and freed if the context is
popped.
* nih/alloc.c (nih_alloc_reparent): Function to reparent a pointer
to a new parent or just orphan it.
* nih/alloc.h: Update.
* nih/tests/test_alloc.c (test_reparent): Make sure it works.
* nih/tests/test_alloc.c (test_alloc_using): Check that this works
properly if the allocator returns NULL.
(test_realloc): A few cases to check here; make sure that it works
if the pointer to realloc is NULL, actually test the children
reparenting code here and test the reallocator returning NULL.
* README: Correct typo.
2006-11-12 Scott James Remnant <scott@netsplit.com>
* nih/Makefile.am (INCLUDES, DEFS): Drop these two variables
(AM_CPPFLAGS): in favour of this combined variable.
* configure.ac (AM_INIT_AUTOMAKE): Include nostdinc so we don't get
Automake's broken default includes.
* nih/Makefile.am (INCLUDES): Include $top_builddir and $top_srcdir,
everything else wants relative paths from there.
(DEFAULT_INCLUDES): Drop override now we don't need it.
* m4/compiler.m4 (NIH_C_THREAD): Define a macro in the manner of
AC_C_CONST that will #define __thread to empty if it isn't supported
by the compiler.
* m4/misc.m4 (NIH_INIT): libnih uses __thread.
2006-10-13 Scott James Remnant <scott@netsplit.com>
* nih/command.h: Adjust type of NihCommandAction to include const.
* nih/tests/test_command.c (my_action): Update.
2006-10-12 Scott James Remnant <scott@netsplit.com>
* configure.ac: Expand AC_GNU_SOURCE so we get _GNU_SOURCE and so
that gettext doesn't complain.
(AM_GNU_GETTEXT_VERSION): Increase to 0.15
(AC_PREREQ): Increase to 2.60
* HACKING: Update autoconf and gettext requirements.
2006-10-11 Scott James Remnant <scott@netsplit.com>
* nih/string.c (nih_str_screen_wrap): Don't quite fill the screen,
instead leave a character spare as it looks somehow neater that way.
* nih/option.c (nih_option_group_help): Likewise.
* nih/tests/test_string.c (test_str_screen_wrap): Update tests.
* nih/tests/test_option.c (test_help): Fix wrapping test.
* TODO: Update.
* nih/command.c: Implement a command parser that uses the first
non-option argument (or program name) and selects different help
and options based on that.
* nih/command.h: Structures and prototypes.
* nih/libnih.h: Include command.h
* nih/tests/test_command.c: Test suite for command parser.
* nih/Makefile.am (libnih_la_SOURCES): Build and link command.c
(nihinclude_HEADERS): Install command.h
(TESTS): Build and run command test cases
(test_command_SOURCES, test_command_LDFLAGS, test_command_LDADD):
Details for command test suite binary.
* nih/tests/test_option.c: Keep a copy of last_option otherwise
it's freed while we're not around.
* nih/option.c (nih_option_set_footer): Add a footer string.
(nih_option_help): Also add the footer string.
* nih/option.h: Update.
* nih/tests/test_option.c (test_help): Check the footer.
* nih/option.c (nih_option_set_usage_stem): Add function to set
the "[OPTION]..." bit of the usage line.
(nih_option_help): Use the usage stem if set.
* nih/option.h: Update.
* nih/tests/test_option.c (test_help): Check the usage stem.
* nih/option.c (nih_option_join): Add function to combine two lists
of options.
(nih_option_parser): Join the options and default_options lists,
don't play with arrays of lists.
(nih_option_get_short, nih_option_get_long): Simply by just iterating
the one array.
(nih_option_help, nih_option_group_help): Again simply by just
iterating the one array.
* nih/option.h: Update.
* nih/tests/test_option.c (test_parser): Don't check addresses of
options as they've moved.
* nih/option.c (nih_option_set_usage, nih_option_set_synopsis)
(nih_option_set_help): Allow NULL to be set to override existing
strings.
* nih/option.c (nih_option_help): Make static.
* nih/option.h: Update.
2006-10-10 Scott James Remnant <scott@netsplit.com>
* TODO: Update.
* nih/option.c (nih_option_group_help): Use a factor of the screen
width when formatting help options, but keep at least 20 chars
visible at all times.
* nih/string.c (nih_str_screen_width): Add function to return just
the screen width.
(nih_str_screen_wrap): Use that function.
* nih/string.h: Update.
* nih/tests/test_string.c (test_str_screen_width): Check function.
* nih/option.c (nih_option_set_synopsis): Function to set a synopsis
string that follows the usage.
(nih_option_set_help): Function to set the help string that follows
the options.
(nih_option_help): Output synopsis and help strings.
* nih/option.h: Update.
* nih/tests/test_option.c (test_help): Check behaviour
* TODO: Update.
* nih/main.c (nih_main_version): Use nih_str_screen_wrap to output
the GPL preamble bit.
* nih/tests/test_main.c (test_version): Unset COLUMNS just in case.
* nih/string.c (nih_str_screen_wrap): Add wrapper around
nih_str_wrap that obtains the screen width and uses that for len.
* nih/string.h: Add prototype.
* nih/tests/test_string.c (test_str_screen_wrap): Test new function.
* nih/Makefile.am (test_string_LDADD): Link with -lutil so we can
use openpty in our "fake terminal" tests.
* nih/tests/test_option.c: Fix minor test case memory leak.
* nih/tests/test_child.c (test_poll, test_poll): Use better
interlocks then usleep.
* nih/tests/test_option.c (main): Enable test of --debug, oops.
* nih/main.c (nih_main_daemonise): Document why this is better than
daemon(), and thus not nih.
* nih/tests/test_main.c (test_daemonise): Test the daemonise
function works properly.
* nih/timer.h: Fix comments.
* nih/hash.c (nih_hash_new): This needs a parent pointer too.
* nih/hash.h: Update prototype.
* nih/tests/test_hash.c: Update test cases.
* nih/child.c: Clarify child_watches item types.
* nih/file.c: Clarify file_watches item types.
* nih/io.c: Clarify io_watches item types.
* nih/main.c: Clarify loop_functions item types.
* nih/timer.c: Clarify timers item types.
* nih/signal.h (NihSignalCb): Rename to NihSignalHandler.
(NihSignal): Change callback name to handler and type
to NihSignalHandler.
* nih/signal.c (nih_signal_add_callback): Rename to
nih_signal_add_handler.
* nih/tests/test_signal.c: Update.
* nih/list.c (nih_list_new): Take a parent pointer like everything
else, showing its age slightly.
* nih/list.h: Update prototype.
* nih/tests/test_list.c: Update test cases.
* nih/child.c (nih_child_init): Pass NULL to nih_list_new().
* nih/error.c (nih_error_init): Pass NULL to nih_list_new().
* nih/file.c (nih_file_init): Pass NULL to nih_list_new().
* nih/io.c (nih_io_init): Pass NULL to nih_list_new().
* nih/main.c (nih_main_loop_init): Pass NULL to nih_list_new().
* nih/signal.c (nih_signal_init): Pass NULL to nih_list_new().
* nih/timer.c (nih_timer_init): Pass NULL to nih_list_new().
* nih/tests/test_hash.c: Pass NULL to nih_list_new().
* nih/alloc.c, nih/alloc.h, nih/child.c, nih/child.h, nih/error.c,
nih/error.h, nih/file.c, nih/file.h, nih/hash.c, nih/hash.h,
nih/io.c, nih/io.h, nih/list.c, nih/list.h, nih/main.c, nih/main.h,
nih/option.c, nih/option.h, nih/signal.c, nih/signal.h, nih/string.c,
nih/string.h, nih/timer.c, nih/timer.h: Clean up documentation and
parent return values.
* HACKING: Detail function documentation requirement and format.
* nih/tests/test_signal.c (test_set_default, test_set_ignore)
(test_reset): amd64 seems to set the SA_NODEFER flag even when
you pass zero, so just check we clear important bits.
2006-09-27 Scott James Remnant <scott@netsplit.com>
* m4/misc.m4 (NIH_INIT): Add easier macro for using libnih.
* m4/compiler.m4: Remove hack to include misc.m4
* configure.ac: Drop the macro set and replace with NIH_INIT
* README: Update.
* nihify: Warn if NIH_INIT not present.
2006-09-25 Scott James Remnant <scott@netsplit.com>
* TODO (main): Update.
* nih/logging.h (nih_message): Add nih_message as an alias for
nih_warn.
* nih/tests/test_logging.c (test_log_message): Check new macro.
2006-09-20 Michael Biebl <mbiebl@gmail.com>
* nih/tests/test_file.c: Include nih/inotify.h when sys/inotify.h
is not available.
2006-09-19 Michael Biebl <mbiebl@gmail.com>
* nih/Makefile.am (nihinclude_HEADERS): Install inotify.h just in
case it's required
2006-09-18 Michael Biebl <mbiebl@gmail.com>
* configure.ac: Check for sys/inotify.h
* nih/inotify.h: Taken from udev, this defines the syscalls
and flags, etc. for inotify on glibc 2.3
* nih/file.c, nih/file.h: Include nih/inotify.h if we do not have
sys/inotify.h
2006-09-13 Scott James Remnant <scott@netsplit.com>
* nih/child.c (nih_child_poll): Zero the siginfo_t struct before
every call to waitid(), the kernel doesn't do it for us when
running the compat syscall (but does for the native one *sigh).
2006-09-08 Scott James Remnant <scott@netsplit.com>
* TODO: Update.
* nih/option.c (nih_option_help): Allow the usage string to be
customised.
(nih_option_set_usage): Using this function.
* nih/option.h: Update.
* nih/tests/test_option.c (test_help): Test the usage string.
* nih/main.c (nih_main_daemonise): Use program_name for the pid file.
* nih/main.h: Update.
* nih/main.c (nih_main_daemonise): Add a daemonise function,
pretty standard really.
* nih/main.h: Update.
2006-09-07 Scott James Remnant <scott@netsplit.com>
* AUTHORS: Mention the ChangeLog file.
2006-09-04 Scott James Remnant <scott@netsplit.com>
* README: Add some documentation for the curious.
* nih/file.c (nih_file_add_watch): Set nih_file_remove_watch as
the default destructor so that nih_free can be called or work in
a tree.
(nih_file_remove_watch): Modify to not call nih_free and work if
called multiple times.
* nih/signal.c (nih_signal_set_default, nih_signal_set_ignore):
Set flags to zero when defaulting or ignoring signals.
* nih/tests/test_signal.c (test_set_default, test_set_ignore)
(test_reset): Modify test cases appropriately.
* nih/hash.h: Add missing attribute for nih_hash_new
* nih/list.h: Add missing attribute for nih_list_new
2006-09-01 Scott James Remnant <scott@netsplit.com>
* nih/option.c (nih_option_group_help): Cast linelen to not induce
a warning.
2006-08-31 Scott James Remnant <scott@netsplit.com>
* nih/main.c (nih_main_loop_interrupt): Always initialise the
interrupt pipe.
(nih_main_loop_init): Move interrupt pipe initialisation to here
so that it's always available.
(nih_main_loop): Drop the extra call to nih_signal_poll().
* nih/option.c (nih_option_get_short, nih_option_get_long): Allow
catch-all options.
* nih/tests/test_option.c (test_parser): Test catch-all options.
* TODO: Update.
* nih/option.c (nih_option_handle_arg): Free any existing option
value.
2006-08-30 Scott James Remnant <scott@netsplit.com>
* nih/option.c (nih_option_debug): Add a hidden --debug option that
sets the logging level up really high.
(nih_option_handle): Just compare the names rather than offset
within a list that can change.
* nih/option.h: Update.
* nih/tests/test_option.c (test_debug): Check that it works.
* nih/option.c (nih_option_group_help): Output "Options" where we
only have the one group.
* nih/option.c (nih_option_group_help): Don't output options without
help strings.
* nih/tests/test_option.c (test_help): Update.
2006-08-25 Scott James Remnant <scott@netsplit.com>
* nih/io.c (nih_io_watcher): Clean up the handling of the out of
memory condition while extending the buffer so that we just return
to be called again rather than end up performing some random action.
2006-08-24 Scott James Remnant <scott@netsplit.com>
* nihify (src_dir): Also copy m4/Makefile.am
* nih/file.c (nih_file_remove_watch): Raise the error before
performing other actions so errno is not lost.
* nih/io.c (nih_io_watcher): Fix a pretty critical bug, we weren't
saving the value of errno so it was usually zero by the time we
looked at it.
* nih/logging.c (nih_logger_syslog): Useful alternative to
nih_logger_printf.
* nih/logging.h: Update.
2006-08-23 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_string.c: Add missing free calls.
* nih/tests/test_io.c (test_watcher): Silence the error message.
* nih/tests/test_option.c (test_parser): Add some forgotten calls
to nih_free
* nih/main.c (nih_main_init_full): Free the package string when
overwriting it.
* nih/tests/test_logging.c: Keep a copy of the last message
otherwise we're reading free'd memory (again).
* nih/tests/test_list.c: Memory cleanups.
* nih/signal.c (nih_signal_set_default, nih_signal_set_ignore):
Don't initialise the signals list, there's no need.
* nih/tests/test_hash.c: Various missing calls to nih_free.
* nih/file.c (nih_file_remove_watch): Fix another wrong call to
nih_free.
* nih/tests/test_child.c (test_poll): Free the watcher.
* nih/file.c (nih_file_remove_watch): Remove from the containing
list before freeing.
* nih/tests/test_file.c (my_watcher): Make sure we copy the name
as it will be freed by the time we get back to the test.
* nih/list.c (nih_list_free): Don't throw away the destructor
return value.
* nih/tests/test_error.c: Further missing calls to nih_free
* nih/tests/test_alloc.c: Correct a few missing nih_free's
* nih/file.c (nih_file_map): Correct a thinko, have to mask
flags by O_ACCMODE and compare for equality to extract the open
access mode.
2006-08-22 Scott James Remnant <scott@netsplit.com>
* nih/file.c (nih_file_map, nih_file_unmap): Add an easier to use
wrapper around mmap() when we just want the file in memory.
* nih/file.h: Add prototypes.
* nih/tests/test_file.c (test_map): Test the functions.
2006-08-21 Scott James Remnant <scott@netsplit.com>
* nih/file.c: Wrap the inotify syscalls with something a little
friendlier to deal with.
* nih/file.h: Typedefs, structures and prototypes.
* nih/libnih.h: Include file.h
* nih/io.h: Correct typo in argument name.
* nih/Makefile.am (libnih_la_SOURCES): Build and link file.c
(nihinclude_HEADERS): Install file.h
(TESTS): Build and run file test cases
(test_file_SOURCES, test_file_LDFLAGS, test_file_LDADD): Details
for file test case binary
2006-08-19 Scott James Remnant <scott@netsplit.com>
* nih/option.c (nih_option_parser): Finish option processing when
the first non-option argument is found (command-mode)
* nih/option.h: Update.
* nih/tests/test_option.c (test_parser): Test command-mode.
* nih/option.c: Implement a simple, yet flexible option parser.
* nih/option.h: Typedefs, structures and prototypes.
* nih/libnih.h: Include option.h
* nih/tests/test_option.c: Test it all pretty thoroughly.
* nih/Makefile.am (libnih_la_SOURCES): Build and link option.c
(nihinclude_HEADERS): Install option.h
(TESTS): Run the option test cases
(test_option_SOURCES, test_option_LDFLAGS, test_option_LDADD):
Details for the option test case binary.
* TODO: Update.
* nih/string.c (nih_str_wrap): Implement a function to wrap a
string into the desired number of characters wide.
* nih/string.h: Update.
* nih/tests/test_string.c (test_str_wrap): Test the new function
to make sure it does the right things.
2006-08-18 Scott James Remnant <scott@netsplit.com>
* TODO: Update.
* nih/main.h (nih_main_init_gettext): Macro that expands to the
usual gettext initialisation spiel if ENABLE_NLS is set, or nothing
if not.
(nih_main_init): Expand nih_main_init_gettext as well, we almost
always want to do that, after all.
* nih/macros.h: Include locale.h if ENABLE_NLS is set, as that
contains setlocale, amongst other things.
* nih/tests/test_main.c (test_init_gettext): Check the macro does
the right things.
* nih/io.h (NihIoCb): Rename to NihIoWatcher.
(NihIoReadCb): Rename to NihIoReader.
(NihIoCloseCb): Rename to NihIoCloseHandler.
(NihIoErrorCb): Rename to NihIoErrorHandler.
(NihIoWatch): Rename callback member to watcher.
(NihIo): Rename read_cb member to reader, close_cb member to
close_handler and error_cb member to error_handler.
* nih/io.c: Update to use new names.
(nih_io_cb): Rename to nih_io_watcher.
* nih/tests/test_io.c: Update to use new names.
* TODO: Update.
2006-08-16 Scott James Remnant <scott@netsplit.com>
* nih/main.c (nih_main_loop_add_func): Add a loop function
(nih_main_loop): Run the loop functions.
* nih/main.h (NihMainLoopCb, NihMainLoopFunc): Typedefs and
structures for main loop callbacks.
* nih/tests/test_main.c (test_main_loop_add_func): Check that
the loop function is allocated correctly.
(test_main_loop): Make sure it actually gets called.
* nih/io.c (nih_io_cb): Add a couple of check assertions.
* nih/macros.h (N_): Should be defined to be a no-op.
2006-08-14 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c (nih_realloc): Yet another fix to realloc, we
forgot to reinitialise our entry in the parent's children list in
the case of no parent. After fixing this and tracing the code, I
realised that the previous fix was inelegant and there is a way to
deal with children without modifying the pointers until after the
reallocation. Documented the reasoning in the function.
* nih/io.c (nih_io_reopen): Report on the error rather than just
suppressing it.
(nih_io_error): Likewise, report on the error.
2006-08-12 Scott James Remnant <scott@netsplit.com>
* nih/main.c (nih_main_loop_close): Drop this function
(nih_main_loop): Instead mark them close on exec.
* nih/main.h: Update.
* nih/main.c (nih_main_loop): Change the main loop to use select
instead of poll, as its semantics are a lot easier to deal with.
We also use allow select to be interrupted by writing to a pipe
from the signal handlers, for when Linux gets around to supporting
SA_RESTART properly.
(nih_main_loop_interrupt): Write to the pipe so the select call gets
interrupted.
(nih_main_loop_exit): Interrupt the main loop, in case we're
waiting forever.
(nih_main_loop_close): Close the interrupt pipe, used in children.
* nih/main.h: Update.
* nih/io.c (nih_io_add_watch): Change type of events parameter.
(nih_io_poll_fds): Remove this function.
(nih_io_select_fds): And replace with this that sets the select
file descriptor sets instead.
(nih_io_handle_fds): Now receives select file descriptor sets, and
becomes rather more obvious in the process. Restore the previous
behaviour where a callback isn't called unless requests events
occur.
(nih_io_reopen): Always poll for reading so we pick up errors.
(nih_io_cb): Change type of events parameter and events settings.
(nih_io_write): Change event settings.
* nih/io.h: Update.
(NihIoEvents): replace the previous poll events with a new enum.
* nih/signal.c (nih_signal_handler): Interrupt the select call in
the main loop.
* nih/tests/test_io.c: Update with new test cases.
* nih/tests/test_child.c: Use select() rather than poll()
* nih/tests/test_io.c (test_buffer_push, test_write): Correct
uninitialised return value.
* nih/main.c (nih_main_loop): Correct a memory leak, we forgot
to clean up the poll fds list.
* nih/io.c (nih_io_handle_fds): Always call the callback, even if
unexpected events happen, otherwise we'll miss ERR, HUP, etc.
(nih_io_shutdown): Allow a socket to be closed lazily, so we can
send (or receive) a whole bunch of stuff and expect the structure to
go away afterwards.
(nih_io_cb): If the shutdown flag has been marked and we run out
of things in either buffer, act as if one end was closed.
(nih_io_reopen): Mark sockets as not shutdown by default.
* nih/io.h: Update.
* nih/tests/test_io.c (test_shutdown): Test behaviour.
(test_handle_fds): Take out some of the tests due to changed
behaviour. While "clever" I think overall this is undesirable.
* nih/io.c (nih_io_set_cloexec): Function to set the FD_CLOEXEC flag.
* nih/io.h: Update.
* nih/tests/test_io.c (test_set_cloexec): Test the function.
2006-08-11 Scott James Remnant <scott@netsplit.com>
* nih/alloc.h, nih/child.h, nih/hash.h, nih/logging.h, nih/signal.h,
nih/timer.h: Document arguments to function pointers.
* nih/io.c: Add a whole bunch of code to provide us with a high-
throughput, async file/socket layer; largely copied from the
dircproxy code (well, it works!). This allows read and write calls
to happen inside the main loop based on whenever poll thinks either
is possible, while user space can just write what it likes or get
called when there's data in the recv buffer.
* nih/io.h: Add the new typedefs, structures and prototypes.
* nih/tests/test_io.c: Lots of test cases for this stuff.
2006-08-10 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c (nih_realloc): Fix a fairly critical bug, we weren't
dealing with the fact that the children list head can move;
do some fancy shifting to make that work.
* nih/string.c (nih_str_split): Add a function to split a string
based on delimiters into an array.
* nih/string.h: Update.
* nih/tests/test_string.c (test_str_split): Test the new function.
2006-08-09 Scott James Remnant <scott@netsplit.com>
* nih/tests/test_child.c (test_poll): Add extra sleep calls for
safety.
* nih/libnih.h: Include errors.h
2006-08-04 Scott James Remnant <scott@netsplit.com>
* nih/errors.h: Include errno.h for helpfulness.
2006-08-03 Scott James Remnant <scott@netsplit.com>
* nih/child.c (nih_child_add_watch): Also takes a parent now.
* nih/child.h: Update.
* nih/tests/test_child.c: Update.
* nih/io.c (nih_io_add_watch): And once more, with feeling; takes
a parent for the watch.
* nih/io.h: Update.
* nih/tests/test_io.c: Update.
* nih/signal.c (nih_signal_add_callback): Give this the same treatment,
it takes the parent for the signal callback.
* nih/signal.h: Update.
* nih/tests/test_signal.c: Update.
* nih/timer.c (nih_timer_add_timeout, nih_timer_add_periodic)
(nih_timer_add_scheduled): Use nih_alloc properly by taking a parent
for the timer object and setting a destructor on it so that it's
automatically removed when the parent is freed.
* nih/timer.h: Update.
* nih/tests/test_timer.c: Update function calls.
* nih/tests/test_main.c (test_main_loop): Update also.
* nih/list.c (nih_list_destructor): Add a destructor function that
just cuts the entry out of the list in preperation for being freed.
* nih/list.h: Update.
* nih/tests/test_list.c (test_destructor): Test the behaviour of
the new function.
* nih/tests/test_error.c: Include fixes.
2006-08-02 Scott James Remnant <scott@netsplit.com>
* nih/signal.c (nih_signal_set_handler, nih_signal_set_default)
(nih_signal_set_ignore): Reset sa_flags so that we don't pass
uninitialised data for SIGALRM.
(nih_signal_reset): Add function to reset signals back to their
default state.
* nih/signal.h: Update.
* nih/tests/test_signal.c (test_reset): Add test case.
* nih/error.c (nih_error_raise_system): Be a lot more careful in
this function! Save the value of errno in case we overwrite it
and call nih_error_init()
* nih/signal.c (nih_signal_set_handler): Add the SA_NOCLDSTOP
signal for SIGCHLD.
* nih/main.c (nih_main_loop): Drop the code that masked out the
child signal, it was inherently racy and there's no particular
reason to do it anyway since we use SA_RESTART in signal.c for
most things.
* nih/signal.c (nih_signal_set_handler, nih_signal_set_default)
(nih_signal_set_ignore): don't set SA_RESTART for SIGALRM.
* nih/signal.c (nih_signal_set_handler, nih_signal_set_default)
(nih_signal_set_ignore): use nih_return_system_error to make the
code rather cleaner.
* nih/error.h (nih_return_error): Add missing doc for retval
(nih_return_system_error): Add additional useful function.
* nih/tests/test_error.c (test_return_system_error): Add test
case for the new macro.
* nih/child.c (nih_child_poll): Convert to use waitid() so that
we can obtain the information about the dead child without reaping
it until we're done processing; useful because it means /proc/$PID
and the child itself is still around during the handlers.
* nih/child.h (NihReaper): Gains a new third argument that indicates
whether the child exited normally or was killed.
* nih/tests/test_child.c (test_poll): Update.
* nihify: Add a few useful sanity checks so that it works with
relative paths and already-nihified directories.
* m4/misc.m4: Remove older force code.
* TODO: Updated.
* m4/Makefile.am (dist_aclocal_DATA): Distribute misc.m4, long
missed.
* nihify: Add useful script for symlinking into source trees until
we intend to get released.
* HACKING: Correct typo (our -> out)
2006-07-28 Scott James Remnant <scott@netsplit.com>
* nih/main.c (nih_main_term_signal): Handy signal callback.
* nih/main.h: Update.
* nih/tests/test_main.c (my_timeout): Cheat and ensure the latest
exit status is used.
* nih/main.c (nih_main_loop): Implement a main loop by calling
various other functions in the right manner.
(nih_main_loop_exit): Function to break the main loop.
* nih/main.h: Update.
* nih/tests/test_main.c (test_main_loop): Add a trivial test case
for the main loop, it's damned difficult to test, but at least this
ensures the bases are touched.
* nih/signal.c (nih_signal_poll): Add missing call to
nih_signal_init()
* nih/child.c (nih_child_poll): Add missing call to nih_child_init()
* nih/io.c (nih_io_poll_fds, nih_io_handle_fds): Add missing calls
to nih_io_init()
* nih/io.c: Code for watching file descriptors and sockets for
events through poll(), but not actually the poll() call itself.
* nih/io.h: Typedefs, structures and prototypes.
* nih/libnih.h: Include io.h
* nih/tests/test_io.c: Test cases for I/O watches.
* nih/Makefile.am (libnih_la_SOURCES): Build and link io.c
(nihinclude_HEADERS): Install io.h
(TESTS): Build and run I/O test cases
(test_io_SOURCES, test_io_LDFLAGS, test_io_LDADD): Details for I/O
test case binary.
* nih/tests/test_timer.c (test_poll): Free entry after testing.
* nih/child.c (nih_child_poll): When the reaper is for a particular
process, be sure to remove it from the list.
* nih/tests/test_child.c (test_poll): Test for that.
* nih/child.c: Simple bit of code to wait for children to
terminate and dispatch the reaper functions for them.
* nih/child.h: Typedefs, structures and prototypes.
* nih/libnih.h: Include child.h
* nih/tests/test_child.c: Test cases for child handling code.
* nih/Makefile.am (libnih_la_SOURCES): Build and link child.c
(nihinclude_HEADERS): Install child.h
(TESTS): Build and run child test cases
(test_child_SOURCES, test_child_LDFLAGS, test_child_LDADD): Details
for child test case binary.
* nih/timer.c (nih_timer_add_timeout, nih_timer_add_periodic)
(nih_timer_add_scheduled): Change argument order so that the time
information is first, to match signal functions.
* nih/timer.h: Update.
* nih/tests/test_timer.c: Update.
* nih/signal.h: Include the system signal.h for ease of use.
* nih/signal.c: Code for handling signals inside the main loop,
rather than trying to fit delicate code in a signal handler; and
for making it generally easier to handle signals.
* nih/signal.h: Typedefs and prototypes.
* nih/libnih.h: Include signal.h
* nih/Makefile.am (libnih_la_SOURCES): Build and link signal.c
(nihinclude_HEADERS): Install signal.h
(TESTS): Build and run signal test cases
(test_signal_SOURCES, test_signal_LDFLAGS, test_signal_LDADD): Details
for signal test case binary.
2006-07-27 Scott James Remnant <scott@netsplit.com>
* nih/timer.c: Code for timeouts, periodic and scheduled timers,
note that the actual scheduling part of scheduled timers it not
implemented yet (we need to think a bit more about it)
* nih/timer.h: Structures, macros and prototypes.
* nih/libnih.h: Include timer.h
* nih/tests/test_timer.c: Test cases for timer code.
* nih/Makefile.am (libnih_la_SOURCES): Build and link timer.c
(nihinclude_HEADERS): Install timer.h
(TESTS): Build and run timer test cases
(test_timer_SOURCES, test_timer_LDFLAGS, test_timer_LDADD): Details
for timer test case binary.
* nih/alloc.c (nih_free): Use new safe list iteration macro.
* nih/hash.c (nih_hash_add_unique, nih_hash_replace)
(nih_hash_search): Use new list iteration macros.
* nih/list.h (NIH_LIST_FOREACH): New macro that expands to the usual
list iteration for loop, prevents mistakes.
(NIH_LIST_FOREACH_SAFE): Macro that does the same as above, but also
includes a "next" variable to allow safe iteration; especially useful
to prevent us getting this wrong!
* nih/tests/test_list.c (test_foreach, test_foreach_safe): Add test
cases for iteration.
* nih/error.c (nih_error_init): Make inline and check value first.
(nih_error_raise, nih_error_raise_printf, nih_error_raise_again)
(nih_error_push_context): Unconditionally call nih_error_init.
* nih/alloc.c (nih_alloc_init): Make inline and check value first.
(nih_alloc): Unconditionally call nih_alloc_init.
* nih/logging.c (nih_log_init): Use the proper functions to
initialise details, check values first; also make inline.
(nih_log_message): Unconditionally call nih_log_init.
* nih/Makefile.am (DEFS): Append to the default DEFS list, rather
than overriding, otherwise we lose HAVE_CONFIG_H
* nih/macros.h: Check for ENABLE_NLS instead of HAVE_GETTEXT and
include libintl.h if defined as well.
2006-07-20 Scott James Remnant <scott@netsplit.com>
* nih/string.c (nih_strv_free): Add a function to free an array
of strings.
* nih/string.h: Update.
* nih/tests/test_string.c (test_strv_free): Test the function.
* nih/error.c: Error handling code.
* nih/error.h: Structures, macros and prototypes.
* nih/errors.h: Error enum and message definitions.
* nih/libnih.h: Include error.h and errors.h
* nih/tests/test_error.c: Error handling test cases.
* nih/Makefile.am (libnih_la_SOURCES): Build and link error.h
(nihinclude_HEADERS): Install error.h
(TESTS): Build and run error handling test cases.
(test_error_SOURCES, test_error_LDFLAGS, test_error_LDADD): Binary
for error handling test cases.
* nih/macros.h (NIH_MUST, NIH_MUST_NOT): Add handy macros to spin
until we get a true or false value from an assignment. Usually
used around a call to memory allocation functions that we can't
deal with failing.
* nih/main.c (nih_main_package_string): Change package_string
to be a module-level static so it can be reset by a call to
nih_main_init_full. Always return if not NULL.
* nih/tests/test_main.c (test_package_string): Call nih_main_init_full
instead of futzing with variables so the static string is reset.
* nih/alloc.c (nih_alloc_using, nih_alloc, nih_realloc)
(nih_alloc_size, nih_alloc_parent): Make various argument pointers
const.
* nih/alloc.h: Update.
* nih/libnih.h, nih/logging.c, nih/main.c: Update to include
string.h not strutil.h
* nih/strutil.c: Renamed to nih/string.c
* nih/strutil.h: Renamed to nih/string.h
* nih/tests/test_strutil.c: Renamed to nih/tests/test_string.h
* nih/Makefile.am (DEFAULT_INCLUDES): Override to stop automake doing
silly things like putting -I. in the pre-processor flags.
(libnih_la_SOURCES, nihinclude_HEADERS, TESTS)
(test_string_SOURCES, test_string_LDFLAGS, test_string_LDADD): Update.
2006-07-19 Scott James Remnant <scott@netsplit.com>
* nih/alloc.h, nih/logging.h, nih/strutil.h: Reformat attribute
declarations to not upset emacs indentation.
2006-07-17 Scott James Remnant <scott@netsplit.com>
* nih/strutil.c (nih_strdup): Implement an nih_alloc-based strdup.
(nih_strdup): and strndup.
* nih/strutil.h: Update.
* nih/tests/test_strutil.c: Test new functions.
2006-07-13 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c (nih_free): Remove the entry from the parent's list.
* nih/logging.h (nih_assert): Reexpress to avoid polluting if
statements without an else.
* nih/alloc.c (nih_realloc): Implement a function that reallocates
a block of memory with the original allocator.
(nih_alloc_init): Don't double-check the allocator.
* nih/alloc.h: Update.
* nih/tests/test_alloc.c (test_realloc): Check behaviour of realloc.
* nih/alloc.c (NihAllocCtx): Drop the name pointer, we never used
that anyway.
(nih_alloc_using): Drop name parameter.
(nih_alloc_named): Rename to nih_alloc.
(nih_alloc_set_name): Drop this function.
(nih_alloc_name): And this one.
* nih/alloc.h (nih_new): Simplify.
(nih_alloc): Drop entirely now it's unneeded.
* nih/tests/test_alloc.c: Update.
* nih/tests/test_list.c (test_new): Test using nih_alloc_size
rather than nih_alloc_name.
* nih/logging.h: Put the log priorities back in ascending order,
but use the zero to mean "unknown". Fix up the descriptions to be
a little more consistent.
* nih/logging.c: Rename max_priority back to min_priority so it
all makes more sense again.
(nih_log_init): Warning is the default minimum priority to show.
(nih_log_set_priority): Set minimum priority.
(nih_log_message): Discard messages below the minimum priority.
(nih_logger_printf): Use stderr when priority is greater than or
equal to warning.
* nih/tests/test_logging.c: Update to match.
* nih/logging.c (nih_log_message): Use nih_vsprintf which makes the
function not core dump (always good, that).
2006-07-12 Scott James Remnant <scott@netsplit.com>
* nih/main.c (nih_main_package_string): Use nih_sprintf and make
the function rather simpler.
* nih/tests/test_alloc.c (main): Formatting fix.
* nih/strutil.c (nih_sprintf): Function to wrap sprintf, allocating
the necessary space using nih_alloc first.
(nih_vsprintf): Function to wrap vsprintf, allocating the necessary
space using nih_alloc first.
* nih/strutil.h: Prototypes.
* nih/libnih.h: Include strutil.h
* nih/Makefile.am (libnih_la_SOURCES): Build and link strutil.c
(nihinclude_HEADERS): Install strutil.h
(TESTS): Build and run strutil test cases
(test_strutil_SOURCES, test_strutil_LDFLAGS)
(test_strutil_LDADD): Binary for strutil test cases.
2006-07-05 Scott James Remnant <scott@netsplit.com>
* nih/logging.c (nih_log_message): Don't bother catching
vsnprintf's return value, C99 doesn't allow it to fail.
* nih/main.c (nih_main_package_string): Likewise for here.
* nih/logging.c (nih_log_message): Don't use a static variable
for no apparent reason, just free afterwards. Catch vsnprintf and
malloc failing.
* nih/main.c (nih_main_package_string): Catch snprintf and realloc
failing here too.
2006-05-30 Scott James Remnant <scott@netsplit.com>
* nih/logging.h (nih_assert): Assertion macro that uses our logging
rather than stderr.
* nih/alloc.c, nih/hash.c, nih/list.c, nih/logging.c, nih/main.c:
Use nih_assert rather than assert.
* nih/Makefile.am (test_alloc_LDFLAGS, test_list_LDFLAGS)
(test_hash_LDFLAGS, test_main_LDFLAGS, test_logging_LDFLAGS): Link
libraries statically.
(test_alloc_LDADD, test_list_LDADD, test_hash_LDADD)
(test_main_LDADD, test_logging_LDADD): Just link to the library.
* nih/macros.h (NIH_STRINGIFY): Correct typo (-s -> _s)
(NIH_LIKELY, NIH_UNLIKELY): Add branch prediction macros.
2006-05-29 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c (nih_alloc_init): Restore this function, it's better
style to keep variables in shared libraries as zero.
(nih_alloc_named): Call nih_alloc_init once more.
* nih/logging.h: Reorder such that NONE is the lowest value.
* nih/logging.c (min_priority): Rename to max_priority and set value
to NIH_LOG_NONE (zero).
(nih_log_init): Initialise the default logger and priority.
(nih_log_set_priority): Assert priority is greater than NONE.
(nih_log_message): Initialise the logging if necessary.
(nih_logger_printf): Check priority with <=
* TODO: Update.
* nih/logging.c: Code for formatting log messages and filtering
based on priority.
* nih/logging.h: Prototypes and macros.
* nih/libnih.h: Include logging.h
* nih/tests/test_logging.c: Logging test cases.
* nih/Makefile.am (libnih_la_SOURCES): Build and link logging.c
(nihinclude_HEADERS): Install logging.h
(TESTS): Build and run logging test cases.
(test_logging_SOURCES, test_logging_LDADD): Binary for logging
test cases.
* nih/tests/test_main.c (test_package_string, test_suggest_help)
(test_version): Add missing comments before tests.
(test_suggest_help, test_version): Close the duplicated stdout/stderr
before leaving the test.
* nih/alloc.h: Declare nih_alloc_named and nih_alloc_using with
the warn_unused_result and malloc attributes.
2006-05-27 Scott James Remnant <scott@netsplit.com>
* m4/compiler.m4 (NIH_COMPILER_WARNINGS): Drop -pedantic as we
usually want gcc extensions (all the world IS gcc).
2006-05-26 Scott James Remnant <scott@netsplit.com>
* nih/main.c (nih_main_init_full): Only take the basename of
the program name, not the full path.
(nih_main_package_string): Use an allocated piece of memory rather
than some on the stack, with C99-style snprintf to do the right thing
with it.
* nih/tests/test_main.c (test_init): Include check for basename.
(test_package_string): Drop tests involving basename here.
* m4/compiler.m4 (NIH_TRY_C99): Macro that tries compiling
some code full of C99 features.
(NIH_C_C99): Use the above macro to determine whether the compiler
supports C99, or whether it can do it with a compiler flag.
* configure.ac: Make sure the compiler does C99.
* nih/list.c: Add missing prototype for nih_list_cut.
* nih/hash.c: Add missing prototype for fnv_hash.
* nih/macros.h (_, N_): Define gettext-wrapper macros if
HAVE_GETTEXT, otherwise define them to just expand to their string.
* nih/main.h: Drop comments for global variables.
* nih/main.c: Provide proper docstrings for them here.
* nih/alloc.c (nih_alloc_init): Drop this function, instead just
initialise the static variable directly.
(nih_alloc_set_allocator): Correct parameter name in docstring,
don't call nih_alloc_init (it's already initialised).
2006-05-24 Scott James Remnant <scott@netsplit.com>
* nih/main.c (nih_main_package_string): Clarify documentation.
2006-05-23 Scott James Remnant <scott@netsplit.com>
* nih/main.c: Add code for the various little functions that we
usually call from main().
* nih/main.h: Prototypes and macros.
* nih/libnih.h: Include main.h
* nih/Makefile.am (libnih_la_SOURCES): Build and link main.c
(nihinclude_HEADERS): Install main.h
(TESTS): Build and run main test-cases
(test_main_SOURCES, test_main_LDADD): Code for main tests.
* m4/misc.m4 (AC_COPYRIGHT): Wraps the Autoconf AC_COPYRIGHT macro
but also defines PACKAGE_COPYRIGHT
* m4/compiler.m4: Temporary hack to make sure misc.m4 gets dragged
in as aclocal doesn't notice it, will go away once we get something
that aclocal will notice.
2006-04-26 Scott James Remnant <scott@netsplit.com>
* nih/hash.c: Add code for FNV hash tables that uses NihList for
the actual bins so is largely polymorphic.
* nih/hash.h: Prototypes, macros and structures.
* nih/macros.h: Include stdint.h as well, we use that a lot.
* nih/libnih.h: Include hash.h
* nih/tests/test_hash.c: Test cases for new hash table code.
* nih/Makefile.am (libnih_la_SOURCES): Build and link hash.c
(nihinclude_HEADERS): Install hash.h
(TESTS): Build and run hash table test-cases.
(test_hash_SOURCES, test_hash_LDADD): Code for hash table tests.
* TODO: Update.
* nih/tests/test_list.c (test_empty): Fix faulty test case that
actually proved one-entry lists were showing up as empty!
* nih/list.h (NIH_LIST_EMPTY): Compare the next and previous pointers
against the list pointer itself!
* nih/list.c (nih_list_cut): Add an inline function that does the
job of nih_list_remove without calling nih_list_init afterwards.
(nih_list_remove): Call nih_list_cut rather than modifying pointers.
(nih_list_free): Use nih_list_cut for efficiency, no point fixing
the pointers if we're just going to free it.
(nih_list_add, nih_list_add_after): Use nih_list_cut as the pointers
get modified afterwards anyway, more efficient this way.
2006-04-25 Scott James Remnant <scott@netsplit.com>
* nih/list.c: Remove unnecessary include of stdlib.h
* nih/list.c (nih_list_new): Fix formatting of docstring.
* nih/alloc.c (nih_alloc_using, nih_alloc_parent): Fix formatting
of docstring.
(nih_alloc_named): Fix docstring to mention NULL can be returned.
* nih/tests/test_alloc.c, nih/tests/test_list.c: Add missing blank
line before includes.
* nih/alloc.c (nih_alloc_using): Return NULL if the allocation
fails.
* nih/list.c (nih_list_new): Also return NULL if the allocation
fails.
* nih/alloc.c (nih_alloc_set_allocator, nih_alloc_using)
(nih_free, nih_alloc_set_name, nih_alloc_set_destructor)
(nih_alloc_name, nih_alloc_size, nih_alloc_parent): Use assert
to uncover programming errors.
* nih/list.c (nih_list_init, nih_list_remove, nih_list_free)
(nih_list_add, nih_list_add_after): Use assert to uncover
programming errors.
(nih_list_new): Comment that nih_new may return NULL and we need
to make sure we catch that.
2006-04-24 Scott James Remnant <scott@netsplit.com>
* m4/Makefile.am (dist_aclocal_DATA): Add missing \
* nih/Makefile.am (INCLUDES): Include top_srcdir otherwise we
can't be built out of tree.
* m4/Makefile.am (dist_aclocal_DATA): Install the m4 files into
the aclocal directory, not a package specific one.
* m4/compiler.m4, m4/linker.m4: Fix closing comment style.
* TODO: Add TODO file.
* nih/list.h (NIH_LIST_EMPTY): Document what this actually does.
2006-04-19 Scott James Remnant <scott@netsplit.com>
* nih/list.c (nih_list_entry_new): Removed. This makes the list
code more focussed and generic, but also we'll nearly always want
the data member to be an nih_alloc child of the list, rather than
the other way around!
* nih/list.h (NihListEntry, nih_list_add_new)
(nih_list_add_new_after): Likewise, remove the structure and helper
macros; if we find ourselves wanting this, we can put it in a new
file and just make it polymorphic like we plan for hashes.
* nih/tests/test_list.c: Replace all uses of NihListEntry with plain
NihList, we never checked the data members anyway.
(test_entry_new): Remove test case.
(test_add): Remove test of nih_list_add_new macro.
(test_add_after): Remove test of nih_list_add_new_after macro.
(test_empty): Check macro works with any list entry.
(test_remove): Test removal of the last list entry, and removal
on an already empty list.
(test_free): Don't check the pointers of a block we've just freed!
2006-04-18 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c (nih_alloc_init): Call nih_alloc_set_allocator.
* nih/alloc.h (NihDestructor): Clarify docstring to not refer
to internal structures.
* nih/list.h (NIH_LIST_EMPTY): Add convenience macro for this
common operation.
* nih/tests/test_list.c (test_empty): Test the new macro.
2006-04-16 Scott James Remnant <scott@netsplit.com>
* nih/list.c (nih_list_new, nih_list_entry_new): Call nih_new rather
than malloc so the list can be a context for data members.
(nih_list_free): Call nih_free rather than free.
* nih/tests/test_list.c: Test cases should not be static.
(test_new, test_entry_new): Check the new object was allocated using
our nih_alloc function.
(test_remove): Test a second removal.
(destructor_called): Function to test whether destructor was called.
(test_free): Test now that we can use an NihDestructor.
* nih/Makefile.am (test_list_LDADD): Link alloc.o now that lists
depend on the allocator.
* nih/list.c, nih/list.h: Fix docstrings to use references where
useful. Split functions into blocks separated by a newline.
* nih/alloc.h: Update and fix formatting.
(NihAllocDestructor): Rename to NihDestructor.
* nih/alloc.c (nih_alloc_init): Make safe against repeated calls.
(nih_alloc_set_allocator): New function to set the default allocator,
overriding any set already.
(nih_alloc_set_destructor): Update type of destructor argument..
(NihAllocCtx): Update type of destructor member.
* nih/tests/test_alloc.c (my_realloc): Wrapper around realloc so
we can check custom allocators are called properly.
(test_alloc_using): Test allocation with a custom allocator.
(test_free): Check that the block is freed using the allocator,
also update destructor checking.
(test_set_allocator): Test new allocator is used.
* nih/alloc.c (nih_alloc_using): New one-shot function to use a given
realloc-style function to make a named block of memory of a given size.
(nih_alloc_named): Replace with a thin-wrapper around nih_alloc_using
that passes in the default allocator.
(NihAllocCtx): Add new allocator member to store the allocator used,
so we free with the right one.
(nih_alloc_init): Set the default allocator to realloc(). Drop
pool initialisation code.
(nih_free): Call the context's original allocator with zero size.
(used_pool, unused_pool, NIH_ALLOC_SMALLEST): Remove, these really
belong in distinct memory handling code.
(nih_alloc_set, nih_alloc_new): Drop functions only needed if we're
doing our own memory management.
(nih_alloc_size, nih_alloc_parent): Add a couple of useful functions.
* nih/alloc.h (NihAllocator): Typedef for allocator function prototype.
(nih_alloc): Rename to nih_new.
(nih_alloc_size): Rename to nih_alloc.
* nih/tests/test_alloc.c (test_alloc_named, test_new, test_alloc): Test
behaviour of standard functions with and without parents.
(destructor_called): Allow it to be called multiple times, change
to static to enforce modularity.
(child_destructor_called): Another function for testing multiple
destructors.
(test_free): Test nih_free using alloc destructors.
(test_alloc_set_name): Rename to just test_set_name for consistency.
* nih/macros.h (NIH_STRINGIFY): Generic hack to turn a numeric
macro into a string.
* nih/alloc.h (nih_alloc, nih_alloc_size): Use generic NIH_STRINGIFY
macro instead of our home-cooked one.
2006-03-31 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c, nih/alloc.h, nih/list.c, nih/list.h, nih/macros.h,
nih/libnih.h, nih/tests/test_alloc.c,
nih/tests/test_list.c: Update FSF address in GPL header.
2006-03-03 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c, nih/alloc.h, nih/list.c, nih/list.h: Formatting fixes,
correct erroneous references to d_* functions and D* structures.
* nih/list.h: Correct docstring for nih_list_new and nih_list_entry_new
functions so that @data is described for the right one.
* nih/Makefile.am: Add blank line between SOURCES and LDFLAGS.
2005-09-29 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c, nih/alloc.h, nih/list.c, nih/list.h: Fix docstring
terminators to be **/ not */.
* nih/alloc.h: Align function parameters.
* nih/tests/test_alloc.c (test_alloc_set_name): Fix to return
ret and not zero all the time.
2005-08-29 Scott James Remnant <scott@netsplit.com>
* nih/alloc.c (NIH_ALLOC_SMALLEST): Set to the size of the
NihAllocCtx structure shifted left twice; this will divide evenly
into a page.
* nih/alloc.c (nih_alloc_init): No need to pass NULL to nih_list_new.
(nih_alloc_new): No need to initialise data member of NihList structs
or cast children member.
(nih_alloc_named): Can cast NihList directly to NihAllocCtx now,
simplify difference test.
(nih_free): Use iter as variable name for clarity.
(nih_alloc_return_unused): Cast NihList directly to NihAllocCtx.
* nih/tests/test_alloc.c: Output "BAD:" instead of "FAIL:"
* nih/list.h (NihList): Remove data pointer, it'll save us 4 bytes
where we want to make lists of structures that are always in lists.
(NihListEntry): Define new structure for those still wanting data
pointers.
(nih_list_add_new, nih_list_add_new_after): Use nih_list_entry_new.
* nih/list.c (nih_list_new): Remove argument and don't initialise
data pointer, this simply allocates and initialises the two-pointer
structure.
(nih_list_entry_new): New function to allocate and initialise an
NihListEntry structure.
* nih/tests/test_list.c: Output "BAD:" instead of "FAIL:"
(test_new): Test without data pointer.
(test_entry_new): Test with data pointer.
(test_add, test_add_after, test_remove): Mix and cast NihList and
NihListEntry properly.
* nih/alloc.c: Implement a heirarchial allocator in a similar
style to halloc and talloc, but designed never to return data to
the system and re-use it instead.
* nih/alloc.h: Prototypes and macros for allocator.
* nih/libnih.h: Include allocator header.
* nih/tests/test_alloc.c: Test-cases for allocator.
* nih/macros.h (MIN, MAX): Define MIN and MAC macros if not already
available.
* nih/Makefile.am (libnih_la_SOURCES): Compile and link alloc.c
(nihinclude_HEADERS): Install alloc.h
(TESTS): Build and run the allocator test-cases.
(test_alloc_SOURCES, alloc_list_LDADD): Identify the test sources and
objects it needs.
2005-08-28 Scott James Remnant <scott@netsplit.com>
* nih/list.c (nih_list_init): Add new function for dealing with
statically allocated list entries, and initialising them.
(nih_list_new): Use nih_list_init() to initialise the list.
(nih_list_new): Use nih_list_init() to re-initialise the list
to a single-member.
* nih/list.h: Add prototype for nih_list_init.
(NihListIter): Remove the iterator structure, it turns
out to be harder work to try and use lists in an "all nodes are
interesting" manner; so we'll iterate them normally instead.
(NIH_LIST_FIRST, NIH_LIST_LAST): Remove iterator test functions.
(NIH_LIST_PREV, NIH_LIST_NEXT): Remove iterator change functions.
* nih/tests/test_list.c: Use NULL for nih_list_new in all functions.
(test_init): New test case for nih_list_init().
(test_iterator): Removed iterator tests.
2005-08-21 Scott James Remnant <scott@netsplit.com>
* nih/list.c: Add code for generic circular doubly-linked lists.
* nih/list.h: Prototypes and macros.
* nih/macros.h: Some generic macros.
* nih/libnih.h: Header to import everything.
* nih/tests/test_list.c: Test-cases for linked-list code.
* nih/Makefile.am (libnih_la_SOURCES): Link list.c in.
(nihincludedir): Define directory to contain header files to be
$includedir/nih.