Skip to content

Commit

Permalink
vsock: connect: respect '--pwd' and '--cwd' if defined
Browse files Browse the repository at this point in the history
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) <matttbe@kernel.org>
  • Loading branch information
matttbe committed Dec 6, 2024
1 parent 3dde14d commit d90031f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"'
Expand All @@ -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
Expand Down

0 comments on commit d90031f

Please sign in to comment.