/* Create an empty cgroup v2 cgroup */
error = _cgroup_create_cgroup(cgroup, NULL, ignore_ownership);
if (error)
+ /*
+ * Since we only attempted to create a single cgroup,
+ * _cgroup_create_cgroup() can capably undo the failure and no
+ * interventions are required here.
+ */
return error;
}
*/
for (i = 0; i < cgroup->index; i++) {
error = _cgroup_create_cgroup(cgroup, cgroup->controller[i], ignore_ownership);
- if (error)
+ if (error) {
+ int del_error;
+
+ /*
+ * This will remove any cgroup directories that were made, but it won't
+ * undo changes that have been written to the parent cgroup's
+ * subtree_control file. To safely undo changes there, we would need to
+ * save the subtree_control file's previous value and restore it.
+ */
+ del_error = cgroup_delete_cgroup(cgroup, 1);
+ if (del_error)
+ cgroup_err("Failed to delete %s: %s\n", cgroup->name,
+ cgroup_strerror(del_error));
return error;
+ }
}
return 0;
#endif
int namespace_enabled = 0;
int mount_enabled = 0;
+ int tmp_errno;
int error;
int ret;
return 0;
err_grp:
+ /*
+ * Save off the error that has already occurred. The errno from
+ * cgroup_config_destroy_groups() is secondary to the original error that was reported,
+ * and thus can be discarded;
+ */
+ tmp_errno = last_errno;
cgroup_config_destroy_groups();
+ last_errno = tmp_errno;
err_mnt:
cgroup_config_unmount_controllers();
cgroup_free_config();