From: Lennart Poettering Date: Thu, 17 Mar 2022 09:31:55 +0000 (+0100) Subject: nspawn: if we refuse to operate on some directory, explain why X-Git-Tag: v251-rc1~125^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aff7ae0d67e0cd4b3c60e043ea9112d3c2972fce;p=thirdparty%2Fsystemd.git nspawn: if we refuse to operate on some directory, explain why (Also, some refactoring to use safer path_join()) --- diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 1a654d88171..a185585b502 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -5612,31 +5612,36 @@ static int run(int argc, char *argv[]) { } if (arg_start_mode == START_BOOT) { + _cleanup_free_ char *b = NULL; const char *p; - if (arg_pivot_root_new) - p = prefix_roota(arg_directory, arg_pivot_root_new); - else + if (arg_pivot_root_new) { + b = path_join(arg_directory, arg_pivot_root_new); + if (!b) + return log_oom(); + + p = b; + } 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; + r = log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Directory %s doesn't look like an OS root directory (os-release file is missing). Refusing.", p); goto finish; } } else { - const char *p, *q; + _cleanup_free_ char *p = NULL; if (arg_pivot_root_new) - p = prefix_roota(arg_directory, arg_pivot_root_new); + p = path_join(arg_directory, arg_pivot_root_new, "/usr/"); else - p = arg_directory; - - q = strjoina(p, "/usr/"); + p = path_join(arg_directory, "/usr/"); + if (!p) + return log_oom(); - if (laccess(q, F_OK) < 0) { - log_error("Directory %s doesn't look like it has an OS tree. Refusing.", p); - r = -EINVAL; + if (laccess(p, F_OK) < 0) { + r = log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Directory %s doesn't look like it has an OS tree (/usr/ directory is missing). Refusing.", arg_directory); goto finish; } }