From: Jan Safranek Date: Tue, 6 Dec 2011 15:06:50 +0000 (+0100) Subject: libcgroup: added new error code when removing non-empty group. X-Git-Tag: v0.38~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4660e8c812cdfa508eaf429e435a5cc878a53c9c;p=thirdparty%2Flibcgroup.git libcgroup: added new error code when removing non-empty group. 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 --- diff --git a/include/libcgroup/error.h b/include/libcgroup/error.h index a78473a4..91b5c1c9 100644 --- a/include/libcgroup/error.h +++ b/include/libcgroup/error.h @@ -75,6 +75,8 @@ enum { ECGMOUNTNAMESPACE, ECGROUPUNSUPP, ECGCANTSETVALUE, + /** Removing of a group failed because it was not empty. */ + ECGNONEMPTY, }; /** diff --git a/src/api.c b/src/api.c index e2d56ef3..20ebf84c 100644 --- 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; + } } }