Merge lp:~jamesodhunt/libnih/bug-776532 into lp:~upstart-devel/libnih/nih

Proposed by Dimitri John Ledkov
Status: Rejected
Rejected by: Steve Langasek
Proposed branch: lp:~jamesodhunt/libnih/bug-776532
Merge into: lp:~upstart-devel/libnih/nih
Diff against target: 167 lines (+102/-1)
3 files modified
ChangeLog (+10/-0)
nih/file.c (+32/-1)
nih/tests/test_watch.c (+60/-0)
To merge this branch: bzr merge lp:~jamesodhunt/libnih/bug-776532
Reviewer Review Type Date Requested Status
Steve Langasek Disapprove
Review via email: mp+140150@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) wrote :

The test suite correctly identifies a bug in this proposed branch. The right fix is for *nih_watch_add* to pass the wrapper *to* nih_dir_walk_scan(); nih_dir_walk_scan() should itself not be wrapping anything or assuming anything about the structure of data, which is what's happening here and causing the test suite failure.

I've got a local fix for this which I'll submit as a separate MP shortly.

review: Disapprove

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2011-09-01 18:41:03 +0000
+++ ChangeLog 2012-12-17 09:25:26 +0000
@@ -1,3 +1,13 @@
12012-04-27 James Hunt <james.hunt@ubuntu.com>
2
3 * nih/file.c (nih_dir_walk_filter): New NihFileFilter function passed to
4 nih_dir_walk_scan() to ensure the nih_watch_new() filter function is
5 passed the NihWatch data rather than the data passed to the
6 nih_dir_walk() NihFileVisitor function (LP: #776532).
7
8 * nih/tests/test_watch.c (test_new): New test "with filter and data"
9 to ensure filter is passed correct value.
10
12011-08-31 James Hunt <james.hunt@ubuntu.com>112011-08-31 James Hunt <james.hunt@ubuntu.com>
212
3 * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c13 * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c
414
=== modified file 'nih/file.c'
--- nih/file.c 2009-10-03 09:37:58 +0000
+++ nih/file.c 2012-12-17 09:25:26 +0000
@@ -44,6 +44,7 @@
44#include <nih/logging.h>44#include <nih/logging.h>
45#include <nih/error.h>45#include <nih/error.h>
46#include <nih/errors.h>46#include <nih/errors.h>
47#include <nih/watch.h>
4748
4849
49/**50/**
@@ -71,6 +72,8 @@
71 NihFileVisitor visitor,72 NihFileVisitor visitor,
72 NihFileErrorHandler error, void *data)73 NihFileErrorHandler error, void *data)
73 __attribute__ ((warn_unused_result));74 __attribute__ ((warn_unused_result));
75static int nih_dir_walk_filter (void *data, const char *path, int is_dir)
76 __attribute__ ((warn_unused_result));
7477
7578
76/**79/**
@@ -542,7 +545,7 @@
542 nih_assert (path != NULL);545 nih_assert (path != NULL);
543 nih_assert (visitor != NULL);546 nih_assert (visitor != NULL);
544547
545 paths = nih_dir_walk_scan (path, filter, data);548 paths = nih_dir_walk_scan (path, nih_dir_walk_filter, data);
546 if (! paths)549 if (! paths)
547 return -1;550 return -1;
548551
@@ -571,6 +574,34 @@
571}574}
572575
573/**576/**
577 * nih_dir_walk_filter:
578 * @data: NihWatch,
579 * @path: path to file,
580 * @is_dir: TRUE if @path is a directory.
581 *
582 * NihFileFilter function that is required to ensure the data passed to
583 * the user-specified NihFileFilter (as specified to nih_watch_new())
584 * is the NihWatch @data and not the NihWatch itself.
585 *
586 * Returns: TRUE if the path should be ignored, FALSE otherwise.
587 **/
588static int
589nih_dir_walk_filter (void *data, const char *path, int is_dir)
590{
591 NihWatch *watch;
592
593 watch = (NihWatch *)data;
594
595 nih_assert (watch);
596
597 /* No filter, so accept all files */
598 if (! watch->filter)
599 return FALSE;
600
601 return watch->filter (watch->data, path, is_dir);
602}
603
604/**
574 * nih_dir_walk_sort:605 * nih_dir_walk_sort:
575 * @a: pointer to first path,606 * @a: pointer to first path,
576 * @b: pointer to second path.607 * @b: pointer to second path.
577608
=== modified file 'nih/tests/test_watch.c'
--- nih/tests/test_watch.c 2011-08-26 18:30:16 +0000
+++ nih/tests/test_watch.c 2012-12-17 09:25:26 +0000
@@ -39,6 +39,8 @@
39#include <nih/error.h>39#include <nih/error.h>
40#include <nih/logging.h>40#include <nih/logging.h>
4141
42/* Read "The Hitchhikers Guide to the Galaxy" */
43#define FILTER_VALUE 42
4244
43static int45static int
44my_filter (void *data,46my_filter (void *data,
@@ -54,6 +56,26 @@
54 return FALSE;56 return FALSE;
55}57}
5658
59/* Set by my_filter2 () so it knows if it has already been called */
60static int my_filter2_called = 0;
61
62static int
63my_filter2 (int *value,
64 const char *path,
65 int is_dir)
66{
67 /* we only want to toggle the value once */
68 if (my_filter2_called)
69 return TRUE;
70
71 my_filter2_called = 1;
72
73 nih_assert (value && *value == FILTER_VALUE);
74 *value = 0;
75
76 return FALSE;
77}
78
57static int create_called = 0;79static int create_called = 0;
58static int modify_called = 0;80static int modify_called = 0;
59static int delete_called = 0;81static int delete_called = 0;
@@ -553,6 +575,44 @@
553 nih_free (watch);575 nih_free (watch);
554 }576 }
555577
578 /* Ensure the file filter gets passed the correct data pointer.
579 */
580 TEST_FEATURE ("with filter and data");
581
582 /* Ensure we have a new directory */
583 TEST_FILENAME (dirname);
584 mkdir (dirname, 0755);
585
586 /* Create a single file */
587 strcpy (filename, dirname);
588 strcat (filename, "/foo");
589
590 fd = fopen (filename, "w");
591 fprintf (fd, "test\n");
592 fclose (fd);
593
594 TEST_ALLOC_FAIL {
595 int watch_data = FILTER_VALUE;
596
597 /* Reset required to appease TEST_ALLOC_FAIL */
598 my_filter2_called = 0;
599
600 watch = nih_watch_new (NULL, dirname,
601 TRUE, TRUE,
602 (NihFileFilter)my_filter2,
603 NULL, NULL, NULL,
604 &watch_data);
605
606 TEST_NE_P (watch, NULL);
607
608 /* Ensure the filter was called and changed the value */
609
610 TEST_NE (my_filter2_called, 0);
611 TEST_EQ (watch_data, 0);
612
613 nih_free (watch);
614 }
615
556 strcpy (filename, dirname);616 strcpy (filename, dirname);
557 strcat (filename, "/bar");617 strcat (filename, "/bar");
558 chmod (filename, 0755);618 chmod (filename, 0755);

Subscribers

People subscribed via source and target branches

to all changes: