From c9fe05e07d29e92d0b84211472f252b80d4b4e2f Mon Sep 17 00:00:00 2001 From: Arnaud Rebillout Date: Mon, 21 May 2018 11:10:21 +0700 Subject: [PATCH] nspawn: support pivot-root option during directory validation Signed-off-by: Arnaud Rebillout --- src/nspawn/nspawn.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 762747686a..9cfbb1171e 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -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; - 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 (arg_pivot_root_new) + p = prefix_roota(arg_directory, arg_pivot_root_new); + else + p = arg_directory; + + q = strjoina(p, "/usr/"); + + 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; }