return 0;
}
-static void trim(char *s)
+static char *trim(char *s)
{
size_t len;
len = strlen(s);
while ((len > 1) && (s[len - 1] == '\n'))
s[--len] = '\0';
+
+ return s;
}
static void lxc_cgfsng_print_hierarchies(struct cgroup_ops *ops)
const char *root, int type)
{
__do_free char *cgroup_root = NULL;
+ bool has_cgns = false, wants_force_mount = false;
int ret;
- bool has_cgns = false, retval = false, wants_force_mount = false;
if (!ops)
return ret_set_errno(false, ENOENT);
cgroup_root = must_make_path(root, DEFAULT_CGROUP_MOUNTPOINT, NULL);
if (ops->cgroup_layout == CGROUP_LAYOUT_UNIFIED) {
if (has_cgns && wants_force_mount) {
- /* If cgroup namespaces are supported but the container
+ /*
+ * If cgroup namespaces are supported but the container
* will not have CAP_SYS_ADMIN after it has started we
* need to mount the cgroups manually.
*/
- return cg_mount_in_cgroup_namespace(type, ops->unified,
- cgroup_root) == 0;
+ return cg_mount_in_cgroup_namespace(type, ops->unified, cgroup_root) == 0;
}
return cg_mount_cgroup_full(type, ops->unified, cgroup_root) == 0;
MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME,
"size=10240k,mode=755", root);
if (ret < 0)
- goto on_error;
+ return false;
for (int i = 0; ops->hierarchies[i]; i++) {
__do_free char *controllerpath = NULL, *path2 = NULL;
continue;
ret = mkdir(controllerpath, 0755);
- if (ret < 0) {
- ERROR("Error creating cgroup path: %s", controllerpath);
- goto on_error;
- }
+ if (ret < 0)
+ return log_error_errno(false, errno, "Error creating cgroup path: %s", controllerpath);
if (has_cgns && wants_force_mount) {
/* If cgroup namespaces are supported but the container
*/
ret = cg_mount_in_cgroup_namespace(type, h, controllerpath);
if (ret < 0)
- goto on_error;
+ return false;
continue;
}
ret = cg_mount_cgroup_full(type, h, controllerpath);
if (ret < 0)
- goto on_error;
+ return false;
if (!cg_mount_needs_subdirs(type))
continue;
ops->container_cgroup, NULL);
ret = mkdir_p(path2, 0755);
if (ret < 0)
- goto on_error;
+ return false;
ret = cg_legacy_mount_controllers(type, h, controllerpath,
path2, ops->container_cgroup);
if (ret < 0)
- goto on_error;
+ return false;
}
- retval = true;
-on_error:
- return retval;
+ return true;
}
/* Only root needs to escape to the cgroup of its init. */
static char *cg_unified_get_current_cgroup(bool relative)
{
__do_free char *basecginfo = NULL;
+ char *copy;
char *base_cgroup;
- char *copy = NULL;
if (!relative && (geteuid() == 0))
basecginfo = read_file("/proc/1/cgroup");
base_cgroup = strstr(basecginfo, "0::/");
if (!base_cgroup)
- goto cleanup_on_err;
+ return NULL;
base_cgroup = base_cgroup + 3;
copy = copy_to_eol(base_cgroup);
if (!copy)
- goto cleanup_on_err;
-
-cleanup_on_err:
- if (copy)
- trim(copy);
+ return NULL;
- return copy;
+ return trim(copy);
}
static int cg_unified_init(struct cgroup_ops *ops, bool relative,