From d90031f5d7d4ca9918d140809f4ae7f19e19c988 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Fri, 6 Dec 2024 13:44:37 +0100 Subject: [PATCH] vsock: connect: respect '--pwd' and '--cwd' if defined So it is possible to change the current directory used to execute the vsock command with '--pwd' or '--cwd'. Note that if --cwd or --root is not defined, 'vng' will set '--pwd'. So by default, 'vng --vsock-connect' will set '--pwd'. Signed-off-by: Matthieu Baerts (NGI0) --- virtme/commands/run.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/virtme/commands/run.py b/virtme/commands/run.py index b922249e..0771460c 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -889,6 +889,13 @@ def do_it() -> int: user = args.user if args.user else '${virtme_user:-root}' + if args.pwd: + cwd = os.path.relpath(os.getcwd(), args.root) + elif args.cwd is not None: + cwd = os.path.relpath(args.cwd, args.root) + else: + cwd = '${virtme_chdir:+"${virtme_chdir}"}' + # use 'su' only if needed: another use, or to get a prompt cmd = f'if [ "{user}" != "root" ]; then\n' + \ f' exec su "{user}"' @@ -908,7 +915,7 @@ def do_it() -> int: 'main() {\n' f'{stty}\n' f'HOME=$(getent passwd "{user}" | cut -d: -f6)\n' - 'cd ${virtme_chdir:+"${virtme_chdir}"}\n' + f'cd {cwd}\n' f'{cmd}\n' '}\n' 'main' # use a function to avoid issues when the script is modified