cgroup: rearrange code blocks

Avoid nesting and improve readability.

Signed-off-by: David Ward <david.ward@ll.mit.edu>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
David Ward 2012-05-04 00:50:15 +02:00 committed by Daniel Lezcano
parent f10e7166ab
commit ad08bbb704

View File

@ -157,6 +157,7 @@ static int get_cgroup_mount(const char *subsystem, char *mnt)
struct mntent *mntent; struct mntent *mntent;
char initcgroup[MAXPATHLEN]; char initcgroup[MAXPATHLEN];
FILE *file = NULL; FILE *file = NULL;
int ret, flags, err = -1;
file = setmntent(MTAB, "r"); file = setmntent(MTAB, "r");
if (!file) { if (!file) {
@ -165,32 +166,29 @@ static int get_cgroup_mount(const char *subsystem, char *mnt)
} }
while ((mntent = getmntent(file))) { while ((mntent = getmntent(file))) {
if (strcmp(mntent->mnt_type, "cgroup")) if (strcmp(mntent->mnt_type, "cgroup"))
continue; continue;
if (!subsystem || hasmntopt_multiple(mntent, subsystem)) { if (subsystem && !hasmntopt_multiple(mntent, subsystem))
int ret; continue;
int flags = get_cgroup_flags(mntent);
ret = snprintf(mnt, MAXPATHLEN, "%s%s%s", flags = get_cgroup_flags(mntent);
mntent->mnt_dir, ret = snprintf(mnt, MAXPATHLEN, "%s%s%s", mntent->mnt_dir,
get_init_cgroup(subsystem, NULL, get_init_cgroup(subsystem, NULL, initcgroup),
initcgroup),
(flags & CGROUP_NS_CGROUP) ? "" : "/lxc"); (flags & CGROUP_NS_CGROUP) ? "" : "/lxc");
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= MAXPATHLEN)
goto fail; goto fail;
fclose(file);
DEBUG("using cgroup mounted at '%s'", mnt); DEBUG("using cgroup mounted at '%s'", mnt);
return 0; err = 0;
} goto out;
}; };
fail: fail:
DEBUG("Failed to find cgroup for %s\n", DEBUG("Failed to find cgroup for %s\n",
subsystem ? subsystem : "(NULL)"); subsystem ? subsystem : "(NULL)");
out:
fclose(file); endmntent(file);
return err;
return -1;
} }
int lxc_ns_is_mounted(void) int lxc_ns_is_mounted(void)
@ -409,10 +407,10 @@ int lxc_cgroup_create(const char *name, pid_t pid)
} }
while ((mntent = getmntent(file))) { while ((mntent = getmntent(file))) {
DEBUG("checking '%s' (%s)", mntent->mnt_dir, mntent->mnt_type); DEBUG("checking '%s' (%s)", mntent->mnt_dir, mntent->mnt_type);
if (!strcmp(mntent->mnt_type, "cgroup")) { if (strcmp(mntent->mnt_type, "cgroup"))
continue;
INFO("[%d] found cgroup mounted at '%s',opts='%s'", INFO("[%d] found cgroup mounted at '%s',opts='%s'",
++found, mntent->mnt_dir, mntent->mnt_opts); ++found, mntent->mnt_dir, mntent->mnt_opts);
@ -420,7 +418,6 @@ int lxc_cgroup_create(const char *name, pid_t pid)
err = lxc_one_cgroup_create(name, mntent, pid); err = lxc_one_cgroup_create(name, mntent, pid);
if (err) if (err)
goto out; goto out;
}
}; };
if (!found) if (!found)
@ -498,7 +495,7 @@ int lxc_cgroup_destroy(const char *name)
{ {
struct mntent *mntent; struct mntent *mntent;
FILE *file = NULL; FILE *file = NULL;
int ret, err = -1; int err = -1;
file = setmntent(MTAB, "r"); file = setmntent(MTAB, "r");
if (!file) { if (!file) {
@ -507,18 +504,15 @@ int lxc_cgroup_destroy(const char *name)
} }
while ((mntent = getmntent(file))) { while ((mntent = getmntent(file))) {
if (!strcmp(mntent->mnt_type, "cgroup")) { if (strcmp(mntent->mnt_type, "cgroup"))
ret = lxc_one_cgroup_destroy(mntent, name); continue;
if (ret) {
fclose(file); err = lxc_one_cgroup_destroy(mntent, name);
return ret; if (err)
} break;
err = 0;
}
} }
fclose(file); endmntent(file);
return err; return err;
} }
/* /*