namespace.c revision c2c13f2df42e0691aecabe3979ea81cd7faa35c7
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync This file is part of systemd.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Copyright 2010 Lennart Poettering
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync systemd is free software; you can redistribute it and/or modify it
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync under the terms of the GNU Lesser General Public License as published by
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync the Free Software Foundation; either version 2.1 of the License, or
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (at your option) any later version.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync systemd is distributed in the hope that it will be useful, but
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync WITHOUT ANY WARRANTY; without even the implied warranty of
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Lesser General Public License for more details.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync You should have received a copy of the GNU Lesser General Public License
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync along with systemd; If not, see <http://www.gnu.org/licenses/>.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef enum MountMode {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /* This is ordered by priority! */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef struct BindMount {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *path;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int append_mounts(BindMount **p, char **strv, MountMode mode) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (*p)->ignore = false;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((mode == INACCESSIBLE || mode == READONLY || mode == READWRITE) && (*i)[0] == '-') {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (*p)->ignore = true;
(*p)->path = *i;
static int mount_path_compare(const void *a, const void *b) {
const BindMount *p = a, *q = b;
assert(m);
assert(n);
previous = t;
static const char devnodes[] =
const char *d, *dev = NULL, *devpts = NULL, *devshm = NULL, *devkdbus = NULL, *devhugepages = NULL, *devmqueue = NULL;
assert(m);
u = umask(0000);
return -errno;
r = -errno;
goto fail;
r = -errno;
goto fail;
r = -errno;
goto fail;
r = -errno;
goto fail;
r = -EINVAL;
goto fail;
if (!dn) {
r = -ENOMEM;
goto fail;
r = -errno;
goto fail;
r = -errno;
goto fail;
fail:
if (devpts)
if (devshm)
if (devkdbus)
if (devhugepages)
if (devmqueue)
if (dev) {
static int apply_mount(
BindMount *m,
const char *tmp_dir,
const char *var_tmp_dir) {
const char *what;
assert(m);
switch (m->mode) {
case PRIVATE_DEV:
return mount_dev(m);
case INACCESSIBLE:
case READONLY:
case READWRITE:
case PRIVATE_TMP:
case PRIVATE_VAR_TMP:
assert(m);
return -errno;
int setup_namespace(
char** read_write_dirs,
char** read_only_dirs,
char** inaccessible_dirs,
char* tmp_dir,
char* var_tmp_dir,
bool private_dev,
unsigned mount_flags) {
if (mount_flags == 0)
return -errno;
if (tmp_dir) {
if (var_tmp_dir) {
if (private_dev) {
return -errno;
goto fail;
r = make_read_only(m);
goto fail;
r = -errno;
goto fail;
fail:
if (m->done)
x = strjoin(prefix, "/systemd-private-", sd_id128_to_string(boot_id, bid), "-", id, "-XXXXXX", NULL);
return -ENOMEM;
if (!mkdtemp(x))
return -errno;
RUN_WITH_UMASK(0000) {
return -errno;
*path = x;
x = NULL;
rmdir(t);
rmdir(a);
free(a);
*tmp_dir = a;
*var_tmp_dir = b;
} control = {};
return -errno;
r = -errno;
goto fail;
r = -errno;
goto fail;
if (netns < 0) {
r = -errno;
goto fail;
r = -errno;
goto fail;
r = -errno;
goto fail;
fail: