Steve Langasek has proposed merging lp:~vorlon/libnih/lp.776532 into lp:~upstart-devel/libnih/nih.
Requested reviews: Upstart Developers (upstart-devel) Related bugs: Bug #776532 in libnih: "nih_dir_walk_scan passes incorrect value to file filter" https://bugs.launchpad.net/libnih/+bug/776532 For more details, see: https://code.launchpad.net/~vorlon/libnih/lp.776532/+merge/153249 Follow-up to lp:~jamesodhunt/libnih/bug-776532 which does the wrapping in the right place (and thus passes the test suite). -- https://code.launchpad.net/~vorlon/libnih/lp.776532/+merge/153249 Your team Upstart Reviewers is subscribed to branch lp:~upstart-devel/libnih/nih.
=== modified file 'ChangeLog' --- ChangeLog 2013-03-05 19:21:57 +0000 +++ ChangeLog 2013-03-13 21:52:25 +0000 @@ -1,3 +1,4 @@ +<<<<<<< TREE 2013-02-28 James Hunt <[email protected]> * Removal of gcc 'malloc' function attribute resulting from @@ -34,6 +35,18 @@ (e)glibc private symbol __abort_msg to avoid upgrade issues (LP: #997359). * nih/tests/test_logging.c: Update tests for __nih_abort_msg. +======= +2013-03-13 Steve Langasek <[email protected]> + + * nih/watch.c (nih_watch_walk_filter): New NihFileFilter function + passed to nih_dir_walk_scan() to ensure the nih_watch_new() filter + function is passed the NihWatch data rather than the data passed to + the nih_dir_walk() NihFileVisitor function (LP: #776532). + + * nih/tests/test_watch.c (test_new): New test "with filter and data" + to ensure filter is passed correct value. + +>>>>>>> MERGE-SOURCE 2011-08-31 James Hunt <[email protected]> * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c === modified file 'nih/tests/test_watch.c' --- nih/tests/test_watch.c 2011-08-26 18:30:16 +0000 +++ nih/tests/test_watch.c 2013-03-13 21:52:25 +0000 @@ -39,6 +39,8 @@ #include <nih/error.h> #include <nih/logging.h> +/* Read "The Hitchhikers Guide to the Galaxy" */ +#define FILTER_VALUE 42 static int my_filter (void *data, @@ -54,6 +56,26 @@ return FALSE; } +/* Set by my_filter2 () so it knows if it has already been called */ +static int my_filter2_called = 0; + +static int +my_filter2 (int *value, + const char *path, + int is_dir) +{ + /* we only want to toggle the value once */ + if (my_filter2_called) + return TRUE; + + my_filter2_called = 1; + + nih_assert (value && *value == FILTER_VALUE); + *value = 0; + + return FALSE; +} + static int create_called = 0; static int modify_called = 0; static int delete_called = 0; @@ -553,6 +575,44 @@ nih_free (watch); } + /* Ensure the file filter gets passed the correct data pointer. + */ + TEST_FEATURE ("with filter and data"); + + /* Ensure we have a new directory */ + TEST_FILENAME (dirname); + mkdir (dirname, 0755); + + /* Create a single file */ + strcpy (filename, dirname); + strcat (filename, "/foo"); + + fd = fopen (filename, "w"); + fprintf (fd, "test\n"); + fclose (fd); + + TEST_ALLOC_FAIL { + int watch_data = FILTER_VALUE; + + /* Reset required to appease TEST_ALLOC_FAIL */ + my_filter2_called = 0; + + watch = nih_watch_new (NULL, dirname, + TRUE, TRUE, + (NihFileFilter)my_filter2, + NULL, NULL, NULL, + &watch_data); + + TEST_NE_P (watch, NULL); + + /* Ensure the filter was called and changed the value */ + + TEST_NE (my_filter2_called, 0); + TEST_EQ (watch_data, 0); + + nih_free (watch); + } + strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0755); === modified file 'nih/watch.c' --- nih/watch.c 2011-08-26 18:30:16 +0000 +++ nih/watch.c 2013-03-13 21:52:25 +0000 @@ -71,6 +71,9 @@ uint32_t events, uint32_t cookie, const char *name, int *caught_free); +static int nih_watch_walk_filter (void *data, const char *path, + int is_dir) + __attribute__ ((warn_unused_result)); /** @@ -185,6 +188,35 @@ } + /** + * nih_watch_walk_filter: + * @data: NihWatch, + * @path: path to file, + * @is_dir: TRUE if @path is a directory. + * + * Callback function for nih_dir_walk(), used by nih_watch_add() to wrap + * the user-specified NihFileFilter (watch->filter) with a filter that can + * take watch itself as an argument. + * + * Returns: TRUE if the path should be ignored, FALSE otherwise. + **/ +static int +nih_watch_walk_filter (void *data, const char *path, int is_dir) +{ + NihWatch *watch; + + watch = (NihWatch *)data; + + nih_assert (watch); + + /* No filter, so accept all files */ + if (! watch->filter) + return FALSE; + + return watch->filter (watch->data, path, is_dir); +} + + /** * nih_watch_handle_by_wd: * @watch: watch to search, @@ -295,7 +327,7 @@ * one; errors within the walk are warned automatically, so if this * fails, it means we literally couldn't watch the top-level. */ - if (subdirs && (nih_dir_walk (path, watch->filter, + if (subdirs && (nih_dir_walk (path, nih_watch_walk_filter, (NihFileVisitor)nih_watch_add_visitor, NULL, watch) < 0)) { NihError *err;
-- upstart-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
