]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgrouptest: open may fail wrt permissions, so use stat
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Fri, 9 Jan 2009 16:30:28 +0000 (16:30 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Fri, 9 Jan 2009 16:30:28 +0000 (16:30 +0000)
From: Sudhir Kumar <skumar@linux.vnet.ibm.com>

The patch was adding a warning
"test_functions.c:359: warning: unused variable ‘ret’"
Hence resending correcting it.

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 <skumar@linux.vnet.ibm.com>
Acked-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@312 4f4bb910-9a46-0410-90c8-c897d4f1cd53

tests/test_functions.c

index fcdd308ac88bf47686fa93a9d32b6d39df0feb87..6af9efdf934b0443adf5545f123fe4a64b3e7b97 100644 (file)
@@ -288,7 +288,7 @@ void test_cgroup_delete_cgroup(int retcode, struct cgroup *cgrp,
                        /* 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
@@ -299,10 +299,10 @@ void test_cgroup_delete_cgroup(int retcode, struct cgroup *cgrp,
                /* check group under both mountpoints */
                /* Check if the group deleted under both mountpoints */
                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
@@ -347,11 +347,20 @@ void get_controllers(const char *name, int *exist)
  */
 int group_exist(char *path_group)
 {
-       int ret;
-       ret = open(path_group, O_DIRECTORY);
-       if (ret == -1)
-               return ret;
-       return 0;
+       struct stat statbuf;
+       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;
 }
 
 /**