summaryrefslogtreecommitdiff
path: root/src/nspawn
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-11-24 21:03:36 +0100
committerLennart Poettering <lennart@poettering.net>2016-12-01 00:25:51 +0100
commit3f342ec4b028914fa558855609cd932364558c05 (patch)
treedaf57b02f076b78fcc909ff7fd4a485629ba2038 /src/nspawn
parente187369587b1c6a5f65a12e7ec0bf7844905d014 (diff)
nspawn: properly handle image/directory paths that are symlinks
This resolves any paths specified on --directory=, --template=, and --image= before using them. This makes sure nspawn can be used correctly on symlinked images and directory trees. Fixes: #2001
Diffstat (limited to 'src/nspawn')
-rw-r--r--src/nspawn/nspawn.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 77b6be95e2..7749a460eb 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -2656,6 +2656,25 @@ static int determine_names(void) {
return 0;
}
+static int chase_symlinks_and_update(char **p) {
+ char *chased;
+ int r;
+
+ assert(p);
+
+ if (!*p)
+ return 0;
+
+ r = chase_symlinks(*p, NULL, &chased);
+ if (r < 0)
+ return log_error_errno(r, "Failed to resolve path %s: %m", *p);
+
+ free(*p);
+ *p = chased;
+
+ return 0;
+}
+
static int determine_uid_shift(const char *directory) {
int r;
@@ -4126,6 +4145,10 @@ int main(int argc, char *argv[]) {
if (arg_ephemeral) {
_cleanup_free_ char *np = NULL;
+ r = chase_symlinks_and_update(&arg_directory);
+ if (r < 0)
+ goto finish;
+
/* If the specified path is a mount point we
* generate the new snapshot immediately
* inside it under a random name. However if
@@ -4181,6 +4204,10 @@ int main(int argc, char *argv[]) {
}
if (arg_template) {
+ r = chase_symlinks_and_update(&arg_template);
+ if (r < 0)
+ goto finish;
+
r = btrfs_subvol_snapshot(arg_template, arg_directory,
(arg_read_only ? BTRFS_SNAPSHOT_READ_ONLY : 0) |
BTRFS_SNAPSHOT_FALLBACK_COPY |
@@ -4199,6 +4226,10 @@ int main(int argc, char *argv[]) {
log_info("Populated %s from template %s.", arg_directory, arg_template);
}
}
+
+ r = chase_symlinks_and_update(&arg_directory);
+ if (r < 0)
+ goto finish;
}
if (arg_start_mode == START_BOOT) {
@@ -4222,6 +4253,10 @@ int main(int argc, char *argv[]) {
assert(arg_image);
assert(!arg_template);
+ r = chase_symlinks_and_update(&arg_image);
+ if (r < 0)
+ goto finish;
+
if (arg_ephemeral) {
_cleanup_free_ char *np = NULL;