Skip to content

Commit

Permalink
vsock: connect: avoid issues with modified script
Browse files Browse the repository at this point in the history
When an in progress Bash script is modified, Bash will continue at the
character where it was before, generally causing troubles.

Because multiple --vsock-connect can be used for the same VM, it sounds
good to use a simple workaround of using a function to avoid such
issues.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
  • Loading branch information
matttbe committed Dec 3, 2024
1 parent 0e75e9d commit f59ac70
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,13 @@ def do_it() -> int:
with open(vsock_script_path, 'w', encoding="utf-8") as file:
print((
'#! /bin/bash\n'
'main() {\n'
f'stty rows {rows} cols {cols} iutf8 echo\n'
'HOME=$(getent passwd ${virtme_user:-root} | cut -d: -f6)\n'
'cd ${virtme_chdir:+"${virtme_chdir}"}\n'
f'exec {cmd}'
f'exec {cmd}\n'
'}\n'
'main' # use a function to avoid issues when the script is modified
), file=file)
os.chmod(vsock_script_path, 0o755)

Expand Down

0 comments on commit f59ac70

Please sign in to comment.