diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-05-21 16:30:58 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-05-21 16:32:01 +0200 |
commit | 03cfe0d51499e86b1573d121337594719d9f2012 (patch) | |
tree | cb76a92a501b16909f879944a4ad29ce88eefbad /src/shared/dev-setup.c | |
parent | ef6fc8ee57eff8a2b612de0270c9a25e066ee290 (diff) |
nspawn: finish user namespace support
Diffstat (limited to 'src/shared/dev-setup.c')
-rw-r--r-- | src/shared/dev-setup.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/shared/dev-setup.c b/src/shared/dev-setup.c index cb15da8a5d..25ad918b85 100644 --- a/src/shared/dev-setup.c +++ b/src/shared/dev-setup.c @@ -23,13 +23,12 @@ #include <stdlib.h> #include <unistd.h> -#include "dev-setup.h" #include "util.h" #include "label.h" +#include "path-util.h" +#include "dev-setup.h" -int dev_setup(const char *prefix) { - const char *j, *k; - +int dev_setup(const char *prefix, uid_t uid, gid_t gid) { static const char symlinks[] = "-/proc/kcore\0" "/dev/core\0" "/proc/self/fd\0" "/dev/fd\0" @@ -37,7 +36,13 @@ int dev_setup(const char *prefix) { "/proc/self/fd/1\0" "/dev/stdout\0" "/proc/self/fd/2\0" "/dev/stderr\0"; + const char *j, *k; + int r; + NULSTR_FOREACH_PAIR(j, k, symlinks) { + _cleanup_free_ char *link_name = NULL; + const char *n; + if (j[0] == '-') { j++; @@ -46,15 +51,21 @@ int dev_setup(const char *prefix) { } if (prefix) { - _cleanup_free_ char *link_name = NULL; - - link_name = strjoin(prefix, "/", k, NULL); + link_name = prefix_root(prefix, k); if (!link_name) return -ENOMEM; - symlink_label(j, link_name); + n = link_name; } else - symlink_label(j, k); + n = k; + + r = symlink_label(j, n); + if (r < 0) + log_debug_errno(r, "Failed to symlink %s to %s: %m", j, n); + + if (uid != UID_INVALID || gid != GID_INVALID) + if (lchown(n, uid, gid) < 0) + log_debug_errno(errno, "Failed to chown %s: %m", n); } return 0; |