From 6d770a4f7b72ca91ad02bc0a498b15dc7388df2a Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 2 Jul 2021 14:12:35 -0700 Subject: [PATCH 1/2] lib.sh: use dirname "${BASH_SOURCE[0]}" because we're sourced dirname "$0" was working by chance and only because all tests sourcing us were at the same level than us. This allows sourcing us from different levels. Signed-off-by: Marc Herbert --- case-lib/lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/case-lib/lib.sh b/case-lib/lib.sh index 13c5b350..75dca312 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -1,7 +1,7 @@ #!/bin/bash # get test-case information -SCRIPT_HOME="$(dirname "$0")" +SCRIPT_HOME="$(dirname "${BASH_SOURCE[0]}")" # get test-case parent folder name SCRIPT_HOME=$(cd "$SCRIPT_HOME/.." && pwd) # shellcheck disable=SC2034 # external script can use it From 1f4555ca70315138f74bde6079c294562e708a9b Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 2 Jul 2021 10:43:21 -0700 Subject: [PATCH 2/2] New systemctl_show_pulseaudio() that catches the sneaky 'gdm' user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trying to stop the unstoppable thanks to the --global option Sample ~/SOF/sof-test/tools/kmod/sof_remove.sh output: SKIP snd_compress not loaded SKIP snd_pcm not loaded 529 /usr/bin/pulseaudio --daemonize=no --log-target=journal + systemctl --system list-unit-files --all '*pulse*' UNIT FILE STATE VENDOR PRESET pulseaudio-enable-autospawn.service masked enabled 1 unit files listed. + systemctl --global list-unit-files --all '*pulse*' UNIT FILE STATE VENDOR PRESET pulseaudio.service enabled enabled pulseaudio.socket enabled enabled 2 unit files listed. + systemctl --user list-unit-files --all '*pulse*' UNIT FILE STATE VENDOR PRESET pulseaudio.service masked enabled pulseaudio.socket masked enabled 2 unit files listed. For joe ONLY: + systemctl --user list-units --all '*pulse*' UNIT LOAD ACTIVE SUB DESCRIPTION ● pulseaudio.service masked inactive dead pulseaudio.service ● pulseaudio.socket masked inactive dead pulseaudio.socket LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type. 2 loaded units listed. To show all installed unit files use 'systemctl list-unit-files'. gdm 529 0.0 0.3 804512 13960 ? S --- case-lib/lib.sh | 36 ++++++++++++++++++++++++++++++++++++ tools/kmod/sof_remove.sh | 10 +++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/case-lib/lib.sh b/case-lib/lib.sh index 75dca312..86fceadf 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -162,6 +162,42 @@ func_lib_check_sudo() } } +systemctl_show_pulseaudio() +{ + printf '\n' + local domain + for domain in --system --global --user; do + ( set -x + systemctl "$domain" list-unit-files --all '*pulse*' + ) || true + printf '\n' + done + + printf 'For %s ONLY:\n' "$(id -un)" + ( set -x + systemctl --user list-units --all '*pulse*' + ) || true + printf '\n' + + # pgrep ouput is nicer because it hides itself, however pgrep does + # not show a critical information: the userID which can be not us + # but 'gdm'! + # shellcheck disable=SC2009 + ps axu | grep -i pulse + >&2 printf 'ERROR: %s fails semi-randomly when pulseaudio is running\n' \ + "$(basename "$0")" + + >&2 printf '\nTry: sudo systemctl --global mask pulseaudio.{socket,service} and reboot. + --global is required for session managers like "gdm" +' + # We cannot suggest "systemctl --user mask" for a 'gdm' user + # because we can't 'su' to it and access its DBUS, so we suggest + # --global to keep it simple. If --global is too strong for you, you + # can manually create a + # /var/lib/gdm3/.config/systemd/user/pulseaudio.service -> /dev/null + # symlink +} + declare -a PULSECMD_LST declare -a PULSE_PATHS diff --git a/tools/kmod/sof_remove.sh b/tools/kmod/sof_remove.sh index 7647fd53..9c95adad 100755 --- a/tools/kmod/sof_remove.sh +++ b/tools/kmod/sof_remove.sh @@ -2,6 +2,12 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Intel Corporation. All rights reserved. + +TOPDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd) + +# shellcheck source=case-lib/lib.sh +source "$TOPDIR"/case-lib/lib.sh + remove_module() { local MODULE="$1" @@ -22,9 +28,7 @@ exit_handler() # warn about any running pulseaudio because it could make us fail # the next time. if pgrep -a pulseaudio; then - >&2 printf 'ERROR: %s fails semi-randomly when pulseaudio is running\n' \ - "$(basename "$0")" - systemctl --user list-units --all '*pulse*' || true + systemctl_show_pulseaudio fi if test "$exit_status" -ne 0; then