Small cleanup

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2013-04-23 08:28:10 -04:00
parent 90ae6c0b82
commit a6b26d9011
2 changed files with 28 additions and 69 deletions

View file

@ -522,9 +522,6 @@ static void strv_free_free(char ***l) {
} }
static void free_join_controllers(void) { static void free_join_controllers(void) {
if (!arg_join_controllers)
return;
strv_free_free(arg_join_controllers); strv_free_free(arg_join_controllers);
arg_join_controllers = NULL; arg_join_controllers = NULL;
} }
@ -1219,14 +1216,14 @@ static int initialize_join_controllers(void) {
return -ENOMEM; return -ENOMEM;
arg_join_controllers[0] = strv_new("cpu", "cpuacct", NULL); 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); arg_join_controllers[1] = strv_new("net_cls", "net_prio", NULL);
if (!arg_join_controllers[1])
return -ENOMEM;
arg_join_controllers[2] = NULL; arg_join_controllers[2] = NULL;
if (!arg_join_controllers[0] || !arg_join_controllers[1]) {
free_join_controllers();
return -ENOMEM;
}
return 0; return 0;
} }

View file

@ -211,9 +211,9 @@ int mount_setup_early(void) {
int mount_cgroup_controllers(char ***join_controllers) { int mount_cgroup_controllers(char ***join_controllers) {
int r; int r;
FILE *f;
char buf[LINE_MAX]; 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. */ /* 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); controllers = set_new(string_hash_func, string_compare_func);
if (!controllers) { if (!controllers)
r = log_oom(); return log_oom();
goto finish;
}
/* Ignore the header line */ /* Ignore the header line */
(void) fgets(buf, sizeof(buf), f); (void) fgets(buf, sizeof(buf), f);
@ -242,8 +240,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
break; break;
log_error("Failed to parse /proc/cgroups."); log_error("Failed to parse /proc/cgroups.");
r = -EIO; return -EIO;
goto finish;
} }
if (!enabled) { if (!enabled) {
@ -254,14 +251,19 @@ int mount_cgroup_controllers(char ***join_controllers) {
r = set_consume(controllers, controller); r = set_consume(controllers, controller);
if (r < 0) { if (r < 0) {
log_error("Failed to add controller to set."); log_error("Failed to add controller to set.");
goto finish; return r;
} }
} }
for (;;) { for (;;) {
MountPoint p; MountPoint p = {
char *controller, *where, *options; .what = "cgroup",
.type = "cgroup",
.flags = MS_NOSUID|MS_NOEXEC|MS_NODEV,
.mode = MNT_IN_CONTAINER,
};
char ***k = NULL; char ***k = NULL;
_cleanup_free_ char *options = NULL, *controller;
controller = set_steal_first(controllers); controller = set_steal_first(controllers);
if (!controller) if (!controller)
@ -278,14 +280,13 @@ int mount_cgroup_controllers(char ***join_controllers) {
for (i = *k, j = *k; *i; i++) { for (i = *k, j = *k; *i; i++) {
if (!streq(*i, controller)) { if (!streq(*i, controller)) {
char *t; char _cleanup_free_ *t;
t = set_remove(controllers, *i); t = set_remove(controllers, *i);
if (!t) { if (!t) {
free(*i); free(*i);
continue; continue;
} }
free(t);
} }
*(j++) = *i; *(j++) = *i;
@ -294,75 +295,36 @@ int mount_cgroup_controllers(char ***join_controllers) {
*j = NULL; *j = NULL;
options = strv_join(*k, ","); options = strv_join(*k, ",");
if (!options) { if (!options)
free(controller); return log_oom();
r = log_oom();
goto finish;
}
} else { } else {
options = controller; options = controller;
controller = NULL; controller = NULL;
} }
where = strappend("/sys/fs/cgroup/", options); p.where = strappenda("/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.options = options; p.options = options;
p.flags = MS_NOSUID|MS_NOEXEC|MS_NODEV;
p.mode = MNT_IN_CONTAINER;
r = mount_one(&p, true); r = mount_one(&p, true);
free(controller); if (r < 0)
free(where); return r;
if (r < 0) {
free(options);
goto finish;
}
if (r > 0 && k && *k) { if (r > 0 && k && *k) {
char **i; char **i;
for (i = *k; *i; i++) { for (i = *k; *i; i++) {
_cleanup_free_ char *t; char *t = strappenda("/sys/fs/cgroup/", *i);
t = strappend("/sys/fs/cgroup/", *i);
if (!t) {
r = log_oom();
free(options);
goto finish;
}
r = symlink(options, t); r = symlink(options, t);
if (r < 0 && errno != EEXIST) { if (r < 0 && errno != EEXIST) {
log_error("Failed to create symlink %s: %m", t); log_error("Failed to create symlink %s: %m", t);
r = -errno; return -errno;
free(options);
goto finish;
} }
} }
} }
free(options);
} }
r = 0; return 0;
finish:
set_free_free(controllers);
fclose(f);
return r;
} }
static int nftw_cb( static int nftw_cb(