]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: added new error code when removing non-empty group.
authorJan Safranek <jsafrane@redhat.com>
Tue, 6 Dec 2011 15:06:50 +0000 (16:06 +0100)
committerJan Safranek <jsafrane@redhat.com>
Fri, 16 Dec 2011 12:51:40 +0000 (13:51 +0100)
ECGNONEMPTY error code is returned by cgroup_delete_cgroup_ext when it
should remove only empty groups, but the group(s) were not empty.

It's not a real error, it's just an indication that some groups were not
removed - it's perfectly valid use case.

Signed-off-by: Jan Safranek <jsafrane@redhat.com>
include/libcgroup/error.h
src/api.c

index a78473a44e95a086c6c9d1856752110e899c6e1b..91b5c1c901a9bfd7b610eb6a2569eae60a752a12 100644 (file)
@@ -75,6 +75,8 @@ enum {
        ECGMOUNTNAMESPACE,
        ECGROUPUNSUPP,
        ECGCANTSETVALUE,
+       /** Removing of a group failed because it was not empty. */
+       ECGNONEMPTY,
 };
 
 /**
index e2d56ef3d2d7d553ac34ef36bbde809f4b9c788f..20ebf84c46befa9459955c603fd52eb229a64ebe 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -118,6 +118,7 @@ const char const *cgroup_strerror_codes[] = {
        "Either mount or namespace keyword has to be specified in the configuration file",
        "This kernel does not support this feature",
        "Value setting does not succeed",
+       "Failed to remove a non-empty group",
 };
 
 static const char const *cgroup_ignored_tasks_files[] = { "tasks", NULL };
@@ -1924,12 +1925,13 @@ static int cg_delete_cgroup_controller(char *cgroup_name, char *controller,
                return ECGROUPSUBSYSNOTMOUNTED;
 
        ret = rmdir(path);
-       if (ret != 0 && errno != ENOENT) {
-               last_errno = errno;
-               return ECGOTHER;
-       }
+       if (ret == 0 || errno == ENOENT)
+               return 0;
+       if (errno == EBUSY)
+               return ECGNONEMPTY;
 
-       return 0;
+       last_errno = errno;
+       return ECGOTHER;
 }
 
 /**
@@ -2130,8 +2132,15 @@ int cgroup_delete_cgroup_ext(struct cgroup *cgroup, int flags)
                 * the group from all of them.
                 */
                if (ret != 0 && first_error == 0) {
-                       first_errno = last_errno;
-                       first_error = ret;
+                       /*
+                        * ECGNONEMPTY is more or less not an error, but an
+                        * indication that something was not removed.
+                        * Therefore it should be replaced by any other error.
+                        */
+                       if (ret != ECGNONEMPTY || first_error == ECGNONEMPTY) {
+                               first_errno = last_errno;
+                               first_error = ret;
+                       }
                }
        }