Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH] alsactl: Skip restore during the lock
Date: Fri, 11 Dec 2020 09:38:04 +0100	[thread overview]
Message-ID: <20201211083804.800-1-tiwai@suse.de> (raw)

Currently alsactl-restore tries to initialize the device when an error
is found for restore action.  But this isn't the right behavior in the
case where the lock is held; it implies that another alsactl is
running concurrently, hence you shouldn't initialize the card at the
same time.  The situation is found easily when two alsactls get
started by both udev and systemd (note that those two invocations are
the designed behavior, see /usr/lib/udev/rules.d/78-sound-cards.rules
for details).

This patch changes load_state() not to handle the initialization if
the locking fails.

BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1179904
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 alsactl/state.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/alsactl/state.c b/alsactl/state.c
index ea1d3bcaaddf..8d1d814341bd 100644
--- a/alsactl/state.c
+++ b/alsactl/state.c
@@ -1663,7 +1663,12 @@ int load_state(const char *file, const char *initfile, int initflags,
 		err = snd_input_stdio_attach(&in, stdin, 0);
 	} else {
 		lock_fd = state_lock(file, 10);
-		err = lock_fd >= 0 ? snd_input_stdio_open(&in, file, "r") : lock_fd;
+		/* skip restore if already locked; i.e. concurrent accesses */
+		if (lock_fd < 0) {
+			err = 0;
+			goto out_global;
+		}
+		err = snd_input_stdio_open(&in, file, "r");
 	}
 	if (err >= 0) {
 		err = snd_config_load(config, in);
@@ -1781,6 +1786,7 @@ single:
 	err = finalerr;
 out:
 	snd_config_delete(config);
+out_global:
 	snd_config_update_free_global();
 	return err;
 }
-- 
2.26.2


             reply	other threads:[~2020-12-11  8:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11  8:38 Takashi Iwai [this message]
2020-12-11 16:45 ` [PATCH] alsactl: Skip restore during the lock Jaroslav Kysela
2020-12-11 16:59   ` Takashi Iwai
2020-12-11 17:06     ` Takashi Iwai
2020-12-11 17:23       ` Jaroslav Kysela
2020-12-11 17:37         ` Takashi Iwai
2020-12-11 17:56           ` Jaroslav Kysela
2020-12-11 18:44             ` Takashi Iwai
2020-12-11 18:48               ` Jaroslav Kysela
2020-12-11 17:20     ` Jaroslav Kysela
2020-12-11 17:35       ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201211083804.800-1-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox