summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-06-14 15:50:19 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-06-16 17:06:56 -0400
commit9fa8446392a8dfdf7e941ad4d25b4e5543e554c8 (patch)
treeea201ad77772e5769353bbf6b4482dce7cd84ef4
parent52196e0b58ee0a8e78991862d49f49c7d7482d15 (diff)
nspawn: Merge chown_cgroup(), sync_cgroup(), and create_subcgroup() into one cgroup_setup()
-rw-r--r--src/nspawn/nspawn-cgroup.c26
-rw-r--r--src/nspawn/nspawn-cgroup.h4
-rw-r--r--src/nspawn/nspawn.c12
3 files changed, 25 insertions, 17 deletions
diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c
index 38a273f42a..5afd2bd062 100644
--- a/src/nspawn/nspawn-cgroup.c
+++ b/src/nspawn/nspawn-cgroup.c
@@ -59,7 +59,7 @@ static int chown_cgroup_path(const char *path, uid_t uid_shift) {
return 0;
}
-int chown_cgroup(pid_t pid, uid_t uid_shift) {
+static int chown_cgroup(pid_t pid, uid_t uid_shift) {
_cleanup_free_ char *path = NULL, *fs = NULL;
int r;
@@ -78,7 +78,7 @@ int chown_cgroup(pid_t pid, uid_t uid_shift) {
return 0;
}
-int sync_cgroup(pid_t pid, CGroupUnified outer_cgver, CGroupUnified inner_cgver, uid_t uid_shift) {
+static int sync_cgroup(pid_t pid, CGroupUnified outer_cgver, CGroupUnified inner_cgver, uid_t uid_shift) {
_cleanup_free_ char *cgroup = NULL;
char tree[] = "/tmp/unifiedXXXXXX", pid_string[DECIMAL_STR_MAX(pid) + 1];
bool undo_mount = false;
@@ -144,7 +144,7 @@ finish:
return r;
}
-int create_subcgroup(pid_t pid, CGroupUnified outer_cgver, CGroupUnified inner_cgver) {
+static int create_subcgroup(pid_t pid, CGroupUnified outer_cgver, CGroupUnified inner_cgver) {
_cleanup_free_ char *cgroup = NULL;
const char *child;
int r;
@@ -182,6 +182,26 @@ int create_subcgroup(pid_t pid, CGroupUnified outer_cgver, CGroupUnified inner_c
return 0;
}
+int cgroup_setup(pid_t pid, CGroupUnified outer_cgver, CGroupUnified inner_cgver, uid_t uid_shift, bool keep_unit) {
+ int r;
+
+ r = sync_cgroup(pid, outer_cgver, inner_cgver, uid_shift);
+ if (r < 0)
+ return r;
+
+ if (keep_unit) {
+ r = create_subcgroup(pid, outer_cgver, inner_cgver);
+ if (r < 0)
+ return r;
+ }
+
+ r = chown_cgroup(pid, uid_shift);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
/********************************************************************/
/* Retrieve existing subsystems. This function is called in a new cgroup
diff --git a/src/nspawn/nspawn-cgroup.h b/src/nspawn/nspawn-cgroup.h
index d0e70b5172..b141c4e5d3 100644
--- a/src/nspawn/nspawn-cgroup.h
+++ b/src/nspawn/nspawn-cgroup.h
@@ -24,9 +24,7 @@
#include "cgroup-util.h"
-int chown_cgroup(pid_t pid, uid_t uid_shift);
-int sync_cgroup(pid_t pid, CGroupUnified outer_cgver, CGroupUnified inner_cgver, uid_t uid_shift);
-int create_subcgroup(pid_t pid, CGroupUnified outer_cgver, CGroupUnified inner_cgver);
+int cgroup_setup(pid_t pid, CGroupUnified outer_cgver, CGroupUnified inner_cgver, uid_t uid_shift, bool keep_unit);
int mount_cgroups(const char *dest, CGroupUnified outer_cgver, CGroupUnified inner_cgver, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context, bool use_cgns);
int mount_systemd_cgroup_writable(const char *dest, CGroupUnified inner_cgver);
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index be1b054045..d3ef37fba3 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -3875,17 +3875,7 @@ static int run(int master,
return r;
}
- r = sync_cgroup(*pid, outer_cgver, arg_unified_cgroup_hierarchy, arg_uid_shift);
- if (r < 0)
- return r;
-
- if (arg_keep_unit) {
- r = create_subcgroup(*pid, outer_cgver, arg_unified_cgroup_hierarchy);
- if (r < 0)
- return r;
- }
-
- r = chown_cgroup(*pid, arg_uid_shift);
+ r = cgroup_setup(*pid, outer_cgver, arg_unified_cgroup_hierarchy, arg_uid_shift, arg_keep_unit);
if (r < 0)
return r;