cgroups: try to handle layouts with no cgroups

Cc: Ondrej Kubik <ondrej.kubik@canonical.com> Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 2fa5dff9
......@@ -1108,6 +1108,9 @@ __cgfsng_ops static void cgfsng_payload_destroy(struct cgroup_ops *ops,
int ret;
struct generic_userns_exec_data wrap;
if (!ops->hierarchies)
return;
wrap.origuid = 0;
wrap.container_cgroup = ops->container_cgroup;
wrap.hierarchies = ops->hierarchies;
......@@ -1376,6 +1379,9 @@ __cgfsng_ops static inline bool cgfsng_monitor_create(struct cgroup_ops *ops,
if (!conf)
return bret;
if (!ops->hierarchies)
return true;
if (conf->cgroup_meta.dir)
tmp = lxc_string_join("/",
(const char *[]){conf->cgroup_meta.dir,
......@@ -1442,6 +1448,9 @@ __cgfsng_ops static inline bool cgfsng_payload_create(struct cgroup_ops *ops,
if (!conf)
return false;
if (!ops->hierarchies)
return true;
if (conf->cgroup_meta.dir)
tmp = lxc_string_join("/", (const char *[]){conf->cgroup_meta.dir, handler->name, NULL}, false);
else
......@@ -1505,6 +1514,9 @@ __cgfsng_ops static bool __do_cgroup_enter(struct cgroup_ops *ops, pid_t pid,
int len;
char pidstr[INTTYPE_TO_STRLEN(pid_t)];
if (!ops->hierarchies)
return true;
len = snprintf(pidstr, sizeof(pidstr), "%d", pid);
if (len < 0 || (size_t)len >= sizeof(pidstr))
return false;
......@@ -1648,6 +1660,9 @@ __cgfsng_ops static bool cgfsng_chown(struct cgroup_ops *ops,
if (lxc_list_empty(&conf->id_map))
return true;
if (!ops->hierarchies)
return true;
wrap.origuid = geteuid();
wrap.path = NULL;
wrap.hierarchies = ops->hierarchies;
......@@ -1798,6 +1813,9 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
char *tmpfspath = NULL;
bool has_cgns = false, retval = false, wants_force_mount = false;
if (!ops->hierarchies)
return true;
if ((type & LXC_AUTO_CGROUP_MASK) == 0)
return true;
......@@ -1961,7 +1979,7 @@ __cgfsng_ops static bool cgfsng_escape(const struct cgroup_ops *ops,
{
int i;
if (conf->cgroup_meta.relative || geteuid())
if (conf->cgroup_meta.relative || geteuid() || !ops->hierarchies)
return true;
for (i = 0; ops->hierarchies[i]; i++) {
......@@ -1985,9 +2003,12 @@ __cgfsng_ops static bool cgfsng_escape(const struct cgroup_ops *ops,
__cgfsng_ops static int cgfsng_num_hierarchies(struct cgroup_ops *ops)
{
int i;
int i = 0;
if (!ops->hierarchies)
return 0;
for (i = 0; ops->hierarchies[i]; i++)
for (; ops->hierarchies[i]; i++)
;
return i;
......@@ -1997,6 +2018,9 @@ __cgfsng_ops static bool cgfsng_get_hierarchies(struct cgroup_ops *ops, int n, c
{
int i;
if (!ops->hierarchies)
return false;
/* sanity check n */
for (i = 0; i < n; i++)
if (!ops->hierarchies[i])
......@@ -2138,6 +2162,9 @@ __cgfsng_ops static bool cgfsng_attach(struct cgroup_ops *ops, const char *name,
int i, len, ret;
char pidstr[INTTYPE_TO_STRLEN(pid_t)];
if (!ops->hierarchies)
return true;
len = snprintf(pidstr, sizeof(pidstr), "%d", pid);
if (len < 0 || (size_t)len >= sizeof(pidstr))
return false;
......@@ -2387,6 +2414,9 @@ static bool __cg_legacy_setup_limits(struct cgroup_ops *ops,
if (lxc_list_empty(cgroup_settings))
return true;
if (!ops->hierarchies)
return false;
sorted_cgroup_settings = sort_cgroup_settings(cgroup_settings);
if (!sorted_cgroup_settings)
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment