All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH alsa-utils 1/2] alsactl: Fix double decrease of lock timeout
@ 2020-12-11 22:50 Takashi Iwai
  2020-12-11 22:50 ` [PATCH alsa-utils 2/2] alsactl: Fix race at creating a lock file Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Iwai @ 2020-12-11 22:50 UTC (permalink / raw)
  To: alsa-devel

The state_lock() has a loop to wait for the lock file creation, and
the timeout value gets decremented twice mistakenly, which leads to a
half timeout (5 seconds) than expected 10 seconds.  Fix it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 alsactl/lock.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/alsactl/lock.c b/alsactl/lock.c
index 4a485392b3bd..05f6e4d2a102 100644
--- a/alsactl/lock.c
+++ b/alsactl/lock.c
@@ -63,7 +63,6 @@ static int state_lock_(const char *file, int lock, int timeout, int _fd)
 			if (fd < 0) {
 				if (errno == EBUSY || errno == EAGAIN) {
 					sleep(1);
-					timeout--;
 				} else {
 					err = -errno;
 					goto out;
-- 
2.26.2


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

* [PATCH alsa-utils 2/2] alsactl: Fix race at creating a lock file
  2020-12-11 22:50 [PATCH alsa-utils 1/2] alsactl: Fix double decrease of lock timeout Takashi Iwai
@ 2020-12-11 22:50 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2020-12-11 22:50 UTC (permalink / raw)
  To: alsa-devel

A race at creating a lock file in state_lock() was discovered
recently: namely, between the first open(O_RDWR) and the second
open(O_RDWR|O_CREAT|O_EXCL) calls, another alsactl invocation may
already create a lock file, then the second open() will return EEXIST,
which isn't handled properly and treated as a fatal error.

In this patch, we check EEXIST case and try again open() with O_RDWR.
This must succeed usually, and if it fails, handle finally as the
fatal error.

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

diff --git a/alsactl/lock.c b/alsactl/lock.c
index 05f6e4d2a102..5b4746231996 100644
--- a/alsactl/lock.c
+++ b/alsactl/lock.c
@@ -63,10 +63,15 @@ static int state_lock_(const char *file, int lock, int timeout, int _fd)
 			if (fd < 0) {
 				if (errno == EBUSY || errno == EAGAIN) {
 					sleep(1);
-				} else {
-					err = -errno;
-					goto out;
+					continue;
 				}
+				if (errno == EEXIST) {
+					fd = open(nfile, O_RDWR);
+					if (fd >= 0)
+						break;
+				}
+				err = -errno;
+				goto out;
 			}
 		}
 	}
-- 
2.26.2


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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11 22:50 [PATCH alsa-utils 1/2] alsactl: Fix double decrease of lock timeout Takashi Iwai
2020-12-11 22:50 ` [PATCH alsa-utils 2/2] alsactl: Fix race at creating a lock file Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.