tests: Fix setup.sh to pass DBus env vars through sudo The script setup.sh starts mapperx daemon using sudo. In some environments, sudo is configured to ignore '-E' (environment preservation), which cleans critical environment variables like LD_LIBRARY_PATH, DBUS_SESSION_BUS_ADDRESS, and DBUS_STARTER_BUS_TYPE. This causes mapperx to fail to start due to missing libraries or failing to connect to the session bus. Fix this by explicitly passing these variables via 'sudo env' when they are set. Change-Id: I12a9b1d57efd43b01b48d86b11c4ae9e520409d9 Signed-off-by: Muhammad Usama <muhammadusama@google.com>
diff --git a/tests/setup.sh b/tests/setup.sh index 7928b6e..0f2a037 100644 --- a/tests/setup.sh +++ b/tests/setup.sh
@@ -21,8 +21,10 @@ # restart O-M so it picks up the correct dbus sudo kill $(pgrep mapperx) for ((i = 1; i <= 5; i++)); do - LD_LIBRARY_PATH="/usr/local/lib/x86_64-linux-gnu/:/usr/local/lib/" \ - sudo -E start-stop-daemon --start -b -c "$(whoami)" --exec /usr/local/libexec/phosphor-objmgr/mapperx \ + sudo env LD_LIBRARY_PATH="/usr/local/lib/x86_64-linux-gnu/:/usr/local/lib/" \ + ${DBUS_SESSION_BUS_ADDRESS:+DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS"} \ + ${DBUS_STARTER_BUS_TYPE:+DBUS_STARTER_BUS_TYPE="$DBUS_STARTER_BUS_TYPE"} \ + start-stop-daemon --start -b -c "$(whoami)" --exec /usr/local/libexec/phosphor-objmgr/mapperx \ -- "--service-namespaces=com.google.gbmc com.intel xyz.openbmc_project org.openbmc" \ "--interface-namespaces=org.freedesktop.DBus.ObjectManager com.google.gbmc com.intel xyz.openbmc_project org.openbmc" \ --service-blacklists= && break