diff mbox series

[2/2] tests: run-tests: don't use sudo if already root

Message ID 20200625202202.93564-2-briannorris@chromium.org
State New
Headers show
Series [1/2] tests: Skip busctl tests when not available | expand

Commit Message

Brian Norris June 25, 2020, 8:22 p.m. UTC
Among other things, sudo can disrupt environment variables that a caller
provides.

Signed-off-by: Brian Norris <briannorris@chromium.org>
---
 tests/hwsim/run-all.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tests/hwsim/run-all.sh b/tests/hwsim/run-all.sh
index 495c9fa744b8..ee48cd0581c6 100755
--- a/tests/hwsim/run-all.sh
+++ b/tests/hwsim/run-all.sh
@@ -122,7 +122,13 @@  if ! ./start.sh $VM $VALGRIND $TRACE channels=$NUM_CH; then
 	exit 1
 fi
 
-sudo ./run-tests.py -D --logdir "$LOGDIR" $TRACE_ARGS -q $DB $RUN_TEST_ARGS || errors=1
+# Only use sudo if not already root.
+if [ "$(id -u)" != 0 ]; then
+	SUDO=sudo
+else
+	SUDO=
+fi
+${SUDO} ./run-tests.py -D --logdir "$LOGDIR" $TRACE_ARGS -q $DB $RUN_TEST_ARGS || errors=1
 
 ./stop.sh