Skip to content

Commit

Permalink
vsock: connect: respect '--user' if defined
Browse files Browse the repository at this point in the history
So it is possible to change the user used to execute the vsock command
with '--user'.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
  • Loading branch information
matttbe committed Dec 6, 2024
1 parent e4651aa commit 3dde14d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,11 @@ def do_it() -> int:
socat_in = '-'
socat_out = f'VSOCK-CONNECT:{args.vsock_cid}:1024'

user = args.user if args.user else '${virtme_user:-root}'

# use 'su' only if needed: another use, or to get a prompt
cmd = 'if [ "${virtme_user:-root}" != "root" ]; then\n' + \
' exec su ${virtme_user}'
cmd = f'if [ "{user}" != "root" ]; then\n' + \
f' exec su "{user}"'
if args.vsock_connect:
exec_escaped = args.vsock_connect.replace('"', '\\"')
cmd += f' -c "{exec_escaped}"' + \
Expand All @@ -905,7 +907,7 @@ def do_it() -> int:
'#! /bin/bash\n'
'main() {\n'
f'{stty}\n'
'HOME=$(getent passwd ${virtme_user:-root} | cut -d: -f6)\n'
f'HOME=$(getent passwd "{user}" | cut -d: -f6)\n'
'cd ${virtme_chdir:+"${virtme_chdir}"}\n'
f'{cmd}\n'
'}\n'
Expand Down

0 comments on commit 3dde14d

Please sign in to comment.