mesa/.gitlab-ci/crosvm-init.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# shellcheck disable=SC1091 # The relative paths in this file only become valid at runtime.
# shellcheck disable=SC2086 # we want word splitting
set -e
VSOCK_STDOUT=$1
VSOCK_STDERR=$2
VM_TEMP_DIR=$3
mount -t proc none /proc
mount -t sysfs none /sys
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
mkdir /dev/shm
mount -t tmpfs -o noexec,nodev,nosuid tmpfs /dev/shm
mount -t tmpfs tmpfs /tmp
. ${VM_TEMP_DIR}/crosvm-env.sh
. ${VM_TEMP_DIR}/setup-test-env.sh
virgl/ci: make crosvm-runner pass variables in a secure way crosvm-runner.sh was using `export -p` to create an environment script for the virtualized system, but this command will dump every declared environment variable in the system, which includes Gitlab's CI variables with sensitive data, such as passwords and auth tokens. Replacing `export -p` to `generate-env.sh`, which only exports the necessary variables for Mesa CI jobs. Extra changes: * Stop changing ${PWD} variable programmatically in scripts. ${PWD} is a variable used by most prolific coreutils and bash commands, such as `cd` and `pwd`, besides it is set by subshells [1]; changing this variable may lead to complex situations. As drop-in replacement for ${PWD}, use ${DEQP_BIN_DIR} to flag that there is a special folder where dEQP should be run. * Double quote path and array variables. See: https://github.com/koalaman/shellcheck/wiki/SC2086 * Do not export variables directly from commands output. See: https://github.com/koalaman/shellcheck/wiki/SC2155 [1] ``` $ cd /tmp $ export PWD=test; bash -c 'echo $PWD' /tmp ``` v2: - Revert $DEQP_BIN_DIR quoting in crosvm-runner.sh and crosvm-init.sh - Log all the passed variables to stdout, to help with debugging when new variable are needed to be put in `generate-env.sh` v3: - Revert $DEQP_BIN_DIR quoting leftovers Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com> Reviewed-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14626>
2022-01-14 21:43:08 +00:00
# .gitlab-ci.yml script variable is using relative paths to install directory,
# so change to that dir before running `crosvm-script`
cd "${CI_PROJECT_DIR}"
# The exception is the dEQP binary, as it needs to run from its own directory
[ -z "${DEQP_BIN_DIR}" ] || cd "${DEQP_BIN_DIR}"
# Use a FIFO to collect relevant error messages
STDERR_FIFO=/tmp/crosvm-stderr.fifo
mkfifo -m 600 ${STDERR_FIFO}
dmesg --level crit,err,warn -w > ${STDERR_FIFO} &
DMESG_PID=$!
# Transfer the errors and crosvm-script output via a pair of virtio-vsocks
socat -d -u pipe:${STDERR_FIFO} vsock-listen:${VSOCK_STDERR} &
socat -d -U vsock-listen:${VSOCK_STDOUT} \
system:"stdbuf -eL bash ${VM_TEMP_DIR}/crosvm-script.sh 2> ${STDERR_FIFO}; echo \$? > ${VM_TEMP_DIR}/exit_code",nofork
kill ${DMESG_PID}
wait
sync
poweroff -d -n -f || true
sleep 1 # Just in case init would exit before the kernel shuts down the VM