From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-961087-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id E1C79139694
	for <garchives@archives.gentoo.org>; Tue, 11 Jul 2017 09:10:29 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 24EA027424A;
	Tue, 11 Jul 2017 09:10:28 +0000 (UTC)
Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id E735627424A
	for <gentoo-commits@lists.gentoo.org>; Tue, 11 Jul 2017 09:10:27 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 35B6F341792
	for <gentoo-commits@lists.gentoo.org>; Tue, 11 Jul 2017 09:10:26 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 974517490
	for <gentoo-commits@lists.gentoo.org>; Tue, 11 Jul 2017 09:10:24 +0000 (UTC)
From: "Lars Wendler" <polynomial-c@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Lars Wendler" <polynomial-c@gentoo.org>
Message-ID: <1499764220.f79bf1ba54fd2cb5cb9b8fcbdc9e99fea1b9acc7.polynomial-c@gentoo>
Subject: [gentoo-commits] repo/gentoo:master commit in: media-sound/alsa-utils/, media-sound/alsa-utils/files/
X-VCS-Repository: repo/gentoo
X-VCS-Files: media-sound/alsa-utils/alsa-utils-1.1.4-r1.ebuild media-sound/alsa-utils/alsa-utils-1.1.4.ebuild media-sound/alsa-utils/files/alsasound.initd-r7
X-VCS-Directories: media-sound/alsa-utils/ media-sound/alsa-utils/files/
X-VCS-Committer: polynomial-c
X-VCS-Committer-Name: Lars Wendler
X-VCS-Revision: f79bf1ba54fd2cb5cb9b8fcbdc9e99fea1b9acc7
X-VCS-Branch: master
Date: Tue, 11 Jul 2017 09:10:24 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: 4e840858-6d6c-4550-bc4f-d88690a6ec46
X-Archives-Hash: 8d62ebf9c0a29e0946bca0a33224a841

commit:     f79bf1ba54fd2cb5cb9b8fcbdc9e99fea1b9acc7
Author:     Virgil Dupras <hsoft <AT> hardcoded <DOT> net>
AuthorDate: Mon May  8 16:16:58 2017 +0000
Commit:     Lars Wendler <polynomial-c <AT> gentoo <DOT> org>
CommitDate: Tue Jul 11 09:10:20 2017 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f79bf1ba

media-sound/alsa-utils: Fix initd delay script when there's no soundcard

Fixes #617782

Package-Manager: Portage-2.3.5, Repoman-2.3.1
Closes: https://github.com/gentoo/gentoo/pull/4570

 ...ils-1.1.4.ebuild => alsa-utils-1.1.4-r1.ebuild} |  2 +-
 media-sound/alsa-utils/files/alsasound.initd-r7    | 87 ++++++++++++++++++++++
 2 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/media-sound/alsa-utils/alsa-utils-1.1.4.ebuild b/media-sound/alsa-utils/alsa-utils-1.1.4-r1.ebuild
similarity index 97%
rename from media-sound/alsa-utils/alsa-utils-1.1.4.ebuild
rename to media-sound/alsa-utils/alsa-utils-1.1.4-r1.ebuild
index 9c10bb2c4ec..87137657c10 100644
--- a/media-sound/alsa-utils/alsa-utils-1.1.4.ebuild
+++ b/media-sound/alsa-utils/alsa-utils-1.1.4-r1.ebuild
@@ -45,7 +45,7 @@ src_install() {
 	default
 	dodoc seq/*/README.*
 
-	newinitd "${FILESDIR}"/alsasound.initd-r6 alsasound
+	newinitd "${FILESDIR}"/alsasound.initd-r7 alsasound
 	newconfd "${FILESDIR}"/alsasound.confd-r4 alsasound
 
 	insinto /etc/modprobe.d

diff --git a/media-sound/alsa-utils/files/alsasound.initd-r7 b/media-sound/alsa-utils/files/alsasound.initd-r7
new file mode 100644
index 00000000000..da2d5b349b8
--- /dev/null
+++ b/media-sound/alsa-utils/files/alsasound.initd-r7
@@ -0,0 +1,87 @@
+#!/sbin/openrc-run
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+alsastatedir=/var/lib/alsa
+alsascrdir=/etc/alsa.d
+alsahomedir=/var/run/alsasound
+
+extra_commands="save restore"
+
+depend() {
+	need localmount
+	after bootmisc modules isapnp coldplug hotplug
+}
+
+restore() {
+	ebegin "Restoring Mixer Levels"
+
+	checkpath -q -d -m 0700 -o root:root ${alsahomedir} || return 1
+
+	if [ ! -r "${alsastatedir}/asound.state" ] ; then
+		ewarn "No mixer config in ${alsastatedir}/asound.state, you have to unmute your card!"
+		eend 0
+		return 0
+	fi
+
+	local cards="$(sed -n -e 's/^ *\([[:digit:]]*\) .*/\1/p' /proc/asound/cards)"
+	local CARDNUM
+	for cardnum in ${cards}; do
+		[ -e /dev/snd/controlC${cardnum} ] || sleep 2
+		[ -e /dev/snd/controlC${cardnum} ] || sleep 2
+		[ -e /dev/snd/controlC${cardnum} ] || sleep 2
+		[ -e /dev/snd/controlC${cardnum} ] || sleep 2
+		alsactl -E HOME="${alsahomedir}" -I -f "${alsastatedir}/asound.state" restore ${cardnum} \
+			|| ewarn "Errors while restoring defaults, ignoring"
+	done
+
+	for ossfile in "${alsastatedir}"/oss/card*_pcm* ; do
+		[ -e "${ossfile}" ] || continue
+		# We use cat because I'm not sure if cp works properly on /proc
+		local procfile=${ossfile##${alsastatedir}/oss}
+		procfile="$(echo "${procfile}" | sed -e 's,_,/,g')"
+		if [ -e /proc/asound/"${procfile}"/oss ] ; then
+		    cat "${ossfile}" > /proc/asound/"${procfile}"/oss 
+		fi
+	done
+
+	eend 0
+}
+
+save() {
+	ebegin "Storing ALSA Mixer Levels"
+
+	checkpath -q -d -m 0700 -o root:root ${alsahomedir} || return 1
+
+	mkdir -p "${alsastatedir}"
+	if ! alsactl -E HOME="${alsahomedir}" -f "${alsastatedir}/asound.state" store; then
+		eerror "Error saving levels."
+		eend 1
+		return 1
+	fi
+
+	for ossfile in /proc/asound/card*/pcm*/oss; do
+		[ -e "${ossfile}" ] || continue
+		local device=${ossfile##/proc/asound/} ; device=${device%%/oss}
+		device="$(echo "${device}" | sed -e 's,/,_,g')"
+		mkdir -p "${alsastatedir}/oss/"
+		cp "${ossfile}" "${alsastatedir}/oss/${device}"
+	done
+
+	eend 0
+}
+
+start() {
+	if [ "${RESTORE_ON_START}" = "yes" ]; then
+		restore
+	fi
+
+	return 0
+}
+
+stop() {
+	if [ "${SAVE_ON_STOP}" = "yes" ]; then
+		save
+	fi
+	return 0
+}