Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmdlib.sh: feed /dev/zero as qemu stdin #3793

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions src/cmdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,6 @@ runvm() {
# and include all GPG keys
find /etc/pki/rpm-gpg/ -type f >> "${vmpreparedir}/hostfiles"

local cmdoutput
cmdoutput=${tmp_builddir}/cmd-output.txt

# the reason we do a heredoc here is so that the var substition takes
# place immediately instead of having to proxy them through to the VM
cat > "${vmpreparedir}/init" <<EOF
Expand All @@ -755,7 +752,7 @@ rc=0
# - Use a subshell because otherwise init will use workdir as its cwd and we won't
# be able to unmount the virtiofs mount cleanly. This leads to consistency issues.
if [ -z "${RUNVM_SHELL:-}" ]; then
(cd ${workdir}; bash ${tmp_builddir}/cmd.sh |& tee ${cmdoutput}) || rc=\$?
(cd ${workdir}; bash ${tmp_builddir}/cmd.sh |& tee /dev/virtio-ports/cosa-cmdout) || rc=\$?
else
(cd ${workdir}; bash)
fi
Expand Down Expand Up @@ -789,9 +786,7 @@ EOF
printf '%q ' "$arg" >> "${tmp_builddir}"/cmd.sh
done

touch "${runvm_console}" "${cmdoutput}"
setpriv --pdeathsig SIGTERM -- tail -qF "${cmdoutput}" --pid $$ &
local tail_pid=$!
touch "${runvm_console}"

# There seems to be some false positives in shellcheck
# https://github.com/koalaman/shellcheck/issues/2217
Expand Down Expand Up @@ -826,7 +821,9 @@ EOF

if [ -z "${RUNVM_SHELL:-}" ]; then
if ! "${kola_args[@]}" -- "${base_qemu_args[@]}" \
"${qemu_args[@]}"; then
-device virtserialport,chardev=virtioserial0,name=cosa-cmdout \
-chardev stdio,id=virtioserial0 \
"${qemu_args[@]}" < /dev/zero; then # qemu hangs if it has nothing to read on stdin
cat "${runvm_console}"
fatal "Failed to run 'kola qemuexec'"
fi
Expand All @@ -845,13 +842,6 @@ EOF
fi
rc="$(cat "${rc_file}")"

# XXX: this is for debugging temporarily
if [ -n "${TAIL_SLEEP:-}" ]; then
sleep "${TAIL_SLEEP}"
fi
# cleanup tail before nuking dir containing file it's following
kill "$tail_pid"

if [ -n "${cleanup_tmpdir:-}" ]; then
rm -rf "${tmp_builddir}"
unset tmp_builddir
Expand Down
2 changes: 1 addition & 1 deletion src/secex-genprotimgvm-scripts/runvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ else
fi

if ! "${kola_args[@]}" -- "${base_qemu_args[@]}" \
"${qemu_args[@]}" <&-; then # the <&- here closes stdin otherwise qemu waits forever
"${qemu_args[@]}" < /dev/zero; then # qemu hangs if it has nothing to read on stdin
cat "${runvm_console}"
echo "Failed to run 'kola qemuexec'"
exit 1
Expand Down
Loading