nspawn: support pivot-root option during directory validation
authorArnaud Rebillout <arnaud.rebillout@collabora.com>
Mon, 21 May 2018 04:10:21 +0000 (11:10 +0700)
committerLennart Poettering <lennart@poettering.net>
Tue, 22 May 2018 12:42:10 +0000 (14:42 +0200)
Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
src/nspawn/nspawn.c

index 7627476..9cfbb11 100644 (file)
@@ -4194,17 +4194,30 @@ int main(int argc, char *argv[]) {
                 }
 
                 if (arg_start_mode == START_BOOT) {
-                        if (path_is_os_tree(arg_directory) <= 0) {
-                                log_error("Directory %s doesn't look like an OS root directory (os-release file is missing). Refusing.", arg_directory);
+                       const char *p;
+
+                       if (arg_pivot_root_new)
+                               p = prefix_roota(arg_directory, arg_pivot_root_new);
+                       else
+                               p = arg_directory;
+
+                        if (path_is_os_tree(p) <= 0) {
+                                log_error("Directory %s doesn't look like an OS root directory (os-release file is missing). Refusing.", p);
                                 r = -EINVAL;
                                 goto finish;
                         }
                 } else {
-                        const char *p;
+                        const char *p, *q;
+
+                       if (arg_pivot_root_new)
+                               p = prefix_roota(arg_directory, arg_pivot_root_new);
+                       else
+                               p = arg_directory;
+
+                        q = strjoina(p, "/usr/");
 
-                        p = strjoina(arg_directory, "/usr/");
-                        if (laccess(p, F_OK) < 0) {
-                                log_error("Directory %s doesn't look like it has an OS tree. Refusing.", arg_directory);
+                        if (laccess(q, F_OK) < 0) {
+                                log_error("Directory %s doesn't look like it has an OS tree. Refusing.", p);
                                 r = -EINVAL;
                                 goto finish;
                         }