On 06/15/2009 05:21 PM, Dhaval Giani wrote:
> 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]>
> Acked-by: Balbir Singh<[email protected]>
> Acked-by: Bharata B Rao<[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      2009-06-15 16:19:48.000000000 +0530
> +++ libcg/src/api.c   2009-06-15 16:20:51.000000000 +0530
> @@ -2194,7 +2194,7 @@
>
>
>   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;
>
> @@ -2218,12 +2218,15 @@
>               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;
> @@ -2254,7 +2257,9 @@
>               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;
>   }
> @@ -2308,6 +2313,8 @@
>               return ECGOTHER;
>       }
>
> +     entry->flags |= CGROUP_WALK_TYPE_PRE_DIR;
> +
>       *base_level = 0;
>       cg_path[0] = full_path;
>       cg_path[1] = NULL;
> @@ -2321,7 +2328,9 @@
>       }
>       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);

Warning: passing argument 3 of ‘cg_walk_node’ makes integer from pointer 
without a cast

> +
>       *handle = entry;
>       return ret;
>   }
> Index: libcg/tests/walk_test.c
> ===================================================================
> --- libcg.orig/tests/walk_test.c      2009-05-18 15:34:44.000000000 +0530
> +++ libcg/tests/walk_test.c   2009-06-15 16:20:51.000000000 +0530
> @@ -41,6 +41,7 @@
>               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 @@
>       }
>       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      2009-06-15 14:27:39.000000000 +0530
> +++ libcg/src/libcgroup.map   2009-06-15 16:20:51.000000000 +0530
> @@ -62,6 +62,7 @@
>       cgroup_read_stats_begin;
>       cgroup_read_stats_next;
>       cgroup_read_stats_end;
> +     cgroup_walk_tree_set_flags;
>       cgroup_get_controller;
>       cgroup_get_uid_gid_from_procfs;
>   } CGROUP_0.33;
>
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> Libcg-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/libcg-devel
>


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to