summaryrefslogtreecommitdiffstats
path: root/src/nspawn/nspawn-mount.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-12-12 17:05:21 +0100
committerLennart Poettering <lennart@poettering.net>2019-12-13 15:11:38 +0100
commitd0556c55e7b66087898dfe8440517177081c2885 (patch)
treec8f15d76abdc1210875472e30edf9d38b5a15b4f /src/nspawn/nspawn-mount.c
parentMerge pull request #14333 from poettering/markdown-header-fixes (diff)
downloadsystemd-d0556c55e7b66087898dfe8440517177081c2885.tar.xz
systemd-d0556c55e7b66087898dfe8440517177081c2885.zip
nspawn: fix overlay with automatic temporary tree
This makes --overlay=+/foobar::/foobar work again, i.e. where the middle parameter is left out. According to the documentation this is supposed to generate a temporary writable work place in the midle. But it apparently never did. Weird.
Diffstat (limited to '')
-rw-r--r--src/nspawn/nspawn-mount.c58
1 files changed, 41 insertions, 17 deletions
diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c
index fa3bf77b0e..0fb83a4ff3 100644
--- a/src/nspawn/nspawn-mount.c
+++ b/src/nspawn/nspawn-mount.c
@@ -102,6 +102,30 @@ static char *resolve_source_path(const char *dest, const char *source) {
return strdup(source);
}
+static int allocate_temporary_source(CustomMount *m) {
+ assert(m);
+ assert(!m->source);
+ assert(!m->rm_rf_tmpdir);
+
+ m->rm_rf_tmpdir = strdup("/var/tmp/nspawn-temp-XXXXXX");
+ if (!m->rm_rf_tmpdir)
+ return log_oom();
+
+ if (!mkdtemp(m->rm_rf_tmpdir)) {
+ m->rm_rf_tmpdir = mfree(m->rm_rf_tmpdir);
+ return log_error_errno(errno, "Failed to acquire temporary directory: %m");
+ }
+
+ m->source = path_join(m->rm_rf_tmpdir, "src");
+ if (!m->source)
+ return log_oom();
+
+ if (mkdir(m->source, 0755) < 0)
+ return log_error_errno(errno, "Failed to create %s: %m", m->source);
+
+ return 0;
+}
+
int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n) {
size_t i;
int r;
@@ -136,21 +160,9 @@ int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n) {
} else {
/* No source specified? In that case, use a throw-away temporary directory in /var/tmp */
- m->rm_rf_tmpdir = strdup("/var/tmp/nspawn-temp-XXXXXX");
- if (!m->rm_rf_tmpdir)
- return log_oom();
-
- if (!mkdtemp(m->rm_rf_tmpdir)) {
- m->rm_rf_tmpdir = mfree(m->rm_rf_tmpdir);
- return log_error_errno(errno, "Failed to acquire temporary directory: %m");
- }
-
- m->source = path_join(m->rm_rf_tmpdir, "src");
- if (!m->source)
- return log_oom();
-
- if (mkdir(m->source, 0755) < 0)
- return log_error_errno(errno, "Failed to create %s: %m", m->source);
+ r = allocate_temporary_source(m);
+ if (r < 0)
+ return r;
}
}
@@ -167,6 +179,20 @@ int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n) {
free_and_replace(*j, s);
}
+ if (m->source) {
+ char *s;
+
+ s = resolve_source_path(dest, m->source);
+ if (!s)
+ return log_oom();
+
+ free_and_replace(m->source, s);
+ } else {
+ r = allocate_temporary_source(m);
+ if (r < 0)
+ return r;
+ }
+
if (m->work_dir) {
char *s;
@@ -176,8 +202,6 @@ int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n) {
free_and_replace(m->work_dir, s);
} else {
- assert(m->source);
-
r = tempfn_random(m->source, NULL, &m->work_dir);
if (r < 0)
return log_error_errno(r, "Failed to acquire working directory: %m");