failtest: save and restore file state inside child (on-demand)
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 30 Nov 2011 00:23:42 +0000 (10:53 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 30 Nov 2011 00:23:42 +0000 (10:53 +1030)
commit67bbee5311280dbbf30debe7122d8722c710e3c3
tree7082e03ee60d9b5480aed294a558629b231e21d2
parent4f2f6f1eba6cc2bcb0683c50269d1dbbe73ed167
failtest: save and restore file state inside child (on-demand)

We currently save all files in the parent, and restore them once
the child is gone.  That doesn't work in a case where the child
manipulates a file the parent doesn't currently have open, so
switch to a model where the child cleans itself up, using the
already-existing cleanup callbacks.

This means that we need to undo much more, especially restoring
file offsets.  We also need to handle the case where we've already
closed the file, and now we're cleaning up.  As a bonus, we now
handle open() with O_TRUNC properly.

The cleanup function now has two modes: one simply frees (so valgrind
doesn't complain about failtest leaking so the user can see real leaks
in their programs), the other restores things so the parent sees no
changes.
ccan/failtest/failtest.c
ccan/failtest/failtest.h
ccan/failtest/failtest_override.h
ccan/failtest/failtest_proto.h
ccan/failtest/failtest_undo.h
ccan/failtest/test/run-failpath.c
ccan/failtest/test/run-history.c
ccan/failtest/test/run-locking.c
ccan/failtest/test/run-malloc.c
ccan/failtest/test/run-open.c
ccan/failtest/test/run-write.c