]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: make use of CHASE_NON_EXISTING when locking image
authorLennart Poettering <lennart@poettering.net>
Tue, 29 Nov 2016 17:16:43 +0000 (18:16 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 30 Nov 2016 23:25:51 +0000 (00:25 +0100)
If --template= is used on an image, then the image might not exist initially.
We can use CHASE_NON_EXISTING to properly lock the image already before it
exists. Let's do so.

src/nspawn/nspawn.c

index 1a625e142e26560a89a16aea55c43feba78a7f02..9a308688e14514f4b50753326dcb575aaeab620f 100644 (file)
@@ -2666,7 +2666,7 @@ static int determine_names(void) {
         return 0;
 }
 
-static int chase_symlinks_and_update(char **p) {
+static int chase_symlinks_and_update(char **p, unsigned flags) {
         char *chased;
         int r;
 
@@ -2675,7 +2675,7 @@ static int chase_symlinks_and_update(char **p) {
         if (!*p)
                 return 0;
 
-        r = chase_symlinks(*p, NULL, 0, &chased);
+        r = chase_symlinks(*p, NULL, flags, &chased);
         if (r < 0)
                 return log_error_errno(r, "Failed to resolve path %s: %m", *p);
 
@@ -4155,7 +4155,7 @@ int main(int argc, char *argv[]) {
                 if (arg_ephemeral) {
                         _cleanup_free_ char *np = NULL;
 
-                        r = chase_symlinks_and_update(&arg_directory);
+                        r = chase_symlinks_and_update(&arg_directory, 0);
                         if (r < 0)
                                 goto finish;
 
@@ -4203,6 +4203,10 @@ int main(int argc, char *argv[]) {
                         remove_directory = true;
 
                 } else {
+                        r = chase_symlinks_and_update(&arg_directory, arg_template ? CHASE_NON_EXISTING : 0);
+                        if (r < 0)
+                                goto finish;
+
                         r = image_path_lock(arg_directory, (arg_read_only ? LOCK_SH : LOCK_EX) | LOCK_NB, &tree_global_lock, &tree_local_lock);
                         if (r == -EBUSY) {
                                 log_error_errno(r, "Directory tree %s is currently busy.", arg_directory);
@@ -4214,7 +4218,7 @@ int main(int argc, char *argv[]) {
                         }
 
                         if (arg_template) {
-                                r = chase_symlinks_and_update(&arg_template);
+                                r = chase_symlinks_and_update(&arg_template, 0);
                                 if (r < 0)
                                         goto finish;
 
@@ -4236,10 +4240,6 @@ 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) {
@@ -4263,7 +4263,7 @@ int main(int argc, char *argv[]) {
                 assert(arg_image);
                 assert(!arg_template);
 
-                r = chase_symlinks_and_update(&arg_image);
+                r = chase_symlinks_and_update(&arg_image, 0);
                 if (r < 0)
                         goto finish;