* Sudhir Kumar <[email protected]> [2009-01-02 17:02:05]:

> open may fail in case there is not proper permissions and hence giving
> a wrong result. This patch uses stat instead which is always better.
> 
> Signed-off-by: Sudhir Kumar <[email protected]>
> 
> ---
>  tests/functions.c |   24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> Index: trunk/tests/functions.c
> ===================================================================
> --- trunk.orig/tests/functions.c
> +++ trunk/tests/functions.c
> @@ -238,7 +238,7 @@ void test_cgroup_delete_cgroup(int retco
>               else            /* check group under mountpoint2 */
>                       build_path(path1_group, mountpoint2, name, NULL);
> 
> -             if (group_exist(path1_group) == -1)
> +             if (group_exist(path1_group) == ENOENT)
>                       message(i, PASS, "delete_cgroup()", retval,
>                                                info[GRPDELETEDINFS]);
>               else
> @@ -248,10 +248,10 @@ void test_cgroup_delete_cgroup(int retco
>       } else { /* check group under both mountpoints */
>               /* Check if the group deleted under both controllers */
>               build_path(path1_group, mountpoint, name, NULL);
> -             if (group_exist(path1_group) == -1) {
> +             if (group_exist(path1_group) == ENOENT) {
>                       build_path(path2_group, mountpoint2, name, NULL);
> 
> -                     if (group_exist(path2_group) == -1)
> +                     if (group_exist(path2_group) == ENOENT)
>                               message(i, PASS, "delete_cgroup()",
>                                                retval, info[GRPDELETEDINFS]);
>                       else
> @@ -284,11 +284,21 @@ void get_controllers(const char *name, i
> 
>  int group_exist(char *path_group)
>  {
> +     struct stat statbuf;
>       int ret;
> -     ret = open(path_group, O_DIRECTORY);
> -     if (ret == -1)
> -             return ret;
> -     return 0;
> +     if (stat(path_group, &statbuf) == -1) {
> +             /* Group deleted. OK */
> +             if (errno == ENOENT)
> +                     return ENOENT;
> +             /* There is some other failure */
> +             printf("stat failed, return code is %d\n", errno);
> +             return -1;
> +     }
> +
> +     if (S_ISDIR(statbuf.st_mode))
> +             return 0;
> +     else
> +             return -1;
>  }

OK, so the success criteria is that the path should exist and should
be a directory right?

The change seems reasonable

Acked-by: Balbir Singh <[email protected]>


-- 
        Balbir

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to