#! /bin/sh # # Atempts to reconfigure hda pin configuration after # a resume. Audio pin configuration presented here # is for a # # Since pulseaudio grabs the codec, reconfiguration will fail. # As such, first we try to stop pulseaudio, then reconfigure # pins and finally resume pulseaudio. # # FIXME: There's an obvious racing condition with this idea # The autospawn feature of pulseaudio may cause it to relaunch # before the pin reconfiguration is performed. Current tests # indicate that this do not occur in practice. Still it would # be better to find a more robust solution. # # # By Thiago Martins. # Adapted the idea of sudoing through # pulseaudio users (and copied get_pulse_users) # from "01PulseAudio" script on "pulseaudio" debian package # by CJ van der Berg # # FIXME: get this dinamically! HDA_USER_RECONFIG_ROOT=/sys/class/sound/hwC0D0 test_pulse_system() { getent passwd pulse | awk -F: '{print $3}' } get_pulse_users() { PULSE_SYSTEM_USER=$(test_pulse_system) if [ -z "${PULSE_SYSTEM_USER}" ]; then ps -C pulseaudio -o uid= | tr -d ' ' else ps -C pulseaudio -o uid= | tr -d ' ' | sed s/${PULSE_SYSTEM_USER}// fi } case $1 in thaw|resume) # check if there's any user pin config on if [ -s ${HDA_USER_RECONFIG_ROOT}/user_pin_configs ] ; then # Kill pulseaudio for everyone for i in $(get_pulse_users); do THIS_USER="$(getent passwd ${i} | cut -f1 -d:)" su "${THIS_USER}" -c -- 'pulseaudio --kill' done # Reset audio pins # For some reason, just writing to reconfig isn't enough TMP_CONFIG_FILE=$(mktemp) cat ${HDA_USER_RECONFIG_ROOT}/user_pin_configs > ${TMP_CONFIG_FILE} cat ${TMP_CONFIG_FILE} > ${HDA_USER_RECONFIG_ROOT}/user_pin_configs rm ${TMP_CONFIG_FILE} echo 1 > ${HDA_USER_RECONFIG_ROOT}/reconfig # Now reenable pulseaudio for i in $(get_pulse_users); do THIS_USER="$(getent passwd ${i} | cut -f1 -d:)" su "${THIS_USER}" -c -- 'pulseaudio --start' done fi ;; *) exit $NA ;; esac