nspawn-cgroup.c revision b5efdb8af40ea759a1ea584c1bc44ecc81dd00ce
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2015 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "alloc-util.h"
#include "cgroup-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "mkdir.h"
#include "nspawn-cgroup.h"
#include "string-util.h"
#include "strv.h"
#include "util.h"
const char *fn;
int r;
if (r < 0)
return log_error_errno(r, "Failed to get container cgroup path: %m");
if (r < 0)
return log_error_errno(r, "Failed to get file system path for container cgroup: %m");
if (fd < 0)
".",
"tasks",
"notify_on_release",
"cgroup.procs",
"cgroup.clone_children",
"cgroup.controllers",
"cgroup.subtree_control",
"cgroup.populated")
"Failed to chown() cgroup file %s, ignoring: %m", fn);
return 0;
}
bool undo_mount = false;
const char *fn;
int unified, r;
unified = cg_unified();
if (unified < 0)
if ((unified > 0) == unified_requested)
return 0;
/* When the host uses the legacy cgroup setup, but the
* container shall use the unified hierarchy, let's make sure
* we copy the path from the name=systemd hierarchy into the
* unified hierarchy. Similar for the reverse situation. */
if (r < 0)
/* In order to access the unified hierarchy we need to mount it */
return log_error_errno(errno, "Failed to generate temporary mount point for unified hierarchy: %m");
if (unified)
else
if (r < 0) {
goto finish;
}
undo_mount = true;
if (r < 0)
log_error_errno(r, "Failed to move process: %m");
if (undo_mount)
return r;
}
const char *child;
int unified, r;
/* In the unified hierarchy inner nodes may only only contain
* subgroups, but not processes. Hence, if we running in the
* unified hierarchy and the container does the same, and we
* did not create a scope unit for the container move us and
* the container into two separate subcgroups. */
if (!unified_requested)
return 0;
unified = cg_unified();
if (unified < 0)
if (unified == 0)
return 0;
r = cg_mask_supported(&supported);
if (r < 0)
return log_error_errno(r, "Failed to determine supported controllers: %m");
if (r < 0)
return log_error_errno(r, "Failed to get our control group: %m");
if (r < 0)
if (r < 0)
/* Try to enable as many controllers as possible for the new payload. */
return 0;
}