]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: allow --volatile=yes instances of -D /
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Jul 2019 15:32:09 +0000 (17:32 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 29 Jul 2019 07:52:02 +0000 (09:52 +0200)
src/nspawn/nspawn.c

index fed5c651cedfa6c56fd72b23f0143cf98a085898..2542888c1e015027d26d7bb9111c69c266dd67c1 100644 (file)
@@ -4740,8 +4740,12 @@ static int run(int argc, char *argv[]) {
         if (arg_directory) {
                 assert(!arg_image);
 
-                if (path_equal(arg_directory, "/") && !arg_ephemeral) {
-                        log_error("Spawning container on root directory is not supported. Consider using --ephemeral.");
+                /* Safety precaution: let's not allow running images from the live host OS image, as long as
+                 * /var from the host will propagate into container dynamically (because bad things happen if
+                 * two systems write to the same /var). Let's allow it for the special cases where /var is
+                 * either copied (i.e. --ephemeral) or replaced (i.e. --volatile=yes|state). */
+                if (path_equal(arg_directory, "/") && !(arg_ephemeral || IN_SET(arg_volatile_mode, VOLATILE_YES, VOLATILE_STATE))) {
+                        log_error("Spawning container on root directory is not supported. Consider using --ephemeral, --volatile=yes or --volatile=state.");
                         r = -EINVAL;
                         goto finish;
                 }