Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] alsactl: Skip restore during the lock
@ 2020-12-11  8:38 Takashi Iwai
  2020-12-11 16:45 ` Jaroslav Kysela
  0 siblings, 1 reply; 11+ messages in thread
From: Takashi Iwai @ 2020-12-11  8:38 UTC (permalink / raw)
  To: alsa-devel

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-12-11 18:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-11  8:38 [PATCH] alsactl: Skip restore during the lock Takashi Iwai
2020-12-11 16:45 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox