* Dhaval Giani <[email protected]> [2009-05-18 14:17:44]: > With the introduction of the flags, we now actually make use of them. > This patch adds a post mode and modifies the test case to also do a post > order walk. > > Signed-off-by: Dhaval Giani <[email protected]> > > --- > src/api.c | 17 +++++++++++++---- > src/libcgroup.map | 1 + > tests/walk_test.c | 27 +++++++++++++++++++++++++++ > 3 files changed, 41 insertions(+), 4 deletions(-) > > Index: libcg/src/api.c > =================================================================== > --- libcg.orig/src/api.c > +++ libcg/src/api.c > @@ -2197,7 +2197,7 @@ int cgroup_get_last_errno() > > > static int cg_walk_node(FTS *fts, FTSENT *ent, const int depth, > - struct cgroup_file_info *info) > + struct cgroup_file_info *info, int dir) > { > int ret = 0; > > @@ -2221,12 +2221,15 @@ static int cg_walk_node(FTS *fts, FTSENT > errno = ent->fts_errno; > break; > case FTS_D: > - info->type = CGROUP_FILE_TYPE_DIR; > + if (dir & CGROUP_WALK_TYPE_PRE_DIR) > + info->type = CGROUP_FILE_TYPE_DIR; > break; > case FTS_DC: > case FTS_NSOK: > case FTS_NS: > case FTS_DP: > + if (dir & CGROUP_WALK_TYPE_POST_DIR) > + info->type = CGROUP_FILE_TYPE_DIR; > break; > case FTS_F: > info->type = CGROUP_FILE_TYPE_FILE; > @@ -2257,7 +2260,9 @@ int cgroup_walk_tree_next(const int dept > return ECGEOF; > if (!base_level && depth) > base_level = ent->fts_level + depth; > - ret = cg_walk_node(entry->fts, ent, base_level, info); > + > + ret = cg_walk_node(entry->fts, ent, base_level, info, entry->flags); > + > *handle = entry; > return ret; > } > @@ -2311,6 +2316,8 @@ int cgroup_walk_tree_begin(char *control > return ECGOTHER; > } > > + entry->flags |= CGROUP_WALK_TYPE_PRE_DIR; > + > *base_level = 0; > cg_path[0] = full_path; > cg_path[1] = NULL; > @@ -2324,7 +2331,9 @@ int cgroup_walk_tree_begin(char *control > } > if (!*base_level && depth) > *base_level = ent->fts_level + depth; > - ret = cg_walk_node(entry->fts, ent, *base_level, info); > + > + ret = cg_walk_node(entry->fts, ent, base_level, info, entry->flags); > + > *handle = entry; > return ret; > } > Index: libcg/tests/walk_test.c > =================================================================== > --- libcg.orig/tests/walk_test.c > +++ libcg/tests/walk_test.c > @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) > exit(EXIT_FAILURE); > } > strcpy(root, info.full_path); > + printf("Begin pre-order walk\n"); > printf("root is %s\n", root); > visit_node(&info, root); > while ((ret = cgroup_walk_tree_next(0, &handle, &info, lvl)) != > @@ -49,6 +50,32 @@ int main(int argc, char *argv[]) > } > cgroup_walk_tree_end(&handle); > > + printf("pre-order walk finished\n"); > + ret = cgroup_walk_tree_begin(controller, "/", 0, &handle, &info, &lvl); > + > + if (ret != 0) { > + fprintf(stderr, "Walk failed\n"); > + exit(EXIT_FAILURE); > + } > + > + ret = cgroup_walk_tree_set_flags(&handle, CGROUP_WALK_TYPE_POST_DIR); > + > + if (ret) { > + fprintf(stderr, "Walk failed with %s\n", cgroup_strerror(ret)); > + exit(EXIT_FAILURE); > + } > + > + strcpy(root, info.full_path); > + printf("Begin post-order walk\n"); > + printf("root is %s\n", root); > + visit_node(&info, root); > + while ((ret = cgroup_walk_tree_next(0, &handle, &info, lvl)) != > + ECGEOF) { > + visit_node(&info, root); > + } > + cgroup_walk_tree_end(&handle); > + printf("post order walk finished\n"); > + > ret = cgroup_walk_tree_begin(controller, "/a", 2, &handle, &info, &lvl); > > if (ret != 0) { > Index: libcg/src/libcgroup.map > =================================================================== > --- libcg.orig/src/libcgroup.map > +++ libcg/src/libcgroup.map > @@ -62,4 +62,5 @@ global: > cgroup_read_stats_begin; > cgroup_read_stats_next; > cgroup_read_stats_end; > + cgroup_walk_tree_set_flags; > } CGROUP_0.33; >
Looks good Acked-by: Balbir Singh <[email protected]> -- Balbir ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com _______________________________________________ Libcg-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libcg-devel
