summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-04-23 08:28:10 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-04-24 00:25:04 -0400
commita6b26d9011de60e1c41f51e8d2aab1d2f7bbf0f5 (patch)
treedaf0eff65c59b6566992b3d4fff94d6205857e16
parent90ae6c0b822bbfd433c801d7945cadcabd1bc1c3 (diff)
Small cleanup
-rw-r--r--src/core/main.c13
-rw-r--r--src/core/mount-setup.c82
2 files changed, 27 insertions, 68 deletions
diff --git a/src/core/main.c b/src/core/main.c
index 6a981a0b7e..ab2ac00d76 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -522,9 +522,6 @@ static void strv_free_free(char ***l) {
}
static void free_join_controllers(void) {
- if (!arg_join_controllers)
- return;
-
strv_free_free(arg_join_controllers);
arg_join_controllers = NULL;
}
@@ -1219,14 +1216,14 @@ static int initialize_join_controllers(void) {
return -ENOMEM;
arg_join_controllers[0] = strv_new("cpu", "cpuacct", NULL);
- if (!arg_join_controllers[0])
- return -ENOMEM;
-
arg_join_controllers[1] = strv_new("net_cls", "net_prio", NULL);
- if (!arg_join_controllers[1])
+ arg_join_controllers[2] = NULL;
+
+ if (!arg_join_controllers[0] || !arg_join_controllers[1]) {
+ free_join_controllers();
return -ENOMEM;
+ }
- arg_join_controllers[2] = NULL;
return 0;
}
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index b841f478c3..4629808a7a 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -211,9 +211,9 @@ int mount_setup_early(void) {
int mount_cgroup_controllers(char ***join_controllers) {
int r;
- FILE *f;
char buf[LINE_MAX];
- Set *controllers;
+ _cleanup_set_free_free_ Set *controllers = NULL;
+ _cleanup_fclose_ FILE *f;
/* Mount all available cgroup controllers that are built into the kernel. */
@@ -224,10 +224,8 @@ int mount_cgroup_controllers(char ***join_controllers) {
}
controllers = set_new(string_hash_func, string_compare_func);
- if (!controllers) {
- r = log_oom();
- goto finish;
- }
+ if (!controllers)
+ return log_oom();
/* Ignore the header line */
(void) fgets(buf, sizeof(buf), f);
@@ -242,8 +240,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
break;
log_error("Failed to parse /proc/cgroups.");
- r = -EIO;
- goto finish;
+ return -EIO;
}
if (!enabled) {
@@ -254,14 +251,19 @@ int mount_cgroup_controllers(char ***join_controllers) {
r = set_consume(controllers, controller);
if (r < 0) {
log_error("Failed to add controller to set.");
- goto finish;
+ return r;
}
}
for (;;) {
- MountPoint p;
- char *controller, *where, *options;
+ MountPoint p = {
+ .what = "cgroup",
+ .type = "cgroup",
+ .flags = MS_NOSUID|MS_NOEXEC|MS_NODEV,
+ .mode = MNT_IN_CONTAINER,
+ };
char ***k = NULL;
+ _cleanup_free_ char *options = NULL, *controller;
controller = set_steal_first(controllers);
if (!controller)
@@ -278,14 +280,13 @@ int mount_cgroup_controllers(char ***join_controllers) {
for (i = *k, j = *k; *i; i++) {
if (!streq(*i, controller)) {
- char *t;
+ char _cleanup_free_ *t;
t = set_remove(controllers, *i);
if (!t) {
free(*i);
continue;
}
- free(t);
}
*(j++) = *i;
@@ -294,75 +295,36 @@ int mount_cgroup_controllers(char ***join_controllers) {
*j = NULL;
options = strv_join(*k, ",");
- if (!options) {
- free(controller);
- r = log_oom();
- goto finish;
- }
-
+ if (!options)
+ return log_oom();
} else {
options = controller;
controller = NULL;
}
- where = strappend("/sys/fs/cgroup/", options);
- if (!where) {
- free(options);
- r = log_oom();
- goto finish;
- }
-
- zero(p);
- p.what = "cgroup";
- p.where = where;
- p.type = "cgroup";
+ p.where = strappenda("/sys/fs/cgroup/", options);
p.options = options;
- p.flags = MS_NOSUID|MS_NOEXEC|MS_NODEV;
- p.mode = MNT_IN_CONTAINER;
r = mount_one(&p, true);
- free(controller);
- free(where);
-
- if (r < 0) {
- free(options);
- goto finish;
- }
+ if (r < 0)
+ return r;
if (r > 0 && k && *k) {
char **i;
for (i = *k; *i; i++) {
- _cleanup_free_ char *t;
-
- t = strappend("/sys/fs/cgroup/", *i);
- if (!t) {
- r = log_oom();
- free(options);
- goto finish;
- }
+ char *t = strappenda("/sys/fs/cgroup/", *i);
r = symlink(options, t);
if (r < 0 && errno != EEXIST) {
log_error("Failed to create symlink %s: %m", t);
- r = -errno;
- free(options);
- goto finish;
+ return -errno;
}
}
}
-
- free(options);
}
- r = 0;
-
-finish:
- set_free_free(controllers);
-
- fclose(f);
-
- return r;
+ return 0;
}
static int nftw_cb(