Merge lp:~vorlon/libnih/lp.776532 into lp:~upstart-devel/libnih/nih

Proposed by Steve Langasek
Status: Merged
Merged at revision: 1061
Proposed branch: lp:~vorlon/libnih/lp.776532
Merge into: lp:~upstart-devel/libnih/nih
Diff against target: 171 lines (+106/-1) (has conflicts)
3 files modified
ChangeLog (+13/-0)
nih/tests/test_watch.c (+60/-0)
nih/watch.c (+33/-1)
Text conflict in ChangeLog
To merge this branch: bzr merge lp:~vorlon/libnih/lp.776532
Reviewer Review Type Date Requested Status
James Hunt Approve
Review via email: mp+153249@code.launchpad.net

Description of the change

Follow-up to lp:~jamesodhunt/libnih/bug-776532 which does the wrapping in
the right place (and thus passes the test suite).

To post a comment you must log in.
Revision history for this message
James Hunt (jamesodhunt) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-03-05 19:21:57 +0000
3+++ ChangeLog 2013-03-13 21:52:25 +0000
4@@ -1,3 +1,4 @@
5+<<<<<<< TREE
6 2013-02-28 James Hunt <james.hunt@ubuntu.com>
7
8 * Removal of gcc 'malloc' function attribute resulting from
9@@ -34,6 +35,18 @@
10 (e)glibc private symbol __abort_msg to avoid upgrade issues (LP: #997359).
11 * nih/tests/test_logging.c: Update tests for __nih_abort_msg.
12
13+=======
14+2013-03-13 Steve Langasek <steve.langasek@ubuntu.com>
15+
16+ * nih/watch.c (nih_watch_walk_filter): New NihFileFilter function
17+ passed to nih_dir_walk_scan() to ensure the nih_watch_new() filter
18+ function is passed the NihWatch data rather than the data passed to
19+ the nih_dir_walk() NihFileVisitor function (LP: #776532).
20+
21+ * nih/tests/test_watch.c (test_new): New test "with filter and data"
22+ to ensure filter is passed correct value.
23+
24+>>>>>>> MERGE-SOURCE
25 2011-08-31 James Hunt <james.hunt@ubuntu.com>
26
27 * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c
28
29=== modified file 'nih/tests/test_watch.c'
30--- nih/tests/test_watch.c 2011-08-26 18:30:16 +0000
31+++ nih/tests/test_watch.c 2013-03-13 21:52:25 +0000
32@@ -39,6 +39,8 @@
33 #include <nih/error.h>
34 #include <nih/logging.h>
35
36+/* Read "The Hitchhikers Guide to the Galaxy" */
37+#define FILTER_VALUE 42
38
39 static int
40 my_filter (void *data,
41@@ -54,6 +56,26 @@
42 return FALSE;
43 }
44
45+/* Set by my_filter2 () so it knows if it has already been called */
46+static int my_filter2_called = 0;
47+
48+static int
49+my_filter2 (int *value,
50+ const char *path,
51+ int is_dir)
52+{
53+ /* we only want to toggle the value once */
54+ if (my_filter2_called)
55+ return TRUE;
56+
57+ my_filter2_called = 1;
58+
59+ nih_assert (value && *value == FILTER_VALUE);
60+ *value = 0;
61+
62+ return FALSE;
63+}
64+
65 static int create_called = 0;
66 static int modify_called = 0;
67 static int delete_called = 0;
68@@ -553,6 +575,44 @@
69 nih_free (watch);
70 }
71
72+ /* Ensure the file filter gets passed the correct data pointer.
73+ */
74+ TEST_FEATURE ("with filter and data");
75+
76+ /* Ensure we have a new directory */
77+ TEST_FILENAME (dirname);
78+ mkdir (dirname, 0755);
79+
80+ /* Create a single file */
81+ strcpy (filename, dirname);
82+ strcat (filename, "/foo");
83+
84+ fd = fopen (filename, "w");
85+ fprintf (fd, "test\n");
86+ fclose (fd);
87+
88+ TEST_ALLOC_FAIL {
89+ int watch_data = FILTER_VALUE;
90+
91+ /* Reset required to appease TEST_ALLOC_FAIL */
92+ my_filter2_called = 0;
93+
94+ watch = nih_watch_new (NULL, dirname,
95+ TRUE, TRUE,
96+ (NihFileFilter)my_filter2,
97+ NULL, NULL, NULL,
98+ &watch_data);
99+
100+ TEST_NE_P (watch, NULL);
101+
102+ /* Ensure the filter was called and changed the value */
103+
104+ TEST_NE (my_filter2_called, 0);
105+ TEST_EQ (watch_data, 0);
106+
107+ nih_free (watch);
108+ }
109+
110 strcpy (filename, dirname);
111 strcat (filename, "/bar");
112 chmod (filename, 0755);
113
114=== modified file 'nih/watch.c'
115--- nih/watch.c 2011-08-26 18:30:16 +0000
116+++ nih/watch.c 2013-03-13 21:52:25 +0000
117@@ -71,6 +71,9 @@
118 uint32_t events, uint32_t cookie,
119 const char *name,
120 int *caught_free);
121+static int nih_watch_walk_filter (void *data, const char *path,
122+ int is_dir)
123+ __attribute__ ((warn_unused_result));
124
125
126 /**
127@@ -185,6 +188,35 @@
128 }
129
130
131+ /**
132+ * nih_watch_walk_filter:
133+ * @data: NihWatch,
134+ * @path: path to file,
135+ * @is_dir: TRUE if @path is a directory.
136+ *
137+ * Callback function for nih_dir_walk(), used by nih_watch_add() to wrap
138+ * the user-specified NihFileFilter (watch->filter) with a filter that can
139+ * take watch itself as an argument.
140+ *
141+ * Returns: TRUE if the path should be ignored, FALSE otherwise.
142+ **/
143+static int
144+nih_watch_walk_filter (void *data, const char *path, int is_dir)
145+{
146+ NihWatch *watch;
147+
148+ watch = (NihWatch *)data;
149+
150+ nih_assert (watch);
151+
152+ /* No filter, so accept all files */
153+ if (! watch->filter)
154+ return FALSE;
155+
156+ return watch->filter (watch->data, path, is_dir);
157+}
158+
159+
160 /**
161 * nih_watch_handle_by_wd:
162 * @watch: watch to search,
163@@ -295,7 +327,7 @@
164 * one; errors within the walk are warned automatically, so if this
165 * fails, it means we literally couldn't watch the top-level.
166 */
167- if (subdirs && (nih_dir_walk (path, watch->filter,
168+ if (subdirs && (nih_dir_walk (path, nih_watch_walk_filter,
169 (NihFileVisitor)nih_watch_add_visitor,
170 NULL, watch) < 0)) {
171 NihError *err;

Subscribers

People subscribed via source and target branches